REDRIVER2/src_rebuild/GAME/C/FELONY.C

494 lines
9.9 KiB
C++
Raw Normal View History

#include "DRIVER2.H"
#include "FELONY.H"
#include "STRINGS.H"
2020-05-27 12:03:46 +02:00
#include "COP_AI.H"
#include "CIV_AI.H"
2020-05-27 12:03:46 +02:00
#include "PLAYERS.H"
#include "CARS.H"
#include "MISSION.H"
#include "CONVERT.H"
#include "GAMESND.H"
#include "DR2ROADS.H"
#include "OVERLAY.H"
#include "MISSION.H"
#include "ABS.H"
short initialOccurrenceDelay[12] = { 24, 0, 0, 0, 0, 0, 0, 0, 24, 0, 24, 0 };
short initialReccurrenceDelay[12] = { 128, 0, 128, 64, 64, 32, 32, 0, 128, 256 };
FELONY_VALUE initialFelonyValue[12] =
{
{ 659, 0 },
{ 659, 75 },
{ 659, 0 },
{ 659, 0 },
{ 659, 659 },
{ 1318, 659 },
{ 659, 659 },
{ 659, 25 },
{ 659, 0 },
{ 659, 0 },
{ 659, 0 },
{ 4096, 0 }
};
FELONY_DATA felonyData;
int FelonyIncreaseTime = 0;
int FelonyDecreaseTime = 0;
int FelonyIncreaseTimer = 0;
int FelonyDecreaseTimer = 0;
2020-09-19 22:10:41 +02:00
// [D] [T]
void InitFelonyDelayArray(FELONY_DELAY *pFelonyDelay, short *pMaximum, int count)
{
2020-09-19 22:10:41 +02:00
FELONY_DELAY *pCurrent;
2020-09-19 22:10:41 +02:00
pCurrent = pFelonyDelay + count;
while (pFelonyDelay < pCurrent)
{
pFelonyDelay->current = 0;
pFelonyDelay->maximum = *pMaximum++;
pFelonyDelay++;
}
}
2020-09-19 22:10:41 +02:00
// [D] [T]
void InitFelonyData(FELONY_DATA *pFelonyData)
{
InitFelonyDelayArray(pFelonyData->occurrenceDelay, initialOccurrenceDelay, numberOf(initialOccurrenceDelay));
InitFelonyDelayArray(pFelonyData->reoccurrenceDelay, initialReccurrenceDelay, numberOf(initialOccurrenceDelay));
memcpy(&pFelonyData->value, &initialFelonyValue, sizeof(initialFelonyValue));
}
2020-09-19 22:10:41 +02:00
// [D] [T]
int GetCarHeading(int direction)
{
return (direction + 0x200U & 0xfff) >> 10;
}
2020-09-19 22:10:41 +02:00
// [D] [T]
char GetCarDirectionOfTravel(CAR_DATA *cp)
{
2020-09-19 22:10:41 +02:00
int direction;
2020-09-19 22:10:41 +02:00
direction = GetCarHeading(cp->hd.direction);;
if (cp->hd.wheel_speed < 0)
2020-09-19 22:10:41 +02:00
direction = direction + 2 & 3;
2020-09-19 22:10:41 +02:00
return direction;
}
2020-05-27 12:03:46 +02:00
// [D]
void NoteFelony(FELONY_DATA *pFelonyData, char type, short scale)
{
2020-09-19 22:10:41 +02:00
int felonyTooLowForRoadblocks;
char rnd; // $s1
int dir; // $a3
2020-05-27 12:03:46 +02:00
short *felony;
int phrase;
2020-09-19 22:10:41 +02:00
int additionalFelonyPoints;
2020-05-27 12:03:46 +02:00
if (player[0].playerCarId < 0)
felony = &pedestrianFelony;
else
felony = &car_data[player[0].playerCarId].felonyRating;
2020-09-19 22:10:41 +02:00
felonyTooLowForRoadblocks = *felony;
if (pFelonyData->occurrenceDelay[type].current < pFelonyData->occurrenceDelay[type].maximum)
return;
2020-05-27 12:03:46 +02:00
#ifdef FELONY_DEBUG
switch (type)
{
case 1:
SetPlayerMessage(0, "Scaring pedestrians", 0, 1);
break;
case 2:
SetPlayerMessage(0, "Speeding", 0, 1);
break;
case 3:
SetPlayerMessage(0, "Red light crossing", 0, 1);
break;
case 4:
SetPlayerMessage(0, "Collision with another vehicle", 0, 1);
break;
case 5:
SetPlayerMessage(0, "Collision with cop", 0, 1);
break;
case 6:
SetPlayerMessage(0, "Collision with building", 0, 1);
break;
case 7:
SetPlayerMessage(0, "Damaging propery", 0, 1);
break;
case 8:
SetPlayerMessage(0, "Wrong way", 0, 1);
break;
case 9:
SetPlayerMessage(0, "Driving without lights", 0, 1);
break;
case 10:
SetPlayerMessage(0, "Reckless driving", 0, 1);
break;
case 11:
SetPlayerMessage(0, "Stealing cop car", 0, 1);
break;
}
#endif
2020-05-27 12:03:46 +02:00
if (CopsCanSeePlayer == 0 && (type != 11))
return;
2020-05-27 12:03:46 +02:00
2020-09-19 22:10:41 +02:00
if (pFelonyData->reoccurrenceDelay[type].current != 0)
return;
2020-05-27 12:03:46 +02:00
2020-09-19 22:10:41 +02:00
pFelonyData->reoccurrenceDelay[type].current = pFelonyData->reoccurrenceDelay[type].maximum;
2020-05-27 12:03:46 +02:00
if (*felony <= FELONY_MIN_VALUE)
2020-09-19 22:10:41 +02:00
additionalFelonyPoints = pFelonyData->value[type].placid;
2020-05-27 12:03:46 +02:00
else
2020-09-19 22:10:41 +02:00
additionalFelonyPoints = pFelonyData->value[type].angry * pFelonyData->pursuitFelonyScale >> 0xc;
2020-05-27 12:03:46 +02:00
2020-09-19 22:10:41 +02:00
*felony += (additionalFelonyPoints * scale >> 12);
2020-05-27 12:03:46 +02:00
if (*felony > FELONY_MAX_VALUE)
*felony = FELONY_MAX_VALUE;
2020-05-27 12:03:46 +02:00
2020-09-19 22:10:41 +02:00
// KILL PEDESTRIAN FELONY HERE
2020-05-27 12:03:46 +02:00
if (player[0].playerType == 2)
*felony = 0;
2020-09-19 22:10:41 +02:00
if (first_offence == 0 && numActiveCops)
2020-05-27 12:03:46 +02:00
{
2020-09-19 22:10:41 +02:00
// say something..
2020-11-01 18:55:21 +01:00
rnd = Random2(1);
2020-09-19 22:10:41 +02:00
dir = GetCarDirectionOfTravel(&car_data[player[0].playerCarId]);
2020-05-27 12:03:46 +02:00
2020-09-19 22:10:41 +02:00
switch (type)
{
case 1:
case 5:
case 6:
case 7:
case 11:
break;
case 3:
if ((rnd & 3) != 0)
break;
CopSay(5, 0);
break;
case 4:
2020-11-01 18:55:21 +01:00
if ((rnd % 3) & 0xff != 0)
2020-09-19 22:10:41 +02:00
break;
CopSay((rnd & 1) + 7, 0);
break;
default:
2020-11-01 18:55:21 +01:00
if ((rnd % 17) & 0xFF == 0)
2020-05-27 12:03:46 +02:00
{
2020-11-01 18:55:21 +01:00
if (MaxPlayerDamage[0] * 3 / 4 < car_data[player[0].playerCarId].totalDamage)
2020-11-02 08:29:23 +01:00
phrase = rnd % 4;
2020-05-27 12:03:46 +02:00
else
2020-11-02 08:29:23 +01:00
phrase = rnd % 3;
2020-05-27 12:03:46 +02:00
2020-09-19 22:10:41 +02:00
if (last_cop_phrase != phrase && 0 < TimeSinceLastSpeech)
{
if (phrase < 3)
CopSay(phrase + 15, dir);
else
CopSay(6, 0);
2020-05-27 12:03:46 +02:00
2020-09-19 22:10:41 +02:00
last_cop_phrase = phrase;
}
}
break;
}
}
2020-05-27 12:03:46 +02:00
2020-09-19 22:10:41 +02:00
if (felonyTooLowForRoadblocks < 0x527)
2020-05-27 12:03:46 +02:00
{
2020-09-19 22:10:41 +02:00
if (*felony > 0x526)
2020-05-27 12:03:46 +02:00
{
2020-09-19 22:10:41 +02:00
roadblockCount = roadblockDelayDiff[gCopDifficultyLevel] + (Random2(0) & 0xff);
}
}
}
2020-09-19 22:10:41 +02:00
// [D] [T]
void AdjustFelony(FELONY_DATA *pFelonyData)
{
2020-05-27 12:03:46 +02:00
FELONY_DELAY *pFelonyDelay;
short *felony;
2020-05-27 12:03:46 +02:00
if (player[0].playerCarId < 0)
felony = &pedestrianFelony;
else
felony = &car_data[player[0].playerCarId].felonyRating;
if (*felony != 0 && *felony <= FELONY_MIN_VALUE)
2020-05-27 12:03:46 +02:00
{
if (FelonyDecreaseTimer++ == FelonyDecreaseTime)
{
(*felony)--;
2020-05-27 12:03:46 +02:00
FelonyDecreaseTimer = 0;
}
}
2020-05-27 12:03:46 +02:00
else if (CopsCanSeePlayer)
{
if (*felony > FELONY_MIN_VALUE && FelonyIncreaseTimer++ == FelonyIncreaseTime)
2020-05-27 12:03:46 +02:00
{
(*felony)++;
2020-05-27 12:03:46 +02:00
if (*felony > FELONY_MAX_VALUE)
*felony = FELONY_MAX_VALUE;
2020-05-27 12:03:46 +02:00
FelonyIncreaseTimer = 0;
}
}
2020-05-27 12:03:46 +02:00
pFelonyDelay = pFelonyData->reoccurrenceDelay;
while (pFelonyDelay <= &pFelonyData->reoccurrenceDelay[11])
{
if (pFelonyDelay->current != 0)
pFelonyDelay->current--;
pFelonyDelay++;
}
}
short playerLastRoad = 0;
2020-09-21 22:31:12 +02:00
// [D] [T]
void CheckPlayerMiscFelonies(void)
{
2020-09-21 22:31:12 +02:00
int i;
bool goingWrongWay;
int surfInd;
int maxSpeed;
int limit;
int exitId;
int _exitId;
VECTOR *carPos;
DRIVER2_ROAD_INFO roadInfo;
DRIVER2_JUNCTION *jn;
CAR_DATA* cp;
// Do not register felony if player does not have a car
if (player[0].playerType == 2 ||
player[0].playerCarId < 0 ||
FelonyBar.active == 0)
return;
cp = &car_data[player[0].playerCarId];
carPos = (VECTOR *)cp->hd.where.t;
surfInd = GetSurfaceIndex(carPos);
// check junctions
2020-09-21 22:31:12 +02:00
if (IS_JUNCTION_SURFACE(surfInd))
{
jn = GET_JUNCTION(surfInd);
if( (IS_CURVED_SURFACE(playerLastRoad) || IS_STRAIGHT_SURFACE(playerLastRoad)) && (jn->flags & 0x1))
{
2020-09-21 22:31:12 +02:00
exitId = 0;
i = 0;
while (i < 4)
{
2020-09-21 22:31:12 +02:00
if (jn->ExitIdx[i] == playerLastRoad)
{
exitId = i;
break;
}
i++;
}
2020-09-21 22:31:12 +02:00
// Run a red light!
if (junctionLightsPhase[exitId & 1] == 1)
NoteFelony(&felonyData, 3, 4096);
}
}
playerLastRoad = surfInd;
goingWrongWay = false;
if(GetSurfaceRoadInfo(&roadInfo, surfInd))
{
2020-09-21 22:31:12 +02:00
int lane_count;
int lane;
int dx;
int dz;
int crd;
2020-09-21 22:31:12 +02:00
lane_count = ROAD_WIDTH_IN_LANES(&roadInfo);
2020-09-21 22:31:12 +02:00
if(roadInfo.straight)
{
dx = carPos->vx - roadInfo.straight->Midx;
dz = carPos->vz - roadInfo.straight->Midz;
lane = ROAD_LANES_COUNT(&roadInfo) - (FIXEDH(dx * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2 + 1] - dz * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2]) + 512 >> 9);
2020-09-21 22:31:12 +02:00
if (lane < 0)
lane = 0;
2020-09-21 22:31:12 +02:00
if (lane_count <= lane)
lane = lane_count - 1;
crd = (roadInfo.straight->angle - cp->hd.direction) + 0x400U >> 0xb & 1;
}
else
{
dx = carPos->vx - roadInfo.curve->Midx;
dz = carPos->vz - roadInfo.curve->Midz;
lane = (SquareRoot0(dx * dx + dz * dz) >> 9) - roadInfo.curve->inside * 2;
if (lane < 0)
lane = 0;
if (lane >= lane_count)
lane = lane_count - 1;
crd = NotTravellingAlongCurve(carPos->vx, carPos->vz, cp->hd.direction, roadInfo.curve);
}
2020-09-21 22:31:12 +02:00
// check if on correct lane
if (ROAD_IS_AI_LANE(&roadInfo, lane))
{
if (ROAD_LANE_DIR(&roadInfo, lane) == 0)
{
if (crd == 1)
goingWrongWay = true;
}
else
{
if (crd == 0)
goingWrongWay = true;
}
}
2020-09-21 22:31:12 +02:00
#if 0
2020-11-01 18:55:21 +01:00
printInfo("ROAD %d lane: %d / %d, (%d). AI drive: %d, flg: %d%d%d, dir: %d, spd: %d (wrong way: %d)\n",
roadInfo.surfId,
2020-09-21 22:31:12 +02:00
lane + 1,
((u_char)roadInfo.NumLanes & 0xF) * 2, // lane count. * 2 for both sides as roads are symmetric
IS_NARROW_ROAD(&roadInfo),
((u_char)roadInfo.AILanes >> (lane / 2) & 1U), // lane AI driveable flag
(roadInfo.NumLanes & 0x20) > 0, // flag 0 - first lane?
(roadInfo.NumLanes & 0x40) > 0, // flag 1 - leftmost park
(roadInfo.NumLanes & 0x80) > 0, // flag 2 - rightmost park
((u_char)roadInfo.LaneDirs >> (lane / 2) & 1U), // direction bit
((u_char)roadInfo.NumLanes >> 4) & 3, // speed limit id
2020-09-21 22:31:12 +02:00
goingWrongWay);
#endif
// get road speed limit
maxSpeed = speedLimits[ROAD_SPEED_LIMIT(&roadInfo)];
}
else
{
maxSpeed = speedLimits[2];
}
// wrong way
if (goingWrongWay)
felonyData.occurrenceDelay[8].current++;
else
felonyData.occurrenceDelay[8].current = 0;
NoteFelony(&felonyData, 8, 4096);
// if lights are off (broken)
if (gTimeOfDay == 3 && cp->ap.damage[0] > 1000 && cp->ap.damage[1] > 1000)
NoteFelony(&felonyData, 9, 4096);
// reckless driving.
// for that checking if rear wheels are sliding
if (cp->wheelspin == 0)
{
if (ABS(cp->hd.rear_vel) > 11100)
felonyData.occurrenceDelay[10].current++;
else
felonyData.occurrenceDelay[10].current = 0;
}
else
{
felonyData.occurrenceDelay[10].current++;
}
NoteFelony(&felonyData, 10, 4096);
// check the speed limit
if (speedLimits[2] == maxSpeed)
limit = (maxSpeed * 19) >> 4;
else
limit = (maxSpeed * 3) >> 1;
if (FIXEDH(cp->hd.wheel_speed) > limit)
NoteFelony(&felonyData, 2, 4096);
}
2020-09-19 22:10:41 +02:00
// [D] [T]
void InitFelonySystem(void)
{
2020-09-19 22:10:41 +02:00
FelonyIncreaseTime = 31;
FelonyDecreaseTime = 31;
FelonyIncreaseTimer = 0;
FelonyDecreaseTimer = 0;
InitFelonyData(&felonyData);
}
2020-09-19 22:10:41 +02:00
// [D] [T]
void CarHitByPlayer(CAR_DATA *victim, int howHard)
{
char type;
if (howHard > 0 && victim->controlType != CONTROL_TYPE_PURSUER_AI)
{
if ((victim->controlFlags & 1) == 0)
{
if (howHard < 32)
{
NoteFelony(&felonyData, 4, (howHard << 0x17) >> 0x10);
return;
}
type = 4;
}
else
{
if (howHard < 16)
{
NoteFelony(&felonyData, 5, (howHard << 0x18) >> 0x10);
return;
}
type = 5;
}
NoteFelony(&felonyData, type, 4096);
}
}