Refactor unit costs.

CorrectiveAction
sigonasr2 1 year ago
parent 2273d11ef6
commit e6b31af7de
  1. 4
      olcCodeJam2023Entry/Constant.cpp
  2. 2
      olcCodeJam2023Entry/Constant.h
  3. 94
      olcCodeJam2023Entry/Unit.cpp
  4. 12
      olcCodeJam2023Entry/Unit.h
  5. 65
      olcCodeJam2023Entry/VirusAttack.cpp
  6. 1
      olcCodeJam2023Entry/VirusAttack.h

@ -28,4 +28,6 @@ float CONSTANT::DEBUFFICON_LIFETIME=0.8;
float CONSTANT::COLLECTION_WAIT_TIME=8; float CONSTANT::COLLECTION_WAIT_TIME=8;
int CONSTANT::MEMORY_ALLOCATOR_COST=5; int CONSTANT::MEMORY_ALLOCATOR_COST=5;
float CONSTANT::UNIT_BUILD_TIME=10;

@ -33,4 +33,6 @@ public:
static float COLLECTION_WAIT_TIME; static float COLLECTION_WAIT_TIME;
static int MEMORY_ALLOCATOR_COST; static int MEMORY_ALLOCATOR_COST;
static float UNIT_BUILD_TIME;
}; };

@ -5,67 +5,42 @@
#include "DebuffIcon.h" #include "DebuffIcon.h"
#include "olcPGEX_QuickGUI.h" #include "olcPGEX_QuickGUI.h"
std::vector<Memory> BasicUnit::resourceCost={{HEALTH,4},{RANGE,2},{ATKSPD,2},{MOVESPD,3},{PROCEDURE,1}};
BasicUnit::BasicUnit(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) BasicUnit::BasicUnit(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit(pge,{ :Unit(pge,BasicUnit::resourceCost,pos,12,*IMAGES[VIRUS_IMG1],WHITE,WHITE,friendly,moveable){}
{HEALTH,4},
{RANGE,2},
{ATKSPD,2},
{MOVESPD,3},
{PROCEDURE,1},
},pos,12,*IMAGES[VIRUS_IMG1],WHITE,WHITE,friendly,moveable){}
void BasicUnit::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ void BasicUnit::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){
victim<<=1; victim<<=1;
} }
std::vector<Memory> BasicUnit2::resourceCost={{RANGE,2},{ATKSPD,2},{MOVESPD,3},{PROCEDURE,1},{HEALTH,4}};
BasicUnit2::BasicUnit2(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) BasicUnit2::BasicUnit2(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit(pge,{ :Unit(pge,BasicUnit2::resourceCost,pos,12,*IMAGES[VIRUS_IMG1],WHITE,WHITE,friendly,moveable){}
{RANGE,2},
{ATKSPD,2},
{MOVESPD,3},
{PROCEDURE,1},
{HEALTH,4},
},pos,12,*IMAGES[VIRUS_IMG1],WHITE,WHITE,friendly,moveable){}
void BasicUnit2::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ void BasicUnit2::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){
victim>>=1; victim>>=1;
} }
std::vector<Memory> LeftShifter::resourceCost={{RANGE,2},{ATKSPD,2},{MOVESPD,3},{PROCEDURE,1},{HEALTH,4}};
LeftShifter::LeftShifter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) LeftShifter::LeftShifter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit(pge,{ :Unit(pge,LeftShifter::resourceCost,pos,12,*IMAGES[LEFT_SHIFTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){}
{RANGE,2},
{ATKSPD,2},
{MOVESPD,3},
{PROCEDURE,1},
{HEALTH,4},
},pos,12,*IMAGES[LEFT_SHIFTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){}
void LeftShifter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ void LeftShifter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){
victim<<=1; victim<<=1;
} }
std::vector<Memory> RightShifter::resourceCost={{HEALTH,4},{RANGE,2},{ATKSPD,2},{MOVESPD,3},{PROCEDURE,1}};
RightShifter::RightShifter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) RightShifter::RightShifter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit(pge,{ :Unit(pge,RightShifter::resourceCost,pos,12,*IMAGES[RIGHT_SHIFTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){}
{HEALTH,4},
{RANGE,2},
{ATKSPD,2},
{MOVESPD,3},
{PROCEDURE,1},
},pos,12,*IMAGES[RIGHT_SHIFTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){}
void RightShifter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ void RightShifter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){
victim>>=1; victim>>=1;
} }
std::vector<Memory> BitRestorer::resourceCost={{PROCEDURE,6},{RANGE,1},{ATKSPD,1},{MOVESPD,1},{HEALTH,2}};
BitRestorer::BitRestorer(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) BitRestorer::BitRestorer(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit(pge,{ :Unit(pge,BitRestorer::resourceCost,pos,12,*IMAGES[BIT_RESTORER],CONSTANT::HEALER_TARGET_COL,CONSTANT::HEALER_ATTACK_COL,friendly,moveable,true,false){}
{PROCEDURE,6},
{RANGE,1},
{ATKSPD,1},
{MOVESPD,1},
{HEALTH,2},
},pos,12,*IMAGES[BIT_RESTORER],CONSTANT::HEALER_TARGET_COL,CONSTANT::HEALER_ATTACK_COL,friendly,moveable,true,false){}
void BitRestorer::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ void BitRestorer::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){
std::vector<int>emptyMemoryPositions; std::vector<int>emptyMemoryPositions;
@ -103,14 +78,9 @@ void BitRestorer::AttemptToHealOtherAllies(std::vector<std::shared_ptr<Unit>>&ot
} }
} }
std::vector<Memory> MemorySwapper::resourceCost={{RANGE,3},{ATKSPD,1},{HEALTH,3},{PROCEDURE,3},{MOVESPD,2}};
MemorySwapper::MemorySwapper(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) MemorySwapper::MemorySwapper(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit(pge,{ :Unit(pge,MemorySwapper::resourceCost,pos,12,*IMAGES[MEMORY_SWAPPER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable,true){
{RANGE,3},
{ATKSPD,1},
{HEALTH,3},
{PROCEDURE,3},
{MOVESPD,2},
},pos,12,*IMAGES[MEMORY_SWAPPER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable,true){
autoAcquireFriendlyTarget=false; autoAcquireFriendlyTarget=false;
} }
@ -118,14 +88,9 @@ void MemorySwapper::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherU
} }
std::vector<Memory> Corrupter::resourceCost={{ATKSPD,3},{RANGE,1},{PROCEDURE,8},{MOVESPD,4},{HEALTH,4}};
Corrupter::Corrupter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) Corrupter::Corrupter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit(pge,{ :Unit(pge,Corrupter::resourceCost,pos,12,*IMAGES[CORRUPTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){}
{ATKSPD,3},
{RANGE,1},
{PROCEDURE,8},
{MOVESPD,4},
{HEALTH,4},
},pos,12,*IMAGES[CORRUPTER],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,moveable){}
void Corrupter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ void Corrupter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){
//Chooses a bit at random and corrupts it. //Chooses a bit at random and corrupts it.
@ -133,14 +98,9 @@ void Corrupter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits
victim.memory[randomBit]=victim.ghostMemory[randomBit]=false; victim.memory[randomBit]=victim.ghostMemory[randomBit]=false;
} }
std::vector<Memory> MemoryAllocator::resourceCost={{RANGE,1},{ATKSPD,1},{MOVESPD,1},{PROCEDURE,1},{HEALTH,1}};
MemoryAllocator::MemoryAllocator(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) MemoryAllocator::MemoryAllocator(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit(pge,{ :Unit(pge,MemoryAllocator::resourceCost,pos,12,*IMAGES[UNIT_ALLOCATOR],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,true,false){
{RANGE,1},
{ATKSPD,1},
{MOVESPD,1},
{PROCEDURE,1},
{HEALTH,1},
},pos,12,*IMAGES[UNIT_ALLOCATOR],CONSTANT::ATTACKER_TARGET_COL,CONSTANT::ATTACKER_ATTACK_COL,friendly,true,false){
isAllocator=true; isAllocator=true;
} }
@ -148,14 +108,9 @@ void MemoryAllocator::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&othe
} }
std::vector<Memory> RAMBank::resourceCost={{RANGE,0},{ATKSPD,0},{MOVESPD,0},{PROCEDURE,25},{HEALTH,16}};
RAMBank::RAMBank(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly) RAMBank::RAMBank(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly)
:Unit(pge,{ :Unit(pge,RAMBank::resourceCost,pos,41,*IMAGES[RAM_BANK],WHITE,WHITE,friendly,false
{RANGE,0},
{ATKSPD,0},
{MOVESPD,0},
{PROCEDURE,25},
{HEALTH,16},
},pos,41,*IMAGES[RAM_BANK],WHITE,WHITE,friendly,false
,false,false ,false,false
),randomOffset({util::random(128),util::random(128)}),matrixImg(*IMAGES[MATRIX]), ),randomOffset({util::random(128),util::random(128)}),matrixImg(*IMAGES[MATRIX]),
originalImg(*IMAGES[RAM_BANK]){ originalImg(*IMAGES[RAM_BANK]){
@ -733,11 +688,11 @@ bool Unit::IsMoveable(){
} }
bool Unit::CanInteractWithAllies(){ bool Unit::CanInteractWithAllies(){
return friendlyInteractable&&attachedPoint.expired(); return friendlyInteractable&&attachedPoint.expired()&&buildTime<=0;
} }
bool Unit::CanInteractWithEnemies(){ bool Unit::CanInteractWithEnemies(){
return enemyInteractable&&attachedPoint.expired(); return enemyInteractable&&attachedPoint.expired()&&buildTime<=0;
} }
Renderable&Unit::GetImage(){ Renderable&Unit::GetImage(){
@ -753,7 +708,7 @@ bool Unit::AutoAcquiresFriendlyTargets(){
} }
bool Unit::CanMove(){ bool Unit::CanMove(){
return moveSpd.size>0&&attachedPoint.expired(); return moveSpd.size>0&&attachedPoint.expired()&&buildTime<=0;
} }
void Unit::SetTargetCollectionPoint(std::weak_ptr<CollectionPoint>targetCP,std::weak_ptr<Unit>self_ptr){ void Unit::SetTargetCollectionPoint(std::weak_ptr<CollectionPoint>targetCP,std::weak_ptr<Unit>self_ptr){
@ -795,5 +750,10 @@ bool Unit::ClickHandled(TileTransformedView&game,Resources&player_resources,std:
void Unit::UpdateGUIState(TileTransformedView&game,Resources&player_resources){}; void Unit::UpdateGUIState(TileTransformedView&game,Resources&player_resources){};
bool Unit::IsAllocator(){ bool Unit::IsAllocator(){
return isAllocator; return isAllocator&&attachedPoint.expired()&&buildTime<=0;
}
void Unit::SetBuildUnit(float buildTime,std::unique_ptr<Unit>finalUnit){
this->buildTime=buildTime;
this->buildTransformUnit=std::move(finalUnit);
} }

@ -74,6 +74,7 @@ public:
virtual void UpdateGUIState(TileTransformedView&game,Resources&player_resources); virtual void UpdateGUIState(TileTransformedView&game,Resources&player_resources);
virtual bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector<std::shared_ptr<Unit>>&units,std::map<Image,std::unique_ptr<Renderable>>&IMAGES); //If you return true here, then the left click does not pass back to the main Virus Attack class. virtual bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector<std::shared_ptr<Unit>>&units,std::map<Image,std::unique_ptr<Renderable>>&IMAGES); //If you return true here, then the left click does not pass back to the main Virus Attack class.
bool IsAllocator(); bool IsAllocator();
void SetBuildUnit(float buildTime,std::unique_ptr<Unit>finalUnit);
std::vector<bool>& operator <<=(const int n){ std::vector<bool>& operator <<=(const int n){
for(int i=0;i<GetMemorySize()-1;i++){ for(int i=0;i<GetMemorySize()-1;i++){
@ -135,47 +136,57 @@ private:
bool willAttachWhenReachingDestination=false; bool willAttachWhenReachingDestination=false;
std::weak_ptr<Unit>self_ptr; std::weak_ptr<Unit>self_ptr;
float collectionTime=0; float collectionTime=0;
float buildTime=0;
std::unique_ptr<Unit>buildTransformUnit;
}; };
struct BasicUnit:Unit{ struct BasicUnit:Unit{
BasicUnit(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true); BasicUnit(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override; void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override;
static std::vector<Memory> resourceCost;
}; };
struct BasicUnit2:Unit{ struct BasicUnit2:Unit{
BasicUnit2(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true); BasicUnit2(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override; void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override;
static std::vector<Memory> resourceCost;
}; };
struct LeftShifter:Unit{ struct LeftShifter:Unit{
LeftShifter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true); LeftShifter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override; void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override;
static std::vector<Memory> resourceCost;
}; };
struct RightShifter:Unit{ struct RightShifter:Unit{
RightShifter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true); RightShifter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override; void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override;
static std::vector<Memory> resourceCost;
}; };
struct BitRestorer:Unit{ struct BitRestorer:Unit{
BitRestorer(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true); BitRestorer(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override; void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override;
void AttemptToHealOtherAllies(std::vector<std::shared_ptr<Unit>>&otherUnits); void AttemptToHealOtherAllies(std::vector<std::shared_ptr<Unit>>&otherUnits);
static std::vector<Memory> resourceCost;
}; };
struct MemorySwapper:Unit{ struct MemorySwapper:Unit{
MemorySwapper(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true); MemorySwapper(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override; void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override;
static std::vector<Memory> resourceCost;
}; };
struct Corrupter:Unit{ struct Corrupter:Unit{
Corrupter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true); Corrupter(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override; void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override;
static std::vector<Memory> resourceCost;
}; };
struct MemoryAllocator:Unit{ struct MemoryAllocator:Unit{
MemoryAllocator(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true); MemoryAllocator(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override; void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override;
static std::vector<Memory> resourceCost;
}; };
struct RAMBank:Unit{ struct RAMBank:Unit{
@ -195,4 +206,5 @@ struct RAMBank:Unit{
bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector<std::shared_ptr<Unit>>&units,std::map<Image,std::unique_ptr<Renderable>>&IMAGES)override; bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector<std::shared_ptr<Unit>>&units,std::map<Image,std::unique_ptr<Renderable>>&IMAGES)override;
void UpdateGUIState(TileTransformedView&game,Resources&player_resources)override; void UpdateGUIState(TileTransformedView&game,Resources&player_resources)override;
void DrawHud(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES)override; void DrawHud(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES)override;
static std::vector<Memory> resourceCost;
}; };

@ -123,21 +123,57 @@ void VirusAttack::InitializeSounds(){
bool VirusAttack::UnitCreationClickHandled(){ bool VirusAttack::UnitCreationClickHandled(){
if(leftShifterButton->bPressed){ if(leftShifterButton->bPressed){
for(auto&u:units){
if(u->IsSelected()&&u->IsAllocator()&&CanAfford(LeftShifter::resourceCost)){
std::unique_ptr<LeftShifter>buildUnit=std::make_unique<LeftShifter>(this,u->GetPos(),IMAGES,u->IsFriendly());
u->SetBuildUnit(CONSTANT::UNIT_BUILD_TIME,std::move(buildUnit));
}
}
return true; return true;
} }
if(rightShifterButton->bPressed){ if(rightShifterButton->bPressed){
for(auto&u:units){
if(u->IsSelected()&&u->IsAllocator()&&CanAfford(RightShifter::resourceCost)){
std::unique_ptr<RightShifter>buildUnit=std::make_unique<RightShifter>(this,u->GetPos(),IMAGES,u->IsFriendly());
u->SetBuildUnit(CONSTANT::UNIT_BUILD_TIME,std::move(buildUnit));
}
}
return true; return true;
} }
if(bitRestorerButton->bPressed){ if(bitRestorerButton->bPressed){
for(auto&u:units){
if(u->IsSelected()&&u->IsAllocator()&&CanAfford(BitRestorer::resourceCost)){
std::unique_ptr<BitRestorer>buildUnit=std::make_unique<BitRestorer>(this,u->GetPos(),IMAGES,u->IsFriendly());
u->SetBuildUnit(CONSTANT::UNIT_BUILD_TIME,std::move(buildUnit));
}
}
return true; return true;
} }
if(memorySwapperButton->bPressed){ if(memorySwapperButton->bPressed){
for(auto&u:units){
if(u->IsSelected()&&u->IsAllocator()&&CanAfford(MemorySwapper::resourceCost)){
std::unique_ptr<MemorySwapper>buildUnit=std::make_unique<MemorySwapper>(this,u->GetPos(),IMAGES,u->IsFriendly());
u->SetBuildUnit(CONSTANT::UNIT_BUILD_TIME,std::move(buildUnit));
}
}
return true; return true;
} }
if(corrupterButton->bPressed){ if(corrupterButton->bPressed){
for(auto&u:units){
if(u->IsSelected()&&u->IsAllocator()&&CanAfford(Corrupter::resourceCost)){
std::unique_ptr<Corrupter>buildUnit=std::make_unique<Corrupter>(this,u->GetPos(),IMAGES,u->IsFriendly());
u->SetBuildUnit(CONSTANT::UNIT_BUILD_TIME,std::move(buildUnit));
}
}
return true; return true;
} }
if(platformButton->bPressed){ if(platformButton->bPressed){
for(auto&u:units){
if(u->IsSelected()&&u->IsAllocator()&&CanAfford(MemoryAllocator::resourceCost)){
std::unique_ptr<MemoryAllocator>buildUnit=std::make_unique<MemoryAllocator>(this,u->GetPos(),IMAGES,u->IsFriendly());
u->SetBuildUnit(CONSTANT::UNIT_BUILD_TIME,std::move(buildUnit));
}
}
return true; return true;
} }
return false; return false;
@ -153,6 +189,12 @@ void VirusAttack::HandleDraggingSelection(){
} }
} }
unitCreationList.DisplayAllControls(allocatorSelected); unitCreationList.DisplayAllControls(allocatorSelected);
leftShifterButton->Enable(CanAfford(LeftShifter::resourceCost));
rightShifterButton->Enable(CanAfford(RightShifter::resourceCost));
bitRestorerButton->Enable(CanAfford(BitRestorer::resourceCost));
memorySwapperButton->Enable(CanAfford(MemorySwapper::resourceCost));
corrupterButton->Enable(CanAfford(Corrupter::resourceCost));
platformButton->Enable(CanAfford(MemoryAllocator::resourceCost));
unitCreationList.Update(this); unitCreationList.Update(this);
if(GetMouse(0).bPressed){ if(GetMouse(0).bPressed){
if(NotClickingOnMinimap()){ if(NotClickingOnMinimap()){
@ -533,6 +575,29 @@ void VirusAttack::RenderFogOfWar(){
} }
} }
bool VirusAttack::CanAfford(std::vector<Memory>&unitCosts){
for(Memory&mem:unitCosts){
switch(mem.type){
case HEALTH:{
if(player_resources.health<mem.size)return false;
}break;
case ATKSPD:{
if(player_resources.atkSpd<mem.size)return false;
}break;
case MOVESPD:{
if(player_resources.moveSpd<mem.size)return false;
}break;
case RANGE:{
if(player_resources.range<mem.size)return false;
}break;
case PROCEDURE:{
if(player_resources.procedure<mem.size)return false;
}break;
}
}
return true;
}
int main() int main()
{ {
VirusAttack app; VirusAttack app;

@ -67,6 +67,7 @@ private:
void DrawResourceBar(); void DrawResourceBar();
bool UnitCreationClickHandled(); bool UnitCreationClickHandled();
void InitializeUnitCreationGUI(); void InitializeUnitCreationGUI();
bool CanAfford(std::vector<Memory>&unitCosts);
public: public:
VirusAttack(); VirusAttack();

Loading…
Cancel
Save