1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-27 22:47:48 +02:00

* probably fixed problem with displaying corpses on battlefield

* fixed buy troops window
* workaround for a problem with GeniusAI
* some magic numbers are removed
This commit is contained in:
mateuszb 2009-03-12 18:06:02 +00:00
parent d6283fd1ca
commit a08aaba29d
8 changed files with 44 additions and 36 deletions

View File

@ -618,7 +618,6 @@ BattleAction CBattleLogic::MakeDecision(int stackID)
} }
} }
BattleAction ba = MakeAttack(stackID, *creatures.begin()); BattleAction ba = MakeAttack(stackID, *creatures.begin());
PrintBattleAction(ba);
return ba; return ba;
} }
@ -845,6 +844,12 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID)
} }
std::vector<int> fields = m_cb->battleGetAvailableHexes(attackerID, false); std::vector<int> fields = m_cb->battleGetAvailableHexes(attackerID, false);
if(fields.size() == 0)
{
return MakeDefend(attackerID);
}
BattleAction ba; BattleAction ba;
ba.side = 1; ba.side = 1;
//ba.actionType = 6; // go and attack //ba.actionType = 6; // go and attack

View File

@ -351,7 +351,7 @@ void CTerrainRect::clickLeft(tribool down)
objs = LOCPLINT->cb->getBlockingObjs(mp); objs = LOCPLINT->cb->getBlockingObjs(mp);
for(size_t i=0; i < objs.size(); ++i) for(size_t i=0; i < objs.size(); ++i)
{ {
if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town if(objs[i]->ID == TOWNI_TYPE && objs[i]->tempOwner == LOCPLINT->playerID) //town
{ {
if(LOCPLINT->adventureInt->selection == (objs[i])) if(LOCPLINT->adventureInt->selection == (objs[i]))
{ {
@ -363,7 +363,7 @@ void CTerrainRect::clickLeft(tribool down)
return; return;
} }
} }
else if(objs[i]->ID == 34 && objs[i]->tempOwner == LOCPLINT->playerID) else if(objs[i]->ID == HEROI_TYPE && objs[i]->tempOwner == LOCPLINT->playerID)
{ {
LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(objs[i])); LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(objs[i]));
return; return;
@ -376,18 +376,18 @@ void CTerrainRect::clickLeft(tribool down)
objs = LOCPLINT->cb->getVisitableObjs(mp); objs = LOCPLINT->cb->getVisitableObjs(mp);
for(size_t i=0; i < objs.size(); ++i) for(size_t i=0; i < objs.size(); ++i)
{ {
if(objs[i]->ID == 98) if(objs[i]->ID == TOWNI_TYPE)
goto endchkpt; goto endchkpt;
} }
objs = LOCPLINT->cb->getBlockingObjs(mp); objs = LOCPLINT->cb->getBlockingObjs(mp);
for(size_t i=0; i < objs.size(); ++i) for(size_t i=0; i < objs.size(); ++i)
{ {
if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town if(objs[i]->ID == TOWNI_TYPE && objs[i]->tempOwner == LOCPLINT->playerID) //town
{ {
LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(objs[i])); LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(objs[i]));
return; return;
} }
else if(objs[i]->ID == 34 && objs[i]->tempOwner == LOCPLINT->playerID && LOCPLINT->adventureInt->selection == (objs[i])) else if(objs[i]->ID == HEROI_TYPE && objs[i]->tempOwner == LOCPLINT->playerID && LOCPLINT->adventureInt->selection == (objs[i]))
{ {
LOCPLINT->openHeroWindow(static_cast<const CGHeroInstance*>(objs[i])); LOCPLINT->openHeroWindow(static_cast<const CGHeroInstance*>(objs[i]));
return; return;
@ -452,7 +452,7 @@ void CTerrainRect::clickRight(tribool down)
const CGObjectInstance * obj = objs[objs.size()-1]; const CGObjectInstance * obj = objs[objs.size()-1];
switch(obj->ID) switch(obj->ID)
{ {
case 34: case HEROI_TYPE:
{ {
if(!vstd::contains(graphics->heroWins,obj->subID)) if(!vstd::contains(graphics->heroWins,obj->subID))
{ {
@ -466,7 +466,7 @@ void CTerrainRect::clickRight(tribool down)
ip->activate(); ip->activate();
break; break;
} }
case 98: case TOWNI_TYPE:
{ {
if(!vstd::contains(graphics->townWins,obj->id)) if(!vstd::contains(graphics->townWins,obj->id))
{ {
@ -507,7 +507,7 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
std::vector<const CGObjectInstance *> objs = LOCPLINT->cb->getVisitableObjs(pom); std::vector<const CGObjectInstance *> objs = LOCPLINT->cb->getVisitableObjs(pom);
for(int i=0; i<objs.size();i++) for(int i=0; i<objs.size();i++)
{ {
if(objs[i]->ID == 98) //town if(objs[i]->ID == TOWNI_TYPE) //town
{ {
CGI->curh->changeGraphic(0,0); CGI->curh->changeGraphic(0,0);
return; return;
@ -516,13 +516,13 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
objs = LOCPLINT->cb->getBlockingObjs(pom); objs = LOCPLINT->cb->getBlockingObjs(pom);
for(size_t i=0; i < objs.size(); ++i) for(size_t i=0; i < objs.size(); ++i)
{ {
if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town if(objs[i]->ID == TOWNI_TYPE && objs[i]->tempOwner == LOCPLINT->playerID) //town
{ {
CGI->curh->changeGraphic(0,3); CGI->curh->changeGraphic(0,3);
return; return;
} }
else if(objs[i]->ID == 34 //mouse over hero else if(objs[i]->ID == HEROI_TYPE //mouse over hero
&& (objs[i]==LOCPLINT->adventureInt->selection || LOCPLINT->adventureInt->selection->ID==98) && (objs[i]==LOCPLINT->adventureInt->selection || LOCPLINT->adventureInt->selection->ID==TOWNI_TYPE)
&& objs[i]->tempOwner == LOCPLINT->playerID) //this hero is selected or we've selected a town && objs[i]->tempOwner == LOCPLINT->playerID) //this hero is selected or we've selected a town
{ {
CGI->curh->changeGraphic(0,2); CGI->curh->changeGraphic(0,2);
@ -1008,12 +1008,12 @@ void CInfoBar::draw(const CGObjectInstance * specific)
if(!specific) if(!specific)
return; return;
if(specific->ID == 34) //hero if(specific->ID == HEROI_TYPE) //hero
{ {
if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end()) if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
blitAt(graphics->heroWins[specific->subID],pos.x,pos.y); blitAt(graphics->heroWins[specific->subID],pos.x,pos.y);
} }
else if (specific->ID == 98) else if (specific->ID == TOWNI_TYPE)
{ {
const CGTownInstance * t = static_cast<const CGTownInstance*>(specific); const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
if(graphics->townWins.find(t->id)!=graphics->townWins.end()) if(graphics->townWins.find(t->id)!=graphics->townWins.end())
@ -1530,7 +1530,7 @@ void CAdvMapInt::select(const CArmedInstance *sel )
LOCPLINT->cb->setSelection(sel); LOCPLINT->cb->setSelection(sel);
centerOn(sel->pos); centerOn(sel->pos);
selection = sel; selection = sel;
if(sel->ID==98) if(sel->ID==TOWNI_TYPE)
{ {
int pos = vstd::findPos(townList.items,sel); int pos = vstd::findPos(townList.items,sel);
townList.selected = pos; townList.selected = pos;

View File

@ -108,25 +108,28 @@ int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool at
} }
void CCreatureAnimation::incrementFrame() void CCreatureAnimation::incrementFrame()
{ {
curFrame = frameGroups[type][(internalFrame++)%frameGroups[type].size()]; if(type!=-1) //when a specific part of animation is played
if(type!=-1)
{ {
internalFrame = (internalFrame + 1) % frameGroups[type].size();
curFrame = frameGroups[type][internalFrame];
if(internalFrame == frameGroups[type].size()) //rewind if(internalFrame == frameGroups[type].size()) //rewind
{ {
if(once) if(once) //playing animation once - return to standing animation
{ {
type = 2; type = 2;
once = false; once = false;
curFrame = frameGroups[2][0]; curFrame = frameGroups[2][0];
} }
else else //
{ {
curFrame = frameGroups[type][0]; curFrame = frameGroups[type][0];
} }
} }
} }
else else //when whole animation is played
{ {
++curFrame;
if(curFrame>=frames) if(curFrame>=frames)
curFrame = 0; curFrame = 0;
} }

View File

@ -89,7 +89,7 @@ void CDefObjInfoHandler::load()
} }
inp >> nobj->printPriority; inp >> nobj->printPriority;
gobjs[nobj->id][nobj->subid] = nobj; gobjs[nobj->id][nobj->subid] = nobj;
if(nobj->id==98) if(nobj->id==TOWNI_TYPE)
castles[nobj->subid]=nobj; castles[nobj->subid]=nobj;
} }
} }

View File

@ -52,7 +52,7 @@ public:
if(!h.saving) //recrete castles map if(!h.saving) //recrete castles map
for(std::map<int,std::map<int,CGDefInfo*> >::iterator i=gobjs.begin(); i!=gobjs.end(); i++) for(std::map<int,std::map<int,CGDefInfo*> >::iterator i=gobjs.begin(); i!=gobjs.end(); i++)
for(std::map<int,CGDefInfo*>::iterator j=i->second.begin(); j!=i->second.end(); j++) for(std::map<int,CGDefInfo*>::iterator j=i->second.begin(); j!=i->second.end(); j++)
if(j->second->id == 98) if(j->second->id == TOWNI_TYPE)
castles[j->second->subid]=j->second; castles[j->second->subid]=j->second;
} }
}; };

View File

@ -457,7 +457,7 @@ int CGHeroInstance::getSpellSecLevel(int spell) const
CGHeroInstance::CGHeroInstance() CGHeroInstance::CGHeroInstance()
{ {
ID = 34; ID = HEROI_TYPE;
tacticFormationEnabled = inTownGarrison = false; tacticFormationEnabled = inTownGarrison = false;
mana = movement = portrait = level = -1; mana = movement = portrait = level = -1;
isStanding = true; isStanding = true;
@ -476,7 +476,7 @@ void CGHeroInstance::initHero(int SUBID)
void CGHeroInstance::initHero() void CGHeroInstance::initHero()
{ {
if(ID == 34) if(ID == HEROI_TYPE)
initHeroDefInfo(); initHeroDefInfo();
if(!type) if(!type)
type = VLC->heroh->heroes[subID]; type = VLC->heroh->heroes[subID];
@ -547,10 +547,10 @@ void CGHeroInstance::initHero()
void CGHeroInstance::initHeroDefInfo() void CGHeroInstance::initHeroDefInfo()
{ {
if(!defInfo || defInfo->id != 34) if(!defInfo || defInfo->id != HEROI_TYPE)
{ {
defInfo = new CGDefInfo(); defInfo = new CGDefInfo();
defInfo->id = 34; defInfo->id = HEROI_TYPE;
defInfo->subid = subID; defInfo->subid = subID;
defInfo->printPriority = 0; defInfo->printPriority = 0;
defInfo->visitDir = 0xff; defInfo->visitDir = 0xff;
@ -574,7 +574,7 @@ bool CGHeroInstance::needsLastStack() const
} }
void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
{ {
if (ID == 34) //hero if (ID == HEROI_TYPE) //hero
{ {
//TODO: check for allies //TODO: check for allies
if(tempOwner == h->tempOwner) //our hero if(tempOwner == h->tempOwner) //our hero
@ -597,7 +597,7 @@ void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
if(cb->getHeroCount(h->tempOwner,false) < 8) //free hero slot if(cb->getHeroCount(h->tempOwner,false) < 8) //free hero slot
{ {
cb->changeObjPos(id,pos+int3(1,0,0),0); cb->changeObjPos(id,pos+int3(1,0,0),0);
cb->setObjProperty(id,6,34); //set ID to 34 cb->setObjProperty(id,6,HEROI_TYPE); //set ID to 34
cb->giveHero(id,h->tempOwner); //recreates def and adds hero to player cb->giveHero(id,h->tempOwner); //recreates def and adds hero to player
InfoWindow iw; InfoWindow iw;

10
map.cpp
View File

@ -1129,7 +1129,7 @@ void Mapa::readPredefinedHeroes( unsigned char * bufor, int &i)
if(!custom) if(!custom)
continue; continue;
CGHeroInstance * cgh = new CGHeroInstance; CGHeroInstance * cgh = new CGHeroInstance;
cgh->ID = 34; cgh->ID = HEROI_TYPE;
cgh->subID = z; cgh->subID = z;
if(readChar(bufor,i))//true if hore's experience is greater than 0 if(readChar(bufor,i))//true if hore's experience is greater than 0
{ cgh->exp = readNormalNr(bufor,i); i+=4; } { cgh->exp = readNormalNr(bufor,i); i+=4; }
@ -1307,7 +1307,7 @@ void Mapa::readDefInfo( unsigned char * bufor, int &i)
vinya->visitMap[zi] = reverse(bytes[6+zi]); vinya->visitMap[zi] = reverse(bytes[6+zi]);
} }
i+=16; i+=16;
if(vinya->id!=34 && vinya->id!=70) if(vinya->id!=HEROI_TYPE && vinya->id!=70)
{ {
CGDefInfo *h = VLC->dobjinfo->gobjs[vinya->id][vinya->subid]; CGDefInfo *h = VLC->dobjinfo->gobjs[vinya->id][vinya->subid];
if(!h) if(!h)
@ -1819,13 +1819,13 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
nobj->pos = pos; nobj->pos = pos;
nobj->ID = defInfo->id; nobj->ID = defInfo->id;
nobj->id = objects.size(); nobj->id = objects.size();
if(nobj->ID != 34) if(nobj->ID != HEROI_TYPE)
nobj->subID = defInfo->subid; nobj->subID = defInfo->subid;
nobj->defInfo = defInfo; nobj->defInfo = defInfo;
objects.push_back(nobj); objects.push_back(nobj);
if(nobj->ID==98) if(nobj->ID==TOWNI_TYPE)
towns.push_back(static_cast<CGTownInstance*>(nobj)); towns.push_back(static_cast<CGTownInstance*>(nobj));
if(nobj->ID==34) if(nobj->ID==HEROI_TYPE)
heroes.push_back(static_cast<CGHeroInstance*>(nobj)); heroes.push_back(static_cast<CGHeroInstance*>(nobj));
} }
} }

View File

@ -358,7 +358,7 @@ void CMapHandler::initObjectRects()
for(size_t f=0; f < map->objects.size(); ++f) for(size_t f=0; f < map->objects.size(); ++f)
{ {
if(!map->objects[f]) continue; if(!map->objects[f]) continue;
if((map->objects[f]->ID==34 && static_cast<CGHeroInstance*>(map->objects[f])->inTownGarrison) if((map->objects[f]->ID==HEROI_TYPE && static_cast<CGHeroInstance*>(map->objects[f])->inTownGarrison)
|| !map->objects[f]->defInfo) || !map->objects[f]->defInfo)
{ {
continue; continue;
@ -425,13 +425,13 @@ void processDef (CGDefInfo* def)
def->height = def->handler->ourImages[0].bitmap->h/32; def->height = def->handler->ourImages[0].bitmap->h/32;
} }
CGDefInfo* pom = CGI->dobjinfo->gobjs[def->id][def->subid]; CGDefInfo* pom = CGI->dobjinfo->gobjs[def->id][def->subid];
if(pom && def->id!=98) if(pom && def->id!=TOWNI_TYPE)
{ {
pom->handler = def->handler; pom->handler = def->handler;
pom->width = pom->handler->ourImages[0].bitmap->w/32; pom->width = pom->handler->ourImages[0].bitmap->w/32;
pom->height = pom->handler->ourImages[0].bitmap->h/32; pom->height = pom->handler->ourImages[0].bitmap->h/32;
} }
else if(def->id != 34 && def->id != 98) else if(def->id != HEROI_TYPE && def->id != TOWNI_TYPE)
tlog3 << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl; tlog3 << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl;
if(!def->handler->alphaTransformed) if(!def->handler->alphaTransformed)
{ {