You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
VirusAttack/olcCodeJam2023Entry/Unit.h

166 lines
5.2 KiB

#pragma once
#include "olcPixelGameEngine.h"
#include "olcPGEX_TransformedView.h"
#include "Constant.h"
#include "Image.h"
struct Marker{
size_t index;
size_t size;
};
enum MemoryType{
HEALTH,
RANGE,
ATKSPD,
MOVESPD,
PROCEDURE
};
struct Memory{
MemoryType type;
int size;
};
struct Unit{
public:
Unit(std::vector<Memory>memory,vf2d pos,float radius,Renderable&img,bool friendly=false,bool moveable=true,bool friendlyInteractable=false,bool enemyInteractable=true);
int GetHealth();
int GetRange();
int GetAtkSpd();
int GetMoveSpd();
int GetProcedure();
int GetMemorySize();
std::vector<bool>memory;
std::vector<bool>ghostMemory;
virtual void Update(PixelGameEngine*pge);
virtual void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)=0;
virtual void Draw(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
virtual void DrawHud(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
bool IsFriendly();
bool IsSelected();
void Select();
void Deselect();
vf2d GetPos();
bool IsDead();
vf2d GetUnitSize();
void SetTargetUnit(std::weak_ptr<Unit>target);
void SetTargetLocation(vf2d targetLoc);
void SetPos(vf2d newPos);
void AttemptAttack(std::weak_ptr<Unit>attacker,std::weak_ptr<Unit>unit,std::vector<std::shared_ptr<Unit>>&otherUnits);
bool InFogOfWar();
bool GhostInFogOfWar();
void HideGhost();
vf2d GetGhostPos();
void _Update(PixelGameEngine*pge);
bool IsMoveable();
void DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
bool CanInteractWithEnemies();
bool CanInteractWithAllies();
Renderable&GetImage();
virtual void RunAI(PixelGameEngine*pge);
void _RunAI(PixelGameEngine*pge);
virtual void Attacked(std::weak_ptr<Unit>attacker);
void _Attacked(std::weak_ptr<Unit>attacker);
std::weak_ptr<Unit>GetCurrentTarget();
std::vector<bool>& operator <<=(const int n){
for(int i=0;i<GetMemorySize()-1;i++){
memory[i]=memory[i+1];
}
memory[GetMemorySize()-1]=0;
if(!InFogOfWar()){
ghostMemory=memory;
}
return memory;
}
std::vector<bool>& operator >>=(const int n){
for(int i=GetMemorySize()-1;i>0;i--){
memory[i]=memory[i-1];
}
memory[0]=0;
if(!InFogOfWar()){
ghostMemory=memory;
}
return memory;
}
protected:
bool friendly;
Renderable&img;
Marker health;
Marker range;
Marker atkSpd;
Marker moveSpd;
Marker procedure;
std::weak_ptr<Unit>target;
vf2d targetLoc=CONSTANT::UNSELECTED;
bool InRange(std::shared_ptr<Unit>target);
bool InRange(Unit*target);
bool InRange(vf2d pos);
private:
vf2d pos;
vf2d ghostPos;
float radius;
int GetBits(Marker&m);
bool selected=false;
bool dead=false;
float reloadTimer=0;
void _Attack(std::weak_ptr<Unit>attacker,std::weak_ptr<Unit>finalTarget,std::vector<std::shared_ptr<Unit>>&otherUnits);
bool moveable=true;
bool friendlyInteractable=false;
bool enemyInteractable=true;
};
struct BasicUnit:Unit{
BasicUnit(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;
};
struct BasicUnit2:Unit{
BasicUnit2(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;
};
struct LeftShifter:Unit{
LeftShifter(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;
};
struct RightShifter:Unit{
RightShifter(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;
};
struct BitRestorer:Unit{
BitRestorer(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 AttemptToHealOtherAllies(std::vector<std::shared_ptr<Unit>>&otherUnits);
};
struct MemorySwapper:Unit{
MemorySwapper(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;
};
struct Corrupter:Unit{
Corrupter(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;
};
struct MemoryAllocator:Unit{
MemoryAllocator(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;
};
struct RAMBank:Unit{
vf2d randomOffset;
Renderable img;
Renderable&originalImg;
Renderable&matrixImg;
RAMBank(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false);
void Update(PixelGameEngine*pge)override;
void Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits)override;
void Draw(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES)override;
};