Example #1
0
//------ Begin of function FirmWork::process_independent_town_worker -----//
//
// Process workers from independent towns.
//
// When workers work for a foreign firm, the overall resistance of
// the worker's town towards that nation decreases.
//
void FirmWork::process_independent_town_worker()
{
	#define RESISTANCE_DECREASE_PER_WORKER	 float(0.2)		// resistance decrease per month every 15 days

	Town* townPtr;

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

		townPtr = town_array[ worker_array[i].town_recno ];

		if( townPtr->nation_recno==0 )		// if it's an independent town
		{
			townPtr->change_resistance( nation_recno, -RESISTANCE_DECREASE_PER_WORKER );
		}
	}
}
Example #2
0
//------- Begin of function Firm::being_killed ------//
//
// <BaseObj*> attackerObj - this can be NULL if the attacker no longer
//									 exists (the damage is caused by a bullet.)
//
void Firm::being_killed(BaseObj* attackerObj)
{
	se_res.sound(center_x, center_y, 1, 'F', firm_id, "DIE" );

	if( nation_recno == nation_array.player_recno && attackerObj )		//BUGHERE
		news_array.firm_destroyed(firm_recno, attackerObj);

	// ######## begin Gilbert 17/6 ########//
	if( nation_recno == 0 && firm_id == FIRM_LAIR && is_monster() )
	{
		news_array.monster_firm_destroyed( monster_id(), center_x, center_y );
	}
	// ######## end Gilbert 17/6 ########//

	if( nation_recno )
	{
		if( attackerObj && attackerObj->nation_recno )
			nation_array[attackerObj->nation_recno]->enemy_firm_destroyed++;

		if( nation_recno )
			nation_array[nation_recno]->own_firm_destroyed++;
	}

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

	if( attackerObj && attackerObj->nation_recno )
	{
		Nation* attackerNation = nation_array[attackerObj->nation_recno];

		//-- destroying a monster firm raise the attacking nation's reputation --//

		if( is_monster() )
		{
			float repIncrease = (float) max_hit_points() / 600;

			//-- if the lair is enslaving the towns, increase the reputation bonus --//

			if( cast_to_FirmLair() )
			{
				int tributeAmount = cast_to_FirmLair()->collect_town_tribute(0);

				repIncrease += (float) tributeAmount / 600;
			}

			attackerNation->change_reputation(repIncrease);

			//--- when destroying an enslaving Fryhtan lair, the independent towns enslaved by it will reduce its resistance towards you by 30 points ---//

			if( cast_to_FirmLair() )
			{
				int   i;
				Town* townPtr;

				for( i=0 ; i<linked_town_count ; i++ )
				{
					if(town_array.is_deleted(linked_town_array[i]))
						continue;

					townPtr = town_array[linked_town_array[i]];

					//--- if it is a linked independent town ---//

					if( townPtr->nation_recno == 0 &&
						 // ####### begin Gilbert 9/3 ########//
						 nation_recno &&
						 // ####### end Gilbert 9/3 ########//
						 townPtr->resistance(nation_recno) < MONSTER_COLLECT_TOWN_TRIBUTE_LOYALTY )
					{
						townPtr->change_resistance(attackerObj->nation_recno, -30);
					}
				}
			}
		}

		//------ destroyng a building gives money ------//

		float killMoney = (float) (firm_res[firm_id]->setup_cost + firm_recno%100) / 3;		// add some randomness

		attackerNation->add_income( INCOME_TREASURE, killMoney );
		attackerNation->increased_cash = killMoney;
	}

	firm_array.del_firm(firm_recno);
}
Example #3
0
//--------- Begin of function UnitGod::cast_on_loc ---------//
//
void UnitGod::cast_on_loc(int castXLoc, int castYLoc)
{
	Location* locPtr = world.get_loc( castXLoc, castYLoc );

	//--- if there is any unit on the location ---//

	if( locPtr->has_unit(UNIT_LAND) )
	{
		cast_on_unit( locPtr->unit_recno(UNIT_LAND), 1 );
	}
	else if( locPtr->has_unit(UNIT_SEA) )
	{
		Unit* unitPtr = unit_array[ locPtr->unit_recno(UNIT_SEA) ];

		//-- only heal human units belonging to our nation in ships --//

		if( unitPtr->nation_recno == nation_recno &&
			 unit_res[unitPtr->unit_id]->unit_class == UNIT_CLASS_SHIP )
		{
			UnitMarine* unitMarine = (UnitMarine*) unitPtr;

			for( int i=0 ; i<unitMarine->unit_count ; i++ )
			{
				int divider = 4;		// the size of a ship is 4 locations (2x2)

				cast_on_unit( unitMarine->unit_recno_array[i], divider );		// the effects are weaken on ship units, only 50% of the original effects
			}
		}
	}

	//--------- on firms ---------//

	else if( locPtr->is_firm() )
	{
		Firm* firmPtr = firm_array[ locPtr->firm_recno() ];
		int	divider = (firmPtr->loc_x2-firmPtr->loc_x1+1) * (firmPtr->loc_y2-firmPtr->loc_y1+1);
		if( god_id == GOD_ZULU )
			divider = 1;		// range of zulu god is 1, no need to divide

		if( firmPtr->overseer_recno )
		{
			cast_on_unit( firmPtr->overseer_recno, divider );
		}

		if( firmPtr->worker_array && firm_res[firmPtr->firm_id]->live_in_town==0 )
		{
			Worker* workerPtr = firmPtr->worker_array;

			for( int i=0 ; i<firmPtr->worker_count ; i++, workerPtr++ )
			{
				cast_on_worker(workerPtr, firmPtr->nation_recno, divider);
			}
		}
	}

	//--------- on towns ----------//

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

		if( god_id == GOD_JAPANESE && townPtr->nation_recno != nation_recno)
		{
			int divider = STD_TOWN_LOC_WIDTH * STD_TOWN_LOC_HEIGHT;

			for( int i=0 ; i<MAX_RACE ; i++ )
			{
				if( townPtr->race_pop_array[i]==0 )
					continue;

				float changePoints = (float)7 + misc.random(8);		// decrease 7 to 15 loyalty points instantly

				if( townPtr->nation_recno )
					townPtr->change_loyalty(i+1, -changePoints/divider);
				else
					townPtr->change_resistance(i+1, nation_recno, -changePoints/divider);
			}
		}
		else if( god_id == GOD_EGYPTIAN && townPtr->nation_recno == nation_recno)
		{
			int headCount;
			int raceId;

			for( headCount = 5; headCount > 0 && townPtr->population < MAX_TOWN_GROWTH_POPULATION
				&& (raceId = townPtr->pick_random_race(1,1)); --headCount )
			{
				townPtr->inc_pop(raceId, 0, (int)townPtr->race_loyalty_array[raceId-1]);
			}
		}
	}
}