Esempio n. 1
0
File: ospya.cpp Progetto: mecirt/7k2
//--------- Begin of function SpyArray::ai_spy_town_rebel ----------//
//
// Tell the AI spies in the town that a rebellion is happening.
//
// When a rebellion happens, all the AI spies in the town will mobilize
// and turn its cloak back to a nation that is not at war with the enemy
// (and notification flag should be off.) and move to a safe place
// (near to one of your towns). Then the spy reaches thedestination, it will
// become idle and then the AI processing function on idle spy will be
// called and handle the spy.
//
// <int> townRecno - recno of the town with rebellion happening.
//
void SpyArray::ai_spy_town_rebel(int townRecno)
{
	int  spyCount=size();
	Spy* spyPtr;

	for( int i=1 ; i<=spyCount ; i++ )
	{
		if( spy_array.is_deleted(i) )
			continue;

		spyPtr = spy_array[i];

		if( spyPtr->spy_place==SPY_TOWN &&
			 spyPtr->spy_place_para==townRecno &&
			 nation_array[spyPtr->true_nation_recno]->is_ai() )
		{
			//-------- mobilize the spy ----------//

			int unitRecno = spyPtr->mobilize_town_spy();

			//----- think new action for the spy ------//

			if( unitRecno )
				spyPtr->think_mobile_spy_new_action();
		}
	}
}
Esempio n. 2
0
File: ospya.cpp Progetto: mecirt/7k2
//--------- Begin of function SpyArray::next_day ----------//
//
void SpyArray::next_day()
{
	int  spyCount = size();
	Spy* spyPtr;

	for( int i=1 ; i<=spyCount ; i++ )
	{
		if( spy_array.is_deleted(i) )
			continue;

		spyPtr = spy_array[i];

		spyPtr->next_day();

		if( spy_array.is_deleted(i) )
			continue;

		if( nation_array[spyPtr->true_nation_recno]->is_ai() )
			spyPtr->process_ai();
	}

	//---------- update Firm::sabotage_level ----------//

	if( info.game_date%15==0 )
		process_sabotage();
}
Esempio n. 3
0
File: ospya.cpp Progetto: mecirt/7k2
//--------- Begin of function SpyArray::change_cloaked_nation ---------//
//
// Change the cloak of all the spies in the specific place.
//
// This function is called when a firm or town change nation.
//
// <int> spyPlace        - spy place
// <int> spyPlacePara    - spy place para
// <int> fromNationRecno - change any spies in the place whose cloaked_nation_recno
// <int> toNationRecno     is fromNationRecno to toNationRecno.
//
void SpyArray::change_cloaked_nation(int spyPlace, int spyPlacePara, int fromNationRecno, int toNationRecno)
{
	Spy* spyPtr;

	for( int i=spy_array.size() ; i>0 ; i-- )
	{
		if( spy_array.is_deleted(i) )
			continue;

		spyPtr = spy_array[i];

		if( spyPtr->cloaked_nation_recno != fromNationRecno )
			continue;

		if( spyPtr->spy_place != spyPlace )
			continue;

		//--- check if the spy is in the specific firm or town ---//

		if( spyPlace == SPY_FIRM || spyPlace == SPY_TOWN )  // only check spy_place_para when spyPlace is SPY_TOWN or SPY_FIRM
		{
			if( spyPtr->spy_place_para != spyPlacePara )
				continue;
		}

		if(spyPlace==spyPtr->spy_place && spyPlacePara==spyPtr->spy_place_para &&
			spyPtr->true_nation_recno==toNationRecno)
			spyPtr->set_action_mode(SPY_IDLE);

		//----- if the spy is associated with a unit (mobile or firm overseer), we call Unit::spy_chnage_nation() ---//

		if( spyPlace == SPY_FIRM )
		{
			FirmCamp *firmCamp = firm_array[spyPtr->spy_place_para]->cast_to_FirmCamp();
			if( firmCamp )
			{
				int firmOverseerRecno = firmCamp->overseer_recno;

				if( firmOverseerRecno && unit_array[firmOverseerRecno]->spy_recno == i )
				{
					unit_array[firmOverseerRecno]->spy_change_nation(toNationRecno, COMMAND_AUTO);
					continue;
				}
			}
		}
		else if( spyPlace == SPY_MOBILE )
		{
			unit_array[spyPtr->spy_place_para]->spy_change_nation(toNationRecno, COMMAND_AUTO);
			continue;
		}

		//---- otherwise, just change the spy cloak ----//

		spyPtr->cloaked_nation_recno = toNationRecno;
	}
}
Esempio n. 4
0
//-------- Begin of static function put_spy_rec --------//
//
static void put_spy_rec(int recNo, int x, int y, int refreshFlag)
{
	int x2 = x+browse_spy.rec_width-1;

	//-------- display icon of the spy unit -----//

	Spy* spyPtr = spy_array[ spy_filter(recNo) ];

	//-------- get the rank of the spy --------//

	int unitId = race_res[spyPtr->race_id]->basic_unit_id;
	int rankId = RANK_SOLDIER;

	if( spyPtr->spy_place == SPY_FIRM )
	{
		int unitRecno = firm_array[spyPtr->spy_place_para]->overseer_recno;

		if( unitRecno && unit_array[unitRecno]->spy_recno == spyPtr->spy_recno )
			rankId = RANK_GENERAL;
	}

	//---------- display unit icon ---------//

	if( refreshFlag == INFO_REPAINT )
	{
		vga.d3_panel_down(x+1, y+1, x+UNIT_SMALL_ICON_WIDTH+4, y+UNIT_SMALL_ICON_HEIGHT+4 );

		vga_front.put_bitmap(x+3, y+3, unit_res[unitId]->get_small_icon_ptr(rankId) );
	}

	//--------- set help parameters --------//

	if( mouse.in_area(x+1, y+1, x+RACE_ICON_WIDTH+4, y+RACE_ICON_HEIGHT+4) )
	{
		help.set_unit_help( unitId, rankId, x+1, y+1, x+RACE_ICON_WIDTH+4, y+RACE_ICON_HEIGHT+4 );
	}

	//-------- display spy skill -------//

	font_san.put( x+40, y+6, spyPtr->spy_skill, 1, x+66 );

	//-------- display spy loyalty -------//

	font_san.put( x+67, y+6, spyPtr->spy_loyalty, 1, x+94 );

	//------ display the action mode of the spy ------//

	vga.blt_buf( x+95, y+6, x2, y+5+font_san.height(), 0 );

   font_san.use_max_height();
	font_san.center_put( x+95, y+6, x2, y+5+font_san.height(), spyPtr->action_str() );
	font_san.use_std_height();
}
Esempio n. 5
0
int main(int argc, char *argv[])
{

  KAboutData aboutData( "spy", I18N_NOOP("Spy"),
    VERSION, description, KAboutData::License_GPL,
    "(c) 2001, Richard Moore", 0, 0, "*****@*****.**");
  aboutData.addAuthor("Richard Moore",0, "*****@*****.**");
  KCmdLineArgs::init( argc, argv, &aboutData );
  KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.

  KApplication a;
  Spy *spy = new Spy();
  a.setMainWidget(spy);

  spy->show();

  return a.exec();
}
Esempio n. 6
0
//--------- Begin of function Info::detect_spy ---------//
//
void Info::detect_spy()
{
	//------- detect the spy browser -------//

	if( browse_spy.detect() )
	{
		browse_spy_recno = browse_spy.recno();

		if( browse_spy.double_click )
		{
			Spy* spyPtr = spy_array[ spy_filter(browse_spy_recno) ];
			int  xLoc, yLoc;

			if( spyPtr->get_loc(xLoc, yLoc) )
				world.go_loc( xLoc, yLoc, 1 );
		}
	}
}
Esempio n. 7
0
File: ospya.cpp Progetto: mecirt/7k2
//--------- Begin of function SpyArray::set_action_mode ----------//
//
// Set all spies in the given place to the specific action mode.
//
void SpyArray::set_action_mode(int spyPlace, int spyPlacePara, int actionMode)
{
	int  spyCount=size();
	Spy* spyPtr;

	for( int i=1 ; i<=spyCount ; i++ )
	{
		if( spy_array.is_deleted(i) )
			continue;

		spyPtr = spy_array[i];

		if( spyPtr->spy_place==spyPlace &&
			 spyPtr->spy_place_para==spyPlacePara )
		{
			spyPtr->set_action_mode(actionMode);
		}
	}
}
Esempio n. 8
0
void Level3::contact_level(b2Contact* contact)
{
	Spy *spyA = spymanager->getChildByBody(contact->GetFixtureA()->GetBody());
	Spy *spyB = spymanager->getChildByBody(contact->GetFixtureB()->GetBody());
	if (spyA != nullptr && spyB != nullptr)
	{
		if (((spyA->getTag() == "dan") && (spyB->getTag() == "goal")))
		{
			b2JointEdge *joint = spyB->getBody()->GetJointList();
			if (joint != nullptr || joint != NULL)
			{
				b2Joint *joint_e = joint->joint;
				for (; joint_e != NULL; joint_e = joint_e->GetNext())
				{
					if (joint_e->GetUserData() == "pig_rope")
					{
						spyA->getSprite()->runAction(CallFuncN::create(CC_CALLBACK_0(Level3::doCallback, this, joint_e)));
						break;
					}
				}
			}
		}
		if ((spyB->getTag() == "dan") && (spyA->getTag() == "goal"))
		{
			b2JointEdge *joint = spyA->getBody()->GetJointList();
			if (joint != nullptr || joint != NULL)
			{
				b2Joint *joint_e = joint->joint;
				for (; joint_e != NULL; joint_e = joint_e->GetNext())
				{
					if (joint_e->GetUserData() == "pig_rope")
					{
						spyB->getSprite()->runAction(CallFuncN::create(CC_CALLBACK_0(Level3::doCallback, this, joint_e)));
						break;
					}
				}
			}
		}
	}

}
Esempio n. 9
0
File: ospya.cpp Progetto: mecirt/7k2
//--------- Begin of function SpyArray::mobilize_all_spy ----------//
//
// Mobilize all spies of the specific nation in the specific place.
//
// <int> spyPlace     - place id. of the spy
// <int> spyPlacePara - town or firm recno of the spy's staying
// <int> nationRecno	 - recno of the nation which the spy should
//							   be mobilized.
//
void SpyArray::mobilize_all_spy(int spyPlace, int spyPlacePara, int nationRecno)
{
	Spy* spyPtr;

	for( int i=size() ; i>0 ; i-- )
	{
		if( spy_array.is_deleted(i) )
			continue;

		spyPtr = spy_array[i];

		if( spyPtr->spy_place == spyPlace &&
			 spyPtr->spy_place_para == spyPlacePara &&
			 spyPtr->true_nation_recno == nationRecno )
		{
			if( spyPtr->spy_place == SPY_TOWN )
				spyPtr->mobilize_town_spy();

			else if( spyPtr->spy_place == SPY_FIRM )
				spyPtr->mobilize_firm_spy();
		}
	}
}
Esempio n. 10
0
void Info::process_viewing_spy()
{
	//---- check if the viewing spy is still valid ----//

	int isValid=1;

	if( spy_array.is_deleted(viewing_spy_recno) )	// the spy is dead
	{
		isValid = 0;
	}
	else
	{
		Spy* spyPtr = spy_array[viewing_spy_recno];

		//-- check if the spy still stay in the same place --//

		if( spyPtr->spy_place_nation_recno() != info.viewing_nation_recno )
		{
			isValid = 0;
		}
		else
		{
		/*
			//--- on average, a spy will get caught in 5 to 15 days when viewing the secret of its enemy ---//

			if( misc2.random(5+spyPtr->spy_skill/5) ) // use m2 to avoid multiplayer sync problem
			{
				spyPtr->set_exposed(COMMAND_PLAYER);
				isValid = 0;
			}
		*/
		}
	}

	if( !isValid )		//-- if not valid, set the mode back to normal viewing mode
		sys.set_view_mode(MODE_NORMAL);
}
Esempio n. 11
0
//--------- Begin of function Nation::ai_assign_spy --------//
//
// Try to locate an existing spy for use.
//
// <int> targetXLoc, targetYLoc - the target location
// [int] spyRaceId			  - if specified, only spies of this race
//											 will be located. (default:0)
// [int] mobileOnly 				  - get mobile spies only. (default:0)
//
int Nation::ai_assign_spy(int targetXLoc, int targetYLoc, int spyRaceId, int mobileOnly)
{
	int unitRecno=0;

	//---- try to find an existing spy ----//

	Spy* spyPtr = ai_find_spy( targetXLoc, targetYLoc, spyRaceId, mobileOnly );

	if( spyPtr )
		unitRecno = spyPtr->mobilize_spy();

	//--- if not successful, then try to hire one ---//

	if( !unitRecno )
		unitRecno = hire_unit(SKILL_SPYING, spyRaceId, targetXLoc, targetYLoc);

	//--- if cannot hire one, try to train one ----//

	int trainTownRecno=0;

	if( !unitRecno )
		unitRecno = train_unit(SKILL_SPYING, spyRaceId, targetXLoc, targetYLoc, trainTownRecno);

	if( !unitRecno )
		return 0;

	//------ get the spy object of the unit ------//

	Unit* unitPtr = unit_array[unitRecno];

	err_when( !unitPtr->spy_recno );

	spyPtr = spy_array[unitPtr->spy_recno];

	//------- get the nation of the assign destination -----//

	Location* locPtr = world.get_loc(targetXLoc, targetYLoc);
	int 		 cloakedNationRecno;

	if( locPtr->is_firm() )
	{
		Firm* firmPtr = firm_array[locPtr->firm_recno()];

		err_when( firmPtr->nation_recno==0 );		// cannot assign to a monster firm

		cloakedNationRecno = firmPtr->nation_recno;
	}
	else if( locPtr->is_town() )
	{
		Town* townPtr = town_array[locPtr->town_recno()];

		cloakedNationRecno = townPtr->nation_recno;
	}
	else
	{
		return 0;		// the original firm or town has been destroyed or sold
	}

	//------- Add the assign spy action --------//

	int actionRecno = add_action( targetXLoc, targetYLoc,
							-1, -1, ACTION_AI_ASSIGN_SPY, cloakedNationRecno, 1, unitRecno );

	if( !actionRecno )
		return 0;

	//------ if the unit is under training ------//

	if( trainTownRecno )
		town_array[trainTownRecno]->train_unit_action_id = get_action(actionRecno)->action_id;

	return 1;
}
Esempio n. 12
0
//--------- Begin of function FirmInn::detect_info ---------//
//
void FirmInn::detect_info()
{
//	firm_inn_ptr = this;

	Firm::detect_info();

//	if( detect_basic_info() )
//		return;

	if( !should_show_info() )
		return;

	detect_unit_list();

	// ------ detect hire button -------//

	// since button_hire and button_spy_mobilize share the same place
	// if one is not visible, do not call detect() to avoid incorrect help text displayed

	if( button_hire_visible && button_hire.detect() 
		&& selected_unit_id > 0 && selected_unit_id <= inn_unit_count )
	{
		InnUnit *innUnit = inn_unit_array + selected_unit_id - 1;

		se_ctrl.immediate_sound("TAXGRANT");

		se_res.far_sound(center_x, center_y, 1, 'S', 
			unit_res[innUnit->unit_id]->sprite_id,
			"RDY" );
		if(remote.is_enable())
		{
			// packet structure : <firm recno>, <hire Id> <nation no> <spy escape>
			short *shortPtr=(short *)remote.new_send_queue_msg(MSG_F_INN_HIRE, 4*sizeof(short));
			shortPtr[0] = firm_recno;
			shortPtr[1] = selected_unit_id;
			shortPtr[2] = nation_recno;
			// ###### begin Gilbert 13/2 #######//
			shortPtr[3] = 0;
			// ###### end Gilbert 13/2 #######//
		}
		else
		{
			hire(selected_unit_id, 0);
		}

		// ------ clear selected_unit_id ------//

		selected_unit_id = 0;
	}
	else if( button_spy_mobilize_visible && button_spy_mobilize.detect() 
		&& selected_unit_id > 0 && selected_unit_id <= inn_unit_count )
	{
		se_res.far_sound(center_x, center_y, 1, 'S', 
			unit_res[inn_unit_array[selected_unit_id-1].unit_id]->sprite_id,
			"RDY" );

		err_when( spy_array.is_deleted(inn_unit_array[selected_unit_id-1].spy_recno) );
		Spy *spyPtr = spy_array[inn_unit_array[selected_unit_id-1].spy_recno];
		if( !remote.is_enable() )
		{
			if( spyPtr->mobilize_firm_spy() )
			{
				spyPtr->notify_cloaked_nation_flag = 0;		// reset it so the player can control it
			}
		}
		else
		{
			// packet structure <spy recno>
			short *shortPtr = (short *)remote.new_send_queue_msg(MSG_SPY_LEAVE_FIRM, sizeof(short) );
			*shortPtr = spyPtr->spy_recno;
		}

		// ------ clear selected_unit_id ------//

		selected_unit_id = 0;
	}

	// -------- detect buy item ------//

	if( selected_unit_id > 0 && selected_unit_id <= inn_unit_count )
	{
		InnUnit *innUnit = inn_unit_array + selected_unit_id - 1;

		if( button_buy_item.detect() )
		{
			se_ctrl.immediate_sound("TAXGRANT");

			if( !remote.is_enable() )
			{
				buy_item( selected_unit_id, 0 );
			}
			else
			{
				short *shortPtr = (short *)remote.new_send_queue_msg(MSG_F_INN_BUY_ITEM, 2*sizeof(short));
				// packet structure : <firm recno>, <inn unid id>
				shortPtr[0] = firm_recno;
				shortPtr[1] = selected_unit_id;
			}
			se_ctrl.immediate_sound("TURN_ON");
		}
		else if( innUnit->item.id )
		{
			help.set_custom_help( button_buy_item.x1, button_buy_item.y1, 
				button_buy_item.x2, button_buy_item.y2, 
				text_firm.str_buy_item_help( &innUnit->item ),
				innUnit->item.item_desc() );
		}
	}
}
Esempio n. 13
0
//-------- Begin of function FirmInn::transfer_inn_unit --------//
//
int FirmInn::transfer_inn_unit(int recNo)
{
	err_when( recNo < 1 );
	
	if( recNo > inn_unit_count )
		return 0;

	InnUnit *innUnit = inn_unit_array+recNo-1;

	if( !innUnit->spy_recno )
		return 0;					// only spy considers transfer

	Spy *spyPtr = NULL;
	if( innUnit->spy_recno && !spy_array.is_deleted(innUnit->spy_recno) )
		spyPtr = spy_array[innUnit->spy_recno];

	// -------- scan any inn firm in world ----------//

	int ownFirmRecno = 0;
	int anyOwnInn = 0;
	int firmRecno = 1+misc.random(firm_array.size());

	int firmCount;
	for( firmCount = firm_array.size(); firmCount > 0; --firmCount, ++firmRecno )
	{
		if( firmRecno > firm_array.size() )
			firmRecno -= firm_array.size();
		err_when(firmRecno < 1 || firmRecno > firm_array.size());

		if( firm_array.is_deleted(firmRecno) )
			continue;

		FirmInn *firmInn = firm_array[firmRecno]->cast_to_FirmInn();

		if( !firmInn )
			continue;

		if( spyPtr && firmInn->nation_recno == spyPtr->true_nation_recno )
		{
			if( !anyOwnInn )
				anyOwnInn = firmRecno;
		}

		if( firmRecno == firm_recno )		// never go back to the same inn
			continue;

		if( firmInn->inn_unit_count >= MAX_INN_UNIT )
			continue;

		if( spyPtr && firmInn->nation_recno == spyPtr->true_nation_recno )
		{
			if( !ownFirmRecno )
				ownFirmRecno = firmRecno;
			continue;							// spy tend not to go back to own firmInn, unless no other choice
		}

		break;
	}

	if( firmCount <= 0 )				// if no other firm found, go back to own firm
		firmRecno = ownFirmRecno;

	if( firmRecno )					// if no any firm to go return false
	{
		// ------ transfer inn unit -------//

		FirmInn *firmInn = firm_array[firmRecno]->cast_to_FirmInn();		
		err_when( !firmInn );
		InnUnit *newInnUnit = firmInn->inn_unit_array + firmInn->inn_unit_count;
		firmInn->inn_unit_count++;
		*newInnUnit = *innUnit;

		// ------- generate new stay count ------//

		newInnUnit->stay_count = 10 + misc.random(5);
		newInnUnit->set_hire_cost();

		// ------ trasfer Spy ------- //

		if( spyPtr )
			spyPtr->set_place(SPY_FIRM, firmRecno);
		innUnit->spy_recno = 0;					// prevent del_inn_unit call spy_array.del_spy

		// ------ delete inn unit of current inn ------//

		del_inn_unit(recNo);
		innUnit = newInnUnit;			// set innUnit to the transferred place for later use
	}
	else if( (firmRecno = anyOwnInn) )
	{
		// mobilize in another any own inn

		hire( recNo, 1, firmRecno );
		innUnit = NULL;
	}

	return firmRecno;
}
Esempio n. 14
0
//-------- Begin of static function put_spy_rec --------//
//
static void put_spy_rec(int recNo, int x, int y, int refreshFlag)
{
	int  spyRecno = spy_filter(recNo);
	Spy* spyPtr   = spy_array[spyRecno];

	x+=3;
	y+=5;

	//------ display rank/skill icon -------//

	int 	 cloakedRankId  = spyPtr->cloaked_rank_id();
	int 	 cloakedSkillId = spyPtr->cloaked_skill_id();
	String str;

	switch( cloakedRankId )
	{
		case RANK_KING:
			str = "U_KING";
			break;

		case RANK_GENERAL:
			str = "U_GENE";
			break;

		case RANK_SOLDIER:
			if( cloakedSkillId )
			{
				str  = "U_";
				str += Skill::skill_code_array[cloakedSkillId-1];
			}
			else
			{
				str = "";
			}
			break;
	}

	if( str.len() > 0 )
		image_icon.put_back(x, y+1, str);

	//------ display race icon -------------//

	vga_back.put_bitmap( x+13, y-4, race_res[spyPtr->race_id]->icon_bitmap_ptr );

	//----------- display name -----------//

	font_san.put( x+39, y, race_res[spyPtr->race_id]->get_name(spyPtr->name_id), 0, 185 );

	//------- display cloaked nation color ------//

	int tx = x+170;

	if( spyPtr->cloaked_nation_recno==0 )		// independent nation
	{
		vga_back.bar( tx, y, tx+12, y+12, V_WHITE );
		vga_back.rect( tx, y, tx+12, y+12, 1, VGA_GRAY+8 );
	}
	else
	{
		nation_array[spyPtr->cloaked_nation_recno]->disp_nation_color(tx, y+2);
	}

	//---------- display other info ----------//

	switch( spyPtr->spy_place )
	{
		case SPY_FIRM:
			str = firm_res[firm_array[spyPtr->spy_place_para]->firm_id]->name;
			break;

		case SPY_TOWN:
			str = town_array[spyPtr->spy_place_para]->town_name();
			break;

		case SPY_MOBILE:
		{
			Unit* unitPtr = unit_array[spyPtr->spy_place_para];

			switch( unitPtr->unit_mode )
			{
				case UNIT_MODE_CONSTRUCT:
					str = firm_res[firm_array[unitPtr->unit_mode_para]->firm_id]->name;
					break;

				case UNIT_MODE_ON_SHIP:
					str = "On Ship";
					break;

				default:
					str = "Mobile";
			}
			break;
		}

		default:
			str = "";
	}

	font_san.put( x+205, y, str );

	font_san.put( x+335, y, spyPtr->spy_skill );
	font_san.put( x+385, y, spyPtr->spy_loyalty );
	font_san.put( x+435, y, spyPtr->action_str() );
}
Esempio n. 15
0
File: ospya.cpp Progetto: mecirt/7k2
//-------- Begin of function SpyArray::catch_spy ------//
//
// <int> spyPlace - either SPY_TOWN or SPY_FIRM
// <int> spyPlacePara - town_recno or firm_recno
//
int SpyArray::catch_spy(int spyPlace, int spyPlacePara)
{
	int nationRecno, totalPop;

	if( spyPlace == SPY_TOWN )
	{
		Town* townPtr = town_array[spyPlacePara];

		nationRecno = townPtr->nation_recno;
		totalPop    = townPtr->population;
	}
	else if( spyPlace == SPY_FIRM )
	{
		Firm* firmPtr = firm_array[spyPlacePara];

		nationRecno = firmPtr->nation_recno;
		if( firmPtr->cast_to_FirmCamp() )
		{
			FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp();
			totalPop    = firmCamp->soldier_count + (firmCamp->overseer_recno>0);
		}
		else if( firmPtr->cast_to_FirmWork() )
		{
			FirmWork *firmWork = firmPtr->cast_to_FirmWork();
			totalPop    = firmWork->worker_count;
		}
		else if( firmPtr->cast_to_FirmTrain() )
		{
			totalPop = firmPtr->cast_to_FirmTrain()->trainee_count;
			return 0;		// don't catch spy
		}
		else if( firmPtr->cast_to_FirmInn() )
		{
			totalPop = firmPtr->cast_to_FirmInn()->inn_unit_count;
			return 0;		// don't catch spy
		}
		else if( firmPtr->cast_to_FirmMarket() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmMonsterTrain() )
		{
			totalPop = firmPtr->cast_to_FirmMonsterTrain()->trainee_count;
			return 0;		// don't catch spy
		}
		else if( firmPtr->cast_to_FirmMonsterAlchemy() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmLishorr() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmMonsterFortress() )
		{
			FirmMonsterFortress *firmMonsterFortress = firmPtr->cast_to_FirmMonsterFortress();
			totalPop = firmMonsterFortress->archer_count + firmMonsterFortress->extra_builder_count;
		}
		else if( firmPtr->cast_to_FirmAnimal() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmIncubator() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmMagic() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmOffensive() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmOffensive2() )
		{
			totalPop = 0;
			return 0;
		}
		else
		{
			err_here();
			totalPop = 0;
		}
	}
	else
		err_here();

	//--- calculate the total of anti-spy skill in this town ----//

	int enemySpyCount=0, counterSpySkill=0;
	Spy* spyPtr;

	int techLevel = 0;
	if( nationRecno )
		techLevel = tech_res[TECH_COUNTER_SPY]->get_nation_tech_level(nationRecno);

	int i;
	for( i=size() ; i>0 ; i-- )
	{
		if( is_deleted(i) )
			continue;

		spyPtr = spy_array[i];

		if( spyPtr->spy_place == spyPlace &&
			 spyPtr->spy_place_para == spyPlacePara )
		{
			if( spyPtr->true_nation_recno == nationRecno )
				counterSpySkill += spyPtr->spy_skill + spyPtr->spy_skill * techLevel / 2;
			else
				enemySpyCount++;
		}
	}

	//----- if all citizens are enemy spies ----//

	if( enemySpyCount == totalPop )
		return 0;

	err_when( enemySpyCount > totalPop );

	//-------- try to catch enemy spies now ------//

	for( i=spy_array.size() ; i>0 ; i-- )
	{
		if( spy_array.is_deleted(i) )
			continue;

		spyPtr = spy_array[i];

		if( spyPtr->action_mode == SPY_IDLE )		// it is very hard to get caught in sleep mode
			continue;

		if( spyPtr->spy_place == spyPlace &&
			 spyPtr->spy_place_para == spyPlacePara &&
			 spyPtr->true_nation_recno != nationRecno )	// doesn't get caught in sleep mode
		{
			int escapeChance = 100 + spyPtr->spy_skill - counterSpySkill;

			escapeChance = max( spyPtr->spy_skill/10, escapeChance );

			if( m.random(escapeChance) == 0 )
			{
				spyPtr->get_killed(); 		// only catch one spy per calling
				return 1;
			}
		}
	}

	return 0;
}
Esempio n. 16
0
//-------- Begin of function Sys::set_view_mode --------//
//
// <int> viewMode 			 - id. of the view mode.
// [int] viewingNationRecno - which nation the player is viewing at with the reports.
//										(default: the player nation)
// [int] viewingSpyRecno 	 - >0 if the spy is viewing secret reports of other nations
//
void Sys::set_view_mode(int viewMode, int viewingNationRecno, int viewingSpyRecno)
{
	if( view_mode == viewMode )
		return;

	info.display_hot_key = 0;
	//---- if the player's kingdom has been destroyed ----//

	err_when( viewingNationRecno && nation_array.is_deleted(viewingNationRecno) );

	if( nation_array.is_deleted(info.default_viewing_nation_recno) )
	{
		if( viewMode != MODE_NORMAL && viewMode != MODE_RANK )		// other reports are not available except the normal and rank report
			return;
	}

	//---- a spy is exposed when he has finished viewing the secrets ----//

	if( info.viewing_spy_recno )
	{
		if( !spy_array.is_deleted(info.viewing_spy_recno) )
		{
			Spy* spyPtr = spy_array[info.viewing_spy_recno];

			int needViewSecretSkill = spy_array.needed_view_secret_skill(info.viewing_spy_recno);
			int escapeChance = spyPtr->spy_skill - needViewSecretSkill;
			int killFlag = 0;

			if( escapeChance > 0 )
			{
				if( m2.random( escapeChance/15 )==0  )		// use m2 instead of m to maintain mulitplayer sync
					killFlag = 1;
			}

			if( killFlag )
				spyPtr->set_exposed(COMMAND_PLAYER);
		}

		info.viewing_spy_recno = 0;
	}

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

	if( viewMode == MODE_NORMAL )
	{
		info.viewing_nation_recno = info.default_viewing_nation_recno;
	}
	else
	{
		if( viewingNationRecno )
			info.viewing_nation_recno = viewingNationRecno;
		else
			info.viewing_nation_recno = info.default_viewing_nation_recno;

		info.viewing_spy_recno = viewingSpyRecno;
	}

	view_mode = viewMode;
	disp_view_mode();

	disp_view();
}
Esempio n. 17
0
//--------- Begin of function Firm::detect_spy_menu ---------//
//
void Firm::detect_spy_menu()
{
	firm_ptr = this;

	if( spy_filter()==0 )
		return;

	browse_spy.detect();

	Spy* spyPtr = spy_array[ spy_filter( browse_spy.recno() ) ];

	//--------- detect buttons --------//

	//--------- spy menu mode -----------//

	if( firm_menu_mode == FIRM_MENU_SPY )
	{
		//------ mobilize spy ---------//

		if( button_spy_mobilize.detect() )
		{
			if( !remote.is_enable() )
			{
				if( spyPtr->mobilize_firm_spy() )
				{
					spyPtr->notify_cloaked_nation_flag = 0;		// reset it so the player can control it
					info.disp();
					return;
				}
			}
			else
			{
				// packet structure <spy recno>
				short *shortPtr = (short *)remote.new_send_queue_msg(MSG_SPY_LEAVE_FIRM, sizeof(short) );
				*shortPtr = spyPtr->spy_recno;
			}
		}

		//------ reward spy ---------//

		else if( button_spy_reward.detect() )
		{
			spyPtr->reward(COMMAND_PLAYER);
		}

		//------- change spy action ---------//

		else if( button_spy_action.detect() )		// set action mode
		{
			if( !remote.is_enable() )
			{
				spyPtr->set_next_action_mode();
				disp_spy_menu( INFO_UPDATE );
			}
			else
			{
				// packet structure <spy recno>
				short *shortPtr = (short *)remote.new_send_queue_msg(MSG_SPY_CYCLE_ACTION, sizeof(short) );
				*shortPtr = spyPtr->spy_recno;
			}
		}

		//------ capture firm ---------//

		else if( button_capture.detect() )
		{
			int spyRecno = can_player_spy_capture();

			if( spyRecno )
			{
				Spy* capturerSpy = spy_array[spyRecno];

				if( !remote.is_enable() )
				{
					capturerSpy->capture_firm();
				}
				else
				{
					// packet structure <spy recno>
					short *shortPtr = (short *)remote.new_send_queue_msg(MSG_SPY_CAPTURE_FIRM, sizeof(short) );
					*shortPtr = capturerSpy->spy_recno;
				}
			}
		}

		//------ view secret ---------//

		else if( button_view_secret.detect() )
		{
			action_spy_recno = spyPtr->spy_recno;
			firm_menu_mode   = FIRM_MENU_VIEW_SECRET;
			info.disp();
		}

		//-------- assassinate ------//

		else if( button_assassinate.detect() )
		{
			spyPtr->assassinate( overseer_recno, COMMAND_PLAYER );
		}
	}

	//--------- select briber mode --------//

	else if( firm_menu_mode == FIRM_MENU_SELECT_BRIBER )
	{
		if( button_bribe.detect() )
		{
			action_spy_recno = spyPtr->spy_recno;
			firm_menu_mode   = FIRM_MENU_SET_BRIBE_AMOUNT;
			info.disp();
		}
	}
	else
	{
		err_here();
	}

	//--------- detect cancel button --------//

	if( button_cancel.detect() )
	{
		firm_menu_mode = FIRM_MENU_MAIN;
		info.disp();
	}
}
Esempio n. 18
0
//--------- Begin of function Firm::spy_bribe ---------//
//
// The money the spy offers to bribe the unit.
//
// <int>   bribeAmount	  - the amount offered
// <short> birberSpyRecno - spy recno of the briber
// <short> workerId		  - if 0, then bribe the overseer,
//									 if >0, then bribe a worker.
//
// return: <int> >0 - bribing succeeded, return the spy recno of the bribed unit (as it has been turned into a spy)
//					  0 - bribing failed
//
int Firm::spy_bribe(int bribeAmount, short briberSpyRecno, short workerId)
{
	if( !can_spy_bribe(workerId, spy_array[briberSpyRecno]->true_nation_recno) )		// this can happen in multiplayer as there is a one frame delay when the message is sent and when it is processed
		return 0;

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

	int succeedChance = spy_bribe_succeed_chance(bribeAmount, briberSpyRecno, workerId);

	Spy* spyPtr = spy_array[briberSpyRecno];

	nation_array[spyPtr->true_nation_recno]->add_expense( EXPENSE_BRIBE, (float) bribeAmount, 0 );

	//------ if the bribe succeeds ------//

	if( succeedChance > 0 && misc.random(100) < succeedChance )
	{
		int spyRecno = spy_array.add_spy();		// add a new Spy record

		Spy* newSpy = spy_array[spyRecno];

		newSpy->spy_skill = 10;
		newSpy->action_mode = SPY_IDLE;
		newSpy->spy_loyalty = MIN( 100, MAX(30,succeedChance) );		// within the 30-100 range

		newSpy->true_nation_recno    = spyPtr->true_nation_recno;
		newSpy->cloaked_nation_recno = spyPtr->cloaked_nation_recno;

		if( workerId )
		{
			Worker* workerPtr = worker_array+workerId-1;

			workerPtr->spy_recno = spyRecno;
			newSpy->race_id = workerPtr->race_id;
			newSpy->name_id = workerPtr->name_id;

			err_when( newSpy->race_id < 1 || newSpy->race_id > MAX_RACE );

			if( !newSpy->name_id )		// if this worker does not have a name, give him one now as a spy must reserve a name (see below on use_name_id() for reasons)
				newSpy->name_id = race_res[newSpy->race_id]->get_new_name_id();
		}
		else if( overseer_recno )
		{
			Unit* unitPtr = unit_array[overseer_recno];

			unitPtr->spy_recno = spyRecno;
			newSpy->race_id = unitPtr->race_id;
			newSpy->name_id = unitPtr->name_id;

			err_when( newSpy->race_id < 1 || newSpy->race_id > MAX_RACE );
		}
		else
			err_here();

		newSpy->set_place( SPY_FIRM, firm_recno );

		//-- Spy always registers its name twice as his name will be freed up in deinit(). Keep an additional right because when a spy is assigned to a town, the normal program will free up the name id., so we have to keep an additional copy

		race_res[newSpy->race_id]->use_name_id(newSpy->name_id);

		bribe_result = BRIBE_SUCCEED;

		if( firm_recno == firm_array.selected_recno )
			info.disp();

		return newSpy->spy_recno;
	}
	else //------- if the bribe fails --------//
	{
		spyPtr->get_killed(0);		// the spy gets killed when the action failed.
											// 0 - don't display new message for the spy being killed, so we already display the msg on the interface
		bribe_result = BRIBE_FAIL;

		if( firm_recno == firm_array.selected_recno )
			info.disp();

		return 0;
	}
}
Esempio n. 19
0
//-------- Begin of function SpyArray::catch_spy ------//
//
// <int> spyPlace - either SPY_TOWN or SPY_FIRM
// <int> spyPlacePara - town_recno or firm_recno
//
int SpyArray::catch_spy(int spyPlace, int spyPlacePara)
{
	int nationRecno, totalPop;

	if( spyPlace == SPY_TOWN )
	{
		Town* townPtr = town_array[spyPlacePara];

		nationRecno = townPtr->nation_recno;
		totalPop    = townPtr->population;
	}
	else if( spyPlace == SPY_FIRM )
	{
		Firm* firmPtr = firm_array[spyPlacePara];

		nationRecno = firmPtr->nation_recno;
		totalPop    = firmPtr->worker_count + (firmPtr->overseer_recno>0);
	}
	else
		err_here();

	//--- calculate the total of anti-spy skill in this town ----//

	int enemySpyCount=0, counterSpySkill=0;
	Spy* spyPtr;

	int i;
	for( i=size() ; i>0 ; i-- )
	{
		if( is_deleted(i) )
			continue;

		spyPtr = spy_array[i];

		if( spyPtr->spy_place == spyPlace &&
			 spyPtr->spy_place_para == spyPlacePara )
		{
			if( spyPtr->true_nation_recno == nationRecno )
				counterSpySkill += spyPtr->spy_skill;
			else
				enemySpyCount++;
		}
	}

	//----- if all villagers are enemy spies ----//

	if( enemySpyCount == totalPop )
		return 0;

	err_when( enemySpyCount > totalPop );

	//-------- try to catch enemy spies now ------//

	for( i=spy_array.size() ; i>0 ; i-- )
	{
		if( spy_array.is_deleted(i) )
			continue;

		spyPtr = spy_array[i];

		if( spyPtr->action_mode == SPY_IDLE )		// it is very hard to get caught in sleep mode
			continue;

		if( spyPtr->spy_place == spyPlace &&
			 spyPtr->spy_place_para == spyPlacePara &&
			 spyPtr->true_nation_recno != nationRecno )	// doesn't get caught in sleep mode
		{
			int escapeChance = 100 + spyPtr->spy_skill - counterSpySkill;

			escapeChance = MAX( spyPtr->spy_skill/10, escapeChance );

			if( m.random(escapeChance) == 0 )
			{
				spyPtr->get_killed(); 		// only catch one spy per calling
				return 1;
			}
		}
	}

	return 0;
}