1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* moved graphics from CAbilityHandler to Graphics

* reading BALLIST.TXT
* minor changes
This commit is contained in:
mateuszb 2009-02-06 14:15:45 +00:00
parent 7b2585e422
commit ba9b58d3a4
14 changed files with 92 additions and 47 deletions

View File

@ -367,9 +367,9 @@ const CCreatureSet* CCallback::getGarrison(const CGObjectInstance *obj) const
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
if(!obj)
return NULL;
if(obj->ID == 34)
if(obj->ID == HEROI_TYPE)
return &(dynamic_cast<const CGHeroInstance*>(obj))->army;
else if(obj->ID == 98)
else if(obj->ID == TOWNI_TYPE)
return &(dynamic_cast<const CGTownInstance*>(obj)->army);
else return NULL;
}

View File

@ -108,7 +108,7 @@ CGObjectInstance * createObject(int id, int subid, int3 pos, int owner)
CGObjectInstance * nobj;
switch(id)
{
case 34: //hero
case HEROI_TYPE: //hero
{
CGHeroInstance * nobj = new CGHeroInstance();
nobj->pos = pos;
@ -117,7 +117,7 @@ CGObjectInstance * createObject(int id, int subid, int3 pos, int owner)
//nobj->initHero(ran);
return nobj;
}
case 98: //town
case TOWNI_TYPE: //town
nobj = new CGTownInstance;
break;
default: //rest of objects
@ -137,7 +137,7 @@ CGObjectInstance * createObject(int id, int subid, int3 pos, int owner)
nobj->defInfo->subid = subid;
//assigning defhandler
if(nobj->ID==34 || nobj->ID==98)
if(nobj->ID==HEROI_TYPE || nobj->ID==TOWNI_TYPE)
return nobj;
nobj->defInfo = VLC->dobjinfo->gobjs[id][subid];
return nobj;
@ -635,7 +635,7 @@ void CGameState::applyNL(IPack * pack)
{
RemoveObject *rh = static_cast<RemoveObject*>(pack);
CGObjectInstance *obj = map->objects[rh->id];
if(obj->ID==34)
if(obj->ID==HEROI_TYPE)
{
CGHeroInstance *h = static_cast<CGHeroInstance*>(obj);
std::vector<CGHeroInstance*>::iterator nitr = std::find(map->heroes.begin(), map->heroes.end(),h);
@ -685,9 +685,9 @@ void CGameState::applyNL(IPack * pack)
{
CArmedInstance *ai = static_cast<CArmedInstance*>(map->objects[i->first]);
ai->army = i->second;
if(ai->ID==98 && (static_cast<CGTownInstance*>(ai))->garrisonHero) //if there is a hero in garrison then we must update also his army
if(ai->ID==TOWNI_TYPE && (static_cast<CGTownInstance*>(ai))->garrisonHero) //if there is a hero in garrison then we must update also his army
const_cast<CGHeroInstance*>((static_cast<CGTownInstance*>(ai))->garrisonHero)->army = i->second;
else if(ai->ID==34)
else if(ai->ID==HEROI_TYPE)
{
CGHeroInstance *h = static_cast<CGHeroInstance*>(ai);
if(h->visitedTown && h->inTownGarrison)
@ -954,7 +954,7 @@ std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj)
return std::pair<int,int>(5,VLC->arth->relics[ran()%VLC->arth->relics.size()]->id);
case 70: //random hero
{
return std::pair<int,int>(34,pickHero(obj->tempOwner));
return std::pair<int,int>(HEROI_TYPE,pickHero(obj->tempOwner));
}
case 71: //random monster
{
@ -991,7 +991,7 @@ std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj)
f = scenarioOps->getIthPlayersSettings(align).castle;
}
if(f<0) f = ran()%VLC->townh->towns.size();
return std::pair<int,int>(98,f);
return std::pair<int,int>(TOWNI_TYPE,f);
}
case 162: //random monster lvl5
return std::pair<int,int>(54,VLC->creh->levelCreatures[5][ran()%VLC->creh->levelCreatures[5].size()]->idNumber);
@ -1013,7 +1013,7 @@ std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj)
faction = map->objects[i]->subID;
break;
}
else if(map->objects[i]->ID==98 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
faction = map->objects[i]->subID;
break;
@ -1051,7 +1051,7 @@ std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj)
faction = map->objects[i]->subID;
break;
}
else if(map->objects[i]->ID==98 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
faction = map->objects[i]->subID;
break;
@ -1093,7 +1093,7 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
std::pair<int,int> ran = pickObject(cur);
if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything
{
if(cur->ID==98) //town - set def
if(cur->ID==TOWNI_TYPE) //town - set def
{
CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
if(t->hasCapitol())
@ -1105,7 +1105,7 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
}
return;
}
else if(ran.first==34)//special code for hero
else if(ran.first==HEROI_TYPE)//special code for hero
{
CGHeroInstance *h = dynamic_cast<CGHeroInstance *>(cur);
if(!h) {tlog2<<"Wrong random hero at "<<cur->pos<<std::endl; return;}
@ -1115,7 +1115,7 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
map->heroes.push_back(h);
return; //TODO: maybe we should do something with definfo?
}
else if(ran.first==98)//special code for town
else if(ran.first==TOWNI_TYPE)//special code for town
{
CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
if(!t) {tlog2<<"Wrong random town at "<<cur->pos<<std::endl; return;}
@ -1233,7 +1233,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed)
if(j == scenarioOps->playerInfos.size())
continue;
int h=pickHero(i);
CGHeroInstance * nnn = static_cast<CGHeroInstance*>(createObject(34,h,hpos,i));
CGHeroInstance * nnn = static_cast<CGHeroInstance*>(createObject(HEROI_TYPE,h,hpos,i));
nnn->id = map->objects.size();
hpos = map->players[i].posOfMainTown;hpos.x+=2;
for(int o=0;o<map->towns.size();o++) //find main town
@ -1544,10 +1544,10 @@ UpgradeInfo CGameState::getUpgradeInfo(CArmedInstance *obj, int stackPos)
{
UpgradeInfo ret;
CCreature *base = &VLC->creh->creatures[obj->army.slots[stackPos].first];
if((obj->ID == 98) || ((obj->ID == 34) && static_cast<const CGHeroInstance*>(obj)->visitedTown))
if((obj->ID == TOWNI_TYPE) || ((obj->ID == HEROI_TYPE) && static_cast<const CGHeroInstance*>(obj)->visitedTown))
{
CGTownInstance * t;
if(obj->ID == 98)
if(obj->ID == TOWNI_TYPE)
t = static_cast<CGTownInstance *>(const_cast<CArmedInstance *>(obj));
else
t = static_cast<const CGHeroInstance*>(obj)->visitedTown;

View File

@ -13,7 +13,6 @@
#include "client/CSpellWindow.h"
#include "client/CConfigHandler.h"
#include "global.h"
#include "hch/CAbilityHandler.h"
#include "hch/CArtHandler.h"
#include "hch/CDefHandler.h"
#include "hch/CGeneralTextHandler.h"
@ -648,49 +647,49 @@ void CHeroWindow::redrawCurBack()
//secondary skills
if(curHero->secSkills.size()>=1)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[0].first*3+3+curHero->secSkills[0].second-1].bitmap, 18, 276, curBack);
blitAt(graphics->abils44->ourImages[curHero->secSkills[0].first*3+3+curHero->secSkills[0].second-1].bitmap, 18, 276, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[0].second-1], 69, 279, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[0].first], 69, 299, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=2)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[1].first*3+3+curHero->secSkills[1].second-1].bitmap, 161, 276, curBack);
blitAt(graphics->abils44->ourImages[curHero->secSkills[1].first*3+3+curHero->secSkills[1].second-1].bitmap, 161, 276, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[1].second-1], 213, 279, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[1].first], 213, 299, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=3)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[2].first*3+3+curHero->secSkills[2].second-1].bitmap, 18, 324, curBack);
blitAt(graphics->abils44->ourImages[curHero->secSkills[2].first*3+3+curHero->secSkills[2].second-1].bitmap, 18, 324, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[2].second-1], 69, 327, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[2].first], 69, 347, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=4)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[3].first*3+3+curHero->secSkills[3].second-1].bitmap, 161, 324, curBack);
blitAt(graphics->abils44->ourImages[curHero->secSkills[3].first*3+3+curHero->secSkills[3].second-1].bitmap, 161, 324, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[3].second-1], 213, 327, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[3].first], 213, 347, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=5)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[4].first*3+3+curHero->secSkills[4].second-1].bitmap, 18, 372, curBack);
blitAt(graphics->abils44->ourImages[curHero->secSkills[4].first*3+3+curHero->secSkills[4].second-1].bitmap, 18, 372, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[4].second-1], 69, 375, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[4].first], 69, 395, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=6)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[5].first*3+3+curHero->secSkills[5].second-1].bitmap, 161, 372, curBack);
blitAt(graphics->abils44->ourImages[curHero->secSkills[5].first*3+3+curHero->secSkills[5].second-1].bitmap, 161, 372, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[5].second-1], 213, 375, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[5].first], 213, 395, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=7)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[6].first*3+3+curHero->secSkills[6].second-1].bitmap, 18, 420, curBack);
blitAt(graphics->abils44->ourImages[curHero->secSkills[6].first*3+3+curHero->secSkills[6].second-1].bitmap, 18, 420, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[6].second-1], 69, 423, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[6].first], 69, 443, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=8)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[7].first*3+3+curHero->secSkills[7].second-1].bitmap, 161, 420, curBack);
blitAt(graphics->abils44->ourImages[curHero->secSkills[7].first*3+3+curHero->secSkills[7].second-1].bitmap, 161, 420, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[7].second-1], 213, 423, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[7].first], 213, 443, GEOR13, zwykly, curBack);
}

View File

@ -17,7 +17,6 @@
#include "client/CConfigHandler.h"
#include "client/CCreatureAnimation.h"
#include "client/Graphics.h"
#include "hch/CAbilityHandler.h"
#include "hch/CArtHandler.h"
#include "hch/CGeneralTextHandler.h"
#include "hch/CHeroHandler.h"
@ -717,10 +716,10 @@ SDL_Surface * SComponent::getImg()
return graphics->pskillsb->ourImages[subtype].bitmap;
break;
case secskill44:
return CGI->abilh->abils44->ourImages[subtype*3 + 3 + val - 1].bitmap;
return graphics->abils44->ourImages[subtype*3 + 3 + val - 1].bitmap;
break;
case secskill:
return CGI->abilh->abils82->ourImages[subtype*3 + 3 + val - 1].bitmap;
return graphics->abils82->ourImages[subtype*3 + 3 + val - 1].bitmap;
break;
case resource:
return graphics->resources->ourImages[subtype].bitmap;
@ -1708,10 +1707,10 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe
{
switch (specific->ID)
{
case 34:
case HEROI_TYPE:
return graphics->drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
break;
case 98:
case TOWNI_TYPE:
return graphics->drawTownInfoWin(dynamic_cast<const CGTownInstance*>(specific));
break;
default:
@ -1973,7 +1972,7 @@ void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownIn
void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
{
boost::unique_lock<boost::recursive_mutex> un(*pim);
if(obj->ID == 34) //hero
if(obj->ID == HEROI_TYPE) //hero
{
const CGHeroInstance * hh;
if(hh = dynamic_cast<const CGHeroInstance*>(obj))
@ -1994,7 +1993,7 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
}
}
else if (obj->ID == 98) //town
else if (obj->ID == TOWNI_TYPE) //town
{
const CGTownInstance * tt;
if(tt = static_cast<const CGTownInstance*>(obj))

View File

@ -220,6 +220,9 @@ Graphics::Graphics()
tasks += GET_DEF(smi,"CPRSMALL.DEF");
tasks += GET_DEF(smi2,"TWCRPORT.DEF");
tasks += GET_DEF(flags,"CREST58.DEF");
tasks += GET_DEF(abils32,"SECSK32.DEF");
tasks += GET_DEF(abils44,"SECSKILL.DEF");
tasks += GET_DEF(abils82,"SECSK82.DEF");
std::ifstream ifs("config/cr_bgs.txt");
int id;

View File

@ -48,6 +48,8 @@ public:
std::map< int, std::vector < std::string > > battleACToDef; //maps AC format to vector of appropriate def names
CDefHandler * spellEffectsPics; //bitmaps representing spells affecting a stack in battle
std::vector<std::string> guildBgs;// name of bitmaps with imgs for mage guild screen
//abilities
CDefHandler * abils32, * abils44, * abils82;
//functions
Graphics();
void initializeBattleGraphics();

View File

@ -7,8 +7,4 @@
void CAbilityHandler::loadAbilities()
{
abils32 = CDefHandler::giveDef("SECSK32.DEF");
abils44 = CDefHandler::giveDef("SECSKILL.DEF");
abils82 = CDefHandler::giveDef("SECSK82.DEF");
}

View File

@ -17,7 +17,7 @@ class CAbilityHandler
{
public:
std::vector<CAbility *> abilities;
CDefHandler * abils32, * abils44, * abils82;
void loadAbilities();
};

View File

@ -157,8 +157,42 @@ void CHeroHandler::loadHeroes()
expPerLevel.push_back(22100);
expPerLevel.push_back(26420);
expPerLevel.push_back(31604);
return;
//ballistics info
buf = bitmaph->getTextFile("BALLIST.TXT");
it = 0;
for(int i=0; i<22; ++i)
{
loadToIt(dump,buf,it,4);
}
for(int lvl=0; lvl<4; ++lvl)
{
CHeroHandler::SBallisticsLevelInfo bli;
si32 tempNum;
loadToIt(tempNum,buf,it,4);
bli.keep = tempNum;
loadToIt(tempNum,buf,it,4);
bli.tower = tempNum;
loadToIt(tempNum,buf,it,4);
bli.gate = tempNum;
loadToIt(tempNum,buf,it,4);
bli.wall = tempNum;
loadToIt(tempNum,buf,it,4);
bli.shots = tempNum;
loadToIt(tempNum,buf,it,4);
bli.noDmg = tempNum;
loadToIt(tempNum,buf,it,4);
bli.oneDmg = tempNum;
loadToIt(tempNum,buf,it,4);
bli.twoDmg = tempNum;
loadToIt(tempNum,buf,it,4);
bli.sum = tempNum;
if(lvl!=3)
{
loadToIt(dump,buf,it,4);
}
ballistics.push_back(bli);
}
}
void CHeroHandler::loadHeroClasses()
{

View File

@ -56,6 +56,19 @@ public:
std::vector<CHero*> heroes; //by³o nodrze
std::vector<CHeroClass *> heroClasses;
std::vector<int> expPerLevel; //expPerLEvel[i] is amount of exp needed to reach level i; if it is not in this vector, multiplicate last value by 1,2 to get next value
struct SBallisticsLevelInfo
{
ui8 keep, tower, gate, wall; //chance to hit in percent (eg. 87 is 87%)
ui8 shots; //how many shots we have
ui8 noDmg, oneDmg, twoDmg; //chances for shot dealing certain dmg in percent (eg. 87 is 87%); must sum to 100
ui8 sum; //I don't know if it is useful for anything, but it's in config file
template <typename Handler> void serialize(Handler &h, const int version)
{
h & keep & tower & gate & wall & shots & noDmg & oneDmg & twoDmg & sum;
}
};
std::vector<SBallisticsLevelInfo> ballistics; //info about ballistics ability per level; [0] - none; [1] - basic; [2] - adv; [3] - expert
unsigned int level(unsigned int experience);
unsigned int reqExp(unsigned int level);
@ -69,7 +82,7 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & heroClasses & heroes & expPerLevel;
h & heroClasses & heroes & expPerLevel & ballistics;
if(!h.saving)
{
//restore class pointers

View File

@ -162,9 +162,9 @@ bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const //screen p
return true;
if(this->pos.y>cmp.pos.y)
return false;
if(cmp.ID==34 && ID!=34)
if(cmp.ID==HEROI_TYPE && ID!=HEROI_TYPE)
return true;
if(cmp.ID!=34 && ID==34)
if(cmp.ID!=HEROI_TYPE && ID==HEROI_TYPE)
return false;
if(!defInfo->isVisitable() && cmp.defInfo->isVisitable())
return true;

View File

@ -10,7 +10,6 @@ class CLodHandler;
class CArtHandler;
class CHeroHandler;
class CCreatureHandler;
//class CAbilityHandler;
class CSpellHandler;
//class CPreGameTextHandler;
class CBuildingHandler;

4
map.h
View File

@ -528,9 +528,9 @@ struct DLL_EXPORT Mapa : public CMapHeader
for(int i=0; i<objects.size(); i++)
{
if(!objects[i]) continue;
if(objects[i]->ID == 34)
if(objects[i]->ID == HEROI_TYPE)
heroes.push_back(static_cast<CGHeroInstance*>(objects[i]));
else if(objects[i]->ID == 98)
else if(objects[i]->ID == TOWNI_TYPE)
towns.push_back(static_cast<CGTownInstance*>(objects[i]));
addBlockVisTiles(objects[i]); //recreate blockvis map

View File

@ -2057,7 +2057,7 @@ void CGameHandler::moveHero(int hid, int3 pos, bool instant)
//check if destination tile is free
BOOST_FOREACH(CGObjectInstance* obj, gs->map->terrain[pos.x-1][pos.y][pos.z].blockingObjects)
{
if(obj->ID==34)
if(obj->ID==HEROI_TYPE)
{
if(obj->tempOwner==h->tempOwner)
return;//TODO: exchange