1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

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.
This commit is contained in:
AlexVinS
2018-03-17 17:58:30 +03:00
committed by AlexVinS
parent 11bb46780a
commit ecaa9f5d0b
475 changed files with 22491 additions and 7123 deletions

View File

@@ -25,7 +25,6 @@
#include "../../CCallback.h"
#include "../../lib/CArtHandler.h"
#include "../../lib/spells/CSpellHandler.h"
#include "../../lib/CGeneralTextHandler.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
@@ -45,10 +44,11 @@ void CHeroArtPlace::createImage()
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
si32 imageIndex = 0;
if(ourArt)
imageIndex = ourArt->artType->iconIndex;
if(locked)
imageIndex = ArtifactID::ART_LOCK;
else if(ourArt)
imageIndex = ourArt->artType->getIconIndex();
image = std::make_shared<CAnimImage>("artifact", imageIndex);
if(!ourArt)
@@ -68,7 +68,7 @@ void CHeroArtPlace::lockSlot(bool on)
if (on)
image->setFrame(ArtifactID::ART_LOCK);
else if (ourArt)
image->setFrame(ourArt->artType->iconIndex);
image->setFrame(ourArt->artType->getIconIndex());
else
image->setFrame(0);
}
@@ -172,7 +172,7 @@ void CHeroArtPlace::clickLeft(tribool down, bool previousState)
else if(cur->isBig())
{
//war machines cannot go to backpack
LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[153]) % cur->Name()));
LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[153]) % cur->getName()));
}
else
{
@@ -197,18 +197,6 @@ void CHeroArtPlace::clickLeft(tribool down, bool previousState)
(!ourArt || ourOwner->curHero->tempOwner == LOCPLINT->playerID))
{
setMeAsDest();
//
// // Special case when the dest artifact can't be fit into the src slot.
// //CGI->arth->unequipArtifact(ourOwner->curHero->artifWorn, slotID);
// const CArtifactsOfHero* srcAOH = ourOwner->commonInfo->src.AOH;
// ui16 srcSlotID = ourOwner->commonInfo->src.slotID;
// if (ourArt && srcSlotID < 19 && !ourArt->canBePutAt(ArtifactLocation(srcAOH->curHero, srcSlotID)))
// {
// // Put dest artifact into owner's backpack.
// ourOwner->commonInfo->src.AOH = ourOwner;
// ourOwner->commonInfo->src.slotID = ourOwner->curHero->artifacts.size() + 19;
// }
ourOwner->realizeCurrentTransaction();
}
}
@@ -226,14 +214,12 @@ bool CHeroArtPlace::askToAssemble(const CArtifactInstance *art, ArtifactPosition
for(const CArtifact *combination : assemblyPossibilities)
{
LOCPLINT->showArtifactAssemblyDialog(
art->artType->id,
combination->id,
true,
std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), hero, slot, true, combination->id),
0);
art->artType,
combination,
std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), hero, slot, true, combination->id));
if(assemblyPossibilities.size() > 2)
logGlobal->warn("More than one possibility of assembling on %s... taking only first", art->artType->Name());
logGlobal->warn("More than one possibility of assembling on %s... taking only first", art->artType->getName());
return true;
}
return false;
@@ -243,14 +229,14 @@ void CHeroArtPlace::clickRight(tribool down, bool previousState)
{
if(ourArt && down && !locked && text.size() && !picked) //if there is no description or it's a lock, do nothing ;]
{
if (slotID < GameConstants::BACKPACK_START)
if(slotID < GameConstants::BACKPACK_START)
{
if(ourOwner->allowedAssembling)
{
std::vector<const CArtifact *> assemblyPossibilities = ourArt->assemblyPossibilities(ourOwner->curHero);
// If the artifact can be assembled, display dialog.
if (askToAssemble(ourArt, slotID, ourOwner->curHero))
if(askToAssemble(ourArt, slotID, ourOwner->curHero))
{
return;
}
@@ -259,11 +245,9 @@ void CHeroArtPlace::clickRight(tribool down, bool previousState)
if(ourArt->canBeDisassembled())
{
LOCPLINT->showArtifactAssemblyDialog(
ourArt->artType->id,
0,
false,
std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), ourOwner->curHero, slotID, false, ArtifactID()),
0);
ourArt->artType,
nullptr,
std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), ourOwner->curHero, slotID, false, ArtifactID()));
return;
}
}
@@ -294,7 +278,7 @@ void CHeroArtPlace::select ()
}
}
CCS->curh->dragAndDropCursor(make_unique<CAnimImage>("artifact", ourArt->artType->iconIndex));
CCS->curh->dragAndDropCursor(make_unique<CAnimImage>("artifact", ourArt->artType->getIconIndex()));
ourOwner->commonInfo->src.setTo(this, false);
ourOwner->markPossibleSlots(ourArt);
@@ -389,7 +373,7 @@ void CHeroArtPlace::setArtifact(const CArtifactInstance *art)
}
image->enable();
image->setFrame(locked ? ArtifactID::ART_LOCK : art->artType->iconIndex);
image->setFrame(locked ? ArtifactID::ART_LOCK : art->artType->getIconIndex());
text = art->getEffectiveDescription(ourOwner->curHero);
@@ -414,7 +398,7 @@ void CHeroArtPlace::setArtifact(const CArtifactInstance *art)
if (locked) // Locks should appear as empty.
hoverText = CGI->generaltexth->allTexts[507];
else
hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1]) % ourArt->artType->Name());
hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1]) % ourArt->artType->getName());
}
void CArtifactsOfHero::SCommonPart::reset()
@@ -769,7 +753,7 @@ void CArtifactsOfHero::artifactMoved(const ArtifactLocation &src, const Artifact
commonInfo->src.art = dst.getArt();
commonInfo->src.slotID = dst.slot;
assert(commonInfo->src.AOH);
CCS->curh->dragAndDropCursor(make_unique<CAnimImage>("artifact", dst.getArt()->artType->iconIndex));
CCS->curh->dragAndDropCursor(make_unique<CAnimImage>("artifact", dst.getArt()->artType->getIconIndex()));
markPossibleSlots(dst.getArt());
}
}
@@ -1020,7 +1004,7 @@ void CCommanderArtPlace::createImage()
int imageIndex = 0;
if(ourArt)
imageIndex = ourArt->artType->iconIndex;
imageIndex = ourArt->artType->getIconIndex();
image = std::make_shared<CAnimImage>("artifact", imageIndex);
if(!ourArt)
@@ -1055,7 +1039,7 @@ void CCommanderArtPlace::setArtifact(const CArtifactInstance * art)
}
image->enable();
image->setFrame(art->artType->iconIndex);
image->setFrame(art->artType->getIconIndex());
text = art->getEffectiveDescription();

View File

@@ -112,7 +112,7 @@ const std::vector<std::string> CComponent::getFileName()
case spell: return gen(spellsArr);
case morale: return gen(moraleArr);
case luck: return gen(luckArr);
case building: return std::vector<std::string>(4, CGI->townh->factions[subtype]->town->clientInfo.buildingsIcons);
case building: return std::vector<std::string>(4, (*CGI->townh)[subtype]->town->clientInfo.buildingsIcons);
case hero: return gen(heroArr);
case flag: return gen(flagArr);
}
@@ -127,8 +127,8 @@ size_t CComponent::getIndex()
case primskill: return subtype;
case secskill: return subtype*3 + 3 + val - 1;
case resource: return subtype;
case creature: return CGI->creh->creatures[subtype]->iconIndex;
case artifact: return CGI->arth->artifacts[subtype]->iconIndex;
case creature: return CGI->creatures()->getByIndex(subtype)->getIconIndex();
case artifact: return CGI->artifacts()->getByIndex(subtype)->getIconIndex();
case experience: return 4;
case spell: return subtype;
case morale: return val+3;
@@ -159,15 +159,15 @@ std::string CComponent::getDescription()
}
else
{
art.reset(CArtifactInstance::createScroll(static_cast<SpellID>(val)));
art.reset(CArtifactInstance::createScroll(SpellID(val)));
}
return art->getEffectiveDescription();
}
case experience: return CGI->generaltexth->allTexts[241];
case spell: return CGI->spellh->objects[subtype]->getLevelInfo(val).description;
case spell: return CGI->spellh->objects[subtype]->getLevelDescription(val);
case morale: return CGI->generaltexth->heroscrn[ 4 - (val>0) + (val<0)];
case luck: return CGI->generaltexth->heroscrn[ 7 - (val>0) + (val<0)];
case building: return CGI->townh->factions[subtype]->town->buildings[BuildingID(val)]->Description();
case building: return (*CGI->townh)[subtype]->town->buildings[BuildingID(val)]->Description();
case hero: return "";
case flag: return "";
}
@@ -193,8 +193,8 @@ std::string CComponent::getSubtitleInternal()
case primskill: return boost::str(boost::format("%+d %s") % val % (subtype < 4 ? CGI->generaltexth->primarySkillNames[subtype] : CGI->generaltexth->allTexts[387]));
case secskill: return CGI->generaltexth->levels[val-1] + "\n" + CGI->skillh->skillName(subtype);
case resource: return boost::lexical_cast<std::string>(val);
case creature: return (val? boost::lexical_cast<std::string>(val) + " " : "") + CGI->creh->creatures[subtype]->*(val != 1 ? &CCreature::namePl : &CCreature::nameSing);
case artifact: return CGI->arth->artifacts[subtype]->Name();
case creature: return (val? boost::lexical_cast<std::string>(val) + " " : "") + CGI->creh->objects[subtype]->*(val != 1 ? &CCreature::namePl : &CCreature::nameSing);
case artifact: return CGI->artifacts()->getByIndex(subtype)->getName();
case experience:
{
if(subtype == 1) //+1 level - tree of knowledge
@@ -208,15 +208,15 @@ std::string CComponent::getSubtitleInternal()
return boost::lexical_cast<std::string>(val); //amount of experience OR level required for seer hut;
}
}
case spell: return CGI->spellh->objects[subtype]->name;
case spell: return CGI->spells()->getByIndex(subtype)->getName();
case morale: return "";
case luck: return "";
case building:
{
auto building = CGI->townh->factions[subtype]->town->buildings[BuildingID(val)];
auto building = (*CGI->townh)[subtype]->town->buildings[BuildingID(val)];
if(!building)
{
logGlobal->error("Town of faction %s has no building #%d", CGI->townh->factions[subtype]->town->faction->name, val);
logGlobal->error("Town of faction %s has no building #%d", (*CGI->townh)[subtype]->town->faction->name, val);
return (boost::format("Missing building #%d") % val).str();
}
return building->Name();
@@ -224,7 +224,7 @@ std::string CComponent::getSubtitleInternal()
case hero: return "";
case flag: return CGI->generaltexth->capColors[subtype];
}
assert(0);
logGlobal->error("Invalid CComponent type: %d", (int)compType);
return "";
}

View File

@@ -355,7 +355,7 @@ void CGarrisonSlot::update()
if(creature)
{
creatureImage->enable();
creatureImage->setFrame(creature->iconIndex);
creatureImage->setFrame(creature->getIconIndex());
stackCount->enable();
stackCount->setText(boost::lexical_cast<std::string>(myStack->count));
@@ -367,12 +367,12 @@ void CGarrisonSlot::update()
}
}
CGarrisonSlot::CGarrisonSlot(CGarrisonInt * Owner, int x, int y, SlotID IID, CGarrisonSlot::EGarrisonType Upg, const CStackInstance * Creature)
: ID(IID),
owner(Owner),
myStack(Creature),
creature(nullptr),
upg(Upg)
CGarrisonSlot::CGarrisonSlot(CGarrisonInt * Owner, int x, int y, SlotID IID, CGarrisonSlot::EGarrisonType Upg, const CStackInstance * creature_)
: ID(IID),
owner(Owner),
myStack(creature_),
creature(creature_ ? creature_->type : nullptr),
upg(Upg)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
@@ -382,7 +382,7 @@ CGarrisonSlot::CGarrisonSlot(CGarrisonInt * Owner, int x, int y, SlotID IID, CGa
std::string imgName = owner->smallIcons ? "cprsmall" : "TWCRPORT";
creatureImage = std::make_shared<CAnimImage>(imgName, 0);
creatureImage->disable();
creatureImage->disable();
selectionImage = std::make_shared<CAnimImage>(imgName, 1);
selectionImage->disable();
@@ -496,13 +496,13 @@ CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point & garsOffset,
const CArmedInstance * s1, const CArmedInstance * s2,
bool _removableUnits, bool smallImgs, bool _twoRows)
: highlighted(nullptr),
inSplittingMode(false),
interx(inx),
garOffset(garsOffset),
pb(false),
smallIcons(smallImgs),
removableUnits(_removableUnits),
twoRows(_twoRows)
inSplittingMode(false),
interx(inx),
garOffset(garsOffset),
pb(false),
smallIcons(smallImgs),
removableUnits(_removableUnits),
twoRows(_twoRows)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);

View File

@@ -53,7 +53,7 @@ public:
void clickRight(tribool down, bool previousState) override;
void clickLeft(tribool down, bool previousState) override;
void update();
CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, EGarrisonType Upg=EGarrisonType::UP, const CStackInstance * Creature=nullptr);
CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, EGarrisonType Upg=EGarrisonType::UP, const CStackInstance * creature_ = nullptr);
void splitIntoParts(EGarrisonType type, int amount, int maxOfSplittedSlots);
void handleSplittingShortcuts();

View File

@@ -243,7 +243,7 @@ void CArmyTooltip::init(const InfoAboutArmy &army)
continue;
}
icons.push_back(std::make_shared<CAnimImage>("CPRSMALL", slot.second.type->iconIndex, 0, slotsPos[slot.first.getNum()].x, slotsPos[slot.first.getNum()].y));
icons.push_back(std::make_shared<CAnimImage>("CPRSMALL", slot.second.type->getIconIndex(), 0, slotsPos[slot.first.getNum()].x, slotsPos[slot.first.getNum()].y));
std::string subtitle;
if(army.army.isDetailed)
@@ -443,12 +443,12 @@ CCreaturePic::CCreaturePic(int x, int y, const CCreature * cre, bool Big, bool A
TFaction faction = cre->faction;
assert(CGI->townh->factions.size() > faction);
assert(CGI->townh->size() > faction);
if(Big)
bg = std::make_shared<CPicture>(CGI->townh->factions[faction]->creatureBg130);
bg = std::make_shared<CPicture>((*CGI->townh)[faction]->creatureBg130);
else
bg = std::make_shared<CPicture>(CGI->townh->factions[faction]->creatureBg120);
bg = std::make_shared<CPicture>((*CGI->townh)[faction]->creatureBg120);
anim = std::make_shared<CCreatureAnim>(0, 0, cre->animDefName);
anim->clipRect(cre->isDoubleWide()?170:150, 155, bg->pos.w, bg->pos.h);
anim->startPreview(cre->hasBonusOfType(Bonus::SIEGE_WEAPON));