Skip to content

Commit

Permalink
implemented smarter general/admiral score calculation, it now ignores…
Browse files Browse the repository at this point in the history
… +defence in the calculation if you are attacking, and vice verca.
  • Loading branch information
ZombieFreak115 committed Feb 1, 2025
1 parent 82e4b73 commit 5e34b65
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/military/military.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4838,18 +4838,25 @@ dcon::nation_id get_land_battle_lead_defender(sys::state& state, dcon::land_batt
return dcon::nation_id{};
}

float get_leader_select_score(sys::state& state, dcon::leader_id l) {
float get_leader_select_score(sys::state& state, dcon::leader_id l, bool is_attacking) {
/*
- Each side has a leader that is in charge of the combat, which is the leader with the greatest
value as determined by the following formula: (organization x 5 + attack + defend + morale +
speed + attrition + experience / 2 + reconnaissance / 5 + reliability / 5) x (prestige + 1)
*/
auto per = state.world.leader_get_personality(l);
auto bak = state.world.leader_get_background(l);
//
// atk and def are both set to 0 initally, and will be set to its actual amount depending if on the on_attacking input param
// this makes it so for example if the leader is attacking, it will disregard all "defence" stats for the purposes of calculating the score
float atk = 0.f;
float def = 0.f;
auto org = state.world.leader_trait_get_organisation(per) + state.world.leader_trait_get_organisation(bak);
auto atk = state.world.leader_trait_get_attack(per) + state.world.leader_trait_get_attack(bak);
auto def = state.world.leader_trait_get_defense(per) + state.world.leader_trait_get_defense(bak);
if(is_attacking) {
atk = state.world.leader_trait_get_attack(per) + state.world.leader_trait_get_attack(bak);
}
else {
def = state.world.leader_trait_get_defense(per) + state.world.leader_trait_get_defense(bak);
}
auto spd = state.world.leader_trait_get_speed(per) + state.world.leader_trait_get_speed(bak);
auto mor = state.world.leader_trait_get_morale(per) + state.world.leader_trait_get_morale(bak);
auto att = state.world.leader_trait_get_experience(per) + state.world.leader_trait_get_experience(bak);
Expand Down Expand Up @@ -4925,7 +4932,7 @@ void update_battle_leaders(sys::state& state, dcon::land_battle_id b) {
continue;
}
bool is_attacking = is_attacker_in_battle(state, a.get_army());
auto score = get_leader_select_score(state, l);
auto score = get_leader_select_score(state, l, is_attacking);
/*if(a.get_army().get_controller_from_army_control() == la) {*/
if(is_attacking) {
if(score > a_score) {
Expand Down Expand Up @@ -4960,7 +4967,7 @@ void update_battle_leaders(sys::state& state, dcon::naval_battle_id b) {
continue;
}
bool is_attacking = is_attacker_in_battle(state, a.get_navy());
auto score = get_leader_select_score(state, l);
auto score = get_leader_select_score(state, l, is_attacking);
if(is_attacking) {
if(score > a_score) {
a_lid = l;
Expand Down

0 comments on commit 5e34b65

Please sign in to comment.