Merge pull request #440 from Fire-Head/master

CWeapon done, fixes
This commit is contained in:
Nikolay Korolev 2020-04-15 23:28:09 +03:00 committed by GitHub
commit 5cb7e2e42a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 2331 additions and 60 deletions

View File

@ -118,7 +118,7 @@ enum eScriptSounds : int16 {
SCRIPT_SOUND_BULLET_HIT_GROUND_1 = 106,
SCRIPT_SOUND_BULLET_HIT_GROUND_2 = 107,
SCRIPT_SOUND_BULLET_HIT_GROUND_3 = 108,
SCRIPT_SOUND_109 = 109,
SCRIPT_SOUND_BULLET_HIT_WATER = 109, //no sound
SCRIPT_SOUND_110 = 110,
SCRIPT_SOUND_111 = 111,
SCRIPT_SOUND_PAYPHONE_RINGING = 112,

View File

@ -35,7 +35,7 @@ void CAutoPilot::ModifySpeed(float speed)
m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() -
(uint32)(positionBetweenNodes * m_nTimeToSpendOnCurrentCurve);
#else
m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() - positionBetweenNodes * m_nSpeedScaleFactor;
m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() - positionBetweenNodes * m_nTimeToSpendOnCurrentCurve;
#endif
}

View File

@ -426,7 +426,7 @@ CCarCtrl::GenerateOneRandomCar()
(uint32)((0.5f + positionBetweenNodes) * pCar->AutoPilot.m_nTimeToSpendOnCurrentCurve);
#else
pCar->AutoPilot.m_nTimeEnteredCurve = CTimer::GetTimeInMilliseconds() -
(0.5f + positionBetweenNodes) * pCar->AutoPilot.m_nSpeedScaleFactor;
(0.5f + positionBetweenNodes) * pCar->AutoPilot.m_nTimeToSpendOnCurrentCurve;
#endif
CVector directionCurrentLink(directionCurrentLinkX, directionCurrentLinkY, 0.0f);
CVector directionNextLink(directionNextLinkX, directionNextLinkY, 0.0f);

View File

@ -1082,7 +1082,7 @@ void CGarage::Update()
#ifdef FIX_BUGS
bool bCreatedAllCars = false;
#else
bool bCraetedAllCars;
bool bCreatedAllCars;
#endif
switch (m_eGarageType) {
case GARAGE_HIDEOUT_ONE: bCreatedAllCars = RestoreCarsForThisHideout(CGarages::aCarsInSafeHouse1); break;

View File

@ -91,6 +91,11 @@ public:
}
}
static float GetAngleBetweenPoints(float x1, float y1, float x2, float y2)
{
return RADTODEG(GetRadianAngleBetweenPoints(x1, y1, x2, y2));
}
// should return direction in 0-8 range. fits perfectly to peds' path directions.
static int GetNodeHeadingFromVector(float x, float y)
{

View File

@ -645,6 +645,8 @@ void CPad::AddToCheatString(char c)
for ( int32 i = ARRAY_SIZE(CheatString) - 2; i >= 0; i-- )
CheatString[i + 1] = CheatString[i];
CheatString[0] = c;
#define _CHEATCMP(str) strncmp(str, CheatString, sizeof(str)-1)
// "4414LDRULDRU" - R2 R2 L1 R2 LEFT DOWN RIGHT UP LEFT DOWN RIGHT UP
if ( !_CHEATCMP("URDLURDL4144") )

View File

@ -58,6 +58,7 @@ WRAPPER void CWorld::ClearPedsFromArea(float, float, float, float, float, float)
WRAPPER void CWorld::CallOffChaseForArea(float, float, float, float) { EAXJMP(0x4B5530); }
WRAPPER void CWorld::TriggerExplosion(const CVector& a1, float a2, float a3, CEntity *a4, bool a5) { EAXJMP(0x4B1140); }
WRAPPER void CWorld::SetPedsOnFire(float, float, float, float, CEntity*) { EAXJMP(0x4B3D30); }
WRAPPER void CWorld::UseDetonator(CEntity *) { EAXJMP(0x4B4650); }
void
CWorld::Initialise()

View File

@ -142,6 +142,8 @@ public:
static void RemoveStaticObjects();
static void Process();
static void TriggerExplosion(const CVector &, float, float, CEntity*, bool);
static void UseDetonator(CEntity *);
};
extern CColPoint gaTempSphereColPoints[MAX_COLLISION_POINTS];

View File

@ -1560,8 +1560,9 @@ void SystemInit()
//
#endif
#ifdef GTA_PS2_STUFF
CPad::Initialise();
#endif
CPad::GetPad(0)->Mode = 0;
CGame::frenchGame = false;

View File

@ -612,7 +612,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
if(model == MI_FIRE_HYDRANT && !Bobj->bHasBeenDamaged){
CParticleObject::AddObject(POBJECT_FIRE_HYDRANT, B->GetPosition() - CVector(0.0f, 0.0f, 0.5f), true);
Bobj->bHasBeenDamaged = true;
}else if(B->IsObject() && model != MI_EXPLODINGBARREL && model != MI_PETROLPUMP)
}else if(B->IsObject() && !IsExplosiveThingModel(model))
Bobj->bHasBeenDamaged = true;
}else{
if(IsGlass(B->GetModelIndex()))

View File

@ -47,6 +47,13 @@ public:
z *= invsqrt;
}
void Normalise2D(void) {
float sq = MagnitudeSqr2D();
float invsqrt = RecipSqrt(sq);
x *= invsqrt;
y *= invsqrt;
}
const CVector &operator+=(CVector const &right) {
x += right.x;
y += right.y;

View File

@ -13,13 +13,14 @@ public:
void Normalise(void){
float sq = MagnitudeSqr();
if(sq > 0.0f){
//if(sq > 0.0f){
float invsqrt = RecipSqrt(sq);
x *= invsqrt;
y *= invsqrt;
}else
x = 1.0f;
//}else
// x = 1.0f;
}
const CVector2D &operator+=(CVector2D const &right) {
x += right.x;
y += right.y;

View File

@ -490,3 +490,10 @@ IsPoliceVehicleModel(int16 id)
id == MI_POLICE ||
id == MI_ENFORCER;
}
inline bool
IsExplosiveThingModel(int16 id)
{
return id == MI_EXPLODINGBARREL ||
id == MI_PETROLPUMP;
}

View File

@ -1228,7 +1228,7 @@ CPed::Attack(void)
weaponAnimAssoc->SetCurrentTime(0.0f);
if (IsPlayer()) {
((CPlayerPed*)this)->field_1376 = 0.0f;
((CPlayerPed*)this)->m_fAttackButtonCounter = 0.0f;
((CPlayerPed*)this)->m_bHaveTargetSelected = false;
}
}

View File

@ -796,7 +796,12 @@ public:
PedState GetPedState(void) { return m_nPedState; }
void SetPedState(PedState state) { m_nPedState = state; }
bool Dead(void) { return m_nPedState == PED_DEAD; }
bool Dying(void) { return m_nPedState == PED_DIE; }
bool DyingOrDead(void) { return m_nPedState == PED_DIE || m_nPedState == PED_DEAD; }
bool OnGround(void) { return m_nPedState == PED_FALL || m_nPedState == PED_DIE || m_nPedState == PED_DEAD; }
bool Driving(void) { return m_nPedState == PED_DRIVING; }
bool InVehicle(void) { return bInVehicle && m_pMyVehicle; } // True when ped is sitting/standing in vehicle, not in enter/exit state.
bool EnteringCar(void) { return m_nPedState == PED_ENTER_CAR || m_nPedState == PED_CARJACK; }

View File

@ -43,8 +43,8 @@ CPlayerPed::CPlayerPed(void) : CPed(PEDTYPE_PLAYER1)
m_fStaminaProgress = 0.0f;
m_nEvadeAmount = 0;
field_1367 = 0;
m_nShotDelay = 0;
field_1376 = 0.0f;
m_nHitAnimDelayTimer = 0;
m_fAttackButtonCounter = 0.0f;
m_bHaveTargetSelected = false;
m_bHasLockOnTarget = false;
m_bCanBeDamaged = true;
@ -1024,10 +1024,10 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed)
if (padUsed->WeaponJustDown()) {
m_bHaveTargetSelected = true;
} else if (!m_bHaveTargetSelected) {
field_1376 += CTimer::GetTimeStepNonClipped();
m_fAttackButtonCounter += CTimer::GetTimeStepNonClipped();
}
} else {
field_1376 = 0.0f;
m_fAttackButtonCounter = 0.0f;
m_bHaveTargetSelected = false;
}
SetAttack(nil);

View File

@ -20,8 +20,8 @@ public:
uint8 m_nEvadeAmount;
int8 field_1367;
uint32 m_nSpeedTimer;
int32 m_nShotDelay;
float field_1376; // m_fAttackButtonCounter?
uint32 m_nHitAnimDelayTimer;
float m_fAttackButtonCounter;
bool m_bHaveTargetSelected; // may have better name
int8 field_1381;
int8 field_1382;

View File

@ -404,6 +404,7 @@ CGlass::AskForObjectToBeRenderedInGlass(CEntity *entity)
void
CGlass::RenderEntityInGlass(CEntity *entity)
{
ASSERT(entity!=nil);
CObject *object = (CObject *)entity;
if ( object->bGlassBroken )
@ -419,7 +420,7 @@ CGlass::RenderEntityInGlass(CEntity *entity)
uint8 alpha = CalcAlphaWithNormal(&fwdNorm);
CColModel *col = object->GetColModel();
ASSERT(col!=nil);
if ( col->numTriangles >= 2 )
{
CVector a = object->GetMatrix() * col->vertices[0];
@ -523,6 +524,8 @@ CGlass::RenderEntityInGlass(CEntity *entity)
int32
CGlass::CalcAlphaWithNormal(CVector *normal)
{
ASSERT(normal!=nil);
float fwdDir = 2.0f * DotProduct(*normal, TheCamera.GetForward());
float fwdDot = DotProduct(TheCamera.GetForward()-fwdDir*(*normal), CVector(0.57f, 0.57f, -0.57f));
return int32(lerp(fwdDot*fwdDot*fwdDot*fwdDot*fwdDot*fwdDot, 20.0f, 255.0f));
@ -597,6 +600,8 @@ CGlass::RenderReflectionPolys(void)
void
CGlass::WindowRespondsToCollision(CEntity *entity, float amount, CVector speed, CVector point, bool explosion)
{
ASSERT(entity!=nil);
CObject *object = (CObject *)entity;
if ( object->bGlassBroken )
@ -605,6 +610,7 @@ CGlass::WindowRespondsToCollision(CEntity *entity, float amount, CVector speed,
object->bGlassCracked = true;
CColModel *col = object->GetColModel();
ASSERT(col!=nil);
CVector a = object->GetMatrix() * col->vertices[0];
CVector b = object->GetMatrix() * col->vertices[1];
@ -647,6 +653,8 @@ CGlass::WindowRespondsToCollision(CEntity *entity, float amount, CVector speed,
void
CGlass::WindowRespondsToSoftCollision(CEntity *entity, float amount)
{
ASSERT(entity!=nil);
CObject *object = (CObject *)entity;
if ( amount > 50.0f && !object->bGlassCracked )
@ -659,6 +667,8 @@ CGlass::WindowRespondsToSoftCollision(CEntity *entity, float amount)
void
CGlass::WasGlassHitByBullet(CEntity *entity, CVector point)
{
ASSERT(entity!=nil);
CObject *object = (CObject *)entity;
if ( IsGlass(object->GetModelIndex()) )
@ -679,6 +689,8 @@ CGlass::WasGlassHitByBullet(CEntity *entity, CVector point)
void
CGlass::WindowRespondsToExplosion(CEntity *entity, CVector point)
{
ASSERT(entity!=nil);
CObject *object = (CObject *)entity;
CVector distToGlass = object->GetPosition() - point;

View File

@ -2,4 +2,8 @@
#include "patcher.h"
#include "BulletInfo.h"
WRAPPER void CBulletInfo::Initialise(void) { EAXJMP(0x558220); }
WRAPPER void CBulletInfo::Shutdown(void) { EAXJMP(0x558450); }
WRAPPER void CBulletInfo::AddBullet(CEntity *firingEntity, eWeaponType type, CVector pos, CVector velocity) { EAXJMP(0x558470); }
WRAPPER void CBulletInfo::Update(void) { EAXJMP(0x558550); }
WRAPPER bool CBulletInfo::TestForSniperBullet(float x1, float x2, float y1, float y2, float z1, float z2) { EAXJMP(0x558D40); }

View File

@ -1,7 +1,14 @@
#pragma once
class CEntity;
enum eWeaponType;
class CBulletInfo
{
public:
static void Initialise(void);
static void Shutdown(void);
static void AddBullet(CEntity *firingEntity, eWeaponType type, CVector pos, CVector velocity);
static void Update(void);
static bool TestForSniperBullet(float x1, float x2, float y1, float y2, float z1, float z2);
};

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,8 @@
#pragma once
#define DRIVEBYAUTOAIMING_MAXDIST (2.5f)
#define DOOMAUTOAIMING_MAXDIST (9000.0f)
enum eWeaponType
{
WEAPONTYPE_UNARMED,
@ -49,7 +52,10 @@ enum eWeaponState
};
class CEntity;
class CPhysical;
class CAutomobile;
struct CColPoint;
class CWeaponInfo;
class CWeapon
{
@ -65,21 +71,49 @@ public:
m_bAddRotOffset = false;
}
CWeaponInfo *GetInfo();
static void InitialiseWeapons(void);
static void ShutdownWeapons (void);
void Initialise(eWeaponType type, int ammo);
void Update(int32 audioEntity);
static void UpdateWeapons (void);
void Initialise(eWeaponType type, int32 ammo);
bool Fire (CEntity *shooter, CVector *fireSource);
bool FireFromCar (CAutomobile *shooter, bool left);
bool FireMelee (CEntity *shooter, CVector &fireSource);
bool FireInstantHit(CEntity *shooter, CVector *fireSource);
void AddGunshell (CEntity *shooter, CVector const &source, CVector2D const &direction, float size);
void DoBulletImpact(CEntity *shooter, CEntity *victim, CVector *source, CVector *target, CColPoint *point, CVector2D ahead);
bool FireShotgun (CEntity *shooter, CVector *fireSource);
bool FireProjectile(CEntity *shooter, CVector *fireSource, float power);
static void GenerateFlameThrowerParticles(CVector pos, CVector dir);
bool FireAreaEffect (CEntity *shooter, CVector *fireSource);
bool FireSniper (CEntity *shooter);
bool FireM16_1stPerson (CEntity *shooter);
bool FireInstantHitFromCar(CAutomobile *shooter, bool left);
static void DoDoomAiming (CEntity *shooter, CVector *source, CVector *target);
static void DoTankDoomAiming (CEntity *shooter, CEntity *driver, CVector *source, CVector *target);
static void DoDriveByAutoAiming(CEntity *shooter, CVector *source, CVector *target);
void Reload(void);
bool Fire(CEntity*, CVector*);
void FireFromCar(CAutomobile *car, bool left);
void AddGunshell(CEntity*, CVector const&, CVector2D const&, float);
void Update(int32 audioEntity);
bool IsTypeMelee (void);
bool IsType2Handed(void);
static void DoTankDoomAiming(CEntity *playerVehicle, CEntity *playerPed, CVector *start, CVector *end);
bool HitsGround(CEntity* holder, CVector* firePos, CEntity* aimingTo);
bool HasWeaponAmmoToBeUsed(void);
static void InitialiseWeapons(void);
static void UpdateWeapons(void);
};
static_assert(sizeof(CWeapon) == 0x18, "CWeapon: error");
void FireOneInstantHitRound(CVector* shotSource, CVector* shotTarget, int32 damage);
static void MakePedsJumpAtShot(CPhysical *shooter, CVector *source, CVector *target);
bool HitsGround(CEntity *holder, CVector *fireSource, CEntity *aimingTo);
static void BlowUpExplosiveThings(CEntity *thing);
bool HasWeaponAmmoToBeUsed(void);
static bool ProcessLineOfSight(CVector const &point1, CVector const &point2, CColPoint &point, CEntity *&entity, eWeaponType type, CEntity *shooter, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies, bool ignoreSeeThrough, bool ignoreSomeObjects);
};
VALIDATE_SIZE(CWeapon, 0x18);
void FireOneInstantHitRound(CVector *source, CVector *target, int32 damage);