本文整理汇总了C++中Nation::add_expense方法的典型用法代码示例。如果您正苦于以下问题:C++ Nation::add_expense方法的具体用法?C++ Nation::add_expense怎么用?C++ Nation::add_expense使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nation
的用法示例。
在下文中一共展示了Nation::add_expense方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process_repair
//---------- Begin of function Firm::process_repair --------//
//
void Firm::process_repair()
{
if( repair_flag && hit_points < max_hit_points()
&& info.game_date > last_attack_date+1 ) // can only do construction when the firm is not under attack //
{
if( nation_recno )
{
Nation* nationPtr = nation_array[nation_recno];
float repairCost = (float) firm_res[firm_id]->setup_cost
* REPAIR_POINTS_PER_DAY / max_hit_points();
float repairLiveCost = (float) firm_res[firm_id]->setup_live_points_cost
* REPAIR_POINTS_PER_DAY / max_hit_points();
if( nationPtr->cash < repairCost || nationPtr->live_points < repairLiveCost )
return;
nationPtr->add_expense( EXPENSE_CONSTRUCTION, repairCost, 1 );
nationPtr->change_live_points( -repairLiveCost );
}
hit_points += REPAIR_POINTS_PER_DAY;
if( hit_points >= max_hit_points() )
{
hit_points = (float) max_hit_points();
set_repair_flag( 0, COMMAND_AUTO );
}
}
}
示例2: process_queue
//--------- Begin of function FirmWar::process_queue ---------//
//
void FirmWar::process_queue()
{
if( build_queue_count==0 )
return;
// ######## begin Gilbert 30/12 #######//
// --- cancel if technology lost -----//
// do not cancel build in progress because tech may be recovered
// cancel when it is going to build
if( nation_recno )
{
// ---- delete queue until the first unit in the queue can build ----//
while( build_queue_count > 0
&& unit_res[build_queue_array[0]]->get_nation_tech_level(nation_recno) == 0 )
{
misc.del_array_rec( build_queue_array, build_queue_count, sizeof(build_queue_array[0]), 1 );
build_queue_count--;
}
}
if( build_queue_count==0)
return;
// ######## end Gilbert 30/12 #######//
//--- first check if the nation has enough money to build the weapon ---//
Nation* nationPtr = nation_array[nation_recno];
build_unit_id = build_queue_array[0];
if( nationPtr->cash < unit_res[build_unit_id]->build_cost )
{
build_unit_id = 0;
return;
}
nationPtr->add_expense( EXPENSE_WEAPON, unit_res[build_unit_id]->build_cost, 1);
err_when( build_queue_count > MAX_BUILD_QUEUE );
misc.del_array_rec( build_queue_array, build_queue_count, sizeof(build_queue_array[0]), 1 );
build_queue_count--;
//------- set building parameters -------//
last_process_build_frame_no = sys.frame_count;
build_progress_days = (float) 0;
if( firm_array.selected_recno == firm_recno )
{
// disable_refresh = 1;
// info.disp();
// disable_refresh = 0;
}
}
示例3: pay_expense
//---------- Begin of function Firm::pay_expense --------//
//
void Firm::pay_expense()
{
if( !nation_recno )
return;
Nation* nationPtr = nation_array[nation_recno];
//-------- fixed expenses ---------//
float dayExpense = (float) year_expense() / 365;
if( nationPtr->cash >= dayExpense )
{
nationPtr->add_expense( EXPENSE_FIRM, dayExpense, 1 );
}
else
{
if( hit_points > 0 )
hit_points--;
if( hit_points < 0 )
hit_points = (float) 0;
//--- when the hit points drop to zero and the firm is destroyed ---//
if( hit_points==0 && nation_recno == nation_array.player_recno )
news_array.firm_worn_out(firm_recno);
}
}
示例4: pay_weapon_expense
//------- Begin of function FirmCamp::pay_weapon_expense -------//
//
void FirmCamp::pay_weapon_expense()
{
Worker* workerPtr = worker_array;
Nation* nationPtr = nation_array[nation_recno];
for( int i=1 ; i<=worker_count ; i++, workerPtr++ )
{
if( workerPtr->unit_id &&
unit_res[workerPtr->unit_id]->unit_class == UNIT_CLASS_WEAPON )
{
if( nationPtr->cash > 0 )
{
nationPtr->add_expense( EXPENSE_WEAPON, (float) unit_res[workerPtr->unit_id]->year_cost / 365, 1 );
}
else // decrease hit points if the nation cannot pay the unit
{
if( workerPtr->hit_points > 0 )
workerPtr->hit_points--;
if( workerPtr->hit_points == 0 )
kill_worker(i); // if its hit points is zero, delete it
err_when( workerPtr->hit_points < 0 );
}
}
}
}
示例5: buy_item
// ------- Begin of function FirmInn::buy_item ------//
//
// checkingFlag : false = buy , 1 = check if can buy
//
int FirmInn::buy_item( short recNo, int checkingFlag )
{
err_when( recNo < 1 );
if( recNo > inn_unit_count ) // this may happen in a multiplayer game
return 0;
//--------- first check if you have enough money to hire, unless own spy ------//
Nation* nationPtr = nation_array[nation_recno];
InnUnit* innUnit = inn_unit_array+recNo-1;
if( !innUnit->item.id )
return 0;
if( innUnit->true_nation_recno() != nation_recno && nationPtr->cash < innUnit->item.cost() )
return 0;
if( !checkingFlag )
{
// drop the item outside
if( site_array.add_site( loc_x2, loc_y2, SITE_ITEM, innUnit->item.id, innUnit->item.para )
|| site_array.add_site( loc_x2, loc_y1, SITE_ITEM, innUnit->item.id, innUnit->item.para )
|| site_array.add_site( loc_x1, loc_y2, SITE_ITEM, innUnit->item.id, innUnit->item.para )
|| site_array.add_site( loc_x1, loc_y1, SITE_ITEM, innUnit->item.id, innUnit->item.para ) )
{
// reduce nation cash
if( innUnit->true_nation_recno() != nation_recno )
{
nationPtr->add_expense( EXPENSE_HIRE_UNIT, (float) innUnit->item.cost(), 0 );
}
// clear item
innUnit->item.clear();
// recalc hire cost
innUnit->set_hire_cost();
return 1;
}
return 0;
}
return 1;
}
示例6: build_ship
void FirmHarbor::build_ship(int unitId, char)
{
if(ship_count>=MAX_SHIP_IN_HARBOR)
return;
Nation* nationPtr = nation_array[nation_recno];
if( nationPtr->cash < unit_res[unitId]->build_cost )
return;
nationPtr->add_expense( EXPENSE_SHIP, unit_res[unitId]->build_cost);
build_unit_id = unitId;
start_build_frame_no = sys.frame_count;
}
示例7: pay_expense
//---------- Begin of function FirmCamp::pay_expense --------//
//
// pay_expense() is called by Firm::next_day()
//
void FirmCamp::pay_expense()
{
if( !nation_recno )
return;
Firm::pay_expense();
//-------- pay expenses to human units and weapons --------//
Soldier* soldierPtr = soldier_array;
Nation* nationPtr = nation_array[nation_recno];
for( int i=1 ; i<=soldier_count ; i++, soldierPtr++ )
{
if( soldierPtr->is_under_training() )
continue;
// #### begin Gilbert 24/3 #####//
// int unitClass = unit_res[soldierPtr->unit_id]->unit_class;
//------ if the unit is a weapon -------//
// if( unitClass == UNIT_CLASS_WEAPON )
// one has life reduce hp when no food
// one has no life, reduce hp when no money
if( !unit_res[soldierPtr->unit_id]->class_info.life )
// #### end Gilbert 24/3 #####//
{
if( nationPtr->cash > 0 )
{
nationPtr->add_expense( EXPENSE_WEAPON,
(float) unit_res[soldierPtr->unit_id]->year_cost / 365, 1 );
}
else
{
//-- if it's a weapon, decrease hit points if the nation cannot pay the unit --//
if( soldierPtr->hit_points > 0 )
soldierPtr->hit_points--;
if( soldierPtr->hit_points == 0 )
kill_soldier(i); // if its hit points is zero, delete it
err_when( soldierPtr->hit_points < 0 );
}
}
}
}
示例8: build_firm
//--------- Begin of function FirmArray::build_firm ---------//
//
// build_firm() will be called by Nation and FirmRes when setting up
// new firm.
//
// <int> xLoc = the x location of the firm to be built
// <int> yLoc = the y location of the firm to be built
// <int> nationRecno = the nation which builds this firm
// <int> firmId = firm type id.
// [short] builderRecno = recno of the builder unit
// [bool] isUpgrade = whether this action is to upgrade a firm
// (default: false)
// [bool] noCost = no cost for building the firm (default: false)
//
// Return : <int> the record no. of the newly added firm
//
int FirmArray::build_firm(int xLoc, int yLoc, int nationRecno, int firmId, char* buildCode, short builderRecno, bool isUpgrade, bool noCost)
{
if( !world.can_build_firm(xLoc, yLoc, firmId) )
return 0;
//--------- check if there is enough cash ----------//
if( nationRecno && !isUpgrade )
{
FirmInfo* firmInfo = firm_res[firmId];
Nation* nationPtr = nation_array[nationRecno];
if( nationRecno && !noCost )
{
if( nationPtr->cash < firmInfo->setup_cost )
return 0;
if( nationPtr->live_points < firmInfo->setup_live_points_cost )
return 0;
}
}
//---------- create and build the firm -------------//
int firmRecno = create_firm(firmId);
base_obj_array.add( firm_array[firmRecno] );
firm_array[firmRecno]->init( xLoc, yLoc, nationRecno, firmId, buildCode, builderRecno);
// Firm::init() will set world matrix, it will use Firm::firm_recno to set the location cargo
//----------- add building cost ----------//
if( nationRecno && !isUpgrade && !noCost )
{
Nation* nationPtr = nation_array[nationRecno];
FirmInfo* firmInfo = firm_res[firmId];
nationPtr->add_expense( EXPENSE_CONSTRUCTION, (float)firmInfo->setup_cost); // setup cost of the firm
nationPtr->change_live_points( (float) -firmInfo->setup_live_points_cost );
}
// world.plant_limit = world.plant_limit - m.random(10);
return firmRecno;
}
示例9: cancel_construction
//--------- Begin of function Firm::cancel_construction ---------//
//
// Cancel construction
//
void Firm::cancel_construction(char remoteAction)
{
if( !remoteAction && remote.is_enable())
{
short *shortPtr = (short *)remote.new_send_queue_msg(MSG_FIRM_CANCEL, sizeof(short));
shortPtr[0] = firm_recno;
return;
}
//------ get half of the construction cost back -------//
Nation* nationPtr = nation_array[nation_recno];
nationPtr->add_expense( EXPENSE_CONSTRUCTION, (float) -firm_res[firm_id]->setup_cost/2 );
if( nationPtr->is_monster() )
nationPtr->change_live_points( (float) firm_res[firm_id]->setup_live_points_cost/2 );
firm_array.del_firm(firm_recno);
}
示例10: start_upgrade
//------- Begin of function Firm::start_upgrade -----------//
//
// <int> upgradeFirmId - id. of the firm type to be upgraded to.
//
void Firm::start_upgrade(int upgradeFirmId, char remoteAction)
{
// err_when( upgrading_firm_id ); // if the upgrade process has already started
if( upgrading_firm_id ) // if the upgrade process has already started
return;
if( !remoteAction && remote.is_enable() )
{
short *shortPtr = (short *)remote.new_send_queue_msg( MSG_FIRM_UPGRADE, 2*sizeof(short));
// packet structure : <firm recno> <upgradeFirmId>
shortPtr[0] = firm_recno;
shortPtr[1] = upgradeFirmId;
return;
}
upgrading_firm_id = upgradeFirmId;
Nation* nationPtr = nation_array[nation_recno];
nationPtr->add_expense( EXPENSE_CONSTRUCTION,
(float)firm_res[upgradeFirmId]->setup_cost ); // setup cost of the firm
nationPtr->change_live_points( (float)-firm_res[upgradeFirmId]->setup_live_points_cost );
}
示例11: pay_expense
//--------- 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;
}
//.........这里部分代码省略.........
示例12: hire
//--------- Begin of function FirmInn::hire ---------//
//
// <short> recNo inn unit recno
// [int] spyEscape whether this is an instance which a spy escape from the inn, instead of hiring a unit. i.e. no hire cost required
// (default: 0)
// [short] exitFirmRecno exit inn's firm recno if not same as this inn (see transfer_inn_unit)
// (default :0)
//
int FirmInn::hire(short recNo, int spyEscape, short exitFirmRecno)
{
err_when( recNo < 1 );
if( recNo > inn_unit_count ) // this may happen in a multiplayer game
return 0;
//--------- first check if you have enough money to hire ------//
Nation* nationPtr = nation_array[nation_recno];
InnUnit* innUnit = inn_unit_array+recNo-1;
int unitRecno = 0;
err_when( exitFirmRecno && firm_array.is_deleted(exitFirmRecno) );
if( innUnit->spy_recno && (spyEscape // no expense if mobilizing spy
|| innUnit->true_nation_recno() == nation_recno) ) // no expense if it is own spy
{
// free, no need to play money
unitRecno = (exitFirmRecno ? firm_array[exitFirmRecno] : this)->create_unit(innUnit->unit_id );
if( !unitRecno )
return 0; // no space for creating the unit
}
else
{
if( nationPtr->cash < innUnit->hire_cost )
return 0;
unitRecno = (exitFirmRecno ? firm_array[exitFirmRecno] : this)->create_unit( innUnit->unit_id );
if( !unitRecno )
return 0; // no space for creating the unit
nationPtr->add_expense(EXPENSE_HIRE_UNIT, innUnit->hire_cost);
}
//-------- set skills of the unit --------//
err_when( !unitRecno );
Unit* unitPtr = unit_array[unitRecno];
unitPtr->skill = innUnit->skill;
unitPtr->hit_points = innUnit->hit_points;
err_when( innUnit->combat_level()<=0 || innUnit->combat_level()>1000 );
//----------------------------------------//
//
// Set loyalty of the hired unit
//
// = 30 + the nation's reputation / 2 + 30 if racially homogenous
//
//----------------------------------------//
int unitLoyalty = 30 + (int)nationPtr->reputation/2;
if( innUnit->spy_recno && (spyEscape
|| innUnit->true_nation_recno() == nation_recno) )
{
unitLoyalty = spy_array[innUnit->spy_recno]->spy_loyalty;
}
if( race_res.is_same_race(unitPtr->race_id, nationPtr->race_id) )
unitLoyalty += 20;
unitLoyalty = MAX( 40, unitLoyalty );
unitLoyalty = MIN( 100, unitLoyalty );
unitPtr->loyalty = unitLoyalty;
// ######## begin Gilbert 24/2 #######//
unitPtr->unique_id = innUnit->unique_id; // set unique before add_spy/set_spy_place
// ######## end Gilbert 24/2 #######//
//----------------------------------------------------//
//
// If spy_skill>0, this unit is a spy with a
// spying skill for hire, he is added by FirmInn
//
//----------------------------------------------------//
if( innUnit->spy_skill > 0 )
{
unitPtr->spy_recno = spy_array.add_spy(unitRecno, innUnit->spy_skill);
spy_array[unitPtr->spy_recno]->spy_loyalty = unitLoyalty; // this is the spy's true loyalty towards you
}
//----------------------------------------------------//
//
// If spy_recno>0, this unit is an enemy spy sneaked
// into the inn.
//
//----------------------------------------------------//
else if( innUnit->spy_recno )
{
//.........这里部分代码省略.........
示例13: hire
//--------- Begin of function FirmInn::hire ---------//
//
int FirmInn::hire(short recNo)
{
err_when( recNo < 1 );
if( recNo > inn_unit_count ) // this may happen in a multiplayer game
return 0;
//--------- first check if you have enough money to hire ------//
InnUnit* innUnit;
Nation* nationPtr = nation_array[nation_recno];
innUnit = inn_unit_array+recNo-1;
if( nationPtr->cash < innUnit->hire_cost )
return 0;
//---------- add the unit now -----------//
int unitRecno = create_unit( innUnit->unit_id );
if(!unitRecno)
return 0; // no space for creating the unit
nationPtr->add_expense(EXPENSE_HIRE_UNIT, innUnit->hire_cost);
//-------- set skills of the unit --------//
Unit* unitPtr = unit_array[unitRecno];
memcpy( &(unitPtr->skill), &(innUnit->skill), sizeof(Skill) );
err_when( innUnit->skill.combat_level<=0 || innUnit->skill.combat_level>100 );
unitPtr->set_combat_level( innUnit->skill.combat_level );
//-------- if the unit's skill is spying -----//
if( unitPtr->skill.skill_id == SKILL_SPYING )
{
unitPtr->spy_recno = spy_array.add_spy(unitRecno, unitPtr->skill.skill_level);
unitPtr->skill.skill_id = 0; // reset its primary skill, its spying skill has been recorded in spy_array
}
//----------------------------------------//
//
// Loyalty of the hired unit
//
// = 30 + the nation's reputation / 2 + 30 if racially homogenous
//
//----------------------------------------//
int unitLoyalty = 30 + (int)nationPtr->reputation/2;
if( race_res.is_same_race(unitPtr->race_id, nationPtr->race_id) )
unitLoyalty += 20;
unitLoyalty = MAX( 40, unitLoyalty );
unitLoyalty = MIN( 100, unitLoyalty );
if( unitPtr->spy_recno )
spy_array[unitPtr->spy_recno]->spy_loyalty = unitLoyalty;
else
unitPtr->loyalty = unitLoyalty;
//---- remove the record from the hire list ----//
del_inn_unit(recNo);
if( firm_recno == firm_array.selected_recno &&
nation_recno == nation_array.player_recno )
{
put_info(INFO_UPDATE);
}
return unitRecno;
}
示例14: process_accepted_reply
//.........这里部分代码省略.........
else if( toNation->get_relation_status(talk_para1) == RELATION_FRIENDLY )
{
memset(&talkMsg, 0, sizeof(TalkMsg));
talkMsg.to_nation_recno = (char) talk_para1;
talkMsg.from_nation_recno = to_nation_recno;
talkMsg.talk_id = TALK_END_FRIENDLY_TREATY;
talk_res.send_talk_msg( &talkMsg, COMMAND_AUTO );
}
//--- send a declare war message to the target kingdom ---//
memset(&talkMsg, 0, sizeof(TalkMsg));
talkMsg.to_nation_recno = (char) talk_para1;
talkMsg.from_nation_recno = to_nation_recno;
talkMsg.talk_id = TALK_DECLARE_WAR;
talk_res.send_talk_msg( &talkMsg, COMMAND_AUTO );
//----------------------------------------------------//
goodRelationDec = 10;
}
break;
case TALK_REQUEST_BUY_FOOD:
{
int buyCost = talk_para1 * talk_para2 / 10;
fromNation->add_food( (float) talk_para1 );
fromNation->add_expense( EXPENSE_IMPORTS, (float) buyCost, 0 );
toNation->consume_food( (float) talk_para1 );
toNation->add_income( INCOME_EXPORTS, (float) buyCost, 0 );
break;
}
case TALK_DECLARE_WAR:
toRelation->started_war_on_us_count++; // how many times this nation has started a war with us, the more the times the worse this nation is.
toNation->set_relation_status(from_nation_recno, RELATION_HOSTILE);
fromRelation->set_never_accept_until_date(TALK_REQUEST_CEASE_WAR, 150);
toRelation->set_never_accept_until_date(TALK_REQUEST_CEASE_WAR, 150);
fromRelation->set_never_accept_until_date(TALK_GIVE_TRIBUTE, 300);
toRelation->set_never_accept_until_date(TALK_GIVE_TRIBUTE, 300);
//--- decrease reputation of the nation which declares war ---//
if( toNation->reputation > 0 )
fromNation->change_reputation( -toNation->reputation * 20 / 100 );
break;
case TALK_GIVE_TRIBUTE:
case TALK_GIVE_AID:
fromNation->give_tribute( to_nation_recno, talk_para1 );
break;
case TALK_DEMAND_TRIBUTE:
case TALK_DEMAND_AID:
toNation->give_tribute( from_nation_recno, talk_para1 );
goodRelationDec = talk_para1/200;
break;