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
|
#include "StdAfx.h"
#include "mmgr.h"
#include "FlareProjectile.h"
#include "Sim/Misc/GlobalSynced.h"
#include "Game/Camera.h"
#include "LogOutput.h"
#include "ProjectileHandler.h"
#include "Rendering/GL/myGL.h"
#include "Rendering/GL/VertexArray.h"
#include "Sim/Units/UnitDef.h"
#include "Sim/Units/Unit.h"
#include "WeaponProjectiles/MissileProjectile.h"
#include "GlobalUnsynced.h"
CR_BIND_DERIVED(CFlareProjectile, CProjectile, (float3(0,0,0),float3(0,0,0),0,0));
CR_REG_METADATA(CFlareProjectile,(
CR_SETFLAG(CF_Synced),
CR_MEMBER(activateFrame),
CR_MEMBER(deathFrame),
CR_MEMBER(numSub),
CR_MEMBER(lastSub),
CR_MEMBER(subPos),
CR_MEMBER(subSpeed),
CR_MEMBER(alphaFalloff),
CR_RESERVED(8)
));
CFlareProjectile::CFlareProjectile(const float3& pos, const float3& speed, CUnit* owner, int activateFrame GML_PARG_C):
//! these are synced, but neither weapon nor piece
//! (only created by units that can drop flares)
CProjectile(pos, speed, owner, true, false, false GML_PARG_P),
activateFrame(activateFrame),
deathFrame(activateFrame + (owner? owner->unitDef->flareTime: 1)),
numSub(0),
lastSub(0)
{
alphaFalloff = owner? 1.0f / owner->unitDef->flareTime: 1.0f;
checkCol = false;
useAirLos = true;
SetRadius(45);
subPos.resize(owner->unitDef->flareSalvoSize);
subSpeed.resize(owner->unitDef->flareSalvoSize);
mygravity *= 0.3f; //! flares fall slower
}
CFlareProjectile::~CFlareProjectile(void)
{
}
void CFlareProjectile::Update(void)
{
CUnit* owner = CProjectile::owner();
if (gs->frameNum == activateFrame) {
if (owner) {
pos = owner->pos;
speed = owner->speed;
speed += owner->rightdir * owner->unitDef->flareDropVector.x;
speed += owner->updir * owner->unitDef->flareDropVector.y;
speed += owner->frontdir * owner->unitDef->flareDropVector.z;
} else {
deleteMe = true;
}
}
if (gs->frameNum >= activateFrame) {
pos += speed;
speed *= 0.95f;
speed.y += mygravity;
//FIXME: just spawn new flares, if new missiles incoming?
if(owner && lastSub<(gs->frameNum - owner->unitDef->flareSalvoDelay) && numSub<owner->unitDef->flareSalvoSize){
subPos[numSub] = owner->pos;
float3 s=owner->speed;
s+=owner->rightdir*owner->unitDef->flareDropVector.x;
s+=owner->updir*owner->unitDef->flareDropVector.y;
s+=owner->frontdir*owner->unitDef->flareDropVector.z;
subSpeed[numSub] = s;
++numSub;
lastSub=gs->frameNum;
for(std::list<CMissileProjectile*>::iterator mi=owner->incomingMissiles.begin();mi!=owner->incomingMissiles.end();++mi){
if(gs->randFloat()<owner->unitDef->flareEfficiency){
CMissileProjectile* missile=*mi;
missile->decoyTarget=this;
missile->AddDeathDependence(this);
}
}
}
for (int a = 0; a < numSub; ++a) {
subPos[a] += subSpeed[a];
subSpeed[a] *= 0.95f;
subSpeed[a].y += mygravity;
}
}
if(gs->frameNum>=deathFrame)
deleteMe=true;
}
void CFlareProjectile::Draw(void)
{
if(gs->frameNum<=activateFrame)
return;
inArray=true;
unsigned char col[4];
float alpha=std::max(0.0f,1-(gs->frameNum-activateFrame)*alphaFalloff);
col[0]=(unsigned char)(alpha*255);
col[1]=(unsigned char)(alpha*0.5f)*255;
col[2]=(unsigned char)(alpha*0.2f)*255;
col[3]=1;
float rad=6.0;
va->EnlargeArrays(numSub*4,0,VA_SIZE_TC);
for(int a=0;a<numSub;++a){ //! CAUTION: loop count must match EnlargeArrays above
float3 interPos=subPos[a]+subSpeed[a]*gu->timeOffset;
va->AddVertexQTC(interPos-camera->right*rad-camera->up*rad,ph->flareprojectiletex.xstart,ph->flareprojectiletex.ystart,col);
va->AddVertexQTC(interPos+camera->right*rad-camera->up*rad,ph->flareprojectiletex.xend,ph->flareprojectiletex.ystart,col);
va->AddVertexQTC(interPos+camera->right*rad+camera->up*rad,ph->flareprojectiletex.xend,ph->flareprojectiletex.yend,col);
va->AddVertexQTC(interPos-camera->right*rad+camera->up*rad,ph->flareprojectiletex.xstart,ph->flareprojectiletex.yend,col);
}
}
|