-
Notifications
You must be signed in to change notification settings - Fork 29
/
gsc_car.cpp
executable file
·192 lines (142 loc) · 4.14 KB
/
gsc_car.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "gsc_car.hpp"
#if COMPILE_CAR == 0
#warning gsc_car.cpp is not compiled
#else
// /root/q3rally/q3rallysa/engine/code/game
// -I/root/q3rally/q3rallysa/
extern "C"
{
#include "engine/code/qcommon/q_shared.h"
#include "engine/code/game/bg_public.h"
#include "engine/code/game/bg_local.h"
}
#define DEBUG_CAR 1
void my_trace(trace_t *results, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int passEntityNum, int contentMask)
{
results->startsolid = qfalse;
results->allsolid = qfalse;
// needed: fraction, plane(plane.normal), endpos, surfaceFlags
//trace 0 00000000
//printf("trace %d %.8x\n", passEntityNum, contentMask);
}
qboolean G_FrictionCalc_(const carPoint_t *point, float *sCOF, float *kCOF)
{
return qfalse;
}
int CG_PointContents_(const vec3_t point, int passEntityNum)
{
return 0;
}
void init_pm()
{
pm = (pmove_t *) malloc(sizeof(pmove_t));
memset(pm, 0, sizeof(pmove_t));
pm->ps = (playerState_t *) malloc(sizeof(playerState_t));
memset(pm->ps, 0, sizeof(playerState_t));
pm->ps->gravity = 800;
pm->ps->viewangles[PITCH] = 0;
pm->ps->viewangles[YAW] = 0;
pm->ps->viewangles[ROLL] = 0;
pm->ps->damageYaw = 0;
pm->ps->damagePitch = 0;
//pm->ps->damageRoll = 0;
pm->ps->extra_eFlags = 0;
//pm->cmd = (usercmd_t *) malloc(sizeof(usercmd_t));
pm->cmd.upmove = 100.0;
pm->cmd.forwardmove = 100.0;
pm->cmd.upmove = 100.0;
pm->ps->stats[STAT_HEALTH] = 100;
pm->manualShift = qfalse;
pm->controlMode = CT_MOUSE;
pm->car_frontweight_dist = 0.5;
pm->car_body_elasticity = 0.05;
pm->car_IT_xScale = 1.0;
pm->car_IT_yScale = 1.0;
pm->car_IT_zScale = 1.0;
pm->car_swaybar = 20;
pm->car_shock_up = 12;
pm->car_shock_down = 11;
pm->car_wheel = 2400;
pm->car_wheel_damp = 140;
pm->car_friction_scale = 1.10;
pm->trace = my_trace;
pm->frictionFunc = G_FrictionCalc_;
pm->pointcontents = CG_PointContents_;
pm->pDebug = 1;
}
int gsc_car_new()
{
float origin[3];
float viewangles[3];
float velocity[3];
static int first = 1;
if (first)
{
printf("init_pm();\n");
init_pm();
first = 0;
}
int helper = 0;
helper += stackGetParamVector(1, origin);
helper += stackGetParamVector(2, viewangles);
helper += stackGetParamVector(3, velocity);
#if DEBUG_CAR
printf("gsc_car_new(origin=(%.2f,%.2f,%.2f), viewangles=(%.2f,%.2f,%.2f), velocity(%.2f,%.2f,%.2f))\n",
origin[0], origin[1], origin[2],
viewangles[0], viewangles[1], viewangles[2],
velocity[0], velocity[1], velocity[2]
);
#endif
if (helper != 3)
{
printf("scriptengine> wrongs args for gsc_car_new(origin, viewangles, velocity)\n");
return stackPushUndefined();
}
car_t *car = (car_t *) malloc(sizeof(car_t));
/*
vec3_t origin = {100,100,100};
vec3_t angles = {100,100,100};
vec3_t velocity = {0,0,10};
*/
// instead of calling it myself, let PM_DriveMove do it
//PM_InitializeVehicle(&car, origin, angles, velocity);
//printf("car.initializeOnNextMove = %d\n", car.initializeOnNextMove);
VectorCopy(origin, pm->ps->origin);
VectorCopy(viewangles, pm->ps->viewangles);
VectorCopy(velocity, pm->ps->velocity);
/*VectorCopy(pm->ps->origin, origin);
VectorCopy(pm->ps->viewangles, angles);
VectorCopy(pm->ps->velocity, velocity);*/
car->initializeOnNextMove = qtrue;
// initialize it the first time (maybe i shall call it myself to prevent the first run)
PM_DriveMove(car, 0.20, qfalse); // includeBodies
int ret = (int) car;
return stackReturnInt(ret);
}
extern "C" void PM_DebugDynamics(carBody_t *body, carPoint_t *points);
int gsc_car_update()
{
int car_address;
int helper = 0;
helper += stackGetParamInt(1, &car_address);
#if DEBUG_CAR
printf("gsc_car_update(car=%d)\n", car_address);
#endif
if (helper != 1)
{
printf("scriptengine> wrongs args for gsc_car_update(car)\n");
return stackPushUndefined();
}
car_t *car = (car_t *) car_address;
PM_DriveMove(car, 0.05, qfalse); // includeBodies
PM_DebugDynamics(&(car->tBody), &(car->tPoints[0]));
int ret = stackPushArray();
// ret[0] = origin
stackPushVector(car->tBody.r);
stackPushArrayLast();
// ret[1] = forward
stackPushVector(car->tBody.forward);
stackPushArrayLast();
return ret;
}
#endif