1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

- merged basicCreatures and upgradedCreatures into single array

- missing fix for savegames
This commit is contained in:
Ivan Savenko 2012-08-07 21:46:24 +00:00
parent 8040a81eec
commit 9cbc1f1058
13 changed files with 84 additions and 107 deletions

View File

@ -2975,7 +2975,10 @@ TSubgoal CGoal::whatToDoToAchieve()
auto creature = VLC->creh->creatures[objid];
if (t->subID == creature->faction) //TODO: how to force AI to build unupgraded creatures? :O
{
int bid = t->creatureDwelling(creature->level);
auto creatures = t->town->creatures[creature->level];
int upgradeNumber = std::find(creatures.begin(), creatures.end(), creature->idNumber) - creatures.begin();
int bid = EBuilding::DWELL_FIRST + creature->level + upgradeNumber * GameConstants::CREATURES_PER_TOWN;
if (t->hasBuilt(bid)) //this assumes only creatures with dwellings are assigned to faction
{
dwellings.push_back(t);

View File

@ -1591,7 +1591,7 @@ CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance *
if (!town->creatures[level].second.empty())
creature = CGI->creh->creatures[town->creatures[level].second.back()];
else
creature = CGI->creh->creatures[town->town->basicCreatures[level]];
creature = CGI->creh->creatures[town->town->creatures[level][0]];
hoverText = boost::str(boost::format(CGI->generaltexth->tcommands[21]) % creature->namePl);
creatureAnim = new CCreaturePic(159, 4, creature, false);

View File

@ -2521,7 +2521,7 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState )
int x = 60, y = 159;
for(int i = 0; i < 7; i++)
{
int c = t.basicCreatures[i];
int c = t.creatures[i][0];
blitAt(graphics->smallImgs[c], x, y, bmp);
CSDL_Ext::printAtMiddleWB(CGI->creh->creatures[c]->nameSing, x + 16, y + 45, FONT_TINY, 10, Colors::Cornsilk, bmp);

View File

@ -761,10 +761,12 @@ void YourTurn::applyCl( CClient *cl )
void SaveGame::applyCl(CClient *cl)
{
tlog1 << "Saving to " << fname << "\n";
CFileInfo info(fname);
CResourceHandler::get()->createResource(info.getStem() + ".vcgm1");
//FIXME: Workaround for a file that was created by server and in future should be used only by server
CResourceHandler::get()->createResource(info.getStem() + ".vlgm1");
try
{
CSaveFile save(CResourceHandler::get()->getResourceName(ResourceID(info.getStem(), EResType::CLIENT_SAVEGAME)));

View File

@ -22,8 +22,7 @@
"properties" :
{
"blit_order" : { "type" : "array", "items" : {"type":"number"}, "default" :[] },
"creatures_basic" : { "type" : "array", "items" : {"type":"number"} },
"creatures_upgraded" :{ "type" : "array", "items" : {"type":"number"} },
"creatures" : { "type" : "array", "items" : { "type" : "array", "items" : {"type":"number"} } },
"horde" : { "type" : "array", "items" : {"type":"number", "default" : -1} },
"primary_resource" : { "type" : "number", "default" : 127},
"mage_guild" : { "type" : "number", "default" : 5},
@ -132,8 +131,7 @@
{ "id" : 20, "defname" : "TBCSBOAT.def", "x" : 478, "y" : 134, "border" : "TOCSDKMN.bmp", "area" : "TZCSDKMN.bmp" }
],
"blit_order" : [ 0, 1, 2, 3, 10, 11, 12, 13, 5, 22, 30, 37, 16, 6, 20, 18, 19, 34, 41 ],
"creatures_basic" : [ 0, 2, 4, 6, 8, 10, 12, 150 ],
"creatures_upgraded" : [ 1, 3, 5, 7, 9, 11, 13 ],
"creatures" : [ [0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13] ],
"horde" : [ 2, null ],
"mage_guild" : 4,
"war_machine" : 4,
@ -221,8 +219,7 @@
{ "id" : 11, "defname" : "TBRMHAL2.def", "x" : 538, "y" : 187, "border" : "TORHAL2.bmp", "area" : "TZRHAL2.bmp" }
],
"blit_order" : [ 33, 40, 35, 42, 16, 32, 39, 0, 1, 2, 3, 4, 31, 18, 38, 19, 34, 24, 41, 25, 5, 30, 37, 14, 10, 11, 12, 13, 17, 21, 22, -1, 27, 28, 29, 15 ],
"creatures_basic" : [ 14, 16, 18, 20, 22, 24, 26, 151 ],
"creatures_upgraded" : [ 15, 17, 19, 21, 23, 25, 27 ],
"creatures" : [ [14, 15], [16, 17], [18, 19], [20, 21], [22, 23], [24, 25], [26, 27] ],
"horde" : [ 1, 4 ],
"mage_guild" : 5,
"primary_resource" : 4,
@ -306,8 +303,7 @@
{ "id" : 8, "defname" : "TBTWCAS2.def", "x" : 301, "y" : 0, "border" : "TOTCAS2.bmp", "area" : "TZTCAS2.bmp" }
],
"blit_order" : [ 36, 43, 32, 39, 10, 11, 12, 13, 32, 35, 42, 15, 5, 18, 19 ],
"creatures_basic" : [ 28, 30, 32, 34, 36, 38, 40, 152 ],
"creatures_upgraded" : [ 29, 31, 33, 35, 37, 39, 41 ],
"creatures" : [ [28, 29], [30, 31], [32, 33], [34, 35], [36, 37], [38, 39], [40, 41] ],
"horde" : [ 1, null ],
"primary_resource" : 5,
"war_machine" : 5,
@ -391,8 +387,7 @@
{ "id" : 8, "defname" : "TBINCAS2.def", "x" : 222, "y" : 44, "border" : "TOICAS1A.bmp", "area" : "TZICAS1A.bmp" }
],
"blit_order" : [ 26, 21, 7, 8, 9, 22, 31, 38, 36, 43, 10, 11, 12, 13, 5, 32, 39, 24, 25, 33, 40, 34, 41, 30, 37, 18, 19, 14, 15, 16, 35, 42 ],
"creatures_basic" : [ 42, 44, 46, 48, 50, 52, 54, 153 ],
"creatures_upgraded" : [ 43, 45, 47, 49, 51, 53, 55 ],
"creatures" : [ [42, 43], [44, 45], [46, 47], [48, 49], [50, 51], [52, 53], [54, 55] ],
"horde" : [ 0, 2 ],
"primary_resource" : 1,
"war_machine" : 5,
@ -481,8 +476,7 @@
{ "id" : 20, "defname" : "TBNCBOAT.def", "x" : 617, "y" : 265, "border" : "TONSHPNA.bmp", "area" : "TZNSHPNA.bmp" }
],
"blit_order" : [ 17, 0, 1, 2, 3, 4, 7, 8, 9, 32, 39, 26, 15, 14, 34, 41, 16, 5, 33, 40, 31, 38, 6, 30, 18, 37, 19, 22, 20 ],
"creatures_basic" : [ 56, 58, 60, 62, 64, 66, 68, 154 ],
"creatures_upgraded" : [ 57, 59, 61, 63, 65, 67, 69 ],
"creatures" : [ [56, 57], [58, 59], [60, 61], [62, 63], [64, 65], [66, 67], [68, 69] ],
"horde" : [ 0, null ],
"war_machine" : 6,
@ -564,8 +558,7 @@
{ "id" : 8, "defname" : "TBDNCAS2.def", "x" : 363, "y" : 87, "border" : "TODCAS2.bmp", "area" : "TZDCAS2.bmp" }
],
"blit_order" : [ 0, 1, 2, 3, 4, 21, 35, 42, 5, 30, 18, 37, 19, 32, 39, 26, 7, 8, 9, 23 ],
"creatures_basic" : [ 70, 72, 74, 76, 78, 80, 82, 155 ],
"creatures_upgraded" : [ 71, 73, 75, 77, 79, 81, 83 ],
"creatures" : [ [70, 71], [72, 73], [74, 75], [76, 77], [78, 79], [80, 81], [82, 83] ],
"horde" : [ 0, null ],
"primary_resource" : 3,
"war_machine" : 4,
@ -645,8 +638,7 @@
{ "id" : 16, "defname" : "TBSTBLAK.def", "x" : 660, "y" : 286, "border" : "TOSBLK1.bmp", "area" : "TZSBLK1.bmp" }
],
"blit_order" : [ 33, 40, 30, 18, 37, 19, 31, 38, 23, 26, 5, 32, 39, 15, 14, 21, 16, 22 ],
"creatures_basic" : [ 84, 86, 88, 90, 92, 94, 96, 156 ],
"creatures_upgraded" : [ 85, 87, 89, 91, 93, 95, 97 ],
"creatures" : [ [84, 85], [86, 87], [88, 89], [90, 91], [92, 93], [94, 95], [96, 97] ],
"horde" : [ 0, null ],
"mage_guild" : 3,
"war_machine" : 5,
@ -730,8 +722,7 @@
{ "id" : 20, "defname" : "TBFRBOAT.def", "x" : 197, "y" : 294, "border" : "TOFDCK1.bmp", "area" : "TZFDCK1.bmp" }
],
"blit_order" : [ 16, 15, 14, 34, 41, 31, 38, 10, 11, 12, 13, 29, 0, 1, 2, 33, 40, 30, 18, 37, 19, 5, 36, 43, 26 ],
"creatures_basic" : [ 98, 100, 104, 106, 102, 108, 110, 157 ],
"creatures_upgraded" : [ 99, 101, 105, 107, 103, 109, 111 ],
"creatures" : [ [98, 99], [100, 101], [102, 103], [104, 105], [106, 107], [108, 109], [110, 111] ],
"horde" : [ 0, null ],
"mage_guild" : 3,
"war_machine" : 6,
@ -818,8 +809,7 @@
{ "id" : 20, "defname" : "TBELBOAT.def", "x" : 239, "y" : 215, "border" : "TOELBOAT.bmp", "area" : "TZELBOAT.bmp" }
],
"blit_order" : [ -1, 27, 28, 16, 34, 41, 6, 20, 33, 40, 36, 43, 21, 0, 1, 2, 3, 4, 5, 15, 14, 17, 35, 42, 30, 18, 37, 19, 10, 11, 12, 13, 29 ],
"creatures_basic" : [ 118, 112, 115, 114, 113, 120, 130, 158 ],
"creatures_upgraded" : [ 119, 127, 123, 129, 125, 121, 131 ],
"creatures" : [ [118, 119], [112, 127], [115, 123], [114, 129], [113, 125], [120, 121], [130, 131] ],
"horde" : [ 0, null ],
"primary_resource" : 1,
"war_machine" : 4,

View File

@ -89,12 +89,14 @@ void CBuildingHandler::loadBuildings()
{
temp = readTo(buf,it,'\n');//read blank line
temp = readTo(buf,it,'\n');// and faction name
for(int bg = 0; bg<14; bg++)
for(int bg = 0; ; bg++)
{
CBuilding *nb = readBg(buf,it);
nb->tid = i;
nb->bid = bg+30;
buildings[i][bg+30] = nb;
if (it >= buf.size() || buf[it] == '\t') //read till empty line
break;
}
}
/////done reading BUILDING.TXT*****************************

View File

@ -589,7 +589,7 @@ std::pair<int,int> CGameState::pickObject (CGObjectInstance *obj)
dwl->info = nullptr;
std::pair<int,int> result(-1, -1);
int cid = VLC->townh->towns[faction].basicCreatures[level];
int cid = VLC->townh->towns[faction].creatures[level][0];
//golem factory is not in list of cregens but can be placed as random object
static const int factoryCreatures[] = {32, 33, 116, 117};

View File

@ -1889,11 +1889,16 @@ int CGTownInstance::mageGuildLevel() const
return 1;
return 0;
}
bool CGTownInstance::creatureDwelling(const int & level, bool upgraded) const
int CGTownInstance::creatureDwellingLevel(int dwelling) const
{
if ( level<0 || level >= GameConstants::CREATURES_PER_TOWN )
return false;
return vstd::contains(builtBuildings, 30+level+upgraded*GameConstants::CREATURES_PER_TOWN);
if ( dwelling<0 || dwelling >= GameConstants::CREATURES_PER_TOWN )
return -1;
for (int i=0; ; i++)
{
if (!vstd::contains(builtBuildings, 30+dwelling+i*GameConstants::CREATURES_PER_TOWN))
return i-1;
}
}
int CGTownInstance::getHordeLevel(const int & HID) const//HID - 0 or 1; returns creature level or -1 if that horde structure is not present
{
@ -2075,10 +2080,10 @@ void CGTownInstance::initObj()
creatures.resize(GameConstants::CREATURES_PER_TOWN);
for (int i = 0; i < GameConstants::CREATURES_PER_TOWN; i++)
{
if(creatureDwelling(i,false))
creatures[i].second.push_back(town->basicCreatures[i]);
if(creatureDwelling(i,true))
creatures[i].second.push_back(town->upgradedCreatures[i]);
int dwellingLevel = creatureDwellingLevel(i);
int creaturesTotal = town->creatures[i].size();
for (int j=0; j< std::min(dwellingLevel + 1, creaturesTotal); j++)
creatures[i].second.push_back(town->creatures[i][j]);
}
switch (subID)
@ -2149,7 +2154,7 @@ void CGTownInstance::newTurn() const
if ((stacksCount() < GameConstants::ARMY_SIZE && rand()%100 < 25) || Slots().empty()) //add new stack
{
int i = rand() % std::min (GameConstants::ARMY_SIZE, cb->getDate(3)<<1);
TCreature c = town->basicCreatures[i];
TCreature c = town->creatures[i][0];
TSlot n = -1;
TQuantity count = creatureGrowth(i);
@ -2233,7 +2238,7 @@ void CGTownInstance::removeCapitols (ui8 owner) const
int CGTownInstance::getBoatType() const
{
const CCreature *c = VLC->creh->creatures[town->basicCreatures.front()];
const CCreature *c = VLC->creh->creatures[town->creatures.front().front()];
if (c->isGood())
return 1;
else if (c->isEvil())
@ -6844,9 +6849,9 @@ void CArmedInstance::randomizeArmy(int type)
if(randID > max)
{
if(randID % 2)
j->second->setType(VLC->townh->towns[type].basicCreatures[(randID-197) / 2 -1]);
j->second->setType(VLC->townh->towns[type].creatures[(randID-197) / 2 -1][0]);
else
j->second->setType(VLC->townh->towns[type].upgradedCreatures[(randID-197) / 2 -1]);
j->second->setType(VLC->townh->towns[type].creatures[(randID-197) / 2 -1][1]);
randID = -1;
}

View File

@ -630,7 +630,7 @@ public:
CGTownInstance::EFortLevel fortLevel() const;
int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
int mageGuildLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
bool creatureDwelling(const int & level, bool upgraded=false) const;
int creatureDwellingLevel(int dwelling) const;
int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present
int creatureGrowth(const int & level) const;
GrowthInfo getGrowthInfo(int level) const;

View File

@ -40,12 +40,8 @@ void CTownHandler::loadStructures()
towns.push_back(town);
}
for(int x=0;x<towns.size();x++) {
/* There is actually 8 basic creatures, but we ignore the 8th
* entry for now */
towns[x].basicCreatures.resize(7);
towns[x].upgradedCreatures.resize(7);
}
for(int x=0;x<towns.size();x++)
towns[x].creatures.resize(GameConstants::CREATURES_PER_TOWN);
structures.resize(GameConstants::F_NUMBER);
@ -96,19 +92,14 @@ void CTownHandler::loadStructures()
tlog3 << "Warning1: No building " << buildingID << " in the castle " << townID << std::endl;
}
// Read basic creatures belonging to that city
// Read creatures belonging to that city
level = 0;
BOOST_FOREACH(const JsonNode &node, town_node["creatures_basic"].Vector()) {
// This if ignores the 8th field (WoG creature)
if (level < towns[townID].basicCreatures.size())
towns[townID].basicCreatures[level] = node.Float();
level ++;
}
// Read upgraded creatures belonging to that city
level = 0;
BOOST_FOREACH(const JsonNode &node, town_node["creatures_upgraded"].Vector()) {
towns[townID].upgradedCreatures[level] = node.Float();
BOOST_FOREACH(const JsonNode &list, town_node["creatures"].Vector())
{
BOOST_FOREACH(const JsonNode &node, list.Vector())
{
towns[townID].creatures[level].push_back(node.Float());
}
level ++;
}

View File

@ -23,8 +23,7 @@ class DLL_LINKAGE CTown
public:
std::vector<std::string> names; //names of the town instances
std::vector<int> basicCreatures; //level (from 0) -> ID
std::vector<int> upgradedCreatures; //level (from 0) -> ID
std::vector<std::vector<int> > creatures; //level (from 0) -> list of creatures on this tier
std::map<int,int> hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present)
ui32 mageLevel; //max available mage guild level
int bonus; //pic number
@ -39,7 +38,7 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & names & basicCreatures & upgradedCreatures & hordeLvl & mageLevel & bonus
h & names & creatures & hordeLvl & mageLevel & bonus
& primaryRes & warMachine & typeID;
}
};

View File

@ -84,7 +84,6 @@ std::string CFileInfo::getBaseName() const
return name.substr(begin, end - begin);
}
EResType::Type CFileInfo::getType() const
{
return EResTypeHelper::getTypeFromExtension(getExtension());

View File

@ -1286,7 +1286,7 @@ void CGameHandler::newTurn()
sac.creatures = t->creatures;
for (int k=0; k < GameConstants::CREATURES_PER_TOWN; k++) //creature growths
{
if(t->creatureDwelling(k))//there is dwelling (k-level)
if(t->creatureDwellingLevel(k) >= 0)//there is dwelling (k-level)
{
ui32 &availableCount = sac.creatures[k].first;
const CCreature *cre = VLC->creh->creatures[t->creatures[k].second.back()];
@ -2420,54 +2420,52 @@ bool CGameHandler::buildStructure( si32 tid, si32 bid, bool force /*=false*/ )
CGTownInstance * t = static_cast<CGTownInstance*>(gs->map->objects[tid].get());
CBuilding * b = VLC->buildh->buildings[t->subID][bid];
if( !force && gs->canBuildStructure(t,bid) != 7)
if(!force)
{
complain("Cannot build that building!");
return false;
}
if (gs->canBuildStructure(t,bid) != 7)
COMPLAIN_RET("Cannot build that building!");
if( !force && bid == 26) //grail
{
if(!t->visitingHero || !t->visitingHero->hasArt(2))
if(bid == 26) //grail
{
complain("Cannot build grail - hero doesn't have it");
return false;
if(!t->visitingHero || !t->visitingHero->hasArt(2))
COMPLAIN_RET("Cannot build grail - hero doesn't have it")
else
removeArtifact(ArtifactLocation(t->visitingHero, t->visitingHero->getArtPos(2, false)));
}
//remove grail
removeArtifact(ArtifactLocation(t->visitingHero, t->visitingHero->getArtPos(2, false)));
}
NewStructures ns;
ns.tid = tid;
//we have upgr. dwelling, upgr. horde will be builded as well
if ( (bid == 18) && (vstd::contains(t->builtBuildings,(t->town->hordeLvl[0]+37))) )
ns.bid.insert(19);//we have upgr. dwelling, upgr. horde will be builded as well
ns.bid.insert(19);
else if ( (bid == 24) && (vstd::contains(t->builtBuildings,(t->town->hordeLvl[1]+37))) )
ns.bid.insert(25);
else if(bid>36) //upg dwelling
else if(bid >= EBuilding::DWELL_FIRST) //dwelling
{
if ( (bid-37 == t->town->hordeLvl[0]) && (vstd::contains(t->builtBuildings,18)) )
ns.bid.insert(19);//we have horde, will be upgraded as well as dwelling
if ( (bid-37 == t->town->hordeLvl[1]) && (vstd::contains(t->builtBuildings,24)) )
ns.bid.insert(25);
int level = (bid - EBuilding::DWELL_FIRST) % GameConstants::CREATURES_PER_TOWN;
int upgradeNumber = (bid - EBuilding::DWELL_FIRST) / GameConstants::CREATURES_PER_TOWN;
if (upgradeNumber >= t->town->creatures[level].size())
COMPLAIN_RET("Cannot build dwelling: no creature found!");
CCreature * crea = VLC->creh->creatures[t->town->creatures[level][upgradeNumber]];
if (vstd::iswithin(bid, EBuilding::DWELL_UP_FIRST, EBuilding::DWELL_UP_LAST))
{
if ( (bid-37 == t->town->hordeLvl[0]) && (vstd::contains(t->builtBuildings,18)) )
ns.bid.insert(19);//we have horde, will be upgraded as well as dwelling
if ( (bid-37 == t->town->hordeLvl[1]) && (vstd::contains(t->builtBuildings,24)) )
ns.bid.insert(25);
}
SetAvailableCreatures ssi;
ssi.tid = tid;
ssi.creatures = t->creatures;
ssi.creatures[bid-37].second.push_back(t->town->upgradedCreatures[bid-37]);
//Test for 2nd upgrade - add sharpshooters if grand elves dwelling was constructed
//if (t->subID == 1 && bid == 39)
// ssi.creatures[bid-37].second.push_back(137);
sendAndApply(&ssi);
}
else if(bid >= 30) //bas. dwelling
{
int crid = t->town->basicCreatures[bid-30];
SetAvailableCreatures ssi;
ssi.tid = tid;
ssi.creatures = t->creatures;
ssi.creatures[bid-30].first = VLC->creh->creatures[crid]->growth;
ssi.creatures[bid-30].second.push_back(crid);
if (bid <= EBuilding::DWELL_LAST)
ssi.creatures[level].first = crea->growth;
ssi.creatures[level].second.push_back(crea->idNumber);
sendAndApply(&ssi);
}
else if(bid == 11)
@ -2476,18 +2474,6 @@ bool CGameHandler::buildStructure( si32 tid, si32 bid, bool force /*=false*/ )
ns.bid.insert(28);
else if(bid == 13)
ns.bid.insert(29);
else if (t->subID == 4 && bid == 17) //veil of darkness
{
//handled via town->reacreateBonuses in apply
// GiveBonus gb(GiveBonus::TOWN);
// gb.bonus.type = Bonus::DARKNESS;
// gb.bonus.val = 20;
// gb.id = t->id;
// gb.bonus.duration = Bonus::PERMANENT;
// gb.bonus.source = Bonus::TOWN_STRUCTURE;
// gb.bonus.id = 17;
// sendAndApply(&gb);
}
else if ( t->subID == 5 && bid == 22 )
{
setPortalDwelling(t);
@ -4709,7 +4695,7 @@ void CGameHandler::handleTownEvents(CGTownInstance * town, NewTurn &n, std::map<
for(si32 i=0;i<ev->creatures.size();i++) //creature growths
{
if(town->creatureDwelling(i) && ev->creatures[i])//there is dwelling
if(town->creatureDwellingLevel(i) >= 0 && ev->creatures[i])//there is dwelling
{
newCreas[town->id][i] += ev->creatures[i];
iw.components.push_back(Component(Component::CREATURE,