home *** CD-ROM | disk | FTP | other *** search
/ Launch & Play / spustahrej2.iso / Egoboo / code / module.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-12-03  |  11.9 KB  |  361 lines

  1. // module.c
  2.  
  3. // Egoboo, Copyright (C) 2000 Aaron Bishop
  4.  
  5. #include "egoboo.h"
  6.  
  7. //--------------------------------------------------------------------------------------------
  8. void release_module( void )
  9. {
  10.     // ZZ> This function frees up memory used by the module
  11.     //RELEASE(lpDDSBars);
  12.     //RELEASE(lpDDSFont);
  13.     release_all_textures();
  14.     release_all_icons();
  15.     release_map();
  16.     reset_sounds();
  17. }
  18.  
  19. //--------------------------------------------------------------------------------------------
  20. int module_reference_matches(char *szLoadName, unsigned int idsz)
  21. {
  22.     // ZZ> This function returns TRUE if the named module has the required IDSZ
  23.     FILE *fileread;
  24.     char newloadname[256];
  25.     unsigned int newidsz;
  26.     int foundidsz;
  27.     int cnt;
  28.  
  29.  
  30.     if(szLoadName[0] == 'N' && szLoadName[1] == 'O' && szLoadName[2] == 'N' && szLoadName[3] == 'E' && szLoadName[4] == 0)
  31.         return TRUE;
  32.     if(idsz == IDSZNONE)
  33.         return TRUE;
  34.  
  35.  
  36.     foundidsz = FALSE;
  37.     sprintf(newloadname, FILENAME("modules/%s/gamedat/menu.txt"), szLoadName);
  38.     fileread = fopen(newloadname, "r"); 
  39.     if(fileread)
  40.     {
  41.         // Read basic data
  42.         globalname = szLoadName;
  43.         goto_colon(fileread);  // Name of module...  Doesn't matter
  44.         goto_colon(fileread);  // Reference directory...
  45.         goto_colon(fileread);  // Reference IDSZ...
  46.         goto_colon(fileread);  // Import...
  47.         goto_colon(fileread);  // Export...
  48.         goto_colon(fileread);  // Min players...
  49.         goto_colon(fileread);  // Max players...
  50.         goto_colon(fileread);  // Respawn...
  51.         goto_colon(fileread);  // RTS...
  52.         goto_colon(fileread);  // Rank...
  53.  
  54.  
  55.         // Summary...
  56.         cnt = 0;
  57.         while(cnt < SUMMARYLINES)
  58.         {
  59.             goto_colon(fileread);
  60.             cnt++;
  61.         }
  62.  
  63.  
  64.         // Now check expansions
  65.         while(goto_colon_yesno(fileread) && foundidsz == FALSE)
  66.         {
  67.             newidsz = get_idsz(fileread);
  68.             if(newidsz == idsz)
  69.             {
  70.                 foundidsz = TRUE;
  71.             }
  72.         }
  73.  
  74.  
  75.         fclose(fileread);
  76.     }
  77.     return foundidsz;
  78. }
  79.  
  80. //--------------------------------------------------------------------------------------------
  81. void add_module_idsz(char *szLoadName, unsigned int idsz)
  82. {
  83.     // ZZ> This function appends an IDSZ to the module's menu.txt file
  84.     FILE *filewrite;
  85.     char newloadname[256];
  86.     char chara, charb, charc, chard;
  87.  
  88.     // Only add if there isn't one already
  89.     if(module_reference_matches(szLoadName, idsz) == FALSE)
  90.     {
  91.         // Try to open the file in append mode
  92.         sprintf(newloadname, FILENAME("modules/%s/gamedat/enu.txt"), szLoadName);
  93.         filewrite = fopen(newloadname, "a"); 
  94.         if(filewrite)
  95.         {
  96.             chara = ((idsz>>15)&31)+'A';
  97.             charb = ((idsz>>10)&31)+'A';
  98.             charc = ((idsz>>5)&31)+'A';
  99.             chard = ((idsz)&31)+'A';
  100.             fprintf(filewrite, ":[%c%c%c%c]\n", chara, charb, charc, chard);
  101.             fclose(filewrite);
  102.         }
  103.     }
  104. }
  105.  
  106. //--------------------------------------------------------------------------------------------
  107. int find_module(char *smallname)
  108. {
  109.     // ZZ> This function returns -1 if the module does not exist locally, the module
  110.     //     index otherwise
  111.  
  112.     int cnt, index;
  113.     cnt = 0;
  114.     index = -1;
  115.     while(cnt < globalnummodule)
  116.     {
  117.         if(strcmp(smallname, modloadname[cnt]) == 0)
  118.         {
  119.             index = cnt;
  120.             cnt = globalnummodule;
  121.         }
  122.         cnt++;
  123.     }
  124.     return index;
  125. }
  126.  
  127. //--------------------------------------------------------------------------------------------
  128. void load_module(char *smallname)
  129. {
  130.     // ZZ> This function loads a module
  131.     char modname[128];
  132.     char musicdirectory[128];
  133.     FILE* musicfile;
  134.  
  135.     //printf("in load_module\n");
  136.  
  137.     beatmodule = FALSE;
  138.     timeron = FALSE;
  139.     sprintf(modname, FILENAME("modules/%s/"), smallname);
  140.     make_randie();    // This should work
  141.     //printf("randie done\n");
  142.     reset_teams();      // This should work
  143.     //printf("reset_teams done\n");
  144.     load_one_icon("basicdat/nullicon.bmp");  // This works (without transparency)
  145.     //printf("load_one_icon done\n");
  146.     reset_particles(modname);  // This should work
  147.     //printf("reset_particles done\n");
  148.     read_wawalite(modname);   // This should work
  149.     //printf("read_wawa done\n");
  150.     make_twist();             // This should work
  151.     //printf("make_twist done\n");
  152.     reset_messages();         // This should work
  153.     //printf("reset messages done\n");
  154.     prime_names();            // This should work
  155.     //printf("prime_names done\n");
  156.     load_basic_textures(modname);  // This should work (without colorkey stuff)
  157.     //printf("load_basic_tex done\n");
  158.     reset_ai_script();        // This should work
  159.     //printf("reset_ai_script done\n");
  160.     load_ai_script("basicdat/script.txt");  // This should work
  161.     //printf("load_ai_script done\n");
  162.     reset_sounds();           // This doesn't do ANYTHING
  163.     //printf("reset_sounds done\n");
  164.     release_all_models();     // This should work
  165.     //printf("release_all_models done\n");
  166.     free_all_enchants();      // This should work
  167.     //printf("free_all_enchants done\n");
  168.  
  169.     // Load sound files
  170.     sprintf(musicdirectory, "%smusic", modname);
  171.     igloaded = FALSE;
  172.     load_global_waves(modname);  // This is not fully implemented
  173.     //printf("load_global_waves done\n");
  174.     load_all_music_sounds(musicdirectory); // This is not fully implemented
  175.     //printf("load_all_music_sounds done\n");
  176.     if(instrumentsloaded == FALSE)
  177.     {
  178.         sprintf(musicdirectory, FILENAME("%sgamedat/igmusic.txt"), modname);  // The file to load
  179.         musicfile = fopen(musicdirectory, "r");
  180.         sprintf(musicdirectory, FILENAME("basicdat/musica"));  // The default directory
  181.         if(musicfile)
  182.         {
  183.             fscanf(musicfile, "%s", musicdirectory);  // Read in a new directory
  184.             fclose(musicfile);
  185.         }
  186.         load_all_music_sounds(musicdirectory);
  187.         igloaded = instrumentsloaded;
  188.     }
  189.  
  190.     //printf("Got to load_all_objects\n");
  191.  
  192. // [claforte Jan 6th 2001]
  193. // The following will crash on _BIG_ENDIAN architectures at the moment,
  194. // since the MD2 loading functions (ie: rip_md2_*) all assume that the machine is
  195. // little-endian.
  196.  
  197. //#ifdef _LITTLE_ENDIAN
  198.     load_all_objects(modname); // This is broken and needs to be fixed
  199.     
  200.     //    printf("Got to load mesh\n");
  201.     if(!load_mesh(modname))
  202.     {
  203.         general_error(0, 0, "LOAD PROBLEMS");
  204.     }
  205.     //printf("Got to setup_particles\n");
  206.     setup_particles();
  207.     //printf("Got to setup_passage\n");
  208.     setup_passage(modname);
  209.     //printf("Got to reset_players\n");
  210.     
  211.     reset_players();
  212.     //printf("Got to setup_characters\n");
  213.     
  214.     setup_characters(modname);
  215. //#endif //_LITTLE_ENDIAN
  216.     
  217.     //    printf("Got to reset_end_text\n");
  218.     reset_end_text();
  219.     //printf("Got to reset_press\n");
  220.     reset_press();
  221.     //printf("Got to setup_alliances\n");
  222.     setup_alliances(modname);
  223.  
  224.     // Load fonts and bars after other images, as not to hog videomem
  225.     //printf("Got to load_font\n");
  226.     load_font("basicdat/font.bmp", "basicdat/font.txt", FALSE);
  227.     //printf("Got to load_bars\n");
  228.     load_bars("basicdat/bars.bmp");
  229.     //printf("Got to load_map\n");
  230.     load_map(modname, FALSE);
  231.     //printf("Got to log_madused\n");
  232.     // GS - log_madused(FILENAME("basicdat/slotused.txt"));
  233.  
  234.  
  235.     // Now setup the music
  236.     //printf("Got to load_all_music_tracks\n");
  237.     // GS - load_all_music_tracks(smallname);
  238.     // GS - load_all_music_loops(smallname);
  239.     // GS - load_music_sequence(smallname);
  240.     play_next_track();
  241.     if(igloaded)
  242.     {
  243.         // Normal music failed, so default to interactive music
  244.         sprintf(generictext, FILENAME("%s/length.txt"), musicdirectory);
  245.         // GS - load_ig_length(generictext);
  246.         // GS - create_ig_trackmaster();
  247.     }
  248.  
  249.     // RTS stuff
  250.     clear_orders();
  251.  
  252.  
  253.     // Start playing the damage tile sound silently...
  254. /*PORT
  255.     play_sound_pvf_looped(damagetilesound, PANMID, VOLMIN, FRQDEFAULT);
  256. */
  257. }
  258.  
  259. //--------------------------------------------------------------------------------------------
  260. int get_module_data(int modnumber, char *szLoadName)
  261. {
  262.     // ZZ> This function loads the module data file
  263.     FILE *fileread;
  264.     char reference[128];
  265.     unsigned int idsz;
  266.     char cTmp;
  267.     int iTmp;
  268.  
  269.     fileread = fopen( FILENAME(szLoadName), "r"); 
  270.     if(fileread)
  271.     {
  272.         // Read basic data
  273.         globalname = szLoadName;
  274.         goto_colon(fileread);  get_name(fileread, modlongname[modnumber]);
  275.         goto_colon(fileread);  fscanf(fileread, "%s", reference);
  276.         goto_colon(fileread);  idsz = get_idsz(fileread);
  277.         if(module_reference_matches(reference, idsz))
  278.         {
  279.             globalname = szLoadName;
  280.             goto_colon(fileread);  fscanf(fileread, "%d", &iTmp);
  281.                 modimportamount[modnumber] = iTmp;
  282.             goto_colon(fileread);  cTmp = get_first_letter(fileread);
  283.                 modallowexport[modnumber] = FALSE;
  284.                 if(cTmp == 'T' || cTmp == 't')  modallowexport[modnumber] = TRUE;
  285.             goto_colon(fileread);  fscanf(fileread, "%d", &iTmp);  modminplayers[modnumber] = iTmp;
  286.             goto_colon(fileread);  fscanf(fileread, "%d", &iTmp);  modmaxplayers[modnumber] = iTmp;
  287.             goto_colon(fileread);  cTmp = get_first_letter(fileread);
  288.                 modrespawnvalid[modnumber] = FALSE;
  289.                 if(cTmp == 'T' || cTmp == 't')  modrespawnvalid[modnumber] = TRUE;
  290.                 if(cTmp == 'A' || cTmp == 'a')  modrespawnvalid[modnumber] = ANYTIME;
  291.             goto_colon(fileread);  cTmp = get_first_letter(fileread);
  292.                 modrtscontrol[modnumber] = FALSE;
  293.                 if(cTmp == 'T' || cTmp == 't')  modrtscontrol[modnumber] = TRUE;
  294.                 if(cTmp == 'A' || cTmp == 'a')  modrtscontrol[modnumber] = ALLSELECT;
  295.             goto_colon(fileread);  fscanf(fileread, "%s", generictext);
  296.                 iTmp = 0;
  297.                 while(iTmp < RANKSIZE-1)
  298.                 {
  299.                     modrank[modnumber][iTmp] = generictext[iTmp];
  300.                     iTmp++;
  301.                 }
  302.                 modrank[modnumber][iTmp] = 0;
  303.  
  304.  
  305.  
  306.             // Read the expansions
  307.             return TRUE;
  308.         }
  309.     }
  310.     return FALSE;
  311. }
  312.  
  313. //--------------------------------------------------------------------------------------------
  314. int get_module_summary(char *szLoadName)
  315. {
  316.     // ZZ> This function gets the quest description out of the module's menu file
  317.     FILE *fileread;
  318.     char cTmp;
  319.     char szLine[160];
  320.     int cnt;
  321.     int tnc;
  322.  
  323.     fileread = fopen(szLoadName, "r"); 
  324.     if(fileread)
  325.     {
  326.         // Skip over basic data
  327.         globalname = szLoadName;
  328.         goto_colon(fileread);  // Name...
  329.         goto_colon(fileread);  // Reference...
  330.         goto_colon(fileread);  // IDSZ...
  331.         goto_colon(fileread);  // Import...
  332.         goto_colon(fileread);  // Export...
  333.         goto_colon(fileread);  // Min players...
  334.         goto_colon(fileread);  // Max players...
  335.         goto_colon(fileread);  // Respawn...
  336.         goto_colon(fileread);  // RTS control...
  337.         goto_colon(fileread);  // Rank...
  338.  
  339.  
  340.         // Read the summary
  341.         cnt = 0;
  342.         while(cnt < SUMMARYLINES)
  343.         {
  344.             goto_colon(fileread);  fscanf(fileread, "%s", szLine);
  345.             tnc = 0;
  346.             cTmp = szLine[tnc];  if(cTmp == '_')  cTmp = ' ';
  347.             while(tnc < SUMMARYSIZE-1 && cTmp != 0)
  348.             {
  349.                 modsummary[cnt][tnc] = cTmp;
  350.                 tnc++;
  351.                 cTmp = szLine[tnc];  if(cTmp == '_')  cTmp = ' ';
  352.             }
  353.             modsummary[cnt][tnc] = 0;
  354.             cnt++;
  355.         }
  356.         return TRUE;
  357.     }
  358.     return FALSE;
  359. }
  360.  
  361.