Skip to content

Commit 5d43c42

Browse files
authored
Custom logics - collision properties and trooper alert sounds (#585)
* More custom logic options - allow usage of the officer and trooper alert sounds * Refactor - give correct names to CollisionInfo variables stepUpHeight (formerly botOffset) stepDownHeight (formerly yPos) Rename ACTORCOL_BIT2 to ACTORCOL_SLIDE_RESPONSE * Allow setting of step heights for custom logics * Allow changing of the collision slide response flag
1 parent aacc1f7 commit 5d43c42

20 files changed

Lines changed: 142 additions & 69 deletions

TheForceEngine/TFE_DarkForces/Actor/actor.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ namespace TFE_DarkForces
442442
{
443443
angle14_32 rAngle = moveMod->physics.responseAngle + (s_curTick & 0xff) - 128;
444444
angle14_32 angleDiff = getAngleDifference(obj->yaw, rAngle) & 8191;
445-
if (angleDiff > 4095)
445+
if (angleDiff > 4095) // 90 degrees
446446
{
447-
newAngle = moveMod->physics.responseAngle - 8191;
447+
newAngle = moveMod->physics.responseAngle - 8191; // 180 degrees
448448
}
449449
else
450450
{
@@ -632,7 +632,7 @@ namespace TFE_DarkForces
632632
{
633633
item, // obj
634634
FIXED(2), 0, FIXED(2), // offset
635-
ONE_16, COL_INFINITY, ONE_16, 0, // botOffset, yPos, height, u1c
635+
ONE_16, COL_INFINITY, ONE_16, 0, // stepUpHeight, stepDownHeight, height, u1c
636636
nullptr, 0, nullptr,
637637
item->worldWidth, 0,
638638
JFALSE,
@@ -1427,6 +1427,7 @@ namespace TFE_DarkForces
14271427
vec3_fixed desiredMove = { 0, 0, 0 };
14281428
vec3_fixed move = { 0, 0, 0 };
14291429

1430+
// First, handle active movement - movement that the actor "intends" to do
14301431
moveMod->collisionWall = nullptr;
14311432
if (!(moveMod->target.flags & TARGET_FREEZE))
14321433
{
@@ -1494,11 +1495,11 @@ namespace TFE_DarkForces
14941495
RSector* triggerSector = (nextSector) ? nextSector : wall->sector;
14951496
if (obj->entityFlags & ETFLAG_SMART_OBJ)
14961497
{
1497-
message_sendToSector(triggerSector, obj, 0, MSG_TRIGGER);
1498+
message_sendToSector(triggerSector, obj, 0, MSG_TRIGGER); // smart object will try to open a door or activate an elevator that it collides with
14981499
}
14991500
}
15001501
// Handles a single collision response + resolution step.
1501-
if (moveMod->collisionFlags & ACTORCOL_BIT2)
1502+
if (moveMod->collisionFlags & ACTORCOL_SLIDE_RESPONSE)
15021503
{
15031504
moveMod->collisionWall = wall;
15041505
dirX = physics->responseDir.x;
@@ -1509,17 +1510,18 @@ namespace TFE_DarkForces
15091510
}
15101511
}
15111512

1513+
// Now handle passive movement - movement caused by being pushed, eg. by explosions or projectile impacts
15121514
// Apply the per-frame delta computed from the actor's velocity.
15131515
if (moveMod->delta.x | moveMod->delta.z)
15141516
{
1515-
physics->flags |= 1;
1517+
physics->flags |= COLINFO_INFINITE_DROP; // actor can be pushed off a cliff
15161518
physics->offsetX = moveMod->delta.x;
15171519
physics->offsetY = 0;
15181520
physics->offsetZ = moveMod->delta.z;
15191521
handleCollision(physics);
15201522

15211523
// Handles a single collision response + resolution step from velocity delta.
1522-
if ((moveMod->collisionFlags & ACTORCOL_BIT2) && physics->responseStep)
1524+
if ((moveMod->collisionFlags & ACTORCOL_SLIDE_RESPONSE) && physics->responseStep)
15231525
{
15241526
moveMod->collisionWall = physics->wall;
15251527
dirX = physics->responseDir.x;
@@ -1649,8 +1651,8 @@ namespace TFE_DarkForces
16491651
{
16501652
SecObject* obj = moveMod->header.obj;
16511653

1652-
moveMod->physics.botOffset = 0x38000; // 3.5
1653-
moveMod->physics.yPos = FIXED(4);
1654+
moveMod->physics.stepUpHeight = 0x38000; // 3.5 units
1655+
moveMod->physics.stepDownHeight = FIXED(4); // 4 units
16541656
moveMod->physics.height = obj->worldHeight;
16551657
moveMod->physics.width = obj->worldWidth;
16561658
moveMod->physics.responseStep = JFALSE;
@@ -1662,7 +1664,7 @@ namespace TFE_DarkForces
16621664
moveMod->collisionWall = nullptr;
16631665
moveMod->unused = 0;
16641666

1665-
moveMod->collisionFlags = (moveMod->collisionFlags | (ACTORCOL_NO_Y_MOVE | ACTORCOL_GRAVITY)) & ~ACTORCOL_BIT2; // Set bits 0, 1 and clear bit 2. This creates a non-flying AI by default.
1667+
moveMod->collisionFlags = (moveMod->collisionFlags | (ACTORCOL_NO_Y_MOVE | ACTORCOL_GRAVITY)) & ~ACTORCOL_SLIDE_RESPONSE; // Set bits 0, 1 and clear bit 2. This creates a non-flying AI by default.
16661668
obj->entityFlags |= ETFLAG_SMART_OBJ;
16671669
}
16681670

@@ -2013,7 +2015,7 @@ namespace TFE_DarkForces
20132015
{
20142016
dispatch->alertSndID = sound_playCued(s_officerAlertSndSrc[s_actorState.officerAlertIndex], obj->posWS);
20152017
s_actorState.officerAlertIndex++;
2016-
if (s_actorState.officerAlertIndex >= 4)
2018+
if (s_actorState.officerAlertIndex >= OFFICER_ALERT_COUNT)
20172019
{
20182020
s_actorState.officerAlertIndex = 0;
20192021
}
@@ -2022,7 +2024,7 @@ namespace TFE_DarkForces
20222024
{
20232025
dispatch->alertSndID = sound_playCued(s_stormAlertSndSrc[s_actorState.stormtrooperAlertIndex], obj->posWS);
20242026
s_actorState.stormtrooperAlertIndex++;
2025-
if (s_actorState.stormtrooperAlertIndex >= 8)
2027+
if (s_actorState.stormtrooperAlertIndex >= STORM_ALERT_COUNT)
20262028
{
20272029
s_actorState.stormtrooperAlertIndex = 0;
20282030
}

TheForceEngine/TFE_DarkForces/Actor/actorModule.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ enum AttackFlags
109109

110110
enum ActorCollisionFlags
111111
{
112-
ACTORCOL_NO_Y_MOVE = FLAG_BIT(0), // When _not_ set, an actor can move vertically. Set for non-flying enemies.
113-
ACTORCOL_GRAVITY = FLAG_BIT(1),
114-
ACTORCOL_BIT2 = FLAG_BIT(2), // Alters the way collision is handled. This is generally set for flying enemies and bosses
115-
ACTORCOL_ALL = ACTORCOL_NO_Y_MOVE | ACTORCOL_GRAVITY | ACTORCOL_BIT2
112+
ACTORCOL_NO_Y_MOVE = FLAG_BIT(0), // When _not_ set, an actor can move vertically. Set for non-flying enemies.
113+
ACTORCOL_GRAVITY = FLAG_BIT(1),
114+
ACTORCOL_SLIDE_RESPONSE = FLAG_BIT(2), // Actor will "slide" along a wall that they collide with. This is generally set for flying enemies and bosses.
115+
ACTORCOL_ALL = ACTORCOL_NO_Y_MOVE | ACTORCOL_GRAVITY | ACTORCOL_SLIDE_RESPONSE
116116
};
117117

118118
struct ActorModule

TheForceEngine/TFE_DarkForces/Actor/actorSerialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ namespace TFE_DarkForces
191191
SERIALIZE(SaveVersionInit, colInfo->offsetX, 0);
192192
SERIALIZE(SaveVersionInit, colInfo->offsetY, 0);
193193
SERIALIZE(SaveVersionInit, colInfo->offsetZ, 0);
194-
SERIALIZE(SaveVersionInit, colInfo->botOffset, 0);
195-
SERIALIZE(SaveVersionInit, colInfo->yPos, 0);
194+
SERIALIZE(SaveVersionInit, colInfo->stepUpHeight, 0);
195+
SERIALIZE(SaveVersionInit, colInfo->stepDownHeight, 0);
196196
SERIALIZE(SaveVersionInit, colInfo->height, 0);
197197
SERIALIZE(SaveVersionInit, colInfo->u24, 0);
198198
SERIALIZE(SaveVersionInit, colInfo->width, 0);

TheForceEngine/TFE_DarkForces/Actor/bobaFett.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ namespace TFE_DarkForces
671671
local(nextCheckForPlayerTick) = 0;
672672
local(changeStateTick) = s_curTick + SEARCH_DURATION;
673673
local(nextChangePhaseTick) = s_curTick + SEARCH_PHASE_INTERVAL;
674-
local(physicsActor)->moveMod.collisionFlags |= ACTORCOL_BIT2;
674+
local(physicsActor)->moveMod.collisionFlags |= ACTORCOL_SLIDE_RESPONSE;
675675

676676
while (local(physicsActor)->state == BOBASTATE_SEARCH)
677677
{
@@ -723,7 +723,7 @@ namespace TFE_DarkForces
723723
}
724724
} // while (state == BOBASTATE_SEARCH)
725725

726-
local(physicsActor)->moveMod.collisionFlags |= ACTORCOL_BIT2;
726+
local(physicsActor)->moveMod.collisionFlags |= ACTORCOL_SLIDE_RESPONSE;
727727
task_end;
728728
}
729729

@@ -955,11 +955,11 @@ namespace TFE_DarkForces
955955
actor_setupSmartObj(&physicsActor->moveMod);
956956

957957
physicsActor->moveMod.physics.width = FIXED(2);
958-
physicsActor->moveMod.physics.botOffset = 0;
958+
physicsActor->moveMod.physics.stepUpHeight = 0;
959959

960960
physicsActor->moveMod.collisionFlags &= ~ACTORCOL_ALL;
961-
physicsActor->moveMod.collisionFlags |= (ACTORCOL_GRAVITY | ACTORCOL_BIT2);
962-
physicsActor->moveMod.physics.yPos = COL_INFINITY;
961+
physicsActor->moveMod.collisionFlags |= (ACTORCOL_GRAVITY | ACTORCOL_SLIDE_RESPONSE);
962+
physicsActor->moveMod.physics.stepDownHeight = COL_INFINITY;
963963
physicsActor->moveMod.physics.height = obj->worldHeight;
964964

965965
LogicAnimation* anim = &physicsActor->anim;
@@ -981,4 +981,4 @@ namespace TFE_DarkForces
981981
}
982982
return (Logic*)bobaFett;
983983
}
984-
} // namespace TFE_DarkForces
984+
} // namespace TFE_DarkForces

TheForceEngine/TFE_DarkForces/Actor/dragon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,8 +1102,8 @@ namespace TFE_DarkForces
11021102
obj->flags |= OBJ_FLAG_MOVABLE;
11031103

11041104
CollisionInfo* physics = &physicsActor->moveMod.physics;
1105-
physics->botOffset = 0x60000;
1106-
physics->yPos = 0x80000;
1105+
physics->stepUpHeight = 0x60000; // 6 units
1106+
physics->stepDownHeight = 0x80000; // 8 units
11071107
physics->width = obj->worldWidth;
11081108
physicsActor->moveMod.collisionFlags |= ACTORCOL_ALL;
11091109
physics->height = obj->worldHeight + HALF_16;

TheForceEngine/TFE_DarkForces/Actor/enemies.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ namespace TFE_DarkForces
193193
dispatch->fov = floatToAngle((f32)cust->fov);
194194
dispatch->awareRange = FIXED(cust->awareRange);
195195

196+
if (cust->officerAlerts)
197+
{
198+
dispatch->flags |= ACTOR_OFFIC_ALERT;
199+
}
200+
if (cust->troopAlerts)
201+
{
202+
dispatch->flags |= ACTOR_TROOP_ALERT;
203+
}
204+
196205
// Damage Module
197206
DamageModule* damageMod = actor_createDamageModule(dispatch);
198207
damageMod->hp = FIXED(cust->hitPoints);
@@ -253,17 +262,28 @@ namespace TFE_DarkForces
253262
dispatch->moveMod = moveMod;
254263
moveMod->physics.width = cust->collisionWidth < 0 ? obj->worldWidth : floatToFixed16(cust->collisionWidth);
255264
moveMod->physics.height = cust->collisionHeight < 0 ? moveMod->physics.height : floatToFixed16(cust->collisionHeight);
265+
moveMod->physics.stepUpHeight = floatToFixed16(cust->stepUpHeight);
266+
moveMod->physics.stepDownHeight = floatToFixed16(cust->stepDownHeight);
256267

257268
if (cust->isFlying)
258269
{
259-
moveMod->collisionFlags = (moveMod->collisionFlags & ~ACTORCOL_ALL) | ACTORCOL_BIT2; // Remove bits 0, 1 and set bit 2
260-
moveMod->physics.yPos = FIXED(200);
270+
moveMod->collisionFlags = (moveMod->collisionFlags & ~ACTORCOL_ALL) | ACTORCOL_SLIDE_RESPONSE; // Remove bits 0, 1 and set bit 2
271+
moveMod->physics.stepDownHeight = FIXED(200);
261272
}
262273
else
263274
{
264275
moveMod->collisionFlags |= ACTORCOL_NO_Y_MOVE;
265276
}
266277

278+
if (cust->slideOnCollision == 0)
279+
{
280+
moveMod->collisionFlags &= ~ACTORCOL_SLIDE_RESPONSE;
281+
}
282+
else if (cust->slideOnCollision == 1)
283+
{
284+
moveMod->collisionFlags |= ACTORCOL_SLIDE_RESPONSE;
285+
}
286+
267287
dispatch->animTable = s_customAnimTable;
268288
actor_setupInitAnimation();
269289

TheForceEngine/TFE_DarkForces/Actor/exploders.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ namespace TFE_DarkForces
104104
colInfo.offsetY = 0;
105105
colInfo.offsetX = mul16(actorLogic->vel.x, 0x4000);
106106
colInfo.offsetZ = mul16(actorLogic->vel.z, 0x4000);
107-
colInfo.botOffset = ONE_16;
108-
colInfo.yPos = COL_INFINITY;
107+
colInfo.stepUpHeight = ONE_16;
108+
colInfo.stepDownHeight = COL_INFINITY;
109109
colInfo.height = ONE_16;
110110
colInfo.unused = 0;
111111
colInfo.width = colInfo.obj->worldWidth;

TheForceEngine/TFE_DarkForces/Actor/flyers.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ namespace TFE_DarkForces
159159

160160
MovementModule* moveMod = actor_createMovementModule(dispatch);
161161
dispatch->moveMod = moveMod;
162-
moveMod->collisionFlags = (moveMod->collisionFlags & ~ACTORCOL_ALL) | ACTORCOL_BIT2;
163-
moveMod->physics.yPos = FIXED(200);
162+
moveMod->collisionFlags = (moveMod->collisionFlags & ~ACTORCOL_ALL) | ACTORCOL_SLIDE_RESPONSE;
163+
moveMod->physics.stepDownHeight = FIXED(200);
164164
moveMod->physics.width = obj->worldWidth;
165165

166166
// Setup the animation.
@@ -209,8 +209,8 @@ namespace TFE_DarkForces
209209

210210
MovementModule* moveMod = actor_createMovementModule(dispatch);
211211
dispatch->moveMod = moveMod;
212-
moveMod->collisionFlags = (moveMod->collisionFlags & ~ACTORCOL_ALL) | ACTORCOL_BIT2;
213-
moveMod->physics.yPos = FIXED(200);
212+
moveMod->collisionFlags = (moveMod->collisionFlags & ~ACTORCOL_ALL) | ACTORCOL_SLIDE_RESPONSE;
213+
moveMod->physics.stepDownHeight = FIXED(200);
214214
moveMod->physics.width = obj->worldWidth;
215215

216216
// Setup the animation.
@@ -264,8 +264,8 @@ namespace TFE_DarkForces
264264
MovementModule* moveMod = actor_createMovementModule(dispatch);
265265
dispatch->moveMod = moveMod;
266266
moveMod->collisionFlags &= ~ACTORCOL_ALL;
267-
moveMod->collisionFlags |= ACTORCOL_BIT2;
268-
moveMod->physics.yPos = FIXED(200);
267+
moveMod->collisionFlags |= ACTORCOL_SLIDE_RESPONSE;
268+
moveMod->physics.stepDownHeight = FIXED(200);
269269

270270
// should be: 0xa7ec
271271
moveMod->physics.width = obj->worldWidth;

TheForceEngine/TFE_DarkForces/Actor/mousebot.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ namespace TFE_DarkForces
487487
obj->worldWidth = width;
488488
obj->worldHeight = width >> 1;
489489

490-
physActor->moveMod.physics.botOffset = 0;
491-
physActor->moveMod.physics.yPos = 0;
492-
physActor->moveMod.collisionFlags = (physActor->moveMod.collisionFlags | (ACTORCOL_NO_Y_MOVE | ACTORCOL_GRAVITY)) & ~ACTORCOL_BIT2;
490+
physActor->moveMod.physics.stepUpHeight = 0;
491+
physActor->moveMod.physics.stepDownHeight = 0;
492+
physActor->moveMod.collisionFlags = (physActor->moveMod.collisionFlags | (ACTORCOL_NO_Y_MOVE | ACTORCOL_GRAVITY)) & ~ACTORCOL_SLIDE_RESPONSE;
493493
physActor->moveMod.physics.height = obj->worldHeight + HALF_16;
494494
physActor->moveMod.target.speed = FIXED(22);
495495
physActor->moveMod.target.speedRotation = FIXED(3185);

TheForceEngine/TFE_DarkForces/Actor/phaseOne.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ namespace TFE_DarkForces
941941
actor_setupSmartObj(&physicsActor->moveMod);
942942

943943
physicsActor->moveMod.collisionFlags |= ACTORCOL_NO_Y_MOVE | ACTORCOL_GRAVITY;
944-
physicsActor->moveMod.collisionFlags &= ~ACTORCOL_BIT2;
944+
physicsActor->moveMod.collisionFlags &= ~ACTORCOL_SLIDE_RESPONSE;
945945

946946
ActorTarget* target = &physicsActor->moveMod.target;
947947
target->flags &= ~TARGET_ALL;

0 commit comments

Comments
 (0)