From a08aaba29d0c8a641f11a650eee153a9c65fe6a1 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Thu, 12 Mar 2009 18:06:02 +0000 Subject: [PATCH] * probably fixed problem with displaying corpses on battlefield * fixed buy troops window * workaround for a problem with GeniusAI * some magic numbers are removed --- AI/GeniusAI/CGeniusAI.cpp | 7 ++++++- CAdvmapInterface.cpp | 28 ++++++++++++++-------------- client/CCreatureAnimation.cpp | 13 ++++++++----- hch/CDefObjInfoHandler.cpp | 2 +- hch/CDefObjInfoHandler.h | 2 +- hch/CObjectHandler.cpp | 12 ++++++------ map.cpp | 10 +++++----- mapHandler.cpp | 6 +++--- 8 files changed, 44 insertions(+), 36 deletions(-) diff --git a/AI/GeniusAI/CGeniusAI.cpp b/AI/GeniusAI/CGeniusAI.cpp index 1e85100fb..2495084a0 100644 --- a/AI/GeniusAI/CGeniusAI.cpp +++ b/AI/GeniusAI/CGeniusAI.cpp @@ -618,7 +618,6 @@ BattleAction CBattleLogic::MakeDecision(int stackID) } } BattleAction ba = MakeAttack(stackID, *creatures.begin()); - PrintBattleAction(ba); return ba; } @@ -845,6 +844,12 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) } std::vector fields = m_cb->battleGetAvailableHexes(attackerID, false); + + if(fields.size() == 0) + { + return MakeDefend(attackerID); + } + BattleAction ba; ba.side = 1; //ba.actionType = 6; // go and attack diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 914bfe9d8..c1f8c7563 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -351,7 +351,7 @@ void CTerrainRect::clickLeft(tribool down) objs = LOCPLINT->cb->getBlockingObjs(mp); 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])) { @@ -363,7 +363,7 @@ void CTerrainRect::clickLeft(tribool down) 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(objs[i])); return; @@ -376,18 +376,18 @@ void CTerrainRect::clickLeft(tribool down) objs = LOCPLINT->cb->getVisitableObjs(mp); for(size_t i=0; i < objs.size(); ++i) { - if(objs[i]->ID == 98) + if(objs[i]->ID == TOWNI_TYPE) goto endchkpt; } objs = LOCPLINT->cb->getBlockingObjs(mp); 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(objs[i])); 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(objs[i])); return; @@ -452,7 +452,7 @@ void CTerrainRect::clickRight(tribool down) const CGObjectInstance * obj = objs[objs.size()-1]; switch(obj->ID) { - case 34: + case HEROI_TYPE: { if(!vstd::contains(graphics->heroWins,obj->subID)) { @@ -466,7 +466,7 @@ void CTerrainRect::clickRight(tribool down) ip->activate(); break; } - case 98: + case TOWNI_TYPE: { if(!vstd::contains(graphics->townWins,obj->id)) { @@ -507,7 +507,7 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent) std::vector objs = LOCPLINT->cb->getVisitableObjs(pom); for(int i=0; iID == 98) //town + if(objs[i]->ID == TOWNI_TYPE) //town { CGI->curh->changeGraphic(0,0); return; @@ -516,13 +516,13 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent) objs = LOCPLINT->cb->getBlockingObjs(pom); 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); return; } - else if(objs[i]->ID == 34 //mouse over hero - && (objs[i]==LOCPLINT->adventureInt->selection || LOCPLINT->adventureInt->selection->ID==98) + else if(objs[i]->ID == HEROI_TYPE //mouse over hero + && (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 { CGI->curh->changeGraphic(0,2); @@ -1008,12 +1008,12 @@ void CInfoBar::draw(const CGObjectInstance * specific) if(!specific) return; - if(specific->ID == 34) //hero + if(specific->ID == HEROI_TYPE) //hero { if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end()) 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(specific); if(graphics->townWins.find(t->id)!=graphics->townWins.end()) @@ -1530,7 +1530,7 @@ void CAdvMapInt::select(const CArmedInstance *sel ) LOCPLINT->cb->setSelection(sel); centerOn(sel->pos); selection = sel; - if(sel->ID==98) + if(sel->ID==TOWNI_TYPE) { int pos = vstd::findPos(townList.items,sel); townList.selected = pos; diff --git a/client/CCreatureAnimation.cpp b/client/CCreatureAnimation.cpp index 0b60a7b4e..0cb4aa3af 100644 --- a/client/CCreatureAnimation.cpp +++ b/client/CCreatureAnimation.cpp @@ -108,25 +108,28 @@ int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool at } void CCreatureAnimation::incrementFrame() { - curFrame = frameGroups[type][(internalFrame++)%frameGroups[type].size()]; - if(type!=-1) + if(type!=-1) //when a specific part of animation is played { + internalFrame = (internalFrame + 1) % frameGroups[type].size(); + curFrame = frameGroups[type][internalFrame]; + if(internalFrame == frameGroups[type].size()) //rewind { - if(once) + if(once) //playing animation once - return to standing animation { type = 2; once = false; curFrame = frameGroups[2][0]; } - else + else // { curFrame = frameGroups[type][0]; } } } - else + else //when whole animation is played { + ++curFrame; if(curFrame>=frames) curFrame = 0; } diff --git a/hch/CDefObjInfoHandler.cpp b/hch/CDefObjInfoHandler.cpp index e0466c7f8..740547528 100644 --- a/hch/CDefObjInfoHandler.cpp +++ b/hch/CDefObjInfoHandler.cpp @@ -89,7 +89,7 @@ void CDefObjInfoHandler::load() } inp >> nobj->printPriority; gobjs[nobj->id][nobj->subid] = nobj; - if(nobj->id==98) + if(nobj->id==TOWNI_TYPE) castles[nobj->subid]=nobj; } } diff --git a/hch/CDefObjInfoHandler.h b/hch/CDefObjInfoHandler.h index 07ab2f5f8..f1f2489a6 100644 --- a/hch/CDefObjInfoHandler.h +++ b/hch/CDefObjInfoHandler.h @@ -52,7 +52,7 @@ public: if(!h.saving) //recrete castles map for(std::map >::iterator i=gobjs.begin(); i!=gobjs.end(); i++) for(std::map::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; } }; diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index db66bce21..060ae054b 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -457,7 +457,7 @@ int CGHeroInstance::getSpellSecLevel(int spell) const CGHeroInstance::CGHeroInstance() { - ID = 34; + ID = HEROI_TYPE; tacticFormationEnabled = inTownGarrison = false; mana = movement = portrait = level = -1; isStanding = true; @@ -476,7 +476,7 @@ void CGHeroInstance::initHero(int SUBID) void CGHeroInstance::initHero() { - if(ID == 34) + if(ID == HEROI_TYPE) initHeroDefInfo(); if(!type) type = VLC->heroh->heroes[subID]; @@ -547,10 +547,10 @@ void CGHeroInstance::initHero() void CGHeroInstance::initHeroDefInfo() { - if(!defInfo || defInfo->id != 34) + if(!defInfo || defInfo->id != HEROI_TYPE) { defInfo = new CGDefInfo(); - defInfo->id = 34; + defInfo->id = HEROI_TYPE; defInfo->subid = subID; defInfo->printPriority = 0; defInfo->visitDir = 0xff; @@ -574,7 +574,7 @@ bool CGHeroInstance::needsLastStack() const } void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const { - if (ID == 34) //hero + if (ID == HEROI_TYPE) //hero { //TODO: check for allies 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 { 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 InfoWindow iw; diff --git a/map.cpp b/map.cpp index 342d87ecb..f4b9e80f6 100644 --- a/map.cpp +++ b/map.cpp @@ -1129,7 +1129,7 @@ void Mapa::readPredefinedHeroes( unsigned char * bufor, int &i) if(!custom) continue; CGHeroInstance * cgh = new CGHeroInstance; - cgh->ID = 34; + cgh->ID = HEROI_TYPE; cgh->subID = z; if(readChar(bufor,i))//true if hore's experience is greater than 0 { 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]); } 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]; if(!h) @@ -1819,13 +1819,13 @@ void Mapa::readObjects( unsigned char * bufor, int &i) nobj->pos = pos; nobj->ID = defInfo->id; nobj->id = objects.size(); - if(nobj->ID != 34) + if(nobj->ID != HEROI_TYPE) nobj->subID = defInfo->subid; nobj->defInfo = defInfo; objects.push_back(nobj); - if(nobj->ID==98) + if(nobj->ID==TOWNI_TYPE) towns.push_back(static_cast(nobj)); - if(nobj->ID==34) + if(nobj->ID==HEROI_TYPE) heroes.push_back(static_cast(nobj)); } } diff --git a/mapHandler.cpp b/mapHandler.cpp index d77d6ec48..bc20d2b38 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -358,7 +358,7 @@ void CMapHandler::initObjectRects() for(size_t f=0; f < map->objects.size(); ++f) { if(!map->objects[f]) continue; - if((map->objects[f]->ID==34 && static_cast(map->objects[f])->inTownGarrison) + if((map->objects[f]->ID==HEROI_TYPE && static_cast(map->objects[f])->inTownGarrison) || !map->objects[f]->defInfo) { continue; @@ -425,13 +425,13 @@ void processDef (CGDefInfo* def) def->height = def->handler->ourImages[0].bitmap->h/32; } 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->width = pom->handler->ourImages[0].bitmap->w/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; if(!def->handler->alphaTransformed) {