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