Skip to content

Commit 77769fd

Browse files
committed
Disabling / enabling the range of cannons on the button. Different colors for loaded and unloaded sides
1 parent 7340ff2 commit 77769fd

File tree

3 files changed

+80
-71
lines changed

3 files changed

+80
-71
lines changed

src/libs/sea_ai/src/ai_ship_cannon_controller.cpp

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ float AIShipCannonController::fMaxCannonDamageRadiusPoint = 1.0f;
99

1010
int AIShipCannonController::ColorA = 0;
1111
int AIShipCannonController::ColorR = 0;
12+
int AIShipCannonController::ColorNA = 0;
13+
int AIShipCannonController::ColorNR = 0;
14+
bool AIShipCannonController::bShowCannonsRange = true;
1215

1316
AIShipCannonController::AIShipCannonController(AIShip *_pShip) : bReload(false), bNotEnoughBalls(false)
1417
{
@@ -563,75 +566,77 @@ void AIShipCannonController::Realize(float fDeltaTime)
563566
debugDrawToggle = !debugDrawToggle;
564567
std::this_thread::sleep_for(100ms);
565568
}
566-
569+
570+
if(!bShowCannonsRange) return;
571+
567572
if (debugDrawToggle)
568573
{
569-
for (auto it = debugFirePositions.begin(); it != debugFirePositions.end();)
570-
{
571-
constexpr auto kDebugFadeTime = 3.0f;
572-
if (auto &[pos, color, dt] = *it; dt <= kDebugFadeTime)
573-
{
574-
dt += fDeltaTime;
575-
576-
CVECTOR cPos;
577-
CVECTOR cAng;
578-
float cFov;
579-
AIHelper::pRS->GetCamera(cPos, cAng, cFov);
580-
581-
const auto dist = (pos - cPos).GetLength();
582-
583-
float radius = 0.3f;
584-
if (dist > 1.0f)
585-
{
586-
radius *= sqrtf(dist);
587-
}
588-
AIHelper::pRS->DrawSphere(pos, radius, color);
589-
++it;
590-
}
591-
else
592-
{
593-
it = debugFirePositions.erase(it);
594-
}
595-
}
596-
597-
static std::vector<RS_LINE> Lines;
598-
Lines.clear();
599-
600-
for (const auto &bort : aShipBorts)
601-
{
602-
for (const auto &cannon : bort.aCannons)
603-
{
604-
if (!cannon.isDamaged())
605-
{
606-
constexpr auto red = ARGB(0xFF, 0xDC, 0x14, 0x3C);
607-
constexpr auto green = ARGB(0xFF, 0x7C, 0xFC, 0x00);
608-
609-
const auto &&vPos = cannon.GetPos();
610-
Lines.emplace_back(RS_LINE{vPos, red});
611-
Lines.emplace_back(RS_LINE{vPos + 5.0f * cannon.GetDir(), red});
612-
Lines.emplace_back(RS_LINE{vPos, green});
613-
Lines.emplace_back(RS_LINE{vPos + CVECTOR{0.0f, cannon.GetDirY(), 0.0f}, green});
614-
}
615-
}
616-
}
617-
618-
if (!Lines.empty())
619-
{
620-
AIHelper::pRS->SetTransform(D3DTS_WORLD, CMatrix());
621-
AIHelper::pRS->DrawLines(Lines.data(), Lines.size() / 2, "Line");
622-
}
623-
624-
if (GetAIShip()->isMainCharacter())
625-
{
626-
std::string buf;
627-
for (const auto &bort : aShipBorts)
628-
{
629-
buf += fmt::format("{:.3f} ", GetBortHeightAngle(bort));
630-
}
631-
AIHelper::pRS->Print(200, 20, buf.c_str());
632-
}
574+
for (auto it = debugFirePositions.begin(); it != debugFirePositions.end();)
575+
{
576+
constexpr auto kDebugFadeTime = 3.0f;
577+
if (auto &[pos, color, dt] = *it; dt <= kDebugFadeTime)
578+
{
579+
dt += fDeltaTime;
580+
581+
CVECTOR cPos;
582+
CVECTOR cAng;
583+
float cFov;
584+
AIHelper::pRS->GetCamera(cPos, cAng, cFov);
585+
586+
const auto dist = (pos - cPos).GetLength();
587+
588+
float radius = 0.3f;
589+
if (dist > 1.0f)
590+
{
591+
radius *= sqrtf(dist);
592+
}
593+
AIHelper::pRS->DrawSphere(pos, radius, color);
594+
++it;
595+
}
596+
else
597+
{
598+
it = debugFirePositions.erase(it);
599+
}
600+
}
601+
602+
static std::vector<RS_LINE> Lines;
603+
Lines.clear();
604+
605+
for (const auto &bort : aShipBorts)
606+
{
607+
for (const auto &cannon : bort.aCannons)
608+
{
609+
if (!cannon.isDamaged())
610+
{
611+
constexpr auto red = ARGB(0xFF, 0xDC, 0x14, 0x3C);
612+
constexpr auto green = ARGB(0xFF, 0x7C, 0xFC, 0x00);
613+
614+
const auto &&vPos = cannon.GetPos();
615+
Lines.emplace_back(RS_LINE{vPos, red});
616+
Lines.emplace_back(RS_LINE{vPos + 5.0f * cannon.GetDir(), red});
617+
Lines.emplace_back(RS_LINE{vPos, green});
618+
Lines.emplace_back(RS_LINE{vPos + CVECTOR{0.0f, cannon.GetDirY(), 0.0f}, green});
619+
}
620+
}
621+
}
622+
623+
if (!Lines.empty())
624+
{
625+
AIHelper::pRS->SetTransform(D3DTS_WORLD, CMatrix());
626+
AIHelper::pRS->DrawLines(Lines.data(), Lines.size() / 2, "Line");
627+
}
628+
629+
if (GetAIShip()->isMainCharacter())
630+
{
631+
std::string buf;
632+
for (const auto &bort : aShipBorts)
633+
{
634+
buf += fmt::format("{:.3f} ", GetBortHeightAngle(bort));
635+
}
636+
AIHelper::pRS->Print(200, 20, buf.c_str());
637+
}
633638
}
634-
639+
635640
struct tr_vertex
636641
{
637642
CVECTOR vPos;
@@ -675,11 +680,11 @@ void AIShipCannonController::Realize(float fDeltaTime)
675680
RotateAroundY(v[2].x, v[2].z, vZ.z, vZ.x);
676681
v[2] += v[0];
677682

678-
if(debugDrawToggle) ColorA = ColorR = ARGB(0x0F, 0x90, 0xEE, 0x90);
683+
if(debugDrawToggle) ColorA = ColorR = ColorNA = ColorNR = ARGB(0x0F, 0x90, 0xEE, 0x90);
679684

680-
Verts.emplace_back(tr_vertex{v[0], static_cast<uint32_t>(ColorA)});
681-
Verts.emplace_back(tr_vertex{v[1], static_cast<uint32_t>(ColorR)});
682-
Verts.emplace_back(tr_vertex{v[2], static_cast<uint32_t>(ColorR)});
685+
Verts.emplace_back(tr_vertex{v[0], bort.isCharged() ? static_cast<uint32_t>(ColorA) : static_cast<uint32_t>(ColorNA)});
686+
Verts.emplace_back(tr_vertex{v[1], bort.isCharged() ? static_cast<uint32_t>(ColorR) : static_cast<uint32_t>(ColorNR)});
687+
Verts.emplace_back(tr_vertex{v[2], bort.isCharged() ? static_cast<uint32_t>(ColorR) : static_cast<uint32_t>(ColorNR)});
683688
}
684689
}
685690
}

src/libs/sea_ai/src/ai_ship_cannon_controller.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ class AIShipCannonController
151151
static float fMaxCannonDamageDistance;
152152
static float fMaxCannonDamageRadiusPoint;
153153

154-
static int ColorA, ColorR;
154+
static int ColorA, ColorR, ColorNA, ColorNR;
155+
static bool bShowCannonsRange;
155156

156157
void Save(CSaveLoad *pSL);
157158
void Load(CSaveLoad *pSL);

src/libs/sea_ai/src/sea_ai.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ uint64_t SEA_AI::ProcessMessage(MESSAGE &message)
343343
case AI_MESSAGE_CANNONS_RANGE:
344344
AIShipCannonController::ColorA = message.Long();
345345
AIShipCannonController::ColorR = message.Long();
346+
AIShipCannonController::ColorNA = message.Long();
347+
AIShipCannonController::ColorNR = message.Long();
348+
AIShipCannonController::bShowCannonsRange = (message.Long() != 0);
346349
break;
347350
// boal 08.08.06 method of recounting guns on the ship <--
348351
case AI_MESSAGE_SEASAVE: //TODO: check these two

0 commit comments

Comments
 (0)