亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? aai.cpp

?? 這是整套橫掃千軍3D版游戲的源碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// -------------------------------------------------------------------------
// AAI
//
// A skirmish AI for the TA Spring engine.
// Copyright Alexander Seizinger
// 
// Released under GPL license: see LICENSE.html for more information.
// -------------------------------------------------------------------------

#include "AAI.h"
#include <math.h>
#include <stdio.h>


AAI::AAI()
{
	// initialize random numbers generator
	srand (time(NULL));

	brain = 0;
	execute = 0;
	bt = 0;
	ut = 0;
	map = 0;
	af = 0;
	am = 0;
	
	side = 0;

	for(int i = 0; i <= MOBILE_CONSTRUCTOR; i++)
	{
		activeUnits[i] = 0;
		futureUnits[i] = 0;
	}

	activeScouts = futureScouts = 0;
	activeBuilders = futureBuilders = 0;
	activeFactories = futureFactories = 0;

	initialized = false;
}

AAI::~AAI()
{
	if(!cfg->initialized)
		return;

	// save several ai data
	fprintf(file, "\nShutting down....\n\n");
	fprintf(file, "Unit category	active / under construction\n");
	for(int i = 0; i <= MOBILE_CONSTRUCTOR; i++)
	{
		fprintf(file, "%-20s: %i / %i\n", bt->GetCategoryString2((UnitCategory)i), activeUnits[i], futureUnits[i]); 
	}

	fprintf(file, "\nGround Groups:    %i\n", group_list[GROUND_ASSAULT].size());
	fprintf(file, "\nAir Groups:       %i\n", group_list[AIR_ASSAULT].size());
	fprintf(file, "\nHover Groups:     %i\n", group_list[HOVER_ASSAULT].size());
	fprintf(file, "\nSea Groups:       %i\n", group_list[SEA_ASSAULT].size());
	fprintf(file, "\nSubmarine Groups: %i\n", group_list[SUBMARINE_ASSAULT].size());
	
	fprintf(file, "\nFuture metal/energy request: %i / %i\n", (int)execute->futureRequestedMetal, (int)execute->futureRequestedEnergy);
	fprintf(file, "Future metal/energy supply:  %i / %i\n", (int)execute->futureAvailableMetal, (int)execute->futureAvailableEnergy);

	fprintf(file, "\nFuture/active scouts: %i / %i\n", futureScouts, activeScouts);

	// delete buildtasks
	for(list<AAIBuildTask*>::iterator task = build_tasks.begin(); task != build_tasks.end(); task++)
	{
		delete (*task);
	}

	// save mod learning data
	bt->SaveBuildTable();

	delete am;
	delete brain;
	delete execute;
	delete ut;
	delete af;
	delete map;
	delete bt;
	
	// delete unit groups
	for(int i = 0; i <= MOBILE_CONSTRUCTOR; i++)
	{
		for(list<AAIGroup*>::iterator group = group_list[i].begin(); group != group_list[i].end(); ++group)
		{
			delete (*group);
		}
	}

//	delete [] group_list;

	fclose(file);
}

void AAI::GotChatMsg(const char *msg, int player) {}

void AAI::EnemyDamaged(int damaged,int attacker,float damage,float3 dir) {}


void AAI::InitAI(IGlobalAICallback* callback, int team)
{
	aicb = callback;
	cb = callback->GetAICallback();

	// open log file
	char filename[500];
	char buffer[500];
	char team_number[3];
	
	#ifdef WIN32
		itoa(team, team_number, 10);
	#else
		snprintf(team_number,10,"%d",team);
	#endif
	
	strcpy(buffer, MAIN_PATH);
	strcat(buffer, AILOG_PATH);
	strcat(buffer, "AAI_log_team_");
	strcat(buffer, team_number);
	strcat(buffer, ".txt");
	ReplaceExtension (buffer, filename, sizeof(filename), ".txt");

	cb->GetValue(AIVAL_LOCATE_FILE_W, filename); 

	file = fopen(filename,"w");

	fprintf(file, "AAI %s running mod %s\n \n", AAI_VERSION, cb->GetModName());

	// load config file first
	cfg->LoadConfig(this);

	if(!cfg->initialized)
	{
		cb->SendTextMsg("Error: Could not load mod and/or general config file, see .../log/AILog.txt for further information",0);
		return;
	}

	// create buildtable
	bt = new AAIBuildTable(cb, this);
	bt->Init();
	
	// init unit table
	ut = new AAIUnitTable(this, bt);

	// init map
	map = new AAIMap(this);
	map->Init();

	// init brain
	brain = new AAIBrain(this);

	// init executer
	execute = new AAIExecute(this, brain);

	// create unit groups
//	group_list = new list<AAIGroup*>[MOBILE_CONSTRUCTOR+1];
	group_list.resize(MOBILE_CONSTRUCTOR+1);
	// init airforce manager
	af = new AAIAirForceManager(this, cb, bt);

	// init attack manager
	am = new AAIAttackManager(this, cb, bt);

	cb->SendTextMsg("AAI loaded", 0);
}

void AAI::UnitDamaged(int damaged, int attacker, float damage, float3 dir)
{
	if(damaged < 0)
		return;

	const UnitDef *def, *att_def;
	UnitCategory att_cat, cat;
	
	// filter out commander
	if(ut->cmdr != -1)
	{
		if(damaged == ut->cmdr)
			brain->DefendCommander(attacker);
	}

	def = cb->GetUnitDef(damaged);

	if(def)
		cat =  bt->units_static[def->id].category;
	else
		cat = UNKNOWN;
	
	// known attacker
	if(attacker != -1)
	{
		att_def = cb->GetUnitDef(attacker);

		// filter out friendly fire
		if(cb->GetUnitTeam(attacker) == cb->GetMyTeam())
			return;

		if(att_def)
		{
			att_cat = bt->units_static[att_def->id].category;

			// retreat builders
			if(ut->IsBuilder(damaged))
				ut->units[damaged].cons->Retreat(att_cat);
			
			if(att_cat >= GROUND_ASSAULT && att_cat <= SUBMARINE_ASSAULT)
			{
				float3 pos = cb->GetUnitPos(attacker);
				AAISector *sector = map->GetSectorOfPos(&pos);

				if(sector && !am->SufficientDefencePowerAt(sector, 1.2f))
				{
					// building has been attacked
					if(cat <= METAL_MAKER)
						execute->DefendUnitVS(damaged, def, att_cat, &pos, 115);
					// builder
					else if(ut->IsBuilder(damaged))
						execute->DefendUnitVS(damaged, def, att_cat, &pos, 110);
					// normal units
					else 
						execute->DefendUnitVS(damaged, def, att_cat, &pos, 105);
				}
			}
		}
	}
	// unknown attacker
	else
	{
		// set default attacker
		float3 pos = cb->GetUnitPos(damaged);

		if(pos.y > 0)
			att_cat = GROUND_ASSAULT;
		else
			att_cat = SEA_ASSAULT;

		// retreat builders
		if(ut->IsBuilder(damaged))
			ut->units[damaged].cons->Retreat(att_cat);
		
		// building has been attacked
		if(cat <= METAL_MAKER)
			execute->DefendUnitVS(damaged, def, att_cat, NULL, 115);
		else if(ut->IsBuilder(damaged))
			execute->DefendUnitVS(damaged, def, att_cat, NULL, 110);
	}
}

void AAI::UnitCreated(int unit)
{
	if(!cfg->initialized)
		return;

	// get unit磗 id and side
	const UnitDef *def = cb->GetUnitDef(unit);
	int side = bt->GetSideByID(def->id)-1;
	UnitCategory category = bt->units_static[def->id].category;

	// add to unittable 
	ut->AddUnit(unit, def->id);

	// get commander a startup
	if(!initialized && ut->IsDefCommander(def->id))
	{
		++futureUnits[COMMANDER];

		// set side
		this->side = side+1;

		//debug
		fprintf(file, "Playing as %s\n", bt->sideNames[side+1].c_str());

		if(this->side < 1 || this->side > bt->numOfSides)
		{
			cb->SendTextMsg("Error: side not properly set", 0);
			fprintf(file, "ERROR: invalid side id %i\n", this->side);
			return;
		}

		// tell the brain about the starting sector
		float3 pos = cb->GetUnitPos(unit);
		int x = pos.x/map->xSectorSize;
		int y = pos.z/map->ySectorSize;

		if(x < 0)
			x = 0;
		if(y < 0 ) 
			y = 0;
		if(x >= map->xSectors)
			x = map->xSectors-1;
		if(y >= map->ySectors)
			y = map->ySectors-1;
		
		// set sector as part of the base
		if(map->sector[x][y].SetBase(true))
		{
			brain->AddSector(&map->sector[x][y]);
			brain->start_pos = pos;
			brain->UpdateNeighbouringSectors();
			brain->UpdateBaseCenter();
		}
		else
		{
			// sector already occupied by another aai team (coms starting too close to each other)
			// choose next free sector
			execute->ChooseDifferentStartingSector(x, y);
		}

	

		if(map->mapType == WATER_MAP)
			brain->ExpandBase(WATER_SECTOR);
		else 
			brain->ExpandBase(LAND_SECTOR);
	
		// now that we know the side, init buildques
		execute->InitBuildques();

		bt->InitCombatEffCache(this->side);

		ut->AddCommander(unit, def->id);

		// add the highest rated, buildable factory
		execute->AddStartFactory();

		// get economy working
		execute->CheckRessources();

		initialized = true;
		return;
	}
	// construction of building started
	else if(category <= METAL_MAKER && category > UNKNOWN)
	{
		// create new buildtask
		AAIBuildTask *task;
		
		try
		{
			task = new AAIBuildTask(this, unit, def->id, cb->GetUnitPos(unit), cb->GetCurrentFrame());
		}
		catch(...) 
		{
			fprintf(file, "Exception thrown when allocating memory for buildtask");
		}

		build_tasks.push_back(task);

		float3 pos = cb->GetUnitPos(unit);
		// find builder and associate building with that builder
		task->builder_id = -1;

		for(set<int>::iterator i = ut->constructors.begin(); i != ut->constructors.end(); ++i)
		{
			if(ut->units[*i].cons->build_pos.x == pos.x && ut->units[*i].cons->build_pos.z == pos.z)
			{
				ut->units[*i].cons->construction_unit_id = unit;
				task->builder_id = ut->units[*i].cons->unit_id;
				ut->units[*i].cons->build_task = task;
				ut->units[*i].cons->CheckAssistance();
				break;
			}
		}

		// add defence buildings to the sector
		if(category == STATIONARY_DEF)
		{
			int x = pos.x/map->xSectorSize;
			int y = pos.z/map->ySectorSize;

			if(x >= 0 && y >= 0 && x < map->xSectors && y < map->ySectors)
				map->sector[x][y].AddDefence(unit, def->id);
		}
		else if(category == EXTRACTOR)
		{
			int x = pos.x/map->xSectorSize;
			int y = pos.z/map->ySectorSize;

			map->sector[x][y].AddExtractor(unit, def->id, &pos);
		}
	}
}

void AAI::UnitDestroyed(int unit, int attacker) 
{
	// get unit磗 id 
	const UnitDef *def = cb->GetUnitDef(unit);
	int side = bt->GetSideByID(def->id)-1;

	if(!def)
	{
		fprintf(file, "Error: UnitDestroyed() called with invalid unit id"); 
		return;
	}

	// get unit's category
	UnitCategory category = bt->units_static[def->id].category;
	// and position
	float3 pos = cb->GetUnitPos(unit);
	int x = pos.x/map->xSectorSize;
	int y = pos.z/map->ySectorSize;

	// check if unit pos is within a valid sector (e.g. aircraft flying outside of the map)
	bool validSector = true;

	if(x >= map->xSectors || x < 0 || y < 0 || y >= map->ySectors)
		validSector = false;

	// update threat map
	if(attacker && validSector)
	{
		const UnitDef *att_def = cb->GetUnitDef(attacker);

		if(att_def)	
			map->sector[x][y].UpdateThreatValues((UnitCategory)category, bt->units_static[att_def->id].category);
	}

	// unfinished unit has been killed
	if(cb->UnitBeingBuilt(unit))
	{
		--futureUnits[category];
		--bt->units_dynamic[def->id].requested;

		// unfinished building
		if(!def->canfly && !def->movedata)
		{
			// delete buildtask
			for(list<AAIBuildTask*>::iterator task = build_tasks.begin(); task != build_tasks.end(); task++)
			{
				if((*task)->unit_id == unit)
				{	
					(*task)->BuildtaskFailed();
					delete *task;

					build_tasks.erase(task);
					break;
				}
			}

			if(bt->units_static[def->id].category == STATIONARY_DEF && validSector)
				map->sector[x][y].RemoveDefence(unit);
		}
		// unfinished unit
		else
		{
			if(category == SCOUT)
				--futureScouts;	

			if(bt->IsBuilder(def->id))
			{
				--futureBuilders;

				for(list<int>::iterator unit = bt->units_static[def->id].canBuildList.begin();  unit != bt->units_static[def->id].canBuildList.end(); ++unit)		
					--bt->units_dynamic[*unit].buildersRequested;
			}

			if(bt->IsFactory(def->id))
			{
				--futureFactories;

				for(list<int>::iterator unit = bt->units_static[def->id].canBuildList.begin();  unit != bt->units_static[def->id].canBuildList.end(); ++unit)		
					--bt->units_dynamic[*unit].buildersRequested;
			}
		}
	}
	else	// finished unit/building has been killed
	{
		activeUnits[category] -= 1;
		bt->units_dynamic[def->id].active -= 1;
		
		// update buildtable
		if(attacker)
		{
			const UnitDef *def_att = cb->GetUnitDef(attacker);
			
			if(def_att)
			{
				int killer = bt->GetIDOfAssaultCategory(bt->units_static[def_att->id].category);
				int killed = bt->GetIDOfAssaultCategory((UnitCategory)category);

				// check if valid id 
				if(killer != -1)		
				{
					brain->AttackedBy(killer);

					if(killed != -1)
					{
						bt->UpdateTable(def_att, killer, def, killed);
						map->UpdateCategoryUsefulness(def_att, killer, def, killed);
					}
				}
			}
		}

		// finished building has been killed
		if(!def->canfly && !def->movedata)
		{
			// decrease number of units of that category in the target sector
			if(validSector)
			{
				map->sector[x][y].unitsOfType[category] -= 1;
				map->sector[x][y].own_structures -= bt->units_static[def->id].cost;

				if(map->sector[x][y].own_structures < 0)
					map->sector[x][y].own_structures = 0;
			}

			// check if building belongs to one of this groups
			// side -1 because sides start with 1; array of sides with 0
			if(category == STATIONARY_DEF)
			{
				if(validSector)
					map->sector[x][y].RemoveDefence(unit);	

				// remove defence from map				
				map->RemoveDefence(&pos, def->id); 
			}
			else if(category == EXTRACTOR)
			{
				ut->RemoveExtractor(unit);

				// mark spots of destroyed mexes as unoccupied
				map->sector[x][y].FreeMetalSpot(cb->GetUnitPos(unit), def);
			}
			else if(category == POWER_PLANT)
			{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线不卡中文字幕| 91久久线看在观草草青青| 亚洲激情自拍偷拍| 国产亚洲精品超碰| 日韩一区二区三区免费观看| 在线观看视频一区| 91亚洲精品乱码久久久久久蜜桃| 久久精品久久精品| 欧美aaa在线| 视频在线在亚洲| 亚洲综合男人的天堂| 亚洲欧美偷拍另类a∨色屁股| 欧美国产亚洲另类动漫| 久久久国产精品麻豆 | 亚洲一级不卡视频| 国产精品久久毛片| 国产精品网站在线播放| 欧美成人性战久久| 欧美精品一区二区三区很污很色的 | 日韩主播视频在线| 中文字幕在线观看一区二区| 国产日韩欧美一区二区三区综合| 精品久久久久99| 精品成人在线观看| 国产日韩欧美高清在线| 久久久91精品国产一区二区精品 | 亚洲国产一区二区视频| 一区二区成人在线视频| 亚洲午夜久久久久久久久电影院 | 亚洲高清一区二区三区| 亚洲精品久久嫩草网站秘色| 国产精品成人午夜| 亚洲婷婷国产精品电影人久久| 国产精品美女久久久久aⅴ| 国产亚洲欧美日韩日本| 中文字幕亚洲在| 国产精品久久久99| 成人在线综合网| 成人h动漫精品一区二| 欧美在线影院一区二区| 欧美一区二区三区视频在线| 久久久久久久av麻豆果冻| 日韩一区二区在线看| 久久综合九色综合欧美98| 亚洲国产高清不卡| 亚洲狠狠爱一区二区三区| 美女被吸乳得到大胸91| 久久99精品国产麻豆婷婷洗澡| 国产成人免费视频精品含羞草妖精 | 日韩一本二本av| 欧美激情一区在线观看| 亚洲激情欧美激情| 久久成人免费网| 99re热这里只有精品视频| 91精品国产综合久久久久久久 | 免费欧美日韩国产三级电影| 国产二区国产一区在线观看| 欧美性欧美巨大黑白大战| 久久久久久9999| 婷婷一区二区三区| 99免费精品视频| 欧美大片顶级少妇| 亚洲在线中文字幕| 粉嫩在线一区二区三区视频| 色诱视频网站一区| 久久人人97超碰com| 丝袜亚洲精品中文字幕一区| 成人一区在线看| 精品国产一区二区三区忘忧草 | 一本色道久久综合狠狠躁的推荐| 日韩免费视频一区| 洋洋成人永久网站入口| 国产成人精品三级麻豆| 欧美一区二区三区视频在线观看| 亚洲男人的天堂av| 成人免费精品视频| 久久久久久日产精品| 日韩av电影免费观看高清完整版| 国产精品88888| 日韩欧美久久一区| 婷婷丁香久久五月婷婷| 91在线视频免费91| 亚洲欧洲性图库| 不卡av在线网| 2022国产精品视频| 91麻豆国产福利精品| 欧美va亚洲va| 免费视频最近日韩| 3d成人h动漫网站入口| 亚洲一区二区偷拍精品| av中文字幕不卡| 国产精品久久久久天堂| 国产乱码精品一区二区三| 久久色在线观看| 国产综合久久久久影院| 精品免费一区二区三区| 日韩中文字幕91| 欧美日韩另类国产亚洲欧美一级| 一区二区三区四区蜜桃| 91国偷自产一区二区三区成为亚洲经典| 国产日韩欧美不卡| av午夜精品一区二区三区| 亚洲婷婷国产精品电影人久久| 99久久国产综合色|国产精品| 国产精品久久久久久久浪潮网站 | 久久久亚洲午夜电影| 国产麻豆欧美日韩一区| 国产日产欧美一区二区视频| 国产成人午夜99999| 中文字幕 久热精品 视频在线 | 国产精品毛片大码女人| 99精品国产一区二区三区不卡| 亚洲欧美区自拍先锋| 色999日韩国产欧美一区二区| 一二三区精品福利视频| 91精品在线免费| 国产呦萝稀缺另类资源| 国产精品久久网站| 欧美无乱码久久久免费午夜一区 | 欧美日韩亚洲综合一区二区三区| 偷拍与自拍一区| 精品久久久久久久久久久久久久久久久 | 国产成人av一区二区| 久久久99精品免费观看不卡| 97久久超碰国产精品电影| 亚洲一二三区不卡| 久久在线观看免费| 一本久久综合亚洲鲁鲁五月天| 亚洲日本护士毛茸茸| 欧美高清精品3d| 国产精品一卡二卡在线观看| 高清成人免费视频| 一区二区三区在线免费观看| 日韩欧美一区在线观看| www.性欧美| 美腿丝袜亚洲三区| 亚洲欧洲国产日韩| 久久一区二区视频| 在线欧美小视频| 国产成人av电影在线| 人人狠狠综合久久亚洲| 日韩理论在线观看| 精品少妇一区二区三区在线播放| 91网站视频在线观看| 久久精品噜噜噜成人av农村| 亚洲免费av在线| 国产日韩欧美亚洲| 日韩欧美国产综合在线一区二区三区| 成人亚洲一区二区一| 奇米888四色在线精品| 亚洲免费高清视频在线| 久久婷婷国产综合精品青草| 欧美精三区欧美精三区| 99精品视频在线观看免费| 久久aⅴ国产欧美74aaa| 性久久久久久久| 中文字幕在线观看不卡视频| 精品久久久久久久久久久久久久久| 在线亚洲高清视频| 色综合视频一区二区三区高清| 国产一二精品视频| 奇米影视7777精品一区二区| 亚洲一区视频在线| 亚洲人成电影网站色mp4| 久久精品欧美日韩| 精品国产1区2区3区| 欧美一区二区三区在线电影| 91女人视频在线观看| 成人午夜精品在线| 国产91露脸合集magnet| 国产美女娇喘av呻吟久久| 久久国产乱子精品免费女| 日韩高清一区二区| 丝袜美腿亚洲色图| 亚洲福利一二三区| 亚洲h在线观看| 亚洲午夜久久久| 亚洲成人免费在线| 亚洲成人手机在线| 日日摸夜夜添夜夜添精品视频| 亚洲一区视频在线| 亚洲一区二区三区四区不卡| 亚洲影视资源网| 亚洲一级电影视频| 日本va欧美va精品发布| 天天色 色综合| 蜜臀久久99精品久久久久宅男 | 国产精品一区二区果冻传媒| 国产乱子伦一区二区三区国色天香| 老司机免费视频一区二区| 久久精品999| 国产精品一区二区无线| 成熟亚洲日本毛茸茸凸凹| 成人av手机在线观看| 91污片在线观看| 亚洲日本一区二区| 亚洲欧美日韩在线不卡| 亚洲成av人片观看| 日本亚洲免费观看| 国产老肥熟一区二区三区|