|
|
|
@ -14,7 +14,7 @@ BasicUnit::BasicUnit(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES |
|
|
|
|
},pos,12,*IMAGES[VIRUS_IMG1],friendly,moveable){} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BasicUnit::Attack(Unit&victim){ |
|
|
|
|
void BasicUnit::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
victim<<=1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -27,7 +27,7 @@ BasicUnit2::BasicUnit2(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAG |
|
|
|
|
{HEALTH,4}, |
|
|
|
|
},pos,12,*IMAGES[VIRUS_IMG1],friendly,moveable){} |
|
|
|
|
|
|
|
|
|
void BasicUnit2::Attack(Unit&victim){ |
|
|
|
|
void BasicUnit2::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
victim>>=1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -40,7 +40,7 @@ LeftShifter::LeftShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IM |
|
|
|
|
{HEALTH,4}, |
|
|
|
|
},pos,12,*IMAGES[LEFT_SHIFTER],friendly,moveable){} |
|
|
|
|
|
|
|
|
|
void LeftShifter::Attack(Unit&victim){ |
|
|
|
|
void LeftShifter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
victim<<=1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -53,7 +53,7 @@ RightShifter::RightShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>& |
|
|
|
|
{PROCEDURE,1}, |
|
|
|
|
},pos,12,*IMAGES[RIGHT_SHIFTER],friendly,moveable){} |
|
|
|
|
|
|
|
|
|
void RightShifter::Attack(Unit&victim){ |
|
|
|
|
void RightShifter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
victim>>=1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -66,8 +66,38 @@ BitRestorer::BitRestorer(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IM |
|
|
|
|
{HEALTH,2}, |
|
|
|
|
},pos,12,*IMAGES[BIT_RESTORER],friendly,moveable,true,false){} |
|
|
|
|
|
|
|
|
|
void BitRestorer::Attack(Unit&victim){ |
|
|
|
|
void BitRestorer::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
std::vector<int>emptyMemoryPositions; |
|
|
|
|
for(int i=0;i<victim.GetMemorySize();i++){ |
|
|
|
|
if(!victim.memory[i]){ |
|
|
|
|
emptyMemoryPositions.emplace_back(i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(emptyMemoryPositions.size()==0){ |
|
|
|
|
//First see if we can find another damaged target, if we can, then we try healing them. Otherwise we exit.
|
|
|
|
|
AttemptToHealOtherAllies(otherUnits); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
int randomBit=emptyMemoryPositions[rand()%emptyMemoryPositions.size()]; |
|
|
|
|
victim.memory[randomBit]=victim.ghostMemory[randomBit]=true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void BitRestorer::AttemptToHealOtherAllies(std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
std::vector<int>emptyMemoryPositions; |
|
|
|
|
for(auto&u:otherUnits){ |
|
|
|
|
if(u->IsFriendly()&&InRange(u)){ |
|
|
|
|
for(int i=0;i<u->GetMemorySize();i++){ |
|
|
|
|
if(!u->memory[i]){ |
|
|
|
|
emptyMemoryPositions.emplace_back(i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(emptyMemoryPositions.size()!=0){ |
|
|
|
|
int randomBit=emptyMemoryPositions[rand()%emptyMemoryPositions.size()]; |
|
|
|
|
u->memory[randomBit]=u->ghostMemory[randomBit]=true; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MemorySwapper::MemorySwapper(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) |
|
|
|
@ -79,7 +109,7 @@ MemorySwapper::MemorySwapper(vf2d pos,std::map<Image,std::unique_ptr<Renderable> |
|
|
|
|
{MOVESPD,2}, |
|
|
|
|
},pos,12,*IMAGES[MEMORY_SWAPPER],friendly,moveable,true){} |
|
|
|
|
|
|
|
|
|
void MemorySwapper::Attack(Unit&victim){ |
|
|
|
|
void MemorySwapper::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -92,7 +122,7 @@ Corrupter::Corrupter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES |
|
|
|
|
{HEALTH,4}, |
|
|
|
|
},pos,12,*IMAGES[CORRUPTER],friendly,moveable){} |
|
|
|
|
|
|
|
|
|
void Corrupter::Attack(Unit&victim){ |
|
|
|
|
void Corrupter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -105,7 +135,7 @@ MemoryAllocator::MemoryAllocator(vf2d pos,std::map<Image,std::unique_ptr<Rendera |
|
|
|
|
{HEALTH,1}, |
|
|
|
|
},pos,12,*IMAGES[UNIT_ALLOCATOR],friendly,false,false){} |
|
|
|
|
|
|
|
|
|
void MemoryAllocator::Attack(Unit&victim){ |
|
|
|
|
void MemoryAllocator::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -127,7 +157,7 @@ RAMBank::RAMBank(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Ren |
|
|
|
|
pge->SetDrawTarget(nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RAMBank::Attack(Unit&victim){ |
|
|
|
|
void RAMBank::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -419,7 +449,7 @@ void Unit::SetPos(vf2d newPos){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Unit::AttemptAttack(Unit*unit){ |
|
|
|
|
void Unit::AttemptAttack(Unit*unit,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
if(reloadTimer>0)return; |
|
|
|
|
Unit*finalTarget=nullptr; |
|
|
|
|
if(unit!=nullptr){ |
|
|
|
@ -433,15 +463,15 @@ void Unit::AttemptAttack(Unit*unit){ |
|
|
|
|
} |
|
|
|
|
if(finalTarget!=nullptr){ |
|
|
|
|
if(InRange(finalTarget)){ |
|
|
|
|
_Attack(finalTarget); //Call the parent function first, followed by the child.
|
|
|
|
|
_Attack(finalTarget,otherUnits); //Call the parent function first, followed by the child.
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Unit::Update(PixelGameEngine*pge){} |
|
|
|
|
|
|
|
|
|
void Unit::_Attack(Unit*finalTarget){ |
|
|
|
|
Attack(*finalTarget); |
|
|
|
|
void Unit::_Attack(Unit*finalTarget,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
Attack(*finalTarget,otherUnits); |
|
|
|
|
reloadTimer=1.f/(GetAtkSpd()/2.f); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|