#pragma region License /* License (OLC-3) ~~~~~~~~~~~~~~~ Copyright 2024 Joshua Sigona Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions or derivations of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions or derivative works in binary form must reproduce the above copyright notice. This list of conditions and the following disclaimer must be reproduced in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Portions of this software are copyright © 2024 The FreeType Project (www.freetype.org). Please see LICENSE_FT.txt for more information. All rights reserved. */ #pragma endregion #include "Monster.h" #include "Animation.h" #include "config.h" #include "DEFINES.h" #include "safemap.h" #include "Item.h" INCLUDE_DATA INCLUDE_STRATEGY_DATA INCLUDE_ANIMATION_DATA INCLUDE_ITEM_DATA std::mapMONSTER_DATA; MonsterData::MonsterData() :atk(0),collisionDmg(0),hp(0),moveSpd(0),size(0),strategy("Run Towards"){} MonsterData::MonsterData(std::string name,int hp,int atk,const uint32_t xp,std::vectordrops,float moveSpd,float size,std::string strategy,int collisionDmg): name(name),hp(hp),atk(atk),xp(xp),moveSpd(moveSpd),size(size),strategy(strategy),dropData(drops),collisionDmg(collisionDmg){} void MonsterData::InitializeMonsterData(){ for(auto&[key,size]:DATA["Monsters"].GetKeys()){ std::string MonsterName=key; if(MONSTER_DATA.count(key)){ ERR("WARNING! A monster with the name "<animations; bool hasFourWaySpriteSheet=false; MonsterData::imgs[MonsterName]=NEW Renderable(); const rcode imgLoadResult=MonsterData::imgs[MonsterName]->Load("assets/monsters/commercial_assets/"+MonsterName+".png"); if(imgLoadResult!=OK)ERR(std::format("WARNING! Image loading for Monster {} failed with result {}",MonsterName,int(imgLoadResult))); EventName hurtSound=""; EventName deathSound=""; EventName walkSound=""; if(DATA["Monsters"][MonsterName].HasProperty("Hurt Sound")){ hurtSound=DATA["Monsters"][MonsterName]["Hurt Sound"].GetString(); } if(DATA["Monsters"][MonsterName].HasProperty("Death Sound")){ deathSound=DATA["Monsters"][MonsterName]["Death Sound"].GetString(); } if(DATA["Monsters"][MonsterName].HasProperty("Walk Sound")){ walkSound=DATA["Monsters"][MonsterName]["Walk Sound"].GetString(); } auto CreateHorizontalAnimationSequence=[&](Renderable&img,int frameCount,vf2d size,std::string state,int row,AnimationData data={}){ Animate2D::FrameSequence anim(data.frameDuration,data.style); for(int i=0;idrops; //Add drop items to monster data from the config. int dropDataCounter=0; while(DATA["Monsters"][MonsterName].HasProperty("DROP["+std::to_string(dropDataCounter)+"]")){ datafile drop=DATA["Monsters"][MonsterName]["DROP["+std::to_string(dropDataCounter)+"]"]; if(!ITEM_DATA.count(drop.GetString(0))){ ERR("Could not add drop "<animations; MonsterData::imgs[NPCName]=NEW Renderable(); const rcode imgLoadResult=MonsterData::imgs[NPCName]->Load("assets/npcs/"+NPCName+".png"); if(imgLoadResult!=OK)ERR(std::format("WARNING! Image loading for NPC {} failed with result {}",NPCName,int(imgLoadResult))); EventName hurtSound=""; EventName deathSound=""; EventName walkSound=""; int health=100; int attack=0; int xp=0; float moveSpd=100.f; float size=100.f; int collisionDmg=0; if(DATA["NPCs"][NPCName].HasProperty("Health"))health=DATA["NPCs"][NPCName]["Health"].GetInt(); if(DATA["NPCs"][NPCName].HasProperty("Attack"))attack=DATA["NPCs"][NPCName]["Attack"].GetInt(); if(DATA["NPCs"][NPCName].HasProperty("XP"))xp=DATA["NPCs"][NPCName]["XP"].GetInt(); if(DATA["NPCs"][NPCName].HasProperty("MoveSpd"))moveSpd=DATA["NPCs"][NPCName]["MoveSpd"].GetReal(); if(DATA["NPCs"][NPCName].HasProperty("Size"))moveSpd=DATA["NPCs"][NPCName]["Size"].GetReal(); if(DATA["NPCs"][NPCName].HasProperty("CollisionDmg"))collisionDmg=DATA["NPCs"][NPCName]["CollisionDmg"].GetInt(); if(DATA["NPCs"][NPCName].HasProperty("Hurt Sound")){ hurtSound=DATA["NPCs"][NPCName]["Hurt Sound"].GetString(); } if(DATA["NPCs"][NPCName].HasProperty("Death Sound")){ deathSound=DATA["NPCs"][NPCName]["Death Sound"].GetString(); } if(DATA["NPCs"][NPCName].HasProperty("Walk Sound")){ walkSound=DATA["NPCs"][NPCName]["Walk Sound"].GetString(); } auto CreateHorizontalAnimationSequence=[&](Renderable&img,int frameCount,vf2d size,std::string state,int row,AnimationData data={}){ Animate2D::FrameSequence anim(data.frameDuration,data.style); for(int i=0;idrops; //Add drop items to monster data from the config. int dropDataCounter=0; while(DATA["NPCs"][NPCName].HasProperty("DROP["+std::to_string(dropDataCounter)+"]")){ datafile drop=DATA["NPCs"][NPCName]["DROP["+std::to_string(dropDataCounter)+"]"]; if(!ITEM_DATA.count(drop.GetString(0))){ ERR("Could not add drop "<&MonsterData::GetDropData(){ return dropData; } const EventName&MonsterData::GetHurtSound(){ return hurtSound; } const EventName&MonsterData::GetDeathSound(){ return deathSound; } const EventName&MonsterData::GetWalkSound(){ return walkSound; } const bool MonsterData::HasFourWaySprites()const{ return fourWayDirectionalSprites; } void MonsterData::SetUsesFourWaySprites(){ fourWayDirectionalSprites=true; } const std::string MonsterData::GetDefaultIdleAnimation()const{ return GetIdleAnimation(Direction::SOUTH); } const std::string MonsterData::GetDefaultJumpAnimation()const{ return GetJumpAnimation(Direction::SOUTH); } const std::string MonsterData::GetDefaultShootAnimation()const{ return GetShootAnimation(Direction::SOUTH); } const std::string MonsterData::GetDefaultDeathAnimation()const{ return GetDeathAnimation(Direction::SOUTH); } const bool MonsterData::HasMountedAnimation()const{ return mountedAnimName.has_value(); } const std::optionalMonsterData::GetMountedAnimation()const{ if(!HasMountedAnimation())ERR("WARNING! Trying to get a mounted animation for a monster that doesn't have a mounted animation to begin with!"); return mountedAnimName.value(); } const vf2d&MonsterData::GetMountedAnimationOffset()const{ if(!HasMountedAnimation())ERR("WARNING! Trying to get a mounted animation offset for a monster that doesn't have a mounted animation to begin with!"); return mountedAnimationOffset; } const bool MonsterData::IgnoresTerrainCollision()const{ return ignoresCollision; } const bool MonsterData::Immovable()const{ return immovable; } const bool MonsterData::Invulnerable()const{ return invulnerable; } const std::optionalMonsterData::GetLifetime()const{ return lifetime; } const float MonsterData::GetCollisionRadius()const{ return collisionRadius; }