mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
- trade windows work with new creatures\artifacts
- removed some duplicated code in creature loading
This commit is contained in:
parent
fa3d32925e
commit
da6cb0ae12
@ -1938,16 +1938,17 @@ void CObjectListWindow::keyPressed (const SDL_KeyboardEvent & key)
|
||||
changeSelection(sel);
|
||||
}
|
||||
|
||||
CTradeWindow::CTradeableItem::CTradeableItem( EType Type, int ID, bool Left, int Serial):
|
||||
type(Type),
|
||||
CTradeWindow::CTradeableItem::CTradeableItem(Point pos, EType Type, int ID, bool Left, int Serial):
|
||||
CIntObject(LCLICK | HOVER | RCLICK, pos),
|
||||
type(EType(-1)),// set to invalid, will be corrected in setType
|
||||
id(ID),
|
||||
serial(Serial),
|
||||
left(Left)
|
||||
{
|
||||
addUsedEvents(LCLICK | HOVER | RCLICK);
|
||||
downSelection = false;
|
||||
hlp = NULL;
|
||||
image = nullptr;
|
||||
setType(Type);
|
||||
}
|
||||
|
||||
void CTradeWindow::CTradeableItem::setType(EType newType)
|
||||
@ -1992,13 +1993,13 @@ std::string CTradeWindow::CTradeableItem::getFilename()
|
||||
switch(type)
|
||||
{
|
||||
case RESOURCE:
|
||||
return "resource 32";
|
||||
return "RESOURCE";
|
||||
case PLAYER:
|
||||
return "flags";
|
||||
return "CREST58";
|
||||
case ARTIFACT_TYPE:
|
||||
case ARTIFACT_PLACEHOLDER:
|
||||
case ARTIFACT_INSTANCE:
|
||||
return "artdefs";
|
||||
return "artifact";
|
||||
case CREATURE:
|
||||
return "crtport";
|
||||
default:
|
||||
@ -2057,7 +2058,7 @@ void CTradeWindow::CTradeableItem::showAll(SDL_Surface * to)
|
||||
|
||||
if (image)
|
||||
{
|
||||
image->moveTo(posToBitmap);
|
||||
image->moveTo(pos.topLeft() + posToBitmap);
|
||||
image->showAll(to);
|
||||
}
|
||||
|
||||
@ -2121,12 +2122,12 @@ void CTradeWindow::CTradeableItem::showAllAt(const Point &dstPos, const std::str
|
||||
std::string oldSub = subtitle;
|
||||
downSelection = true;
|
||||
|
||||
pos = dstPos;
|
||||
moveTo(dstPos);
|
||||
subtitle = customSub;
|
||||
showAll(to);
|
||||
|
||||
downSelection = false;
|
||||
pos = oldPos;
|
||||
moveTo(oldPos.topLeft());
|
||||
subtitle = oldSub;
|
||||
}
|
||||
|
||||
@ -2274,9 +2275,8 @@ void CTradeWindow::initItems(bool Left)
|
||||
xOffset = -361;
|
||||
yOffset = +46;
|
||||
|
||||
CTradeableItem *hlp = new CTradeableItem(itemsType[Left], -1, 1, 0);
|
||||
CTradeableItem *hlp = new CTradeableItem(Point(137, 469), itemsType[Left], -1, 1, 0);
|
||||
hlp->recActions &= ~(UPDATE | SHOWALL);
|
||||
hlp->pos += Rect(137, 469, 42, 42);
|
||||
items[Left].push_back(hlp);
|
||||
}
|
||||
else //ARTIFACT_EXP
|
||||
@ -2320,8 +2320,8 @@ void CTradeWindow::initItems(bool Left)
|
||||
if(id < 0 && mode != EMarketMode::ARTIFACT_EXP) //when sacrificing artifacts we need to prepare empty slots
|
||||
continue;
|
||||
|
||||
CTradeableItem *hlp = new CTradeableItem(itemsType[Left], id, Left, j);
|
||||
hlp->pos = pos[j] + hlp->pos;
|
||||
CTradeableItem *hlp = new CTradeableItem(pos[j].topLeft(), itemsType[Left], id, Left, j);
|
||||
hlp->pos = pos[j] + this->pos.topLeft();
|
||||
items[Left].push_back(hlp);
|
||||
}
|
||||
|
||||
@ -3017,6 +3017,7 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*=
|
||||
|
||||
initItems(true);
|
||||
mimicCres();
|
||||
artIcon = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3035,6 +3036,8 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*=
|
||||
|
||||
initItems(true);
|
||||
initItems(false);
|
||||
artIcon = new CAnimImage("ARTIFACT", 0, 0, 281, 442);
|
||||
artIcon->disable();
|
||||
}
|
||||
|
||||
//Experience needed to reach next level
|
||||
@ -3198,8 +3201,8 @@ void CAltarWindow::mimicCres()
|
||||
|
||||
BOOST_FOREACH(CTradeableItem *t, items[1])
|
||||
{
|
||||
CTradeableItem *hlp = new CTradeableItem(CREATURE_PLACEHOLDER, t->id, false, t->serial);
|
||||
hlp->pos = positions[t->serial] + hlp->pos;
|
||||
CTradeableItem *hlp = new CTradeableItem(positions[t->serial].topLeft(), CREATURE_PLACEHOLDER, t->id, false, t->serial);
|
||||
hlp->pos = positions[t->serial] + this->pos.topLeft();
|
||||
items[0].push_back(hlp);
|
||||
}
|
||||
}
|
||||
@ -3337,7 +3340,8 @@ void CAltarWindow::showAll(SDL_Surface * to)
|
||||
CTradeWindow::showAll(to);
|
||||
if(mode == EMarketMode::ARTIFACT_EXP && arts && arts->commonInfo->src.art)
|
||||
{
|
||||
blitAtLoc(graphics->artDefs->ourImages[arts->commonInfo->src.art->artType->id].bitmap, 281, 442, to);
|
||||
artIcon->setFrame(arts->commonInfo->src.art->artType->id);
|
||||
artIcon->showAll(to);
|
||||
|
||||
int dmp, val;
|
||||
market->getOffer(arts->commonInfo->src.art->artType->id, 0, dmp, val, EMarketMode::ARTIFACT_EXP);
|
||||
|
@ -615,7 +615,7 @@ public:
|
||||
void showAll(SDL_Surface * to);
|
||||
void clickLeft(tribool down, bool previousState);
|
||||
std::string getName(int number = -1) const;
|
||||
CTradeableItem(EType Type, int ID, bool Left, int Serial);
|
||||
CTradeableItem(Point pos, EType Type, int ID, bool Left, int Serial);
|
||||
};
|
||||
|
||||
const IMarket *market;
|
||||
@ -687,6 +687,7 @@ public:
|
||||
|
||||
class CAltarWindow : public CTradeWindow
|
||||
{
|
||||
CAnimImage * artIcon;
|
||||
public:
|
||||
CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c-tor
|
||||
|
||||
|
@ -120,18 +120,13 @@ void Graphics::initializeBattleGraphics()
|
||||
}
|
||||
Graphics::Graphics()
|
||||
{
|
||||
CDefHandler *smi2;
|
||||
|
||||
std::vector<Task> tasks; //preparing list of graphics to load
|
||||
tasks += boost::bind(&Graphics::loadFonts,this);
|
||||
tasks += boost::bind(&Graphics::loadPaletteAndColors,this);
|
||||
tasks += boost::bind(&Graphics::loadHeroFlags,this);
|
||||
tasks += boost::bind(&Graphics::initializeBattleGraphics,this);
|
||||
tasks += boost::bind(&Graphics::loadErmuToPicture,this);
|
||||
tasks += GET_DEF_ESS(artDefs,"ARTIFACT.DEF");
|
||||
tasks += GET_DEF_ESS(resources32,"RESOURCE.DEF");
|
||||
tasks += GET_DEF(smi2,"TWCRPORT.DEF");
|
||||
tasks += GET_DEF_ESS(flags,"CREST58.DEF");
|
||||
tasks += GET_DEF_ESS(spellscr,"SPELLSCR.DEF");
|
||||
tasks += GET_DEF_ESS(heroMoveArrows,"ADAG.DEF");
|
||||
|
||||
@ -142,16 +137,6 @@ Graphics::Graphics()
|
||||
{
|
||||
CSDL_Ext::alphaTransform(heroMoveArrows->ourImages[y].bitmap);
|
||||
}
|
||||
|
||||
smi2->notFreeImgs = true;
|
||||
for (size_t i=0; i<smi2->ourImages.size(); ++i)
|
||||
{
|
||||
bigImgs[i-2] = smi2->ourImages[i].bitmap;
|
||||
}
|
||||
//hack for green color on big infernal troglodite image - Mantis #758
|
||||
SDL_Color green = {0x30, 0x5c, 0x20, SDL_ALPHA_OPAQUE};
|
||||
bigImgs[71]->format->palette->colors[7] = green;
|
||||
delete smi2;
|
||||
}
|
||||
|
||||
void Graphics::loadHeroAnims()
|
||||
|
@ -46,10 +46,8 @@ public:
|
||||
SDL_Color * playerColorPalette; //palette to make interface colors good - array of size [256]
|
||||
SDL_Color * neutralColorPalette;
|
||||
|
||||
CDefEssential * artDefs; //artifacts //TODO: move to CArtifact class
|
||||
std::vector<CDefEssential *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,
|
||||
CDefEssential * resources32; //resources 32x32
|
||||
CDefEssential * flags;
|
||||
CDefEssential * heroMoveArrows;
|
||||
std::map<std::string, CDefEssential *> heroAnims; // [hero class def name] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
|
||||
std::vector<CDefEssential *> boatAnims; // [boat type: 0 - 3] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
|
||||
@ -59,8 +57,6 @@ public:
|
||||
std::map<std::string, CDefEssential *> advmapobjGraphics;
|
||||
CDefEssential * getDef(const CGObjectInstance * obj);
|
||||
CDefEssential * getDef(const CGDefInfo * info);
|
||||
//creatures
|
||||
std::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border
|
||||
//towns
|
||||
std::map<int, std::string> ERMUtoPicture[GameConstants::F_NUMBER]; //maps building ID to it's picture's name for each town type
|
||||
//for battles
|
||||
|
@ -317,80 +317,26 @@ void CCreatureHandler::loadCreatures()
|
||||
|
||||
BOOST_FOREACH(auto & node, config.Struct())
|
||||
{
|
||||
const JsonNode &creature = node.second;
|
||||
int creatureID = creature["id"].Float();
|
||||
const JsonNode *value;
|
||||
|
||||
// Set various creature properties
|
||||
int creatureID = node.second["id"].Float();
|
||||
CCreature *c = creatures[creatureID];
|
||||
c->level = creature["level"].Float();
|
||||
|
||||
c->animDefName = creature["defname"].String();
|
||||
|
||||
VLC->modh->identifiers.requestIdentifier(std::string("faction.") + creature["faction"].String(), [=](si32 faction)
|
||||
BOOST_FOREACH(const JsonNode &ability, node.second["ability_remove"].Vector())
|
||||
{
|
||||
c->faction = faction;
|
||||
});
|
||||
|
||||
BOOST_FOREACH(const JsonNode &value, creature["upgrades"].Vector())
|
||||
RemoveAbility(c, ability);
|
||||
}
|
||||
BOOST_FOREACH(const JsonNode &ability, node.second["abilities"].Vector())
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier(std::string("creature.") + value.String(), [=](si32 identifier)
|
||||
{
|
||||
c->upgrades.insert(identifier);
|
||||
});
|
||||
AddAbility(c, ability.Vector());
|
||||
}
|
||||
|
||||
value = &creature["projectile_defname"];
|
||||
if (!value->isNull())
|
||||
{
|
||||
c->projectile = value->String();
|
||||
|
||||
value = &creature["projectile_spin"];
|
||||
c->projectileSpin = value->Bool();
|
||||
}
|
||||
|
||||
value = &creature["ability_remove"];//remove first - arch devil
|
||||
if (!value->isNull())
|
||||
{
|
||||
BOOST_FOREACH(const JsonNode &ability, value->Vector())
|
||||
{
|
||||
RemoveAbility(c, ability);
|
||||
}
|
||||
}
|
||||
|
||||
value = &creature["abilities"];
|
||||
if (!value->isNull()) {
|
||||
BOOST_FOREACH(const JsonNode &ability, value->Vector())
|
||||
{
|
||||
AddAbility(c, ability.Vector());
|
||||
}
|
||||
}
|
||||
|
||||
c->special = creature["special"].Bool();
|
||||
if ( c->special )
|
||||
notUsedMonsters.insert(c->idNumber);
|
||||
|
||||
const JsonNode & sounds = creature["sound"];
|
||||
|
||||
#define GET_SOUND_VALUE(value_name) c->sounds.value_name = sounds[#value_name].String()
|
||||
GET_SOUND_VALUE(attack);
|
||||
GET_SOUND_VALUE(defend);
|
||||
GET_SOUND_VALUE(killed);
|
||||
GET_SOUND_VALUE(move);
|
||||
GET_SOUND_VALUE(shoot);
|
||||
GET_SOUND_VALUE(wince);
|
||||
GET_SOUND_VALUE(ext1);
|
||||
GET_SOUND_VALUE(ext2);
|
||||
GET_SOUND_VALUE(startMoving);
|
||||
GET_SOUND_VALUE(endMoving);
|
||||
#undef GET_SOUND_VALUE
|
||||
loadCreatureJson(c, node.second);
|
||||
|
||||
// Main reference name, e.g. royalGriffin
|
||||
c->nameRef = node.first;
|
||||
VLC->modh->identifiers.registerObject("creature." + node.first, c->idNumber);
|
||||
|
||||
// Alternative names, if any
|
||||
BOOST_FOREACH(const JsonNode &name, creature["extraNames"].Vector())
|
||||
BOOST_FOREACH(const JsonNode &name, node.second["extraNames"].Vector())
|
||||
{
|
||||
VLC->modh->identifiers.registerObject("creature." + name.String(), c->idNumber);
|
||||
}
|
||||
@ -618,7 +564,6 @@ CCreature * CCreatureHandler::loadCreature(const JsonNode & node)
|
||||
|
||||
cre->cost = Res::ResourceSet(node["cost"]);
|
||||
|
||||
cre->level = node["level"].Float();
|
||||
cre->fightValue = node["fightValue"].Float();
|
||||
cre->AIValue = node["aiValue"].Float();
|
||||
cre->growth = node["growth"].Float();
|
||||
@ -636,24 +581,6 @@ CCreature * CCreatureHandler::loadCreature(const JsonNode & node)
|
||||
cre->ammMin = amounts["min"].Float();
|
||||
cre->ammMax = amounts["max"].Float();
|
||||
|
||||
std::string factionStr = node["faction"].String();
|
||||
if (factionStr.empty())
|
||||
factionStr = "neutral"; //TODO: should be done in schema
|
||||
|
||||
VLC->modh->identifiers.requestIdentifier(std::string("faction.") + factionStr, [=](si32 faction)
|
||||
{
|
||||
cre->faction = faction;
|
||||
});
|
||||
|
||||
//optional
|
||||
BOOST_FOREACH (auto & str, node["upgrades"].Vector())
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier(std::string("creature.") + str.String(), [=](si32 identifier)
|
||||
{
|
||||
cre->upgrades.insert(identifier);
|
||||
});
|
||||
}
|
||||
|
||||
if (!node["shots"].isNull())
|
||||
cre->addBonus(node["shots"].Float(), Bonus::SHOTS);
|
||||
|
||||
@ -709,7 +636,6 @@ CCreature * CCreatureHandler::loadCreature(const JsonNode & node)
|
||||
//graphics
|
||||
|
||||
const JsonNode & graphics = node["graphics"];
|
||||
cre->animDefName = graphics["animation"].String();
|
||||
cre->timeBetweenFidgets = graphics["timeBetweenFidgets"].Float();
|
||||
cre->troopCountLocationOffset = graphics["troopCountLocationOffset"].Float();
|
||||
cre->attackClimaxFrame = graphics["attackClimaxFrame"].Float();
|
||||
@ -718,12 +644,8 @@ CCreature * CCreatureHandler::loadCreature(const JsonNode & node)
|
||||
cre->walkAnimationTime = animationTime["walk"].Float();
|
||||
cre->attackAnimationTime = animationTime["attack"].Float();
|
||||
cre->flightAnimationDistance = animationTime["flight"].Float(); //?
|
||||
//TODO: background?
|
||||
const JsonNode & missile = graphics["missile"];
|
||||
//TODO: parse
|
||||
cre->projectile = missile["projectile"].String();
|
||||
cre->projectileSpin = missile["spinning"].Bool();
|
||||
|
||||
const JsonNode & missile = graphics["missile"];
|
||||
const JsonNode & offsets = missile["offset"];
|
||||
cre->upperRightMissleOffsetX = offsets["upperX"].Float();
|
||||
cre->upperRightMissleOffsetY = offsets["upperY"].Float();
|
||||
@ -739,9 +661,38 @@ CCreature * CCreatureHandler::loadCreature(const JsonNode & node)
|
||||
cre->advMapDef = graphics["map"].String();
|
||||
cre->iconIndex = graphics["iconIndex"].Float();
|
||||
|
||||
const JsonNode & sounds = node["sound"];
|
||||
loadCreatureJson(cre, node);
|
||||
return cre;
|
||||
}
|
||||
|
||||
#define GET_SOUND_VALUE(value_name) do { cre->sounds.value_name = sounds[#value_name].String(); } while(0)
|
||||
void CCreatureHandler::loadCreatureJson(CCreature * creature, const JsonNode & config)
|
||||
{
|
||||
creature->level = config["level"].Float();
|
||||
creature->animDefName = config["graphics"]["animation"].String();
|
||||
|
||||
VLC->modh->identifiers.requestIdentifier(std::string("faction.") + config["faction"].String(), [=](si32 faction)
|
||||
{
|
||||
creature->faction = faction;
|
||||
});
|
||||
|
||||
BOOST_FOREACH(const JsonNode &value, config["upgrades"].Vector())
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier(std::string("creature.") + value.String(), [=](si32 identifier)
|
||||
{
|
||||
creature->upgrades.insert(identifier);
|
||||
});
|
||||
}
|
||||
|
||||
creature->projectile = config["graphics"]["missile"]["projectile"].String();
|
||||
creature->projectileSpin = config["graphics"]["missile"]["spinning"].Bool();
|
||||
|
||||
creature->special = config["special"].Bool();
|
||||
if ( creature->special )
|
||||
notUsedMonsters.insert(creature->idNumber);
|
||||
|
||||
const JsonNode & sounds = config["sound"];
|
||||
|
||||
#define GET_SOUND_VALUE(value_name) creature->sounds.value_name = sounds[#value_name].String()
|
||||
GET_SOUND_VALUE(attack);
|
||||
GET_SOUND_VALUE(defend);
|
||||
GET_SOUND_VALUE(killed);
|
||||
@ -753,8 +704,6 @@ CCreature * CCreatureHandler::loadCreature(const JsonNode & node)
|
||||
GET_SOUND_VALUE(startMoving);
|
||||
GET_SOUND_VALUE(endMoving);
|
||||
#undef GET_SOUND_VALUE
|
||||
|
||||
return cre;
|
||||
}
|
||||
|
||||
void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, CLegacyConfigParser & parser) //help function for parsing CREXPBON.txt
|
||||
|
@ -125,9 +125,11 @@ public:
|
||||
|
||||
class DLL_LINKAGE CCreatureHandler
|
||||
{
|
||||
private: //?
|
||||
private:
|
||||
CBonusSystemNode allCreatures;
|
||||
CBonusSystemNode creaturesOfLevel[GameConstants::CREATURES_PER_TOWN + 1];//index 0 is used for creatures of unknown tier or outside <1-7> range
|
||||
|
||||
void loadCreatureJson(CCreature * creature, const JsonNode & config);
|
||||
public:
|
||||
std::set<int> notUsedMonsters;
|
||||
std::set<TCreature> doubledCreatures; //they get double week
|
||||
|
Loading…
Reference in New Issue
Block a user