Example #1
0
//--------- Begin of function FirmCamp::capture_firm --------//
//
// The firm is being captured by another nation.
//
void FirmCamp::capture_firm(int newNationRecno)
{
	if( nation_recno == nation_array.player_recno )
		news_array.firm_captured(firm_recno, newNationRecno, 0);		// 0 - the capturer is not a spy

	//-------- if this is an AI firm --------//

	if( is_ai )
		ai_firm_captured(newNationRecno);

	//------------------------------------------//
	//
	// If there is an overseer in this firm, then the only
	// unit who can capture this firm will be the overseer only,
	// so calling its betray() function will capture the whole
	// firm already.
	//
	//------------------------------------------//

	if( overseer_recno && unit_array[overseer_recno]->spy_recno )
		unit_array[overseer_recno]->spy_change_nation(newNationRecno, COMMAND_AUTO);
	else
		change_nation(newNationRecno);
}
Example #2
0
//--------- Begin of function Unit::betray ---------//
//
// If this unit is a spy, this function betray() will be
// called by Unit::spy_change_nation() or Firm::capture_firm().
//
// If this is not a spy, this function will only be called
// by think_betray() and other nation deinit functions.
//
int Unit::betray(int newNationRecno)
{
	//----- if this is a spy, call spy_change_nation -----//

	if( spy_recno &&
		 spy_array[spy_recno]->cloaked_nation_recno != newNationRecno ) 	// cloaked_nation_recno == newNationRecno if betray() is called by spy_change_nation() already
	{
		spy_change_nation(newNationRecno, COMMAND_AUTO);
		return 1;
	}

	//-------------------------------//

	err_when( newNationRecno && nation_array[newNationRecno]->is_human() &&		// monsters in firms should not betray to humans
			    is_monster() && unit_mode == UNIT_MODE_OVERSEE );		

	int unitRecno = sprite_recno;

	err_when( unit_array.is_truly_deleted(unitRecno) );

	err_when( rank_id == RANK_KING );

	if( nation_recno == newNationRecno )
		return 0;

	if( unit_mode == UNIT_MODE_CONSTRUCT_FIRM ||	 // don't change nation when the unit is constructing a firm
		 unit_mode == UNIT_MODE_CONSTRUCT_TOWN ||	 
		 unit_mode == UNIT_MODE_ON_SHIP   )  	// don't change nation when the unit is constructing a firm
	{
		return 0;
	}

	//--- special case: units in Monster Fortress cannot change nation ---//

	if( unit_mode == UNIT_MODE_OVERSEE &&
		 firm_array[unit_mode_para]->firm_id == FIRM_FORTRESS )
	{
		return 0;
	}

	//---------- add news -----------//

	if( nation_recno == nation_array.player_recno ||
		 newNationRecno == nation_array.player_recno )
	{
		//--- if this is a spy, don't display news message for betrayal as it is already displayed in Unit::spy_change_nation() ---//

		if( !spy_recno )
			news_array.unit_betray(sprite_recno, newNationRecno);
	}

	//------ change nation now ------//

	err_when( unit_array.is_truly_deleted(unitRecno) );

	change_nation(newNationRecno);

	err_when( unit_array.is_truly_deleted(unitRecno) );

	//-------- set the loyalty of the unit -------//

	if( nation_recno )
	{
		Nation* nationPtr = nation_array[nation_recno];

		loyalty = UNIT_BETRAY_LOYALTY + 10 + m.random(20);

		if( nationPtr->reputation > 0 )
			change_loyalty( (int) nationPtr->reputation );

		if( race_res.is_same_race( nationPtr->race_id, race_id ) )
			change_loyalty( 30 );

		err_when( loyalty < 0 || loyalty > 100 );

		update_loyalty();		// update target loyalty
	}
	else  //------ if change to independent rebel -------//
	{
		loyalty = 0;      // no loyalty needed
	}

	//--- if this unit is a general, change nation for the units he commands ---//

	if( rank_id==RANK_GENERAL )
	{
		err_when( !team_info );

		for( int i=0 ; i<team_info->member_count ; i++ )
		{
			int memberUnitRecno = team_info->member_unit_array[i];

			if( memberUnitRecno == unitRecno )		// this is the unit itself
				continue;

			Unit* unitPtr = unit_array[memberUnitRecno];

			if( !unitPtr->is_visible() )
				continue;

			if( unitPtr->spy_recno )		// if the unit is a spy
				unitPtr->spy_change_nation(newNationRecno, COMMAND_AUTO);
			else
				unitPtr->change_nation(newNationRecno);
		}
	}

	err_when( unit_array.is_truly_deleted(unitRecno) );

	//------ go to meet the new master -------//

	if( is_visible() && nation_recno )
	{
		if( !spy_recno || spy_array[spy_recno]->notify_cloaked_nation_flag )
		{
			if( is_civilian() )
				ai_move_to_nearby_town();
			else
				ai_move_to_nearby_firm(FIRM_CAMP, FIRM_FORT);
		}
	}

	err_when( unit_array.is_truly_deleted(unitRecno) );

	return 1;
}