double Squad::ScoreTransportUtility(AiMain *ai, ArmyAgent *transport) { double max_score = BAD_UTILITY; double tmp_score; sint32 agent_idx, agent_num; Agent *agent = NULL; ArmyAgent *army_agent = NULL; agent_num = my_agents.count; for (agent_idx = agent_num-1; 0 <= agent_idx; agent_idx--) { agent = (Agent*)my_agents.Return_Data_By_Number(agent_idx); if (agent->GetType() != AGENT_TYPE_ARMY) continue; army_agent = (ArmyAgent*) agent; tmp_score = army_agent->EstimateTransportUtility(ai, transport); if (tmp_score > max_score) max_score = tmp_score; } return max_score; }
void Squad::UngroupAllArmies(AiMain *ai) { sint32 agent_idx, agent_num; Agent *agent = NULL; ArmyAgent *army_agent = NULL; BOOL is_unknown_id; agent_num = my_agents.count; for (agent_idx = agent_num-1; 0 <= agent_idx; agent_idx--) { agent = (Agent*)my_agents.Return_Data_By_Number(agent_idx); if (agent->GetType() != AGENT_TYPE_ARMY) continue; army_agent = (ArmyAgent*) agent; if ((army_agent->GetNUnits() > 1) && (army_agent->GetState() != AGENT_STATE_MARKED_DEAD)) { Assert(army_agent->GetID().GetVal() != 0); ai->m_player->ArmyUngroup(army_agent->GetID().GetVal(), &is_unknown_id); Assert(!is_unknown_id); } } }
sint32 Squad::GetUsableTransport(AiMain *ai) { sint32 agent_idx, agent_num; Agent *agent = NULL; ArmyAgent *army_agent = NULL; sint32 total_empty = 0; sint32 empty, full; agent_num = my_agents.count; for (agent_idx = agent_num-1; 0 <= agent_idx; agent_idx--) { agent = (Agent*)my_agents.Return_Data_By_Number(agent_idx); if (agent->GetType() == AGENT_TYPE_ARMY) { army_agent = (ArmyAgent *) agent; if (army_agent->GetMovePoints() >= MINIMUM_MOVEMENT_POINTS_TO_MOVE && !army_agent->IsWaitState()) { if (army_agent->GetNumCargo(ai, full, empty)) total_empty += empty; } } } return total_empty; }
void Squad::GroupWithArmy(AiMain *ai, ArmyAgent *army_agent) { sint32 agent_idx, agent_num; Agent *agent = NULL; ArmyAgent *grouped_agent = NULL; BOOL is_unknown_id; MapPointData army_pos; MapPointData grouped_pos; agent_num = my_agents.count; army_agent->GetPos(ai,army_pos); Assert(army_agent->GetState() != AGENT_STATE_MARKED_DEAD); if (army_agent->GetState() == AGENT_STATE_MARKED_DEAD) return; for (agent_idx = agent_num-1; 0 <= agent_idx; agent_idx--) { agent = (Agent*)my_agents.Return_Data_By_Number(agent_idx); if (agent->GetType() == AGENT_TYPE_ARMY) { grouped_agent = (ArmyAgent *) agent; Assert(grouped_agent->GetState() != AGENT_STATE_MARKED_DEAD); if (grouped_agent->GetState() == AGENT_STATE_MARKED_DEAD) continue; grouped_agent->GetPos(ai,grouped_pos); if (grouped_agent->GetID().GetVal() != army_agent->GetID().GetVal() && grouped_pos.x == army_pos.x && grouped_pos.y == army_pos.y && grouped_pos.z == army_pos.z) { Remove_Agent(grouped_agent); ai->m_player->ArmyGroup(grouped_agent->GetID().GetVal(), army_agent->GetID().GetVal(), &is_unknown_id); Assert(!is_unknown_id); if (!is_unknown_id) { grouped_agent->m_has_been_executed = TRUE; grouped_agent->SetState(AGENT_STATE_MARKED_DEAD); } } } } }
BOOL Squad::Ok_To_Rally(AiMain *ai) { sint32 agent_idx, agent_num; Agent *agent = NULL; ArmyAgent *army_agent = NULL; sint32 dest_cont; BOOL dest_is_land; MapPointData pos; sint32 num_in_water = 0; sint32 num_at_dest = 0; agent_num = my_agents.count; ArmyGoal *army_goal = (ArmyGoal*) my_strategic_goal; army_goal->GetPos(pos); if(pos.z == SPACE_Z) return TRUE; BOOL r = ai->m_continents->GetContinent(ai, pos, dest_cont, dest_is_land); Assert(r); if (!dest_is_land) return TRUE; for (agent_idx = agent_num-1; 0 <= agent_idx; agent_idx--) { agent = (Agent*)my_agents.Return_Data_By_Number(agent_idx); if (agent->GetType() != AGENT_TYPE_ARMY) continue; army_agent = (ArmyAgent*) agent; if ((army_agent->GetNUnits() > 0) && (army_agent->GetState() != AGENT_STATE_MARKED_DEAD)) { if ((army_agent->GetContinent() != dest_cont) && (army_agent->GetMyIsLand())) return FALSE; if (!army_agent->GetMyIsLand()) num_in_water++; else if (army_agent->GetContinent() == dest_cont) num_at_dest++; } } return (agent_num == (num_in_water + num_at_dest)); }
sint32 Squad::GetTransportUnitsCount(AiMain *ai) { sint32 my_transports = 0; Agent *agent; for (sint32 i = 0; i < my_agents.count; i++) { agent = (Agent *) my_agents.Return_Data_By_Number( i ); if (agent->GetType() != AGENT_TYPE_CITY) my_transports += ((ArmyAgent*) agent)->GetTransports(ai); } return my_transports; }
int Goal_Attack_Region::Get_Totally_Complete(AiMain *ai) { int i; int completely_there_count = 0; Agent *agent = NULL; ArmyAgent *aa=NULL; MapPointData army_pos; if (attacking_squad == NULL) return false; for (i=0; i < attacking_squad->my_agents.count; i++) { agent = (Agent *) attacking_squad->my_agents.Return_Data_By_Number(i); if (agent->GetType() == AGENT_TYPE_ARMY) { aa = (ArmyAgent *) agent; if (aa->GetState() == AGENT_STATE_MARKED_DEAD) { continue; } aa->GetPos(ai, army_pos); if ((m_pos->x == army_pos.x) && (m_pos->y == army_pos.y) && (m_pos->z == army_pos.z) ) { completely_there_count++; } } } Set_Totally_Complete(completely_there_count == attacking_squad->my_agents.count); return m_is_completed; }
uint32 Squad::GetMoveTypes(AiMain *ai) { if (m_moveType) return m_moveType; Agent *agent; ArmyAgent *army_agent; for (sint32 i = 0; i < my_agents.count; i++) { agent = (Agent *) my_agents.Return_Data_By_Number( i ); if (agent->GetType() != AGENT_TYPE_CITY) { army_agent = (ArmyAgent *)agent; m_moveType |= army_agent->GetMoveIntersection(ai); } } return m_moveType; }
double Squad::GetUsableDefense(AiMain *ai) { sint32 agent_idx, agent_num; Agent *agent = NULL; ArmyAgent *army_agent = NULL; double total_defense = 0.0; agent_num = my_agents.count; for (agent_idx = agent_num-1; 0 <= agent_idx; agent_idx--) { agent = (Agent*)my_agents.Return_Data_By_Number(agent_idx); if (agent->GetType() == AGENT_TYPE_ARMY) { army_agent = (ArmyAgent *) agent; if (army_agent->GetMovePoints() >= MINIMUM_MOVEMENT_POINTS_TO_MOVE && !army_agent->IsWaitState()) total_defense += army_agent->GetDefenseStrength(); } } return total_defense; }