Merge pull request #655 from aap/miami

CPlane done
This commit is contained in:
aap 2020-07-20 19:56:03 +02:00 committed by GitHub
commit f0f3ce018d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 523 additions and 109 deletions

View File

@ -4031,7 +4031,7 @@ bool
CCamera::IsPointVisible(const CVector &center, const CMatrix *mat)
{
RwV3d c;
c = *(RwV3d*)&center;
c = center;
RwV3dTransformPoints(&c, &c, 1, &mat->m_matrix);
if(c.y < CDraw::GetNearClipZ()) return false;
if(c.y > CDraw::GetFarClipZ()) return false;
@ -4046,7 +4046,7 @@ bool
CCamera::IsSphereVisible(const CVector &center, float radius, const CMatrix *mat)
{
RwV3d c;
c = *(RwV3d*)&center;
c = center;
RwV3dTransformPoints(&c, &c, 1, &mat->m_matrix);
if(c.y + radius < CDraw::GetNearClipZ()) return false;
if(c.y - radius > CDraw::GetFarClipZ()) return false;

View File

@ -1,11 +1,14 @@
#include "common.h"
#include "main.h"
#include "RenderBuffer.h"
#include "Entity.h"
#include "Fluff.h"
#include "Camera.h"
#include "Sprite.h"
#include "Coronas.h"
#include "Rubbish.h"
#include "Timecycle.h"
#include "General.h"
#include "Timer.h"
#include "Clock.h"
@ -18,6 +21,277 @@
#include "Bones.h"
#include "World.h"
CPlaneTrail CPlaneTrails::aArray[6];
RwImVertexIndex TrailIndices[32] = {
0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16
};
void
CPlaneTrail::Init(void)
{
int i;
for(i = 0; i < ARRAY_SIZE(m_time); i++)
m_time[i] = 0;
}
void
CPlaneTrail::Render(float visibility)
{
int i;
int numVerts = 0;
if(!TheCamera.IsSphereVisible(m_pos[0], 1000.0f))
return;
int alpha = visibility*110.0f;
if(alpha == 0)
return;
for(i = 0; i < ARRAY_SIZE(m_pos); i++){
int32 time = CTimer::GetTimeInMilliseconds() - m_time[i];
if(time > 30000)
m_time[i] = 0;
if(m_time[i] != 0){
float fade = (30000.0f - time) / 10000.0f;
fade = Min(fade, 1.0f);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[numVerts], 255, 255, 255, (int)(alpha*fade));
RwIm3DVertexSetPos(&TempBufferRenderVertices[numVerts], m_pos[i].x, m_pos[i].y, m_pos[i].z);
numVerts++;
}
}
if(numVerts > 1){
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil);
if(RwIm3DTransform(TempBufferRenderVertices, numVerts, nil, rwIM3D_VERTEXXYZ|rwIM3D_VERTEXUV)){
RwIm3DRenderIndexedPrimitive(rwPRIMTYPELINELIST, TrailIndices, (numVerts-1)*2);
RwIm3DEnd();
}
}
}
void
CPlaneTrail::RegisterPoint(CVector pos)
{
int i;
bool bNewPoint = false;
if(m_time[0] != 0 && CTimer::GetTimeInMilliseconds() - m_time[0] > 2000){
bNewPoint = true;
for(i = ARRAY_SIZE(m_pos)-1; i > 0; i--){
m_pos[i] = m_pos[i-1];
m_time[i] = m_time[i-1];
}
}
m_pos[0] = pos;
if(bNewPoint || m_time[0] == 0)
m_time[0] = CTimer::GetTimeInMilliseconds();
}
void
CPlaneTrails::Init(void)
{
int i;
for(i = 0; i < ARRAY_SIZE(aArray); i++)
aArray[i].Init();
}
void
CPlaneTrails::Update(void)
{
CVector planePos;
planePos.x = 1590.0f * Sin((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI);
planePos.y = 1200.0f * Cos((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI);
planePos.z = 550.0f;
RegisterPoint(planePos, 3);
if(CClock::GetHours() > 22 || CClock::GetHours() < 7){
if(CTimer::GetTimeInMilliseconds() & 0x200)
CCoronas::RegisterCorona(101, 255, 0, 0, 255, planePos, 5.0f, 2000.0f,
CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF,
CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f);
else
CCoronas::UpdateCoronaCoors(101, planePos, 2000.0f, 0.0f);
}
planePos.x = 1000.0f * Sin((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI);
planePos.y = -1600.0f * Cos((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI);
planePos.z = 500.0f;
RegisterPoint(planePos, 4);
if(CClock::GetHours() > 22 || CClock::GetHours() < 7){
if(CTimer::GetTimeInMilliseconds() & 0x200)
CCoronas::RegisterCorona(102, 255, 0, 0, 255, planePos, 5.0f, 2000.0f,
CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF,
CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f);
else
CCoronas::UpdateCoronaCoors(102, planePos, 2000.0f, 0.0f);
}
planePos.x = 1100.0f * Cos((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI);
planePos.y = 700.0f * Sin((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI);
planePos.z = 600.0f;
RegisterPoint(planePos, 5);
if(CClock::GetHours() > 22 || CClock::GetHours() < 7){
if(CTimer::GetTimeInMilliseconds() & 0x200)
CCoronas::RegisterCorona(103, 255, 0, 0, 255, planePos, 5.0f, 2000.0f,
CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF,
CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f);
else
CCoronas::UpdateCoronaCoors(103, planePos, 2000.0f, 0.0f);
}
}
void
CPlaneTrails::Render(void)
{
int i;
float visibility = Min(1.0f-CWeather::Foggyness, 1.0f-CWeather::CloudCoverage);
visibility = Min(visibility, 1.0f-CWeather::Rain);
visibility = Min(Max(Max(CTimeCycle::GetSkyTopRed(), CTimeCycle::GetSkyTopGreen()), CTimeCycle::GetSkyTopBlue())/256.0f, visibility);
if(visibility > 0.0001f)
for(i = 0; i < ARRAY_SIZE(aArray); i++)
aArray[i].Render(visibility);
}
void
CPlaneTrails::RegisterPoint(CVector pos, uint32 id)
{
aArray[id].RegisterPoint(pos);
}
CPlaneBanner CPlaneBanners::aArray[5];
void
CPlaneBanner::Init(void)
{
int i;
for(i = 0; i < ARRAY_SIZE(m_pos); i++){
m_pos[i].x = i;
m_pos[i].y = 0.0f;
m_pos[i].z = -60.0f;
}
}
void
CPlaneBanner::Update(void)
{
int i;
if(m_pos[0].z > -50.0f){
m_pos[0].z -= 0.05f*CTimer::GetTimeStep();
m_pos[0].z = Max(m_pos[0].z, -100.0f);
for(i = 1; i < ARRAY_SIZE(m_pos); i++){
CVector dist = m_pos[i] - m_pos[i-1];
float len = dist.Magnitude();
if(len > 8.0f)
m_pos[i] = m_pos[i-1] + dist/len*8.0f;
}
}
}
void
CPlaneBanner::Render(void)
{
int i;
if(m_pos[0].z > -50.0f){
float camDist = (TheCamera.GetPosition() - m_pos[0]).Magnitude();
if(TheCamera.IsSphereVisible(m_pos[4], 32.0f) && camDist < 300.0f){
TempBufferVerticesStored = 0;
TempBufferIndicesStored = 0;
int alpha = camDist < 250.0f ? 160 : (300.0f-camDist)/(300.0f-250.0f)*160;
TempBufferVerticesStored += 2;
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[0], 255, 255, 255, alpha);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[1], 255, 255, 255, alpha);
RwIm3DVertexSetPos(&TempBufferRenderVertices[0], m_pos[2].x, m_pos[2].y, m_pos[2].z);
RwIm3DVertexSetPos(&TempBufferRenderVertices[1], m_pos[2].x, m_pos[2].y, m_pos[2].z - 4.0f);
RwIm3DVertexSetU(&TempBufferRenderVertices[0], 0.0f);
RwIm3DVertexSetV(&TempBufferRenderVertices[0], 0.0f);
RwIm3DVertexSetU(&TempBufferRenderVertices[1], 0.0f);
RwIm3DVertexSetV(&TempBufferRenderVertices[1], 1.0f);
for(i = 2; i < 8; i++){
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+0], 255, 255, 255, alpha);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+1], 255, 255, 255, alpha);
RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+0], m_pos[i].x, m_pos[i].y, m_pos[i].z);
RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+1], m_pos[i].x, m_pos[i].y, m_pos[i].z - 4.0f);
RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored+0], (i-2)/5.0f);
RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored+0], 0.0f);
RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored+1], (i-2)/5.0f);
RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored+1], 1.0f);
TempBufferRenderIndexList[TempBufferIndicesStored+0] = TempBufferVerticesStored-2;
TempBufferRenderIndexList[TempBufferIndicesStored+1] = TempBufferVerticesStored-1;
TempBufferRenderIndexList[TempBufferIndicesStored+2] = TempBufferVerticesStored+1;
TempBufferRenderIndexList[TempBufferIndicesStored+3] = TempBufferVerticesStored-2;
TempBufferRenderIndexList[TempBufferIndicesStored+4] = TempBufferVerticesStored+1;
TempBufferRenderIndexList[TempBufferIndicesStored+5] = TempBufferVerticesStored;
TempBufferVerticesStored += 2;
TempBufferIndicesStored += 6;
}
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE);
RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpRubbishTexture[2]));
#ifdef FIX_BUGS
if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXXYZ|rwIM3D_VERTEXUV)){
#else
if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, 0)){
#endif
RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored);
RwIm3DEnd();
}
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE);
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE);
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE);
TempBufferVerticesStored = 0;
TempBufferIndicesStored = 0;
}
}
}
void
CPlaneBanner::RegisterPoint(CVector pos)
{
m_pos[0] = pos;
}
void
CPlaneBanners::Init(void)
{
int i;
for(i = 0; i < ARRAY_SIZE(aArray); i++)
aArray[i].Init();
}
void
CPlaneBanners::Update(void)
{
int i;
for(i = 0; i < ARRAY_SIZE(aArray); i++)
aArray[i].Update();
}
void
CPlaneBanners::Render(void)
{
int i;
for(i = 0; i < ARRAY_SIZE(aArray); i++)
aArray[i].Render();
}
void
CPlaneBanners::RegisterPoint(CVector pos, uint32 id)
{
aArray[id].RegisterPoint(pos);
}
bool CSmokeTrails::CigOn = false;
CSmokeTrail CSmokeTrails::aSmoke[3];
@ -113,7 +387,9 @@ CMovingThing CMovingThings::aMovingThings[NUMMOVINGTHINGS];
void CMovingThings::Init()
{
CPlaneTrails::Init();
CSmokeTrails::Init();
CPlaneBanners::Init();
StartCloseList.m_pNext = &CMovingThings::EndCloseList;
StartCloseList.m_pPrev = nil;
@ -162,14 +438,19 @@ void CMovingThings::Shutdown()
int i;
for (i = 0; i < ARRAY_SIZE(aScrollBars); ++i)
aScrollBars[i].SetVisibility(false);
/*
for (i = 0; i < ARRAY_SIZE(aTowerClocks); ++i)
aTowerClocks[i].SetVisibility(false);
for (i = 0; i < ARRAY_SIZE(aDigitalClocks); ++i)
aDigitalClocks[i].SetVisibility(false);
*/
}
void CMovingThings::Update()
{
CPlaneBanners::Update();
CPlaneTrails::Update();
const int TIME_SPAN = 64; // frames to process all aMovingThings
int16 i;
@ -214,6 +495,7 @@ void CMovingThings::Render()
if (aScrollBars[i].IsVisible())
aScrollBars[i].Render();
}
/*
for (i = 0; i < ARRAY_SIZE(aTowerClocks); ++i)
{
if (aTowerClocks[i].IsVisible())
@ -224,8 +506,11 @@ void CMovingThings::Render()
if (aDigitalClocks[i].IsVisible())
aDigitalClocks[i].Render();
}
*/
CPlaneTrails::Render();
CSmokeTrails::Render();
CPlaneBanners::Render();
}
// ---------- CMovingThing ----------
@ -934,7 +1219,6 @@ CSmokeTrails::Render(void) {
void
CSmokeTrail::Render(void) {
int numVerts = 0;
RwIm3DVertex TempVertexBuffer[16];
if (TheCamera.IsSphereVisible(m_pos[0], 10.0f)) {
for (int32 i = 0; i < 16; i++) {
@ -949,8 +1233,8 @@ CSmokeTrail::Render(void) {
float posX = (m_pos[i].x + timeSinceSpawned * RandomSmoke[(i - m_seed) & 0xF] * 0.00001f) - offset;
float posY = (m_pos[i].y + timeSinceSpawned * RandomSmoke[(i - m_seed + 5) & 0xF] * 0.00001f) - offset;
float posZ = m_pos[i].z + timeSinceSpawned * 0.0004f;
RwIm3DVertexSetRGBA(&TempVertexBuffer[i], 200, 200, 200, alpha);
RwIm3DVertexSetPos(&TempVertexBuffer[i], posX, posY, posZ);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[i], 200, 200, 200, alpha);
RwIm3DVertexSetPos(&TempBufferRenderVertices[i], posX, posY, posZ);
numVerts++;
}
}
@ -962,7 +1246,7 @@ CSmokeTrail::Render(void) {
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil);
if (RwIm3DTransform(TempVertexBuffer, numVerts, nil, rwIM3D_VERTEXXYZ | rwIM3D_VERTEXRGBA)) {
if (RwIm3DTransform(TempBufferRenderVertices, numVerts, nil, rwIM3D_VERTEXXYZ | rwIM3D_VERTEXRGBA)) {
RwIm3DRenderIndexedPrimitive(rwPRIMTYPEPOLYLINE, SmokeTrailIndices, 2 * (numVerts - 1));
RwIm3DEnd();
}
@ -994,13 +1278,12 @@ CSmokeTrails::Update(void) {
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil);
RwIm3DVertex TempVertexBuffer[2];
RwIm3DVertexSetRGBA(&TempVertexBuffer[0], 255, 255, 255, 255);
RwIm3DVertexSetPos(&TempVertexBuffer[0], startPos.x, startPos.y, startPos.z);
RwIm3DVertexSetRGBA(&TempVertexBuffer[1], 255, 255, 255, 255);
RwIm3DVertexSetPos(&TempVertexBuffer[1], endPos.x, endPos.y, endPos.z);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[0], 255, 255, 255, 255);
RwIm3DVertexSetPos(&TempBufferRenderVertices[0], startPos.x, startPos.y, startPos.z);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[1], 255, 255, 255, 255);
RwIm3DVertexSetPos(&TempBufferRenderVertices[1], endPos.x, endPos.y, endPos.z);
if (RwIm3DTransform(TempVertexBuffer, 2, nil, rwIM3D_VERTEXXYZ | rwIM3D_VERTEXRGBA)) {
if (RwIm3DTransform(TempBufferRenderVertices, 2, nil, rwIM3D_VERTEXXYZ | rwIM3D_VERTEXRGBA)) {
RwIm3DRenderIndexedPrimitive(rwPRIMTYPEPOLYLINE, SmokeTrailIndices, 2);
RwIm3DEnd();
}

View File

@ -2,6 +2,70 @@
#include "common.h"
#include "Vector.h"
// TODO
class CScriptPath
{
public:
};
// TODO
class CScriptPaths
{
public:
};
class CPlaneTrail
{
CVector m_pos[16];
int32 m_time[16];
public:
void Init(void);
void Render(float visibility);
void RegisterPoint(CVector pos);
};
class CPlaneTrails
{
static CPlaneTrail aArray[6]; // NB: 3 CPlanes and 3 hardcoded far away ones
public:
static void Init(void);
static void Update(void);
static void Render(void);
static void RegisterPoint(CVector pos, uint32 id);
};
class CPlaneBanner
{
CVector m_pos[8];
public:
void Init(void);
void Update(void);
void Render(void);
void RegisterPoint(CVector pos);
};
class CPlaneBanners
{
static CPlaneBanner aArray[5];
public:
static void Init(void);
static void Update(void);
static void Render(void);
static void RegisterPoint(CVector pos, uint32 id);
};
// TODO
class CEscalators
{
public:
};
// TODO
class CEscalator
{
public:
};
class CMovingThing
{
public:

View File

@ -5,8 +5,7 @@
int32 TempBufferVerticesStored;
int32 TempBufferIndicesStored;
RwIm3DVertex TempBufferRenderVertices[TEMPBUFFERVERTSIZE];
RwIm2DVertex *TempVertexBuffer = (RwIm2DVertex*)TempBufferRenderVertices;
VertexBufferUnion TempVertexBuffer;
RwImVertexIndex TempBufferRenderIndexList[TEMPBUFFERINDEXSIZE];
int RenderBuffer::VerticesToBeStored;

View File

@ -12,8 +12,14 @@ public:
#define TEMPBUFFERVERTSIZE 512
#define TEMPBUFFERINDEXSIZE 1024
struct VertexBufferUnion
{
RwIm2DVertex im2d[TEMPBUFFERVERTSIZE];
RwIm3DVertex im3d[TEMPBUFFERVERTSIZE];
};
extern int32 TempBufferVerticesStored;
extern int32 TempBufferIndicesStored;
extern RwIm2DVertex *TempVertexBuffer;
extern RwIm3DVertex TempBufferRenderVertices[TEMPBUFFERVERTSIZE];
extern VertexBufferUnion TempVertexBuffer;
#define TempBufferRenderVertices (TempVertexBuffer.im3d)
extern RwImVertexIndex TempBufferRenderIndexList[TEMPBUFFERINDEXSIZE];

View File

@ -49,3 +49,5 @@ public:
static void Init(void);
static void Shutdown(void);
};
extern RwTexture *gpRubbishTexture[4];

View File

@ -432,7 +432,7 @@ void CSprite2d::Draw2DPolygon(float x1, float y1, float x2, float y2, float x3,
void
CSprite2d::AddToBuffer(const CRect &r, const CRGBA &c, float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2)
{
SetVertices(&TempVertexBuffer[nextBufferVertex], r, c, c, c, c, u0, v0, u1, v1, u3, v3, u2, v2);
SetVertices(&TempVertexBuffer.im2d[nextBufferVertex], r, c, c, c, c, u0, v0, u1, v1, u3, v3, u2, v2);
RwImVertexIndex *pIndexList = &TempBufferRenderIndexList[nextBufferIndex];
pIndexList[0] = nextBufferVertex;
pIndexList[1] = nextBufferVertex + 1;
@ -457,7 +457,7 @@ CSprite2d::RenderVertexBuffer()
{
if (nextBufferVertex > 0) {
RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR);
RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempVertexBuffer, nextBufferVertex, TempBufferRenderIndexList, nextBufferIndex);
RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempVertexBuffer.im2d, nextBufferVertex, TempBufferRenderIndexList, nextBufferIndex);
nextBufferVertex = 0;
nextBufferIndex = 0;
}

View File

@ -851,7 +851,7 @@ CBoat::BlowUpCar(CEntity *culprit)
bLightsOn = false;
ChangeLawEnforcerState(false);
CExplosion::AddExplosion(this, culprit, EXPLOSION_HELI, GetPosition(), 0);
CExplosion::AddExplosion(this, culprit, EXPLOSION_BOAT, GetPosition(), 0);
CDarkel::RegisterCarBlownUpByPlayer(this);
if(m_aBoatNodes[BOAT_MOVING] == nil)
return;

View File

@ -2,6 +2,7 @@
#include "main.h"
#include "General.h"
#include "CutsceneMgr.h"
#include "ModelIndices.h"
#include "FileMgr.h"
#include "Streaming.h"
@ -12,10 +13,13 @@
#include "Coronas.h"
#include "Particle.h"
#include "Explosion.h"
#include "Fluff.h"
#include "World.h"
#include "HandlingMgr.h"
#include "Plane.h"
//--MIAMI: file done
CPlaneNode *pPathNodes;
CPlaneNode *pPath2Nodes;
CPlaneNode *pPath3Nodes;
@ -39,12 +43,10 @@ CPlaneInterpolationLine aPlaneLineBits[6];
float PlanePathPosition[3];
float OldPlanePathPosition[3];
float PlanePathSpeed[3];
float PlanePath2Position[3];
float PlanePath3Position;
float PlanePath4Position;
float PlanePath2Speed[3];
float PlanePath3Speed;
float PlanePath4Speed;
float PlanePath2Position[5];
float PlanePath3Position[4];
float PlanePath2Speed[5];
float PlanePath3Speed[4];
enum
@ -62,7 +64,6 @@ int32 DropOffCesnaMissionStatus;
int32 DropOffCesnaMissionStartTime;
CPlane *pDropOffCesna;
CPlane::CPlane(int32 id, uint8 CreatedBy)
: CVehicle(CreatedBy)
{
@ -80,14 +81,13 @@ CPlane::CPlane(int32 id, uint8 CreatedBy)
m_bHasBeenHit = false;
m_bIsDrugRunCesna = false;
m_bIsDropOffCesna = false;
m_bTempPlane = false;
SetStatus(STATUS_PLANE);
bIsBIGBuilding = true;
m_level = LEVEL_GENERIC;
#ifdef FIX_BUGS
m_isFarAway = true;
#endif
m_isFarAway = false;
}
CPlane::~CPlane()
@ -123,6 +123,15 @@ CPlane::ProcessControl(void)
int i;
CVector pos;
if(CReplay::IsPlayingBack())
return;
if(GetModelIndex() == MI_AIRTRAIN){
if(GetPosition().z > 100.0f)
CPlaneTrails::RegisterPoint(GetPosition(), m_nPlaneId);
}else if(GetModelIndex() == MI_DEADDODO)
CPlaneBanners::RegisterPoint(GetPosition(), m_nPlaneId);
// Explosion
if(m_bHasBeenHit){
// BUG: since this is all based on frames, you can skip the explosion processing when you go into the menu
@ -154,7 +163,7 @@ CPlane::ProcessControl(void)
int f = ++nFrameGen & 3;
CParticle::AddParticle(PARTICLE_HELI_DEBRIS, GetMatrix() * CVector(0.0f, 0.0f, 0.0f), dir,
nil, CGeneral::GetRandomNumberInRange(0.1f, 1.0f),
colors[nFrameGen], rotSpeed, 0, f, 0);
colors[nFrameGen&7], rotSpeed, 0, f, 0);
}
}
if(frm >= 40 && frm <= 80 && frm & 1){
@ -197,17 +206,18 @@ CPlane::ProcessControl(void)
colors[6] = CRGBA(0, 0, 0, 255);
colors[7] = CRGBA(252, 66, 66, 255);
CVector dir;
for(i = 0; i < 40; i++){
dir.x = CGeneral::GetRandomNumberInRange(-2.0f, 2.0f);
dir.y = CGeneral::GetRandomNumberInRange(-2.0f, 2.0f);
dir.z = CGeneral::GetRandomNumberInRange(0.0f, 2.0f);
int rotSpeed = CGeneral::GetRandomNumberInRange(30.0f, 20.0f);
if(CGeneral::GetRandomNumber() & 1)
rotSpeed = -rotSpeed;
int f = ++nFrameGen & 3;
CParticle::AddParticle(PARTICLE_HELI_DEBRIS, GetMatrix() * CVector(0.0f, 0.0f, 0.0f),
CVector(CGeneral::GetRandomNumberInRange(-2.0f, 2.0f),
CGeneral::GetRandomNumberInRange(-2.0f, 2.0f),
CGeneral::GetRandomNumberInRange(0.0f, 2.0f)),
CParticle::AddParticle(PARTICLE_HELI_DEBRIS, GetMatrix() * CVector(0.0f, 0.0f, 0.0f), dir,
nil, CGeneral::GetRandomNumberInRange(0.1f, 1.0f),
colors[nFrameGen], rotSpeed, 0, f, 0);
colors[nFrameGen&7], rotSpeed, 0, f, 0);
}
}
if(frm >= 40 && frm <= 60 && frm & 1){
@ -226,7 +236,7 @@ CPlane::ProcessControl(void)
}
if(frm == 30)
bRenderScorched = true;
if(frm == 61){
if(frm == 62){
TheCamera.SetFadeColour(200, 200, 200);
TheCamera.Fade(0.0f, FADE_OUT);
TheCamera.ProcessFade();
@ -363,7 +373,7 @@ CPlane::ProcessControl(void)
CVector posFront2 = (1.0f - f)*pPathNodes[curPathNodeFront2].p + f*pPathNodes[nextPathNodeFront2].p;
// Now set matrix
GetMatrix().GetPosition() = (posRear + posFront) / 2.0f;
GetMatrix().SetTranslateOnly((posRear + posFront) / 2.0f);
GetMatrix().GetPosition().z += 4.3f;
CVector fwd = posFront - posRear;
fwd.Normalise();
@ -382,13 +392,12 @@ CPlane::ProcessControl(void)
GetMatrix().GetRight() = right;
GetMatrix().GetUp() = up;
GetMatrix().GetForward() = fwd;
// Set speed
m_vecMoveSpeed = fwd*PlanePathSpeed[m_nPlaneId]/60.0f;
m_fSpeed = PlanePathSpeed[m_nPlaneId]/60.0f;
m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f);
m_isFarAway = !((posFront - TheCamera.GetPosition()).Magnitude2D() < sq(300.0f));
m_isFarAway = !((posFront - TheCamera.GetPosition()).MagnitudeSqr2D() < sq(300.0f));
}else{
float planePathPosition;
float totalLengthOfFlightPath;
@ -396,26 +405,12 @@ CPlane::ProcessControl(void)
float planePathSpeed;
int numPathNodes;
if(m_bIsDrugRunCesna){
planePathPosition = PlanePath3Position;
if(GetModelIndex() == MI_CHOPPER){
planePathPosition = PlanePath3Position[m_nPlaneId];
totalLengthOfFlightPath = TotalLengthOfFlightPath3;
pathNodes = pPath3Nodes;
planePathSpeed = PlanePath3Speed;
planePathSpeed = PlanePath3Speed[m_nPlaneId];
numPathNodes = NumPath3Nodes;
if(CesnaMissionStatus == CESNA_STATUS_LANDED){
pDrugRunCesna = nil;
FlagToDestroyWhenNextProcessed();
}
}else if(m_bIsDropOffCesna){
planePathPosition = PlanePath4Position;
totalLengthOfFlightPath = TotalLengthOfFlightPath4;
pathNodes = pPath4Nodes;
planePathSpeed = PlanePath4Speed;
numPathNodes = NumPath4Nodes;
if(DropOffCesnaMissionStatus == CESNA_STATUS_LANDED){
pDropOffCesna = nil;
FlagToDestroyWhenNextProcessed();
}
}else{
planePathPosition = PlanePath2Position[m_nPlaneId];
totalLengthOfFlightPath = TotalLengthOfFlightPath2;
@ -484,7 +479,7 @@ CPlane::ProcessControl(void)
f = (pathPositionFront - pathNodes[curPathNodeFront].t)/dist;
CVector posFront = (1.0f - f)*pathNodes[curPathNodeFront].p + f*pathNodes[nextPathNodeFront].p;
// And for another point 60 units in front of the plane, used to calculate roll
// And for another point 30 units in front of the plane, used to calculate roll
float pathPositionFront2 = pathPositionFront + 30.0f;
if(pathPositionFront2 > totalLengthOfFlightPath)
pathPositionFront2 -= totalLengthOfFlightPath;
@ -515,7 +510,7 @@ CPlane::ProcessControl(void)
CVector posFront2 = (1.0f - f)*pathNodes[curPathNodeFront2].p + f*pathNodes[nextPathNodeFront2].p;
// Now set matrix
GetMatrix().GetPosition() = (posRear + posFront) / 2.0f;
GetMatrix().SetTranslateOnly((posRear + posFront) / 2.0f);
GetMatrix().GetPosition().z += 1.0f;
CVector fwd = posFront - posRear;
fwd.Normalise();
@ -535,7 +530,7 @@ CPlane::ProcessControl(void)
m_fSpeed = planePathSpeed/60.0f;
m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f);
m_isFarAway = !((posFront - TheCamera.GetPosition()).Magnitude2D() < sq(300.0f));
m_isFarAway = !((posFront - TheCamera.GetPosition()).MagnitudeSqr2D() < sq(300.0f));
}
}
@ -639,7 +634,8 @@ CPlane::PreRender(void)
void
CPlane::Render(void)
{
CEntity::Render();
if(!CCutsceneMgr::IsRunning())
CEntity::Render();
}
#define CRUISE_SPEED (50.0f)
@ -657,11 +653,9 @@ CPlane::InitPlanes(void)
pPathNodes = LoadPath("data\\paths\\flight.dat", NumPathNodes, TotalLengthOfFlightPath, true);
// Figure out which nodes are on ground
CColPoint colpoint;
CEntity *entity;
for(i = 0; i < NumPathNodes; i++){
if(CWorld::ProcessVerticalLine(pPathNodes[i].p, 1000.0f, colpoint, entity, true, false, false, false, true, false, nil)){
pPathNodes[i].p.z = colpoint.point.z;
if(pPathNodes[i].p.z < 14.0f){
pPathNodes[i].p.z = 14.0f;
pPathNodes[i].bOnGround = true;
}else
pPathNodes[i].bOnGround = false;
@ -688,7 +682,7 @@ CPlane::InitPlanes(void)
aPlaneLineBits[0].position = position;
aPlaneLineBits[0].speed = TAXI_SPEED;
aPlaneLineBits[0].acceleration = 0.0f;
float dist = (TakeOffPoint-600.0f) - position;
float dist = (TakeOffPoint-500.0f) - position;
time += dist/TAXI_SPEED;
position += dist;
@ -697,9 +691,9 @@ CPlane::InitPlanes(void)
aPlaneLineBits[1].time = time;
aPlaneLineBits[1].position = position;
aPlaneLineBits[1].speed = TAXI_SPEED;
aPlaneLineBits[1].acceleration = 33.0f/32.0f;
time += 600.0f/((CRUISE_SPEED+TAXI_SPEED)/2.0f);
position += 600.0f;
aPlaneLineBits[1].acceleration = 618.75f/500.0f;
time += 500.0f/((CRUISE_SPEED+TAXI_SPEED)/2.0f);
position += 500.0f;
// Fly at cruise speed
aPlaneLineBits[2].type = 1;
@ -716,9 +710,9 @@ CPlane::InitPlanes(void)
aPlaneLineBits[3].time = time;
aPlaneLineBits[3].position = position;
aPlaneLineBits[3].speed = CRUISE_SPEED;
aPlaneLineBits[3].acceleration = -33.0f/32.0f;
time += 600.0f/((CRUISE_SPEED+TAXI_SPEED)/2.0f);
position += 600.0f;
aPlaneLineBits[3].acceleration = -618.75f/500.0f;
time += 500.0f/((CRUISE_SPEED+TAXI_SPEED)/2.0f);
position += 500.0f;
// Taxi
aPlaneLineBits[4].type = 1;
@ -739,24 +733,17 @@ CPlane::InitPlanes(void)
TotalDurationOfFlightPath2 = TotalLengthOfFlightPath2/CRUISE_SPEED;
}
/*
// Mission Cesna
// Heli
if(pPath3Nodes == nil){
pPath3Nodes = LoadPath("data\\paths\\flight3.dat", NumPath3Nodes, TotalLengthOfFlightPath3, false);
TotalDurationOfFlightPath3 = TotalLengthOfFlightPath3/CRUISE_SPEED;
}
// Mission Cesna
if(pPath4Nodes == nil){
pPath4Nodes = LoadPath("data\\paths\\flight4.dat", NumPath4Nodes, TotalLengthOfFlightPath4, false);
TotalDurationOfFlightPath4 = TotalLengthOfFlightPath4/CRUISE_SPEED;
}
*/
CStreaming::LoadAllRequestedModels(false);
CStreaming::RequestModel(MI_AIRTRAIN, 0);
CStreaming::LoadAllRequestedModels(false);
// NB: 3 hardcoded also in CPlaneTrails
for(i = 0; i < 3; i++){
CPlane *plane = new CPlane(MI_AIRTRAIN, PERMANENT_VEHICLE);
plane->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f);
@ -766,20 +753,6 @@ CPlane::InitPlanes(void)
plane->m_nCurPathNode = 0;
CWorld::Add(plane);
}
CStreaming::RequestModel(MI_DEADDODO, 0);
CStreaming::LoadAllRequestedModels(false);
for(i = 0; i < 3; i++){
CPlane *plane = new CPlane(MI_DEADDODO, PERMANENT_VEHICLE);
plane->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f);
plane->SetStatus(STATUS_ABANDONED);
plane->bIsLocked = true;
plane->m_nPlaneId = i;
plane->m_nCurPathNode = 0;
CWorld::Add(plane);
}
}
void
@ -811,7 +784,6 @@ CPlane::LoadPath(char const *filename, int32 &numNodes, float &totalLength, bool
CPlaneNode *nodes = new CPlaneNode[numNodes];
for(i = 0; i < numNodes; i++){
*gString = '\0';
for(lp = 0; work_buff[bp] != '\n' && work_buff[bp] != '\0'; bp++, lp++)
gString[lp] = work_buff[bp];
bp++;
@ -833,6 +805,10 @@ CPlane::LoadPath(char const *filename, int32 &numNodes, float &totalLength, bool
return nodes;
}
int32 LastTimeInPlane, LastTimeNotInPlane;
bool bCesnasActivated;
bool bHelisActivated;
void
CPlane::UpdatePlanes(void)
{
@ -875,25 +851,87 @@ CPlane::UpdatePlanes(void)
t = TotalDurationOfFlightPath2/0x80000;
PlanePath2Position[0] = CRUISE_SPEED * (time & 0x7FFFF)*t;
PlanePath2Position[1] = CRUISE_SPEED * ((time + 0x80000/3) & 0x7FFFF)*t;
PlanePath2Position[2] = CRUISE_SPEED * ((time + 0x80000/3*2) & 0x7FFFF)*t;
PlanePath2Position[1] = CRUISE_SPEED * ((time + 0x80000/5) & 0x7FFFF)*t;
PlanePath2Position[2] = CRUISE_SPEED * ((time + 0x80000/5*2) & 0x7FFFF)*t;
PlanePath2Position[3] = CRUISE_SPEED * ((time + 0x80000/5*3) & 0x7FFFF)*t;
PlanePath2Position[4] = CRUISE_SPEED * ((time + 0x80000/5*4) & 0x7FFFF)*t;
PlanePath2Speed[0] = CRUISE_SPEED*t;
PlanePath2Speed[1] = CRUISE_SPEED*t;
PlanePath2Speed[2] = CRUISE_SPEED*t;
PlanePath2Speed[3] = CRUISE_SPEED*t;
PlanePath2Speed[4] = CRUISE_SPEED*t;
if(CesnaMissionStatus == CESNA_STATUS_FLYING){
PlanePath3Speed = CRUISE_SPEED*TotalDurationOfFlightPath3/0x20000;
PlanePath3Position = PlanePath3Speed * ((time - CesnaMissionStartTime) & 0x1FFFF);
if(time - CesnaMissionStartTime >= 128072)
CesnaMissionStatus = CESNA_STATUS_LANDED;
}
t = TotalDurationOfFlightPath3/0x80000;
PlanePath3Position[0] = CRUISE_SPEED * (time & 0x7FFFF)*t;
PlanePath3Position[1] = CRUISE_SPEED * ((time + 0x80000/4) & 0x7FFFF)*t;
PlanePath3Position[2] = CRUISE_SPEED * ((time + 0x80000/4*2) & 0x7FFFF)*t;
PlanePath3Position[3] = CRUISE_SPEED * ((time + 0x80000/4*3) & 0x7FFFF)*t;
PlanePath3Speed[0] = CRUISE_SPEED*t;
PlanePath3Speed[1] = CRUISE_SPEED*t;
PlanePath3Speed[2] = CRUISE_SPEED*t;
PlanePath3Speed[3] = CRUISE_SPEED*t;
if(DropOffCesnaMissionStatus == CESNA_STATUS_FLYING){
PlanePath4Speed = CRUISE_SPEED*TotalDurationOfFlightPath4/0x80000;
PlanePath4Position = PlanePath4Speed * ((time - DropOffCesnaMissionStartTime) & 0x7FFFF);
if(time - DropOffCesnaMissionStartTime >= 521288)
DropOffCesnaMissionStatus = CESNA_STATUS_LANDED;
if(FindPlayerVehicle() && (FindPlayerVehicle()->GetVehicleAppearance() == VEHICLE_APPEARANCE_HELI ||
FindPlayerVehicle()->GetVehicleAppearance() == VEHICLE_APPEARANCE_PLANE))
LastTimeInPlane = CTimer::GetTimeInMilliseconds();
else
LastTimeNotInPlane = CTimer::GetTimeInMilliseconds();
if(CTimer::GetTimeInMilliseconds() - LastTimeNotInPlane > 10000){
if(!bCesnasActivated){
if(CStreaming::HasModelLoaded(MI_DEADDODO)){
for(i = 0; i < 5; i++){
CPlane *plane = new CPlane(MI_DEADDODO, PERMANENT_VEHICLE);
plane->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f);
plane->SetStatus(STATUS_ABANDONED);
plane->bIsLocked = true;
plane->m_nPlaneId = i;
plane->m_nCurPathNode = 0;
plane->m_bTempPlane = true;
CWorld::Add(plane);
}
bCesnasActivated = true;
}else
CStreaming::RequestModel(MI_DEADDODO, 0);
}
if(!bHelisActivated){
if(CStreaming::HasModelLoaded(MI_CHOPPER)){
for(i = 0; i < 4; i++){
CPlane *plane = new CPlane(MI_CHOPPER, PERMANENT_VEHICLE);
plane->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f);
plane->SetStatus(STATUS_ABANDONED);
plane->bIsLocked = true;
plane->m_nPlaneId = i;
plane->m_nCurPathNode = 0;
plane->m_bTempPlane = true;
CWorld::Add(plane);
}
bHelisActivated = true;
}else
CStreaming::RequestModel(MI_CHOPPER, 0);
}
}else if(CTimer::GetTimeInMilliseconds() - LastTimeInPlane > 10000)
RemoveTemporaryPlanes();
}
void
CPlane::RemoveTemporaryPlanes(void)
{
int i;
if(!bHelisActivated && !bCesnasActivated)
return;
i = CPools::GetVehiclePool()->GetSize();
while(--i >= 0){
CPlane *plane = (CPlane*)CPools::GetVehiclePool()->GetSlot(i);
if(plane && plane->IsPlane() && plane->m_bTempPlane){
CWorld::Remove(plane);
delete plane;
}
}
bCesnasActivated = false;
bHelisActivated = false;
}
bool
@ -921,6 +959,7 @@ CPlane::TestRocketCollision(CVector *rocketPos)
return false;
}
//--MIAMI: unused
// BUG: not in CPlane in the game
void
CPlane::CreateIncomingCesna(void)
@ -944,6 +983,7 @@ CPlane::CreateIncomingCesna(void)
printf("CPlane::CreateIncomingCesna(void)\n");
}
//--MIAMI: unused
void
CPlane::CreateDropOffCesna(void)
{
@ -966,8 +1006,21 @@ CPlane::CreateDropOffCesna(void)
printf("CPlane::CreateDropOffCesna(void)\n");
}
//--MIAMI: all unused
const CVector CPlane::FindDrugPlaneCoordinates(void) { return pDrugRunCesna->GetPosition(); }
const CVector CPlane::FindDropOffCesnaCoordinates(void) { return pDropOffCesna->GetPosition(); }
bool CPlane::HasCesnaLanded(void) { return CesnaMissionStatus == CESNA_STATUS_LANDED; }
bool CPlane::HasCesnaBeenDestroyed(void) { return CesnaMissionStatus == CESNA_STATUS_DESTROYED; }
bool CPlane::HasDropOffCesnaBeenShotDown(void) { return DropOffCesnaMissionStatus == CESNA_STATUS_DESTROYED; }
void
CPlane::Load(void)
{
RemoveTemporaryPlanes();
}
void
CPlane::Save(void)
{
RemoveTemporaryPlanes();
}

View File

@ -29,7 +29,6 @@ struct CPlaneInterpolationLine
class CPlane : public CVehicle
{
public:
// 0x288
int16 m_nPlaneId;
int16 m_isFarAway;
int16 m_nCurPathNode;
@ -38,6 +37,7 @@ public:
bool m_bHasBeenHit;
bool m_bIsDrugRunCesna;
bool m_bIsDropOffCesna;
bool m_bTempPlane;
CPlane(int32 id, uint8 CreatedBy);
~CPlane(void);
@ -53,6 +53,7 @@ public:
static void InitPlanes(void);
static void Shutdown(void);
static CPlaneNode *LoadPath(char const *filename, int32 &numNodes, float &totalLength, bool loop);
static void RemoveTemporaryPlanes(void);
static void UpdatePlanes(void);
static bool TestRocketCollision(CVector *rocketPos);
static void CreateIncomingCesna(void);
@ -62,6 +63,8 @@ public:
static bool HasCesnaLanded(void);
static bool HasCesnaBeenDestroyed(void);
static bool HasDropOffCesnaBeenShotDown(void);
static void Load(void);
static void Save(void);
};
extern float LandingPoint;

View File

@ -170,6 +170,7 @@ CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionT
break;
case EXPLOSION_CAR:
case EXPLOSION_CAR_QUICK:
case EXPLOSION_BOAT:
explosion.m_fRadius = 9.0f;
explosion.m_fPower = 300.0f;
explosion.m_fStopTime = lifetime + CTimer::GetTimeInMilliseconds() + 4250;
@ -205,6 +206,7 @@ CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionT
}
break;
case EXPLOSION_HELI:
case EXPLOSION_HELI2:
explosion.m_fRadius = 6.0f;
explosion.m_fPower = 300.0f;
explosion.m_fStopTime = lifetime + CTimer::GetTimeInMilliseconds() + 750;

View File

@ -10,7 +10,9 @@ enum eExplosionType
EXPLOSION_ROCKET,
EXPLOSION_CAR,
EXPLOSION_CAR_QUICK,
EXPLOSION_BOAT,
EXPLOSION_HELI,
EXPLOSION_HELI2,
EXPLOSION_MINE,
EXPLOSION_BARREL,
EXPLOSION_TANK_GRENADE,