double GoalSally::Action_Bid(AiMain *ai, Agent *agent) { ArmyAgent *army_agent = (ArmyAgent *)agent; CityAgent *city_agent = (CityAgent *)agent; if (agent->GetType() == AGENT_TYPE_CITY) return city_agent->FindBestBuildUtility(ai,this,army_agent); if (!PretestBid(ai, army_agent)) return BAD_UTILITY; if (army_agent->GetState() == AGENT_STATE_UNBUILT) { if (army_agent->GetHomeCityAgent()->GetQueueLen() > 0) return BAD_UTILITY; } double move_point_cost; sint32 rounds; double build_time; if (army_agent->BidDistance(ai, FALSE, *m_pos, move_point_cost, rounds, build_time) < 0.0) { return BAD_UTILITY; } double bonuses = 0.0; sint32 best_attack; sint32 my_attack = army_agent->GetBestAttack(ai); if (ai->m_science_agent->GetBestLandAttack(best_attack)) bonuses += (1.0 - (my_attack / best_attack)) * ai->m_planner->the_AIP.max_misc_bid_bonus; else ; double time_term; MapPointData dest_pos; army_agent->GetPos(ai, dest_pos); double tile_count = ai->m_map->WrappedDistance(*m_pos, dest_pos); time_term = ( rounds * rounds * ai->m_planner->the_AIP.distance_from_unit_priority_modifier ) - tile_count; return bonuses + time_term + Compute_Raw_Priority(ai); }
int GoalSally::Is_Unit_Appropriate ( AiMain *ai, Agent * unit_in_question ) { AGENT_STATE agent_state; AGENT_TYPE agent_type; ArmyAgent * the_army; CityAgent * the_city; agent_type = unit_in_question->GetType(); switch (agent_type) { case AGENT_TYPE_ARMY: { the_army = (ArmyAgent *) unit_in_question; if (!PretestBid(ai, the_army)) return FALSE; if (the_army->IsWounded()) return false; if (the_army->IsInCity(ai, the_city) && ArmyGoal::PretestUnitTypes(ai, the_army, GOAL_TYPE_DEFENSE)) { sint32 units_in_city = (sint32) the_city->GetGarrisonCount(); Assert(the_city); MapPointData pos; the_city->GetPos(pos); if (!(pos == *m_pos)) { if (units_in_city - the_army->GetNUnits() < ai->m_planner->the_AIP.num_city_defenders || units_in_city - the_army->GetNUnits() < the_city->GetMinSlaveGarrison()) return FALSE; } } agent_state = the_army->GetState(); switch (agent_state) { case AGENT_STATE_MARKED_SETTLE: case AGENT_STATE_MARKED_DEAD: case AGENT_STATE_MARKED_GARRISON: case AGENT_STATE_AT_GOAL: return false; default: return true; } break; } break; case AGENT_TYPE_CITY: { the_city = (CityAgent *) unit_in_question; if (the_city->GetQueueLen() > 0) return true; else return false; break; } default: return false; } }
double GoalBombard::Action_Bid(AiMain *ai, Agent *agent) { ArmyAgent *army_agent = (ArmyAgent *)agent; CityAgent *city_agent = (CityAgent *)agent; if (agent->GetType() == AGENT_TYPE_CITY) return city_agent->FindBestBuildUtility(ai,this,army_agent); if (!PretestBid(ai, army_agent)) return BAD_UTILITY; if (army_agent->GetState() == AGENT_STATE_UNBUILT) { if (army_agent->GetHomeCityAgent()->GetQueueLen() > 0) return BAD_UTILITY; } double move_point_cost; sint32 rounds; MapPointData army_pos; army_agent->GetPos(ai, army_pos); MapPointData ignore_space = *m_pos; ignore_space.z = army_pos.z; double build_time; if (army_agent->BidDistance(ai, FALSE, ignore_space, move_point_cost, rounds, build_time) < 0.0) { return BAD_UTILITY; } if (ai->m_my_player_id == PLAYER_INDEX_VANDALS && rounds > ai->m_planner->the_AIP.wander_rounds_from_target) return BAD_UTILITY; double high_movement_weight = 0.5; double high_attack_weight = 0.5; double bonuses = 0.0; sint32 best_attack; sint32 my_attack = army_agent->GetBestAttack(ai); if (ai->m_science_agent->GetBestLandAttack(best_attack)) { bonuses += (my_attack / best_attack) * ai->m_planner->the_AIP.max_misc_bid_bonus * high_attack_weight; } else ; sint32 best_move; double my_move = army_agent->GetBestMove(ai); if (ai->m_science_agent->GetBestLandMove(best_move)) bonuses += (my_move / best_move) * ai->m_planner->the_AIP.max_misc_bid_bonus * high_movement_weight; else ; double time_term; MapPointData dest_pos; army_agent->GetPos(ai, dest_pos); double tile_count = ai->m_map->WrappedDistance(*m_pos, dest_pos); time_term = ( rounds * rounds * ai->m_planner->the_AIP.distance_from_unit_priority_modifier ) - tile_count; return bonuses + time_term + Compute_Raw_Priority(ai); }
double GoalMapTarget::Action_Bid(AiMain *ai, Agent *agent) { ArmyAgent *army_agent = (ArmyAgent *)agent; CityAgent *city_agent = (CityAgent *)agent; BOOL ASSERT_MAP_TARGET_INVALID = 0; if (agent->GetType() == AGENT_TYPE_CITY) return city_agent->FindBestBuildUtility(ai,this,army_agent); if (army_agent->IsWounded()) return BAD_UTILITY; if (!PretestBid(ai, army_agent)) return BAD_UTILITY; if (GetType() == GOAL_TYPE_TRANSPORT) return Compute_Raw_Priority(ai); if (army_agent->GetState() == AGENT_STATE_UNBUILT) { if (army_agent->GetHomeCityAgent()->GetQueueLen() > 0) return BAD_UTILITY; } double move_point_cost; sint32 rounds; double build_time; if (army_agent->BidDistance(ai, FALSE, *m_pos, move_point_cost, rounds, build_time) < 0.0) { return BAD_UTILITY; } if (ai->my_player_index == PLAYER_INDEX_VANDALS && rounds > ai->m_planner->the_AIP.wander_rounds_from_target && GetType() != GOAL_TYPE_WANDER) return BAD_UTILITY; double high_movement_weight; double low_defense_weight; double high_defense_weight; double high_attack_weight; double bonus = 0.0; switch (GetType()) { case GOAL_TYPE_PILLAGE: case GOAL_TYPE_PIRATE: case GOAL_TYPE_PROBE_WORMHOLE: high_movement_weight = 0.75; low_defense_weight = 0.25; high_defense_weight = 0.0; high_attack_weight = 0.0; break; case GOAL_TYPE_WANDER: case GOAL_TYPE_COUNTER_STEALTH: case GOAL_TYPE_BONUS_FOOD: case GOAL_TYPE_GOODY_HUT: high_movement_weight = 1.0; low_defense_weight = 0.0; high_defense_weight = 0.0; high_attack_weight = 0.0; break; case GOAL_TYPE_CHOKEPOINT: high_movement_weight = 0.0; low_defense_weight = 0.0; high_defense_weight = 0.75; high_attack_weight = 0.25; break; default: Assert(ASSERT_MAP_TARGET_INVALID); } sint32 best_defense; sint32 my_defense = army_agent->GetBestDefense(ai); if (ai->m_science_agent->GetBestLandDefense(best_defense)) { bonus += (1.0 - (my_defense / best_defense)) * ai->m_planner->the_AIP.max_misc_bid_bonus * low_defense_weight; } else ; sint32 best_move; double my_move = army_agent->GetBestMove(ai); if (ai->m_science_agent->GetBestLandMove(best_move)) bonus += (my_move / best_move) * ai->m_planner->the_AIP.max_misc_bid_bonus * high_movement_weight; else ; if (ai->m_science_agent->GetBestLandDefense(best_defense)) { bonus += (my_defense / best_defense) * ai->m_planner->the_AIP.max_misc_bid_bonus * high_defense_weight; } else ; sint32 best_attack; sint32 my_attack = army_agent->GetBestAttack(ai); if (ai->m_science_agent->GetBestLandAttack(best_attack)) { if(best_attack == 0) { best_attack = 1; } bonus += (my_attack / best_attack) * ai->m_planner->the_AIP.max_misc_bid_bonus * high_attack_weight; } else ; double time_term; MapPointData dest_pos; army_agent->GetPos(ai, dest_pos); double tile_count = ai->m_map->WrappedDistance(*m_pos, dest_pos); time_term = ( rounds * rounds * ai->m_planner->the_AIP.distance_from_unit_priority_modifier ) - tile_count; return bonus + time_term + Compute_Raw_Priority(ai); }
int GoalBombard::Is_Unit_Appropriate ( AiMain *ai, Agent * unit_in_question ) { AGENT_STATE agent_state; AGENT_TYPE agent_type; ArmyAgent * the_army; CityAgent * the_city; if (!ArmyGoal::Is_Unit_Appropriate(ai, unit_in_question)) return FALSE; agent_type = unit_in_question->GetType(); switch (agent_type) { case AGENT_TYPE_ARMY: { the_army = (ArmyAgent *) unit_in_question; if (!PretestBid(ai, the_army)) return FALSE; Assert(attacking_squad); if (!attacking_squad) return FALSE; if (attacking_squad->GetUnitCount() > 1 && (attacking_squad->GetMoveTypes(ai) & the_army->GetMoveIntersection(ai)) == 0x0) return FALSE; agent_state = the_army->GetState(); switch (agent_state) { case AGENT_STATE_MARKED_SETTLE: case AGENT_STATE_MARKED_DEAD: case AGENT_STATE_MARKED_GARRISON: case AGENT_STATE_AT_GOAL: return FALSE; default: return TRUE; } break; } break; case AGENT_TYPE_CITY: { the_city = (CityAgent *) unit_in_question; if (the_city->GetQueueLen() > 0) return TRUE; else return FALSE; break; } default: return FALSE; } }