1 #ifndef __SCHEDULING_H
2 #define __SCHEDULING_H
3 
4 #include "Soldier_Init_List.h"
5 
6 
7 //Merc scheduling actions
8 //NOTE:  Any modifications to this enumeration also require updating the text in EditorMercs.c used
9 //       in the editor for merc schedule purposes.
10 enum
11 {
12 	SCHEDULE_ACTION_NONE,
13 	SCHEDULE_ACTION_LOCKDOOR,
14 	SCHEDULE_ACTION_UNLOCKDOOR,
15 	SCHEDULE_ACTION_OPENDOOR,
16 	SCHEDULE_ACTION_CLOSEDOOR,
17 	SCHEDULE_ACTION_GRIDNO,
18 	SCHEDULE_ACTION_LEAVESECTOR,
19 	SCHEDULE_ACTION_ENTERSECTOR,
20 	SCHEDULE_ACTION_STAYINSECTOR,
21 	SCHEDULE_ACTION_SLEEP,
22 	SCHEDULE_ACTION_WAKE,
23 	NUM_SCHEDULE_ACTIONS
24 };
25 
26 #define SCHEDULE_FLAGS_VARIANCE1					0x0001
27 #define SCHEDULE_FLAGS_VARIANCE2					0x0002
28 #define SCHEDULE_FLAGS_VARIANCE3					0x0004
29 #define SCHEDULE_FLAGS_VARIANCE4					0x0008
30 #define SCHEDULE_FLAGS_ACTIVE1						0x0010
31 #define SCHEDULE_FLAGS_ACTIVE2						0x0020
32 #define SCHEDULE_FLAGS_ACTIVE3						0x0040
33 #define SCHEDULE_FLAGS_ACTIVE4						0x0080
34 #define SCHEDULE_FLAGS_TEMPORARY					0x0100	//for default schedules -- not saved.
35 #define SCHEDULE_FLAGS_SLEEP_CONVERTED		0x0200	//converted (needs to be uncoverted before saving)
36 #define SCHEDULE_FLAGS_NPC_SLEEPING				0x0400	//if processing a sleep command, this flag will be set.
37 
38 // combo flag for turning active flags off
39 #define SCHEDULE_FLAGS_ACTIVE_ALL		0x00F0
40 
41 #define MAX_SCHEDULE_ACTIONS 4
42 
43 struct SCHEDULENODE
44 {
45 	SCHEDULENODE* next;
46 	UINT16 usTime[MAX_SCHEDULE_ACTIONS];	//converted to minutes 12:30PM would be 12*60 + 30 = 750
47 	UINT16 usData1[MAX_SCHEDULE_ACTIONS]; //typically the gridno, but depends on the action
48 	UINT16 usData2[MAX_SCHEDULE_ACTIONS]; //secondary information, not used by most actions
49 	UINT8 ubAction[MAX_SCHEDULE_ACTIONS];
50 	UINT8 ubScheduleID;
51 	UINT16 usFlags;
52 	SOLDIERTYPE* soldier;
53 };
54 
55 
56 extern UINT8				gubScheduleID;
57 extern SCHEDULENODE *gpScheduleList;
58 
59 //Access functions
60 SCHEDULENODE* GetSchedule( UINT8 ubScheduleID );
61 
62 //Removes all schedules from the event list, and cleans out the list.
63 void DestroyAllSchedules(void);
64 void DestroyAllSchedulesWithoutDestroyingEvents(void);
65 
66 //This is the callback whenever a schedule is processed
67 void ProcessTacticalSchedule( UINT8 ubScheduleID );
68 
69 void DeleteSchedule( UINT8 ubScheduleID );
70 
71 void LoadSchedules(HWFILE);
72 void LoadSchedulesFromSave(HWFILE);
73 void SaveSchedules(HWFILE);
74 
75 void PostNextSchedule( SOLDIERTYPE *pSoldier );
76 
77 //After the world is loaded and the temp modifications have been applied,
78 //we then need to post the events and process schedules for the time that we have been gone.
79 void PostSchedules(void);
80 
81 //Sorts the schedule in chronological order.  Returns TRUE if any sorting took place.
82 BOOLEAN SortSchedule( SCHEDULENODE *pSchedule );
83 //Adds a schedule to the list.  COPIES THE DATA OVER (ALLOCATES NEW NODE!)
84 void CopyScheduleToList( SCHEDULENODE *pSchedule, SOLDIERINITNODE *pNode );
85 //Entering the editor automatically removes all events posted.
86 void PrepareSchedulesForEditorEntry(void);
87 //Leaving the editor and entering the game posts the events.
88 void PrepareSchedulesForEditorExit(void);
89 //Packs all of the scheduleIDs, and updates the links.  This is done whenever necessary and
90 //before saving the map, as this forces the IDs to align with the SOLDIERINITNODE->ubScheduleID's.
91 void OptimizeSchedules(void);
92 
93 BOOLEAN ExtractScheduleDoorLockAndUnlockInfo( SOLDIERTYPE * pSoldier, UINT32 * puiOpeningTime, UINT32 * puiClosingTime );
94 
95 BOOLEAN BumpAnyExistingMerc( INT16 sGridNo );
96 
97 /* used to fix a bug in the editor where the schedules were reversed.  Because
98  * only some maps were effected, this feature was required. */
99 void ReverseSchedules(void);
100 
101 void ClearAllSchedules(void);
102 
103 #endif
104