Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cheat #89

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion include/Mechanics/UnitManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <utility>


class UnitManager : public Player {
public:
UnitManager() {}
Expand Down Expand Up @@ -65,8 +66,13 @@ class UnitManager : public Player {
return m_AvatarManager->getAvatarSize();;
}

void setCheatMode(bool cheat){
m_cheat=cheat;
}


bool getCheatMode(){
return m_cheat;
}


private:
Expand All @@ -80,6 +86,7 @@ class UnitManager : public Player {
std::shared_ptr<MapClass> m_Map = std::make_shared<MapClass>();
float m_mainDeltaTime = 0;
Util::Time m_Time;
bool m_cheat=false;
};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_UNITMANAGER_HPP
2 changes: 2 additions & 0 deletions src/UI/IngameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ void IngamUI::ShowHeaderSection() {
if (ImGui::Button("Cheat Mode On")) {
// TODO inf money, speed build time and cant player unit health cant be
// damaged
m_gameObjectManager->setCheatMode(true);
}
if (ImGui::Button("Cheat Mode off")) {
// TODO
m_gameObjectManager->setCheatMode(false);
}

ImGui::PopFont();
Expand Down
41 changes: 30 additions & 11 deletions src/UI/UIScriptProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,26 @@ void UIScriptProcess::Update(bool queueContinue) {
}

float UIScriptProcess::GetStructureTime(UnitType type) {
float returnValue = 0.f;
if (type == UnitType::POWER_PLANT) {
return std::make_shared<PowerPlants>()->getBuildingTime();
returnValue = std::make_shared<PowerPlants>()->getBuildingTime();
}
if (type == UnitType::BARRACKS) {
return std::make_shared<Barracks>()->getBuildingTime();
returnValue = std::make_shared<Barracks>()->getBuildingTime();
}
if (type == UnitType::ORE_REF) {
return std::make_shared<OreRefinery>()->getBuildingTime();
returnValue = std::make_shared<OreRefinery>()->getBuildingTime();
}
if (type == UnitType::WAR_FACT) {
return std::make_shared<WarFactory>()->getBuildingTime();
returnValue = std::make_shared<WarFactory>()->getBuildingTime();
}
if (type == UnitType::ADV_POWER_PLANT) {
return std::make_shared<ADVPowerPlants>()->getBuildingTime();
returnValue = std::make_shared<ADVPowerPlants>()->getBuildingTime();
}
if(m_gameObjectManager->getCheatMode()){
returnValue *=0.01;
}
return returnValue;
}

void UIScriptProcess::SetIfFinished(UnitType type, bool value) {
Expand Down Expand Up @@ -218,6 +223,9 @@ void UIScriptProcess::AddToSpawnQueue(UnitType type) {
float UIScriptProcess::GetSpawnTime(UnitType type) {
switch (type) {
case UnitType::INFANTRY: {
if(m_gameObjectManager->getCheatMode()){
return 0.1F;
}
return 5.F;
}
}
Expand Down Expand Up @@ -247,22 +255,33 @@ float UIScriptProcess::GetSpawnCountDownTime() {
}
}
int UIScriptProcess::GetObjCost(UnitType type) {
int returnValue = 0;
switch (type) {
case UnitType::BARRACKS:
return std::make_shared<Barracks>()->getBuildingCost();
returnValue = std::make_shared<Barracks>()->getBuildingCost();
break;
case UnitType::ORE_REF:
return std::make_shared<OreRefinery>()->getBuildingCost();
returnValue = std::make_shared<OreRefinery>()->getBuildingCost();
break;
case UnitType::POWER_PLANT:
return std::make_shared<PowerPlants>()->getBuildingCost();
returnValue = std::make_shared<PowerPlants>()->getBuildingCost();
break;
case UnitType::WAR_FACT:
return std::make_shared<WarFactory>()->getBuildingCost();
returnValue = std::make_shared<WarFactory>()->getBuildingCost();
break;
case UnitType::ADV_POWER_PLANT:
return std::make_shared<ADVPowerPlants>()->getBuildingCost();
returnValue = std::make_shared<ADVPowerPlants>()->getBuildingCost();
break;
case UnitType::INFANTRY:
return 100;
returnValue = 100;
break;
default:
// Handle the case when type doesn't match any of the options
// For example, you might throw an exception or set a default value
break;
}
if(m_gameObjectManager->getCheatMode()){
return 1;
}
return returnValue;
}
Loading