⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aaibuildtask.cpp

📁 这是整套横扫千军3D版游戏的源码
💻 CPP
字号:
// -------------------------------------------------------------------------
// AAI
//
// A skirmish AI for the TA Spring engine.
// Copyright Alexander Seizinger
// 
// Released under GPL license: see LICENSE.html for more information.
// -------------------------------------------------------------------------

#include "AAIBuildTask.h"
#include "AAI.h"
#include "AAIConstructor.h"

AAIBuildTask::AAIBuildTask(AAI *ai, int unit_id, int def_id, float3 pos, int tick)
{
	this->ai = ai;
	this->unit_id = unit_id;
	this->def_id = def_id;

	order_tick = tick;

	builder_id = -1;

	build_pos = pos;
}

AAIBuildTask::~AAIBuildTask(void)
{
}

void AAIBuildTask::BuilderDestroyed()
{
	builder_id = -1;

	// com only allowed if buildpos is inside the base
	bool commander = false;
	
	int x = build_pos.x / ai->map->xSectorSize;
	int y = build_pos.z / ai->map->ySectorSize;

	if(x >= 0 && y >= 0 && x < ai->map->xSectors && y < ai->map->ySectors)
	{
		if(ai->map->sector[x][y].distance_to_base == 0)
			commander = true;
	}
	
	// look for new builder 
	AAIConstructor *new_builder;

	if(ai->bt->unitList[def_id-1]->minWaterDepth <= 0)
		new_builder = ai->ut->FindClosestAssister(build_pos, 10, commander, false, false);
	else
		new_builder = ai->ut->FindClosestAssister(build_pos, 10, commander, false, ai->bt->unitList[def_id-1]->floater);

	if(new_builder)
	{
		new_builder->TakeOverConstruction(this);
		builder_id = new_builder->unit_id;
	}
}

void AAIBuildTask::BuildtaskFailed()
{
	// cleanup buildmap etc.
	ai->execute->ConstructionFailed(build_pos, def_id);
	
	// tell builder to stop construction (and release assisters) (if still alive)
	if(builder_id >= 0 && ai->ut->units[builder_id].cons)
		ai->ut->units[builder_id].cons->ConstructionFinished();	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -