Subversion Repositories eduke32

Rev

Rev 4941 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4941 Rev 5069
Line 111... Line 111...
111
        DO_FREE_AND_NULL(aGameArrays[i].szLabel);
111
        DO_FREE_AND_NULL(aGameArrays[i].szLabel);
112
}
112
}
113
113
114
int32_t Gv_ReadSave(int32_t fil, int32_t newbehav)
114
int32_t Gv_ReadSave(int32_t fil, int32_t newbehav)
115
{
115
{
116
    int32_t i, j;
-
 
117
    char savedstate[MAXVOLUMES*MAXLEVELS];
116
    char savedstate[MAXVOLUMES*MAXLEVELS];
118
    char tbuf[12];
117
    char tbuf[12];
119
118
120
    if (newbehav)
119
    if (newbehav)
121
    {
120
    {
Line 131... Line 130...
131
130
132
    //  Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
131
    //  Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
133
    //  AddLog(g_szBuf);
132
    //  AddLog(g_szBuf);
134
133
135
    if (kdfread(&g_gameVarCount,sizeof(g_gameVarCount),1,fil) != 1) goto corrupt;
134
    if (kdfread(&g_gameVarCount,sizeof(g_gameVarCount),1,fil) != 1) goto corrupt;
136
    for (i=0; i<g_gameVarCount; i++)
135
    for (int i=0; i<g_gameVarCount; i++)
137
    {
136
    {
138
        char *const olabel = aGameVars[i].szLabel;
137
        char *const olabel = aGameVars[i].szLabel;
139
138
140
        if (kdfread(&aGameVars[i], sizeof(gamevar_t), 1, fil) != 1)
139
        if (kdfread(&aGameVars[i], sizeof(gamevar_t), 1, fil) != 1)
141
            goto corrupt;
140
            goto corrupt;
Line 168... Line 167...
168
    //  Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
167
    //  Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
169
    //  AddLog(g_szBuf);
168
    //  AddLog(g_szBuf);
170
    Gv_RefreshPointers();
169
    Gv_RefreshPointers();
171
170
172
    if (kdfread(&g_gameArrayCount,sizeof(g_gameArrayCount),1,fil) != 1) goto corrupt;
171
    if (kdfread(&g_gameArrayCount,sizeof(g_gameArrayCount),1,fil) != 1) goto corrupt;
173
    for (i=0; i<g_gameArrayCount; i++)
172
    for (int i=0; i<g_gameArrayCount; i++)
174
    {
173
    {
175
        if (aGameArrays[i].dwFlags&GAMEARRAY_READONLY)
174
        if (aGameArrays[i].dwFlags&GAMEARRAY_READONLY)
176
            continue;
175
            continue;
177
176
178
        char *const olabel = aGameArrays[i].szLabel;
177
        char *const olabel = aGameArrays[i].szLabel;
Line 202... Line 201...
202
    //  Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
201
    //  Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
203
    //  AddLog(g_szBuf);
202
    //  AddLog(g_szBuf);
204
203
205
    if (kdfread(&savedstate[0],sizeof(savedstate),1,fil) != 1) goto corrupt;
204
    if (kdfread(&savedstate[0],sizeof(savedstate),1,fil) != 1) goto corrupt;
206
205
207
    for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
206
    for (int i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
208
    {
207
    {
209
        if (savedstate[i])
208
        if (savedstate[i])
210
        {
209
        {
211
            if (MapInfo[i].savedstate == NULL)
210
            if (MapInfo[i].savedstate == NULL)
212
                MapInfo[i].savedstate = (mapstate_t *)Xaligned_alloc(16, sizeof(mapstate_t));
211
                MapInfo[i].savedstate = (mapstate_t *)Xaligned_alloc(16, sizeof(mapstate_t));
213
            if (kdfread(MapInfo[i].savedstate,sizeof(mapstate_t),1,fil) != sizeof(mapstate_t)) goto corrupt;
212
            if (kdfread(MapInfo[i].savedstate,sizeof(mapstate_t),1,fil) != sizeof(mapstate_t)) goto corrupt;
214
            for (j=0; j<g_gameVarCount; j++)
213
            for (int j=0; j<g_gameVarCount; j++)
215
            {
214
            {
216
                if (aGameVars[j].dwFlags & GAMEVAR_NORESET) continue;
215
                if (aGameVars[j].dwFlags & GAMEVAR_NORESET) continue;
217
                if (aGameVars[j].dwFlags & GAMEVAR_PERPLAYER)
216
                if (aGameVars[j].dwFlags & GAMEVAR_PERPLAYER)
218
                {
217
                {
219
//                    if (!MapInfo[i].savedstate->vars[j])
218
//                    if (!MapInfo[i].savedstate->vars[j])
Line 267... Line 266...
267
    return(1);
266
    return(1);
268
}
267
}
269
268
270
void Gv_WriteSave(FILE *fil, int32_t newbehav)
269
void Gv_WriteSave(FILE *fil, int32_t newbehav)
271
{
270
{
272
    int32_t i, j;
-
 
273
    char savedstate[MAXVOLUMES*MAXLEVELS];
271
    char savedstate[MAXVOLUMES*MAXLEVELS];
274
272
275
    Bmemset(&savedstate,0,sizeof(savedstate));
273
    Bmemset(&savedstate,0,sizeof(savedstate));
276
274
277
    //   AddLog("Saving Game Vars to File");
275
    //   AddLog("Saving Game Vars to File");
278
    if (newbehav)
276
    if (newbehav)
279
        fwrite("BEG: EDuke32", 12, 1, fil);
277
        fwrite("BEG: EDuke32", 12, 1, fil);
280
278
281
    dfwrite(&g_gameVarCount,sizeof(g_gameVarCount),1,fil);
279
    dfwrite(&g_gameVarCount,sizeof(g_gameVarCount),1,fil);
282
280
283
    for (i=0; i<g_gameVarCount; i++)
281
    for (int i=0; i<g_gameVarCount; i++)
284
    {
282
    {
285
        dfwrite(&(aGameVars[i]),sizeof(gamevar_t),1,fil);
283
        dfwrite(&(aGameVars[i]),sizeof(gamevar_t),1,fil);
286
        dfwrite(aGameVars[i].szLabel,sizeof(uint8_t) * MAXVARLABEL, 1, fil);
284
        dfwrite(aGameVars[i].szLabel,sizeof(uint8_t) * MAXVARLABEL, 1, fil);
287
285
288
        if (aGameVars[i].dwFlags & GAMEVAR_PERPLAYER)
286
        if (aGameVars[i].dwFlags & GAMEVAR_PERPLAYER)
Line 299... Line 297...
299
        }
297
        }
300
    }
298
    }
301
299
302
    dfwrite(&g_gameArrayCount,sizeof(g_gameArrayCount),1,fil);
300
    dfwrite(&g_gameArrayCount,sizeof(g_gameArrayCount),1,fil);
303
301
304
    for (i=0; i<g_gameArrayCount; i++)
302
    for (int i=0; i<g_gameArrayCount; i++)
305
    {
303
    {
306
        if (aGameArrays[i].dwFlags&GAMEARRAY_READONLY)
304
        if (aGameArrays[i].dwFlags&GAMEARRAY_READONLY)
307
            continue;
305
            continue;
308
306
309
        // write for .size and .dwFlags (the rest are pointers):
307
        // write for .size and .dwFlags (the rest are pointers):
Line 315... Line 313...
315
313
316
    G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_FWD_NON0);
314
    G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_FWD_NON0);
317
    dfwrite(apScriptGameEvent,sizeof(apScriptGameEvent),1,fil);
315
    dfwrite(apScriptGameEvent,sizeof(apScriptGameEvent),1,fil);
318
    G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_BACK_NON0);
316
    G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_BACK_NON0);
319
317
320
    for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
318
    for (int i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
321
        if (MapInfo[i].savedstate != NULL)
319
        if (MapInfo[i].savedstate != NULL)
322
            savedstate[i] = 1;
320
            savedstate[i] = 1;
323
321
324
    dfwrite(&savedstate[0],sizeof(savedstate),1,fil);
322
    dfwrite(&savedstate[0],sizeof(savedstate),1,fil);
325
323
326
    for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
324
    for (int i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
327
        if (MapInfo[i].savedstate)
325
        if (MapInfo[i].savedstate)
328
        {
326
        {
329
            dfwrite(MapInfo[i].savedstate,sizeof(mapstate_t),1,fil);
327
            dfwrite(MapInfo[i].savedstate,sizeof(mapstate_t),1,fil);
330
            for (j=0; j<g_gameVarCount; j++)
328
            for (int j=0; j<g_gameVarCount; j++)
331
            {
329
            {
332
                if (aGameVars[j].dwFlags & GAMEVAR_NORESET) continue;
330
                if (aGameVars[j].dwFlags & GAMEVAR_NORESET) continue;
333
                if (aGameVars[j].dwFlags & GAMEVAR_PERPLAYER)
331
                if (aGameVars[j].dwFlags & GAMEVAR_PERPLAYER)
334
                {
332
                {
335
                    dfwrite(&MapInfo[i].savedstate->vars[j][0],sizeof(intptr_t) * MAXPLAYERS, 1, fil);
333
                    dfwrite(&MapInfo[i].savedstate->vars[j][0],sizeof(intptr_t) * MAXPLAYERS, 1, fil);
Line 398... Line 396...
398
}
396
}
399
397
400
// XXX: This function is very strange.
398
// XXX: This function is very strange.
401
void Gv_ResetVars(void) /* this is called during a new game and nowhere else */
399
void Gv_ResetVars(void) /* this is called during a new game and nowhere else */
402
{
400
{
403
    int32_t i;
-
 
404
-
 
405
    Gv_Free();
401
    Gv_Free();
406
402
407
    osd->log.errors = 0;
403
    osd->log.errors = 0;
408
404
409
    for (i=0; i<MAXGAMEVARS; i++)
405
    for (int i=0; i<MAXGAMEVARS; i++)
410
    {
406
    {
411
        if (aGameVars[i].szLabel != NULL)
407
        if (aGameVars[i].szLabel != NULL)
412
            Gv_NewVar(aGameVars[i].szLabel,
408
            Gv_NewVar(aGameVars[i].szLabel,
413
                      aGameVars[i].dwFlags & GAMEVAR_NODEFAULT ? aGameVars[i].val.lValue : aGameVars[i].lDefault,
409
                      aGameVars[i].dwFlags & GAMEVAR_NODEFAULT ? aGameVars[i].val.lValue : aGameVars[i].lDefault,
414
                      aGameVars[i].dwFlags);
410
                      aGameVars[i].dwFlags);
415
    }
411
    }
416
412
417
    for (i=0; i<MAXGAMEARRAYS; i++)
413
    for (int i=0; i<MAXGAMEARRAYS; i++)
418
    {
414
    {
419
        if (aGameArrays[i].szLabel != NULL && (aGameArrays[i].dwFlags & GAMEARRAY_RESET))
415
        if (aGameArrays[i].szLabel != NULL && (aGameArrays[i].dwFlags & GAMEARRAY_RESET))
420
            Gv_NewArray(aGameArrays[i].szLabel,aGameArrays[i].plValues,aGameArrays[i].size,aGameArrays[i].dwFlags);
416
            Gv_NewArray(aGameArrays[i].szLabel,aGameArrays[i].plValues,aGameArrays[i].size,aGameArrays[i].dwFlags);
421
    }
417
    }
422
}
418
}
Line 614... Line 610...
614
    id &= (MAXGAMEVARS - 1);
610
    id &= (MAXGAMEVARS - 1);
615
611
616
    int rv, f;
612
    int rv, f;
617
    f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK);
613
    f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK);
618
614
619
    if (!f) rv = (aGameVars[id].val.lValue ^ -negateResult) + negateResult;
615
    if (!f) rv = aGameVars[id].val.lValue;
620
    else if (f == GAMEVAR_PERPLAYER)
616
    else if (f == GAMEVAR_PERPLAYER)
621
    {
617
    {
622
        if (EDUKE32_PREDICT_FALSE((unsigned) iPlayer >= MAXPLAYERS)) goto bad_id;
618
        if (EDUKE32_PREDICT_FALSE((unsigned) iPlayer >= MAXPLAYERS)) goto badplayer;
623
        rv = (aGameVars[id].val.plValues[iPlayer] ^ -negateResult) + negateResult;
619
        rv = aGameVars[id].val.plValues[iPlayer];
624
    }
620
    }
625
    else if (f == GAMEVAR_PERACTOR)
621
    else if (f == GAMEVAR_PERACTOR)
626
    {
622
    {
627
        if (EDUKE32_PREDICT_FALSE((unsigned) iActor >= MAXSPRITES)) goto bad_id;
623
        if (EDUKE32_PREDICT_FALSE((unsigned) iActor >= MAXSPRITES)) goto badsprite;
628
        rv = (aGameVars[id].val.plValues[iActor] ^ -negateResult) + negateResult;
624
        rv = aGameVars[id].val.plValues[iActor];
629
    }
625
    }
630
    else switch (f)
626
    else switch (f)
631
    {
627
    {
632
        case GAMEVAR_INTPTR: rv = ((*((int32_t *)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult; break;
628
        case GAMEVAR_INTPTR: rv = *(int32_t *)aGameVars[id].val.lValue; break;
633
        case GAMEVAR_SHORTPTR: rv = ((*((int16_t *)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult; break;
629
        case GAMEVAR_SHORTPTR: rv = *(int16_t *)aGameVars[id].val.lValue; break;
634
        case GAMEVAR_CHARPTR: rv = ((*((char *)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult; break;
630
        case GAMEVAR_CHARPTR: rv = *(char *)aGameVars[id].val.lValue; break;
635
        default: EDUKE32_UNREACHABLE_SECTION(rv = 0; break);
631
        default: EDUKE32_UNREACHABLE_SECTION(rv = 0; break);
636
    }
632
    }
637
633
638
    return rv;
634
    return (rv ^ -negateResult) + negateResult;
639
635
640
nastyhacks:
636
nastyhacks:
641
    if (id & (MAXGAMEVARS << 2))  // array
637
    if (id & (MAXGAMEVARS << 2))  // array
642
    {
638
    {
643
        id &= (MAXGAMEVARS - 1);  // ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1));
639
        id &= (MAXGAMEVARS - 1);  // ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1));
Line 648... Line 644...
648
        {
644
        {
649
            iActor = index;
645
            iActor = index;
650
            goto badindex;
646
            goto badindex;
651
        }
647
        }
652
648
653
        return ((aGameArrays[id].plValues[index] ^ -negateResult) + negateResult);
649
        rv = aGameArrays[id].plValues[index];
654
    }
650
    }
655
-
 
656
    if (id&(MAXGAMEVARS<<3)) // struct shortcut vars
651
    else if (id&(MAXGAMEVARS<<3)) // struct shortcut vars
657
    {
652
    {
-
 
653
        int indexvar = *insptr;
658
        int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer);
654
        int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer);
659
655
660
        switch ((id&(MAXGAMEVARS-1)) - g_iSpriteVarID)
656
        switch ((id&(MAXGAMEVARS-1)) - g_iSpriteVarID)
661
        {
657
        {
662
        case 0: //if (id == g_iSpriteVarID)
658
        case 0: //if (id == g_iSpriteVarID)
663
        {
659
        {
664
            int32_t parm2 = 0, label = *insptr++;
660
            int const label = *insptr++;
665
661
666
            /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/
662
            /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/
667
            if (EDUKE32_PREDICT_FALSE(ActorLabels[label].flags & LABEL_HASPARM2))
663
            indexvar = (EDUKE32_PREDICT_FALSE(ActorLabels[label].flags & LABEL_HASPARM2)) ?
668
                parm2 = Gv_GetVar(*insptr++, iActor, iPlayer);
664
                        Gv_GetVar(*insptr++, iActor, iPlayer) : 0;
669
665
670
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSPRITES))
666
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSPRITES))
671
            {
667
            {
672
                iPlayer = index;
668
                iActor = index;
673
                goto badsprite;
669
                goto badsprite;
674
            }
670
            }
675
671
676
            return ((VM_AccessSpriteX(index, label, parm2) ^ -negateResult) + negateResult);
672
            rv = VM_AccessSpriteX(index, label, indexvar) ^ -negateResult;
-
 
673
            break;
677
        }
674
        }
-
 
675
678
        case 3: //else if (id == g_iPlayerVarID)
676
        case 3: //else if (id == g_iPlayerVarID)
679
        {
677
        {
680
            int32_t parm2 = 0, label = *insptr++;
678
            int const label = *insptr++;
681
679
682
            if (EDUKE32_PREDICT_FALSE(PlayerLabels[label].flags & LABEL_HASPARM2))
-
 
683
                parm2 = Gv_GetVar(*insptr++, iActor, iPlayer);
680
            if (indexvar == g_iThisActorID) index = vm.g_p;
684
681
-
 
682
            indexvar = (EDUKE32_PREDICT_FALSE(PlayerLabels[label].flags & LABEL_HASPARM2)) ?
685
            if (index == vm.g_i) index = vm.g_p;
683
                Gv_GetVar(*insptr++, iActor, iPlayer) : 0;
686
684
687
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXPLAYERS))
685
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXPLAYERS))
688
            {
686
            {
689
                iPlayer = index;
687
                iPlayer = index;
690
                goto badplayer;
688
                goto badplayer;
691
            }
689
            }
692
690
693
            return ((VM_AccessPlayerX(index, label, parm2) ^ -negateResult) + negateResult);
691
            rv = VM_AccessPlayerX(index, label, indexvar);
-
 
692
            break;
694
        }
693
        }
-
 
694
695
        case 4: //else if (id == g_iActorVarID)
695
        case 4: //else if (id == g_iActorVarID)
696
            return ((Gv_GetVar(*insptr++, index, iPlayer) ^ -negateResult) + negateResult);
696
            rv = Gv_GetVar(*insptr++, index, iPlayer);
-
 
697
            break;
-
 
698
697
        case 1: //else if (id == g_iSectorVarID)
699
        case 1: //else if (id == g_iSectorVarID)
698
            if (index == vm.g_i) index = sprite[vm.g_i].sectnum;
700
            if (indexvar == g_iThisActorID) index = sprite[vm.g_i].sectnum;
699
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSECTORS))
701
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSECTORS))
700
            {
702
            {
701
                iPlayer = index;
703
                iPlayer = index;
702
                insptr++;
704
                insptr++;
703
                goto badsector;
705
                goto badsector;
704
            }
706
            }
705
            return ((VM_AccessSectorX(index, *insptr++) ^ -negateResult) + negateResult);
707
            rv = VM_AccessSectorX(index, *insptr++);
-
 
708
            break;
-
 
709
706
        case 2: //else if (id == g_iWallVarID)
710
        case 2: //else if (id == g_iWallVarID)
707
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXWALLS))
711
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXWALLS))
708
            {
712
            {
709
                iPlayer = index;
713
                iPlayer = index;
710
                insptr++;
714
                insptr++;
711
                goto badwall;
715
                goto badwall;
712
            }
716
            }
713
            return ((VM_AccessWallX(index, *insptr++) ^ -negateResult) + negateResult);
717
            rv = VM_AccessWallX(index, *insptr++);
-
 
718
            break;
-
 
719
714
        default:
720
        default:
715
            EDUKE32_UNREACHABLE_SECTION(return -1);
721
            EDUKE32_UNREACHABLE_SECTION(return -1);
716
        }
722
        }
717
    }
723
    }
-
 
724
    else
-
 
725
    {
-
 
726
        CON_ERRPRINTF("Gv_GetVar(): invalid gamevar ID (%d)\n", id);
-
 
727
        return -1;
-
 
728
    }
718
729
719
    CON_ERRPRINTF("Gv_GetVar(): invalid gamevar ID (%d)\n", id);
730
    return (rv ^ -negateResult) + negateResult;
720
    return -1;
-
 
721
-
 
722
bad_id:
-
 
723
    CON_ERRPRINTF("Gv_GetVar(): invalid sprite/player ID %d/%d\n", iActor,iPlayer);
-
 
724
    return -1;
-
 
725
-
 
726
731
727
badindex:
732
badindex:
728
    CON_ERRPRINTF("Gv_GetVar(): invalid array index (%s[%d])\n", aGameArrays[id].szLabel,iActor);
733
    CON_ERRPRINTF("Gv_GetVar(): invalid array index (%s[%d])\n", aGameArrays[id].szLabel,iActor);
729
    return -1;
734
    return -1;
730
735
731
badplayer:
736
badplayer:
732
    CON_ERRPRINTF("Gv_GetVar(): invalid player ID %d\n", iPlayer);
737
    CON_ERRPRINTF("Gv_GetVar(): invalid player ID %d\n", iPlayer);
733
    return -1;
738
    return -1;
734
739
735
badsprite:
740
badsprite:
736
    CON_ERRPRINTF("Gv_GetVar(): invalid sprite ID %d\n", iPlayer);
741
    CON_ERRPRINTF("Gv_GetVar(): invalid sprite ID %d\n", iActor);
737
    return -1;
742
    return -1;
738
743
739
badsector:
744
badsector:
740
    CON_ERRPRINTF("Gv_GetVar(): invalid sector ID %d\n", iPlayer);
745
    CON_ERRPRINTF("Gv_GetVar(): invalid sector ID %d\n", iPlayer);
741
    return -1;
746
    return -1;
Line 743... Line 748...
743
badwall:
748
badwall:
744
    CON_ERRPRINTF("Gv_GetVar(): invalid wall ID %d\n", iPlayer);
749
    CON_ERRPRINTF("Gv_GetVar(): invalid wall ID %d\n", iPlayer);
745
    return -1;
750
    return -1;
746
}
751
}
747
752
748
void __fastcall Gv_SetVar(int32_t id, int32_t lValue, int32_t iActor, int32_t iPlayer)
753
void __fastcall Gv_SetVar(int32_t const id, int32_t const lValue, int32_t const iActor, int32_t const iPlayer)
749
{
754
{
750
    if (EDUKE32_PREDICT_FALSE((unsigned)id >= (unsigned)g_gameVarCount)) goto badvarid;
755
    if (EDUKE32_PREDICT_FALSE((unsigned)id >= (unsigned)g_gameVarCount)) goto badvarid;
751
756
752
    int f;
757
    int f;
753
    f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK);
758
    f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK);
Line 810... Line 815...
810
        return vm.g_i;
815
        return vm.g_i;
811
816
812
    if (id == MAXGAMEVARS)
817
    if (id == MAXGAMEVARS)
813
        return *insptr++;
818
        return *insptr++;
814
819
815
    int negateResult = !!(id & (MAXGAMEVARS << 1)), rv = -1, f;
820
    int const negateResult = !!(id & (MAXGAMEVARS << 1));
-
 
821
    int rv = -1;
816
822
817
    if (EDUKE32_PREDICT_FALSE(id >= g_gameVarCount && negateResult == 0))
823
    if (EDUKE32_PREDICT_FALSE(id >= g_gameVarCount && negateResult == 0))
818
        goto nastyhacks;
824
        goto nastyhacks;
-
 
825
    else
-
 
826
    {
-
 
827
        id &= MAXGAMEVARS-1;
819
828
820
    id &= MAXGAMEVARS-1;
829
        int const f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK);
821
830
-
 
831
        if (!f) rv = aGameVars[id].val.lValue;
822
    f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK);
832
        else if (f == GAMEVAR_PERPLAYER)
-
 
833
        {
-
 
834
            if (EDUKE32_PREDICT_FALSE((unsigned) vm.g_p >= MAXPLAYERS))
-
 
835
                goto perr;
-
 
836
            rv = aGameVars[id].val.plValues[vm.g_p];
-
 
837
        }
-
 
838
        else if (f == GAMEVAR_PERACTOR)
-
 
839
            rv = aGameVars[id].val.plValues[vm.g_i];
-
 
840
        else switch (f)
-
 
841
        {
-
 
842
            case GAMEVAR_INTPTR:
-
 
843
                rv = (*((int32_t *) aGameVars[id].val.lValue)); break;
-
 
844
            case GAMEVAR_SHORTPTR:
-
 
845
                rv = (*((int16_t *) aGameVars[id].val.lValue)); break;
-
 
846
            case GAMEVAR_CHARPTR:
-
 
847
                rv = (*((uint8_t *) aGameVars[id].val.lValue)); break;
-
 
848
        }
823
849
824
    if (!f) rv = (aGameVars[id].val.lValue ^ -negateResult) + negateResult;
850
        return (rv ^ -negateResult) + negateResult;
825
    else if (f == GAMEVAR_PERPLAYER)
-
 
826
    {
-
 
827
        if (EDUKE32_PREDICT_FALSE((unsigned) vm.g_p >= MAXPLAYERS))
-
 
828
            goto perr;
-
 
829
        rv = (aGameVars[id].val.plValues[vm.g_p] ^ -negateResult) + negateResult;
-
 
830
    }
-
 
831
    else if (f == GAMEVAR_PERACTOR)
-
 
832
        rv = (aGameVars[id].val.plValues[vm.g_i] ^ -negateResult) + negateResult;
-
 
833
    else switch (f)
-
 
834
    {
-
 
835
        case GAMEVAR_INTPTR:
-
 
836
            rv = ((*((int32_t *) aGameVars[id].val.lValue)) ^ -negateResult) + negateResult; break;
-
 
837
        case GAMEVAR_SHORTPTR:
-
 
838
            rv = ((*((int16_t *) aGameVars[id].val.lValue)) ^ -negateResult) + negateResult; break;
-
 
839
        case GAMEVAR_CHARPTR:
-
 
840
            rv = ((*((uint8_t *) aGameVars[id].val.lValue)) ^ -negateResult) + negateResult; break;
-
 
841
    }
851
    }
842
852
843
    return rv;
-
 
844
-
 
845
perr:
-
 
846
    id = vm.g_p;
-
 
847
    CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], id);
-
 
848
    return -1;
-
 
849
-
 
850
nastyhacks:
853
nastyhacks:
851
    if (id & (MAXGAMEVARS << 2))  // array
854
    if (id & (MAXGAMEVARS << 2))  // array
852
    {
855
    {
853
        int32_t index = Gv_GetVarX(*insptr++);
856
        int const index = Gv_GetVarX(*insptr++);
854
857
855
        id &= (MAXGAMEVARS - 1);  // ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1));
858
        id &= (MAXGAMEVARS - 1);  // ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1));
856
859
-
 
860
        int const siz = (aGameArrays[id].dwFlags & GAMEARRAY_VARSIZE) ?
857
        int siz = (aGameArrays[id].dwFlags & GAMEARRAY_VARSIZE) ? Gv_GetVarX(aGameArrays[id].size) : aGameArrays[id].size;
861
            Gv_GetVarX(aGameArrays[id].size) : aGameArrays[id].size;
858
862
859
        if (EDUKE32_PREDICT_FALSE((unsigned) index >= (unsigned) siz))
863
        if (EDUKE32_PREDICT_FALSE((unsigned)index >= (unsigned)siz))
860
        {
864
        {
861
            negateResult = index;
-
 
862
            CON_ERRPRINTF("%s %s[%d]\n", gvxerrs[GVX_BADINDEX], aGameArrays[id].szLabel, index);
865
            CON_ERRPRINTF("%s %s[%d]\n", gvxerrs[GVX_BADINDEX], aGameArrays[id].szLabel, index);
863
            return -1;
866
            return -1;
864
        }
867
        }
865
868
866
        switch (aGameArrays[id].dwFlags & GAMEARRAY_TYPE_MASK)
869
        switch (aGameArrays[id].dwFlags & GAMEARRAY_TYPE_MASK)
867
        {
870
        {
868
            case 0: return ((aGameArrays[id].plValues)[index] ^ -negateResult) + negateResult;
871
            case 0: rv = (aGameArrays[id].plValues)[index]; break;
869
            case GAMEARRAY_OFINT: return (((int32_t *) aGameArrays[id].plValues)[index] ^ -negateResult) + negateResult;
872
            case GAMEARRAY_OFINT: rv = ((int32_t *)aGameArrays[id].plValues)[index]; break;
870
            case GAMEARRAY_OFSHORT:
-
 
871
                return (((int16_t *) aGameArrays[id].plValues)[index] ^ -negateResult) + negateResult;
873
            case GAMEARRAY_OFSHORT: rv = ((int16_t *)aGameArrays[id].plValues)[index]; break;
872
            case GAMEARRAY_OFCHAR: return (((uint8_t *) aGameArrays[id].plValues)[index] ^ -negateResult) + negateResult;
874
            case GAMEARRAY_OFCHAR: rv = ((uint8_t *)aGameArrays[id].plValues)[index]; break;
873
            default: EDUKE32_UNREACHABLE_SECTION(return -1);
-
 
874
        }
875
        }
875
    }
876
    }
876
-
 
877
    if (id&(MAXGAMEVARS<<3)) // struct shortcut vars
877
    else if (id & (MAXGAMEVARS << 3))  // struct shortcut vars
878
    {
878
    {
-
 
879
        int indexvar = *insptr;
879
        int32_t index=Gv_GetVarX(*insptr++);
880
        int index = Gv_GetVarX(*insptr++);
880
881
881
        switch ((id&(MAXGAMEVARS-1)) - g_iSpriteVarID)
882
        switch ((id & (MAXGAMEVARS - 1)) - g_iSpriteVarID)
882
        {
883
        {
883
        case 0: //if (id == g_iSpriteVarID)
884
            case 0:  // if (id == g_iSpriteVarID)
884
        {
885
            {
885
            int32_t parm2 = 0, label = *insptr++;
886
                int const label = *insptr++;
886
887
887
            /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/
888
                /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/
888
            if (EDUKE32_PREDICT_FALSE(ActorLabels[label].flags & LABEL_HASPARM2))
889
                indexvar = (EDUKE32_PREDICT_FALSE(ActorLabels[label].flags & LABEL_HASPARM2)) ?
889
                parm2 = Gv_GetVarX(*insptr++);
890
                            Gv_GetVarX(*insptr++) : 0;
890
891
891
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSPRITES))
892
                if (EDUKE32_PREDICT_FALSE((unsigned)index >= MAXSPRITES))
892
            {
893
                {
893
                id = index;
894
                    id = index;
894
                CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADSPRITE], id);
895
                    CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADSPRITE], id);
895
                return -1;
896
                    return -1;
-
 
897
                }
-
 
898
-
 
899
                rv = VM_AccessSpriteX(index, label, indexvar);
-
 
900
                break;
896
            }
901
            }
897
902
898
            return ((VM_AccessSpriteX(index, label, parm2) ^ -negateResult) + negateResult);
-
 
899
        }
-
 
900
        case 3: //else if (id == g_iPlayerVarID)
903
            case 3:  // else if (id == g_iPlayerVarID)
901
        {
904
            {
902
            int32_t parm2 = 0, label = *insptr++;
905
                int const label = *insptr++;
903
906
904
            if (EDUKE32_PREDICT_FALSE(PlayerLabels[label].flags & LABEL_HASPARM2))
907
                if (indexvar == g_iThisActorID)
905
                parm2 = Gv_GetVarX(*insptr++);
908
                    index = vm.g_p;
906
909
-
 
910
                indexvar = (EDUKE32_PREDICT_FALSE(PlayerLabels[label].flags & LABEL_HASPARM2)) ?
907
            if (index == vm.g_i) index = vm.g_p;
911
                    Gv_GetVarX(*insptr++) : 0;
908
912
909
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXPLAYERS))
913
                if (EDUKE32_PREDICT_FALSE((unsigned)index >= MAXPLAYERS))
910
            {
914
                {
911
                id = index;
915
                    id = index;
912
                CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], id);
916
                    CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], id);
913
                return -1;
917
                    return -1;
914
            }
918
                }
915
            return ((VM_AccessPlayerX(index, label, parm2) ^ -negateResult) + negateResult);
-
 
916
        }
919
917
        case 4: //else if (id == g_iActorVarID)
-
 
918
            return ((Gv_GetVar(*insptr++, index, vm.g_p) ^ -negateResult) + negateResult);
-
 
919
        case 1: //else if (id == g_iSectorVarID)
-
 
920
            if (index == vm.g_i) index = sprite[vm.g_i].sectnum;
-
 
921
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSECTORS))
-
 
922
            {
-
 
923
                id = index;
-
 
924
                insptr++;
-
 
925
                CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADSECTOR], id);
-
 
926
                return -1;
-
 
927
            }
-
 
928
            return ((VM_AccessSectorX(index, *insptr++) ^ -negateResult) + negateResult);
920
                rv = VM_AccessPlayerX(index, label, indexvar);
929
        case 2: //else if (id == g_iWallVarID)
-
 
930
            if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXWALLS))
-
 
931
            {
-
 
932
                id = index;
-
 
933
                insptr++;
-
 
934
                CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADWALL], id);
-
 
935
                return -1;
921
                break;
936
            }
922
            }
-
 
923
-
 
924
            case 4:  // else if (id == g_iActorVarID)
-
 
925
                rv = Gv_GetVar(*insptr++, index, vm.g_p);
-
 
926
                break;
-
 
927
-
 
928
            case 1:  // else if (id == g_iSectorVarID)
-
 
929
                if (indexvar == g_iThisActorID)
-
 
930
                    index = sprite[vm.g_i].sectnum;
-
 
931
-
 
932
                if (EDUKE32_PREDICT_FALSE((unsigned)index >= MAXSECTORS))
-
 
933
                {
-
 
934
                    id = index;
-
 
935
                    insptr++;
-
 
936
                    CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADSECTOR], id);
-
 
937
                    return -1;
-
 
938
                }
937
            return ((VM_AccessWallX(index, *insptr++) ^ -negateResult) + negateResult);
939
                rv = VM_AccessSectorX(index, *insptr++);
-
 
940
                break;
-
 
941
-
 
942
            case 2:  // else if (id == g_iWallVarID)
-
 
943
                if (EDUKE32_PREDICT_FALSE((unsigned)index >= MAXWALLS))
-
 
944
                {
-
 
945
                    id = index;
-
 
946
                    insptr++;
-
 
947
                    CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADWALL], id);
-
 
948
                    return -1;
938
        default:
949
                }
-
 
950
                rv = VM_AccessWallX(index, *insptr++);
-
 
951
                break;
-
 
952
939
            EDUKE32_UNREACHABLE_SECTION(return -1);
953
            default: EDUKE32_UNREACHABLE_SECTION(return -1);
940
        }
954
        }
941
    }
955
    }
942
956
943
    EDUKE32_UNREACHABLE_SECTION(return -1);
957
    return (rv ^ -negateResult) + negateResult;
-
 
958
-
 
959
perr:
-
 
960
    id = vm.g_p;
-
 
961
    CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], id);
-
 
962
    return -1;
944
}
963
}
945
964
946
void __fastcall Gv_SetVarX(int32_t id, int32_t lValue)
965
void __fastcall Gv_SetVarX(int32_t const id, int32_t const lValue)
947
{
966
{
948
    int f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK);
967
    int const f = aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK);
949
968
950
    if (!f) aGameVars[id].val.lValue = lValue;
969
    if (!f) aGameVars[id].val.lValue = lValue;
951
    else if (f == GAMEVAR_PERPLAYER)
970
    else if (f == GAMEVAR_PERPLAYER)
952
    {
971
    {
953
        if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_p >= MAXPLAYERS)) goto badindex;
972
        if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_p >= MAXPLAYERS)) goto badindex;
Line 956... Line 975...
956
    else if (f == GAMEVAR_PERACTOR)
975
    else if (f == GAMEVAR_PERACTOR)
957
    {
976
    {
958
        if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_i >= MAXSPRITES)) goto badindex;
977
        if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_i >= MAXSPRITES)) goto badindex;
959
        aGameVars[id].val.plValues[vm.g_i] = lValue;
978
        aGameVars[id].val.plValues[vm.g_i] = lValue;
960
    }
979
    }
961
    else
980
    else switch (f)
962
    {
981
    {
963
        switch (f)
-
 
964
        {
-
 
965
            case GAMEVAR_INTPTR: *((int32_t *)aGameVars[id].val.lValue) = (int32_t)lValue; break;
982
        case GAMEVAR_INTPTR: *((int32_t *)aGameVars[id].val.lValue) = (int32_t)lValue; break;
966
            case GAMEVAR_SHORTPTR: *((int16_t *)aGameVars[id].val.lValue) = (int16_t)lValue; break;
983
        case GAMEVAR_SHORTPTR: *((int16_t *)aGameVars[id].val.lValue) = (int16_t)lValue; break;
967
            case GAMEVAR_CHARPTR: *((uint8_t *)aGameVars[id].val.lValue) = (uint8_t)lValue; break;
984
        case GAMEVAR_CHARPTR: *((uint8_t *)aGameVars[id].val.lValue) = (uint8_t)lValue; break;
968
        }
-
 
969
    }
985
    }
970
986
971
    return;
987
    return;
972
988
973
badindex:
989
badindex:
974
    CON_ERRPRINTF("Gv_SetVar(): invalid index (%d) for gamevar %s\n",
990
    CON_ERRPRINTF("Gv_SetVar(): invalid index (%d) for gamevar %s\n",
975
               aGameVars[id].dwFlags & GAMEVAR_PERACTOR ? vm.g_i : vm.g_p,
991
               aGameVars[id].dwFlags & GAMEVAR_PERACTOR ? vm.g_i : vm.g_p,
976
               aGameVars[id].szLabel);
992
               aGameVars[id].szLabel);
977
}
993
}
978
994
979
int32_t Gv_GetVarByLabel(const char *szGameLabel, int32_t lDefault, int32_t iActor, int32_t iPlayer)
995
int32_t Gv_GetVarByLabel(const char *szGameLabel, int32_t const lDefault, int32_t const iActor, int32_t const iPlayer)
980
{
996
{
981
    int32_t i = hash_find(&h_gamevars,szGameLabel);
997
    int32_t const i = hash_find(&h_gamevars,szGameLabel);
982
-
 
983
    return EDUKE32_PREDICT_FALSE(i < 0) ? lDefault : Gv_GetVar(i, iActor, iPlayer);
998
    return EDUKE32_PREDICT_FALSE(i < 0) ? lDefault : Gv_GetVar(i, iActor, iPlayer);
984
}
999
}
985
1000
986
static intptr_t *Gv_GetVarDataPtr(const char *szGameLabel)
1001
static intptr_t *Gv_GetVarDataPtr(const char *szGameLabel)
987
{
1002
{
988
    int32_t i = hash_find(&h_gamevars,szGameLabel);
1003
    int32_t const i = hash_find(&h_gamevars,szGameLabel);
989
1004
990
    if (EDUKE32_PREDICT_FALSE(i < 0))
1005
    if (EDUKE32_PREDICT_FALSE(i < 0))
991
        return NULL;
1006
        return NULL;
992
1007
993
    if (aGameVars[i].dwFlags & (GAMEVAR_PERACTOR | GAMEVAR_PERPLAYER))
1008
    if (aGameVars[i].dwFlags & (GAMEVAR_PERACTOR | GAMEVAR_PERPLAYER))
Line 1007... Line 1022...
1007
#if !defined LUNATIC
1022
#if !defined LUNATIC
1008
    char aszBuf[64];
1023
    char aszBuf[64];
1009
1024
1010
    //AddLog("ResetWeaponDefaults");
1025
    //AddLog("ResetWeaponDefaults");
1011
1026
1012
    for (int j=MAXPLAYERS-1; j>=0; j--)
1027
    for (int i = 0; i < MAX_WEAPONS; ++i)
1013
    {
1028
    {
1014
        for (int i=MAX_WEAPONS-1; i>=0; i--)
1029
        for (int j = 0; j < MAXPLAYERS; ++j)
1015
        {
1030
        {
1016
            Bsprintf(aszBuf,"WEAPON%d_CLIP",i);
1031
            Bsprintf(aszBuf, "WEAPON%d_CLIP", i);
1017
            aplWeaponClip[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1032
            aplWeaponClip[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1018
            Bsprintf(aszBuf,"WEAPON%d_RELOAD",i);
1033
            Bsprintf(aszBuf, "WEAPON%d_RELOAD", i);
1019
            aplWeaponReload[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1034
            aplWeaponReload[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1020
            Bsprintf(aszBuf,"WEAPON%d_FIREDELAY",i);
1035
            Bsprintf(aszBuf, "WEAPON%d_FIREDELAY", i);
1021
            aplWeaponFireDelay[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1036
            aplWeaponFireDelay[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1022
            Bsprintf(aszBuf,"WEAPON%d_TOTALTIME",i);
1037
            Bsprintf(aszBuf, "WEAPON%d_TOTALTIME", i);
1023
            aplWeaponTotalTime[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1038
            aplWeaponTotalTime[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1024
            Bsprintf(aszBuf,"WEAPON%d_HOLDDELAY",i);
1039
            Bsprintf(aszBuf, "WEAPON%d_HOLDDELAY", i);
1025
            aplWeaponHoldDelay[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1040
            aplWeaponHoldDelay[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1026
            Bsprintf(aszBuf,"WEAPON%d_FLAGS",i);
1041
            Bsprintf(aszBuf, "WEAPON%d_FLAGS", i);
1027
            aplWeaponFlags[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1042
            aplWeaponFlags[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1028
            Bsprintf(aszBuf,"WEAPON%d_SHOOTS",i);
1043
            Bsprintf(aszBuf, "WEAPON%d_SHOOTS", i);
1029
            aplWeaponShoots[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1044
            aplWeaponShoots[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1030
            if ((unsigned)aplWeaponShoots[i][j] >= MAXTILES)
1045
            if ((unsigned)aplWeaponShoots[i][j] >= MAXTILES)
1031
                aplWeaponShoots[i][j] = 0;
1046
                aplWeaponShoots[i][j] = 0;
1032
            Bsprintf(aszBuf,"WEAPON%d_SPAWNTIME",i);
1047
            Bsprintf(aszBuf, "WEAPON%d_SPAWNTIME", i);
1033
            aplWeaponSpawnTime[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1048
            aplWeaponSpawnTime[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1034
            Bsprintf(aszBuf,"WEAPON%d_SPAWN",i);
1049
            Bsprintf(aszBuf, "WEAPON%d_SPAWN", i);
1035
            aplWeaponSpawn[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1050
            aplWeaponSpawn[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1036
            Bsprintf(aszBuf,"WEAPON%d_SHOTSPERBURST",i);
1051
            Bsprintf(aszBuf, "WEAPON%d_SHOTSPERBURST", i);
1037
            aplWeaponShotsPerBurst[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1052
            aplWeaponShotsPerBurst[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1038
            Bsprintf(aszBuf,"WEAPON%d_WORKSLIKE",i);
1053
            Bsprintf(aszBuf, "WEAPON%d_WORKSLIKE", i);
1039
            aplWeaponWorksLike[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1054
            aplWeaponWorksLike[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1040
            Bsprintf(aszBuf,"WEAPON%d_INITIALSOUND",i);
1055
            Bsprintf(aszBuf, "WEAPON%d_INITIALSOUND", i);
1041
            aplWeaponInitialSound[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1056
            aplWeaponInitialSound[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1042
            Bsprintf(aszBuf,"WEAPON%d_FIRESOUND",i);
1057
            Bsprintf(aszBuf, "WEAPON%d_FIRESOUND", i);
1043
            aplWeaponFireSound[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1058
            aplWeaponFireSound[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1044
            Bsprintf(aszBuf,"WEAPON%d_SOUND2TIME",i);
1059
            Bsprintf(aszBuf, "WEAPON%d_SOUND2TIME", i);
1045
            aplWeaponSound2Time[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1060
            aplWeaponSound2Time[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1046
            Bsprintf(aszBuf,"WEAPON%d_SOUND2SOUND",i);
1061
            Bsprintf(aszBuf, "WEAPON%d_SOUND2SOUND", i);
1047
            aplWeaponSound2Sound[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1062
            aplWeaponSound2Sound[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1048
            Bsprintf(aszBuf,"WEAPON%d_RELOADSOUND1",i);
1063
            Bsprintf(aszBuf, "WEAPON%d_RELOADSOUND1", i);
1049
            aplWeaponReloadSound1[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1064
            aplWeaponReloadSound1[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1050
            Bsprintf(aszBuf,"WEAPON%d_RELOADSOUND2",i);
1065
            Bsprintf(aszBuf, "WEAPON%d_RELOADSOUND2", i);
1051
            aplWeaponReloadSound2[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1066
            aplWeaponReloadSound2[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1052
            Bsprintf(aszBuf,"WEAPON%d_SELECTSOUND",i);
1067
            Bsprintf(aszBuf, "WEAPON%d_SELECTSOUND", i);
1053
            aplWeaponSelectSound[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1068
            aplWeaponSelectSound[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1054
            Bsprintf(aszBuf,"WEAPON%d_FLASHCOLOR",i);
1069
            Bsprintf(aszBuf, "WEAPON%d_FLASHCOLOR", i);
1055
            aplWeaponFlashColor[i][j]=Gv_GetVarByLabel(aszBuf,0, -1, j);
1070
            aplWeaponFlashColor[i][j] = Gv_GetVarByLabel(aszBuf, 0, -1, j);
1056
        }
1071
        }
1057
    }
1072
    }
1058
1073
1059
    g_iReturnVarID=Gv_GetVarIndex("RETURN");
1074
    g_iReturnVarID = Gv_GetVarIndex("RETURN");
1060
    g_iWeaponVarID=Gv_GetVarIndex("WEAPON");
1075
    g_iWeaponVarID = Gv_GetVarIndex("WEAPON");
1061
    g_iWorksLikeVarID=Gv_GetVarIndex("WORKSLIKE");
1076
    g_iWorksLikeVarID = Gv_GetVarIndex("WORKSLIKE");
1062
    g_iZRangeVarID=Gv_GetVarIndex("ZRANGE");
1077
    g_iZRangeVarID = Gv_GetVarIndex("ZRANGE");
1063
    g_iAngRangeVarID=Gv_GetVarIndex("ANGRANGE");
1078
    g_iAngRangeVarID = Gv_GetVarIndex("ANGRANGE");
1064
    g_iAimAngleVarID=Gv_GetVarIndex("AUTOAIMANGLE");
1079
    g_iAimAngleVarID = Gv_GetVarIndex("AUTOAIMANGLE");
1065
    g_iLoTagID=Gv_GetVarIndex("LOTAG");
1080
    g_iLoTagID = Gv_GetVarIndex("LOTAG");
1066
    g_iHiTagID=Gv_GetVarIndex("HITAG");
1081
    g_iHiTagID = Gv_GetVarIndex("HITAG");
1067
    g_iTextureID=Gv_GetVarIndex("TEXTURE");
1082
    g_iTextureID = Gv_GetVarIndex("TEXTURE");
1068
    g_iThisActorID=Gv_GetVarIndex("THISACTOR");
1083
    g_iThisActorID = Gv_GetVarIndex("THISACTOR");
1069
1084
1070
    g_iSpriteVarID=Gv_GetVarIndex("sprite");
1085
    g_iSpriteVarID = Gv_GetVarIndex("sprite");
1071
    g_iSectorVarID=Gv_GetVarIndex("sector");
1086
    g_iSectorVarID = Gv_GetVarIndex("sector");
1072
    g_iWallVarID=Gv_GetVarIndex("wall");
1087
    g_iWallVarID = Gv_GetVarIndex("wall");
1073
    g_iPlayerVarID=Gv_GetVarIndex("player");
1088
    g_iPlayerVarID = Gv_GetVarIndex("player");
1074
    g_iActorVarID=Gv_GetVarIndex("actorvar");
1089
    g_iActorVarID = Gv_GetVarIndex("actorvar");
1075
#endif
1090
#endif
1076
1091
1077
    for (int i = 0; i <= MAXTILES - 1; i++)
1092
    for (int i = 0; i <= MAXTILES - 1; i++)
1078
        Bmemcpy(&ProjectileData[i], &g_tile[i].defproj, sizeof(projectile_t));
1093
        Bmemcpy(&ProjectileData[i], &g_tile[i].defproj, sizeof(projectile_t));
1079
1094
Line 1196... Line 1211...
1196
    },
1211
    },
1197
};
1212
};
1198
1213
1199
// KEEPINSYNC with what is contained above
1214
// KEEPINSYNC with what is contained above
1200
// XXX: ugly
1215
// XXX: ugly
1201
static int32_t G_StaticToDynamicTile(int32_t tile)
1216
static int32_t G_StaticToDynamicTile(int32_t const tile)
1202
{
1217
{
1203
    switch (tile)
1218
    switch (tile)
1204
    {
1219
    {
1205
    case CHAINGUN__STATIC: return CHAINGUN;
1220
    case CHAINGUN__STATIC: return CHAINGUN;
1206
    case FREEZEBLAST__STATIC: return FREEZEBLAST;
1221
    case FREEZEBLAST__STATIC: return FREEZEBLAST;
Line 1216... Line 1231...
1216
    case SHRINKER__STATIC: return SHRINKER;
1231
    case SHRINKER__STATIC: return SHRINKER;
1217
    default: return tile;
1232
    default: return tile;
1218
    }
1233
    }
1219
}
1234
}
1220
1235
1221
static int32_t G_StaticToDynamicSound(int32_t sound)
1236
static int32_t G_StaticToDynamicSound(int32_t const sound)
1222
{
1237
{
1223
    switch (sound)
1238
    switch (sound)
1224
    {
1239
    {
1225
    case CAT_FIRE__STATIC: return CAT_FIRE;
1240
    case CAT_FIRE__STATIC: return CAT_FIRE;
1226
    case CHAINGUN_FIRE__STATIC: return CHAINGUN_FIRE;
1241
    case CHAINGUN_FIRE__STATIC: return CHAINGUN_FIRE;
Line 1279... Line 1294...
1279
1294
1280
// Process the dynamic {tile,sound} mappings after CON has been translated.
1295
// Process the dynamic {tile,sound} mappings after CON has been translated.
1281
// We cannot do this before, because the dynamic maps are not yet set up then.
1296
// We cannot do this before, because the dynamic maps are not yet set up then.
1282
void Gv_FinalizeWeaponDefaults(void)
1297
void Gv_FinalizeWeaponDefaults(void)
1283
{
1298
{
1284
    int32_t i;
-
 
1285
-
 
1286
    for (i=0; i<MAX_WEAPONS; i++)
1299
    for (int i=0; i<MAX_WEAPONS; i++)
1287
    {
1300
    {
1288
        FINISH_WEAPON_DEFAULT_TILE(i, Shoots);
1301
        FINISH_WEAPON_DEFAULT_TILE(i, Shoots);
1289
        FINISH_WEAPON_DEFAULT_TILE(i, Spawn);
1302
        FINISH_WEAPON_DEFAULT_TILE(i, Spawn);
1290
1303
1291
        FINISH_WEAPON_DEFAULT_SOUND(i, InitialSound);
1304
        FINISH_WEAPON_DEFAULT_SOUND(i, InitialSound);
Line 1309... Line 1322...
1309
{
1322
{
1310
    // only call ONCE
1323
    // only call ONCE
1311
#if !defined LUNATIC
1324
#if !defined LUNATIC
1312
    char aszBuf[64];
1325
    char aszBuf[64];
1313
#endif
1326
#endif
1314
    int32_t i;
-
 
1315
1327
1316
    if (NAM)
1328
    if (NAM)
1317
    {
1329
    {
1318
        weapondefaults[PISTOL_WEAPON].Clip = 20;
1330
        weapondefaults[PISTOL_WEAPON].Clip = 20;
1319
        weapondefaults[PISTOL_WEAPON].Reload = 50;
1331
        weapondefaults[PISTOL_WEAPON].Reload = 50;
Line 1325... Line 1337...
1325
        weapondefaults[GROW_WEAPON].SpawnTime = 2;
1337
        weapondefaults[GROW_WEAPON].SpawnTime = 2;
1326
        weapondefaults[GROW_WEAPON].Spawn = SHELL;
1338
        weapondefaults[GROW_WEAPON].Spawn = SHELL;
1327
        weapondefaults[GROW_WEAPON].FireSound = 0;
1339
        weapondefaults[GROW_WEAPON].FireSound = 0;
1328
    }
1340
    }
1329
1341
1330
    for (i=0; i<MAX_WEAPONS; i++)
1342
    for (int i=0; i<MAX_WEAPONS; i++)
1331
    {
1343
    {
1332
        ADDWEAPONVAR(i, WorksLike);
1344
        ADDWEAPONVAR(i, WorksLike);
1333
        ADDWEAPONVAR(i, Clip);
1345
        ADDWEAPONVAR(i, Clip);
1334
        ADDWEAPONVAR(i, Reload);
1346
        ADDWEAPONVAR(i, Reload);
1335
        ADDWEAPONVAR(i, FireDelay);
1347
        ADDWEAPONVAR(i, FireDelay);
Line 1348... Line 1360...
1348
        ADDWEAPONVAR(i, ReloadSound2);
1360
        ADDWEAPONVAR(i, ReloadSound2);
1349
        ADDWEAPONVAR(i, SelectSound);
1361
        ADDWEAPONVAR(i, SelectSound);
1350
        ADDWEAPONVAR(i, FlashColor);
1362
        ADDWEAPONVAR(i, FlashColor);
1351
    }
1363
    }
1352
#ifdef LUNATIC
1364
#ifdef LUNATIC
1353
    for (i=0; i<MAXPLAYERS; i++)
1365
    for (int i=0; i<MAXPLAYERS; i++)
1354
    {
1366
    {
1355
        DukePlayer_t *ps = g_player[i].ps;
1367
        DukePlayer_t *ps = g_player[i].ps;
1356
1368
1357
        ps->pipebombControl = NAM ? PIPEBOMB_TIMER : PIPEBOMB_REMOTE;
1369
        ps->pipebombControl = NAM ? PIPEBOMB_TIMER : PIPEBOMB_REMOTE;
1358
        ps->pipebombLifetime = NAM_GRENADE_LIFETIME;
1370
        ps->pipebombLifetime = NAM_GRENADE_LIFETIME;
Line 1510... Line 1522...
1510
}
1522
}
1511
1523
1512
#if !defined LUNATIC
1524
#if !defined LUNATIC
1513
void Gv_InitWeaponPointers(void)
1525
void Gv_InitWeaponPointers(void)
1514
{
1526
{
1515
    int32_t i;
-
 
1516
    char aszBuf[64];
1527
    char aszBuf[64];
1517
    // called from game Init AND when level is loaded...
1528
    // called from game Init AND when level is loaded...
1518
1529
1519
    //AddLog("Gv_InitWeaponPointers");
1530
    //AddLog("Gv_InitWeaponPointers");
1520
1531
1521
    for (i=(MAX_WEAPONS-1); i>=0; i--)
1532
    for (int i=(MAX_WEAPONS-1); i>=0; i--)
1522
    {
1533
    {
1523
        Bsprintf(aszBuf,"WEAPON%d_CLIP",i);
1534
        Bsprintf(aszBuf,"WEAPON%d_CLIP",i);
1524
        aplWeaponClip[i]=Gv_GetVarDataPtr(aszBuf);
1535
        aplWeaponClip[i]=Gv_GetVarDataPtr(aszBuf);
1525
        if (!aplWeaponClip[i])
1536
        if (!aplWeaponClip[i])
1526
        {
1537
        {