Example #1
0
//--------- Begin of function FirmCamp::detect_soldier_list ---------//
//
// <int> selecteSpyMenu        0=main menu; 1=selecting spy
// when selectSpyMenu is 0, return 1 if left click on a unit, return 2 if right click on a unit
// when selectSpyMenu is 1, return spy_recno of the clicked spy, 0 if no own spy is clicked
//
int FirmCamp::detect_soldier_list(int selectSpyMenu)
{
	int dispY1 = disp_soldier_list_y1;

	// display in ascending order to select the overseer first

	for( int i = 0; i <= soldier_count; ++i )
	{
		// display soldier i

		int row = i/SOLDIER_PER_ROW;
		int x = INFO_X1 + 18 + (i % SOLDIER_PER_ROW) * SOLDIER_X_SPACING;
		int y = INFO_Y1 + 50 + row * SOLDIER_Y_SPACING;
		int yHp = INFO_Y1 + 7 + row * SOLDIER_Y_SPACING;

		int windowX1 = INFO_X1 + 16;
		int windowX2 = INFO_X1 + 220;
		int windowY1 = INFO_Y1 + 5 + row * 84;	// 5,89
		int windowY2 = windowY1 + 80 - 1 ;

		int unitId;
		int hp;
		int maxHp;
		// ##### begin Gilbert 21/9 ######//
		int combatLevel;
		int skillLevel;
		int loyalty;
		// ##### end Gilbert 21/9 ######//
		int ownSpy;

		if( i==0 )
		{
			if( !overseer_recno )
				continue;

			// overseer
			Unit *overseer = unit_array[overseer_recno];
			unitId = overseer->unit_id;

			hp = (int) overseer->hit_points;
			maxHp = overseer->max_hit_points();
			combatLevel = (int) overseer->combat_level();
			skillLevel = (int) overseer->skill_level();

			if( overseer->rank_id != RANK_GENERAL )
				loyalty = overseer->loyalty;
			else
				loyalty = -1;		// king or other(?)

			ownSpy = overseer->is_own_spy() ? overseer->spy_recno : 0;
		}
		else
		{
			// soldier
			Soldier *soldierPtr = &soldier_array[i-1];
			unitId = soldierPtr->unit_id;

			hp = soldierPtr->hit_points;
			maxHp = soldierPtr->max_hit_points();
			combatLevel = (int) soldierPtr->combat_level();
			skillLevel = (int) soldierPtr->skill_level();

			if( soldierPtr->race_id )
				loyalty = soldierPtr->loyalty;
			else
				loyalty = -1;
			ownSpy = soldierPtr->is_own_spy() ? soldierPtr->spy_recno : 0;
		}

		if( selectSpyMenu && !ownSpy )
			continue;

		int rc = info.draw_unit_icon( x+SOLDIER_X_SPACING/2, y,
			unitId, nation_recno, 
			windowX1, windowY1, windowX2, windowY2, 24 );		// detect left button (8) and right button(16)

		if( !rc )
			continue;

		if( selectSpyMenu == 0 )
		{
			// -------- main menu ---------//

			if( rc & 8 )
			{
				// ----- left click select soldier/overseer -------//

				selected_soldier_id = i;
				return 1;
			}
			else if( rc & 16 && is_own() )
			{
				// ------ right click mobilize solidier/overseer ------//

				if( i == 0 )
				{
					if(remote.is_enable())
					{
						// packet structure : <firm recno>
						short *shortPtr=(short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_OVERSEER, sizeof(short));
						shortPtr[0] = firm_recno;
					}
					else
					{
						assign_overseer(0);		// the overseer quits the camp
					}
				}
				else
				{
					// #### begin Gilbert 26/1 #####//
					if( !soldier_array[i-1].is_under_training() )
						mobilize_soldier(i, COMMAND_PLAYER);
					else
						cancel_train_soldier(i, COMMAND_PLAYER);
					// #### end Gilbert 26/1 #####//
				}
				return 2;
			}
		}
		else if( selectSpyMenu == 1 )
		{
			if( rc & 8 && ownSpy )
			{
				selected_soldier_id = i;
				return ownSpy;
			}
		}
	}

	return 0;

	/*
	if( !should_show_info() )
		return 0;

	if( is_own() )
	{
		//------ detect the overseer button -----//
		int rc = mouse.single_click(INFO_X1+6, INFO_Y1+58,
					INFO_X1+5+UNIT_LARGE_ICON_WIDTH, INFO_Y1+57+UNIT_LARGE_ICON_HEIGHT, 2 );

		if( rc==1 )
		{
			selected_soldier_id = 0;
			return 1;
		}
		else if( rc==2 && is_own() )
		{
			if(remote.is_enable())
			{
				// packet structure : <firm recno>
				short *shortPtr=(short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_OVERSEER, sizeof(short));
				shortPtr[0] = firm_recno;
			}
			else
			{
				assign_overseer(0);		// the overseer quits the camp
			}
			return 1;
		}
	}

	//------- detect buttons on hiring firm soldiers -------//

	int i, x, y;

	for( i=0 ; i<soldier_count ; i++ )
	{
		x = INFO_X1+6+i%4*50;
		y = pop_disp_y1+1+i/4*29;

		switch( mouse.single_click(x, y, x+27, y+23, 2) )
		{
		case 1:         // left button to select soldier
			selected_soldier_id = i+1;
			return 1;

		case 2:
			if( is_own() )		// only if this is our own firm
			{
				//--- if the town where the unit lives belongs to the nation of this firm ---//

				mobilize_soldier(i+1, COMMAND_PLAYER);
				return 1;
			}
			break;
		}
	}

	return 0;
	*/
}
Example #2
0
//--------- Begin of function FirmCamp::patrol_all_soldier ---------//
//
// [int] overseerRecno - if this is given, this will be used instead
//								 of looking at overseer_recno.
//
// return 1 if there is enough space for patroling all soldiers
// return 0 otherwise
//
int FirmCamp::patrol_all_soldier(int overseerRecno, char patrolType)
{
	err_when(!soldier_array);    // this function shouldn't be called if this firm does not need soldier

	//------- detect buttons on hiring firm soldiers -------//

	err_when(soldier_count>MAX_SOLDIER);

	#ifdef DEBUG
		int loopCount=0;
	#endif

	short unitRecno;
	int mobileSoldierId = 1;

	patrol_unit_count = 0;		// reset it, it will be increased later

	for( mobileSoldierId = 1; mobileSoldierId <= soldier_count ; ++mobileSoldierId )
	{
		err_when(++loopCount > 100);

		if( soldier_array[mobileSoldierId-1].is_under_training() )
			continue;

		if( (soldier_array[mobileSoldierId-1].hit_points < 
			  soldier_array[mobileSoldierId-1].max_hit_points() - 25) &&
			  patrolType == 2
			)
			continue;

		unitRecno = mobilize_soldier(mobileSoldierId, COMMAND_AUTO);

		patrol_unit_array[patrol_unit_count++] = unitRecno;
		err_when(patrol_unit_count>MAX_SOLDIER);

		if(!unitRecno)
			return 0; // keep the rest soldiers as there is no space for creating the unit

		--mobileSoldierId;	// if can mobilize successfully, mobileSoldierId is unchanged

//		if( !overseerRecno )
		if( !overseerRecno && patrolType == 0)
			overseerRecno = overseer_recno;

		Unit* unitPtr = unit_array[unitRecno];
		if(overseerRecno)
		{			
			unitPtr->update_loyalty();							// the unit is just assigned to a new leader, set its target loyalty

			err_when( unit_array[overseerRecno]->rank_id != RANK_KING &&
					  unit_array[overseerRecno]->rank_id != RANK_GENERAL );
			if( nation_recno == nation_array.player_recno )
				unitPtr->select();		
		}
		else
			if( nation_recno == nation_array.player_recno )	
				unitPtr->select(true);
	}

	return 1;
}
Example #3
0
//--------- Begin of function FirmMonsterFortress::detect_soldier_list ---------//
//
// <int> selecteSpyMenu        0=main menu; 1=selecting spy
// when selectSpyMenu is 0, return 1 if left click on a unit, return 2 if right click on a unit
// when selectSpyMenu is 1, return spy_recno of the clicked spy, 0 if no own spy is clicked
//
int FirmMonsterFortress::detect_soldier_list(int selectSpyMenu)
{
	int dispY1 = disp_soldier_list_y1;

	// display in ascending order to select the overseer first

	for( int i = 1; i <= archer_count; ++i )
	{
		// display soldier i

		int x = INFO_X1 + 24 + (i-1) * ARHCER_X_SPACING;
		int y = INFO_Y1 + 136;
		int yHp = INFO_Y1 + 93;

		int windowX1 = INFO_X1 + 16;
		int windowX2 = INFO_X1 + 220;
		int windowY1 = INFO_Y1 + 89;
		int windowY2 = windowY1 + 80 - 1 ;

		int unitId;
		int hp;
		int maxHp;
		int combatLevel;
		int skillLevel;
		int loyalty;
		int ownSpy;
		int itemId;

		Unit *unitPtr = unit_array[archer_unit_recno[i-1]];
		unitId = unitPtr->unit_id;

		hp = (int) unitPtr->hit_points;
		maxHp = unitPtr->max_hit_points();
		combatLevel = (int) unitPtr->combat_level();
		skillLevel = (int) unitPtr->skill_level();

		if( unitPtr->rank_id != RANK_GENERAL )
			loyalty = -1;		// king or other(?)
		else
			loyalty = unitPtr->loyalty;

		ownSpy = unitPtr->is_own_spy() ? unitPtr->spy_recno : 0;
		itemId = unitPtr->item.id;

		if( selectSpyMenu && !ownSpy )			// skip displaying spy
			continue;

		int rc = info.draw_unit_icon( x+ARHCER_X_SPACING/2, y,
			unitId, nation_recno, 
			windowX1, windowY1, windowX2, windowY2, 24 );		// detect left button (8) and right button(16)

		if( !rc )
			continue;

		if( selectSpyMenu == 0 )
		{
			// -------- main menu ---------//

			if( rc & 8 )
			{
				// ----- left click select soldier/overseer -------//

				selected_archer_id = i;
				swap_item_src = selected_archer_id;		// turn on the selecting swap target
				swap_item_id = itemId;
				return 1;
			}
			else if( rc & 16 && is_own() )
			{
				// ------ right click mobilize solidier/overseer ------//

				mobilize_soldier(i, COMMAND_PLAYER);
				return 2;
			}
		}
		else if( selectSpyMenu == 1 )
		{
			if( rc & 8 && ownSpy )
			{
				selected_archer_id = i;
				return ownSpy;
			}
		}
	}

	// swaping item

	if( is_own() && selectSpyMenu == 0 && swap_item_src >= 0 && mouse.release_click() )
	{
		if( pointed_archer_id >= 0 )
		{
			swap_item( swap_item_src, pointed_archer_id, swap_item_id, COMMAND_PLAYER );
		}
		else
		{
			swap_item_src = -1;		// reset from selecting swap target
		}
	}

	return 0;
}