//--------- Begin of function Unit::unit_name ---------// // // [int] withTitle - whether return a string with the title of the unit // or not. (default: 1) // // [int] firstNameOnly - whether return the first word of the name only // (default: 0) // const char* Unit::unit_name(int withTitle, int firstNameOnly) { // static String str; UnitInfo* unitInfo = unit_res[unit_id]; //------------------------------------// if( race_id && unit_id != UNIT_WAGON ) { const char *baseName; if( hero_id ) baseName = hero_res[hero_id]->name; else if( rank_id == RANK_KING ) // use the player name baseName = nation_array[nation_recno]->king_name(firstNameOnly); else baseName = race_res[race_id]->get_name(name_id, firstNameOnly?1:0); if( withTitle ) { if( unit_mode == UNIT_MODE_REBEL ) { if( rank_id == RANK_GENERAL ) return text_unit.str_rebel_unit_titled( race_id, baseName, rank_id ); } else { if( rank_id != RANK_SOLDIER ) // human soldier has no "SOLIDER" has title return text_unit.str_unit_titled( race_id, baseName, rank_id ); } } return baseName; } else { int kingAnimal = 0; if (unitInfo->unit_class == UNIT_CLASS_ANIMAL && attack_count > 1) { AttackInfo *attackInfo = attack_info_array + 1; if (combat_level() >= attackInfo->combat_level) kingAnimal = 1; } return text_unit.str_non_race_unit_name( unitInfo->name, (unitInfo->class_info.has_weapon_version ? get_weapon_version() : 0), (unitInfo->unit_class != UNIT_CLASS_GOD ? name_id : 0), // don't put serial no. to god kingAnimal ); } // return str; }
void Unit::init_attack_info() { int techLevel; UnitInfo *unitInfo = unit_res[unit_id]; attack_count = unitInfo->attack_count; if( attack_count > 0 && unitInfo->first_attack > 0) attack_info_array = unit_res.attack_info_array+unitInfo->first_attack-1; else attack_info_array = NULL; // ####### begin Gilbert 24/3 ########// // if( unitInfo->unit_class == UNIT_CLASS_WEAPON && // (techLevel=get_weapon_version()) > 0 ) if( unitInfo->class_info.has_weapon_version && (techLevel=get_weapon_version()) > 0 ) // ####### end Gilbert 24/3 ########// { switch( unit_id ) { case UNIT_BALLISTA: //#ifdef AMPLUS case UNIT_F_BALLISTA: //#endif attack_count = 2; break; case UNIT_EXPLOSIVE_CART: attack_count = 0; break; case UNIT_M_CANNON: attack_count = 2; break; default: attack_count = 1; } if( attack_count > 0) { attack_info_array += (techLevel-1) * attack_count; } else { // no attack like explosive cart attack_info_array = NULL; } } }
//----------- Begin of function Unit::obj_power -----------// // // Return a power index of the weapon, this is for calculating // the total combat level of a target. // int Unit::obj_power() { UnitInfo* unitInfo = unit_res[unit_id]; // ##### begin Gilbert 24/3 #######// // if( unitInfo->unit_class == UNIT_CLASS_WEAPON ) if( !unitInfo->class_info.has_combat_level ) { // return (int) hit_points + (unitInfo->weapon_power + get_weapon_version() - 1) * 15; int power = (int)hit_points + unitInfo->weapon_power * 15; if( unitInfo->class_info.has_weapon_version ) power += (get_weapon_version() - 1) * 15; return power; } // ##### end Gilbert 24/3 #######// else { return (int) hit_points; } }
//--------- Begin of function Unit::pay_expense ---------// // void Unit::pay_expense() { if( game.game_mode == GAME_TEST ) // no deduction in testing game return; if( !nation_recno ) return; //--- if it's a mobile spy or the spy is in its own firm, no need to pay salary here as Spy::pay_expense() will do that ---// // // -If your spies are mobile: // >your nation pays them 1 food and $5 dollars per month // // -If your spies are in an enemy's town or firm: // >the enemy pays them 1 food and the normal salary of their jobs. // // >your nation pays them $5 dollars per month. (your nation pays them no food) // // -If your spies are in your own town or firm: // >your nation pays them 1 food and $5 dollars per month // //------------------------------------------------------// if( spy_recno ) { if( is_visible() ) // the cost will be deducted in spy_array return; if( unit_mode == UNIT_MODE_OVERSEE && firm_array[unit_mode_para]->nation_recno == true_nation_recno() ) { return; } } //---------- if it's a human unit -----------// // // The unit is paid even during its training period in a town // //-------------------------------------------// Nation* nationPtr = nation_array[nation_recno]; if( unit_res[unit_id]->race_id > 0 ) { if( rank_id != RANK_KING ) { //---------- reduce cash -----------// if( nationPtr->cash > 0 ) { if( rank_id == RANK_SOLDIER ) nationPtr->add_expense( EXPENSE_MOBILE_UNIT, (float) SOLDIER_YEAR_SALARY / 365, 1 ); if( rank_id == RANK_GENERAL ) nationPtr->add_expense( EXPENSE_GENERAL, (float) GENERAL_YEAR_SALARY / 365, 1 ); } //---------- reduce food -----------// if( nationPtr->food > 0 ) nationPtr->consume_food((float) UNIT_FOOD_YEAR_CONSUMPTION / 365); else { if( info.game_date%NO_FOOD_LOYALTY_DECREASE_INTERVAL == 0 ) // decrease 1 loyalty point every 2 days change_loyalty(-1); } } } else if( unit_res[unit_id]->is_monster() ) { //--- currently not cost for monsters ----// } else //----- it's a non-human unit ------// { if( nationPtr->cash > 0 ) { int expenseType; switch(unit_res[unit_id]->unit_class) { case UNIT_CLASS_WEAPON: expenseType = EXPENSE_WEAPON; break; case UNIT_CLASS_SHIP: err_here(); // expenseType = EXPENSE_SHIP; break; case UNIT_CLASS_CARAVAN: expenseType = EXPENSE_CARAVAN; break; default: expenseType = EXPENSE_MOBILE_UNIT; } nationPtr->add_expense( expenseType, (float) unit_res[unit_id]->year_cost / 365, 1 ); } else // decrease hit points if the nation cannot pay the unit { if( unit_res[unit_id]->unit_class != UNIT_CLASS_CARAVAN ) // Even when caravans are not paid, they still stay in your service. { if( hit_points > 0 ) { hit_points--; if( hit_points < 0 ) hit_points = (float) 0; //--- when the hit points drop to zero and the unit is destroyed ---// if( hit_points==0 ) { if( nation_recno == nation_array.player_recno ) { int unitClass = unit_res[unit_id]->unit_class; // ###### begin Gilbert 24/3 #######// if( unitClass==UNIT_CLASS_WEAPON || unitClass==UNIT_CLASS_MONS_WEAPON ) news_array.weapon_ship_worn_out(unit_id, get_weapon_version()); // ###### end Gilbert 24/3 #######// else if( unitClass==UNIT_CLASS_SHIP ) news_array.weapon_ship_worn_out(unit_id, 0); } } } } } } }