Beispiel #1
0
//------- Begin of function FirmInn::recover_hit_point -------//
//
// Units recover their hit points. Units assigned to this firm
// by players will have lower than maximum hit points
//
void FirmInn::recover_hit_point()
{
	InnUnit* innUnit = inn_unit_array;

	for( int i=0 ; i<inn_unit_count ; i++, innUnit++ )
	{
		int hpInc = 1;
		short maxHp = innUnit->max_hit_points();

		//------- item effect -------- //

		hpInc += ( 1 + innUnit->item.ability(ITEM_ABILITY_RECOVERY) ) / 2;

		//------- increase soldier hit points --------//

		if( innUnit->hit_points < maxHp )
		{
			innUnit->hit_points += hpInc;

			if( innUnit->hit_points > maxHp )
				innUnit->hit_points = maxHp;
		}
	}
}
Beispiel #2
0
void FirmInn::add_inn_unit(int raceId)
{
	err_when( inn_unit_count >= MAX_INN_UNIT );

	InnUnit *innUnit = inn_unit_array+inn_unit_count;
	RaceInfo *raceInfo = race_res[raceId];

	int spyFlag = 0;	// must determine before inn_unit_count increase

	if( count_soldier() >= MAX_INN_UNIT/2 )
		spyFlag = 1;
	else if( count_spy() >= MAX_INN_UNIT/2 )
		spyFlag = 0;
	else
		spyFlag = misc.random(2);

	memset( innUnit, 0, sizeof(InnUnit) );

	inn_unit_count++;

	//---- determine whether the unit is a spy or a military unit ----//

	if( !spyFlag )		// a military unit
	{
		//------- create a unit now -----------//

		int unitRecno;

		if( misc.random(20)==0 )		// 5% have a hero
		{
			unitRecno = hero_res.create_hero( -1, -1, 0, 0, 0, 0, 1);		// -1 - create the unit as an invisible unit
		}																								// last 1 - the heroes are for hire, check the HeroInfo::for_hire before adding it
		else		//---- just create a unit, not a hero  -----//
		{
			int unitId;

			int heroPower = 20 + misc.random(20);

			if( misc.random(2)==0 )
				unitId = raceInfo->infantry_unit_id;
			else
				unitId = raceInfo->special_unit_id;

			unitRecno = hero_res.create_powerful_unit( -1, -1, 0, unitId, heroPower);		// -1 - create the unit as an invisible unit
		}

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

		if( !unitRecno )
		{
			inn_unit_count--;
			return;
		}

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

		Unit* unitPtr = unit_array[unitRecno];

		err_when( !unitPtr->unit_id );

		innUnit->hero_id 	  = unitPtr->hero_id;
		innUnit->unit_id	  = unitPtr->unit_id;
		innUnit->skill      = unitPtr->skill;
		innUnit->hit_points = unitPtr->hit_points;
		innUnit->item       = unitPtr->item;
		unitPtr->item.clear();

		unit_array.del(unitRecno);		// delete the unit as it was created temporarily for setting skill and item values
	}
	else							// a spy
	{
		switch( misc.random(3) )
		{
		case 0:					// civilian spy
			innUnit->unit_id = (char) raceInfo->civilian_unit_id;
			innUnit->skill.init(innUnit->unit_id, CITIZEN_COMBAT_LEVEL, 0);
			innUnit->spy_skill			 = 30+misc.random(40);
			break;
		case 1:					// infantry spy
			innUnit->unit_id = (char) raceInfo->infantry_unit_id;
			innUnit->skill.init(innUnit->unit_id, 20+misc.random(30), 20+misc.random(30));	// a spy also have leadership and combat ability, but lower than units with leadership as their main skills
			innUnit->spy_skill			 = 30+misc.random(40);
			break;
		case 2:					// special unit spy
			innUnit->unit_id = (char) raceInfo->special_unit_id;
			innUnit->skill.init(innUnit->unit_id, 30+misc.random(30), 10+misc.random(20));	// a spy also have leadership and combat ability, but lower than units with leadership as their main skills
			innUnit->spy_skill			 = 30+misc.random(40);
			break;
		default:
			err_here();
		}

		if( misc.random(4)==0 )
			innUnit->spy_skill += misc.random(30);

		else if( misc.random(2)==0 )
			innUnit->spy_skill += misc.random(15);
	}

	err_when( !innUnit->unit_id );

	// ------ randomly assign a unique id --------//

	// ###### begin Gilbert 23/2 ######//
	innUnit->unique_id = misc.rand_long();
	// ###### end Gilbert 23/2 ######//

	// ------ set current hit point -------//

	innUnit->hit_points = (float) innUnit->max_hit_points();

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

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