📄 aaibrain.cpp
字号:
else
{
// choose unit category dependend on map type
if(mapType == LAND_MAP)
{
// determine effectiveness vs several other units
anti_ground_urgency = (int)( 2 + (0.05f + bt->attacked_by_category[1][0][t]) * ground_usefulness * (2.0f * attacked_by[0] + 1.0f) * (4.0f * max_units_spotted[0] + 0.2f) / (4.0f * defence_power_vs[0] + 1));
anti_air_urgency = (int)( 2 + (0.05f + bt->attacked_by_category[1][1][t]) * air_usefulness * (2.0f * attacked_by[1] + 1.0f) * (4.0f * max_units_spotted[1] + 0.2f) / (4.0f * defence_power_vs[1] + 1));
anti_hover_urgency = (int)( 2 + (0.05f + bt->attacked_by_category[1][2][t]) * hover_usefulness * (2.0f * attacked_by[2] + 1.0f) * (4.0f * max_units_spotted[2] + 0.2f) / (4.0f * defence_power_vs[2] + 1));
for(int i = 0; i < execute->unitProductionRate; ++i)
{
ground_eff = 0;
air_eff = 0;
hover_eff = 0;
stat_eff = 0;
// determine unit type
if(rand()%(cfg->AIRCRAFT_RATE * 100) < 100)
{
category = AIR_ASSAULT;
k = rand()%1024;
if(k < 384)
{
ground_eff = 4;
hover_eff = 1;
}
else if(k < 640)
{
air_eff = 4;
}
else
{
stat_eff = 4;
}
}
else
{
// decide between hover and ground based on experience
if(rand()%((int)(ground_usefulness + hover_usefulness)) >= (int) ground_usefulness)
category = HOVER_ASSAULT;
else
category = GROUND_ASSAULT;
k = rand()%(anti_ground_urgency + anti_air_urgency + anti_hover_urgency);
if(k < anti_ground_urgency)
{
stat_eff = 2;
ground_eff = 5;
hover_eff = 1;
}
else if(k < anti_ground_urgency + anti_air_urgency)
{
air_eff = 4;
if(anti_air_urgency > 1.5 * anti_ground_urgency)
urgent = true;
}
else
{
ground_eff = 1;
hover_eff = 4;
}
}
BuildUnitOfCategory(category, cost, ground_eff, air_eff, hover_eff, sea_eff, submarine_eff,stat_eff, urgent);
}
// debug
/*fprintf(ai->file, "Selecting units: %i %i\n", k , anti_ground_urgency + anti_air_urgency + anti_hover_urgency);
fprintf(ai->file, "Selected: ground %f air %f hover %f\n", ground_eff, air_eff, hover_eff);
fprintf(ai->file, "Ground assault: %f %f %f %i \n", defence_power_vs[0], attacked_by[0], max_units_spotted[0], anti_ground_urgency);
fprintf(ai->file, "Air assault: %f %f %f %i \n", defence_power_vs[1], attacked_by[1], max_units_spotted[1], anti_air_urgency);
fprintf(ai->file, "Hover assault: %f %f %f %i \n", defence_power_vs[2], attacked_by[2], max_units_spotted[1], anti_hover_urgency);*/
}
else if(mapType == LAND_WATER_MAP)
{
// determine effectiveness vs several other units
anti_ground_urgency = (int)( 2 + (0.05f + bt->attacked_by_category[1][0][t]) * ground_usefulness * (2.0f * attacked_by[0] + 1.0f) * (4.0f * max_units_spotted[0] + 0.2f) / (4.0f * defence_power_vs[0] + 1));
anti_air_urgency = (int)( 2 + (0.05f + bt->attacked_by_category[1][1][t]) * air_usefulness * (2.0f * attacked_by[1] + 1.0f) * (4.0f * max_units_spotted[1] + 0.2f) / (4.0f * defence_power_vs[1] + 1));
anti_hover_urgency = (int)( 2 + (0.05f + bt->attacked_by_category[1][2][t]) * hover_usefulness * (2.0f * attacked_by[2] + 1.0f) * (4.0f * max_units_spotted[2] + 0.2f) / (4.0f * defence_power_vs[2] + 1));
anti_sea_urgency = (int) (2 + (0.05f + bt->attacked_by_category[1][3][t]) * sea_usefulness * (2.0f * attacked_by[3] + 1.0f) * (4.0f * max_units_spotted[3] + 0.2f) / (4.0f * defence_power_vs[3] + 1));
anti_submarine_urgency = (int)( 2 + (0.05f + bt->attacked_by_category[1][4][t]) * submarine_usefulness * (2.0f * attacked_by[4] + 1.0f) * (4.0f * max_units_spotted[4] + 0.2f) / (4.0f * defence_power_vs[4] + 1));
for(int i = 0; i < execute->unitProductionRate; ++i)
{
ground_eff = 0;
air_eff = 0;
hover_eff = 0;
sea_eff = 0;
submarine_eff = 0;
stat_eff = 0;
if(rand()%(cfg->AIRCRAFT_RATE * 100) < 100)
{
category = AIR_ASSAULT;
if(rand()%1000 < 333)
{
ground_eff = 4;
hover_eff = 1;
sea_eff = 2;
}
else if(rand()%1000 < 333)
{
air_eff = 4;
}
else
{
stat_eff = 4;
}
}
else
{
// decide between hover and ground based on experience
int random = rand()%((int)(ground_usefulness + hover_usefulness + sea_usefulness + submarine_usefulness));
if(random < (int) ground_usefulness )
{
category = GROUND_ASSAULT;
anti_submarine_urgency = 0;
}
else if(random < (int)(ground_usefulness + hover_usefulness))
{
category = HOVER_ASSAULT;
anti_submarine_urgency = 0;
}
else if(random < (int)(ground_usefulness + hover_usefulness + sea_usefulness))
{
category = SEA_ASSAULT;
anti_submarine_urgency = (int) (1 + submarine_usefulness * (attacked_by[4] + 2) * (max_units_spotted[4] + 2) / (defence_power_vs[4] + 1));
}
else
{
category = SUBMARINE_ASSAULT;
anti_submarine_urgency = (int) (1 + submarine_usefulness * (attacked_by[4] + 2) * (max_units_spotted[4] + 2) / (defence_power_vs[4] + 1));
}
k = rand()%(anti_ground_urgency + anti_air_urgency + anti_hover_urgency + anti_sea_urgency + anti_submarine_urgency);
if(k < anti_ground_urgency)
{
stat_eff = 2;
ground_eff = 5;
hover_eff = 1;
}
else if(k < anti_ground_urgency + anti_air_urgency)
{
air_eff = 4;
if(anti_air_urgency > anti_ground_urgency)
urgent = true;
}
else if(k < anti_ground_urgency + anti_air_urgency + anti_hover_urgency)
{
ground_eff = 1;
hover_eff = 4;
}
else if(k < anti_ground_urgency + anti_air_urgency + anti_hover_urgency + anti_sea_urgency)
{
hover_eff = 1;
sea_eff = 4;
}
else
{
submarine_eff = 4;
sea_eff = 1;
}
}
BuildUnitOfCategory(category, cost, ground_eff, air_eff, hover_eff, sea_eff, submarine_eff,stat_eff, urgent);
}
}
else if(mapType == WATER_MAP)
{
// determine effectiveness vs several other units
anti_air_urgency = (int)( 2 + (0.05f + bt->attacked_by_category[1][1][t]) * air_usefulness * (2.0f * attacked_by[1] + 1.0f) * (4.0f * max_units_spotted[1] + 0.2f) / (4.0f * defence_power_vs[1] + 1));
anti_hover_urgency = (int)( 2 + (0.05f + bt->attacked_by_category[1][2][t]) * hover_usefulness * (2.0f * attacked_by[2] + 1.0f) * (4.0f * max_units_spotted[2] + 0.2f) / (4.0f * defence_power_vs[2] + 1));
anti_sea_urgency = (int) (2 + (0.05f + bt->attacked_by_category[1][3][t]) * sea_usefulness * (2.0f * attacked_by[3] + 1.0f) * (4.0f * max_units_spotted[3] + 0.2f) / (4.0f * defence_power_vs[3] + 1));
anti_submarine_urgency = (int)( 2 + (0.05f + bt->attacked_by_category[1][4][t]) * submarine_usefulness * (2.0f * attacked_by[4] + 1.0f) * (4.0f * max_units_spotted[4] + 0.2f) / (4.0f * defence_power_vs[4] + 1));
for(int i = 0; i < execute->unitProductionRate; ++i)
{
air_eff = 0;
hover_eff = 0;
sea_eff = 0;
submarine_eff = 0;
stat_eff = 0;
if(rand()%(cfg->AIRCRAFT_RATE * 100) < 100)
{
category = AIR_ASSAULT;
anti_submarine_urgency = (int) (1 + submarine_usefulness * (attacked_by[4] + 2) * (max_units_spotted[4] + 2) / (defence_power_vs[4] + 1));
if(rand()%1000 < 333)
{
sea_eff = 4;
hover_eff = 2;
}
else if(rand()%1000 < 333)
{
air_eff = 4;
}
else
{
stat_eff = 4;
}
}
else
{
// decide between hover and ground based on experience
int random = rand()%((int)(hover_usefulness + sea_usefulness + submarine_usefulness));
if(random < (int)(hover_usefulness))
{
category = HOVER_ASSAULT;
anti_submarine_urgency = 0;
}
else if(random < (int)(hover_usefulness + sea_usefulness))
{
category = SEA_ASSAULT;
anti_submarine_urgency = (int) (1 + submarine_usefulness * (attacked_by[4] + 2) * (max_units_spotted[4] + 2) / (defence_power_vs[4] + 1));
}
else
{
category = SUBMARINE_ASSAULT;
anti_submarine_urgency = (int) (1 + submarine_usefulness * (attacked_by[4] + 2) * (max_units_spotted[4] + 2) / (defence_power_vs[4] + 1));
}
k = rand()%(anti_sea_urgency + anti_air_urgency + anti_hover_urgency + anti_submarine_urgency);
if(k < anti_air_urgency)
{
air_eff = 4;
if(anti_air_urgency > anti_sea_urgency)
urgent = true;
}
else if(k < anti_hover_urgency + anti_air_urgency)
{
sea_eff = 1;
hover_eff = 5;
stat_eff = 2;
}
else if(k < anti_hover_urgency + anti_air_urgency + anti_submarine_urgency)
{
submarine_eff = 4;
sea_eff = 1;
}
else
{
hover_eff = 1;
sea_eff = 5;
stat_eff = 2;
}
}
BuildUnitOfCategory(category, cost, ground_eff, air_eff, hover_eff, sea_eff, submarine_eff,stat_eff, urgent);
}
}
else if(mapType == AIR_MAP)
{
category = AIR_ASSAULT;
if(rand()%3 == 1)
{
air_eff = 0.5;
stat_eff = 4;
}
else
{
air_eff = 4;
stat_eff = 0.5;
}
BuildUnitOfCategory(category, cost, ground_eff, air_eff, hover_eff, sea_eff, submarine_eff,stat_eff, urgent);
}
}
}
void AAIBrain::BuildUnitOfCategory(UnitCategory category, float cost, float ground_eff, float air_eff, float hover_eff, float sea_eff, float submarine_eff, float stat_eff, bool urgent)
{
float speed = 0;
float range = 0;
float power = 2;
float eff = 2;
if(category != UNKNOWN)
{
// determine speed, range & eff
if(rand()%cfg->FAST_UNITS_RATE == 1)
{
if(rand()%2 == 1)
speed = 1;
else
speed = 2;
}
else
speed = 0.1f;
if(rand()%cfg->HIGH_RANGE_UNITS_RATE == 1)
{
int t = rand()%1000;
if(t < 350)
range = 0.75;
else if(t == 700)
range = 1.3f;
else
t = 1.7f;
}
else
range = 0.1f;
if(rand()%3 == 1)
power = 4;
if(rand()%3 == 1)
eff = 4;
execute->BuildUnit(category, speed, cost, range, power, ground_eff, air_eff, hover_eff, sea_eff, submarine_eff, stat_eff, eff, urgent);
}
}
int AAIBrain::GetGamePeriod()
{
int tick = cb->GetCurrentFrame();
if(tick < 18000)
return 0;
else if(tick < 36000)
return 1;
else if(tick < 72000)
return 2;
else
return 3;
}
bool AAIBrain::IsSafeSector(AAISector *sector)
{
// TODO: improve criteria
if(sector->enemy_structures <= 0 && sector->lost_units[MOBILE_CONSTRUCTOR-COMMANDER] < 1 && sector->threat <= 0)
return true;
else
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -