Ejemplo n.º 1
0
// --------- begin of function FirmWork::kill_all_worker --------//
//
void FirmWork::kill_all_worker()
{
	for( int w = worker_count-1; w >= 0; --w )
	{
		//------- decrease population -----//

		if( !town_array.is_deleted(worker_array[w].town_recno) )
		{
			Town *townPtr = town_array[ worker_array[w].town_recno ];

			// ###### begin Gilbert 18/1 #######//
			// ----- kill town spy -------//
			int spySeq;
			if( townPtr->spy_count > 0 && (spySeq = m.random(townPtr->population)) < townPtr->spy_count )
			{
				int spyRecno = spy_array.find_town_spy(townPtr->town_recno, spySeq+1 );
				spy_array.del_spy(spyRecno);
			}
			// ###### end Gilbert 18/1 #######//

			townPtr->population--;
		}
	}

	worker_count = 0;
	selected_worker_id = 0;

	calc_productivity();
}
Ejemplo n.º 2
0
//--------- Begin of function FirmWork::resign_worker ---------//
//
// Resign a worker from the firm.
//
void FirmWork::resign_worker(int workerId)
{
	err_when( !worker_array );    // this function shouldn't be called if this firm does not need worker

	err_when( workerId<1 || workerId>worker_count );

	//------- decrease worker no. and create an unit -----//

	Town *townPtr = town_array[ worker_array[workerId-1].town_recno ];

	townPtr->jobless_population++;

	//------- delete the record from the worker_array ------//

	err_when( worker_count > MAX_WORKER );
	err_when( selected_worker_id > worker_count );

	m.del_array_rec(worker_array, worker_count, sizeof(Worker), workerId);

	if( selected_worker_id > workerId || selected_worker_id == worker_count )
		selected_worker_id--;

	worker_count--;

	err_when( worker_count < 0 );
	err_when( selected_worker_id > worker_count );

	calc_productivity();
}
Ejemplo n.º 3
0
//------ Begin of function FirmWork::set_needed_worker_count ------//
//
void FirmWork::set_needed_worker_count(int neededWorkerCount, char remoteAction)
{
	if( neededWorkerCount > MAX_WORKER )
		neededWorkerCount = MAX_WORKER;

	if( !remoteAction && remote.is_enable() )
	{
		// ##### begin Gilbert 7/10 ######//
		// packet structure : <firm recno> <new needed worker count>
		short *shortPtr = (short *)remote.new_send_queue_msg(MSG_FIRM_SET_WORKER_COUNT, 2*sizeof(short) );
		*shortPtr = firm_recno;
		shortPtr[1] = neededWorkerCount;
		// ##### end Gilbert 7/10 ######//
		return;
	}

	//--- if the new needed worker count is larger than the existing number of workers ---//

	if( worker_count > neededWorkerCount )
	{
		//------ resign local worker -------//

		for(int i=worker_count-1; worker_count > neededWorkerCount && i >= 0 ; i-- )
		{
			Town* townPtr = town_array[ worker_array[i].town_recno ];

			resign_worker(i+1);
		}
	}

	needed_worker_count = neededWorkerCount;

	calc_productivity();
}
Ejemplo n.º 4
0
//---------- Begin of function FirmWork::recruit_worker --------//
//
void FirmWork::recruit_worker()
{
	if( worker_count >= needed_worker_count )
		return;

	err_when( worker_count > needed_worker_count );
	err_when( needed_worker_count > MAX_WORKER );

	//-------- recruit workers from towns --------//

	Town* townPtr;
	int	recruitRating, bestRating=0, bestTownRecno=0;

	for( int i=0 ; i<linked_town_count ; i++ )
	{
		if( linked_town_enable_array[i] != LINK_EE )
			continue;

		townPtr = town_array[linked_town_array[i]];

		err_when( townPtr->nation_recno != nation_recno && townPtr->nation_recno != 0 );		// only recruit from own towns

		if( townPtr->jobless_population==0 )
			continue;

		int townDistance = m.points_distance(townPtr->center_x, townPtr->center_y, center_x, center_y);

		//-------- calculate the recruit rating --------//

		recruitRating = 100 * townPtr->jobless_population / townPtr->population		// relative value
							 + townPtr->jobless_population * 2;									// absolute value

		if( recruitRating > bestRating )
		{
			bestRating 	  = recruitRating;
			bestTownRecno = townPtr->town_recno;
		}
	}

	if( !bestTownRecno )
		return;

	//------- recruit now ---------//

	worker_array[worker_count++].town_recno = bestTownRecno;

	town_array[bestTownRecno]->jobless_population--;

	calc_productivity();
}
Ejemplo n.º 5
0
//--------- Begin of function FirmBase::next_day ---------//
//
void FirmBase::next_day()
{
	//----- call next_day() of the base class -----//

	Firm::next_day();

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

	calc_productivity();

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

	if( info.game_date%15 == firm_recno%15 )			// once a week
	{
		train_unit();
		recover_hit_point();
	}

	//------- increase pray points --------//

	if( overseer_recno && pray_points < MAX_PRAY_POINTS )
	{
		// ###### patch begin Gilbert 21/1 #######//
		if( config.fast_build )
			pray_points += productivity/10;
		else
			pray_points += productivity/100;
		// ###### patch end Gilbert 21/1 #######//

		if( pray_points > MAX_PRAY_POINTS )
			pray_points = (float) MAX_PRAY_POINTS;
	}

	//------ validate god_unit_recno ------//

	if( god_unit_recno )
	{
		if( unit_array.is_deleted(god_unit_recno) )
			god_unit_recno = 0;

	#ifdef DEBUG
		if( god_unit_recno )
		{
			err_when( !unit_array[god_unit_recno]->is_visible() );
			err_when( unit_array[god_unit_recno]->nation_recno != nation_recno );
		}
	#endif
	}
}
Ejemplo n.º 6
0
//---------- Begin of function FirmWork::next_day --------//
//
void FirmWork::next_day()
{
	Firm::next_day();

	//------ recruit workers ---------//

	if( info.game_date%5 == firm_recno%5 )    // recruit workers once 5 days
		recruit_worker();

	//--- reduce independent town resistance if their people work here ---//

	if( info.game_date%15 == firm_recno%15 )
		process_independent_town_worker();

	//----- calculate productivity -----//

	calc_productivity();
}
Ejemplo n.º 7
0
//------ Begin of function FirmWork::resign_all_worker ------//
//
void FirmWork::resign_all_worker()
{
	Town* townPtr;

	for( int i=0 ; i<worker_count ; i++ )
	{
		townPtr = town_array[ worker_array[i].town_recno ];

		townPtr->jobless_population++;

		err_when( townPtr->jobless_population > townPtr->population );
	}

	worker_count=0;
	selected_worker_id = 0;

	calc_productivity();
}
Ejemplo n.º 8
0
//--------- Begin of function FirmMine::produce_raw ---------//
//
// Produce raw materials.
//
void FirmMine::produce_raw()
{
	//----- if stock capacity reached or reserve exhausted -----//

	if( stock_qty == max_stock_qty || reserve_qty==0 )
		return;

	err_when( reserve_qty < 0 );
	err_when( stock_qty > max_stock_qty );

	//------- calculate the productivity of the workers -----------//

	calc_productivity();

	//-------- mine raw materials -------//

	float produceQty = (float) 100 * productivity / 100;

	produceQty = MIN( produceQty, reserve_qty );
	produceQty = MIN( produceQty, max_stock_qty-stock_qty );

	reserve_qty -= produceQty;
	stock_qty	+= produceQty;

	cur_month_production += produceQty;

	site_array[site_recno]->reserve_qty = (int) reserve_qty;		// update the reserve_qty in site_array

	err_when( reserve_qty < 0 );
	err_when( stock_qty > max_stock_qty );

	//---- add news if run out of raw deposit ----//

	if( reserve_qty == 0 )
	{
		site_array.untapped_raw_count++;		// have to restore its first as del_site() will decrease uptapped_raw_count

		site_array.del_site(site_recno);
		site_recno = 0;

		if( nation_recno == nation_array.player_recno )
			news_array.raw_exhaust(raw_id, center_x, center_y);
	}
}
Ejemplo n.º 9
0
//--------- Begin of function FirmFactory::production ---------//
//
void FirmFactory::production()
{
	//----- if stock capacity reached or reserve exhausted -----//

	if( stock_qty == max_stock_qty )
		return;

	err_when( stock_qty > max_stock_qty );

	//------- calculate the productivity of the workers -----------//

	calc_productivity();

	//------- generate revenue for the nation --------//

	float produceQty = (float) 20 * productivity / 100;

	produceQty = MIN( produceQty, max_stock_qty-stock_qty );

	manufacture(produceQty);
}
Ejemplo n.º 10
0
//--------- Begin of function FirmResearch::next_day ---------//
//
void FirmResearch::next_day()
{
	//----- call next_day() of the base class -----//

	Firm::next_day();

	//----------- update population -------------//

	recruit_worker();

	//-------- train up the skill ------------//

	update_worker();

	//--------- calculate productivity ----------//

	calc_productivity();

	//--------- process research ----------//

	process_research();
}