From 15c744f3dad2668d4d848c0023016899fad63f95 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 14 May 2020 00:04:14 +0200 Subject: [PATCH] - movement code of the VM transitioned --- source/build/include/build.h | 21 + source/games/duke/CMakeLists.txt | 1 + source/games/duke/src/actors.cpp | 329 ++++- source/games/duke/src/actors.h | 5 + source/games/duke/src/actors_d.cpp | 206 ++++ source/games/duke/src/actors_r.cpp | 323 +++++ source/games/duke/src/condef.h | 4 +- source/games/duke/src/gamedef.cpp | 11 +- source/games/duke/src/gameexec.cpp | 1613 +++++++++++++++++++++++++ source/games/duke/src/gameexec.h | 20 +- source/games/duke/src/gamevar.cpp | 1 + source/games/duke/src/gamevar.h | 3 +- source/games/duke/src/global.h | 2 +- source/games/duke/src/sector.h | 2 +- source/games/duke/src/zz_game.cpp | 18 +- source/games/duke/src/zz_gameexec.cpp | 588 +-------- source/games/duke/src/zz_namesdyn.cpp | 2 + source/games/duke/src/zz_player.cpp | 10 +- source/games/duke/src/zz_premap.cpp | 8 +- source/games/duke/src/zz_rrdh.cpp | 2 +- source/games/duke/src/zz_savegame.cpp | 4 +- source/games/duke/src/zz_sector.cpp | 2 +- 22 files changed, 2550 insertions(+), 625 deletions(-) create mode 100644 source/games/duke/src/gameexec.cpp diff --git a/source/build/include/build.h b/source/build/include/build.h index 8b2dbb1e6..d26e60843 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -889,9 +889,30 @@ static FORCE_INLINE void rotatesprite_win(int32_t sx, int32_t sy, int32_t z, int void getzrange(const vec3_t *pos, int16_t sectnum, int32_t *ceilz, int32_t *ceilhit, int32_t *florz, int32_t *florhit, int32_t walldist, uint32_t cliptype) ATTRIBUTE((nonnull(1,3,4,5,6))); +inline void getzrange(int x, int y, int z, int16_t sectnum, int32_t* ceilz, int32_t* ceilhit, int32_t* florz, + int32_t* florhit, int32_t walldist, uint32_t cliptype) +{ + vec3_t v = { x, y, z }; + getzrange(&v, sectnum, ceilz, ceilhit, florz, florhit, walldist, cliptype); +} extern vec2_t hitscangoal; int32_t hitscan(const vec3_t *sv, int16_t sectnum, int32_t vx, int32_t vy, int32_t vz, hitdata_t *hitinfo, uint32_t cliptype) ATTRIBUTE((nonnull(1,6))); +inline int hitscan(int x, int y, int z, int16_t sectnum, int32_t vx, int32_t vy, int32_t vz, + short* hitsect, short* hitwall, short* hitspr, int* hitx, int* hity, int* hitz, uint32_t cliptype) +{ + vec3_t v{ x,y,z }; + hitdata_t hd{}; + int res = hitscan(&v, sectnum, vx, vy, vz, &hd, cliptype); + *hitsect = hd.sect; + *hitwall = hd.wall; + *hitspr = hd.sprite; + *hitx = hd.pos.x; + *hity = hd.pos.y; + *hitz = hd.pos.z ; + return res; +} + void neartag(int32_t xs, int32_t ys, int32_t zs, int16_t sectnum, int16_t ange, int16_t *neartagsector, int16_t *neartagwall, int16_t *neartagsprite, int32_t *neartaghitdist, int32_t neartagrange, uint8_t tagsearch, diff --git a/source/games/duke/CMakeLists.txt b/source/games/duke/CMakeLists.txt index 7e363b59f..556975c31 100644 --- a/source/games/duke/CMakeLists.txt +++ b/source/games/duke/CMakeLists.txt @@ -6,6 +6,7 @@ set( PCH_SOURCES src/actors_lava.cpp src/bowling.cpp src/gamedef.cpp + src/gameexec.cpp src/gamevar.cpp src/zz_actors.cpp src/sectors.cpp diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index f77540a49..3f0664ec1 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -67,6 +67,7 @@ int ifhitsectors_d(int sectnum); int ifhitsectors_r(int sectnum); int ifhitbyweapon_r(int sn); int ifhitbyweapon_d(int sn); +int adjustfall(spritetype* s, int c); bool ceilingspace(int sectnum) { @@ -1111,7 +1112,7 @@ void movetrash(int i) { makeitfall(i); if (krand() & 1) s->zvel -= 256; - if (klabs(s->xvel) < 48) + if (abs(s->xvel) < 48) s->xvel += (krand() & 3); } else deletesprite(i); @@ -4727,4 +4728,330 @@ void handle_se130(int i, int countmax, int EXPLOSION2) } +//--------------------------------------------------------------------------- +// +// code fron gameexec/conrun +// +//--------------------------------------------------------------------------- + +int getincangle(int a,int na) +{ + a &= 2047; + na &= 2047; + + if(abs(a-na) < 1024) + return (na-a); + else + { + if(na > 1024) na -= 2048; + if(a > 1024) a -= 2048; + + na -= 2048; + a -= 2048; + return (na-a); + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void getglobalz(int i) +{ + int hz,lz,zr; + + spritetype *s = &sprite[i]; + + if( s->statnum == STAT_PLAYER || s->statnum == STAT_STANDABLE || s->statnum == STAT_ZOMBIEACTOR || s->statnum == STAT_ACTOR || s->statnum == STAT_PROJECTILE) + { + if(s->statnum == STAT_PROJECTILE) + zr = 4; + else zr = 127; + + getzrange(s->x,s->y,s->z-(FOURSLEIGHT),s->sectnum,&hittype[i].ceilingz,&hz,&hittype[i].floorz,&lz,zr,CLIPMASK0); + + if( (lz&49152) == 49152 && (sprite[lz&(MAXSPRITES-1)].cstat&48) == 0 ) + { + lz &= (MAXSPRITES-1); + if( badguy(&sprite[lz]) && sprite[lz].pal != 1) + { + if( s->statnum != 4 ) + { + hittype[i].flags |= SFLAG_NOFLOORSHADOW; + //hittype[i].dispicnum = -4; // No shadows on actors + s->xvel = -256; + ssp(i,CLIPMASK0); + } + } + else if(sprite[lz].picnum == APLAYER && badguy(s) ) + { + hittype[i].flags |= SFLAG_NOFLOORSHADOW; + //hittype[i].dispicnum = -4; // No shadows on actors + s->xvel = -256; + ssp(i,CLIPMASK0); + } + else if(s->statnum == 4 && sprite[lz].picnum == APLAYER) + if(s->owner == lz) + { + hittype[i].ceilingz = sector[s->sectnum].ceilingz; + hittype[i].floorz = sector[s->sectnum].floorz; + } + } + } + else + { + hittype[i].ceilingz = sector[s->sectnum].ceilingz; + hittype[i].floorz = sector[s->sectnum].floorz; + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void makeitfall(int i) +{ + spritetype *s = &sprite[i]; + int hz,lz,c; + + if( floorspace(s->sectnum) ) + c = 0; + else + { + if( ceilingspace(s->sectnum) || sector[s->sectnum].lotag == ST_2_UNDERWATER) + c = gc/6; + else c = gc; + } + + if (isRRRA()) + { + c = adjustfall(s, c); // this accesses sprite indices and cannot be in shared code. Should be done better. + } + + if( ( s->statnum == STAT_ACTOR || s->statnum == STAT_PLAYER || s->statnum == STAT_ZOMBIEACTOR || s->statnum == STAT_STANDABLE ) ) + getzrange(s->x,s->y,s->z-(FOURSLEIGHT),s->sectnum,&hittype[i].ceilingz,&hz,&hittype[i].floorz,&lz,127L,CLIPMASK0); + else + { + hittype[i].ceilingz = sector[s->sectnum].ceilingz; + hittype[i].floorz = sector[s->sectnum].floorz; + } + + if( s->z < hittype[i].floorz-(FOURSLEIGHT) ) + { + if( sector[s->sectnum].lotag == 2 && s->zvel > 3122 ) + s->zvel = 3144; + if(s->zvel < 6144) + s->zvel += c; + else s->zvel = 6144; + s->z += s->zvel; + } + if( s->z >= hittype[i].floorz-(FOURSLEIGHT) ) + { + s->z = hittype[i].floorz - FOURSLEIGHT; + s->zvel = 0; + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +int dodge(spritetype* s) +{ + short i; + long bx, by, mx, my, bxvect, byvect, mxvect, myvect, d; + + mx = s->x; + my = s->y; + mxvect = sintable[(s->ang + 512) & 2047]; myvect = sintable[s->ang & 2047]; + + for (i = headspritestat[4]; i >= 0; i = nextspritestat[i]) //weapons list + { + if (sprite[i].owner == i || sprite[i].sectnum != s->sectnum) + continue; + + bx = sprite[i].x - mx; + by = sprite[i].y - my; + bxvect = sintable[(sprite[i].ang + 512) & 2047]; byvect = sintable[sprite[i].ang & 2047]; + + if (mxvect * bx + myvect * by >= 0) + if (bxvect * bx + byvect * by < 0) + { + d = bxvect * by - byvect * bx; + if (abs(d) < 65536 * 64) + { + s->ang -= 512 + (krand() & 1024); + return 1; + } + } + } + return 0; +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +int furthestangle(int i, int angs) +{ + short j, hitsect, hitwall, hitspr, furthest_angle, angincs; + int hx, hy, hz, d, greatestd; + spritetype* s = &sprite[i]; + + greatestd = -(1 << 30); + angincs = 2048 / angs; + + if (s->picnum != APLAYER) + if ((hittype[i].t_data[0] & 63) > 2) return(s->ang + 1024); + + for (j = s->ang; j < (2048 + s->ang); j += angincs) + { + hitscan(s->x, s->y, s->z - (8 << 8), s->sectnum, + sintable[(j + 512) & 2047], + sintable[j & 2047], 0, + &hitsect, &hitwall, &hitspr, &hx, &hy, &hz, CLIPMASK1); + + d = abs(hx - s->x) + abs(hy - s->y); + + if (d > greatestd) + { + greatestd = d; + furthest_angle = j; + } + } + return (furthest_angle & 2047); +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +int furthestcanseepoint(int i, spritetype* ts, int* dax, int* day) +{ + short j, hitsect, hitwall, hitspr, angincs; + int hx, hy, hz, d, da;//, d, cd, ca,tempx,tempy,cx,cy; + spritetype* s = &sprite[i]; + + if ((hittype[i].t_data[0] & 63)) return -1; + + if (ud.multimode < 2 && ud.player_skill < 3) + angincs = 2048 / 2; + else angincs = 2048 / (1 + (krand() & 1)); + + for (j = ts->ang; j < (2048 + ts->ang); j += (angincs - (krand() & 511))) + { + hitscan(ts->x, ts->y, ts->z - (16 << 8), ts->sectnum, + sintable[(j + 512) & 2047], + sintable[j & 2047], 16384 - (krand() & 32767), + &hitsect, &hitwall, &hitspr, &hx, &hy, &hz, CLIPMASK1); + + d = abs(hx - ts->x) + abs(hy - ts->y); + da = abs(hx - s->x) + abs(hy - s->y); + + if (d < da) + if (cansee(hx, hy, hz, hitsect, s->x, s->y, s->z - (16 << 8), s->sectnum)) + { + *dax = hx; + *day = hy; + return hitsect; + } + } + return -1; +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void alterang(int a, int g_i, int g_p) +{ + short aang, angdif, goalang, j; + int ticselapsed; + intptr_t *moveptr; + int* g_t = hittype[g_i].t_data; + auto* g_sp = &sprite[g_i]; + + moveptr = apScript + g_t[1]; + + ticselapsed = (g_t[0]) & 31; + + aang = g_sp->ang; + + g_sp->xvel += (*moveptr - g_sp->xvel) / 5; + if (g_sp->zvel < 648) g_sp->zvel += ((*(moveptr + 1) << 4) - g_sp->zvel) / 5; + + if (isRRRA() && (a & windang)) + g_sp->ang = WindDir; + else if (a & seekplayer) + { + j = !isRR() && ps[g_p].holoduke_on; + + // NOTE: looks like 'owner' is set to target sprite ID... + + if (j >= 0 && cansee(sprite[j].x, sprite[j].y, sprite[j].z, sprite[j].sectnum, g_sp->x, g_sp->y, g_sp->z, g_sp->sectnum)) + g_sp->owner = j; + else g_sp->owner = ps[g_p].i; + + if (sprite[g_sp->owner].picnum == APLAYER) + goalang = getangle(hittype[g_i].lastvx - g_sp->x, hittype[g_i].lastvy - g_sp->y); + else + goalang = getangle(sprite[g_sp->owner].x - g_sp->x, sprite[g_sp->owner].y - g_sp->y); + + if (g_sp->xvel && g_sp->picnum != TILE_DRONE) + { + angdif = getincangle(aang, goalang); + + if (ticselapsed < 2) + { + if (abs(angdif) < 256) + { + j = 128 - (krand() & 256); + g_sp->ang += j; + if (hits(g_i) < 844) + g_sp->ang -= j; + } + } + else if (ticselapsed > 18 && ticselapsed < 26) // choose + { + if (abs(angdif >> 2) < 128) g_sp->ang = goalang; + else g_sp->ang += angdif >> 2; + } + } + else g_sp->ang = goalang; + } + + if (ticselapsed < 1) + { + j = 2; + if (a & furthestdir) + { + goalang = furthestangle(g_i, j); + g_sp->ang = goalang; + g_sp->owner = ps[g_p].i; + } + + if (a & fleeenemy) + { + goalang = furthestangle(g_i, j); + g_sp->ang = goalang; // += angdif; // = getincangle(aang,goalang)>>1; + } + } +} + + + + + END_DUKE_NS diff --git a/source/games/duke/src/actors.h b/source/games/duke/src/actors.h index 0ef79e343..4bb8d44a7 100644 --- a/source/games/duke/src/actors.h +++ b/source/games/duke/src/actors.h @@ -76,7 +76,9 @@ enum amoveflags_t face_player_smart = 64, fleeenemy = 128, jumptoplayer_only = 256, + justjump1 = 256, jumptoplayer_bits = 257, // NOTE: two bits set! + jumptoplayer = 257, // NOTE: two bits set! seekplayer = 512, furthestdir = 1024, dodgebullet = 4096, @@ -456,6 +458,9 @@ int ifhitbyweapon(int sn); int movesprite(short spritenum, int xchange, int ychange, int zchange, unsigned int cliptype); void lotsofmoney(spritetype* s, short n); +int dodge(spritetype*); +void alterang(int a, int g_i, int g_p); + // tile names which are identical for all games. enum { diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 70377288a..6ef746eb5 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -3950,4 +3950,210 @@ void moveeffectors_d(void) //STATNUM 3 } } +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void move_d(int g_i, int g_p, int g_x) +{ + auto g_sp = &sprite[g_i]; + auto g_t = hittype[g_i].t_data; + int l; + intptr_t* moveptr; + short a, goalang, angdif; + int daxvel; + + a = g_sp->hitag; + + if (a == -1) a = 0; + + g_t[0]++; + + if (a & face_player) + { + if (ps[g_p].newowner >= 0) + goalang = getangle(ps[g_p].oposx - g_sp->x, ps[g_p].oposy - g_sp->y); + else goalang = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); + angdif = getincangle(g_sp->ang, goalang) >> 2; + if (angdif > -8 && angdif < 0) angdif = 0; + g_sp->ang += angdif; + } + + if (a & spin) + g_sp->ang += sintable[((g_t[0] << 3) & 2047)] >> 6; + + if (a & face_player_slow) + { + if (ps[g_p].newowner >= 0) + goalang = getangle(ps[g_p].oposx - g_sp->x, ps[g_p].oposy - g_sp->y); + else goalang = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); + angdif = ksgn(getincangle(g_sp->ang, goalang)) << 5; + if (angdif > -32 && angdif < 0) + { + angdif = 0; + g_sp->ang = goalang; + } + g_sp->ang += angdif; + } + + + if ((a & jumptoplayer) == jumptoplayer) + { + if (g_t[0] < 16) + g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] >> 5); + } + + if (a & face_player_smart) + { + long newx, newy; + + newx = ps[g_p].posx + (ps[g_p].posxv / 768); + newy = ps[g_p].posy + (ps[g_p].posyv / 768); + goalang = getangle(newx - g_sp->x, newy - g_sp->y); + angdif = getincangle(g_sp->ang, goalang) >> 2; + if (angdif > -8 && angdif < 0) angdif = 0; + g_sp->ang += angdif; + } + + if (g_t[1] == 0 || a == 0) + { + if ((badguy(g_sp) && g_sp->extra <= 0) || (hittype[g_i].bposx != g_sp->x) || (hittype[g_i].bposy != g_sp->y)) + { + hittype[g_i].bposx = g_sp->x; + hittype[g_i].bposy = g_sp->y; + setsprite(g_i, g_sp->x, g_sp->y, g_sp->z); + } + return; + } + + moveptr = apScript + g_t[1]; + + if (a & geth) g_sp->xvel += (*moveptr - g_sp->xvel) >> 1; + if (a & getv) g_sp->zvel += ((*(moveptr + 1) << 4) - g_sp->zvel) >> 1; + + if (a & dodgebullet) + dodge(g_sp); + + if (g_sp->picnum != APLAYER) + alterang(a, g_i, g_p); + + if (g_sp->xvel > -6 && g_sp->xvel < 6) g_sp->xvel = 0; + + a = badguy(g_sp); + + if (g_sp->xvel || g_sp->zvel) + { + if (a && g_sp->picnum != ROTATEGUN) + { + if ((g_sp->picnum == DRONE || g_sp->picnum == COMMANDER) && g_sp->extra > 0) + { + if (g_sp->picnum == COMMANDER) + { + hittype[g_i].floorz = l = getflorzofslope(g_sp->sectnum, g_sp->x, g_sp->y); + if (g_sp->z > (l - (8 << 8))) + { + if (g_sp->z > (l - (8 << 8))) g_sp->z = l - (8 << 8); + g_sp->zvel = 0; + } + + hittype[g_i].ceilingz = l = getceilzofslope(g_sp->sectnum, g_sp->x, g_sp->y); + if ((g_sp->z - l) < (80 << 8)) + { + g_sp->z = l + (80 << 8); + g_sp->zvel = 0; + } + } + else + { + if (g_sp->zvel > 0) + { + hittype[g_i].floorz = l = getflorzofslope(g_sp->sectnum, g_sp->x, g_sp->y); + if (g_sp->z > (l - (30 << 8))) + g_sp->z = l - (30 << 8); + } + else + { + hittype[g_i].ceilingz = l = getceilzofslope(g_sp->sectnum, g_sp->x, g_sp->y); + if ((g_sp->z - l) < (50 << 8)) + { + g_sp->z = l + (50 << 8); + g_sp->zvel = 0; + } + } + } + } + else if (g_sp->picnum != ORGANTIC) + { + if (g_sp->zvel > 0 && hittype[g_i].floorz < g_sp->z) + g_sp->z = hittype[g_i].floorz; + if (g_sp->zvel < 0) + { + l = getceilzofslope(g_sp->sectnum, g_sp->x, g_sp->y); + if ((g_sp->z - l) < (66 << 8)) + { + g_sp->z = l + (66 << 8); + g_sp->zvel >>= 1; + } + } + } + } + else if (g_sp->picnum == APLAYER) + if ((g_sp->z - hittype[g_i].ceilingz) < (32 << 8)) + g_sp->z = hittype[g_i].ceilingz + (32 << 8); + + daxvel = g_sp->xvel; + angdif = g_sp->ang; + + if (a && g_sp->picnum != ROTATEGUN) + { + if (g_x < 960 && g_sp->xrepeat > 16) + { + + daxvel = -(1024 - g_x); + angdif = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); + + if (g_x < 512) + { + ps[g_p].posxv = 0; + ps[g_p].posyv = 0; + } + else + { + ps[g_p].posxv = mulscale(ps[g_p].posxv, dukefriction - 0x2000, 16); + ps[g_p].posyv = mulscale(ps[g_p].posyv, dukefriction - 0x2000, 16); + } + } + else if (g_sp->picnum != DRONE && g_sp->picnum != SHARK && g_sp->picnum != COMMANDER) + { + if (hittype[g_i].bposz != g_sp->z || (ud.multimode < 2 && ud.player_skill < 2)) + { + if ((g_t[0] & 1) || ps[g_p].actorsqu == g_i) return; + else daxvel <<= 1; + } + else + { + if ((g_t[0] & 3) || ps[g_p].actorsqu == g_i) return; + else daxvel <<= 2; + } + } + } + + hittype[g_i].movflag = movesprite(g_i, + (daxvel * (sintable[(angdif + 512) & 2047])) >> 14, + (daxvel * (sintable[angdif & 2047])) >> 14, g_sp->zvel, CLIPMASK0); + } + + if (a) + { + if (sector[g_sp->sectnum].ceilingstat & 1) + g_sp->shade += (sector[g_sp->sectnum].ceilingshade - g_sp->shade) >> 1; + else g_sp->shade += (sector[g_sp->sectnum].floorshade - g_sp->shade) >> 1; + + if (sector[g_sp->sectnum].floorpicnum == MIRROR) + deletesprite(g_i); + } +} + END_DUKE_NS diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 07548abe2..e160dec51 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -4027,4 +4027,327 @@ void moveeffectors_r(void) //STATNUM 3 } } + +//--------------------------------------------------------------------------- +// +// game specific part of makeitfall. +// +//--------------------------------------------------------------------------- + +int adjustfall(spritetype *s, int c) +{ + if ((s->picnum == BIKERB || s->picnum == CHEERB) && c == gc) + c = gc>>2; + else if (s->picnum == BIKERBV2 && c == gc) + c = gc>>3; + return c; +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void move_r(int g_i, int g_p, int g_x) +{ + auto g_sp = &sprite[g_i]; + auto g_t = hittype[g_i].t_data; + int l; + intptr_t *moveptr; + short a, goalang, angdif; + int daxvel; + + a = g_sp->hitag; + + if (a == -1) a = 0; + + g_t[0]++; + + if (a & face_player) + { + if (ps[g_p].newowner >= 0) + goalang = getangle(ps[g_p].oposx - g_sp->x, ps[g_p].oposy - g_sp->y); + else goalang = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); + angdif = getincangle(g_sp->ang, goalang) >> 2; + if (angdif > -8 && angdif < 0) angdif = 0; + g_sp->ang += angdif; + } + + if (a & spin) + g_sp->ang += sintable[((g_t[0] << 3) & 2047)] >> 6; + + if (a & face_player_slow) + { + if (ps[g_p].newowner >= 0) + goalang = getangle(ps[g_p].oposx - g_sp->x, ps[g_p].oposy - g_sp->y); + else goalang = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); + angdif = ksgn(getincangle(g_sp->ang, goalang)) << 5; + if (angdif > -32 && angdif < 0) + { + angdif = 0; + g_sp->ang = goalang; + } + g_sp->ang += angdif; + } + + if (isRRRA()) + { + if (a & antifaceplayerslow) + { + if (ps[g_p].newowner >= 0) + goalang = (getangle(ps[g_p].oposx - g_sp->x, ps[g_p].oposy - g_sp->y) + 1024) & 2047; + else goalang = (getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y) + 1024) & 2047; + angdif = ksgn(getincangle(g_sp->ang, goalang)) << 5; + if (angdif > -32 && angdif < 0) + { + angdif = 0; + g_sp->ang = goalang; + } + g_sp->ang += angdif; + } + + if ((a & jumptoplayer) == jumptoplayer) + { + if (g_sp->picnum == CHEER) + { + if (g_t[0] < 16) + g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 40); + } + else + { + if (g_t[0] < 16) + g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] >> 5); + } + } + if (a & justjump1) + { + if (g_sp->picnum == RABBIT) + { + if (g_t[0] < 8) + g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 30); + } + else if (g_sp->picnum == MAMA) + { + if (g_t[0] < 8) + g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 35); + } + } + if (a & justjump2) + { + if (g_sp->picnum == RABBIT) + { + if (g_t[0] < 8) + g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 24); + } + else if (g_sp->picnum == MAMA) + { + if (g_t[0] < 8) + g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 28); + } + } + if (a & windang) + { + if (g_t[0] < 8) + g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 24); + } + } + else if ((a & jumptoplayer) == jumptoplayer) + { + if (g_t[0] < 16) + g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] >> 5); + } + + + if (a & face_player_smart) + { + long newx, newy; + + newx = ps[g_p].posx + (ps[g_p].posxv / 768); + newy = ps[g_p].posy + (ps[g_p].posyv / 768); + goalang = getangle(newx - g_sp->x, newy - g_sp->y); + angdif = getincangle(g_sp->ang, goalang) >> 2; + if (angdif > -8 && angdif < 0) angdif = 0; + g_sp->ang += angdif; + } + + if (g_t[1] == 0 || a == 0) + { + if ((badguy(g_sp) && g_sp->extra <= 0) || (hittype[g_i].bposx != g_sp->x) || (hittype[g_i].bposy != g_sp->y)) + { + hittype[g_i].bposx = g_sp->x; + hittype[g_i].bposy = g_sp->y; + setsprite(g_i, g_sp->x, g_sp->y, g_sp->z); + } + if (badguy(g_sp) && g_sp->extra <= 0) + { + if (sector[g_sp->sectnum].ceilingstat & 1) + { + if (shadedsector[g_sp->sectnum] == 1) + { + g_sp->shade += (16 - g_sp->shade) >> 1; + } + else + { + g_sp->shade += (sector[g_sp->sectnum].ceilingshade - g_sp->shade) >> 1; + } + } + else + { + g_sp->shade += (sector[g_sp->sectnum].floorshade - g_sp->shade) >> 1; + } + } + return; + } + + moveptr = apScript + g_t[1]; + + if (a & geth) g_sp->xvel += (*moveptr - g_sp->xvel) >> 1; + if (a & getv) g_sp->zvel += ((*(moveptr + 1) << 4) - g_sp->zvel) >> 1; + + if (a & dodgebullet) + dodge(g_sp); + + if (g_sp->picnum != APLAYER) + alterang(a, g_i, g_p); + + if (g_sp->xvel > -6 && g_sp->xvel < 6) g_sp->xvel = 0; + + a = badguy(g_sp); + + if (g_sp->xvel || g_sp->zvel) + { + if (a) + { + if (g_sp->picnum == DRONE && g_sp->extra > 0) + { + if (g_sp->zvel > 0) + { + hittype[g_i].floorz = l = getflorzofslope(g_sp->sectnum, g_sp->x, g_sp->y); + if (isRRRA()) + { + if (g_sp->z > (l - (28 << 8))) + g_sp->z = l - (28 << 8); + } + else + { + if (g_sp->z > (l - (30 << 8))) + g_sp->z = l - (30 << 8); + } + } + else + { + hittype[g_i].ceilingz = l = getceilzofslope(g_sp->sectnum, g_sp->x, g_sp->y); + if ((g_sp->z - l) < (50 << 8)) + { + g_sp->z = l + (50 << 8); + g_sp->zvel = 0; + } + } + } + if (g_sp->zvel > 0 && hittype[g_i].floorz < g_sp->z) + g_sp->z = hittype[g_i].floorz; + if (g_sp->zvel < 0) + { + l = getceilzofslope(g_sp->sectnum, g_sp->x, g_sp->y); + if ((g_sp->z - l) < (66 << 8)) + { + g_sp->z = l + (66 << 8); + g_sp->zvel >>= 1; + } + } + } + else if (g_sp->picnum == APLAYER) + if ((g_sp->z - hittype[g_i].ceilingz) < (32 << 8)) + g_sp->z = hittype[g_i].ceilingz + (32 << 8); + + daxvel = g_sp->xvel; + angdif = g_sp->ang; + + if (a) + { + if (g_x < 960 && g_sp->xrepeat > 16) + { + + daxvel = -(1024 - g_x); + angdif = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); + + if (g_x < 512) + { + ps[g_p].posxv = 0; + ps[g_p].posyv = 0; + } + else + { + ps[g_p].posxv = mulscale(ps[g_p].posxv, dukefriction - 0x2000, 16); + ps[g_p].posyv = mulscale(ps[g_p].posyv, dukefriction - 0x2000, 16); + } + } + else if ((isRRRA() && g_sp->picnum != DRONE && g_sp->picnum != SHARK && g_sp->picnum != UFO1_RRRA) || + (!isRRRA() && g_sp->picnum != DRONE && g_sp->picnum != SHARK && g_sp->picnum != UFO1_RR + && g_sp->picnum != UFO2 && g_sp->picnum != UFO3 && g_sp->picnum != UFO4 && g_sp->picnum != UFO5)) + { + if (hittype[g_i].bposz != g_sp->z || (ud.multimode < 2 && ud.player_skill < 2)) + { + if ((g_t[0] & 1) || ps[g_p].actorsqu == g_i) return; + else daxvel <<= 1; + } + else + { + if ((g_t[0] & 3) || ps[g_p].actorsqu == g_i) return; + else daxvel <<= 2; + } + } + } + if (isRRRA()) + { + if (sector[g_sp->sectnum].lotag != 1) + { + switch (g_sp->picnum) + { + case MINIONBOAT: + case HULKBOAT: + case CHEERBOAT: + daxvel >>= 1; + break; + } + } + else if (sector[g_sp->sectnum].lotag == 1) + { + switch (g_sp->picnum) + { + case BIKERB: + case BIKERBV2: + case CHEERB: + daxvel >>= 1; + break; + } + } + } + + hittype[g_i].movflag = movesprite(g_i, + (daxvel * (sintable[(angdif + 512) & 2047])) >> 14, + (daxvel * (sintable[angdif & 2047])) >> 14, g_sp->zvel, CLIPMASK0); + } + + if (a) + { + if (sector[g_sp->sectnum].ceilingstat & 1) + { + if (shadedsector[g_sp->sectnum] == 1) + { + g_sp->shade += (16 - g_sp->shade) >> 1; + } + else + { + g_sp->shade += (sector[g_sp->sectnum].ceilingshade - g_sp->shade) >> 1; + } + } + else g_sp->shade += (sector[g_sp->sectnum].floorshade - g_sp->shade) >> 1; + + if (sector[g_sp->sectnum].floorpicnum == MIRROR) + deletesprite(g_i); + } +} + END_DUKE_NS diff --git a/source/games/duke/src/condef.h b/source/games/duke/src/condef.h index 074d542c4..56edfe81a 100644 --- a/source/games/duke/src/condef.h +++ b/source/games/duke/src/condef.h @@ -18,7 +18,7 @@ cmd(fall) // 16 cmd(state) // 17 cmd(ends) // 18 cmd(define) // 19 -cmdx(comment, "//") // 20 +//cmdx(comment, "//") // 20 cmd(ifai) // 21 cmd(killit) // 22 cmd(addweapon) // 23 @@ -37,7 +37,7 @@ cmd(ifactioncount) // 35 cmd(resetactioncount) // 36 cmd(debris) // 37 cmd(pstomp) // 38 -cmdx(blockcomment, "/*") // 39 +//cmdx(blockcomment, "/*") // 39 cmd(cstat) // 40 cmd(ifmove) // 41 cmd(resetplayer) // 42 diff --git a/source/games/duke/src/gamedef.cpp b/source/games/duke/src/gamedef.cpp index 7cc317707..c45ba1ef1 100644 --- a/source/games/duke/src/gamedef.cpp +++ b/source/games/duke/src/gamedef.cpp @@ -844,18 +844,20 @@ int parsecommand() } parsebuffer.Push(0); - auto fn = fileSystem.FindFile(parsebuffer.Data()); - if (fn < 0) + auto fni = fileSystem.FindFile(parsebuffer.Data()); + if (fni < 0) { errorcount++; + Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Could not find '%s'.\n", fn, line_number, parsebuffer.Data()); + ReportError(ERROR_COULDNOTFIND); return 0; } - auto data = fileSystem.GetFileData(fn, 1); + auto data = fileSystem.GetFileData(fni, 1); temp_current_file = g_currentSourceFile; - g_currentSourceFile = fn; + g_currentSourceFile = fni; temp_line_number = line_number; line_number = 1; @@ -872,6 +874,7 @@ int parsecommand() line_number = temp_line_number; checking_ifelse = temp_ifelse_check; g_currentSourceFile = temp_current_file; + if (*textptr == '"') textptr++; // needed for RR. return 0; } diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp new file mode 100644 index 000000000..71d501c29 --- /dev/null +++ b/source/games/duke/src/gameexec.cpp @@ -0,0 +1,1613 @@ +//------------------------------------------------------------------------- +/* +Copyright (C) 1996, 2003 - 3D Realms Entertainment +Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements) +Copyright (C) 2020 - Christoph Oelckers + +This file is part of Enhanced Duke Nukem 3D version 1.5 - Atomic Edition + +Duke Nukem 3D is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +Original Source: 1996 - Todd Replogle +Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms + +EDuke enhancements integrated: 04/13/2003 - Matt Saettler + +Note: EDuke source was in transition. Changes are in-progress in the +source as it is released. + +*/ +//------------------------------------------------------------------------- +#include "ns.h" +#include "duke3d_ed.h" +#include "gamedef.h" +#include "gamevar.h" +#include "gameexec.h" + +BEGIN_DUKE_NS + +#if 0 +char parse(void); + +void parseifelse(int condition) +{ + if( condition ) + { + // skip 'else' pointer.. and... + insptr+=2; + parse(); + } + else + { + insptr = (int *) *(insptr+1); + if(*insptr == 10) + { + // else... + + // skip 'else' and... + insptr+=2; + + parse(); + } + } +} + +// int *it = 0x00589a04; + +char parse(void) +{ + int j, l, s; + + if(killit_flag) return 1; + + switch(*insptr) + { + case 3: + insptr++; + parseifelse( rnd(*insptr)); + break; + case 45: + + if(g_x > 1024) + { + short temphit, sclip, angdif; + + if( badguy(g_sp) && g_sp->xrepeat > 56 ) + { + sclip = 3084; + angdif = 48; + } + else + { + sclip = 768; + angdif = 16; + } + + j = hitasprite(g_i,&temphit); + if(j == (1<<30)) + { + parseifelse(1); + break; + } + if(j > sclip) + { + if(temphit >= 0 && sprite[temphit].picnum == g_sp->picnum) + j = 0; + else + { + g_sp->ang += angdif;j = hitasprite(g_i,&temphit);g_sp->ang -= angdif; + if(j > sclip) + { + if(temphit >= 0 && sprite[temphit].picnum == g_sp->picnum) + j = 0; + else + { + g_sp->ang -= angdif;j = hitasprite(g_i,&temphit);g_sp->ang += angdif; + if( j > 768 ) + { + if(temphit >= 0 && sprite[temphit].picnum == g_sp->picnum) + j = 0; + else j = 1; + } + else j = 0; + } + } + else j = 0; + } + } + else j = 0; + } + else j = 1; + + parseifelse(j); + break; + case 91: + j = cansee(g_sp->x,g_sp->y,g_sp->z-((TRAND&41)<<8),g_sp->sectnum,ps[g_p].posx,ps[g_p].posy,ps[g_p].posz/*-((TRAND&41)<<8)*/,sprite[ps[g_p].i].sectnum); + parseifelse(j); + if( j ) hittype[g_i].timetosleep = SLEEPTIME; + break; + + case 49: + parseifelse(hittype[g_i].actorstayput == -1); + break; + case 5: + { + spritetype *s; + short sect; + + // select sprite for monster to target + // if holoduke is on, let them target holoduke first. + // + if(ps[g_p].holoduke_on >= 0) + { + s = &sprite[ps[g_p].holoduke_on]; + j = cansee(g_sp->x,g_sp->y,g_sp->z-(TRAND&((32<<8)-1)),g_sp->sectnum, + s->x,s->y,s->z,s->sectnum); + + if(j == 0) + { + // they can't see player's holoduke + // check for player... + s = &sprite[ps[g_p].i]; + } + } + else s = &sprite[ps[g_p].i]; // holoduke not on. look for player + + // can they see player, (or player's holoduke) + j = cansee(g_sp->x,g_sp->y,g_sp->z-(TRAND&((47<<8))),g_sp->sectnum, + s->x,s->y,s->z-(24<<8),s->sectnum); + + if(j == 0) + { + // they can't see it. + + // Huh?. This does nothing.... + // (the result is always j==0....) + if( ( abs(hittype[g_i].lastvx-g_sp->x)+abs(hittype[g_i].lastvy-g_sp->y) ) < + ( abs(hittype[g_i].lastvx-s->x)+abs(hittype[g_i].lastvy-s->y) ) ) + j = 0; + + // um yeah, this if() will always fire.... + if( j == 0 ) + { + // search around for target player + + // also modifies 'target' x&y if found.. + + j = furthestcanseepoint(g_i,s,&hittype[g_i].lastvx,&hittype[g_i].lastvy); + + if(j == -1) j = 0; + else j = 1; + } + } + else + { + // else, they did see it. + // save where we were looking... + hittype[g_i].lastvx = s->x; + hittype[g_i].lastvy = s->y; + } + + if( j == 1 && ( g_sp->statnum == 1 || g_sp->statnum == 6 ) ) + hittype[g_i].timetosleep = SLEEPTIME; + + parseifelse(j == 1); + break; + } + + case 6: + parseifelse(ifhitbyweapon(g_i) >= 0); + break; + case 27: + parseifelse( ifsquished(g_i, g_p) == 1); + break; + case 26: + { + j = g_sp->extra; + if(g_sp->picnum == APLAYER) + j--; + parseifelse(j < 0); + } + break; + case 24: + insptr++; + g_t[5] = *insptr; + g_t[4] = *(int *)(g_t[5]); // Action + g_t[1] = *(int *)(g_t[5]+4); // move + g_sp->hitag = *(int *)(g_t[5]+8); // Ai + g_t[0] = g_t[2] = g_t[3] = 0; + if(g_sp->hitag&random_angle) + g_sp->ang = TRAND&2047; + insptr++; + break; + case 7: + insptr++; + g_t[2] = 0; + g_t[3] = 0; + g_t[4] = *insptr; + insptr++; + break; + + case 8: + insptr++; + parseifelse(g_x < *insptr); + if(g_x > MAXSLEEPDIST && hittype[g_i].timetosleep == 0) + hittype[g_i].timetosleep = SLEEPTIME; + break; + case 9: + insptr++; + parseifelse(g_x > *insptr); + if(g_x > MAXSLEEPDIST && hittype[g_i].timetosleep == 0) + hittype[g_i].timetosleep = SLEEPTIME; + break; + case 10: + insptr = (int *) *(insptr+1); + break; + case 100: + insptr++; + g_sp->extra += *insptr; + insptr++; + break; + case 11: + insptr++; + g_sp->extra = *insptr; + insptr++; + break; + case 94: + insptr++; + + if(ud.coop >= 1 && ud.multimode > 1) + { + if(*insptr == 0) + { + for(j=0;j < ps[g_p].weapreccnt;j++) + if( ps[g_p].weaprecs[j] == g_sp->picnum ) + break; + + parseifelse(j < ps[g_p].weapreccnt && g_sp->owner == g_i); + } + else if(ps[g_p].weapreccnt < 16) + { + ps[g_p].weaprecs[ps[g_p].weapreccnt++] = g_sp->picnum; + parseifelse(g_sp->owner == g_i); + } + } + else parseifelse(0); + break; + case 95: + insptr++; + if(g_sp->picnum == APLAYER) + g_sp->pal = ps[g_sp->yvel].palookup; + else g_sp->pal = hittype[g_i].tempang; + hittype[g_i].tempang = 0; + break; + case 104: + insptr++; + checkweapons(&ps[g_sp->yvel]); + break; + case 106: + insptr++; + break; + case 97: + insptr++; + if(Sound[g_sp->yvel].num == 0) + spritesound(g_sp->yvel,g_i); + break; + case 96: + insptr++; + + if( ud.multimode > 1 && g_sp->picnum == APLAYER ) + { + if(ps[otherp].quick_kick == 0) + ps[otherp].quick_kick = 14; + } + else if(g_sp->picnum != APLAYER && ps[g_p].quick_kick == 0) + ps[g_p].quick_kick = 14; + break; + case 28: + insptr++; + + // JBF 20030805: As I understand it, if xrepeat becomes 0 it basically kills the + // sprite, which is why the "sizeto 0 41" calls in 1.3d became "sizeto 4 41" in + // 1.4, so instead of patching the CONs I'll surruptitiously patch the code here + //if (!PLUTOPAK && *insptr == 0) *insptr = 4; + + j = ((*insptr)-g_sp->xrepeat)<<1; + g_sp->xrepeat += ksgn(j); + + insptr++; + + if( ( g_sp->picnum == APLAYER && g_sp->yrepeat < 36 ) || *insptr < g_sp->yrepeat || ((g_sp->yrepeat*(tilesizy[g_sp->picnum]+8))<<2) < (hittype[g_i].floorz - hittype[g_i].ceilingz) ) + { + j = ((*insptr)-g_sp->yrepeat)<<1; + if( abs(j) ) g_sp->yrepeat += ksgn(j); + } + + insptr++; + + break; + case 99: + insptr++; + g_sp->xrepeat = (char) *insptr; + insptr++; + g_sp->yrepeat = (char) *insptr; + insptr++; + break; + case 13: + insptr++; + shoot(g_i,(short)*insptr); + insptr++; + break; + case 87: + insptr++; + if( Sound[*insptr].num == 0 ) + spritesound((short) *insptr,g_i); + insptr++; + break; + case CON_IFSOUND: + insptr++; + parseifelse( Sound[*insptr].num == 0 ); + break; + case 89: + insptr++; + if( Sound[*insptr].num > 0 ) + stopsound((short)*insptr); + insptr++; + break; + case 92: + insptr++; + if(g_p == screenpeek || ud.coop==1) + spritesound((short) *insptr,ps[screenpeek].i); + insptr++; + break; + case 15: + insptr++; + spritesound((short) *insptr,g_i); + insptr++; + break; + case 84: + insptr++; + ps[g_p].tipincs = 26; + break; + case 16: + insptr++; + g_sp->xoffset = 0; + g_sp->yoffset = 0; +// if(!gotz) + { + int c; + + if( floorspace(g_sp->sectnum) ) + c = 0; + else + { + if( ceilingspace(g_sp->sectnum) || sector[g_sp->sectnum].lotag == 2) + c = gc/6; + else c = gc; + } + + if( hittype[g_i].cgg <= 0 || (sector[g_sp->sectnum].floorstat&2) ) + { + getglobalz(g_i); + hittype[g_i].cgg = 6; + } + else hittype[g_i].cgg --; + + if( g_sp->z < (hittype[g_i].floorz-FOURSLEIGHT) ) + { + g_sp->zvel += c; + g_sp->z+=g_sp->zvel; + + if(g_sp->zvel > 6144) g_sp->zvel = 6144; + } + else + { + g_sp->z = hittype[g_i].floorz - FOURSLEIGHT; + + if( badguy(g_sp) || ( g_sp->picnum == APLAYER && g_sp->owner >= 0) ) + { + + if( g_sp->zvel > 3084 && g_sp->extra <= 1) + { + if(g_sp->pal != 1 && g_sp->picnum != DRONE) + { + if(g_sp->picnum == APLAYER && g_sp->extra > 0) + goto SKIPJIBS; + guts(g_sp,JIBS6,15,g_p); + spritesound(SQUISHED,g_i); + spawn(g_i,BLOODPOOL); + } + + SKIPJIBS: + + hittype[g_i].picnum = SHOTSPARK1; + hittype[g_i].extra = 1; + g_sp->zvel = 0; + } + else if(g_sp->zvel > 2048 && sector[g_sp->sectnum].lotag != 1) + { + + j = g_sp->sectnum; + pushmove(&g_sp->x,&g_sp->y,&g_sp->z,&j,128L,(4L<<8),(4L<<8),CLIPMASK0); + if(j != g_sp->sectnum && j >= 0 && j < MAXSECTORS) + changespritesect(g_i,j); + + spritesound(THUD,g_i); + } + } + if(sector[g_sp->sectnum].lotag == 1) + switch (g_sp->picnum) + { + case OCTABRAIN: + case COMMANDER: + case DRONE: + break; + default: + g_sp->z += (24<<8); + break; + } + else g_sp->zvel = 0; + } + } + + break; + case 4: + case 12: + case 18: + return 1; + case 30: + insptr++; + return 1; + case 2: + insptr++; + if( ps[g_p].ammo_amount[*insptr] >= max_ammo_amount[*insptr] ) + { + killit_flag = 2; + break; + } + addammo( *insptr, &ps[g_p], *(insptr+1) ); + if(ps[g_p].curr_weapon == KNEE_WEAPON) + if( ps[g_p].gotweapon[*insptr] ) + addweapon( &ps[g_p], *insptr ); + insptr += 2; + break; + case 86: + insptr++; + lotsofmoney(g_sp,*insptr); + insptr++; + break; + case 102: + insptr++; + lotsofmail(g_sp,*insptr); + insptr++; + break; + case 105: + insptr++; + hittype[g_i].timetosleep = (short)*insptr; + insptr++; + break; + case 103: + insptr++; + lotsofpaper(g_sp,*insptr); + insptr++; + break; + case 88: + insptr++; + ps[g_p].actors_killed += *insptr; + hittype[g_i].actorstayput = -1; + insptr++; + break; + case 93: + insptr++; + spriteglass(g_i,*insptr); + insptr++; + break; + case 22: + insptr++; + killit_flag = 1; + break; + case 23: // addweapon + insptr++; + if( ps[g_p].gotweapon[*insptr] == 0 ) addweapon( &ps[g_p], *insptr ); + else if( ps[g_p].ammo_amount[*insptr] >= max_ammo_amount[*insptr] ) + { + killit_flag = 2; + break; + } + addammo( *insptr, &ps[g_p], *(insptr+1) ); + if(ps[g_p].curr_weapon == KNEE_WEAPON) + if( ps[g_p].gotweapon[*insptr] ) + addweapon( &ps[g_p], *insptr ); + insptr+=2; + break; + case 68: + insptr++; + printf("%ld\n",*insptr); + insptr++; + break; + case 69: + insptr++; + ps[g_p].timebeforeexit = *insptr; + ps[g_p].customexitsound = -1; + ud.eog = 1; + insptr++; + break; + case 25: + insptr++; + + if(ps[g_p].newowner >= 0) + { + ps[g_p].newowner = -1; + ps[g_p].posx = ps[g_p].oposx; + ps[g_p].posy = ps[g_p].oposy; + ps[g_p].posz = ps[g_p].oposz; + ps[g_p].ang = ps[g_p].oang; + updatesector(ps[g_p].posx,ps[g_p].posy,&ps[g_p].cursectnum); + setpal(&ps[g_p]); + + j = headspritestat[1]; + while(j >= 0) + { + if(sprite[j].picnum==CAMERA1) + sprite[j].yvel = 0; + j = nextspritestat[j]; + } + } + + j = sprite[ps[g_p].i].extra; + + if(g_sp->picnum != ATOMICHEALTH) + { + if( j > max_player_health && *insptr > 0 ) + { + insptr++; + break; + } + else + { + if(j > 0) + j += *insptr; + if ( j > max_player_health && *insptr > 0 ) + j = max_player_health; + } + } + else + { + if( j > 0 ) + j += *insptr; + if ( j > (max_player_health<<1) ) + j = (max_player_health<<1); + } + + if(j < 0) j = 0; + + if(ud.god == 0) + { + if(*insptr > 0) + { + if( ( j - *insptr ) < (max_player_health>>2) && + j >= (max_player_health>>2) ) + spritesound(DUKE_GOTHEALTHATLOW,ps[g_p].i); + + ps[g_p].last_extra = j; + } + + sprite[ps[g_p].i].extra = j; + } + + insptr++; + break; + case 17: + { + int *tempscrptr; + + tempscrptr = insptr+2; + + insptr = (int *) *(insptr+1); + while(1) if(parse()) break; + insptr = tempscrptr; + } + break; + case 29: + insptr++; + while(1) if(parse()) break; + break; + case 32: + g_t[0]=0; + insptr++; + g_t[1] = *insptr; + insptr++; + g_sp->hitag = *insptr; + insptr++; + if(g_sp->hitag&random_angle) + g_sp->ang = TRAND&2047; + break; + case 31: + insptr++; + if(g_sp->sectnum >= 0 && g_sp->sectnum < MAXSECTORS) + spawn(g_i,*insptr); + insptr++; + break; + case 33: + insptr++; + parseifelse( hittype[g_i].picnum == *insptr); + break; + case 21: + insptr++; + parseifelse(g_t[5] == *insptr); + break; + case 34: + insptr++; + parseifelse(g_t[4] == *insptr); + break; + case 35: + insptr++; + parseifelse(g_t[2] >= *insptr); + break; + case 36: + insptr++; + g_t[2] = 0; + break; + case 37: + { + short dnum; + + insptr++; + dnum = *insptr; + insptr++; + + if(g_sp->sectnum >= 0 && g_sp->sectnum < MAXSECTORS) + for(j=(*insptr)-1;j>=0;j--) + { + if(g_sp->picnum == BLIMP && dnum == SCRAP1) + s = 0; + else s = (TRAND%3); + + l = EGS(g_sp->sectnum, + g_sp->x+(TRAND&255)-128,g_sp->y+(TRAND&255)-128,g_sp->z-(8<<8)-(TRAND&8191), + dnum+s,g_sp->shade,32+(TRAND&15),32+(TRAND&15), + TRAND&2047,(TRAND&127)+32, + -(TRAND&2047),g_i,5); + if(g_sp->picnum == BLIMP && dnum == SCRAP1) + sprite[l].yvel = weaponsandammosprites[j%14]; + else sprite[l].yvel = -1; + sprite[l].pal = g_sp->pal; + } + insptr++; + } + break; + case 52: + insptr++; + g_t[0] = (short) *insptr; + insptr++; + break; + case 101: + insptr++; + g_sp->cstat |= (short)*insptr; + insptr++; + break; + case 110: + insptr++; + g_sp->clipdist = (short) *insptr; + insptr++; + break; + case 40: + insptr++; + g_sp->cstat = (short) *insptr; + insptr++; + break; + case 41: + insptr++; + parseifelse(g_t[1] == *insptr); + break; + case 42: + insptr++; + +//AddLog("resetplayer"); + if(ud.multimode < 2) + { + if( lastsavedpos >= 0 && ud.recstat != 2 ) + { + ps[g_p].gm = MODE_MENU; + KB_ClearKeyDown(sc_Space); + cmenu(15000); + } + else ps[g_p].gm = MODE_RESTART; + killit_flag = 2; + } + else + { + pickrandomspot(g_p); + g_sp->x = hittype[g_i].bposx = ps[g_p].bobposx = ps[g_p].oposx = ps[g_p].posx; + g_sp->y = hittype[g_i].bposy = ps[g_p].bobposy = ps[g_p].oposy =ps[g_p].posy; + g_sp->z = hittype[g_i].bposy = ps[g_p].oposz =ps[g_p].posz; + updatesector(ps[g_p].posx,ps[g_p].posy,&ps[g_p].cursectnum); + setsprite(ps[g_p].i,ps[g_p].posx,ps[g_p].posy,ps[g_p].posz+PHEIGHT); + g_sp->cstat = 257; + + g_sp->shade = -12; + g_sp->clipdist = 64; + g_sp->xrepeat = 42; + g_sp->yrepeat = 36; + g_sp->owner = g_i; + g_sp->xoffset = 0; + g_sp->pal = ps[g_p].palookup; + + ps[g_p].last_extra = g_sp->extra = max_player_health; + ps[g_p].wantweaponfire = -1; + ps[g_p].horiz = 100; + ps[g_p].on_crane = -1; + ps[g_p].frag_ps = g_p; + ps[g_p].horizoff = 0; + ps[g_p].opyoff = 0; + ps[g_p].wackedbyactor = -1; + ps[g_p].shield_amount = max_armour_amount; + ps[g_p].dead_flag = 0; + ps[g_p].pals_time = 0; + ps[g_p].footprintcount = 0; + ps[g_p].weapreccnt = 0; + ps[g_p].fta = 0; + ps[g_p].ftq = 0; + ps[g_p].posxv = ps[g_p].posyv = 0; + ps[g_p].rotscrnang = 0; + + ps[g_p].falling_counter = 0; + + hittype[g_i].extra = -1; + hittype[g_i].owner = g_i; + + hittype[g_i].cgg = 0; + hittype[g_i].movflag = 0; + hittype[g_i].tempang = 0; + hittype[g_i].actorstayput = -1; + hittype[g_i].dispicnum = 0; + hittype[g_i].owner = ps[g_p].i; + + resetinventory(g_p); + resetweapons(g_p); + + cameradist = 0; + cameraclock = totalclock; + } + setpal(&ps[g_p]); +//AddLog("EOF: resetplayer"); + + break; + case 43: + parseifelse( abs(g_sp->z-sector[g_sp->sectnum].floorz) < (32<<8) && sector[g_sp->sectnum].lotag == 1); + break; + case 44: + parseifelse( sector[g_sp->sectnum].lotag == 2); + break; + case 46: + insptr++; + parseifelse(g_t[0] >= *insptr); + break; + case 53: + insptr++; + parseifelse(g_sp->picnum == *insptr); + break; + case 47: + insptr++; + g_t[0] = 0; + break; + case 48: + insptr+=2; + switch(*(insptr-1)) + { + case 0: + ps[g_p].steroids_amount = *insptr; + ps[g_p].inven_icon = 2; + break; + case 1: + ps[g_p].shield_amount += *insptr;// 100; + if(ps[g_p].shield_amount > max_player_health) + ps[g_p].shield_amount = max_player_health; + break; + case 2: + ps[g_p].scuba_amount = *insptr;// 1600; + ps[g_p].inven_icon = 6; + break; + case 3: + ps[g_p].holoduke_amount = *insptr;// 1600; + ps[g_p].inven_icon = 3; + break; + case 4: + ps[g_p].jetpack_amount = *insptr;// 1600; + ps[g_p].inven_icon = 4; + break; + case 6: + switch(g_sp->pal) + { + case 0: ps[g_p].got_access |= 1;break; + case 21: ps[g_p].got_access |= 2;break; + case 23: ps[g_p].got_access |= 4;break; + } + break; + case 7: + ps[g_p].heat_amount = *insptr; + ps[g_p].inven_icon = 5; + break; + case 9: + ps[g_p].inven_icon = 1; + ps[g_p].firstaid_amount = *insptr; + break; + case 10: + ps[g_p].inven_icon = 7; + ps[g_p].boot_amount = *insptr; + break; + } + insptr++; + break; + case 50: + hitradius(g_i,*(insptr+1),*(insptr+2),*(insptr+3),*(insptr+4),*(insptr+5)); + insptr+=6; + break; + case 51: + { + insptr++; + + l = *insptr; + j = 0; + + s = g_sp->xvel; + + if( (l&8) && ps[g_p].on_ground && (sync[g_p].bits&2) ) + j = 1; + else if( (l&16) && ps[g_p].jumping_counter == 0 && !ps[g_p].on_ground && + ps[g_p].poszv > 2048 ) + j = 1; + else if( (l&32) && ps[g_p].jumping_counter > 348 ) + j = 1; + else if( (l&1) && s >= 0 && s < 8) + j = 1; + else if( (l&2) && s >= 8 && !(sync[g_p].bits&(1<<5)) ) + j = 1; + else if( (l&4) && s >= 8 && sync[g_p].bits&(1<<5) ) + j = 1; + else if( (l&64) && ps[g_p].posz < (g_sp->z-(48<<8)) ) + j = 1; + else if( (l&128) && s <= -8 && !(sync[g_p].bits&(1<<5)) ) + j = 1; + else if( (l&256) && s <= -8 && (sync[g_p].bits&(1<<5)) ) + j = 1; + else if( (l&512) && ( ps[g_p].quick_kick > 0 || ( ps[g_p].curr_weapon == KNEE_WEAPON && ps[g_p].kickback_pic > 0 ) ) ) + j = 1; + else if( (l&1024) && sprite[ps[g_p].i].xrepeat < 32 ) + j = 1; + else if( (l&2048) && ps[g_p].jetpack_on ) + j = 1; + else if( (l&4096) && ps[g_p].steroids_amount > 0 && ps[g_p].steroids_amount < 400 ) + j = 1; + else if( (l&8192) && ps[g_p].on_ground) + j = 1; + else if( (l&16384) && sprite[ps[g_p].i].xrepeat > 32 && sprite[ps[g_p].i].extra > 0 && ps[g_p].timebeforeexit == 0 ) + j = 1; + else if( (l&32768) && sprite[ps[g_p].i].extra <= 0) + j = 1; + else if( (l&65536L) ) + { + if(g_sp->picnum == APLAYER && ud.multimode > 1) + j = getincangle(ps[otherp].ang,getangle(ps[g_p].posx-ps[otherp].posx,ps[g_p].posy-ps[otherp].posy)); + else + j = getincangle(ps[g_p].ang,getangle(g_sp->x-ps[g_p].posx,g_sp->y-ps[g_p].posy)); + + if( j > -128 && j < 128 ) + j = 1; + else + j = 0; + } + + parseifelse((int) j); + + } + break; + case 56: + insptr++; + parseifelse(g_sp->extra <= *insptr); + break; + case 58: + insptr += 2; + guts(g_sp,*(insptr-1),*insptr,g_p); + insptr++; + break; + case 59: + insptr++; +// if(g_sp->owner >= 0 && sprite[g_sp->owner].picnum == *insptr) + // parseifelse(1); +// else + parseifelse( hittype[g_i].picnum == *insptr); + break; + case 61: + insptr++; + forceplayerangle(&ps[g_p]); + return 0; + case 62: + insptr++; + parseifelse( (( hittype[g_i].floorz - hittype[g_i].ceilingz ) >> 8 ) < *insptr); + break; + case 63: + parseifelse( sync[g_p].bits&(1<<29)); + break; + case 64: + parseifelse(sector[g_sp->sectnum].ceilingstat&1); + break; + case 65: + parseifelse(ud.multimode > 1); + break; + case 66: + insptr++; + if( sector[g_sp->sectnum].lotag == 0 ) + { + neartag(g_sp->x,g_sp->y,g_sp->z-(32<<8),g_sp->sectnum,g_sp->ang,&neartagsector,&neartagwall,&neartagsprite,&neartaghitdist,768L,1); + if( neartagsector >= 0 && isanearoperator(sector[neartagsector].lotag) ) + if( (sector[neartagsector].lotag&0xff) == 23 || sector[neartagsector].floorz == sector[neartagsector].ceilingz ) + if( (sector[neartagsector].lotag&16384) == 0 ) + if( (sector[neartagsector].lotag&32768) == 0 ) + { + j = headspritesect[neartagsector]; + while(j >= 0) + { + if(sprite[j].picnum == ACTIVATOR) + break; + j = nextspritesect[j]; + } + if(j == -1) + operatesectors(neartagsector,g_i); + } + } + break; + case 67: + parseifelse(ceilingspace(g_sp->sectnum)); + break; + + case 74: + insptr++; + if(g_sp->picnum != APLAYER) + hittype[g_i].tempang = g_sp->pal; + g_sp->pal = *insptr; + insptr++; + break; + + case 77: + insptr++; + g_sp->picnum = *insptr; + insptr++; + break; + + case 70: + parseifelse( dodge(g_sp) == 1); + break; + case 71: + if( badguy(g_sp) ) + parseifelse( ud.respawn_monsters ); + else if( inventory(g_sp) ) + parseifelse( ud.respawn_inventory ); + else + parseifelse( ud.respawn_items ); + break; + case 72: + insptr++; +// getglobalz(g_i); + parseifelse( (hittype[g_i].floorz - g_sp->z) <= ((*insptr)<<8)); + break; + case 73: + insptr++; +// getglobalz(g_i); + parseifelse( ( g_sp->z - hittype[g_i].ceilingz ) <= ((*insptr)<<8)); + break; + case 14: + + insptr++; + ps[g_p].pals_time = *insptr; + insptr++; + for(j=0;j<3;j++) + { + ps[g_p].pals[j] = *insptr; + insptr++; + } + break; + +/* case 74: + insptr++; + getglobalz(g_i); + parseifelse( (( hittype[g_i].floorz - hittype[g_i].ceilingz ) >> 8 ) >= *insptr); + break; +*/ +#ifdef WW2 + case CON_ADDLOG: + { int l; + int lFile; + insptr++; + lFile=*(insptr++); // file + l=*(insptr++); // line + sprintf(g_szBuf,"ADDLOG: %s L=%ld",g_achSourceFiles[lFile],l); + AddLog(g_szBuf); + break; + } + case CON_ADDLOGVAR: + { int l; + char szBuf[256]; + int lFile; + insptr++; + lFile=*(insptr++); // file + l=*(insptr++); // l=Line number, *instpr=varID + if( (*insptr >= iGameVarCount) + || *insptr < 0 + ) + { + // invalid varID + insptr++; + sprintf(g_szBuf,"ADDLOGVAR: %s L=%ld INVALID VARIABLE",g_achSourceFiles[lFile],l); + AddLog(g_szBuf); + sprintf(g_szBuf,"Offset=%0lX\n",scriptptr-script); + AddLog(g_szBuf); + break; // out of switch + } + sprintf(szBuf,"ADDLOGVAR: %s L=%ld %s ",g_achSourceFiles[lFile],l, aGameVars[*insptr].szLabel); + strcpy(g_szBuf,szBuf); + + if( aGameVars[*insptr].dwFlags & GAMEVAR_FLAG_READONLY) + { + sprintf(szBuf," (read-only)"); + strcat(g_szBuf,szBuf); + } + if( aGameVars[*insptr].dwFlags & GAMEVAR_FLAG_PERPLAYER) + { + sprintf(szBuf," (Per Player. Player=%d)",g_p); + } + else if( aGameVars[*insptr].dwFlags & GAMEVAR_FLAG_PERACTOR) + { + sprintf(szBuf," (Per Actor. Actor=%d)",g_i); + } + else + { + sprintf(szBuf," (Global)"); + } + strcat(g_szBuf,szBuf); + sprintf(szBuf," =%ld", GetGameVarID(*insptr, g_i, g_p)); + strcat(g_szBuf,szBuf); + AddLog(g_szBuf); + insptr++; + break; + } + case CON_SETVAR: + { int i; + insptr++; + i=*(insptr++); // ID of def + SetGameVarID(i, *insptr, g_i, g_p ); + insptr++; + break; + } + case CON_SETVARVAR: + { int i; + insptr++; + i=*(insptr++); // ID of def + SetGameVarID(i, GetGameVarID(*insptr, g_i, g_p), g_i, g_p ); +// aGameVars[i].lValue = aGameVars[*insptr].lValue; + insptr++; + break; + } + case CON_ADDVAR: + { int i; + insptr++; + i=*(insptr++); // ID of def +//sprintf(g_szBuf,"AddVar %d to Var ID=%d, g_i=%d, g_p=%d\n",*insptr, i, g_i, g_p); +//AddLog(g_szBuf); + SetGameVarID(i, GetGameVarID(i, g_i, g_p) + *insptr, g_i, g_p ); + insptr++; + break; + } + case CON_SIN: + { int i; + int lValue; + insptr++; + i=*(insptr++); // ID of def + lValue=GetGameVarID(*insptr, g_i, g_p); + lValue=sintable[lValue&2047]; + SetGameVarID(i, lValue , g_i, g_p ); + insptr++; + break; + } + + case CON_ADDVARVAR: + { int i; + insptr++; + i=*(insptr++); // ID of def + SetGameVarID(i, GetGameVarID(i, g_i, g_p) + GetGameVarID(*insptr, g_i, g_p), g_i, g_p ); + insptr++; + break; + } + case CON_SPGETLOTAG: + { + insptr++; + SetGameVarID(g_iLoTagID, g_sp->lotag, g_i, g_p); + break; + } + case CON_SPGETHITAG: + { + insptr++; + SetGameVarID(g_iHiTagID, g_sp->hitag, g_i, g_p); + break; + } + case CON_SECTGETLOTAG: + { + insptr++; + SetGameVarID(g_iLoTagID, sector[g_sp->sectnum].lotag, g_i, g_p); + break; + } + case CON_SECTGETHITAG: + { + insptr++; + SetGameVarID(g_iHiTagID, sector[g_sp->sectnum].hitag, g_i, g_p); + break; + } + case CON_GETTEXTUREFLOOR: + { + insptr++; + SetGameVarID(g_iTextureID, sector[g_sp->sectnum].floorpicnum, g_i, g_p); + break; + } + + case CON_IFVARVARAND: + { + int i; + insptr++; + i=*(insptr++); // ID of def + j=0; + if(GetGameVarID(i, g_i, g_p) & GetGameVarID(*(insptr), g_i, g_p) ) + { + j=1; + } + parseifelse( j ); + break; + } + case CON_IFVARVARN: + { + int i; + insptr++; + i=*(insptr++); // ID of def + j=0; + if(GetGameVarID(i, g_i, g_p) != GetGameVarID(*(insptr), g_i, g_p) ) + { + j=1; + } + parseifelse( j ); + break; + } + case CON_IFVARVARE: + { + int i; + insptr++; + i=*(insptr++); // ID of def + j=0; + if(GetGameVarID(i, g_i, g_p) == GetGameVarID(*(insptr), g_i, g_p) ) + { + j=1; + } + parseifelse( j ); + break; + } + case CON_IFVARVARG: + { + int i; + insptr++; + i=*(insptr++); // ID of def + j=0; + if(GetGameVarID(i, g_i, g_p) > GetGameVarID(*(insptr), g_i, g_p) ) + { + j=1; + } + parseifelse( j ); + break; + } + case CON_IFVARVARL: + { + int i; + insptr++; + i=*(insptr++); // ID of def + j=0; + if(GetGameVarID(i, g_i, g_p) < GetGameVarID(*(insptr), g_i, g_p) ) + { + j=1; + } + parseifelse( j ); + break; + } + case CON_IFVARE: + { + int i; + insptr++; + i=*(insptr++); // ID of def + j=0; + if(GetGameVarID(i, g_i, g_p) == *insptr) + { + j=1; + } + parseifelse( j ); + break; + } + case CON_IFVARN: + { + int i; + insptr++; + i=*(insptr++); // ID of def + j=0; + if(GetGameVarID(i, g_i, g_p) != *insptr) + { + j=1; + } + parseifelse( j ); + break; + } + case CON_IFVARAND: + { + int i; + insptr++; + i=*(insptr++); // ID of def + j=0; + if(GetGameVarID(i, g_i, g_p) & *insptr) + { + j=1; + } + parseifelse( j ); + break; + } + case CON_IFVARG: + { + int i; + insptr++; + i=*(insptr++); // ID of def + j=0; + if(GetGameVarID(i, g_i, g_p) > *insptr) + { + j=1; + } + parseifelse( j ); + break; + } + case CON_IFVARL: + { + int i; + insptr++; + i=*(insptr++); // ID of def + j=0; + if(GetGameVarID(i, g_i, g_p) < *insptr) + { + j=1; + } + parseifelse( j ); + break; + } +#endif + case 78: + insptr++; + parseifelse( sprite[ps[g_p].i].extra < *insptr); + break; + + case 75: + { + insptr++; + j = 0; + switch(*(insptr++)) + { + case 0:if( ps[g_p].steroids_amount != *insptr) + j = 1; + break; + case 1:if(ps[g_p].shield_amount != max_player_health ) + j = 1; + break; + case 2:if(ps[g_p].scuba_amount != *insptr) j = 1;break; + case 3:if(ps[g_p].holoduke_amount != *insptr) j = 1;break; + case 4:if(ps[g_p].jetpack_amount != *insptr) j = 1;break; + case 6: + switch(g_sp->pal) + { + case 0: if(ps[g_p].got_access&1) j = 1;break; + case 21: if(ps[g_p].got_access&2) j = 1;break; + case 23: if(ps[g_p].got_access&4) j = 1;break; + } + break; + case 7:if(ps[g_p].heat_amount != *insptr) j = 1;break; + case 9: + if(ps[g_p].firstaid_amount != *insptr) j = 1;break; + case 10: + if(ps[g_p].boot_amount != *insptr) j = 1;break; + } + + parseifelse(j); + break; + } + case 38: + insptr++; + if( ps[g_p].knee_incs == 0 && sprite[ps[g_p].i].xrepeat >= 40 ) + if( cansee(g_sp->x,g_sp->y,g_sp->z-(4<<8),g_sp->sectnum,ps[g_p].posx,ps[g_p].posy,ps[g_p].posz+(16<<8),sprite[ps[g_p].i].sectnum) ) + { + ps[g_p].knee_incs = 1; + if(ps[g_p].weapon_pos == 0) + ps[g_p].weapon_pos = -1; + ps[g_p].actorsqu = g_i; + } + break; + case 90: + { + short s1; + + s1 = g_sp->sectnum; + + j = 0; + + updatesector(g_sp->x+108,g_sp->y+108,&s1); + if( s1 == g_sp->sectnum ) + { + updatesector(g_sp->x-108,g_sp->y-108,&s1); + if( s1 == g_sp->sectnum ) + { + updatesector(g_sp->x+108,g_sp->y-108,&s1); + if( s1 == g_sp->sectnum ) + { + updatesector(g_sp->x-108,g_sp->y+108,&s1); + if( s1 == g_sp->sectnum ) + j = 1; + } + } + } + parseifelse( j ); + } + + break; + case 80: + insptr++; + FTA(*insptr,&ps[g_p]); + insptr++; + break; + case 81: + parseifelse( floorspace(g_sp->sectnum)); + break; + case 82: + parseifelse( (hittype[g_i].movflag&49152) > 16384 ); + break; + case 83: + insptr++; + switch(g_sp->picnum) + { + case FEM1: + case FEM2: + case FEM3: + case FEM4: + case FEM5: + case FEM6: + case FEM7: + case FEM8: + case FEM9: + case FEM10: + case PODFEM1: + case NAKED1: + case STATUE: + if(g_sp->yvel) operaterespawns(g_sp->yvel); + break; + default: + if(g_sp->hitag >= 0) operaterespawns(g_sp->hitag); + break; + } + break; + case 85: + insptr++; + parseifelse( g_sp->pal == *insptr); + break; + + case 111: + insptr++; + j = abs(getincangle(ps[g_p].ang,g_sp->ang)); + parseifelse( j <= *insptr); + break; + + case 109: + + for(j=1;jpicnum] == 0 ) return; + + insptr = 4 + (actorLoadEventScrptr[g_sp->picnum]); + + killit_flag = 0; + + if(g_sp->sectnum < 0 || g_sp->sectnum >= MAXSECTORS) + { +// if(badguy(g_sp)) +// ps[g_p].actors_killed++; + deletesprite(g_i); + return; + } + do + done = parse(); + while( done == 0 ); + + if(killit_flag == 1) + { + // if player was set to squish, first stop that... + if (g_p >= 0 ) + { + if(ps[g_p].actorsqu == g_i) + ps[g_p].actorsqu = -1; + } + deletesprite(g_i); + } + else + { + move(); + + if( g_sp->statnum == 1) + { + if( badguy(g_sp) ) + { + if( g_sp->xrepeat > 60 ) return; + if( ud.respawn_monsters == 1 && g_sp->extra <= 0 ) return; + } + else if( ud.respawn_items == 1 && (g_sp->cstat&32768) ) return; + + if(hittype[g_i].timetosleep > 1) + hittype[g_i].timetosleep--; + else if(hittype[g_i].timetosleep == 1) + changespritestat(g_i,2); + } + + else if(g_sp->statnum == 6) + { + switch(g_sp->picnum) + { + case RUBBERCAN: + case EXPLODINGBARREL: + case WOODENHORSE: + case HORSEONSIDE: + case CANWITHSOMETHING: + case FIREBARREL: + case NUKEBARREL: + case NUKEBARRELDENTED: + case NUKEBARRELLEAKED: + case TRIPBOMB: + case EGG: + if(hittype[g_i].timetosleep > 1) + hittype[g_i].timetosleep--; + else if(hittype[g_i].timetosleep == 1) + changespritestat(g_i,2); + break; + } + } + } + +} + +void execute(short i,short p,int x) +{ + char done; + + g_i = i; // Sprite ID + g_p = p; // Player ID + g_x = x; // ?? + g_sp = &sprite[g_i]; // Pointer to sprite structure + g_t = &hittype[g_i].temp_data[0]; // Sprite's 'extra' data + + if( actorscrptr[g_sp->picnum] == 0 ) return; + + insptr = 4 + (actorscrptr[g_sp->picnum]); + + killit_flag = 0; + + if(g_sp->sectnum < 0 || g_sp->sectnum >= MAXSECTORS) + { + if(badguy(g_sp)) + ps[g_p].actors_killed++; + deletesprite(g_i); + return; + } + + if(g_t[4]) + { + g_sp->lotag += TICSPERFRAME; + if(g_sp->lotag > *(int *)(g_t[4]+16) ) + { + g_t[2]++; + g_sp->lotag = 0; + g_t[3] += *(int *)( g_t[4]+12 ); + } + if( abs(g_t[3]) >= abs( *(int *)(g_t[4]+4) * *(int *)(g_t[4]+12) ) ) + g_t[3] = 0; + } + + do + done = parse(); + while( done == 0 ); + + if(killit_flag == 1) + { + // if player was set to squish, first stop that... + if(ps[g_p].actorsqu == g_i) + ps[g_p].actorsqu = -1; + deletesprite(g_i); + } + else + { + move(); + + if( g_sp->statnum == 1) + { + if( badguy(g_sp) ) + { + if( g_sp->xrepeat > 60 ) return; + if( ud.respawn_monsters == 1 && g_sp->extra <= 0 ) return; + } + else if( ud.respawn_items == 1 && (g_sp->cstat&32768) ) return; + + if(hittype[g_i].timetosleep > 1) + hittype[g_i].timetosleep--; + else if(hittype[g_i].timetosleep == 1) + changespritestat(g_i,2); + } + + else if(g_sp->statnum == 6) + switch(g_sp->picnum) + { + case RUBBERCAN: + case EXPLODINGBARREL: + case WOODENHORSE: + case HORSEONSIDE: + case CANWITHSOMETHING: + case FIREBARREL: + case NUKEBARREL: + case NUKEBARRELDENTED: + case NUKEBARRELLEAKED: + case TRIPBOMB: + case EGG: + if(hittype[g_i].timetosleep > 1) + hittype[g_i].timetosleep--; + else if(hittype[g_i].timetosleep == 1) + changespritestat(g_i,2); + break; + } + } +} + +#endif + +END_DUKE_NS diff --git a/source/games/duke/src/gameexec.h b/source/games/duke/src/gameexec.h index f64d637b7..906ef6623 100644 --- a/source/games/duke/src/gameexec.h +++ b/source/games/duke/src/gameexec.h @@ -79,22 +79,10 @@ inline void execute(int s, int p, int d) { A_Execute(s, p, d); } -void A_Fall(int spriteNum); -inline void makeitfall(int s) -{ - A_Fall(s); -} -int32_t A_GetFurthestAngle(int spriteNum, int angDiv); -void A_GetZLimits(int spriteNum); -inline void getglobalz(int s) -{ - A_GetZLimits(s); -} -int32_t __fastcall G_GetAngleDelta(int32_t currAngle, int32_t newAngle); -inline int getincangle(int c, int n) -{ - return G_GetAngleDelta(c, n); -} +void makeitfall(int s); +int furthestangle(int spriteNum, int angDiv); +void getglobalz(int s); +int getincangle(int c, int n); //void G_RestoreMapState(); //void G_SaveMapState(); diff --git a/source/games/duke/src/gamevar.cpp b/source/games/duke/src/gamevar.cpp index 35d0dbabb..d41e2b95b 100644 --- a/source/games/duke/src/gamevar.cpp +++ b/source/games/duke/src/gamevar.cpp @@ -2,6 +2,7 @@ /* Copyright (C) 1996, 2003 - 3D Realms Entertainment Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements) +Copyright (C) 2020 - Christoph Oelckers This file is part of Enhanced Duke Nukem 3D version 1.5 - Atomic Edition diff --git a/source/games/duke/src/gamevar.h b/source/games/duke/src/gamevar.h index a4ba6e18f..0b9532db1 100644 --- a/source/games/duke/src/gamevar.h +++ b/source/games/duke/src/gamevar.h @@ -158,13 +158,14 @@ extern int g_iZRangeVarID; // var ID of "ZRANGE" extern int g_iAngRangeVarID; // var ID of "ANGRANGE" extern int g_iAimAngleVarID; // var ID of "AUTOAIMANGLE" - +#if 0 // global crap for event management extern int g_i, g_p; extern int g_x; extern int* g_t; extern uint8_t killit_flag; //extern sprite_ype* g_sp; +#endif bool AddGameVar(const char *pszLabel, intptr_t lValue, unsigned dwFlags); int GetGameID(const char *szGameLabel); diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index 4b4b91ccc..4d99ef1ec 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -216,7 +216,7 @@ struct msy_ G_EXTERN msx_ msx; G_EXTERN msy_ msy; -G_EXTERN int32_t g_windTime, g_windDir; +G_EXTERN int32_t g_windTime, WindDir; G_EXTERN int16_t g_fakeBubbaCnt, g_mamaSpawnCnt, g_banjoSong, g_bellTime, g_bellSprite; #define BellTime g_bellTime #define word_119BE0 g_bellSprite diff --git a/source/games/duke/src/sector.h b/source/games/duke/src/sector.h index 66bb8b425..8040d7825 100644 --- a/source/games/duke/src/sector.h +++ b/source/games/duke/src/sector.h @@ -40,7 +40,7 @@ BEGIN_DUKE_NS #define VIEWSCREEN_ACTIVE_DISTANCE 8192 -extern uint8_t g_shadedSector[MAXSECTORS]; +extern uint8_t shadedsector[MAXSECTORS]; typedef struct { int16_t wallnum, tag; diff --git a/source/games/duke/src/zz_game.cpp b/source/games/duke/src/zz_game.cpp index 189a4f710..10e6354dd 100644 --- a/source/games/duke/src/zz_game.cpp +++ b/source/games/duke/src/zz_game.cpp @@ -1565,7 +1565,7 @@ default_case: break; } - A_Fall(newSprite); + makeitfall(newSprite); if (A_CheckSpriteFlags(newSprite, SFLAG_BADGUYSTAYPUT)) pActor->actorstayput = pSprite->sectnum; @@ -2822,7 +2822,7 @@ rrbloodpool_fallthrough: } else { - A_Fall(newSprite); + makeitfall(newSprite); if (pSprite->picnum == TILE_RAT) { @@ -3142,7 +3142,7 @@ rr_badguy: } else { - A_Fall(newSprite); + makeitfall(newSprite); if (pSprite->picnum == TILE_RAT) { @@ -3215,7 +3215,7 @@ rr_badguy: changespritestat(newSprite, STAT_ACTOR); - A_GetZLimits(newSprite); + getglobalz(newSprite); int const oozSize = (pActor->floorz-pActor->ceilingz)>>9; @@ -3389,7 +3389,7 @@ rr_badguy: else { changespritestat(newSprite, STAT_ZOMBIEACTOR); - A_Fall(newSprite); + makeitfall(newSprite); } if (RR) { @@ -4301,7 +4301,7 @@ rr_badguy: if (spriteNum >= 0) pSprite->xrepeat = pSprite->yrepeat = 32; pSprite->clipdist = 72; - A_Fall(newSprite); + makeitfall(newSprite); if (spriteNum >= 0) pSprite->owner = spriteNum; else pSprite->owner = newSprite; @@ -4588,7 +4588,7 @@ default_case1: if ((t->cstat&16) || (A_CheckEnemySprite(t) && (unsigned)t->owner < MAXSPRITES && sprite[t->owner].extra > 0) || t->statnum == STAT_PLAYER) { - if (RR && g_shadedSector[s->sectnum] == 1) + if (RR && shadedsector[s->sectnum] == 1) { s->shade = 16; t->shade = 16; @@ -4744,7 +4744,7 @@ default_case1: sprite[pSprite->owner].y - g_player[screenpeek].ps->pos.y); int16_t const sqb = getangle(sprite[pSprite->owner].x - t->x, sprite[pSprite->owner].y - t->y); - if (klabs(G_GetAngleDelta(sqa,sqb)) > 512) + if (klabs(getincangle(sqa,sqb)) > 512) if (ldist(&sprite[pSprite->owner],(const spritetype *)t) < ldist(&sprite[g_player[screenpeek].ps->i],&sprite[pSprite->owner])) t->xrepeat = t->yrepeat = 0; } @@ -5232,7 +5232,7 @@ PALONLY: } if (t->pal == 6) t->shade = -120; - if (RR && g_shadedSector[pSprite->sectnum] == 1) + if (RR && shadedsector[pSprite->sectnum] == 1) t->shade = 16; fallthrough__; case SCRAP1__STATIC: diff --git a/source/games/duke/src/zz_gameexec.cpp b/source/games/duke/src/zz_gameexec.cpp index 959c67252..931d71634 100644 --- a/source/games/duke/src/zz_gameexec.cpp +++ b/source/games/duke/src/zz_gameexec.cpp @@ -202,103 +202,8 @@ GAMEEXEC_STATIC GAMEEXEC_INLINE void P_ForceAngle(DukePlayer_t *pPlayer) } // wow, this function sucks -int32_t A_Dodge(spritetype * const); -int32_t A_Dodge(spritetype * const pSprite) -{ - if (DEER) - { - pSprite->ang += ((rrdh_random() & 255) - 127) * 2; - pSprite->ang &= 2047; - return 0; - } - vec2_t const msin = { sintable[(pSprite->ang + 512) & 2047], sintable[pSprite->ang & 2047] }; +int furthestcanseepoint(int i, spritetype* ts, int* dax, int* day); - for (native_t nexti, SPRITES_OF_STAT_SAFE(STAT_PROJECTILE, i, nexti)) //weapons list - { - if (OW(i) == i || SECT(i) != pSprite->sectnum) - continue; - - vec2_t const b = { SX(i) - pSprite->x, SY(i) - pSprite->y }; - vec2_t const v = { sintable[(SA(i) + 512) & 2047], sintable[SA(i) & 2047] }; - - if (((msin.x * b.x) + (msin.y * b.y) >= 0) && ((v.x * b.x) + (v.y * b.y) < 0)) - { - if (klabs((v.x * b.y) - (v.y * b.x)) < 65536 << 6) - { - pSprite->ang -= 512+(krand2()&1024); - return 1; - } - } - } - - return 0; -} - -int32_t A_GetFurthestAngle(int const spriteNum, int const angDiv) -{ - uspritetype *const pSprite = (uspritetype *)&sprite[spriteNum]; - - if (pSprite->picnum != TILE_APLAYER && (AC_COUNT(actor[spriteNum].t_data)&63) > 2) - return pSprite->ang + 1024; - - int32_t furthestAngle = 0; - int32_t greatestDist = INT32_MIN; - int const angIncs = tabledivide32_noinline(2048, angDiv); - hitdata_t hit; - - for (native_t j = pSprite->ang; j < (2048 + pSprite->ang); j += angIncs) - { - pSprite->z -= ZOFFSET3; - hitscan((const vec3_t *)pSprite, pSprite->sectnum, sintable[(j + 512) & 2047], sintable[j & 2047], 0, &hit, CLIPMASK1); - pSprite->z += ZOFFSET3; - - int const hitDist = klabs(hit.pos.x-pSprite->x) + klabs(hit.pos.y-pSprite->y); - - if (hitDist > greatestDist) - { - greatestDist = hitDist; - furthestAngle = j; - } - } - - return furthestAngle&2047; -} - -int A_FurthestVisiblePoint(int const spriteNum, uspritetype * const ts, vec2_t * const vect) -{ - if (AC_COUNT(actor[spriteNum].t_data)&63) - return -1; - - const uspritetype *const pnSprite = (uspritetype *)&sprite[spriteNum]; - - hitdata_t hit; - int const angincs = ((!g_netServer && ud.multimode < 2) && ud.player_skill < 3) ? 2048 / 2 : tabledivide32_noinline(2048, 1 + (krand2() & 1)); - - for (native_t j = ts->ang; j < (2048 + ts->ang); j += (angincs-(krand2()&511))) - { - ts->z -= ZOFFSET2; - hitscan((const vec3_t *)ts, ts->sectnum, sintable[(j + 512) & 2047], sintable[j & 2047], 16384 - (krand2() & 32767), &hit, CLIPMASK1); - ts->z += ZOFFSET2; - - if (hit.sect < 0) - continue; - - int const d = klabs(hit.pos.x - ts->x) + klabs(hit.pos.y - ts->y); - int const da = klabs(hit.pos.x - pnSprite->x) + klabs(hit.pos.y - pnSprite->y); - - if (d < da) - { - if (cansee(hit.pos.x, hit.pos.y, hit.pos.z, hit.sect, pnSprite->x, pnSprite->y, pnSprite->z - ZOFFSET2, pnSprite->sectnum)) - { - vect->x = hit.pos.x; - vect->y = hit.pos.y; - return hit.sect; - } - } - } - - return -1; -} static void VM_GetZRange(int const spriteNum, int32_t * const ceilhit, int32_t * const florhit, int const wallDist) { @@ -309,205 +214,9 @@ static void VM_GetZRange(int const spriteNum, int32_t * const ceilhit, int32_t * getzrange(&tempVect, pSprite->sectnum, &actor[spriteNum].ceilingz, ceilhit, &actor[spriteNum].floorz, florhit, wallDist, CLIPMASK0); } -void A_GetZLimits(int const spriteNum) -{ - spritetype *const pSprite = &sprite[spriteNum]; - int32_t ceilhit, florhit; - - if (pSprite->statnum == STAT_PLAYER || pSprite->statnum == STAT_STANDABLE || pSprite->statnum == STAT_ZOMBIEACTOR - || pSprite->statnum == STAT_ACTOR || pSprite->statnum == STAT_PROJECTILE) - { - VM_GetZRange(spriteNum, &ceilhit, &florhit, (pSprite->statnum == STAT_PROJECTILE) ? 4 : 127); - actor[spriteNum].flags &= ~SFLAG_NOFLOORSHADOW; - - if ((florhit&49152) == 49152 && (sprite[florhit&(MAXSPRITES-1)].cstat&48) == 0) - { - uspritetype const * const hitspr = (uspritetype *)&sprite[florhit&(MAXSPRITES-1)]; - - florhit &= (MAXSPRITES-1); - - // If a non-projectile would fall onto non-frozen enemy OR an enemy onto a player... - if ((A_CheckEnemySprite(hitspr) && hitspr->pal != 1 && pSprite->statnum != STAT_PROJECTILE) - || (hitspr->picnum == TILE_APLAYER && A_CheckEnemySprite(pSprite))) - { - actor[spriteNum].flags |= SFLAG_NOFLOORSHADOW; // No shadows on actors - pSprite->xvel = -256; // SLIDE_ABOVE_ENEMY - A_SetSprite(spriteNum, CLIPMASK0); - } - else if (pSprite->statnum == STAT_PROJECTILE && hitspr->picnum == TILE_APLAYER && pSprite->owner==florhit) - { - actor[spriteNum].ceilingz = sector[pSprite->sectnum].ceilingz; - actor[spriteNum].floorz = sector[pSprite->sectnum].floorz; - } - } - } - else - { - actor[spriteNum].ceilingz = sector[pSprite->sectnum].ceilingz; - actor[spriteNum].floorz = sector[pSprite->sectnum].floorz; - } -} - -void A_Fall(int const spriteNum) -{ - spritetype *const pSprite = &sprite[spriteNum]; - int spriteGravity = g_spriteGravity; - - if (EDUKE32_PREDICT_FALSE(G_CheckForSpaceFloor(pSprite->sectnum))) - spriteGravity = 0; - else if (sector[pSprite->sectnum].lotag == ST_2_UNDERWATER || EDUKE32_PREDICT_FALSE(G_CheckForSpaceCeiling(pSprite->sectnum))) - spriteGravity = g_spriteGravity/6; - - if (RRRA && spriteGravity == g_spriteGravity) - { - if (pSprite->picnum == TILE_BIKERB || pSprite->picnum == TILE_CHEERB) - spriteGravity >>= 2; - else if (pSprite->picnum == TILE_BIKERBV2) - spriteGravity >>= 3; - } - - if (pSprite->statnum == STAT_ACTOR || pSprite->statnum == STAT_PLAYER || pSprite->statnum == STAT_ZOMBIEACTOR - || pSprite->statnum == STAT_STANDABLE) - { - int32_t ceilhit, florhit; - VM_GetZRange(spriteNum, &ceilhit, &florhit, 127); - } - else - { - actor[spriteNum].ceilingz = sector[pSprite->sectnum].ceilingz; - actor[spriteNum].floorz = sector[pSprite->sectnum].floorz; - } - -#ifdef YAX_ENABLE - int fbunch = (sector[pSprite->sectnum].floorstat&512) ? -1 : yax_getbunch(pSprite->sectnum, YAX_FLOOR); -#endif - - if (pSprite->z < actor[spriteNum].floorz-ZOFFSET -#ifdef YAX_ENABLE - || fbunch >= 0 -#endif - ) - { - if (sector[pSprite->sectnum].lotag == ST_2_UNDERWATER && pSprite->zvel > 3122) - pSprite->zvel = 3144; - if (pSprite->zvel < 6144) - pSprite->zvel += spriteGravity; - else pSprite->zvel = 6144; - pSprite->z += pSprite->zvel; - } - -#ifdef YAX_ENABLE - if (fbunch >= 0) - setspritez(spriteNum, (vec3_t *)pSprite); - else -#endif - if (pSprite->z >= actor[spriteNum].floorz-ZOFFSET) - { - pSprite->z = actor[spriteNum].floorz-ZOFFSET; - pSprite->zvel = 0; - } -} - -int32_t __fastcall G_GetAngleDelta(int32_t currAngle, int32_t newAngle) -{ - currAngle &= 2047; - newAngle &= 2047; - - if (klabs(currAngle-newAngle) < 1024) - { -// Printf("G_GetAngleDelta() returning %d\n",na-a); - return newAngle-currAngle; - } - - if (newAngle > 1024) - newAngle -= 2048; - if (currAngle > 1024) - currAngle -= 2048; - -// Printf("G_GetAngleDelta() returning %d\n",na-a); - return newAngle-currAngle; -} - -GAMEEXEC_STATIC void VM_AlterAng(int32_t const moveFlags) -{ - int const elapsedTics = (AC_COUNT(vm.pData))&31; - - const intptr_t *moveptr; - if (EDUKE32_PREDICT_FALSE((unsigned)AC_MOVE_ID(vm.pData) >= (unsigned)g_scriptSize-1)) - - { - AC_MOVE_ID(vm.pData) = 0; - Printf(TEXTCOLOR_RED "bad moveptr for actor %d (%d)!\n", vm.spriteNum, vm.pUSprite->picnum); - return; - } - - moveptr = apScript + AC_MOVE_ID(vm.pData); - - vm.pSprite->xvel += (moveptr[0] - vm.pSprite->xvel)/5; - if (vm.pSprite->zvel < 648) - vm.pSprite->zvel += ((moveptr[1]<<4) - vm.pSprite->zvel)/5; - - if (RRRA && (moveFlags&windang)) - vm.pSprite->ang = g_windDir; - else if (moveFlags&seekplayer) - { - int const spriteAngle = vm.pSprite->ang; - int const holoDukeSprite = vm.pPlayer->holoduke_on; - - // NOTE: looks like 'owner' is set to target sprite ID... - - vm.pSprite->owner = (!RR && holoDukeSprite >= 0 - && cansee(sprite[holoDukeSprite].x, sprite[holoDukeSprite].y, sprite[holoDukeSprite].z, sprite[holoDukeSprite].sectnum, - vm.pSprite->x, vm.pSprite->y, vm.pSprite->z, vm.pSprite->sectnum)) - ? holoDukeSprite - : vm.pPlayer->i; - - int const goalAng = (sprite[vm.pSprite->owner].picnum == TILE_APLAYER) - ? getangle(vm.pActor->lastv.x - vm.pSprite->x, vm.pActor->lastv.y - vm.pSprite->y) - : getangle(sprite[vm.pSprite->owner].x - vm.pSprite->x, sprite[vm.pSprite->owner].y - vm.pSprite->y); - - if (vm.pSprite->xvel && vm.pSprite->picnum != TILE_DRONE) - { - int const angDiff = G_GetAngleDelta(spriteAngle, goalAng); - - if (elapsedTics < 2) - { - if (klabs(angDiff) < 256) - { - int const angInc = 128-(krand2()&256); - vm.pSprite->ang += angInc; - if (A_GetHitscanRange(vm.spriteNum) < 844) - vm.pSprite->ang -= angInc; - } - } - else if (elapsedTics > 18 && elapsedTics < GAMETICSPERSEC) // choose - { - if (klabs(angDiff >> 2) < 128) - vm.pSprite->ang = goalAng; - else - vm.pSprite->ang += angDiff >> 2; - } - } - else - vm.pSprite->ang = goalAng; - } - - if (elapsedTics < 1) - { - if (moveFlags&furthestdir) - { - vm.pSprite->ang = A_GetFurthestAngle(vm.spriteNum, 2); - vm.pSprite->owner = vm.pPlayer->i; - } - - if (moveFlags&fleeenemy) - vm.pSprite->ang = A_GetFurthestAngle(vm.spriteNum, 2); - } -} - static inline void VM_AddAngle(int const shift, int const goalAng) { - int angDiff = G_GetAngleDelta(vm.pSprite->ang, goalAng) >> shift; + int angDiff = getincangle(vm.pSprite->ang, goalAng) >> shift; if (angDiff > -8 && angDiff < 0) angDiff = 0; @@ -559,287 +268,12 @@ static int32_t VM_GetFlorZOfSlope(void) //////////////////// static int32_t A_GetWaterZOffset(int spritenum); +void move_d(int g_i, int g_p, int g_x); +void move_r(int g_i, int g_p, int g_x); GAMEEXEC_STATIC void VM_Move(void) { - auto const movflagsptr = &AC_MOVFLAGS(vm.pSprite, &actor[vm.spriteNum]); - // NOTE: test against -1 commented out and later revived in source history - // XXX: Does its presence/absence break anything? Where are movflags with all bits set created? - int const movflags = (*movflagsptr == (std::remove_pointer::type)-1) ? 0 : *movflagsptr; - - AC_COUNT(vm.pData)++; - - if (movflags&face_player) - VM_FacePlayer(2); - - if (movflags&spin) - vm.pSprite->ang += sintable[((AC_COUNT(vm.pData)<<3)&2047)]>>6; - - if (movflags&face_player_slow) - { - int const goalAng = (vm.pPlayer->newowner >= 0) ? getangle(vm.pPlayer->opos.x - vm.pSprite->x, vm.pPlayer->opos.y - vm.pSprite->y) - : getangle(vm.pPlayer->pos.x - vm.pSprite->x, vm.pPlayer->pos.y - vm.pSprite->y); - - vm.pSprite->ang += ksgn(G_GetAngleDelta(vm.pSprite->ang, goalAng)) << 5; - } - - if (RRRA && (movflags&antifaceplayerslow)) - { - int goalAng = (vm.pPlayer->newowner >= 0) ? getangle(vm.pPlayer->opos.x - vm.pSprite->x, vm.pPlayer->opos.y - vm.pSprite->y) - : getangle(vm.pPlayer->pos.x - vm.pSprite->x, vm.pPlayer->pos.y - vm.pSprite->y); - goalAng = (goalAng+1024)&2047; - - vm.pSprite->ang += ksgn(G_GetAngleDelta(vm.pSprite->ang, goalAng)) << 5; - } - - if ((movflags&jumptoplayer_bits) == jumptoplayer_bits) - { - if (AC_COUNT(vm.pData) < 16) - vm.pSprite->zvel -= (!DEER && RRRA && vm.pSprite->picnum == TILE_CHEER) ? (sintable[(512+(AC_COUNT(vm.pData)<<4))&2047]/40) - : (sintable[(512+(AC_COUNT(vm.pData)<<4))&2047]>>5); - } - - if (movflags&face_player_smart) - { - vec2_t const vect = { vm.pPlayer->pos.x + (vm.pPlayer->vel.x / 768), vm.pPlayer->pos.y + (vm.pPlayer->vel.y / 768) }; - VM_AddAngle(2, getangle(vect.x - vm.pSprite->x, vect.y - vm.pSprite->y)); - } - - if (RRRA && (vm.pSprite->picnum == TILE_RABBIT || vm.pSprite->picnum == TILE_MAMA)) - { - if(movflags&jumptoplayer_only) - { - if (AC_COUNT(vm.pData) < 8) - vm.pSprite->zvel -= sintable[(512+(AC_COUNT(vm.pData)<<4))&2047]/(vm.pSprite->picnum == TILE_RABBIT ? 30 : 35); - } - if(movflags&justjump2) - { - if (AC_COUNT(vm.pData) < 8) - vm.pSprite->zvel -= sintable[(512+(AC_COUNT(vm.pData)<<4))&2047]/(vm.pSprite->picnum == TILE_RABBIT ? 24 : 28); - } - } - - if (RRRA && (movflags&windang)) - { - if (AC_COUNT(vm.pData) < 8) - vm.pSprite->zvel -= sintable[(512+(AC_COUNT(vm.pData)<<4))&2047]/24; - } - - if (AC_MOVE_ID(vm.pData) == 0 || movflags == 0) - { - if ((A_CheckEnemySprite(vm.pSprite) && vm.pSprite->extra <= 0) || (vm.pActor->bpos.x != vm.pSprite->x) || (vm.pActor->bpos.y != vm.pSprite->y)) - { - vm.pActor->bpos.x = vm.pSprite->x; - vm.pActor->bpos.y = vm.pSprite->y; - setsprite(vm.spriteNum, (vec3_t *)vm.pSprite); - } - if (RR && A_CheckEnemySprite(vm.pSprite) && vm.pSprite->extra <= 0) - { - vm.pSprite->shade += (sector[vm.pSprite->sectnum].ceilingstat & 1) ? ((g_shadedSector[vm.pSprite->sectnum] == 1 ? 16 : sector[vm.pSprite->sectnum].ceilingshade) - vm.pSprite->shade) >> 1 - : (sector[vm.pSprite->sectnum].floorshade - vm.pSprite->shade) >> 1; - } - return; - } - - if (EDUKE32_PREDICT_FALSE((unsigned)AC_MOVE_ID(vm.pData) >= (unsigned)g_scriptSize-1)) - { - AC_MOVE_ID(vm.pData) = 0; - Printf(TEXTCOLOR_RED "clearing bad moveptr for actor %d (%d)\n", vm.spriteNum, vm.pUSprite->picnum); - return; - } - - intptr_t const * const moveptr = apScript + AC_MOVE_ID(vm.pData); - - if (movflags & geth) - vm.pSprite->xvel += ((moveptr[0]) - vm.pSprite->xvel) >> 1; - if (movflags & getv) - vm.pSprite->zvel += ((moveptr[1] << 4) - vm.pSprite->zvel) >> 1; - - if (movflags&dodgebullet) - A_Dodge(vm.pSprite); - - if (vm.pSprite->picnum != TILE_APLAYER) - VM_AlterAng(movflags); - - if (vm.pSprite->xvel > -6 && vm.pSprite->xvel < 6) - vm.pSprite->xvel = 0; - - int badguyp = A_CheckEnemySprite(vm.pSprite); - - if (vm.pSprite->xvel || vm.pSprite->zvel) - { - int spriteXvel = vm.pSprite->xvel; - int angDiff = vm.pSprite->ang; - - if (badguyp && (vm.pSprite->picnum != TILE_ROTATEGUN || RR)) - { - if ((vm.pSprite->picnum == TILE_DRONE || (!RR && vm.pSprite->picnum == TILE_COMMANDER)) && vm.pSprite->extra > 0) - { - if (!RR && vm.pSprite->picnum == TILE_COMMANDER) - { - int32_t nSectorZ; - // NOTE: TILE_COMMANDER updates both actor[].floorz and - // .ceilingz regardless of its zvel. - vm.pActor->floorz = nSectorZ = VM_GetFlorZOfSlope(); - if (vm.pSprite->z > nSectorZ-ZOFFSET3) - { - vm.pSprite->z = nSectorZ-ZOFFSET3; - vm.pSprite->zvel = 0; - } - - vm.pActor->ceilingz = nSectorZ = VM_GetCeilZOfSlope(); - if (vm.pSprite->z < nSectorZ+(80<<8)) - { - vm.pSprite->z = nSectorZ+(80<<8); - vm.pSprite->zvel = 0; - } - } - else - { - int32_t nSectorZ; - // The TILE_DRONE updates either .floorz or .ceilingz, not both. - if (vm.pSprite->zvel > 0) - { - vm.pActor->floorz = nSectorZ = VM_GetFlorZOfSlope(); - int const zDiff = RRRA ? (28<<8) : (30<<8); - if (vm.pSprite->z > nSectorZ-zDiff) - vm.pSprite->z = nSectorZ-zDiff; - } - else - { - vm.pActor->ceilingz = nSectorZ = VM_GetCeilZOfSlope(); - if (vm.pSprite->z < nSectorZ+(50<<8)) - { - vm.pSprite->z = nSectorZ+(50<<8); - vm.pSprite->zvel = 0; - } - } - } - } - else if (vm.pSprite->picnum != TILE_ORGANTIC || RR) - { - // All other actors besides TILE_ORGANTIC don't update .floorz or - // .ceilingz here. - if (vm.pSprite->zvel > 0) - { - if (vm.pSprite->z > vm.pActor->floorz) - vm.pSprite->z = vm.pActor->floorz; - //vm.pSprite->z += A_GetWaterZOffset(vm.spriteNum); - } - else if (vm.pSprite->zvel < 0) - { - int const l = VM_GetCeilZOfSlope(); - - if (vm.pSprite->z < l+(66<<8)) - { - vm.pSprite->z = l+(66<<8); - vm.pSprite->zvel >>= 1; - } - } - } - - if (vm.playerDist < 960 && vm.pSprite->xrepeat > 16) - { - spriteXvel = -(1024 - vm.playerDist); - angDiff = getangle(vm.pPlayer->pos.x - vm.pSprite->x, vm.pPlayer->pos.y - vm.pSprite->y); - - if (vm.playerDist < 512) - { - vm.pPlayer->vel.x = 0; - vm.pPlayer->vel.y = 0; - } - else - { - vm.pPlayer->vel.x = mulscale16(vm.pPlayer->vel.x, vm.pPlayer->runspeed - 0x2000); - vm.pPlayer->vel.y = mulscale16(vm.pPlayer->vel.y, vm.pPlayer->runspeed - 0x2000); - } - } - else if (vm.pSprite->picnum != TILE_DRONE && vm.pSprite->picnum != TILE_SHARK - && ((!RR && vm.pSprite->picnum != TILE_COMMANDER) - || (RR && vm.pSprite->picnum != TILE_UFO1) - || (RR && !RRRA && vm.pSprite->picnum != TILE_UFO2 && vm.pSprite->picnum != TILE_UFO3 && vm.pSprite->picnum != TILE_UFO4 && vm.pSprite->picnum != TILE_UFO5))) - { - if (vm.pPlayer->actorsqu == vm.spriteNum) - return; - - if (vm.pActor->bpos.z != vm.pSprite->z || (!g_netServer && ud.multimode < 2 && ud.player_skill < 2)) - { - if (AC_COUNT(vm.pData)&1) return; - spriteXvel <<= 1; - } - else - { - if (AC_COUNT(vm.pData)&3) return; - spriteXvel <<= 2; - } - } - } - else if (vm.pSprite->picnum == TILE_APLAYER) - if (vm.pSprite->z < vm.pActor->ceilingz+ZOFFSET5) - vm.pSprite->z = vm.pActor->ceilingz+ZOFFSET5; - - if (RRRA) - { - if (sector[vm.pSprite->sectnum].lotag != ST_1_ABOVE_WATER) - { - switch (DYNAMICTILEMAP(vm.pSprite->picnum)) - { - case MINIONBOAT__STATICRR: - case HULK__STATICRR: - case CHEERBOAT__STATICRR: - spriteXvel >>= 1; - break; - } - } - else - { - switch (DYNAMICTILEMAP(vm.pSprite->picnum)) - { - case BIKERB__STATICRR: - case BIKERBV2__STATICRR: - case CHEERB__STATICRR: - spriteXvel >>= 1; - break; - } - } - } - - vec3_t const vect - = { (spriteXvel * (sintable[(angDiff + 512) & 2047])) >> 14, (spriteXvel * (sintable[angDiff & 2047])) >> 14, vm.pSprite->zvel }; - - vm.pActor->movflag = A_MoveSprite(vm.spriteNum, &vect, CLIPMASK0); - if (DEER && vm.pSprite->picnum != TILE_DOGRUN) - { - if ((vm.pActor->movflag & 49152) == 32768) - { - int const wallnum = vm.pActor->movflag & (MAXWALLS-1); - if (ghcons_isanimalescapewall(wallnum)) - { - vm.pSprite->z = sector[vm.pSprite->sectnum].ceilingz; - A_MoveSprite(vm.spriteNum, &vect, CLIPMASK0); - vm.pSprite->z = sector[vm.pSprite->sectnum].floorz; - } - } - else if ((vm.pActor->movflag & 49152) == 16384) - { - int sectnum = vm.pActor->movflag & (MAXSECTORS-1); - if (ghcons_isanimalescapesect(sectnum)) - { - A_MoveSprite(vm.spriteNum, &vect, CLIPMASK0); - vm.pSprite->z = sector[vm.pSprite->sectnum].floorz; - } - } - } - } - - if (!badguyp) - return; - - vm.pSprite->shade += (sector[vm.pSprite->sectnum].ceilingstat & 1) ? ((g_shadedSector[vm.pSprite->sectnum] == 1 ? 16 : sector[vm.pSprite->sectnum].ceilingshade) - vm.pSprite->shade) >> 1 - : (sector[vm.pSprite->sectnum].floorshade - vm.pSprite->shade) >> 1; - - if (sector[vm.pSprite->sectnum].floorpicnum == TILE_MIRROR) - A_DeleteSprite(vm.spriteNum); + if (isRR()) move_r(vm.spriteNum, vm.playerNum, vm.playerDist); else move_d(vm.spriteNum, vm.playerNum, vm.playerDist); } static void VM_AddWeapon(DukePlayer_t * const pPlayer, int const weaponNum, int const nAmount) @@ -1044,7 +478,7 @@ static void VM_Fall(int const spriteNum, spritetype * const pSprite) if (actor[spriteNum].cgg <= 0 || (sector[pSprite->sectnum].floorstat&2)) { - A_GetZLimits(spriteNum); + getglobalz(spriteNum); actor[spriteNum].cgg = 6; } else actor[spriteNum].cgg--; @@ -1370,7 +804,7 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop) // also modifies 'target' x&y if found.. tw = 1; - if (A_FurthestVisiblePoint(vm.spriteNum, pSprite, &vm.pActor->lastv) == -1) + if (furthestcanseepoint(vm.spriteNum, (spritetype*)pSprite, &vm.pActor->lastv.x, &vm.pActor->lastv.y) == -1) tw = 0; } else @@ -2367,9 +1801,9 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop) { nResult = (vm.pSprite->picnum == TILE_APLAYER && (g_netServer || ud.multimode > 1)) - ? G_GetAngleDelta(fix16_to_int(g_player[otherp].ps->q16ang), + ? getincangle(fix16_to_int(g_player[otherp].ps->q16ang), getangle(pPlayer->pos.x - g_player[otherp].ps->pos.x, pPlayer->pos.y - g_player[otherp].ps->pos.y)) - : G_GetAngleDelta(fix16_to_int(pPlayer->q16ang), getangle(vm.pSprite->x - pPlayer->pos.x, vm.pSprite->y - pPlayer->pos.y)); + : getincangle(fix16_to_int(pPlayer->q16ang), getangle(vm.pSprite->x - pPlayer->pos.x, vm.pSprite->y - pPlayer->pos.y)); nResult = (nResult > -128 && nResult < 128); } @@ -2465,7 +1899,7 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop) vm.pSprite->picnum = *insptr++; continue; - case concmd_ifbulletnear: VM_CONDITIONAL(A_Dodge(vm.pSprite) == 1); continue; + case concmd_ifbulletnear: VM_CONDITIONAL(dodge(vm.pSprite) == 1); continue; case concmd_ifrespawn: if (A_CheckEnemySprite(vm.pSprite)) @@ -2651,7 +2085,7 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop) case concmd_ifangdiffl: insptr++; - tw = klabs(G_GetAngleDelta(fix16_to_int(pPlayer->q16ang), vm.pSprite->ang)); + tw = klabs(getincangle(fix16_to_int(pPlayer->q16ang), vm.pSprite->ang)); VM_CONDITIONAL(tw <= *insptr); continue; diff --git a/source/games/duke/src/zz_namesdyn.cpp b/source/games/duke/src/zz_namesdyn.cpp index 4621e7875..48539de49 100644 --- a/source/games/duke/src/zz_namesdyn.cpp +++ b/source/games/duke/src/zz_namesdyn.cpp @@ -2897,11 +2897,13 @@ void G_InitDynamicTiles(void) { APLAYER = 3845; CAMERA1 = 1134; + //DRONE = 1880; } else { APLAYER = 1405; CAMERA1 = 621; + //DRONE = 4916; } diff --git a/source/games/duke/src/zz_player.cpp b/source/games/duke/src/zz_player.cpp index 9a5e1b7c9..321cf1891 100644 --- a/source/games/duke/src/zz_player.cpp +++ b/source/games/duke/src/zz_player.cpp @@ -1894,7 +1894,7 @@ void P_DisplayWeapon(void) int weaponX = (160) - 90; int weaponY = klabs(pPlayer->look_ang) / 9; int weaponYOffset = 80 - (pPlayer->weapon_pos * pPlayer->weapon_pos); - int weaponShade = (RR && pPlayer->cursectnum >= 0 && g_shadedSector[pPlayer->cursectnum]) ? 16 : (sprite[pPlayer->i].shade <= 24 ? sprite[pPlayer->i].shade : 24); + int weaponShade = (RR && pPlayer->cursectnum >= 0 && shadedsector[pPlayer->cursectnum]) ? 16 : (sprite[pPlayer->i].shade <= 24 ? sprite[pPlayer->i].shade : 24); int32_t weaponBits = 0; UNREFERENCED_PARAMETER(weaponBits); @@ -4207,7 +4207,7 @@ static int32_t P_DoCounters(int playerNum) else if ((krand2() & 127) == 8) { g_windTime = 120+((krand2()&63)<<2); - g_windDir = krand2()&2047; + WindDir = krand2()&2047; } if (g_bellTime > 0) @@ -8480,7 +8480,7 @@ HORIZONLY:; if (pPlayer->cursectnum >= 0 && ud.clipping == 0) { int const squishPlayer = (pushmove((vec3_t *)pPlayer, &pPlayer->cursectnum, (!RR || pSprite->clipdist == 64) ? 164 : 16, (4L << 8), (4L << 8), CLIPMASK0) < 0 && - A_GetFurthestAngle(pPlayer->i, 8) < 512); + furthestangle(pPlayer->i, 8) < 512); if (squishPlayer || klabs(actor[pPlayer->i].floorz-actor[pPlayer->i].ceilingz) < (48<<8)) { @@ -8641,7 +8641,7 @@ HORIZONLY:; } else if (pPlayer->actorsqu >= 0) pPlayer->q16ang += fix16_from_int( - G_GetAngleDelta(fix16_to_int(pPlayer->q16ang), + getincangle(fix16_to_int(pPlayer->q16ang), getangle(sprite[pPlayer->actorsqu].x - pPlayer->pos.x, sprite[pPlayer->actorsqu].y - pPlayer->pos.y)) >> 2); } @@ -9151,7 +9151,7 @@ void P_DHProcessInput(int playerNum) if (pPlayer->cursectnum >= 0 && ud.clipping == 0) { int const squishPlayer = (pushmove((vec3_t *)pPlayer, &pPlayer->cursectnum, (!RR || pSprite->clipdist == 64) ? 164 : 16, (4L << 8), (4L << 8), CLIPMASK0) < 0 && - A_GetFurthestAngle(pPlayer->i, 8) < 512); + furthestangle(pPlayer->i, 8) < 512); } if (pPlayer->return_to_center > 0) diff --git a/source/games/duke/src/zz_premap.cpp b/source/games/duke/src/zz_premap.cpp index 7db9685d1..cb3a2ca01 100644 --- a/source/games/duke/src/zz_premap.cpp +++ b/source/games/duke/src/zz_premap.cpp @@ -1164,7 +1164,7 @@ static void resetprestat(int playerNum, int gameMode) if (RRRA) { g_windTime = 0; - g_windDir = 0; + WindDir = 0; g_fakeBubbaCnt = 0; RRRA_ExitedLevel = 0; g_bellTime = 0; @@ -1303,7 +1303,7 @@ static void prelevel(char g) Bmemset(g_spriteExtra, 0, sizeof(g_spriteExtra)); Bmemset(g_sectorExtra, 0, sizeof(g_sectorExtra)); - Bmemset(g_shadedSector, 0, sizeof(g_shadedSector)); + Bmemset(shadedsector, 0, sizeof(shadedsector)); Bmemset(g_geoSectorWarp, -1, sizeof(g_geoSectorWarp)); Bmemset(g_geoSectorWarp2, -1, sizeof(g_geoSectorWarp2)); Bmemset(g_ambientHitag, -1, sizeof(g_ambientHitag)); @@ -1323,7 +1323,7 @@ static void prelevel(char g) if (RRRA) { g_windTime = 0; - g_windDir = 0; + WindDir = 0; g_fakeBubbaCnt = 0; RRRA_ExitedLevel = 0; g_mamaSpawnCnt = 15; // ??? @@ -1519,7 +1519,7 @@ static void prelevel(char g) break; case RRTILE68__STATICRR: - g_shadedSector[SECT(i)] = 1; + shadedsector[SECT(i)] = 1; A_DeleteSprite(i); break; diff --git a/source/games/duke/src/zz_rrdh.cpp b/source/games/duke/src/zz_rrdh.cpp index f42d01ff5..e4c79f1b2 100644 --- a/source/games/duke/src/zz_rrdh.cpp +++ b/source/games/duke/src/zz_rrdh.cpp @@ -3785,7 +3785,7 @@ void gharrow_move(void) } else { - A_GetZLimits(i); + getglobalz(i); v24 = s->x; v28 = s->y; v20 = s->y; diff --git a/source/games/duke/src/zz_savegame.cpp b/source/games/duke/src/zz_savegame.cpp index b011d3b53..b543af1f6 100644 --- a/source/games/duke/src/zz_savegame.cpp +++ b/source/games/duke/src/zz_savegame.cpp @@ -874,7 +874,7 @@ static const dataspec_t svgm_anmisc[] = { 0, &g_spriteExtra[0], sizeof(g_spriteExtra[0]), MAXSPRITES }, { 0, &g_sectorExtra[0], sizeof(g_sectorExtra[0]), MAXSECTORS }, - { 0, &g_shadedSector[0], sizeof(g_shadedSector[0]), MAXSECTORS }, + { 0, &shadedsector[0], sizeof(shadedsector[0]), MAXSECTORS }, { 0, &g_ambientCnt, sizeof(g_ambientCnt), 1 }, { 0, &g_ambientHitag[0], sizeof(g_ambientHitag[0]), ARRAY_SIZE(g_ambientHitag) }, @@ -895,7 +895,7 @@ static const dataspec_t svgm_anmisc[] = { 0, &g_geoSectorCnt, sizeof(g_geoSectorCnt), 1 }, { 0, &g_windTime, sizeof(g_windTime), 1 }, - { 0, &g_windDir, sizeof(g_windDir), 1 }, + { 0, &WindDir, sizeof(WindDir), 1 }, { 0, &g_fakeBubbaCnt, sizeof(g_fakeBubbaCnt), 1 }, { 0, &g_mamaSpawnCnt, sizeof(g_mamaSpawnCnt), 1 }, { 0, &g_banjoSong, sizeof(g_banjoSong), 1 }, diff --git a/source/games/duke/src/zz_sector.cpp b/source/games/duke/src/zz_sector.cpp index 12d25045d..245a74058 100644 --- a/source/games/duke/src/zz_sector.cpp +++ b/source/games/duke/src/zz_sector.cpp @@ -36,7 +36,7 @@ void operatejaildoors(int hitag); static int g_haltSoundHack = 0; -uint8_t g_shadedSector[MAXSECTORS]; +uint8_t shadedsector[MAXSECTORS]; int S_FindMusicSFX(int sectNum, int* sndptr) {