|
@@ -3893,111 +3893,93 @@ static void AiAdjustLoan(Player *p)
|
|
|
if (p->player_money > base * 1400) {
|
|
|
// Decrease loan
|
|
|
if (p->current_loan != 0) {
|
|
|
DoCommandByTile(0, 0, 0, DC_EXEC, CMD_DECREASE_LOAN);
|
|
|
}
|
|
|
} else if (p->player_money < base * 500) {
|
|
|
// Increase loan
|
|
|
if (p->current_loan < _economy.max_loan &&
|
|
|
p->num_valid_stat_ent >= 2 &&
|
|
|
-(p->old_economy[0].expenses+p->old_economy[1].expenses) < base * 60) {
|
|
|
DoCommandByTile(0, 0, 0, DC_EXEC, CMD_INCREASE_LOAN);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void AiBuildCompanyHQ(Player *p)
|
|
|
{
|
|
|
TileIndex tile;
|
|
|
|
|
|
if (p->location_of_house == 0 &&
|
|
|
p->last_build_coordinate != 0) {
|
|
|
tile = AdjustTileCoordRandomly(p->last_build_coordinate, 8);
|
|
|
DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void AiDoGameLoop(Player *p)
|
|
|
{
|
|
|
_cur_ai_player = p;
|
|
|
|
|
|
if (p->bankrupt_asked != 0) {
|
|
|
AiHandleTakeover(p);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// Ugly hack to make sure the service interval of the AI is good, not looking
|
|
|
// to the patch-setting
|
|
|
// Also, it takes into account the setting if the service-interval is in days
|
|
|
// or in %
|
|
|
_ai_service_interval = _patches.servint_ispercent?80:180;
|
|
|
|
|
|
if (IS_HUMAN_PLAYER(_current_player))
|
|
|
return;
|
|
|
|
|
|
AiAdjustLoan(p);
|
|
|
AiBuildCompanyHQ(p);
|
|
|
|
|
|
if (_opt.diff.competitor_speed == 4) {
|
|
|
/* ultraspeed */
|
|
|
_ai_actions[p->ai.state](p);
|
|
|
if (p->bankrupt_asked != 0)
|
|
|
return;
|
|
|
} else if (_opt.diff.competitor_speed != 3) {
|
|
|
p->ai.tick++;
|
|
|
if (!(p->ai.tick&1))
|
|
|
return;
|
|
|
if (_opt.diff.competitor_speed != 2) {
|
|
|
if (!(p->ai.tick&2))
|
|
|
return;
|
|
|
if (_opt.diff.competitor_speed == 0) {
|
|
|
if (!(p->ai.tick&4))
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#if 0
|
|
|
{
|
|
|
static byte old_state = 99;
|
|
|
static bool hasdots = false;
|
|
|
char *_ai_state_names[]={
|
|
|
"AiCase0",
|
|
|
"AiCase1",
|
|
|
"AiStateVehLoop",
|
|
|
"AiStateCheckReplaceVehicle",
|
|
|
"AiStateDoReplaceVehicle",
|
|
|
"AiStateWantNewRoute",
|
|
|
"AiStateBuildDefaultRailBlocks",
|
|
|
"AiStateBuildRail",
|
|
|
"AiStateBuildRailVeh",
|
|
|
"AiStateDeleteRailBlocks",
|
|
|
"AiStateBuildDefaultRoadBlocks",
|
|
|
"AiStateBuildRoad",
|
|
|
"AiStateBuildRoadVehicles",
|
|
|
"AiStateDeleteRoadBlocks",
|
|
|
"AiStateAirportStuff",
|
|
|
"AiStateBuildDefaultAirportBlocks",
|
|
|
"AiStateBuildAircraftVehicles",
|
|
|
"AiStateCheckShipStuff",
|
|
|
"AiStateBuildDefaultShipBlocks",
|
|
|
"AiStateDoShipStuff",
|
|
|
"AiStateSellVeh",
|
|
|
"AiStateRemoveStation",
|
|
|
"AiStateRemoveTrack",
|
|
|
"AiStateRemoveSingleRailTile"
|
|
|
};
|
|
|
|
|
|
if (p->ai.state != old_state) {
|
|
|
if (hasdots)
|
|
|
printf("\n");
|
|
|
hasdots=false;
|
|
|
printf("AiState: %s\n", _ai_state_names[old_state=p->ai.state]);
|
|
|
} else {
|
|
|
printf(".");
|
|
|
hasdots=true;
|
|
|
}
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
_ai_actions[p->ai.state](p);
|
|
|
}
|