From 39c4db9c6f4638a7673d4e94a42fb391c9c4a81a Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii Date: Fri, 8 Sep 2023 16:00:07 +0000 Subject: [PATCH] Okay, this is more sane. Templates removed and Set does a check to make sure it's the correct type. Co-authored-by: sigonasr2 --- Crawler/Monster.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++- Crawler/Monster.h | 30 ++++---------------------- Crawler/SlimeKing.cpp | 4 ++-- 3 files changed, 55 insertions(+), 29 deletions(-) diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index a7dd49c2..51ceb16d 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -254,7 +254,7 @@ bool Monster::Hurt(int damage,bool onUpperLevel){ if(!IsAlive()){ animation.ChangeState(internal_animState,GetDeathAnimationName()); } - iframe_timer=GET_FLOAT(Attribute::IFRAME_TIME_UPON_HIT); + iframe_timer=GetFloat(Attribute::IFRAME_TIME_UPON_HIT); return true; } @@ -383,4 +383,52 @@ void Monster::SetSize(float newSize,bool immediate){ void Monster::Set(_ATTRIBUTE a,std::variantval){ attributes[a]=val; + //Error handling below! + //The idea is if we cannot retrieve the value, the program errors out. + switch(a.type){ + case Attribute::TYPE::FLOAT:{ + GetFloat(a); + }break; + case Attribute::TYPE::INT:{ + GetInt(a); + }break; + case Attribute::TYPE::STRING:{ + GetString(a); + }break; + case Attribute::TYPE::BOOL:{ + GetBool(a); + }break; + } +} + +float Monster::GetFloat(_ATTRIBUTE a){ + if(attributes.count(a)>0){ + return std::get(attributes[a]); + }else{ + return 0; + } +} + +int Monster::GetInt(_ATTRIBUTE a){ + if(attributes.count(a)>0){ + return std::get(attributes[a]); + }else{ + return 0; + } +} + +std::string Monster::GetString(_ATTRIBUTE a){ + if(attributes.count(a)>0){ + return std::get(attributes[a]); + }else{ + return 0; + } +} + +bool Monster::GetBool(_ATTRIBUTE a){ + if(attributes.count(a)>0){ + return std::get(attributes[a]); + }else{ + return 0; + } } \ No newline at end of file diff --git a/Crawler/Monster.h b/Crawler/Monster.h index 4cd235ef..113fb836 100644 --- a/Crawler/Monster.h +++ b/Crawler/Monster.h @@ -8,11 +8,6 @@ #include #include "MonsterAttribute.h" -#define GET_FLOAT(attribute) _Get(attribute); -#define GET_INT(attribute) _Get(attribute); -#define GET_STRING(attribute) _Get(attribute); -#define GET_BOOL(attribute) _Get(attribute); - struct Player; enum MonsterAnimation{ @@ -142,27 +137,10 @@ public: std::string GetStrategy(); void SetSize(float newSize,bool immediate=true); void Set(_ATTRIBUTE a,std::variantval); - template - T _Get(_ATTRIBUTE a){ - if(attributes.count(a)>0){ - return std::get(attributes[a]); - }else{ - switch(a.type){ - case Attribute::TYPE::FLOAT:{ - return 0; - }break; - case Attribute::TYPE::INT:{ - return 0; - }break; - case Attribute::TYPE::STRING:{ - return ""; - }break; - case Attribute::TYPE::BOOL:{ - return false; - }break; - } - } - } + float GetFloat(_ATTRIBUTE a); + int GetInt(_ATTRIBUTE a); + std::string GetString(_ATTRIBUTE a); + bool GetBool(_ATTRIBUTE a); private: struct STRATEGY{ static int _GetInt(Monster&m,std::string param,int strategyNumber,int index=0); diff --git a/Crawler/SlimeKing.cpp b/Crawler/SlimeKing.cpp index 14278ed4..4a010c46 100644 --- a/Crawler/SlimeKing.cpp +++ b/Crawler/SlimeKing.cpp @@ -12,7 +12,7 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe case 0:{ m.size=ConfigInt("Phase1.Size")/100; m.diesNormally=false; - m.Set(Attribute::IFRAME_TIME_UPON_HIT,0); + m.Set(Attribute::IFRAME_TIME_UPON_HIT,0.f); m.iframe_timer=ConfigFloat("Phase5.IframeTimePerHit"); m.phase=1; }break; @@ -37,7 +37,7 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe case 4:{ if(m.hp<=0){ m.phase=5; - m.Set(Attribute::IFRAME_TIME_UPON_HIT,1); + m.Set(Attribute::IFRAME_TIME_UPON_HIT,1.f); } }break; }