void Unit::init_unit_id(int unitId) { unit_id = unitId; UnitInfo* unitInfo = unit_res[unit_id]; sprite_id = unitInfo->sprite_id; sprite_info = sprite_res[sprite_id]; mobile_type = unitInfo->mobile_type; // #### begin Gilbert 6/11 ######// defense_attribute = unitInfo->defense_attribute; // #### end Gilbert 6/11 ######// //--- if this unit is a weapon unit with multiple versions ---// int techLevel; if( nation_recno && // ##### begin Gilbert 24/3 ########// //unitInfo->unit_class == UNIT_CLASS_WEAPON ) unitInfo->class_info.has_weapon_version ) // ##### end Gilbert 24/3 ########// { techLevel=unitInfo->nation_tech_level_array[nation_recno-1]; if (techLevel == 0) set_weapon_version(1); else set_weapon_version(techLevel); } init_attack_info(); //-------- set unit count ----------// if( nation_recno ) { if( rank_id != RANK_KING ) unitInfo->inc_nation_unit_count(nation_recno); if( rank_id == RANK_GENERAL ) unitInfo->inc_nation_general_count(nation_recno); } //--------- increase monster count ----------// // ##### begin Gilbert 24/3 #######// // if( unit_res[unit_id]->unit_class == UNIT_CLASS_MONSTER ) if( unit_res[unit_id]->class_info.monster_side ) unit_res.mobile_monster_count++; // ##### end Gilbert 24/3 #######// }
//--------- Begin of function Unit::set_rank ---------// // // Only if the unit has leadership skill, it can be a general or king. // void Unit::set_rank(int rankId) { err_when( !race_id ); if( rank_id == rankId ) return; err_when( unit_mode != UNIT_MODE_REBEL && rankId >= RANK_GENERAL && is_civilian() ); //------- promote --------// if( rankId > rank_id ) change_loyalty(PROMOTE_LOYALTY_INCREASE); //------- demote -----------// else if( rankId < rank_id && rank_id != RANK_KING ) // no decrease in loyalty if a spy king hands his nation to his parent nation and become a general again change_loyalty(-DEMOTE_LOYALTY_DECREASE); //---- update nation_general_count_array[] ----// if( nation_recno ) { UnitInfo* unitInfo = unit_res[unit_id]; if( rank_id == RANK_GENERAL ) // if it was a general originally unitInfo->dec_nation_general_count(nation_recno); if( rankId == RANK_GENERAL ) // if the new rank is general unitInfo->inc_nation_general_count(nation_recno); //------ if demote a king to a unit ------// if( rank_id == RANK_KING && rankId != RANK_KING ) unitInfo->inc_nation_unit_count(nation_recno); // since kings are not included in nation_unit_count, when it is no longer a king, we need to re-increase it. //------ if promote a unit to a king ------// if( rank_id != RANK_KING && rankId == RANK_KING ) unitInfo->dec_nation_unit_count(nation_recno); // since kings are not included in nation_unit_count, we need to decrease it } //----- reset leader_unit_recno if demote a general to soldier ----// if( rank_id == RANK_GENERAL && rankId == RANK_SOLDIER ) { //----- reset leader_unit_recno of the units he commands ----// for( int i=unit_array.size() ; i>0 ; i-- ) { Unit* unitPtr = (Unit*) unit_array.get_ptr(i); // don't use is_deleted() as it filters out units that are currently dying if( unitPtr && unitPtr->leader_unit_recno == sprite_recno ) { unitPtr->leader_unit_recno = 0; // unitPtr->team_id = 0; } } //--------- deinit team_info ---------// err_when( !team_info ); mem_del(team_info); team_info = NULL; // team_id = 0; } //----- if this is a soldier being promoted to a general -----// else if( rank_id == RANK_SOLDIER && rankId == RANK_GENERAL ) { //-- if this soldier is formerly commanded by a general, detech it ---// if( leader_unit_recno ) { if( !unit_array.is_deleted(leader_unit_recno) ) // the leader unit may have been killed at the same time { err_when( !unit_array[leader_unit_recno]->team_info ); unit_array[leader_unit_recno]->team_info->del_member(sprite_recno); } leader_unit_recno = 0; } } // ###### patch begin Gilbert 27/9 #######// // ------- clear royal in campaign mode -----// if( rankId == RANK_KING ) { is_royal = 0; } // ###### patch end Gilbert 27/9 #######// //-------------- update AI info --------------// if( nation_recno ) { if( rank_id == RANK_GENERAL || rank_id == RANK_KING ) nation_array[nation_recno]->del_general_info(sprite_recno); rank_id = rankId; if( rank_id == RANK_GENERAL || rank_id == RANK_KING ) nation_array[nation_recno]->add_general_info(sprite_recno); } else { rank_id = rankId; } //----- if this is a general/king ------// if( rank_id == RANK_GENERAL || rank_id == RANK_KING ) { //--------- init team_info -------// if( !team_info ) { team_info = (TeamInfo*) mem_add( sizeof(TeamInfo) ); memset( team_info, 0, sizeof(TeamInfo) ); } //--- set leadership if this unit does not have any now ----// if( skill_level() < 10 ) skill.set_skill_level( + m.random(40) ); } //------ refresh if the current unit is selected -----// if( unit_array.selected_recno == sprite_recno ) info.disp(); }