3 #include "../MathUtilities.h" 14 for (
t = 0;
t < MAX_WEAPONS;
t++)
29 bool senddamage =
false;
89 for (
t = 0;
t < MAX_WEAPONS;
t++)
96 if (D3DXVec3Length(&cross) > D3DXVec3Length(&
weaponarray[
t].velleft))
103 if (D3DXVec3Length(&cross) > D3DXVec3Length(&
weaponarray[
t].posleft))
114 D3DXVECTOR3 proposed;
115 proposed.x =
static_cast<float>(proposedx);
116 proposed.y =
static_cast<float>(proposedy);
117 proposed.z =
static_cast<float>(proposedz);
119 #pragma region Collision Detection (Weapons) 122 D3DXVECTOR3 location;
131 D3DXVECTOR3 dockoffset = proposed;
132 if (D3DXVec3Length(&dockoffset) <=
allobjects[
s].bound)
140 D3DXVec3Add(&result, &
allobjects[
s].componentarray[
r].nominalxyz, &result);
144 D3DXVec3Subtract(&cross, &location, &dockoffset);
146 if (D3DXVec3Length(&cross) <=
allobjects[
s].componentarray[
r].boundsphere)
173 for (
s = 0;
s < MAX_SCAN;
s++)
188 result.x = result.y = result.z = 999.0f;
201 location = D3DXVECTOR3(0, 0, 0);
202 D3DXVec3TransformCoord(&location, &location, &
playerships[
s].componentarray[
r].matWorld);
209 if (D3DXVec3Length(&cross) >=
playerships[
s].componentarray[
r].boundsphere)
221 sprintf_s(msg, 99,
"Vehicle Elapsed %i",
s);
226 sprintf_s(msg, 99,
"Vehicle NotOrigin %i",
s);
233 proposed = D3DXVECTOR3(static_cast<float>(proposedx), static_cast<float>(proposedy), static_cast<float>(proposedz));
252 for (
s = 0;
s < MAX_WEAPONS;
s++)
264 D3DXVec3Subtract(&result, &result, &proposed);
265 if (D3DXVec3Length(&result) < 0.001f)
291 if (wtcp.u >= 0 && wtcp.u <= 62 && wtcp.v >= 0 && wtcp.v <= 62)
295 float buildingAGL, buildingBGL;
298 float f_tempu, f_tempv, f_tempd;
299 D3DXVECTOR3 result = -proposed;
300 D3DXVec3Normalize(&result, &result);
305 if (buildZoneOrdinal != -1)
340 if (wtcp.u > 15 && wtcp.u < 48 && wtcp.v>15 && wtcp.v < 48)
349 if (buildZoneOrdinal != -1)
351 D3DXVECTOR3 oldpos, result1, result2, result3;
356 D3DXVec3Normalize(&newpos, &newpos);
358 V(
buildzone[buildZoneOrdinal].VB->Lock(0, 0, reinterpret_cast<void**>(&wepverts), D3DLOCK_READONLY));
365 if (
buildzone[buildZoneOrdinal].componentarray[
s].type != 8)
368 result1.x = (*(wepverts + offset)).x;
369 result1.y = (*(wepverts + offset)).y;
370 result1.z = (*(wepverts + offset)).z;
372 result2.x = (*(wepverts + offset)).x;
373 result2.y = (*(wepverts + offset)).y;
374 result2.z = (*(wepverts + offset)).z;
376 result3.x = (*(wepverts + offset)).x;
377 result3.y = (*(wepverts + offset)).y;
378 result3.z = (*(wepverts + offset)).z;
382 if (D3DXIntersectTri(&result1, &result2, &result3, &oldpos, &newpos, &pu, &pv, &dist))
387 sprintf_s(msg,
sizeof(msg),
"Weapon %i hit polygon %i of module %i at %f %f (dist %f)",
t,
r,
s, pu, pv, dist);
396 r = (
unsigned short)
buildzone[buildZoneOrdinal].componentarray[
s].primitives;
404 V(
buildzone[buildZoneOrdinal].VB->Unlock());
411 weaponAGL = D3DXVec3Length(&proposed) - weaponAGL;
412 if (weaponAGL < buildingBGL && buildingBGL != 255.0f)
414 if (weaponAGL <= buildingAGL)
463 for (
s = 0;
s < smoketrailC;
s++)
499 D3DXVec3Subtract(&cross, &proposed, &
playerships[0].position);
501 D3DXVec3Subtract(&cross, &proposed, &
playerships[0].dockoffset);
503 float f_temp = D3DXVec3Length(&cross);
506 if (f_temp < furthest)
511 else if (f_temp > 60.0f)
546 weapcol.x = 0.25f * invAnimate;
547 weapcol.y = 0.5f * invAnimate;
548 weapcol.z = 0.5f * invAnimate;
553 weapcol.x = 1.0f * invAnimate;
554 weapcol.y = 0.36f * invAnimate;
555 weapcol.z = 0.35f * invAnimate;
561 weapcol.x = 1.0f * yieldMod * invAnimate * invAnimate;
562 weapcol.y = 0.5f * yieldMod * invAnimate * invAnimate;
563 const float allowBlue = min(0.0f, yieldMod - 1.0f);
564 weapcol.z = allowBlue * yieldMod * invAnimate* invAnimate;
571 weapcol.x = 0.25f; weapcol.y = 0.5f; weapcol.z = 0.5f;
575 weapcol.x = 1.0f; weapcol.y = 0.36f; weapcol.z = 0.35f;
579 weapcol.x = weapcol.y = weapcol.z = 0.0f;
592 D3DXVECTOR4 weappos = D3DXVECTOR4(0, 0, 0, 0);
606 float compare = 0.0f;
619 SWeaponPacket outpacket;
622 result.x = 0.0f; result.y = 0.0f; result.z = 0.5f;
623 D3DXVec3TransformNormal(&result, &result, &
playerships[0].matrixWorld);
633 outpacket.status = 1;
634 outpacket.array = 255;
641 outpacket.target = 0;
652 SWeaponPacket outpacket;
653 outpacket.status = 3;
661 outpacket.array =
static_cast<unsigned char>(
t);
674 sprintf_s(msg,
sizeof(msg),
"We sent that weapon %i exploded at %.3f %.3f %.3f (%s)",
t, outpacket.position.x, outpacket.position.y, outpacket.position.z, reason.c_str());
680 sprintf_s(msg,
sizeof(msg),
"Received that weapon %i exploded at %.3f %.3f %.3f (%s)",
t, static_cast<float>(
weaponarray[
t].precisionx), static_cast<float>(
weaponarray[
t].precisiony), static_cast<float>(
weaponarray[
t].precisionz), reason.c_str());
695 D3DXVECTOR3 difference;
701 D3DXVec3Subtract(&difference, &difference, &
playerships[0].position);
703 D3DXVec3Subtract(&difference, &difference, &
playerships[0].dockoffset);
704 const float distance = D3DXVec3Length(&difference);
707 sprintf_s(msg,
sizeof(msg),
"Explosion! Distance: %.3f", distance);
716 const float distNextSecond = D3DXVec3Length(&difference);
717 const float ourClosingRate = distance - distNextSecond;
719 if (ourClosingRate >= 0.001f)
721 sprintf_s(msg,
sizeof(msg),
"--- we are closing at %.3f kms", ourClosingRate);
724 else if (ourClosingRate <= 0.001f)
726 sprintf_s(msg,
sizeof(msg),
"--- we are distancing at %.3f kms", -ourClosingRate);
730 const float delay = distance / closingRate;
739 const float psi = powf(
weaponarray[
t].yieldKg * 0.000001f * 1.66667f / max(powf(distance, 3.0f), 0.000000001f), 0.6f);
744 const float yield = psi * 0.00178136f;
753 D3DXVec3Normalize(&shockWave.
shockmag, &difference);
754 D3DXMATRIX matrixInverse;
756 D3DXMatrixRotationQuaternion(&matrixInverse, &
playerships[0].orientation);
757 D3DXVec3TransformNormal(&shockWave.
shockmag, &shockWave.
shockmag, &matrixInverse);
761 sprintf_s(msg,
sizeof(msg),
"--- yield: %.1f kg, tti %.1f, psi: %.1f",
weaponarray[
t].yieldKg, shockWave.
timetoshock, psi);
768 sprintf_s(msg,
sizeof(msg),
"--- yield: %.1f kg, no shock wave, psi: %.1f",
weaponarray[
t].yieldKg, psi);
776 volume = powf(
weaponarray[
t].yieldKg, 0.333333f) * 0.120608f;
777 volume -= powf(distance, 2.0f) * 0.02161f;
779 sprintf_s(msg,
sizeof(msg),
"--- delay: %.3f, volume %.3f", delay, volume);
785 else if (volume <= 0)
803 D3DXMATRIX matrixTemp, matrixWorld;
809 for (
t = 0;
t < MAX_WEAPONS;
t++)
813 D3DXMatrixRotationZ(&matrixTemp, -D3DX_PI);
814 D3DXMatrixMultiply(&matrixWorld, &matrixTemp, matrixLookAtLocal);
816 D3DXMatrixScaling(&matrixTemp, 0.005f, 0.005f, 0.005f);
818 D3DXMatrixScaling(&matrixTemp, 0.06f, 0.06f, 0.06f);
822 float scale = powf(
weaponarray[
t].yieldKg, 0.333333f) * 0.00723648f;
826 D3DXMatrixScaling(&matrixTemp, scale, scale, scale);
828 D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
830 D3DXMatrixMultiply(&matrixTemp, &matrixTemp, &matrixWorld);
844 matrixTemp._41 = -result.x;
845 matrixTemp._42 = -result.y;
846 matrixTemp._43 = -result.z;
848 pd3dDevice->SetTransform(D3DTS_WORLD, &matrixTemp);
850 D3DXMatrixIdentity(&matrixTemp);
852 pd3dDevice->SetTransform(D3DTS_TEXTURE0, &matrixTemp);
853 pd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
857 pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
858 pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
860 pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
864 pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
865 pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
867 pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
871 pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
872 pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
874 pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
877 pd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
882 pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,
true);
883 pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
884 pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
885 pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);
895 for (
t = 0;
t < MAX_WEAPONS;
t++)
901 D3DXMatrixRotationZ(&matrixTemp, -D3DX_PI);
902 D3DXMatrixMultiply(&matrixWorld, &matrixTemp, matrixLookAtLocal);
903 D3DXMatrixScaling(&matrixTemp, 0.005f, 0.005f, 0.005f);
904 D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
911 D3DXVec3Normalize(&result, &result);
916 D3DXMatrixLookAtRH(&matrixWorld, &
centerC, &result1, &result);
917 D3DXMatrixRotationY(&matrixTemp, -D3DX_HALFPI);
918 D3DXMatrixMultiply(&matrixWorld, &matrixWorld, &matrixTemp);
919 D3DXMatrixInverse(&matrixWorld,
nullptr, &matrixWorld);
923 matrixTemp = matrixWorld;
937 matrixTemp._41 = -result.x;
938 matrixTemp._42 = -result.y;
939 matrixTemp._43 = -result.z;
951 if (
r == 0)
continue;
952 pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR,
r << 24);
954 pd3dDevice->SetTransform(D3DTS_WORLD, &matrixTemp);
960 pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
967 pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
971 pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,
false);
975 pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0,
polyobjects[13].polygons);
976 pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,
true);
986 const unsigned char slot = datapacket.array;
988 if (datapacket.status == 0)
994 if (datapacket.status == 1 || datapacket.status == 4)
1011 if (datapacket.origin)
1013 for (
short t = 0;
t < MAX_SCAN;
t++)
1044 if (datapacket.status != 4)
1046 for (
short t = 0;
t < MAX_SCAN;
t++)
1052 logger->
Log(
"Weapon::ProcessPacket Weapon launched!");
1053 if (datapacket.type == 1)
1055 else if (datapacket.type == 2)
1057 else if (datapacket.type == 3)
1063 float distance = D3DXVec3Length(&result);
1064 if (distance < 20.0f)
1066 float f_temp = distance / 20.0f;
1067 f_temp = 1.0f - f_temp;
1069 const float inverse_f_temp = 1.0f - f_temp;
1071 logger->
Log(
"Weapon::ProcessPacket Weapon detected!");
1075 if (datapacket.type == 1)
1077 else if (datapacket.type == 2)
1092 bool doItAnyway =
false;
1093 if (datapacket.status == 3 || datapacket.status == 4)
1105 if (datapacket.status == 2 || doItAnyway)
LPDIRECT3DTEXTURE9 m_pddsWeapon[weaponanimateC]
s_mesh_component * componentarray
weapon(Viewscreen *prtGame)
void EnergyWeaponImpact()
LPDIRECT3DTEXTURE9 m_pddsCityTexture[citytextureC]
LPDIRECT3DTEXTURE9 m_pddsSinker[weaponanimateC]
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
VECTOR2SHORT CalculateCGC(D3DXVECTOR3 position, char cube) const
s_network_objects playerships[MAX_SCAN]
bool IsUserColony() const
void ProcessPacket(SWeaponPacket datapacket)
#define weaponsinkerreadyC
float CheckDepthMap(VECTOR2SHORT newdepthpos, short u, short v)
propulsion * ptrPropulsion
s_universe_object allobjects[maxstarC]
void RequestScannerData() const
s_mesh_component * componentarray
float CheckFloorMap(VECTOR2SHORT newdepthpos, short u, short v)
void Update(float fElapsedTime)
LPDIRECT3DVOLUMETEXTURE9 m_pddsFuzerX
void Render(IDirect3DDevice9 *pd3dDevice, D3DXMATRIX *matrixLookAtLocal)
#define weaponlongarmreadyC
void ExplodeWeapon(short t, bool wasus, std::string reason)
void KillScannerData() const
float CalculateAGL(short u, short v, D3DXVECTOR3 position, bool makeleveler)
#define depthFloorResolutionC
BUILDZONE buildzone[buildingVBC]
void AddDelayedSound(int soundEnum, float delay, float volume=1.0f)
LPDIRECT3DVOLUMETEXTURE9 m_pddsSinkerX
const D3DXVECTOR3 centerC
float GetAttenuation(bool applyDensity) const
void Log(const char *msg, Level level=Info, int errorCode=0)
s_polygon_object polyobjects[maxpolyC]
std::vector< SShockWave > shockwaves
LPDIRECT3DVOLUMETEXTURE9 m_pddsBlastX
char CalculateCube(D3DXVECTOR3 position) const
#define weaponfuzerreadyC
unsigned short components
LOCALGRID2 gridarray[64][64]
void PlayEx(int soundEnum, bool loop, float volume=1.0f, float frequencyMod=1.0f, float pan=0.0f, bool restart=true)
unsigned short components
void AddToCallStack(const char *msg)
void FireWeapon(unsigned char bay) const
SWeaponData weaponarray[MAX_WEAPONS]
unsigned short components
LPDIRECT3DVERTEXBUFFER9 m_avSunVertices