DOOM64-RE

DOOM 64 Reverse Engineering
Log | Files | Refs | README | LICENSE

p_macros.c (4460B)


      1 /* P_Macros.c */
      2 #include "doomdef.h"
      3 #include "r_local.h"
      4 #include "p_local.h"
      5 #include "st_main.h"
      6 
      7 /* MACRO Variables */
      8 macro_t     *activemacro;       // 800A6094
      9 mobj_t      *macroactivator;    // 800A6098
     10 line_t      macrotempline;      // 800A60A0
     11 line_t      *macroline;         // 800A60EC
     12 thinker_t   *macrothinker;      // 800A60F0
     13 int         macrointeger;       // 800A60F4
     14 macro_t     *restartmacro;      // 800A60F8
     15 int         macrocounter;       // 800A60FC
     16 macroactivator_t macroqueue[4]; // 800A6100
     17 int         macroidx1;          // 800A6120
     18 int         macroidx2;          // 800A6124
     19 
     20 // [GEC]
     21 // Prevents crashes when changing the special line to 0,
     22 // causing the index of the initial macro to be lost.
     23 int         tempMacroIndex;
     24 
     25 int P_StartMacro(int macroindex, line_t *line, mobj_t *thing) // 80021088
     26 {
     27     macro_t *macro;
     28 
     29     if (activemacro)
     30         return 0;
     31 
     32     macro = macros[macroindex-256];
     33     if (macro->id <= 0)
     34     {
     35         if (macro->id == 0)
     36             line->special = 0;
     37 
     38         return 0;
     39     }
     40 
     41     activemacro = macro;
     42     macroactivator = thing;
     43     macrothinker = NULL;
     44     macroline = line;
     45     tempMacroIndex = SPECIALMASK(macroline->special)-256; // [GEC] temporarily save macro index
     46 
     47     D_memcpy(&macrotempline, line, sizeof(line_t));
     48     P_ChangeSwitchTexture(line, line->special & MLU_REPEAT);
     49 
     50     return 1;
     51 }
     52 
     53 int P_SuspendMacro(void) // 80021148
     54 {
     55     macroactivator_t *activatorInfo;
     56 
     57     if(!activemacro)
     58         return 0;
     59 
     60     macrothinker = NULL;
     61     macrocounter = 0;
     62     activemacro = NULL;
     63 
     64     if (!(macroline->special & MLU_REPEAT))
     65     {
     66         //macros[SPECIALMASK(macroline->special)-256]->id = 0;
     67         macros[tempMacroIndex]->id = 0;
     68         macroline->special = 0;
     69     }
     70 
     71     if (macroidx2 != macroidx1)
     72     {
     73         activatorInfo = &macroqueue[macroidx2];
     74         macroidx2 = (macroidx2 + 1) & 3;
     75 
     76         P_ActivateLineByTag(activatorInfo->tag, activatorInfo->activator);
     77     }
     78 
     79     return 1;
     80 }
     81 
     82 void P_ToggleMacros(int tag, boolean toggleon) // 80021214
     83 {
     84     macro_t *macro = macros[tag-256];
     85 
     86     if(toggleon)
     87     {
     88         if(macro->id >= 0)
     89             return;
     90     }
     91     else
     92     {
     93         if(macro->id <= 0)
     94             return;
     95     }
     96 
     97     macro->id = -macro->id;
     98 }
     99 
    100 void P_RunMacros(void) // 8002126C
    101 {
    102     thinker_t *thinker;
    103     int id;
    104 
    105     if(!activemacro)
    106         return;
    107 
    108     if(macrothinker)
    109     {
    110         //ST_DebugPrint("macrothinker %x wait", macrothinker);
    111         return; /* must wait for this thinker to finish */
    112     }
    113 
    114     //ST_DebugPrint("activemacro->id %d",activemacro->id);
    115 
    116 
    117     /* keep track of the current thinker */
    118     thinker = thinkercap.prev;
    119 
    120     while(activemacro->id != 0)
    121     {
    122         id = activemacro->id;
    123 
    124         macrotempline.special = activemacro->special;
    125         macrotempline.tag = activemacro->tag;
    126 
    127         activemacro++;
    128 
    129         /* invoke a line special from this macro */
    130         P_UseSpecialLine(&macrotempline, macroactivator);
    131 
    132         /* keep executing macros until reaching a new batch ID */
    133         if (id != activemacro->id)
    134         {
    135             if (activemacro->id == 0)
    136             {
    137                 //ST_DebugPrint("P_SuspendMacro act->id %d",activemacro->id);
    138                 P_SuspendMacro();
    139                 return;
    140             }
    141 
    142             /* if the last macro produced a new thinker then keep track of it */
    143             if (thinker != thinkercap.prev)
    144             {
    145                 /* don't execute any more macros until this thinker is done */
    146                 macrothinker = thinkercap.prev;
    147                 return;
    148             }
    149         }
    150 
    151         thinker = thinkercap.prev;
    152     }
    153 }
    154 
    155 void P_RestartMacro(line_t *line, int id) // 80021384
    156 {
    157     macro_t *macro;
    158 
    159     if(!activemacro)
    160         return;
    161 
    162     if (macrocounter == 0)
    163     {
    164         //macro = macros[SPECIALMASK(macroline->special)-256];
    165         macro = macros[tempMacroIndex];
    166 
    167         /* find the first macro in the batch to restart on */
    168         while((macro->id != 0) && (macro->id != id))
    169         {
    170             macro++;
    171         }
    172 
    173         if ((macro->id != 0) && (line->tag != 0))
    174         {
    175             /* its now set */
    176             activemacro = macro;
    177             restartmacro = macro;
    178             macrocounter = line->tag;
    179 
    180         }
    181     }
    182     else
    183     {
    184         if(macrocounter > 0)
    185         {
    186             if(--macrocounter == 0)
    187                 return;
    188         }
    189 
    190         // restart the macro
    191         activemacro = restartmacro;
    192     }
    193 }