2023-06-17 14:21:42 +02:00
/*
* CGCreature . h , part of VCMI engine
*
* Authors : listed in file AUTHORS in main folder
*
* License : GNU General Public License v2 .0 or later
* Full text of license available in license . txt file , in main folder
*
*/
# pragma once
# include "CArmedInstance.h"
# include "../ResourceSet.h"
VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE CGCreature : public CArmedInstance //creatures on map
{
public :
2024-01-01 16:37:48 +02:00
using CArmedInstance : : CArmedInstance ;
2023-06-17 14:21:42 +02:00
enum Action {
FIGHT = - 2 , FLEE = - 1 , JOIN_FOR_FREE = 0 //values > 0 mean gold price
} ;
enum Character {
2023-10-17 22:06:08 +02:00
COMPLIANT = 0 , FRIENDLY = 1 , AGGRESSIVE = 2 , HOSTILE = 3 , SAVAGE = 4
2023-06-17 14:21:42 +02:00
} ;
ui32 identifier ; //unique code for this monster (used in missions)
2024-05-02 16:32:27 +02:00
si8 character = 0 ; //character of this set of creatures (0 - the most friendly, 4 - the most hostile) => on init changed to -4 (compliant) ... 10 value (savage)
2023-09-27 23:25:19 +02:00
MetaString message ; //message printed for attacking hero
2023-06-17 14:21:42 +02:00
TResources resources ; // resources given to hero that has won with monsters
ArtifactID gainedArtifact ; //ID of artifact gained to hero, -1 if none
2024-05-02 16:32:27 +02:00
bool neverFlees = false ; //if true, the troops will never flee
bool notGrowingTeam = false ; //if true, number of units won't grow
2024-05-16 20:53:49 +02:00
int64_t temppower = 0 ; //used to handle fractional stack growth for tiny stacks
2023-06-17 14:21:42 +02:00
2024-05-02 16:32:27 +02:00
bool refusedJoining = false ;
2023-06-17 14:21:42 +02:00
void onHeroVisit ( const CGHeroInstance * h ) const override ;
std : : string getHoverText ( PlayerColor player ) const override ;
std : : string getHoverText ( const CGHeroInstance * hero ) const override ;
2023-11-02 15:49:21 +02:00
std : : string getPopupText ( PlayerColor player ) const override ;
std : : string getPopupText ( const CGHeroInstance * hero ) const override ;
std : : vector < Component > getPopupComponents ( PlayerColor player ) const override ;
2024-06-01 17:28:17 +02:00
void initObj ( vstd : : RNG & rand ) override ;
void pickRandomObject ( vstd : : RNG & rand ) override ;
void newTurn ( vstd : : RNG & rand ) const override ;
2023-06-17 14:21:42 +02:00
void battleFinished ( const CGHeroInstance * hero , const BattleResult & result ) const override ;
void blockingDialogAnswered ( const CGHeroInstance * hero , ui32 answer ) const override ;
2023-10-24 16:11:25 +02:00
CreatureID getCreature ( ) const ;
2023-06-17 14:21:42 +02:00
//stack formation depends on position,
bool containsUpgradedStack ( ) const ;
int getNumberOfStacks ( const CGHeroInstance * hero ) const ;
2024-01-20 20:34:51 +02:00
template < typename Handler > void serialize ( Handler & h )
2023-06-17 14:21:42 +02:00
{
h & static_cast < CArmedInstance & > ( * this ) ;
h & identifier ;
h & character ;
h & message ;
h & resources ;
h & gainedArtifact ;
h & neverFlees ;
h & notGrowingTeam ;
h & temppower ;
h & refusedJoining ;
h & formation ;
}
protected :
2023-11-06 18:27:16 +02:00
void setPropertyDer ( ObjProperty what , ObjPropertyID identifier ) override ;
2023-06-17 14:21:42 +02:00
void serializeJsonOptions ( JsonSerializeFormat & handler ) override ;
private :
void fight ( const CGHeroInstance * h ) const ;
void flee ( const CGHeroInstance * h ) const ;
void fleeDecision ( const CGHeroInstance * h , ui32 pursue ) const ;
void joinDecision ( const CGHeroInstance * h , int cost , ui32 accept ) const ;
int takenAction ( const CGHeroInstance * h , bool allowJoin = true ) const ; //action on confrontation: -2 - fight, -1 - flee, >=0 - will join for given value of gold (may be 0)
void giveReward ( const CGHeroInstance * h ) const ;
} ;
VCMI_LIB_NAMESPACE_END