File: module.c

package info (click to toggle)
egoboo-data 2.22-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 44,296 kB
  • ctags: 2,618
  • sloc: ansic: 23,985; makefile: 94
file content (360 lines) | stat: -rw-r--r-- 12,164 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// module.c

// Egoboo, Copyright (C) 2000 Aaron Bishop

#include "egoboo.h"

//--------------------------------------------------------------------------------------------
void release_module( void )
{
    // ZZ> This function frees up memory used by the module
    //RELEASE(lpDDSBars);
    //RELEASE(lpDDSFont);
    release_all_textures();
    release_all_icons();
    release_map();
    reset_sounds();
}

//--------------------------------------------------------------------------------------------
int module_reference_matches(char *szLoadName, unsigned int idsz)
{
    // ZZ> This function returns TRUE if the named module has the required IDSZ
    FILE *fileread;
    char newloadname[256];
    unsigned int newidsz;
    int foundidsz;
    int cnt;


    if(szLoadName[0] == 'N' && szLoadName[1] == 'O' && szLoadName[2] == 'N' && szLoadName[3] == 'E' && szLoadName[4] == 0)
        return TRUE;
    if(idsz == IDSZNONE)
        return TRUE;


    foundidsz = FALSE;
    sprintf(newloadname, FILENAME("modules/%s/gamedat/menu.txt"), szLoadName);
    fileread = fopen(newloadname, "r"); 
    if(fileread)
    {
        // Read basic data
        globalname = szLoadName;
        goto_colon(fileread);  // Name of module...  Doesn't matter
        goto_colon(fileread);  // Reference directory...
        goto_colon(fileread);  // Reference IDSZ...
        goto_colon(fileread);  // Import...
        goto_colon(fileread);  // Export...
        goto_colon(fileread);  // Min players...
        goto_colon(fileread);  // Max players...
        goto_colon(fileread);  // Respawn...
        goto_colon(fileread);  // RTS...
        goto_colon(fileread);  // Rank...


        // Summary...
        cnt = 0;
        while(cnt < SUMMARYLINES)
        {
            goto_colon(fileread);
            cnt++;
        }


        // Now check expansions
        while(goto_colon_yesno(fileread) && foundidsz == FALSE)
        {
            newidsz = get_idsz(fileread);
            if(newidsz == idsz)
            {
                foundidsz = TRUE;
            }
        }


        fclose(fileread);
    }
    return foundidsz;
}

//--------------------------------------------------------------------------------------------
void add_module_idsz(char *szLoadName, unsigned int idsz)
{
    // ZZ> This function appends an IDSZ to the module's menu.txt file
    FILE *filewrite;
    char newloadname[256];
    char chara, charb, charc, chard;

    // Only add if there isn't one already
    if(module_reference_matches(szLoadName, idsz) == FALSE)
    {
        // Try to open the file in append mode
        sprintf(newloadname, FILENAME("modules/%s/gamedat/enu.txt"), szLoadName);
        filewrite = fopen(newloadname, "a"); 
        if(filewrite)
        {
            chara = ((idsz>>15)&31)+'A';
            charb = ((idsz>>10)&31)+'A';
            charc = ((idsz>>5)&31)+'A';
            chard = ((idsz)&31)+'A';
            fprintf(filewrite, ":[%c%c%c%c]\n", chara, charb, charc, chard);
            fclose(filewrite);
        }
    }
}

//--------------------------------------------------------------------------------------------
int find_module(char *smallname)
{
    // ZZ> This function returns -1 if the module does not exist locally, the module
    //     index otherwise

    int cnt, index;
    cnt = 0;
    index = -1;
    while(cnt < globalnummodule)
    {
        if(strcmp(smallname, modloadname[cnt]) == 0)
        {
            index = cnt;
            cnt = globalnummodule;
        }
        cnt++;
    }
    return index;
}

//--------------------------------------------------------------------------------------------
void load_module(char *smallname)
{
    // ZZ> This function loads a module
    char modname[128];
    char musicdirectory[128];
    FILE* musicfile;

    //printf("in load_module\n");

    beatmodule = FALSE;
    timeron = FALSE;
    sprintf(modname, FILENAME("modules/%s/"), smallname);
    make_randie();	// This should work
    //printf("randie done\n");
    reset_teams();      // This should work
    //printf("reset_teams done\n");
    load_one_icon("basicdat/nullicon.bmp");  // This works (without transparency)
    //printf("load_one_icon done\n");
    reset_particles(modname);  // This should work
    //printf("reset_particles done\n");
    read_wawalite(modname);   // This should work
    //printf("read_wawa done\n");
    make_twist();             // This should work
    //printf("make_twist done\n");
    reset_messages();         // This should work
    //printf("reset messages done\n");
    prime_names();            // This should work
    //printf("prime_names done\n");
    load_basic_textures(modname);  // This should work (without colorkey stuff)
    //printf("load_basic_tex done\n");
    reset_ai_script();        // This should work
    //printf("reset_ai_script done\n");
    load_ai_script("basicdat/script.txt");  // This should work
    //printf("load_ai_script done\n");
    reset_sounds();           // This doesn't do ANYTHING
    //printf("reset_sounds done\n");
    release_all_models();     // This should work
    //printf("release_all_models done\n");
    free_all_enchants();      // This should work
    //printf("free_all_enchants done\n");

    // Load sound files
    sprintf(musicdirectory, "%smusic", modname);
    igloaded = FALSE;
    load_global_waves(modname);  // This is not fully implemented
    //printf("load_global_waves done\n");
    load_all_music_sounds(musicdirectory); // This is not fully implemented
    //printf("load_all_music_sounds done\n");
    if(instrumentsloaded == FALSE)
    {
        sprintf(musicdirectory, FILENAME("%sgamedat/igmusic.txt"), modname);  // The file to load
        musicfile = fopen(musicdirectory, "r");
        sprintf(musicdirectory, FILENAME("basicdat/musica"));  // The default directory
        if(musicfile)
        {
            fscanf(musicfile, "%s", musicdirectory);  // Read in a new directory
            fclose(musicfile);
        }
        load_all_music_sounds(musicdirectory);
        igloaded = instrumentsloaded;
    }

    //printf("Got to load_all_objects\n");

// [claforte Jan 6th 2001]
// The following will crash on _BIG_ENDIAN architectures at the moment,
// since the MD2 loading functions (ie: rip_md2_*) all assume that the machine is
// little-endian.

//#ifdef _LITTLE_ENDIAN
    load_all_objects(modname); // This is broken and needs to be fixed
	
	//	printf("Got to load mesh\n");
    if(!load_mesh(modname))
    {
        general_error(0, 0, "LOAD PROBLEMS");
    }
    //printf("Got to setup_particles\n");
    setup_particles();
    //printf("Got to setup_passage\n");
    setup_passage(modname);
    //printf("Got to reset_players\n");
    
	reset_players();
    //printf("Got to setup_characters\n");
    
	setup_characters(modname);
//#endif //_LITTLE_ENDIAN
	
	//	printf("Got to reset_end_text\n");
    reset_end_text();
    //printf("Got to reset_press\n");
    reset_press();
    //printf("Got to setup_alliances\n");
    setup_alliances(modname);

    // Load fonts and bars after other images, as not to hog videomem
    //printf("Got to load_font\n");
    load_font("basicdat/font.bmp", "basicdat/font.txt", FALSE);
    //printf("Got to load_bars\n");
    load_bars("basicdat/bars.bmp");
    //printf("Got to load_map\n");
    load_map(modname, FALSE);
    //printf("Got to log_madused\n");
    // GS - log_madused(FILENAME("basicdat/slotused.txt"));


    // Now setup the music
    //printf("Got to load_all_music_tracks\n");
    // GS - load_all_music_tracks(smallname);
    // GS - load_all_music_loops(smallname);
    // GS - load_music_sequence(smallname);
    play_next_track();
    if(igloaded)
    {
        // Normal music failed, so default to interactive music
        sprintf(generictext, FILENAME("%s/length.txt"), musicdirectory);
        // GS - load_ig_length(generictext);
        // GS - create_ig_trackmaster();
    }

    // RTS stuff
    clear_orders();


    // Start playing the damage tile sound silently...
/*PORT
    play_sound_pvf_looped(damagetilesound, PANMID, VOLMIN, FRQDEFAULT);
*/
}

//--------------------------------------------------------------------------------------------
int get_module_data(int modnumber, char *szLoadName)
{
    // ZZ> This function loads the module data file
    FILE *fileread;
    char reference[128];
    unsigned int idsz;
    char cTmp;
    int iTmp;

    fileread = fopen( FILENAME(szLoadName), "r"); 
    if(fileread)
    {
        // Read basic data
        globalname = szLoadName;
        goto_colon(fileread);  get_name(fileread, modlongname[modnumber]);
        goto_colon(fileread);  fscanf(fileread, "%s", reference);
        goto_colon(fileread);  idsz = get_idsz(fileread);
        if(module_reference_matches(reference, idsz))
        {
            globalname = szLoadName;
            goto_colon(fileread);  fscanf(fileread, "%d", &iTmp);
                modimportamount[modnumber] = iTmp;
            goto_colon(fileread);  cTmp = get_first_letter(fileread);
                modallowexport[modnumber] = FALSE;
                if(cTmp == 'T' || cTmp == 't')  modallowexport[modnumber] = TRUE;
            goto_colon(fileread);  fscanf(fileread, "%d", &iTmp);  modminplayers[modnumber] = iTmp;
            goto_colon(fileread);  fscanf(fileread, "%d", &iTmp);  modmaxplayers[modnumber] = iTmp;
            goto_colon(fileread);  cTmp = get_first_letter(fileread);
                modrespawnvalid[modnumber] = FALSE;
                if(cTmp == 'T' || cTmp == 't')  modrespawnvalid[modnumber] = TRUE;
                if(cTmp == 'A' || cTmp == 'a')  modrespawnvalid[modnumber] = ANYTIME;
            goto_colon(fileread);  cTmp = get_first_letter(fileread);
                modrtscontrol[modnumber] = FALSE;
                if(cTmp == 'T' || cTmp == 't')  modrtscontrol[modnumber] = TRUE;
                if(cTmp == 'A' || cTmp == 'a')  modrtscontrol[modnumber] = ALLSELECT;
            goto_colon(fileread);  fscanf(fileread, "%s", generictext);
                iTmp = 0;
                while(iTmp < RANKSIZE-1)
                {
                    modrank[modnumber][iTmp] = generictext[iTmp];
                    iTmp++;
                }
                modrank[modnumber][iTmp] = 0;



            // Read the expansions
            return TRUE;
        }
    }
    return FALSE;
}

//--------------------------------------------------------------------------------------------
int get_module_summary(char *szLoadName)
{
    // ZZ> This function gets the quest description out of the module's menu file
    FILE *fileread;
    char cTmp;
    char szLine[160];
    int cnt;
    int tnc;

    fileread = fopen(szLoadName, "r"); 
    if(fileread)
    {
        // Skip over basic data
        globalname = szLoadName;
        goto_colon(fileread);  // Name...
        goto_colon(fileread);  // Reference...
        goto_colon(fileread);  // IDSZ...
        goto_colon(fileread);  // Import...
        goto_colon(fileread);  // Export...
        goto_colon(fileread);  // Min players...
        goto_colon(fileread);  // Max players...
        goto_colon(fileread);  // Respawn...
        goto_colon(fileread);  // RTS control...
        goto_colon(fileread);  // Rank...


        // Read the summary
        cnt = 0;
        while(cnt < SUMMARYLINES)
        {
            goto_colon(fileread);  fscanf(fileread, "%s", szLine);
            tnc = 0;
            cTmp = szLine[tnc];  if(cTmp == '_')  cTmp = ' ';
            while(tnc < SUMMARYSIZE-1 && cTmp != 0)
            {
                modsummary[cnt][tnc] = cTmp;
                tnc++;
                cTmp = szLine[tnc];  if(cTmp == '_')  cTmp = ' ';
            }
            modsummary[cnt][tnc] = 0;
            cnt++;
        }
        return TRUE;
    }
    return FALSE;
}