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.
210 lines
8.1 KiB
210 lines
8.1 KiB
#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"
|
|
#include "CollectionPoint.h"
|
|
#include "MemoryType.h"
|
|
#include "Resources.h"
|
|
#include "olcPGEX_QuickGUI.h"
|
|
|
|
struct Marker{
|
|
size_t index;
|
|
size_t size;
|
|
};
|
|
|
|
struct Memory{
|
|
MemoryType type;
|
|
int size;
|
|
};
|
|
|
|
struct Unit{
|
|
public:
|
|
Unit(PixelGameEngine*pge,std::vector<Memory>memory,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::vector<bool>memory;
|
|
std::vector<bool>ghostMemory;
|
|
virtual void Update(PixelGameEngine*pge,std::map<Sound,std::unique_ptr<Audio>>&SOUNDS);
|
|
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);
|
|
void _DrawHud(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
|
|
virtual void OnDeath(std::map<Sound,std::unique_ptr<Audio>>&SOUNDS);
|
|
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,std::vector<DebuffIcon>&debuffIcons,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
|
|
bool InFogOfWar();
|
|
bool GhostInFogOfWar();
|
|
void HideGhost();
|
|
vf2d GetGhostPos();
|
|
void _Update(PixelGameEngine*pge,std::map<Sound,std::unique_ptr<Audio>>&SOUNDS,Resources&player_resources,Resources&enemy_resources);
|
|
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();
|
|
void DrawUnitDamageStats(PixelGameEngine*pge,TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
|
|
bool AutoAcquiresFriendlyTargets();
|
|
bool CanMove();
|
|
void SetTargetCollectionPoint(std::weak_ptr<CollectionPoint>targetCP,std::weak_ptr<Unit>self_ptr);
|
|
Pixel GetUnitColor();
|
|
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.
|
|
bool IsAllocator();
|
|
void SetBuildUnit(float buildTime,std::unique_ptr<Unit>finalUnit);
|
|
|
|
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;
|
|
std::weak_ptr<Unit>appliedTarget;
|
|
vf2d targetLoc=CONSTANT::UNSELECTED;
|
|
bool InRange(std::shared_ptr<Unit>target);
|
|
bool InRange(Unit*target);
|
|
bool InRange(vf2d pos);
|
|
float reloadTimer=0;
|
|
bool attackFailed=false;
|
|
bool autoAcquireFriendlyTarget=true;
|
|
bool isAllocator=false;
|
|
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_ptr<Unit>attacker,std::weak_ptr<Unit>finalTarget,std::vector<std::shared_ptr<Unit>>&otherUnits);
|
|
bool moveable=true;
|
|
bool friendlyInteractable=false;
|
|
bool enemyInteractable=true;
|
|
float lineShift=0;
|
|
void ApplyMatrixEffect(Renderable&r);
|
|
std::weak_ptr<CollectionPoint>attachedPoint;
|
|
std::weak_ptr<CollectionPoint>attachTarget;
|
|
bool willAttachWhenReachingDestination=false;
|
|
std::weak_ptr<Unit>self_ptr;
|
|
float collectionTime=0;
|
|
float buildTime=0;
|
|
std::unique_ptr<Unit>buildTransformUnit;
|
|
};
|
|
|
|
struct BasicUnit:Unit{
|
|
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;
|
|
static std::vector<Memory> resourceCost;
|
|
};
|
|
|
|
struct BasicUnit2:Unit{
|
|
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;
|
|
static std::vector<Memory> resourceCost;
|
|
};
|
|
|
|
struct LeftShifter:Unit{
|
|
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;
|
|
static std::vector<Memory> resourceCost;
|
|
};
|
|
|
|
struct RightShifter:Unit{
|
|
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;
|
|
static std::vector<Memory> resourceCost;
|
|
};
|
|
|
|
struct BitRestorer:Unit{
|
|
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 AttemptToHealOtherAllies(std::vector<std::shared_ptr<Unit>>&otherUnits);
|
|
static std::vector<Memory> resourceCost;
|
|
};
|
|
|
|
struct MemorySwapper:Unit{
|
|
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;
|
|
static std::vector<Memory> resourceCost;
|
|
};
|
|
|
|
struct Corrupter:Unit{
|
|
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;
|
|
static std::vector<Memory> resourceCost;
|
|
};
|
|
|
|
struct MemoryAllocator:Unit{
|
|
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;
|
|
static std::vector<Memory> resourceCost;
|
|
};
|
|
|
|
struct RAMBank:Unit{
|
|
vf2d randomOffset;
|
|
Renderable img;
|
|
Renderable&originalImg;
|
|
Renderable&matrixImg;
|
|
bool soundStarted=false;
|
|
int soundHandle;
|
|
QuickGUI::Manager allocatorManager;
|
|
QuickGUI::ImageButton*allocatorButton;
|
|
RAMBank(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false);
|
|
void Update(PixelGameEngine*pge,std::map<Sound,std::unique_ptr<Audio>>&SOUNDS)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;
|
|
void OnDeath(std::map<Sound,std::unique_ptr<Audio>>&SOUNDS)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 DrawHud(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES)override;
|
|
static std::vector<Memory> resourceCost;
|
|
}; |