1 #include "Hourly_Update.h"
2 #include "Types.h"
3 #include "Game_Events.h"
4 #include "SoundMan.h"
5 #include "Environment.h"
6 #include "Ambient_Control.h"
7 #include "Quests.h"
8 #include "AIMMembers.h"
9 #include "Strategic_Event_Handler.h"
10 #include "BobbyR.h"
11 #include "Mercs.h"
12 #include "EMail.h"
13 #include "Game_Clock.h"
14 #include "Merc_Hiring.h"
15 #include "Insurance_Contract.h"
16 #include "Strategic_Merc_Handler.h"
17 #include "Strategic_Movement.h"
18 #include "Assignments.h"
19 #include "Strategic_Mines.h"
20 #include "Strategic_Town_Loyalty.h"
21 #include "Map_Screen_Interface.h"
22 #include "Map_Screen_Helicopter.h"
23 #include "Scheduling.h"
24 #include "BobbyRGuns.h"
25 #include "Arms_Dealer_Init.h"
26 #include "Meanwhile.h"
27 #include "Overhead.h"
28 #include "Random.h"
29 #include "Creature_Spreading.h"
30 #include "Strategic_AI.h"
31 #include "Merc_Contract.h"
32 #include "Strategic_Status.h"
33 #include "Soldier_Profile.h"
34 #include "Laptop.h"
35 #include "Campaign.h"
36 #include "Debug.h"
37 
38 extern UINT32	guiTimeStampOfCurrentlyExecutingEvent;
39 extern BOOLEAN gfPreventDeletionOfAnyEvent;
40 
41 
DelayEventIfBattleInProgress(STRATEGICEVENT * pEvent)42 static BOOLEAN DelayEventIfBattleInProgress(STRATEGICEVENT* pEvent)
43 {
44 	STRATEGICEVENT *pNewEvent;
45 	if( gTacticalStatus.fEnemyInSector )
46 	{
47 		pNewEvent = AddAdvancedStrategicEvent(static_cast<StrategicEventFrequency>(pEvent->ubEventType), static_cast<StrategicEventKind>(pEvent->ubCallbackID), pEvent->uiTimeStamp + 180 + Random(121), pEvent->uiParam);
48 		Assert( pNewEvent );
49 		pNewEvent->uiTimeOffset = pEvent->uiTimeOffset;
50 		return TRUE;
51 	}
52 	return FALSE;
53 }
54 
ExecuteStrategicEvent(STRATEGICEVENT * pEvent)55 BOOLEAN ExecuteStrategicEvent( STRATEGICEVENT *pEvent )
56 {
57 	BOOLEAN fOrigPreventFlag;
58 
59 	fOrigPreventFlag = gfPreventDeletionOfAnyEvent;
60 	gfPreventDeletionOfAnyEvent = TRUE;
61 	//No events can be posted before this time when gfProcessingGameEvents is set, otherwise,
62 	//we have a chance of running into an infinite loop.
63 	guiTimeStampOfCurrentlyExecutingEvent = pEvent->uiTimeStamp;
64 
65 	if( pEvent->ubFlags & SEF_DELETION_PENDING)
66 	{
67 		gfPreventDeletionOfAnyEvent = fOrigPreventFlag;
68 		return FALSE;
69 	}
70 
71 	// Look at the ID of event and do stuff according to that!
72 	switch( pEvent->ubCallbackID )
73 	{
74 		case EVENT_CHANGELIGHTVAL:
75 			// Change light to value
76 			gubEnvLightValue = (UINT8)pEvent->uiParam;
77 			if( !gfBasement && !gfCaves )
78 				gfDoLighting = TRUE;
79 			break;
80 		case EVENT_CHECKFORQUESTS:
81 			CheckForQuests( GetWorldDay() );
82 			break;
83 		case EVENT_AMBIENT:
84 			if( pEvent->ubEventType == ENDRANGED_EVENT )
85 			{
86 				if (pEvent->uiParam != NO_SAMPLE) SoundStopRandom(pEvent->uiParam);
87 			}
88 			else
89 			{
90 				pEvent->uiParam = SetupNewAmbientSound( pEvent->uiParam );
91 			}
92 			break;
93 		case EVENT_AIM_RESET_MERC_ANNOYANCE:
94 			ResetMercAnnoyanceAtPlayer( (UINT8) pEvent->uiParam );
95 			break;
96 		//The players purchase from Bobby Ray has arrived
97 		case EVENT_BOBBYRAY_PURCHASE:
98 			BobbyRayPurchaseEventCallback( (UINT8) pEvent->uiParam);
99 			break;
100 		//Gets called once a day ( at BOBBYRAY_UPDATE_TIME).  To simulate the items being bought and sold at bobby rays
101 		case EVENT_DAILY_UPDATE_BOBBY_RAY_INVENTORY:
102 			DailyUpdateOfBobbyRaysNewInventory();
103 			DailyUpdateOfBobbyRaysUsedInventory();
104 			DailyUpdateOfArmsDealersInventory();
105 			break;
106 		//Add items to BobbyR's new/used inventory
107 		case EVENT_UPDATE_BOBBY_RAY_INVENTORY:
108 			AddFreshBobbyRayInventory( (UINT16) pEvent->uiParam );
109 			break;
110 		//Called once a day to update the number of days that a hired merc from M.E.R.C. has been on contract.
111 		// Also if the player hasn't paid for a while Specks will start sending e-mails to the player
112 		case EVENT_DAILY_UPDATE_OF_MERC_SITE:
113 			DailyUpdateOfMercSite( (UINT16)GetWorldDay() );
114 			break;
115 		case EVENT_DAY3_ADD_EMAIL_FROM_SPECK:
116 			AddEmail(MERC_INTRO, MERC_INTRO_LENGTH, SPECK_FROM_MERC, GetWorldTotalMin( ) );
117 			break;
118 		case EVENT_DAY2_ADD_EMAIL_FROM_IMP:
119 			AddEmail(IMP_EMAIL_PROFILE_RESULTS, IMP_EMAIL_PROFILE_RESULTS_LENGTH, IMP_PROFILE_RESULTS, GetWorldTotalMin( ) );
120 			break;
121 		//If a merc gets hired and they dont show up immediately, the merc gets added to the queue and shows up
122 		// uiTimeTillMercArrives  minutes later
123 		case EVENT_DELAYED_HIRING_OF_MERC:
124 			MercArrivesCallback(GetMan(pEvent->uiParam));
125 			break;
126 		//handles the life insurance contract for a merc from AIM.
127 		case EVENT_HANDLE_INSURED_MERCS:
128 			DailyUpdateOfInsuredMercs();
129 			break;
130 		//handles when a merc is killed an there is a life insurance payout
131 		case EVENT_PAY_LIFE_INSURANCE_FOR_DEAD_MERC:
132 			InsuranceContractPayLifeInsuranceForDeadMerc( (UINT8) pEvent->uiParam );
133 			break;
134 		//gets called every day at midnight.
135 		case EVENT_MERC_DAILY_UPDATE:
136 			MercDailyUpdate();
137 			break;
138 		case EVENT_MERC_ABOUT_TO_LEAVE:
139 			FindOutIfAnyMercAboutToLeaveIsGonnaRenew( );
140 			break;
141 		//Whenever any group (player or enemy) arrives in a new sector during movement.
142 		case EVENT_GROUP_ARRIVAL:
143 			GroupArrivedAtSector(*GetGroup((UINT8)pEvent->uiParam), TRUE, FALSE);
144 			break;
145 		case EVENT_MERC_COMPLAIN_EQUIPMENT:
146 			MercComplainAboutEquipment( (UINT8) pEvent->uiParam );
147 			break;
148 		case EVENT_HOURLY_UPDATE:
149 			HandleHourlyUpdate();
150 			break;
151 		case EVENT_MINUTE_UPDATE:
152 			/* unused, used to be empty */
153 			break;
154 		case EVENT_HANDLE_MINE_INCOME:
155 			HandleIncomeFromMines( );
156 			//ScreenMsg( FONT_MCOLOR_DKRED, MSG_INTERFACE, ST::format("Income From Mines at {}", GetWorldTotalMin()) );
157 			break;
158 		case EVENT_SETUP_MINE_INCOME:
159 			PostEventsForMineProduction();
160 			break;
161 		case EVENT_SET_BY_NPC_SYSTEM:
162 			HandleNPCSystemEvent( pEvent->uiParam );
163 			break;
164 		case EVENT_SECOND_AIRPORT_ATTENDANT_ARRIVED:
165 			AddSecondAirportAttendant();
166 			break;
167 		case EVENT_HELICOPTER_HOVER_TOO_LONG:
168 			HandleHeliHoverLong( );
169 			break;
170 		case EVENT_HELICOPTER_HOVER_WAY_TOO_LONG:
171 			HandleHeliHoverTooLong( );
172 			break;
173 		case EVENT_MERC_LEAVE_EQUIP_IN_DRASSEN:
174 			HandleEquipmentLeftInDrassen( pEvent->uiParam );
175 			break;
176 		case EVENT_MERC_LEAVE_EQUIP_IN_OMERTA:
177 			HandleEquipmentLeftInOmerta( pEvent->uiParam );
178 			break;
179 		case EVENT_BANDAGE_BLEEDING_MERCS:
180 			BandageBleedingDyingPatientsBeingTreated( );
181 			break;
182 		case EVENT_DAILY_EARLY_MORNING_EVENTS:
183 			HandleEarlyMorningEvents();
184 			break;
185 		case EVENT_GROUP_ABOUT_TO_ARRIVE:
186 			HandleGroupAboutToArrive();
187 			break;
188 		case EVENT_PROCESS_TACTICAL_SCHEDULE:
189 			ProcessTacticalSchedule( (UINT8)pEvent->uiParam );
190 			break;
191 		case EVENT_BEGINRAINSTORM:
192 			//EnvBeginRainStorm( (UINT8)pEvent->uiParam );
193 			break;
194 		case EVENT_ENDRAINSTORM:
195 			//EnvEndRainStorm( );
196 			break;
197 		case EVENT_RAINSTORM:
198 
199 			// ATE: Disabled
200 			//
201 			//if( pEvent->ubEventType == ENDRANGED_EVENT )
202 			//{
203 			//	EnvEndRainStorm( );
204 			//}
205 			//else
206 			//{
207 			//	EnvBeginRainStorm( (UINT8)pEvent->uiParam );
208 			//}
209 			break;
210 
211 		case EVENT_MAKE_CIV_GROUP_HOSTILE_ON_NEXT_SECTOR_ENTRANCE:
212 			MakeCivGroupHostileOnNextSectorEntrance( (UINT8)pEvent->uiParam );
213 			break;
214 		case EVENT_MEANWHILE:
215 			if( !DelayEventIfBattleInProgress( pEvent ) )
216 			{
217 				BeginMeanwhile( (UINT8)pEvent->uiParam );
218 				InterruptTime();
219 			}
220 			break;
221 		case EVENT_CREATURE_SPREAD:
222 			SpreadCreatures();
223 			break;
224 		case EVENT_CREATURE_NIGHT_PLANNING:
225 			CreatureNightPlanning();
226 			break;
227 		case EVENT_CREATURE_ATTACK:
228 			CreatureAttackTown( (UINT8)pEvent->uiParam, FALSE );
229 			break;
230 		case EVENT_EVALUATE_QUEEN_SITUATION:
231 			EvaluateQueenSituation();
232 			break;
233 		case EVENT_CHECK_ENEMY_CONTROLLED_SECTOR:
234 			CheckEnemyControlledSector( (UINT8)pEvent->uiParam );
235 			break;
236 		case EVENT_TURN_ON_NIGHT_LIGHTS:
237 			TurnOnNightLights();
238 			break;
239 		case EVENT_TURN_OFF_NIGHT_LIGHTS:
240 			TurnOffNightLights();
241 			break;
242 		case EVENT_TURN_ON_PRIME_LIGHTS:
243 			TurnOnPrimeLights();
244 			break;
245 		case EVENT_TURN_OFF_PRIME_LIGHTS:
246 			TurnOffPrimeLights();
247 			break;
248 		case EVENT_ENRICO_MAIL:
249 			HandleEnricoEmail();
250 			break;
251 		case EVENT_INSURANCE_INVESTIGATION_STARTED:
252 			StartInsuranceInvestigation( (UINT8) pEvent->uiParam );
253 			break;
254 		case EVENT_INSURANCE_INVESTIGATION_OVER:
255 			EndInsuranceInvestigation( (UINT8) pEvent->uiParam );
256 			break;
257 		case EVENT_TEMPERATURE_UPDATE:
258 			UpdateTemperature( (UINT8) pEvent->uiParam );
259 			break;
260 		case EVENT_KEITH_GOING_OUT_OF_BUSINESS:
261 			// make sure killbillies are still alive, if so, set fact 274 true
262 			if (!CheckFact(FACT_HILLBILLIES_KILLED, KEITH))
263 			{
264 				//s et the fact true keith is out of business
265 				SetFactTrue( FACT_KEITH_OUT_OF_BUSINESS );
266 			}
267 			break;
268 		case EVENT_MERC_SITE_BACK_ONLINE:
269 			GetMercSiteBackOnline();
270 			break;
271 		case EVENT_CHECK_IF_MINE_CLEARED:
272 			// If so, the head miner will say so, and the mine's shutdown will be ended.
273 			HourlyMinesUpdate();		// not-so hourly, in this case!
274 			break;
275 		case EVENT_REMOVE_ASSASSIN:
276 			RemoveAssassin( (UINT8) pEvent->uiParam );
277 			break;
278 		case EVENT_BEGIN_CONTRACT_RENEWAL_SEQUENCE:
279 			BeginContractRenewalSequence( );
280 			break;
281 		case EVENT_RPC_WHINE_ABOUT_PAY:
282 			RPCWhineAboutNoPay(GetMan(pEvent->uiParam));
283 			break;
284 
285 		case EVENT_HAVENT_MADE_IMP_CHARACTER_EMAIL:
286 			HaventMadeImpMercEmailCallBack();
287 			break;
288 
289 		case EVENT_QUARTER_HOUR_UPDATE:
290 			HandleQuarterHourUpdate();
291 			break;
292 
293 		case EVENT_MERC_MERC_WENT_UP_LEVEL_EMAIL_DELAY:
294 			MERCMercWentUpALevelSendEmail( (UINT8) pEvent->uiParam );
295 			break;
296 
297 		case EVENT_MERC_SITE_NEW_MERC_AVAILABLE:
298 			NewMercsAvailableAtMercSiteCallBack( );
299 			break;
300 	}
301 	gfPreventDeletionOfAnyEvent = fOrigPreventFlag;
302 	return TRUE;
303 }
304