|
|
|
@ -85,7 +85,7 @@ void BitRestorer::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUni |
|
|
|
|
void BitRestorer::AttemptToHealOtherAllies(std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
std::vector<int>emptyMemoryPositions; |
|
|
|
|
for(auto&u:otherUnits){ |
|
|
|
|
if(u->IsFriendly()&&InRange(u)){ |
|
|
|
|
if(u.get()!=this&&u->IsFriendly()&&InRange(u)){ |
|
|
|
|
for(int i=0;i<u->GetMemorySize();i++){ |
|
|
|
|
if(!u->memory[i]){ |
|
|
|
|
emptyMemoryPositions.emplace_back(i); |
|
|
|
@ -324,6 +324,12 @@ int Unit::GetMemorySize(){ |
|
|
|
|
return memory.size(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Unit::RunAI(PixelGameEngine*pge){} |
|
|
|
|
|
|
|
|
|
void Unit::_RunAI(PixelGameEngine*pge){ |
|
|
|
|
RunAI(pge); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Unit::_Update(PixelGameEngine*pge){ |
|
|
|
|
if(!target.expired()){ |
|
|
|
|
auto ptrTarget=target.lock(); |
|
|
|
@ -339,25 +345,7 @@ void Unit::_Update(PixelGameEngine*pge){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!IsFriendly()){ |
|
|
|
|
if(changeDirTimer==0){ |
|
|
|
|
changeDirTimer=rand()%30; |
|
|
|
|
switch(rand()%4){ |
|
|
|
|
case 0:{ |
|
|
|
|
movementVel={16,0}; |
|
|
|
|
}break; |
|
|
|
|
case 1:{ |
|
|
|
|
movementVel={0,16}; |
|
|
|
|
}break; |
|
|
|
|
case 2:{ |
|
|
|
|
movementVel={-16,0}; |
|
|
|
|
}break; |
|
|
|
|
case 3:{ |
|
|
|
|
movementVel={0,-16}; |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SetPos(GetPos()+movementVel*pge->GetElapsedTime()); |
|
|
|
|
changeDirTimer=std::max(0.f,changeDirTimer-pge->GetElapsedTime()); |
|
|
|
|
_RunAI(pge); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!GhostInFogOfWar()&&InFogOfWar()){ |
|
|
|
@ -449,30 +437,47 @@ void Unit::SetPos(vf2d newPos){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Unit::AttemptAttack(Unit*unit,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
void Unit::AttemptAttack(std::weak_ptr<Unit>attacker,std::weak_ptr<Unit>unit,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
if(reloadTimer>0)return; |
|
|
|
|
Unit*finalTarget=nullptr; |
|
|
|
|
if(unit!=nullptr){ |
|
|
|
|
std::weak_ptr<Unit>finalTarget; |
|
|
|
|
if(!unit.expired()){ |
|
|
|
|
finalTarget=unit; |
|
|
|
|
if(!target.expired()){ |
|
|
|
|
auto ptrTarget=target.lock(); |
|
|
|
|
if(InRange(ptrTarget)){ |
|
|
|
|
finalTarget=ptrTarget.get(); |
|
|
|
|
finalTarget=ptrTarget; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(finalTarget!=nullptr){ |
|
|
|
|
if(InRange(finalTarget)){ |
|
|
|
|
_Attack(finalTarget,otherUnits); //Call the parent function first, followed by the child.
|
|
|
|
|
if(!finalTarget.expired()){ |
|
|
|
|
if(InRange(finalTarget.lock())){ |
|
|
|
|
_Attack(attacker,finalTarget,otherUnits); //Call the parent function first, followed by the child.
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Unit::Update(PixelGameEngine*pge){} |
|
|
|
|
|
|
|
|
|
void Unit::_Attack(Unit*finalTarget,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
Attack(*finalTarget,otherUnits); |
|
|
|
|
void Unit::Attacked(std::weak_ptr<Unit>attacker){} |
|
|
|
|
|
|
|
|
|
void Unit::_Attacked(std::weak_ptr<Unit>attacker){ |
|
|
|
|
Attacked(attacker); |
|
|
|
|
if(attacker.lock()->IsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){ |
|
|
|
|
SetTargetUnit(attacker); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Unit::_Attack(std::weak_ptr<Unit>attacker,std::weak_ptr<Unit>finalTarget,std::vector<std::shared_ptr<Unit>>&otherUnits){ |
|
|
|
|
if(GetAtkSpd()>0){ |
|
|
|
|
Attack(*finalTarget.lock(),otherUnits); |
|
|
|
|
finalTarget.lock()->_Attacked(attacker); |
|
|
|
|
reloadTimer=1.f/(GetAtkSpd()/2.f); |
|
|
|
|
if(GetCurrentTarget().expired()&&!IsFriendly()){ |
|
|
|
|
if(finalTarget.lock()->IsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){ |
|
|
|
|
SetTargetUnit(finalTarget); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Unit::InFogOfWar(){ |
|
|
|
@ -506,3 +511,7 @@ bool Unit::CanInteractWithEnemies(){ |
|
|
|
|
Renderable&Unit::GetImage(){ |
|
|
|
|
return img; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::weak_ptr<Unit>Unit::GetCurrentTarget(){ |
|
|
|
|
return target; |
|
|
|
|
} |