File: IObjectInterface.h

package info (click to toggle)
vcmi 1.6.5%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 32,060 kB
  • sloc: cpp: 238,971; python: 265; sh: 224; xml: 157; ansic: 78; objc: 61; makefile: 49
file content (117 lines) | stat: -rw-r--r-- 3,756 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * IObjectInterface.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 "../GameCallbackHolder.h"
#include "../constants/EntityIdentifiers.h"
#include "../networkPacks/EInfoWindowMode.h"
#include "../networkPacks/ObjProperty.h"
#include "../serializer/Serializeable.h"

VCMI_LIB_NAMESPACE_BEGIN

namespace vstd
{
class RNG;
}

struct BattleResult;
class UpgradeInfo;
class BoatId;
class CGObjectInstance;
class CStackInstance;
class CGHeroInstance;
class IGameCallback;
class ResourceSet;
class int3;
class MetaString;
class PlayerColor;
class IOwnableObject;

class DLL_LINKAGE IObjectInterface : public GameCallbackHolder, public virtual Serializeable
{
public:
	using GameCallbackHolder::GameCallbackHolder;

	virtual ~IObjectInterface() = default;

	virtual MapObjectID getObjGroupIndex() const = 0;
	virtual MapObjectSubID getObjTypeIndex() const = 0;

	virtual PlayerColor getOwner() const = 0;
	virtual int3 visitablePos() const = 0;
	virtual int3 anchorPos() const = 0;

	virtual void onHeroVisit(const CGHeroInstance * h) const;
	virtual void onHeroLeave(const CGHeroInstance * h) const;

	/// Called on new turn by server. This method can not modify object state on its own
	/// Instead all changes must be propagated via netpacks
	virtual void newTurn(vstd::RNG & rand) const;
	virtual void initObj(vstd::RNG & rand); //synchr
	virtual void pickRandomObject(vstd::RNG & rand);
	virtual void setProperty(ObjProperty what, ObjPropertyID identifier);//synchr

	//Called when queries created DURING HERO VISIT are resolved
	//First parameter is always hero that visited object and triggered the query
	virtual void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const;
	virtual void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const;
	virtual void garrisonDialogClosed(const CGHeroInstance *hero) const;
	virtual void heroLevelUpDone(const CGHeroInstance *hero) const;

	//unified helper to show info dialog for object owner
	virtual void showInfoDialog(const ui32 txtID, const ui16 soundID = 0, EInfoWindowMode mode = EInfoWindowMode::AUTO) const;

	virtual const IOwnableObject * asOwnable() const = 0;

	//unified interface, AI helpers
	virtual bool wasVisited (PlayerColor player) const;
	virtual bool wasVisited (const CGHeroInstance * h) const;

	static void preInit(); //called before objs receive their initObj
	static void postInit();//called after objs receive their initObj

	template <typename Handler> void serialize(Handler &h)
	{
		logGlobal->error("IObjectInterface serialized, unexpected, should not happen!");
	}
};

class DLL_LINKAGE ICreatureUpgrader
{
public:
	virtual void fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack) const = 0;

	virtual ~ICreatureUpgrader() = default;
};

class DLL_LINKAGE IBoatGenerator
{
public:
	virtual ~IBoatGenerator() = default;

	virtual const IObjectInterface * getObject() const = 0;

	virtual BoatId getBoatType() const = 0; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral
	virtual void getOutOffsets(std::vector<int3> & offsets) const = 0; //offsets to obj pos when we boat can be placed
	int3 bestLocation() const; //returns location when the boat should be placed

	enum EGeneratorState {GOOD, BOAT_ALREADY_BUILT, TILE_BLOCKED, NO_WATER, UNKNOWN};
	virtual EGeneratorState shipyardStatus() const;
	void getProblemText(MetaString &out, const CGHeroInstance *visitor = nullptr) const;
};

class DLL_LINKAGE IShipyard : public IBoatGenerator
{
public:
	virtual void getBoatCost(ResourceSet & cost) const;
};

VCMI_LIB_NAMESPACE_END