Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Jun 14, 2024
1 parent b803cf1 commit 317031d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/Scene/SandBoxScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <glm/glm.hpp>

#define DEBUG_KEY P
#define AI_CHEAT_KEY Q

class SandBoxScene : public Scene {
enum class Stages {
Expand Down
25 changes: 16 additions & 9 deletions src/AI/AIScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ void AIScript::Update() {
m_mainDeltaTime = 0;
if (m_buildingCDTime < 1.f) {
m_EnemyObjectManager->addTotalCurrency(m_buildingCost / (-1.f));
m_paid += m_buildingCost /m_buildingCDTime * (-1.f);
m_paid += m_buildingCost / m_buildingCDTime * (-1.f);
} else {
m_paid += m_buildingCost /m_buildingCDTime * (-1.f);
m_paid += m_buildingCost / m_buildingCDTime * (-1.f);
m_EnemyObjectManager->addTotalCurrency(m_buildingCost /
m_buildingCDTime * (-1.f));
}
Expand Down Expand Up @@ -116,22 +116,23 @@ void AIScript::setCDTime(float time, SpawnMode spawnMode, bool cheat) {
void AIScript::setCost(float cost, SpawnMode spawnMode) {
if (spawnMode == SpawnMode::AVATAR) {
m_avatarCost = cost;
if(m_EnemyObjectManager->getCheatMode()){
if (m_EnemyObjectManager->getCheatMode()) {
m_avatarCost = 1;
}
}
if (spawnMode == SpawnMode::BUILDINGS) {
m_buildingCost = cost;
m_paid = 0;
if(m_EnemyObjectManager->getCheatMode()){
if (m_EnemyObjectManager->getCheatMode()) {
m_buildingCost = 1;
}
}
}

void AIScript::buildBasic() {
if (m_selectedBuildingType != UnitType::NONE) {
if(m_selectedBuildingType != UnitType::ORE_REF && m_EnemyObjectManager->getTotalCurrency() > 2000+100-m_paid){
if (m_selectedBuildingType != UnitType::ORE_REF &&
m_EnemyObjectManager->getTotalCurrency() > 2000 + 100 - m_paid) {
spawnUnit();
}
return;
Expand All @@ -149,8 +150,8 @@ void AIScript::buildBasic() {
setCost(300, SpawnMode::BUILDINGS);
m_selectedBuildingType = UnitType::BARRACKS;
} else if (m_EnemyObjectManager->getUnitConstructCount(UnitType::ORE_REF) <
1 &&
m_EnemyObjectManager->getTotalCurrency() > 2000) {
1 &&
m_EnemyObjectManager->getTotalCurrency() > 2000) {
setCDTime(100.f, SpawnMode::BUILDINGS);
setCost(2000, SpawnMode::BUILDINGS);
m_selectedBuildingType = UnitType::ORE_REF;
Expand All @@ -177,7 +178,10 @@ void AIScript::buildADV() {

void AIScript::spawnUnit() {
if (m_selectedAvatarType != UnitType::NONE ||
m_EnemyObjectManager->getAvatarCount() > MAX_TROOPS_SIZE) {
m_EnemyObjectManager->getAvatarCount() > MAX_TROOPS_SIZE ||
m_EnemyObjectManager->getStructureManager()
->getStructureArray()
->ifBarrackBuilt() == false) {
return;
}
if (m_EnemyObjectManager->getAvatarCount() <= MAX_TROOPS_SIZE &&
Expand Down Expand Up @@ -216,7 +220,10 @@ void AIScript::UpdateSpawnScript(SpawnMode spawnMode) {
return;
}
if (m_selectedAvatarType == UnitType::INFANTRY) {
m_EnemyObjectManager->setBarrackWayPointByCell({m_baseCell.x-1+5*(m_EnemyObjectManager->getAvatarCount()%3),m_baseCell.y-1});
m_EnemyObjectManager->setBarrackWayPointByCell(
{m_baseCell.x - 1 +
5 * (m_EnemyObjectManager->getAvatarCount() % 3),
m_baseCell.y - 1});
m_EnemyObjectManager->spawnToWayPoint(m_selectedAvatarType,
HouseType::ENEMY);
setCost(0, SpawnMode::AVATAR);
Expand Down
2 changes: 1 addition & 1 deletion src/Scene/SandBoxScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void SandBoxScene::stageUpdate() {
if (m_stage == Stages::PLAYER_WON || m_stage == Stages::AI_WON) {
m_Text->Draw();
}
if (Util::Input::IsKeyPressed(Util::Keycode::DEBUG_KEY)) {
if (Util::Input::IsKeyPressed(Util::Keycode::AI_CHEAT_KEY)) {
m_EnemyObjectManager->setCheatMode(true);
}
}

0 comments on commit 317031d

Please sign in to comment.