Skip to content

Commit 0fb73df

Browse files
committed
BSPC: implement jumppad snapping
i don't yet fully understand the purpose - but that's how it was found in the binary
1 parent a4b643c commit 0fb73df

1 file changed

Lines changed: 43 additions & 3 deletions

File tree

code/tools/bspc/rch_load.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,47 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5656
#define RCH_YXML_BUF_SIZE 4096
5757
#define RCH_CONTENT_BUF_SIZE 64
5858

59-
// traveltype for jumppad (TRAVEL_JUMPPAD in be_aas_reach.c)
60-
#define TRAVEL_JUMPPAD 0x12
61-
6259
extern int AAS_PointAreaNum(vec3_t point);
6360
extern int AAS_NextBSPEntity(int ent);
6461
extern int AAS_ValueForBSPEpairKey(int ent, char *key, char *value, int size);
62+
extern int AAS_VectorForBSPEpairKey(int ent, const char *key, vec3_t v);
63+
64+
// For jumppad reachabilities (traveltype 0x12), snap the start position
65+
// to the nearest trigger_push entity origin, matching the binary behavior.
66+
static void RCH_SnapToJumppad(aas_reachability_t *reach) {
67+
int ent;
68+
char classname[128];
69+
vec3_t origin;
70+
float bestdist = 99999.0f;
71+
int bestent = 0;
72+
73+
for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent)) {
74+
if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, sizeof(classname)))
75+
continue;
76+
if (strcmp(classname, "trigger_push") != 0)
77+
continue;
78+
if (!AAS_VectorForBSPEpairKey(ent, "origin", origin))
79+
continue;
80+
81+
float dx = origin[0] - reach->start[0];
82+
float dy = origin[1] - reach->start[1];
83+
float dz = origin[2] - reach->start[2];
84+
float dist = (float)sqrt(dx * dx + dy * dy + dz * dz);
85+
if (dist < bestdist) {
86+
bestdist = dist;
87+
bestent = ent;
88+
}
89+
}
90+
91+
if (bestent) {
92+
AAS_VectorForBSPEpairKey(bestent, "origin", origin);
93+
VectorCopy(origin, reach->start);
94+
Log_Print(" snapped jumppad reach to trigger_push at (%.1f %.1f %.1f), dist=%.1f\n",
95+
origin[0], origin[1], origin[2], bestdist);
96+
} else {
97+
Log_Print("WARNING: no trigger_push found for jumppad reachability\n");
98+
}
99+
}
65100

66101
// Temporary linked-list node for parsed reachabilities
67102
typedef struct rch_reach_s {
@@ -117,6 +152,11 @@ static void RCH_FinalizeReach(rch_state_t *state) {
117152
if (!r)
118153
return;
119154

155+
// For jumppad reachabilities, snap start to nearest trigger_push
156+
if (r->reach.traveltype == TRAVEL_JUMPPAD) {
157+
RCH_SnapToJumppad(&r->reach);
158+
}
159+
120160
// Resolve areanum from start position (overrides XML areanum)
121161
r->reach.areanum = AAS_PointAreaNum(r->reach.start);
122162

0 commit comments

Comments
 (0)