Пример #1
0
//--------- Begin of function Firm::detect_worker_list ---------//
//
int Firm::detect_worker_list()
{
	if( !should_show_info() )
		return 0;

	//------- detect buttons on hiring firm workers -------//

	int i, x, y;
	int liveInTown = firm_res[firm_id]->live_in_town;

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

		switch( mouse.any_click(x, y, x+27, y+23, LEFT_BUTTON) ? 1 : (mouse.any_click(x, y, x+27, y+23, RIGHT_BUTTON) ? 2 : 0) )
		{
			case 1:         // left button to select worker
				selected_worker_id = i+1;
				return 1;

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

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

	return 0;
}
Пример #2
0
//--------- Begin of function FirmCamp::patrol_all_soldier ---------//
//
// return 1 if there is enough space for patroling all soldiers
// return 0 otherwise
//
int FirmCamp::patrol_all_soldier()
{
	err_when(!worker_array);    // this function shouldn't be called if this firm does not need worker

	//------- detect buttons on hiring firm workers -------//

	err_when(worker_count>MAX_WORKER);
	
	#ifdef DEBUG
		int loopCount=0;
	#endif

	short unitRecno;
	int mobileWorkerId = 1;

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

	while(worker_count>0 && mobileWorkerId<=worker_count)
	{
		err_when(++loopCount > 100);

		if(worker_array[mobileWorkerId-1].skill_id==SKILL_LEADING)
		{
			unitRecno = mobilize_worker(mobileWorkerId, COMMAND_AUTO);

			patrol_unit_array[patrol_unit_count++] = unitRecno;
			err_when(patrol_unit_count>MAX_WORKER);
		}
		else
		{
			mobileWorkerId++;
			continue;
		}

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

		if(overseer_recno)
		{
			Unit* unitPtr = unit_array[unitRecno];
			unitPtr->team_id = unit_array.cur_team_id;   // define it as a team
			unitPtr->leader_unit_recno = overseer_recno;
			unitPtr->update_loyalty();							// the unit is just assigned to a new leader, set its target loyalty

			err_when( unit_array[overseer_recno]->rank_id != RANK_KING &&
					  unit_array[overseer_recno]->rank_id != RANK_GENERAL );

			if( nation_recno == nation_array.player_recno )
			{
				unitPtr->selected_flag = 1;
				unit_array.selected_count++;
			}
		}
	}

	unit_array.cur_team_id++;
	return 1;
}
Пример #3
0
//--------- Begin of function FirmCamp::defense ---------//
//### begin alex 15/10 ###//
//void FirmCamp::defense(short targetRecno)
void FirmCamp::defense(short targetRecno, int useRangeAttack)
//#### end alex 15/10 ####//
{
	//### begin alex 15/10 ###//
	//--******* BUGHERE , please provide a reasonable condition to set useRangeAttack to 1
	if(unit_array[targetRecno]->mobile_type!=UNIT_LAND)
		useRangeAttack = 1;
	else
		useRangeAttack = 0;
	//#### end alex 15/10 ####//

	if( !defense_flag )
		return;

	//--------------- define parameters ------------------//

	DefenseUnit *defPtr, *defPtr2;
	Unit *unitPtr;
	short unitRecno;
	int numOfUnitInside = worker_count + (overseer_recno>0);
	int i, j;

	if(employ_new_worker)
	{
		//---------- reset unit's parameters in the previous defense -----------//
		defPtr = defense_array;
		for(int i=0; i<=MAX_WORKER; i++, defPtr++)
		{
			if(defPtr->status==OUTSIDE_CAMP && defPtr->unit_recno && !unit_array.is_deleted(defPtr->unit_recno))
			{
				unitPtr = unit_array[defPtr->unit_recno];
				if(unitPtr->nation_recno==nation_recno && unitPtr->action_misc==ACTION_MISC_DEFENSE_CAMP_RECNO &&
					unitPtr->action_misc_para==firm_recno)
				{
					unitPtr->clear_unit_defense_mode();
					err_when(unitPtr->in_auto_defense_mode());
				}
			}
		}
		memset(defense_array, 0, sizeof(DefenseUnit)*(MAX_WORKER+1));
	}

	//------------------------------------------------------------------//
	// check all the exist(not dead) units outside the camp and arrange
	// them in the front part of the array.
	//------------------------------------------------------------------//
	j = 0;
	defPtr2 = defense_array;

	if(!employ_new_worker)	// some soliders may be outside the camp
	{
		for(i=0, defPtr=defense_array; i<=MAX_WORKER; i++, defPtr++)
		{
			if(!defPtr->unit_recno)
				continue;	// a free slot

			if(unit_array.is_deleted(defPtr->unit_recno))
			{
				defPtr->unit_recno = 0;
				continue;	// unit is dead
			}

			//----------------------------------------------------------------//
			// arrange the recno in the array front part
			//----------------------------------------------------------------//
			if(defPtr->status==OUTSIDE_CAMP)
			{
				unitPtr = unit_array[defPtr->unit_recno];

				//-------------- ignore this unit if it is dead --------------------//
				if(unitPtr->is_unit_dead())
					continue;

				if(!unitPtr->in_auto_defense_mode())
					continue; // the unit is ordered by the player to do other thing, so cannot control it afterwards

				//--------------- the unit is in defense mode ----------------//
				defPtr2->unit_recno = defPtr->unit_recno;
				defPtr2->status = OUTSIDE_CAMP;
				j++;
				defPtr2++;
			}
		}

		err_when(defPtr2 + (MAX_WORKER-j+1) > defense_array + MAX_WORKER + 1);
		memset(defPtr2, 0, sizeof(DefenseUnit)*(MAX_WORKER-j+1));
	}
	
	set_employ_worker(0);

	//------------------------------------------------------------------//
	// the unit outside the camp should be in defense mode and ready to
	// attack new target
	//------------------------------------------------------------------//
	for(i=0, defPtr=defense_array; i<j; i++, defPtr++)
	{
		//------------------------------------------------------------------//
		// order those unit outside the camp to attack the target
		//------------------------------------------------------------------//
		unitPtr = unit_array[defPtr->unit_recno];
		defense_outside_camp(defPtr->unit_recno, targetRecno);
		unitPtr->action_misc = ACTION_MISC_DEFENSE_CAMP_RECNO;
		unitPtr->action_misc_para = firm_recno;
	}

	int mobilizePos = 0;
	//### begin alex 13/10 ###//
	//for(; i<MAX_WORKER && worker_count; i++, defPtr++)
	for(; i<MAX_WORKER && mobilizePos<worker_count; i++, defPtr++)
	//#### end alex 13/10 ####//
	{
		err_when(mobilizePos >= worker_count);

		//------------------------------------------------------------------//
		// order those soldier inside the firm to move to target for attacking
		// keep those unable to attack inside the firm
		//------------------------------------------------------------------//
		//### begin alex 13/10 ###//
		//if(worker_array[mobilizePos].unit_id==UNIT_EXPLOSIVE_CART)
		if(worker_array[mobilizePos].unit_id==UNIT_EXPLOSIVE_CART ||
			(useRangeAttack && worker_array[mobilizePos].max_attack_range()==1))
		//#### end alex 13/10 ####//
		{
			mobilizePos++;
			continue;
		}
				
		unitRecno = mobilize_worker(mobilizePos+1, COMMAND_AUTO);
		//unitRecno = mobilize_worker(1, COMMAND_AUTO);        // always record 1 as the workers info are moved forward from the back to the front
		if(!unitRecno)
			break;
		
		Unit* unitPtr = unit_array[unitRecno];
		unitPtr->team_id = unit_array.cur_team_id;   // define it as a team
		unitPtr->action_misc = ACTION_MISC_DEFENSE_CAMP_RECNO;
		unitPtr->action_misc_para = firm_recno; // store the firm_recno for going back camp

		defense_inside_camp(unitRecno, targetRecno);
		defPtr->unit_recno = unitRecno;
		defPtr->status = OUTSIDE_CAMP;
	}

	/*if(overseer_recno>0)
	{
		//------------------------------------------------------------------//
		// order those overseer inside the firm to move to target for attacking
		//------------------------------------------------------------------//
		unitPtr = unit_array[overseer_recno];
		assign_overseer(0);
		unitPtr->team_id = unit_array.cur_team_id;   // define it as a team
		unitPtr->action_misc = ACTION_MISC_DEFENSE_CAMP_RECNO;
		unitPtr->action_misc_para = firm_recno; // store the firm_recno for going back camp

		defense_inside_camp(unitPtr->sprite_recno, targetRecno);
		defPtr->unit_recno = unitPtr->sprite_recno;
		defPtr->status = OUTSIDE_CAMP;
	}*/

	unit_array.cur_team_id++;
}