- track.cpp complete.

This commit is contained in:
Christoph Oelckers 2021-11-06 00:37:16 +01:00
parent 4796ebc73c
commit f8105dc92b
3 changed files with 69 additions and 113 deletions

View file

@ -48,7 +48,7 @@ void SpawnVis(DSWActor* Parent, short sectnum, int x, int y, int z, int amt);
enum TriggerType { TRIGGER_TYPE_REMOTE_SO }; enum TriggerType { TRIGGER_TYPE_REMOTE_SO };
int ActorFollowTrack(DSWActor*, short locktics); int ActorFollowTrack(DSWActor*, short locktics);
void ActorLeaveTrack(short SpriteNum); void ActorLeaveTrack(DSWActor*);
void RefreshPoints(SECTOR_OBJECTp sop, int nx, int ny, bool dynamic); void RefreshPoints(SECTOR_OBJECTp sop, int nx, int ny, bool dynamic);
void TrackSetup(void); void TrackSetup(void);
void PlaceSectorObject(SECTOR_OBJECTp sop, int newx, int newy); void PlaceSectorObject(SECTOR_OBJECTp sop, int newx, int newy);

View file

@ -52,9 +52,9 @@ ANIMATOR NinjaJumpActionFunc;
int GlobSpeedSO; int GlobSpeedSO;
// determine if moving down the track will get you closer to the player // determine if moving down the track will get you closer to the player
short short TrackTowardPlayer(DSWActor* actor, TRACKp t, TRACK_POINTp start_point)
TrackTowardPlayer(SPRITEp sp, TRACKp t, TRACK_POINTp start_point)
{ {
auto sp = &actor->s();
TRACK_POINTp end_point; TRACK_POINTp end_point;
int end_dist, start_dist; int end_dist, start_dist;
@ -80,10 +80,9 @@ TrackTowardPlayer(SPRITEp sp, TRACKp t, TRACK_POINTp start_point)
} }
short short TrackStartCloserThanEnd(DSWActor* actor, TRACKp t, TRACK_POINTp start_point)
TrackStartCloserThanEnd(short SpriteNum, TRACKp t, TRACK_POINTp start_point)
{ {
SPRITEp sp = User[SpriteNum]->SpriteP; SPRITEp sp = &actor->s();
TRACK_POINTp end_point; TRACK_POINTp end_point;
int end_dist, start_dist; int end_dist, start_dist;
@ -117,12 +116,10 @@ point to the sprite.
*/ */
short short ActorFindTrack(DSWActor* actor, int8_t player_dir, int track_type, short *track_point_num, short *track_dir)
ActorFindTrack(DSWActor* actor, int8_t player_dir, int track_type, short *track_point_num, short *track_dir)
{ {
USERp u = actor->u(); USERp u = actor->u();
SPRITEp sp = &actor->s(); SPRITEp sp = &actor->s();
int SpriteNum = actor->GetSpriteIndex();
int dist, near_dist = 999999, zdiff; int dist, near_dist = 999999, zdiff;
int track_sect=0; int track_sect=0;
@ -133,8 +130,11 @@ ActorFindTrack(DSWActor* actor, int8_t player_dir, int track_type, short *track_
TRACKp t, near_track = nullptr; TRACKp t, near_track = nullptr;
TRACK_POINTp tp, near_tp = nullptr; TRACK_POINTp tp, near_tp = nullptr;
#define TOWARD_PLAYER 1 enum
#define AWAY_FROM_PLAYER -1 {
TOWARD_PLAYER = 1,
AWAY_FROM_PLAYER = -1
};
// look at all tracks finding the closest endpoint // look at all tracks finding the closest endpoint
for (t = &Track[0]; t < &Track[MAX_TRACKS]; t++) for (t = &Track[0]; t < &Track[MAX_TRACKS]; t++)
@ -220,14 +220,14 @@ ActorFindTrack(DSWActor* actor, int8_t player_dir, int track_type, short *track_
// to // to
if (player_dir == TOWARD_PLAYER) if (player_dir == TOWARD_PLAYER)
{ {
if (!TrackTowardPlayer(&u->targetActor->s(), t, tp)) if (!TrackTowardPlayer(u->targetActor, t, tp))
{ {
continue; continue;
} }
} }
else if (player_dir == AWAY_FROM_PLAYER) else if (player_dir == AWAY_FROM_PLAYER)
{ {
if (TrackTowardPlayer(&u->targetActor->s(), t, tp)) if (TrackTowardPlayer(u->targetActor, t, tp))
{ {
continue; continue;
} }
@ -235,7 +235,7 @@ ActorFindTrack(DSWActor* actor, int8_t player_dir, int track_type, short *track_
// make sure the start distance is closer than the end // make sure the start distance is closer than the end
// distance // distance
if (!TrackStartCloserThanEnd(SpriteNum, t, tp)) if (!TrackStartCloserThanEnd(actor, t, tp))
{ {
continue; continue;
} }
@ -273,8 +273,7 @@ ActorFindTrack(DSWActor* actor, int8_t player_dir, int track_type, short *track_
} }
void void NextTrackPoint(SECTOR_OBJECTp sop)
NextTrackPoint(SECTOR_OBJECTp sop)
{ {
sop->point += sop->dir; sop->point += sop->dir;
@ -286,10 +285,9 @@ NextTrackPoint(SECTOR_OBJECTp sop)
} }
void void NextActorTrackPoint(DSWActor* actor)
NextActorTrackPoint(short SpriteNum)
{ {
USERp u = User[SpriteNum].Data(); USERp u = actor->u();
u->point += u->track_dir; u->point += u->track_dir;
@ -572,7 +570,7 @@ void QuickLadderSetup(short stat, short lotag, short type)
void TrackSetup(void) void TrackSetup(void)
{ {
int SpriteNum = 0, ndx; int ndx;
TRACK_POINTp tp; TRACK_POINTp tp;
TRACKp t; TRACKp t;
TRACK_POINTp New; TRACK_POINTp New;
@ -701,8 +699,7 @@ DSWActor* FindBoundSprite(int tag)
} }
void void SectorObjectSetupBounds(SECTOR_OBJECTp sop)
SectorObjectSetupBounds(SECTOR_OBJECTp sop)
{ {
int xlow, ylow, xhigh, yhigh; int xlow, ylow, xhigh, yhigh;
int startwall, endwall; int startwall, endwall;
@ -713,7 +710,7 @@ SectorObjectSetupBounds(SECTOR_OBJECTp sop)
SECTORp *sectp; SECTORp *sectp;
USERp u = sop->sp_child->u(); USERp u = sop->sp_child->u();
static uint8_t StatList[] = static const uint8_t StatList[] =
{ {
STAT_DEFAULT, STAT_MISC, STAT_ITEM, STAT_TRAP, STAT_DEFAULT, STAT_MISC, STAT_ITEM, STAT_TRAP,
STAT_SPAWN_SPOT, STAT_SOUND_SPOT, STAT_WALL_MOVE, STAT_SPAWN_SPOT, STAT_SOUND_SPOT, STAT_WALL_MOVE,
@ -1017,8 +1014,7 @@ cont:
} }
void void SetupSectorObject(short sectnum, short tag)
SetupSectorObject(short sectnum, short tag)
{ {
SPRITEp sp; SPRITEp sp;
SECTOR_OBJECTp sop; SECTOR_OBJECTp sop;
@ -1409,8 +1405,7 @@ SetupSectorObject(short sectnum, short tag)
} }
void void PostSetupSectorObject(void)
PostSetupSectorObject(void)
{ {
SECTOR_OBJECTp sop; SECTOR_OBJECTp sop;
@ -1423,8 +1418,7 @@ PostSetupSectorObject(void)
} }
SECTOR_OBJECTp SECTOR_OBJECTp PlayerOnObject(short sectnum_match)
PlayerOnObject(short sectnum_match)
{ {
short i, j; short i, j;
SECTOR_OBJECTp sop; SECTOR_OBJECTp sop;
@ -1451,8 +1445,7 @@ PlayerOnObject(short sectnum_match)
} }
void void PlaceSectorObjectsOnTracks(void)
PlaceSectorObjectsOnTracks(void)
{ {
short i, j, k, startwall, endwall; short i, j, k, startwall, endwall;
bool found; bool found;
@ -1505,15 +1498,11 @@ PlaceSectorObjectsOnTracks(void)
low_dist = dist; low_dist = dist;
sop->point = j; sop->point = j;
found = true; found = true;
////DSPRINTF(ds,"point = %d, dist = %d, x1=%d, y1=%d",j,low_dist,(tpoint +j)->x,(tpoint+j)->y);
//MONO_PRINT(ds);
} }
} }
if (!found) if (!found)
{ {
//DSPRINTF(ds,"track not found");
MONO_PRINT(ds);
sop->track = -1; sop->track = -1;
continue; continue;
} }
@ -1528,22 +1517,21 @@ PlaceSectorObjectsOnTracks(void)
} }
void void PlaceActorsOnTracks(void)
PlaceActorsOnTracks(void)
{ {
short i, j, tag; short j, tag;
SPRITEp sp; SPRITEp sp;
USERp u; USERp u;
TRACK_POINTp tpoint = nullptr; TRACK_POINTp tpoint = nullptr;
// place each actor on the track // place each actor on the track
StatIterator it(STAT_ENEMY); SWStatIterator it(STAT_ENEMY);
while ((i = it.NextIndex()) >= 0) while (auto actor = it.Next())
{ {
int low_dist = 999999, dist; int low_dist = 999999, dist;
sp = User[i]->SpriteP; sp = &actor->s();
u = User[i].Data(); u = actor->u();
tag = sp->lotag; tag = sp->lotag;
@ -1581,11 +1569,11 @@ PlaceActorsOnTracks(void)
} }
} }
NextActorTrackPoint(i); NextActorTrackPoint(actor);
if (Track[u->track].NumPoints == 0) if (Track[u->track].NumPoints == 0)
{ {
Printf("WARNING: Sprite %d (%d, %d) placed on track %d with no points!\n", i, sp->x, sp->y, u->track); Printf("WARNING: Sprite %d (%d, %d) placed on track %d with no points!\n", actor->GetIndex(), sp->x, sp->y, u->track);
continue; continue;
} }
@ -1595,8 +1583,7 @@ PlaceActorsOnTracks(void)
} }
void void MovePlayer(PLAYERp pp, SECTOR_OBJECTp sop, int nx, int ny)
MovePlayer(PLAYERp pp, SECTOR_OBJECTp sop, int nx, int ny)
{ {
void DoPlayerZrange(PLAYERp pp); void DoPlayerZrange(PLAYERp pp);
@ -1671,8 +1658,7 @@ MovePlayer(PLAYERp pp, SECTOR_OBJECTp sop, int nx, int ny)
UpdatePlayerSprite(pp); UpdatePlayerSprite(pp);
} }
void void MovePoints(SECTOR_OBJECTp sop, short delta_ang, int nx, int ny)
MovePoints(SECTOR_OBJECTp sop, short delta_ang, int nx, int ny)
{ {
int j, k; int j, k;
vec2_t rxy; vec2_t rxy;
@ -1896,7 +1882,7 @@ PlayerPart:
//pp->posz -= PLAYER_HEIGHT + Z(12); //pp->posz -= PLAYER_HEIGHT + Z(12);
DoPlayerZrange(pp); DoPlayerZrange(pp);
pp->posz = pp->loz - PLAYER_CRAWL_HEIGHT; pp->posz = pp->loz - PLAYER_CRAWL_HEIGHT;
pp->SpriteP->z = pp->loz; pp->Actor()->s().z = pp->loz;
} }
else else
{ {
@ -1907,7 +1893,7 @@ PlayerPart:
if (!TEST(pp->Flags, PF_JUMPING | PF_FALLING | PF_FLYING)) if (!TEST(pp->Flags, PF_JUMPING | PF_FALLING | PF_FLYING))
{ {
pp->posz = pp->loz - PLAYER_HEIGHT; pp->posz = pp->loz - PLAYER_HEIGHT;
pp->SpriteP->z = pp->loz; pp->Actor()->s().z = pp->loz;
} }
} }
} }
@ -2047,8 +2033,7 @@ void UpdateSectorObjectSprites(SECTOR_OBJECTp sop)
} }
} }
SECTOR_OBJECTp SECTOR_OBJECTp DetectSectorObject(SECTORp sectph)
DetectSectorObject(SECTORp sectph)
{ {
short j; short j;
SECTORp *sectp; SECTORp *sectp;
@ -2072,17 +2057,13 @@ DetectSectorObject(SECTORp sectph)
return nullptr; return nullptr;
} }
SECTOR_OBJECTp SECTOR_OBJECTp DetectSectorObjectByWall(WALLp wph)
DetectSectorObjectByWall(WALLp wph)
{ {
short j, k, startwall, endwall; short j, k, startwall, endwall;
SECTORp *sectp; SECTORp *sectp;
WALLp wp; WALLp wp;
SECTOR_OBJECTp sop; SECTOR_OBJECTp sop;
// if (wph->nextsector >= 0)
// return(DetectSectorObject(&sector[wph->nextsector]));
// collapse the SO to a single point // collapse the SO to a single point
// move all points to nx,ny // move all points to nx,ny
for (sop = SectorObject; sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++) for (sop = SectorObject; sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++)
@ -2115,8 +2096,7 @@ DetectSectorObjectByWall(WALLp wph)
} }
void void CollapseSectorObject(SECTOR_OBJECTp sop, int nx, int ny)
CollapseSectorObject(SECTOR_OBJECTp sop, int nx, int ny)
{ {
short j, k, startwall, endwall; short j, k, startwall, endwall;
SECTORp *sectp; SECTORp *sectp;
@ -2152,8 +2132,7 @@ CollapseSectorObject(SECTOR_OBJECTp sop, int nx, int ny)
} }
void void MoveZ(SECTOR_OBJECTp sop)
MoveZ(SECTOR_OBJECTp sop)
{ {
short i; short i;
SECTORp *sectp; SECTORp *sectp;
@ -2298,8 +2277,7 @@ void CallbackSOsink(ANIMp ap, void *data)
} }
void void MoveSectorObjects(SECTOR_OBJECTp sop, short locktics)
MoveSectorObjects(SECTOR_OBJECTp sop, short locktics)
{ {
int nx, ny; int nx, ny;
short speed; short speed;
@ -2395,9 +2373,7 @@ void DoTrack(SECTOR_OBJECTp sop, short locktics, int *nx, int *ny)
// NOTE: Jittery ride - try new value out here // NOTE: Jittery ride - try new value out here
// NOTE: Put a loop around this (locktics) to make it more acuruate // NOTE: Put a loop around this (locktics) to make it more acuruate
#define TRACK_POINT_SIZE 200 const int TRACK_POINT_SIZE = 200;
//dist = Distance(sop->xmid, sop->ymid, tpoint->x, tpoint->y);
//if (dist < TRACK_POINT_SIZE)
if (sop->target_dist < 100) if (sop->target_dist < 100)
{ {
switch (tpoint->tag_low) switch (tpoint->tag_low)
@ -2726,8 +2702,7 @@ void DoTrack(SECTOR_OBJECTp sop, short locktics, int *nx, int *ny)
} }
void void OperateSectorObjectForTics(SECTOR_OBJECTp sop, short newang, int newx, int newy, short locktics)
OperateSectorObjectForTics(SECTOR_OBJECTp sop, short newang, int newx, int newy, short locktics)
{ {
int i; int i;
SECTORp *sectp; SECTORp *sectp;
@ -2766,14 +2741,12 @@ OperateSectorObjectForTics(SECTOR_OBJECTp sop, short newang, int newx, int newy,
RefreshPoints(sop, newx - sop->xmid, newy - sop->ymid, false); RefreshPoints(sop, newx - sop->xmid, newy - sop->ymid, false);
} }
void void OperateSectorObject(SECTOR_OBJECTp sop, short newang, int newx, int newy)
OperateSectorObject(SECTOR_OBJECTp sop, short newang, int newx, int newy)
{ {
OperateSectorObjectForTics(sop, newang, newx, newy, synctics); OperateSectorObjectForTics(sop, newang, newx, newy, synctics);
} }
void void PlaceSectorObject(SECTOR_OBJECTp sop, int newx, int newy)
PlaceSectorObject(SECTOR_OBJECTp sop, int newx, int newy)
{ {
so_setinterpolationtics(sop, synctics); so_setinterpolationtics(sop, synctics);
RefreshPoints(sop, newx - sop->xmid, newy - sop->ymid, false); RefreshPoints(sop, newx - sop->xmid, newy - sop->ymid, false);
@ -2823,8 +2796,7 @@ void VehicleSetSmoke(SECTOR_OBJECTp sop, ANIMATORp animator)
} }
void void KillSectorObject(SECTOR_OBJECTp sop)
KillSectorObject(SECTOR_OBJECTp sop)
{ {
int newx = MAXSO; int newx = MAXSO;
int newy = MAXSO; int newy = MAXSO;
@ -2874,8 +2846,7 @@ void TornadoSpin(SECTOR_OBJECTp sop)
} }
} }
void void DoTornadoObject(SECTOR_OBJECTp sop)
DoTornadoObject(SECTOR_OBJECTp sop)
{ {
int xvect,yvect; int xvect,yvect;
int cursect; int cursect;
@ -2907,8 +2878,7 @@ DoTornadoObject(SECTOR_OBJECTp sop)
RefreshPoints(sop, pos.x - sop->xmid, pos.y - sop->ymid, true); RefreshPoints(sop, pos.x - sop->xmid, pos.y - sop->ymid, true);
} }
void void DoAutoTurretObject(SECTOR_OBJECTp sop)
DoAutoTurretObject(SECTOR_OBJECTp sop)
{ {
auto actor = sop->sp_child; auto actor = sop->sp_child;
USERp u = actor->u(); USERp u = actor->u();
@ -3003,11 +2973,10 @@ DoAutoTurretObject(SECTOR_OBJECTp sop)
} }
void void DoActorHitTrackEndPoint(DSWActor* actor)
DoActorHitTrackEndPoint(USERp u)
{ {
auto actor = &swActors[u->SpriteNum]; auto u = actor->u();
SPRITEp sp = u->SpriteP; SPRITEp sp = &actor->s();
RESET(Track[u->track].flags, TF_TRACK_OCCUPIED); RESET(Track[u->track].flags, TF_TRACK_OCCUPIED);
@ -3051,10 +3020,9 @@ DoActorHitTrackEndPoint(USERp u)
} }
void void ActorLeaveTrack(DSWActor* actor)
ActorLeaveTrack(short SpriteNum)
{ {
USERp u = User[SpriteNum].Data(); USERp u = actor->u();
if (u->track == -1) if (u->track == -1)
return; return;
@ -3064,24 +3032,12 @@ ActorLeaveTrack(short SpriteNum)
u->track = -1; u->track = -1;
} }
/* bool ActorTrackDecide(TRACK_POINTp tpoint, DSWActor* actor)
ScanToWall
(lsp->x, lsp->y, SPRITEp_TOS(sp) - DIV2(SPRITEp_SIZE_Z(sp)), lsp->sectnum,
-bcos(lsp->ang),
-bsin(lsp->ang),
0,
&hitinfo);
*/
bool
ActorTrackDecide(TRACK_POINTp tpoint, short SpriteNum)
{ {
SPRITEp sp; SPRITEp sp;
auto actor = &swActors[SpriteNum]; USERp u = actor->u();
USERp u = User[SpriteNum].Data();
sp = u->SpriteP; sp = &actor->s();
switch (tpoint->tag_low) switch (tpoint->tag_low)
{ {
@ -3093,7 +3049,7 @@ ActorTrackDecide(TRACK_POINTp tpoint, short SpriteNum)
{ {
if (u->track_dir == -1) if (u->track_dir == -1)
{ {
DoActorHitTrackEndPoint(u); DoActorHitTrackEndPoint(actor);
return false; return false;
} }
} }
@ -3107,7 +3063,7 @@ ActorTrackDecide(TRACK_POINTp tpoint, short SpriteNum)
{ {
if (u->track_dir == 1) if (u->track_dir == 1)
{ {
DoActorHitTrackEndPoint(u); DoActorHitTrackEndPoint(actor);
return false; return false;
} }
} }
@ -3201,7 +3157,7 @@ ActorTrackDecide(TRACK_POINTp tpoint, short SpriteNum)
sp->ang = tpoint->ang; sp->ang = tpoint->ang;
ActorLeaveTrack(SpriteNum); ActorLeaveTrack(actor);
if (tpoint->tag_high) if (tpoint->tag_high)
{ {
@ -3246,7 +3202,7 @@ ActorTrackDecide(TRACK_POINTp tpoint, short SpriteNum)
{ {
sp->ang = tpoint->ang; sp->ang = tpoint->ang;
ActorLeaveTrack(SpriteNum); ActorLeaveTrack(actor);
if (tpoint->tag_high) if (tpoint->tag_high)
{ {
@ -3268,7 +3224,7 @@ ActorTrackDecide(TRACK_POINTp tpoint, short SpriteNum)
if (u->ActorActionSet->Jump) if (u->ActorActionSet->Jump)
{ {
ActorLeaveTrack(SpriteNum); ActorLeaveTrack(actor);
return false; return false;
} }
@ -3280,7 +3236,7 @@ ActorTrackDecide(TRACK_POINTp tpoint, short SpriteNum)
{ {
sp->ang = tpoint->ang; sp->ang = tpoint->ang;
ActorLeaveTrack(SpriteNum); ActorLeaveTrack(actor);
if (!tpoint->tag_high) if (!tpoint->tag_high)
u->WaitTics = 4 * 120; u->WaitTics = 4 * 120;
@ -3531,7 +3487,7 @@ ActorTrackDecide(TRACK_POINTp tpoint, short SpriteNum)
if (!lActor) if (!lActor)
{ {
ActorLeaveTrack(SpriteNum); ActorLeaveTrack(actor);
return false; return false;
} }
lsp = &lActor->s(); lsp = &lActor->s();
@ -3557,7 +3513,7 @@ ActorTrackDecide(TRACK_POINTp tpoint, short SpriteNum)
if (hit_wall < 0) if (hit_wall < 0)
{ {
ActorLeaveTrack(SpriteNum); ActorLeaveTrack(actor);
return false; return false;
} }
@ -3675,11 +3631,11 @@ int ActorFollowTrack(DSWActor* actor, short locktics)
if ((dist = Distance(sp->x, sp->y, tpoint->x, tpoint->y)) < 200) // 64 if ((dist = Distance(sp->x, sp->y, tpoint->x, tpoint->y)) < 200) // 64
{ {
if (!ActorTrackDecide(tpoint, actor->GetSpriteIndex())) if (!ActorTrackDecide(tpoint, actor))
return true; return true;
// get the next point // get the next point
NextActorTrackPoint(actor->GetSpriteIndex()); NextActorTrackPoint(actor);
tpoint = Track[u->track].TrackPoint + u->point; tpoint = Track[u->track].TrackPoint + u->point;
if (!(TEST(u->Flags, SPR_CLIMBING | SPR_DONT_UPDATE_ANG))) if (!(TEST(u->Flags, SPR_CLIMBING | SPR_DONT_UPDATE_ANG)))
@ -3743,7 +3699,7 @@ int ActorFollowTrack(DSWActor* actor, short locktics)
sp->ang = getangle(tpoint->x - sp->x, tpoint->y - sp->y); sp->ang = getangle(tpoint->x - sp->x, tpoint->y - sp->y);
ActorLeaveTrack(actor->GetSpriteIndex()); ActorLeaveTrack(actor);
RESET(sp->cstat, CSTAT_SPRITE_YCENTER); RESET(sp->cstat, CSTAT_SPRITE_YCENTER);
sp->z += u->sy; sp->z += u->sy;
@ -3774,7 +3730,7 @@ int ActorFollowTrack(DSWActor* actor, short locktics)
if (u->coll.type != kHitNone) if (u->coll.type != kHitNone)
{ {
if (!TEST(u->Flags, SPR_JUMPING|SPR_FALLING)) if (!TEST(u->Flags, SPR_JUMPING|SPR_FALLING))
ActorLeaveTrack(actor->GetSpriteIndex()); ActorLeaveTrack(actor);
} }

View file

@ -5242,7 +5242,7 @@ int ActorPain(DSWActor* actor)
{ {
if (u->ActorActionSet && u->ActorActionSet->Pain) if (u->ActorActionSet && u->ActorActionSet->Pain)
{ {
ActorLeaveTrack(actor->GetSpriteIndex()); ActorLeaveTrack(actor);
u->WaitTics = 60; u->WaitTics = 60;
NewStateGroup(actor, u->ActorActionSet->Pain); NewStateGroup(actor, u->ActorActionSet->Pain);
return true; return true;