#pragma once #include "olcPixelGameEngine.h" #include "olcPGEX_TransformedView.h" #include "Constant.h" #include "Image.h" #include "Sound.h" #include "olcPGEX_AudioSource.h" #include "util.h" #include "DebuffIcon.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(PixelGameEngine*pge,std::vectormemory,vf2d pos,float radius,Renderable&img,Pixel targetLineColor,Pixel attackingLineColor,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::vectormemory; std::vectorghostMemory; virtual void Update(PixelGameEngine*pge,std::map>&SOUNDS); virtual void Attack(Unit&victim,std::vector>&otherUnits)=0; virtual void Draw(TileTransformedView&game,std::map>&IMAGES); virtual void DrawHud(TileTransformedView&game,std::map>&IMAGES); virtual void OnDeath(std::map>&SOUNDS); bool IsFriendly(); bool IsSelected(); void Select(); void Deselect(); vf2d GetPos(); bool IsDead(); vf2d GetUnitSize(); void SetTargetUnit(std::weak_ptrtarget); void SetTargetLocation(vf2d targetLoc); void SetPos(vf2d newPos); void AttemptAttack(std::weak_ptrattacker,std::weak_ptrunit,std::vector>&otherUnits,std::vector&debuffIcons,std::map>&IMAGES); bool InFogOfWar(); bool GhostInFogOfWar(); void HideGhost(); vf2d GetGhostPos(); void _Update(PixelGameEngine*pge,std::map>&SOUNDS); bool IsMoveable(); void DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map>&IMAGES); bool CanInteractWithEnemies(); bool CanInteractWithAllies(); Renderable&GetImage(); virtual void RunAI(PixelGameEngine*pge); void _RunAI(PixelGameEngine*pge); virtual void Attacked(std::weak_ptrattacker); void _Attacked(std::weak_ptrattacker); std::weak_ptrGetCurrentTarget(); void DrawUnitDamageStats(PixelGameEngine*pge,TileTransformedView&game,std::map>&IMAGES); bool AutoAcquiresFriendlyTargets(); std::vector& operator <<=(const int n){ for(int i=0;i& 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_ptrtarget; std::weak_ptrappliedTarget; vf2d targetLoc=CONSTANT::UNSELECTED; bool InRange(std::shared_ptrtarget); bool InRange(Unit*target); bool InRange(vf2d pos); float reloadTimer=0; bool attackFailed=false; bool autoAcquireFriendlyTarget=true; private: Renderable targetingLine; Renderable attackingLine; Pixel targetLineCol,attackingLineCol; vf2d pos; vf2d ghostPos; float radius; int GetBits(Marker&m); bool selected=false; bool dead=false; void _Attack(std::weak_ptrattacker,std::weak_ptrfinalTarget,std::vector>&otherUnits); bool moveable=true; bool friendlyInteractable=false; bool enemyInteractable=true; float lineShift=0; void ApplyMatrixEffect(Renderable&r); }; struct BasicUnit:Unit{ BasicUnit(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim,std::vector>&otherUnits)override; }; struct BasicUnit2:Unit{ BasicUnit2(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim,std::vector>&otherUnits)override; }; struct LeftShifter:Unit{ LeftShifter(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim,std::vector>&otherUnits)override; }; struct RightShifter:Unit{ RightShifter(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim,std::vector>&otherUnits)override; }; struct BitRestorer:Unit{ BitRestorer(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim,std::vector>&otherUnits)override; void AttemptToHealOtherAllies(std::vector>&otherUnits); }; struct MemorySwapper:Unit{ MemorySwapper(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim,std::vector>&otherUnits)override; }; struct Corrupter:Unit{ Corrupter(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim,std::vector>&otherUnits)override; }; struct MemoryAllocator:Unit{ MemoryAllocator(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim,std::vector>&otherUnits)override; }; struct RAMBank:Unit{ vf2d randomOffset; Renderable img; Renderable&originalImg; Renderable&matrixImg; bool soundStarted=false; int soundHandle; RAMBank(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly=false); void Update(PixelGameEngine*pge,std::map>&SOUNDS)override; void Attack(Unit&victim,std::vector>&otherUnits)override; void Draw(TileTransformedView&game,std::map>&IMAGES)override; void OnDeath(std::map>&SOUNDS)override; };