2014-07-13 16:11:25 +03:00
|
|
|
/*
|
|
|
|
* CGarrisonInt.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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../windows/CWindowObject.h"
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class CArmedInstance;
|
|
|
|
class CCreatureSet;
|
|
|
|
class CStackInstance;
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2014-07-13 16:11:25 +03:00
|
|
|
class CGarrisonInt;
|
2014-08-03 14:16:19 +03:00
|
|
|
class CButton;
|
2014-07-13 16:11:25 +03:00
|
|
|
class CAnimImage;
|
|
|
|
class CGarrisonSlot;
|
|
|
|
class CLabel;
|
|
|
|
|
|
|
|
/// A single garrison slot which holds one creature of a specific amount
|
|
|
|
class CGarrisonSlot : public CIntObject
|
|
|
|
{
|
|
|
|
SlotID ID; //for identification
|
|
|
|
CGarrisonInt *owner;
|
2018-04-07 13:34:11 +02:00
|
|
|
const CStackInstance * myStack; //nullptr if slot is empty
|
|
|
|
const CCreature * creature;
|
2015-08-24 23:40:12 +02:00
|
|
|
|
|
|
|
/// Type of Garrison for slot (up or down)
|
|
|
|
enum EGarrisonType
|
|
|
|
{
|
|
|
|
UP=0, ///< 0 - up garrison (Garrisoned)
|
|
|
|
DOWN, ///< 1 - down garrison (Visiting)
|
|
|
|
} upg; ///< Flag indicating if it is the up or down garrison
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CAnimImage> creatureImage;
|
|
|
|
std::shared_ptr<CAnimImage> selectionImage; // image for selection, not always visible
|
|
|
|
std::shared_ptr<CLabel> stackCount;
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2015-08-24 22:39:56 +02:00
|
|
|
bool viewInfo();
|
|
|
|
bool highlightOrDropArtifact();
|
|
|
|
bool split();
|
2015-08-25 00:41:41 +02:00
|
|
|
bool mustForceReselection() const;
|
2015-08-24 22:39:56 +02:00
|
|
|
|
2014-07-13 16:11:25 +03:00
|
|
|
void setHighlight(bool on);
|
2021-11-28 14:57:38 +02:00
|
|
|
std::function<void()> getDismiss() const;
|
|
|
|
|
2014-07-13 16:11:25 +03:00
|
|
|
public:
|
2015-10-12 15:47:10 +02:00
|
|
|
virtual void hover (bool on) override; //call-in
|
2014-07-13 16:11:25 +03:00
|
|
|
const CArmedInstance * getObj() const;
|
|
|
|
bool our() const;
|
2021-11-28 21:48:22 +02:00
|
|
|
SlotID getSlot() const { return ID; }
|
2015-03-16 01:04:18 +02:00
|
|
|
bool ally() const;
|
2015-10-12 15:47:10 +02:00
|
|
|
void clickRight(tribool down, bool previousState) override;
|
|
|
|
void clickLeft(tribool down, bool previousState) override;
|
2014-07-13 16:11:25 +03:00
|
|
|
void update();
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, EGarrisonType Upg=EGarrisonType::UP, const CStackInstance * creature_ = nullptr);
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2021-11-28 14:57:38 +02:00
|
|
|
void splitIntoParts(EGarrisonType type, int amount);
|
|
|
|
bool handleSplittingShortcuts(); /// Returns true when some shortcut is pressed, false otherwise
|
2017-10-26 18:40:09 +02:00
|
|
|
|
2014-07-13 16:11:25 +03:00
|
|
|
friend class CGarrisonInt;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Class which manages slots of upper and lower garrison, splitting of units
|
|
|
|
class CGarrisonInt :public CIntObject
|
|
|
|
{
|
2015-08-25 00:45:46 +02:00
|
|
|
/// Chosen slot. Should be changed only via selectSlot.
|
2018-04-07 13:34:11 +02:00
|
|
|
CGarrisonSlot * highlighted;
|
2014-07-13 16:11:25 +03:00
|
|
|
bool inSplittingMode;
|
2018-04-07 13:34:11 +02:00
|
|
|
std::vector<std::shared_ptr<CGarrisonSlot>> availableSlots; ///< Slots of upper and lower garrison
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void createSlots();
|
2021-11-28 14:57:38 +02:00
|
|
|
bool checkSelected(const CGarrisonSlot * selected, TQuantity min = 0) const;
|
|
|
|
|
2014-07-13 16:11:25 +03:00
|
|
|
public:
|
2015-08-25 00:45:46 +02:00
|
|
|
int interx; ///< Space between slots
|
|
|
|
Point garOffset; ///< Offset between garrisons (not used if only one hero)
|
2018-04-07 13:34:11 +02:00
|
|
|
std::vector<std::shared_ptr<CButton>> splitButtons; ///< May be empty if no buttons
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2015-08-25 00:45:46 +02:00
|
|
|
SlotID p2; ///< TODO: comment me
|
2014-07-13 16:11:25 +03:00
|
|
|
bool pb,
|
2015-08-25 00:45:46 +02:00
|
|
|
smallIcons, ///< true - 32x32 imgs, false - 58x64
|
|
|
|
removableUnits, ///< player Can remove units from up
|
|
|
|
twoRows, ///< slots Will be placed in 2 rows
|
|
|
|
owned[2]; ///< player Owns up or down army ([0] upper, [1] lower)
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void selectSlot(CGarrisonSlot * slot); ///< @param slot null = deselect
|
2021-11-28 14:57:38 +02:00
|
|
|
const CGarrisonSlot * getSelection() const;
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
void setSplittingMode(bool on);
|
|
|
|
bool getSplittingMode();
|
|
|
|
|
2021-11-28 14:57:38 +02:00
|
|
|
bool hasEmptySlot(CGarrisonSlot::EGarrisonType type) const;
|
|
|
|
SlotID getEmptySlot(CGarrisonSlot::EGarrisonType type) const;
|
2017-03-18 15:21:41 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
const CArmedInstance * armedObjs[2]; ///< [0] is upper, [1] is down
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void setArmy(const CArmedInstance * army, bool bottomGarrison);
|
|
|
|
void addSplitBtn(std::shared_ptr<CButton> button);
|
2014-07-13 16:11:25 +03:00
|
|
|
|
|
|
|
void recreateSlots();
|
|
|
|
|
2015-08-25 00:45:46 +02:00
|
|
|
void splitClick(); ///< handles click on split button
|
|
|
|
void splitStacks(int amountLeft, int amountRight); ///< TODO: comment me
|
2021-11-28 14:57:38 +02:00
|
|
|
void moveStackToAnotherArmy(const CGarrisonSlot * selected);
|
|
|
|
void bulkMoveArmy(const CGarrisonSlot * selected);
|
|
|
|
void bulkMergeStacks(const CGarrisonSlot * selected); // Gather all creatures of selected type to the selected slot from other hero/garrison slots
|
|
|
|
void bulkSplitStack(const CGarrisonSlot * selected); // Used to separate one-creature troops from main stack
|
|
|
|
void bulkSmartSplitStack(const CGarrisonSlot * selected);
|
2015-08-25 00:45:46 +02:00
|
|
|
|
|
|
|
/// Constructor
|
|
|
|
/// @param x, y Position
|
|
|
|
/// @param inx Distance between slots;
|
|
|
|
/// @param garsOffset
|
|
|
|
/// @param s1, s2 Top and bottom armies
|
|
|
|
/// @param _removableUnits You can take units from top
|
|
|
|
/// @param smallImgs Units images size 64x58 or 32x32
|
|
|
|
/// @param _twoRows Display slots in 2 row (1st row = 4 slots, 2nd = 3 slots)
|
2018-04-07 13:34:11 +02:00
|
|
|
CGarrisonInt(int x, int y, int inx,
|
|
|
|
const Point & garsOffset,
|
|
|
|
const CArmedInstance * s1, const CArmedInstance * s2 = nullptr,
|
|
|
|
bool _removableUnits = true,
|
|
|
|
bool smallImgs = false,
|
|
|
|
bool _twoRows = false);
|
2014-07-13 16:11:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CGarrisonHolder
|
|
|
|
{
|
|
|
|
public:
|
2018-04-07 13:34:11 +02:00
|
|
|
virtual void updateGarrisons() = 0;
|
2014-07-13 16:11:25 +03:00
|
|
|
};
|
|
|
|
|