1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

- Fixed some issues and crashes

- Simplified projectile handling. New creatures can now shoot.
This commit is contained in:
DjWarmonger 2012-09-21 19:49:35 +00:00
parent 8e3de98059
commit e2bfd53c98
8 changed files with 29 additions and 24 deletions

View File

@ -768,13 +768,7 @@ bool CShootingAnimation::init()
spi.step = 0;
spi.frameNum = 0;
if(vstd::contains(CGI->creh->idToProjectileSpin, shooterInfo->idNumber))
spi.spin = CGI->creh->idToProjectileSpin[shooterInfo->idNumber];
else
{
tlog2 << "Warning - no projectile spin for spi.creID " << shooterInfo->idNumber << std::endl;
spi.spin = false;
}
spi.spin = shooterInfo->projectileSpin;
Point xycoord = CClickableHex::getXYUnitAnim(shooter->position, true, shooter, owner);
Point destcoord;

View File

@ -284,10 +284,10 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
BOOST_FOREACH(const CStack *s, stacks)
{
int creID = (s->getCreature()->idNumber == 149) ? CGI->creh->factionToTurretCreature[siegeH->town->town->typeID] : s->getCreature()->idNumber; //id of creature whose shots should be loaded
if(s->getCreature()->isShooting() && vstd::contains(CGI->creh->idToProjectile, creID))
if(s->getCreature()->isShooting())
{
CDefHandler *&projectile = idToProjectile[s->getCreature()->idNumber];
projectile = CDefHandler::giveDef(CGI->creh->idToProjectile[creID]);
projectile = CDefHandler::giveDef(s->getCreature()->projectile);
if(projectile->ourImages.size() > 2) //add symmetric images
{

View File

@ -33,6 +33,7 @@
#include "../lib/VCMIDirs.h"
#include "../lib/NetPacks.h"
#include "CMessage.h"
#include "../lib/CModHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CScriptingModule.h"
@ -758,8 +759,9 @@ static void listenForEvents()
vstd::clear_pointer(client);
delete CGI->dobjinfo.get();
const_cast<CGameInfo*>(CGI)->dobjinfo = new CDefObjInfoHandler;
const_cast<CGameInfo*>(CGI)->dobjinfo = new CDefObjInfoHandler;
const_cast<CGameInfo*>(CGI)->dobjinfo->load();
const_cast<CGameInfo*>(CGI)->modh->recreateAdvMapDefs(); //add info about new creatures to dobjinfo
};
switch(ev.user.code)

View File

@ -432,10 +432,10 @@ void CCreatureHandler::loadCreatures()
value = &creature["projectile_defname"];
if (!value->isNull())
{
idToProjectile[creatureID] = value->String();
c->projectile = value->String();
value = &creature["projectile_spin"];
idToProjectileSpin[creatureID] = value->Bool();
c->projectileSpin = value->Bool();
}
value = &creature["turret_shooter"];

View File

@ -47,6 +47,7 @@ public:
double missleFrameAngles[12];
int troopCountLocationOffset, attackClimaxFrame;
std::string projectile;
ui8 projectileSpin; //if true, appropriate projectile is spinning during flight
///end of anim info
//sound info
@ -109,7 +110,7 @@ public:
& timeBetweenFidgets & walkAnimationTime & attackAnimationTime & flightAnimationDistance
& upperRightMissleOffsetX & rightMissleOffsetX & lowerRightMissleOffsetX & upperRightMissleOffsetY & rightMissleOffsetY & lowerRightMissleOffsetY
& missleFrameAngles & troopCountLocationOffset & attackClimaxFrame;
h & sounds & projectile;
h & sounds & projectile & projectileSpin;
h & doubleWide;
}
@ -129,8 +130,6 @@ public:
std::set<TCreature> doubledCreatures; //they get double week
std::vector<ConstTransitivePtr<CCreature> > creatures; //creature ID -> creature info
bmap<std::string,int> nameToID;
bmap<int,std::string> idToProjectile;
bmap<int,bool> idToProjectileSpin; //if true, appropriate projectile is spinning during flight
std::vector<si8> factionAlignments; //1 for good, 0 for neutral and -1 for evil with faction ID as index
int factionToTurretCreature[GameConstants::F_NUMBER]; //which creature's animation should be used to dispaly creature in turret while siege
@ -168,7 +167,7 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
//TODO: should be optimized, not all these informations needs to be serialized (same for ccreature)
h & notUsedMonsters & creatures & nameToID & idToProjectile & idToProjectileSpin & factionToTurretCreature;
h & notUsedMonsters & creatures & nameToID & factionToTurretCreature;
h & stackBonuses & expRanks & maxExpPerBattle & expAfterUpgrade;
h & factionCommanders & skillLevels & skillRequirements & commanderLevelPremy;
h & allCreatures;

View File

@ -234,10 +234,10 @@ CCreature * CModHandler::loadCreature (const JsonNode &node)
cre->missleFrameAngles[i++] = angle.Float();
}
cre->advMapDef = graphics["map"].String();
//TODO: we need to know creature id to add it
//FIXME: creature handler is not yet initialized
//VLC->creh->idToProjectile[cre->idNumber] = "PLCBOWX.DEF";
//TODO: parse
cre->projectile = "PLCBOWX.DEF";
cre->projectileSpin = false;
const JsonNode & sounds = node["sound"];
@ -257,6 +257,16 @@ CCreature * CModHandler::loadCreature (const JsonNode &node)
creatures.push_back(cre);
return cre;
}
void CModHandler::recreateAdvMapDefs()
{
BOOST_FOREACH (auto creature, creatures)
{
//generate adventure map object info & graphics
CGDefInfo* nobj = new CGDefInfo (*VLC->dobjinfo->gobjs[GameConstants::CREI_TYPE][0]);//copy all typical properties
nobj->name = creature->advMapDef; //change only def name (?)
VLC->dobjinfo->gobjs[GameConstants::CREI_TYPE][creature->idNumber] = nobj;
}
}
void CModHandler::recreateHandlers()
{
//TODO: consider some template magic to unify all handlers?
@ -273,11 +283,8 @@ void CModHandler::recreateHandlers()
// VLC->creh->nameToID[creature->nameRef] = creature->idNumber;
VLC->creh->nameToID[creature->nameSing] = creature->idNumber;
//generate adventure map object info & graphics
CGDefInfo* nobj = new CGDefInfo (*VLC->dobjinfo->gobjs[GameConstants::CREI_TYPE][0]);//copy all typical properties
nobj->name = creature->advMapDef; //change only def name (?)
VLC->dobjinfo->gobjs[GameConstants::CREI_TYPE][creature->idNumber] = nobj;
}
recreateAdvMapDefs();
BOOST_FOREACH (auto creature, VLC->creh->creatures) //populate upgrades described with string
{
BOOST_FOREACH (auto upgradeName, creature->upgradeNames)

View File

@ -75,7 +75,8 @@ public:
void loadConfigFromFile (std::string name);
void saveConfigToFile (std::string name);
CCreature * loadCreature (const JsonNode &node); //TODO: handler collections now use ModHandler vector index. Should they be aligned according to mods actually used??
CCreature * loadCreature (const JsonNode &node);
void recreateAdvMapDefs();
void recreateHandlers();
struct DLL_LINKAGE hardcodedFeatures

View File

@ -102,6 +102,7 @@ void LibClasses::init()
tlog0<<"\tSpell handler: "<<pomtime.getDiff()<<std::endl;
modh->recreateHandlers(); //load all new creatures parsed in the meantime.
//FIXME: make sure that everything is ok after game restart
//TODO: This should be done every time mod config changes
IS_AI_ENABLED = false;
@ -145,6 +146,7 @@ void LibClasses::callWhenDeserializing()
generaltexth = new CGeneralTextHandler;
generaltexth->load();
arth->loadArtifacts(true);
//modh->recreateHandlers();
//modh->loadConfigFromFile ("defaultMods"); //TODO: remember last saved config
}