- MAX_CARS everywhere, add CAMERA_COLLIDER_CARID and TANNER_COLLIDER_CARID

- fix mistakes
This commit is contained in:
Ilya Shurumov 2020-10-20 16:17:12 +06:00
parent 3304fc1adb
commit c33dc9c78b
20 changed files with 64 additions and 56 deletions

View File

@ -222,7 +222,8 @@ void HandleThrownBombs(void)
}
cp = car_data;
while (cp < car_data + 20)
while (cp < &car_data[MAX_CARS])
{
if (cp != gBombTargetVehicle && cp->controlType != CONTROL_TYPE_NONE && BombCollisionCheck(cp, &bomb->position) != 0)
{
@ -633,11 +634,10 @@ void ExplosionCollisionCheck(_CAR_DATA *cp, _ExOBJECT *pE)
long reaction[4];
long lever[4];
isCar = (cp != car_data + 20);
isCar = (cp != &car_data[CAMERA_COLLIDER_CARID]);
if (player[0].playerType == 2 || isCar)
{
cd[1].x.vx = cp->hd.where.t[0];
cd[1].length[0] = car_cosmetics[cp->ap.model].colBox.vz;
cd[1].length[1] = car_cosmetics[cp->ap.model].colBox.vx;

View File

@ -710,7 +710,7 @@ void PlaceCameraFollowCar(_PLAYER *lp)
}
}
jcam = &car_data[20];
jcam = &car_data[CAMERA_COLLIDER_CARID];
ClearMem((char *)jcam, sizeof(_CAR_DATA));
jcam->controlType = CONTROL_TYPE_CAMERACOLLIDER;
@ -937,7 +937,7 @@ void PlaceCameraInCar(_PLAYER *lp, int BumperCam)
cp = NULL;
if (lp->cameraCarId > -1)
cp = car_data + lp->cameraCarId;
cp = &car_data[lp->cameraCarId];
viewer_position.vx = 0;

View File

@ -1,6 +1,8 @@
#ifndef CAMERA_H
#define CAMERA_H
#define CAMERA_COLLIDER_CARID (MAX_CARS+1)
extern VECTOR camera_position;
extern char old_camera_change;
extern char camera_change;

View File

@ -1783,7 +1783,7 @@ int CheckChangeLanes(DRIVER2_STRAIGHT* straight, DRIVER2_CURVE* curve, int distA
cd[0].length[1] = cp->ap.carCos->colBox.vx;
cd[0].theta = cp->hd.direction;
lcp = car_data + MAX_CARS-1;
lcp = &car_data[MAX_CARS-1];
while (lcp >= car_data)
{
@ -2964,7 +2964,7 @@ int CreateCivCarWotDrivesABitThenStops(int direction, long(*startPos)[4], long(*
carCnt++;
slot++;
} while (carCnt < car_data + MAX_TRAFFIC_CARS);
} while (carCnt < &car_data[MAX_TRAFFIC_CARS]);
if (pNewCar == NULL)
return -1;
@ -3102,7 +3102,7 @@ int CreateStationaryCivCar(int direction, long orientX, long orientZ, long(*star
carCnt++;
slot++;
} while (carCnt < car_data + MAX_TRAFFIC_CARS);
} while (carCnt < &car_data[MAX_TRAFFIC_CARS]);
}
if (newCar)
@ -3468,7 +3468,7 @@ int PingInCivCar(int minPingInDist)
carCnt++;
slot++;
} while (carCnt < car_data + MAX_TRAFFIC_CARS);
} while (carCnt < &car_data[MAX_TRAFFIC_CARS]);
if (newCar == NULL)
{
@ -3820,7 +3820,7 @@ int PingInCivCar(int minPingInDist)
count = 0;
carCnt = car_data;
while (carCnt < car_data + MAX_CARS)
while (carCnt < &car_data[MAX_CARS])
{
if (carCnt->controlType != CONTROL_TYPE_NONE)
{
@ -4439,7 +4439,7 @@ int CivAccelTrafficRules(_CAR_DATA * cp, int* distToNode)
carDir = cp->hd.direction & 0xfff;
distToObstacle = 0x7fffff;
lcp = car_data + 19;
lcp = &car_data[MAX_CARS-1];
while (lcp >= car_data)
{
if (lcp->ai.c.thrustState != 3 && lcp != cp && lcp->controlType != CONTROL_TYPE_NONE)
@ -4639,7 +4639,7 @@ int CivAccelTrafficRules(_CAR_DATA * cp, int* distToNode)
/* WARNING: Removing unreachable block (ram,0x0002b034) */
/* WARNING: Unknown calling convention yet parameter storage is locked */
int brakeLength[20];
int brakeLength[MAX_CARS];
int CAR_PAUSE_START = 100;
static _CAR_DATA(*horncarflag[2]) = { 0 };
@ -4663,7 +4663,7 @@ void SetUpCivCollFlags(void)
ClearMem((char*)brakeLength, sizeof(brakeLength));
cp0 = car_data + MAX_CARS - 1;
cp0 = &car_data[MAX_CARS - 1];
while (cp0 >= car_data)
{
@ -4696,7 +4696,7 @@ void SetUpCivCollFlags(void)
gte_rtv0tr();
gte_stlvnl(&cd[0].x);
cp1 = car_data + MAX_CARS;
cp1 = &car_data[MAX_CARS];
while (cp1 >= car_data)
{
@ -4704,7 +4704,7 @@ void SetUpCivCollFlags(void)
{
car_cos = cp1->ap.carCos;
if (CAR_INDEX(cp1) == 20)
if (CAR_INDEX(cp1) == TANNER_COLLIDER_CARID)
{
if (player[0].playerType != 2)
{
@ -4760,7 +4760,7 @@ void SetUpCivCollFlags(void)
}
// check height difference
if (CAR_INDEX(cp1) == 20)
if (CAR_INDEX(cp1) == CAMERA_COLLIDER_CARID)
{
if (ABS(player[0].pos[1] - cp0->hd.where.t[1]) >= 500)
{
@ -4796,14 +4796,14 @@ void SetUpCivCollFlags(void)
continue;
}
if (CAR_INDEX(cp1) == 20)
if (CAR_INDEX(cp1) == TANNER_COLLIDER_CARID)
cp0->ai.c.carPauseCnt = CAR_PAUSE_START;
// do horns
// horn to player and chased cars (except Steal the Ambulance)
if (cp0->ai.c.thrustState != 3 &&
(cp1->controlType == CONTROL_TYPE_PLAYER || cp1->controlType == CONTROL_TYPE_CUTSCENE && gCurrentMissionNumber != 26 && ProxyBar.active == 0 ||
CAR_INDEX(cp1) == 20))
CAR_INDEX(cp1) == TANNER_COLLIDER_CARID))
{
int dont;
int rnd;
@ -6024,7 +6024,7 @@ void CreateRoadblock(void)
PingOutCar(newCar);
}
cp = car_data + MAX_CARS - 1;
cp = &car_data[MAX_CARS - 1];
do {
if (cp->controlType != CONTROL_TYPE_NONE && !IS_ROADBLOCK_CAR(cp))
{
@ -6101,7 +6101,7 @@ void CreateRoadblock(void)
PingOutCar(newCar);
}
cp = car_data + MAX_CARS - 1;
cp = &car_data[MAX_CARS - 1];
do {
if (cp->controlType != CONTROL_TYPE_NONE && !IS_ROADBLOCK_CAR(cp))
{

View File

@ -421,7 +421,7 @@ void ControlCops(void)
else
{
if (player[0].playerCarId > -1)
targetVehicle = car_data + player[0].playerCarId;
targetVehicle = &car_data[player[0].playerCarId];
if (player_position_known > 0)
{
@ -1872,7 +1872,7 @@ void ControlNumberOfCops(void)
}
}
lcp++;
} while (lcp < car_data + MAX_CARS);
} while (lcp < &car_data[MAX_CARS]);
gCopData.cutOffDistance = cutOffDistance;
} while (numWantedCops < num_closer);

View File

@ -2860,7 +2860,7 @@ int SelectCameraCar(int current)
return 0;
if (current < -1)
current = 18 - current;
current = (MAX_CARS - 2) - current;
count = current + 1;
@ -2896,7 +2896,7 @@ int SelectCameraCar(int current)
}
else
{
event = events.track[count - 20];
event = events.track[count - MAX_CARS];
if (event == NULL)
{
@ -2923,7 +2923,7 @@ int SelectCameraCar(int current)
if (car != NULL)
return car->id;
return 18 - count;
return (MAX_CARS - 2) - count;
}
}

View File

@ -1633,19 +1633,21 @@ int num_cars_drawn = 0;
// [D] [T]
void DrawAllTheCars(int view)
{
static int car_distance[20]; // offset 0x0
static int car_distance[MAX_CARS]; // offset 0x0
_CAR_DATA* cars_to_draw[MAX_CARS];
int dx, dz;
int dist;
int i, j;
_CAR_DATA* cp;
int num_cars_to_draw;
int spacefree;
_CAR_DATA* cars_to_draw[20];
num_cars_drawn = 0;
num_cars_to_draw = 0;
cp = car_data + MAX_CARS - 1;
cp = &car_data[MAX_CARS - 1];
do {
if (cp->controlType != CONTROL_TYPE_NONE &&
PositionVisible((VECTOR*)cp->hd.where.t))

View File

@ -3239,7 +3239,7 @@ void StepEvents(void)
i++;
cp++;
} while (i < 20);
} while (i < MAX_CARS && i < 32);
// make Tanner on boat also
if (player[0].playerType == 2 && OnBoat((VECTOR*)player, ev, &dist) != 0)
@ -3295,7 +3295,7 @@ void StepEvents(void)
do {
pos = (VECTOR*)car_data[i].hd.where.t;
if (i == 20)
if (i == TANNER_COLLIDER_CARID)
{
pos = (VECTOR*)player[0].pos;
vel = NULL;
@ -3318,7 +3318,7 @@ void StepEvents(void)
pos->vx += iVar6;
pos->vz += iVar4;
if (i == 20)
if (i == TANNER_COLLIDER_CARID)
{
SetTannerPosition((VECTOR*)pos);
carsOnBoat = carsOnBoat & 0xffefffff;

View File

@ -1648,8 +1648,8 @@ void DoDopplerSFX(void)
uint uVar18;
int *piVar10;
int cars;
ulong car_dist[20];
ushort indexlist[20];
ulong car_dist[MAX_CARS];
ushort indexlist[MAX_CARS];
char sirens;
uint local_34;
uint local_30;
@ -1716,7 +1716,7 @@ void DoDopplerSFX(void)
LAB_0004e984:
car++;
} while (car < 20);
} while (car < MAX_CARS);
local_34 = (cars < 3);
local_30 = (cars < 5);

View File

@ -195,11 +195,11 @@ void HandleExplosion(void)
cp = car_data;
do {
if (cp == &car_data[20] || cp != gBombTargetVehicle && cp->controlType != CONTROL_TYPE_NONE)
if (cp == &car_data[CAMERA_COLLIDER_CARID] || cp != gBombTargetVehicle && cp->controlType != CONTROL_TYPE_NONE)
ExplosionCollisionCheck(cp, &explosion[i]);
cp++;
} while (cp < &car_data[20]);
} while (cp < &car_data[MAX_CARS]);
}
i++;

View File

@ -2502,7 +2502,7 @@ void UpdateRoadPosition(_CAR_DATA *cp, VECTOR *basePos, int intention)
} while (iVar16 < 0xb);
lcp = (car_data + 0x13);
lcp = &car_data[MAX_CARS - 1];
while (car_data < lcp)
{

View File

@ -945,7 +945,7 @@ void GameInit(void)
do {
lightsOnDelay[i] = Random2(0);
i++;
} while (i < 20);
} while (i < MAX_CARS);
}
tracking_car = 1;
@ -1447,7 +1447,7 @@ void StepSim(void)
}
}
if (requestStationaryCivCar == 1 && (numCivCars < maxCivCars || (PingOutCar(car_data + furthestCivID), numCivCars < maxCivCars)))
if (requestStationaryCivCar == 1 && (numCivCars < maxCivCars || (PingOutCar(&car_data[furthestCivID]), numCivCars < maxCivCars)))
{
requestStationaryCivCar = 0;
}
@ -2040,7 +2040,7 @@ void StepGame(void)
// player flip cheat
if (gRightWayUp != 0)
{
TempBuildHandlingMatrix(car_data + player[0].playerCarId, 0);
TempBuildHandlingMatrix(&car_data[player[0].playerCarId], 0);
gRightWayUp = 0;
}

View File

@ -2879,7 +2879,7 @@ int MRProcessTarget(MR_THREAD *thread, _TARGET *target)
cp->inform = NULL;
PingOutCar(car_data + slot);
PingOutCar(&car_data[slot]);
slot = CreateCivCarWotDrivesABitThenStops(direction, (long(*)[4])pos, NULL, model, palette);
cp->inform = inform;
@ -3416,7 +3416,7 @@ int MRCreateCar(_TARGET *target)
{
playerid = 0xff;
InitPlayer((_PLAYER *)(player + 1), car_data + curslot, 4, target->data[5], (long(*)[4])pos, target->data[7], target->data[8], (char *)&playerid);
InitPlayer((_PLAYER *)(player + 1), &car_data[curslot], 4, target->data[5], (long(*)[4])pos, target->data[7], target->data[8], (char *)&playerid);
EnablePercentageBar(&DamageBar, target->data[13]);
NewLeadDelay = 0;

View File

@ -1103,7 +1103,7 @@ void CheckScenaryCollisions(_CAR_DATA *cp)
gLastModelCollisionCheck = cop->type;
if (CAR_INDEX(cp) == 21)
if (CAR_INDEX(cp) == TANNER_COLLIDER_CARID)
{
if (count >= mdcount && cop->pad != 0)
{
@ -1459,7 +1459,7 @@ void DoScenaryCollisions(void)
{
_CAR_DATA *cp;
cp = car_data + MAX_CARS - 1;
cp = &car_data[MAX_CARS - 1];
do {
if (cp->controlType != CONTROL_TYPE_NONE)

View File

@ -1005,7 +1005,7 @@ LAB_00016fac:
DrawSightCone(&copSightData, (VECTOR *)cp->hd.where.t, cp->hd.direction);
cp++;
} while (cp <= &car_data[20]);
} while (cp <= &car_data[MAX_CARS]);
sVar2 = -uVar28;
@ -1800,7 +1800,7 @@ void DrawCopIndicators(void)
}
}
cp++;
} while (cp <= &car_data[20]);
} while (cp <= &car_data[MAX_CARS]);
}

View File

@ -1650,7 +1650,7 @@ void addCivs(void)
cp++;
if (&car_data[19] < cp)
if (&car_data[MAX_CARS-1] < cp)
return;
} while (true);

View File

@ -3284,7 +3284,7 @@ void TannerCollision(PEDESTRIAN* pPed)
if (pPed->type == PED_ACTION_SIT)
return;
pcdTanner = &car_data[21];
pcdTanner = &car_data[TANNER_COLLIDER_CARID];
ClearMem((char*)pcdTanner, sizeof(_CAR_DATA));
@ -3526,15 +3526,15 @@ int TannerCarCollisionCheck(VECTOR* pPos, int dir, int bQuick)
CRET2D collisionResult; // offset 0x30
CDATA2D cd[2];
pcdTanner = &car_data[21];
pcdTanner = &car_data[TANNER_COLLIDER_CARID];
cd[0].length[0] = 0x3c;
cd[0].length[1] = 0x3c;
cd[0].length[0] = 60;
cd[0].length[1] = 60;
cd[0].x.vx = pPos->vx;
cd[0].x.vz = pPos->vz;
cd[0].theta = dir;
cp1 = car_data + MAX_CARS - 1;
cp1 = &car_data[MAX_CARS - 1];
do {
car_cos = &car_cosmetics[cp1->ap.model];
@ -4574,7 +4574,7 @@ void add_seated(SEATED_PEDESTRIANS* seatedptr, int seat_index)
PEDESTRIAN* pedptr;
long rnd;
if (num_pedestrians < 20)
if (num_pedestrians < MAX_SEATED_PEDS)
{
pedptr = CreatePedestrian();
@ -4738,11 +4738,11 @@ void BuildCarCollisionBox(void)
set_coll_box(1, &car_data[player[0].playerCarId], 9);
}
cp = car_data + (CameraCnt & 3);
cp = &car_data[(CameraCnt & 3)];
collision_boxes_set = 2;
while (cp < car_data + MAX_CARS)
while (cp < &car_data[MAX_CARS])
{
if (cp != &car_data[player[0].playerCarId] && cp->controlType != CONTROL_TYPE_NONE)
{

View File

@ -1,6 +1,8 @@
#ifndef PEDEST_H
#define PEDEST_H
#define TANNER_COLLIDER_CARID (MAX_CARS)
extern MODEL* pmTannerModels[17];
extern MODEL* pmJerichoModels[6];

View File

@ -4064,7 +4064,7 @@ void CheckSpecialSpool(void)
return;
lcp++;
} while (lcp < &car_data[20]);
} while (lcp < &car_data[MAX_CARS]);
specModelValid = 0;

View File

@ -5,8 +5,10 @@
// please populate this file only with engine limits during refactoring
#define MAX_CARS 20
#define MAX_CAR_MODELS 5
#define MAX_PEDESTRIANS 28
#define MAX_SEATED_PEDS 20
#define MAX_PLACED_PEDS 15
#define MAX_TRAFFIC_CARS 19
#define MAX_EXPLOSION_OBJECTS 5