| | 1 | #include "system.h" |
| | 2 | #include "prototyp.h" |
| | 3 | #include "stratdef.h" |
| | 4 | #include "mission.h" |
| | 5 | #include <assert.h> |
| | 6 | #include <string.h> |
| | 7 | #include <stdlib.h> |
| | 8 | |
| | 9 | extern void MissionObjectiveTriggered(void* mission_objective); |
| | 10 | extern void MakeMissionVisible(void* mission_objective); |
| | 11 | extern void MakeMissionPossible(void* mission_objective); |
| | 12 | |
| | 13 | void MissionCompleteBehaveInit(void* bhdata, STRATEGYBLOCK* sbptr) |
| | 14 | { |
| | 15 | assert(sbptr); |
| | 16 | |
| | 17 | MISSION_COMPLETE_BEHAV_BLOCK* m_bhv = malloc(sizeof(MISSION_COMPLETE_BEHAV_BLOCK)); |
| | 18 | |
| | 19 | if(NULL == m_bhv) |
| | 20 | { |
| | 21 | RemoveBehaviourStrategy(sbptr); |
| | 22 | return; |
| | 23 | } |
| | 24 | |
| | 25 | sbptr->dataptr = m_bhv; |
| | 26 | MISSION_COMPLETE_TOOLS_TEMPLATE* mc_tt = (MISSION_COMPLETE_TOOLS_TEMPLATE*) bhdata; |
| | 27 | |
| | 28 | m_bhv->bhvr_type = I_BehaviourMissionComplete; |
| | 29 | sbptr->shapeIndex = 0; |
| | 30 | COPY_NAME(sbptr->SBname, mc_tt->nameID); |
| | 31 | |
| | 32 | m_bhv->mission_objective_ptr=mc_tt->mission_objective_ptr; |
| | 33 | } |
| | 34 | |
| | 35 | #define MissionTrigger_MakeVisible 0x00000001 |
| | 36 | #define MissionTrigger_MakePossible 0x00000002 |
| | 37 | #define MissionTrigger_DontComplete 0x00000004 |
| | 38 | |
| | 39 | void SendRequestToMissionStrategy(STRATEGYBLOCK* sbptr, int state,int extended_data) |
| | 40 | { |
| | 41 | assert(sbptr); |
| | 42 | assert(sbptr->dataptr); |
| | 43 | MISSION_COMPLETE_BEHAV_BLOCK *mc_bhv = (MISSION_COMPLETE_BEHAV_BLOCK*)sbptr->dataptr; |
| | 44 | assert((mc_bhv->bhvr_type == I_BehaviourMissionComplete)); |
| | 45 | |
| | 46 | if(!state) |
| | 47 | return; |
| | 48 | |
| | 49 | if(extended_data & MissionTrigger_MakeVisible) |
| | 50 | MakeMissionVisible(mc_bhv->mission_objective_ptr); |
| | 51 | |
| | 52 | if(extended_data & MissionTrigger_MakePossible) |
| | 53 | MakeMissionPossible(mc_bhv->mission_objective_ptr); |
| | 54 | |
| | 55 | if(!(extended_data & MissionTrigger_DontComplete)) |
| | 56 | MissionObjectiveTriggered(mc_bhv->mission_objective_ptr); |
| | 57 | } |
| | 58 | |
| | 59 | typedef struct message_behav_block |
| | 60 | { |
| | 61 | AVP_BEHAVIOUR_TYPE bhvr_type; |
| | 62 | int string_no; |
| | 63 | int active; |
| | 64 | |
| | 65 | } MESSAGE_BEHAV_BLOCK; |
| | 66 | |
| | 67 | void MessageBehaveInit(void* bhdata,STRATEGYBLOCK* sbptr) |
| | 68 | { |
| | 69 | assert(sbptr); |
| | 70 | |
| | 71 | MESSAGE_BEHAV_BLOCK* m_bhv = malloc(sizeof(MESSAGE_BEHAV_BLOCK)); |
| | 72 | |
| | 73 | if(!m_bhv) |
| | 74 | { |
| | 75 | RemoveBehaviourStrategy(sbptr); |
| | 76 | return; |
| | 77 | } |
| | 78 | |
| | 79 | sbptr->dataptr = m_bhv; |
| | 80 | MESSAGE_TOOLS_TEMPLATE* m_tt = (MESSAGE_TOOLS_TEMPLATE*) bhdata; |
| | 81 | |
| | 82 | m_bhv->bhvr_type = I_BehaviourMessage; |
| | 83 | sbptr->shapeIndex = 0; |
| | 84 | COPY_NAME(sbptr->SBname, m_tt->nameID); |
| | 85 | |
| | 86 | m_bhv->string_no = m_tt->string_no; |
| | 87 | m_bhv->active = m_tt->active; |
| | 88 | } |
| | 89 | |
| | 90 | extern const char * missionlevel_messages[]; |
| | 91 | void SendRequestToMessageStrategy(STRATEGYBLOCK* sbptr, int state,int extended_data) |
| | 92 | { |
| | 93 | assert(sbptr); |
| | 94 | assert(sbptr->dataptr); |
| | 95 | MESSAGE_BEHAV_BLOCK *m_bhv = (MESSAGE_BEHAV_BLOCK*)sbptr->dataptr; |
| | 96 | assert((m_bhv->bhvr_type == I_BehaviourMessage)); |
| | 97 | |
| | 98 | extern unsigned int mission_messages_timer; |
| | 99 | |
| | 100 | switch(extended_data) |
| | 101 | { |
| | 102 | case 1: |
| | 103 | m_bhv->active = state; |
| | 104 | break; |
| | 105 | case 2: |
| | 106 | m_bhv->active = state; |
| | 107 | |
| | 108 | if(m_bhv->active) |
| | 109 | { |
| | 110 | PrintStringTableEntryInConsole(missionlevel_messages[m_bhv->string_no]); |
| | 111 | mission_messages_timer = timeGetTime() + strlen(missionlevel_messages[m_bhv->string_no]) * 80; |
| | 112 | } |
| | 113 | break; |
| | 114 | default: |
| | 115 | if(m_bhv->active && state) |
| | 116 | { |
| | 117 | PrintStringTableEntryInConsole(missionlevel_messages[m_bhv->string_no]); |
| | 118 | mission_messages_timer = timeGetTime() + strlen(missionlevel_messages[m_bhv->string_no]) * 80; |
| | 119 | } |
| | 120 | } |
| | 121 | } |
| | 122 | |
| | 123 | /*--------------------** |
| | 124 | ** Loading and Saving ** |
| | 125 | **--------------------*/ |
| | 126 | #include "savegame.h" |
| | 127 | |
| | 128 | typedef struct message_save_block |
| | 129 | { |
| | 130 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 131 | |
| | 132 | int active; |
| | 133 | |
| | 134 | } MESSAGE_SAVE_BLOCK; |
| | 135 | |
| | 136 | void LoadStrategy_Message(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 137 | { |
| | 138 | MESSAGE_SAVE_BLOCK* block = (MESSAGE_SAVE_BLOCK*) header; |
| | 139 | |
| | 140 | //check the size of the save block |
| | 141 | if(header->size != sizeof(*block)) |
| | 142 | return; |
| | 143 | |
| | 144 | //find the existing strategy block |
| | 145 | STRATEGYBLOCK* sbPtr = FindSBWithName(header->SBname); |
| | 146 | |
| | 147 | if(!sbPtr) |
| | 148 | return; |
| | 149 | |
| | 150 | //make sure the strategy found is of the right type |
| | 151 | if(sbPtr->type != I_BehaviourMessage) |
| | 152 | return; |
| | 153 | |
| | 154 | MESSAGE_BEHAV_BLOCK* m_bhv = (MESSAGE_BEHAV_BLOCK *)sbPtr->dataptr; |
| | 155 | |
| | 156 | //start copying stuff |
| | 157 | |
| | 158 | m_bhv->active = block->active; |
| | 159 | } |
| | 160 | |
| | 161 | void SaveStrategy_Message(STRATEGYBLOCK* sbPtr) |
| | 162 | { |
| | 163 | MESSAGE_SAVE_BLOCK* block; |
| | 164 | MESSAGE_BEHAV_BLOCK* m_bhv = (MESSAGE_BEHAV_BLOCK *)sbPtr->dataptr; |
| | 165 | |
| | 166 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 167 | |
| | 168 | //start copying stuff |
| | 169 | block->active = m_bhv->active; |
| | 170 | } |
| | 171 | |
| | 172 | /*------------------------------** |
| | 173 | ** Loading/Saving mission state ** |
| | 174 | **------------------------------*/ |
| | 175 | extern int GetMissionStateForSave(void* mission_objective); |
| | 176 | extern void SetMissionStateFromLoad(void* mission_objective,int state); |
| | 177 | |
| | 178 | typedef struct mission_complete_save_block |
| | 179 | { |
| | 180 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 181 | |
| | 182 | int state; |
| | 183 | |
| | 184 | } MISSION_COMPLETE_SAVE_BLOCK; |
| | 185 | |
| | 186 | void LoadStrategy_MissionComplete(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 187 | { |
| | 188 | MISSION_COMPLETE_SAVE_BLOCK* block = (MISSION_COMPLETE_SAVE_BLOCK*) header; |
| | 189 | |
| | 190 | //check the size of the save block |
| | 191 | if(header->size != sizeof(*block)) |
| | 192 | return; |
| | 193 | |
| | 194 | //find the existing strategy block |
| | 195 | STRATEGYBLOCK* sbPtr = FindSBWithName(header->SBname); |
| | 196 | if(!sbPtr) |
| | 197 | return; |
| | 198 | |
| | 199 | //make sure the strategy found is of the right type |
| | 200 | if(sbPtr->type != I_BehaviourMissionComplete) |
| | 201 | return; |
| | 202 | |
| | 203 | MISSION_COMPLETE_BEHAV_BLOCK* m_bhv = (MISSION_COMPLETE_BEHAV_BLOCK *)sbPtr->dataptr; |
| | 204 | |
| | 205 | //start copying stuff |
| | 206 | SetMissionStateFromLoad(m_bhv->mission_objective_ptr , block->state); |
| | 207 | } |
| | 208 | |
| | 209 | void SaveStrategy_MissionComplete(STRATEGYBLOCK* sbPtr) |
| | 210 | { |
| | 211 | MISSION_COMPLETE_SAVE_BLOCK* block; |
| | 212 | MISSION_COMPLETE_BEHAV_BLOCK* m_bhv = (MISSION_COMPLETE_BEHAV_BLOCK *)sbPtr->dataptr; |
| | 213 | |
| | 214 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 215 | |
| | 216 | //start copying stuff |
| | 217 | block->state = GetMissionStateForSave(m_bhv->mission_objective_ptr); |
| | 218 | } |