From 3c4923a31e6da909cb90d4cd154a4376fee0e746 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sat, 15 Sep 2007 18:04:12 +0000 Subject: [PATCH] hero animation --- CGameInterface.cpp | 11 ++- hch/CAmbarCendamo.cpp | 4 + hch/CHeroHandler.cpp | 182 ++++++++++++++++-------------------------- hch/CHeroHandler.h | 3 +- hch/CObjectHandler.h | 3 + mapHandler.cpp | 136 ++++++++++++++++++++++++++++--- 6 files changed, 214 insertions(+), 125 deletions(-) diff --git a/CGameInterface.cpp b/CGameInterface.cpp index 02f2b4571..35bb5a372 100644 --- a/CGameInterface.cpp +++ b/CGameInterface.cpp @@ -207,6 +207,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) int3 hp = CGI->heroh->heroInstances[details.heroID]->pos; if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl { + ho->moveDir = 1; CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31))); CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31))); CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31))); @@ -239,6 +240,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t { + ho->moveDir = 2; CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31))); CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31))); CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31))); @@ -265,6 +267,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr { + ho->moveDir = 3; CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31))); CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31))); CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31))); @@ -297,6 +300,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r { + ho->moveDir = 4; subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id); subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id); subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id); @@ -319,6 +323,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br { + ho->moveDir = 5; subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id); subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id); subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id); @@ -351,6 +356,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b { + ho->moveDir = 6; subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id); subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id); subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id); @@ -377,6 +383,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl { + ho->moveDir = 7; CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1))); subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id); subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id); @@ -409,6 +416,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l { + ho->moveDir = 8; CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0))); subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id); subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id); @@ -432,7 +440,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) //first initializing done SDL_framerateDelay(mainFPSmng); // after first move //main moving - for(int i=1; i<32; ++i) + for(int i=1; i<32; i+=4) { if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl { @@ -722,6 +730,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) delObjRect(hp.x, hp.y, hp.z, ho->id); } CGI->heroh->heroInstances[details.heroID]->pos = details.dst; //actualizing hero position + ho->moveDir = 0; //move ended //move finished } void CPlayerInterface::heroKilled(const CHeroInstance * hero) diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index b2fc887fd..11329d38d 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -532,6 +532,8 @@ void CAmbarCendamo::deh3m() nobj->pos.z = bufor[i++]; nobj->defNumber = readNormalNr(i, 4); i+=4; nobj->defObjInfoNumber = -1; + nobj->isHero = false; + nobj->moveDir = 0; //if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size()) // std::cout << "Alarm!!! Obiekt "<info = spec; //////creating CHeroInstance CHeroInstance * nhi = new CHeroInstance; + spec->myInstance = nhi; + nobj->isHero = true; nhi->exp = spec->experience; nhi->level = CGI->heroh->level(nhi->exp); nhi->primSkills.resize(PRIMARY_SKILLS); diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index cfee3c56e..a3c97615e 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -6,7 +6,9 @@ #include "CGeneralTextHandler.h" #include "CLodHandler.h" #include "CAbilityHandler.h" +#include "SDL_Extensions.h" #include +#include CHeroHandler::~CHeroHandler() { @@ -310,6 +312,59 @@ void CHeroHandler::loadHeroClasses() ++i; } ++i; + std::stringstream nm; + nm<<"AH"; + nm<moveAnim = CGI->spriteh->giveDef(nm.str()); + + for(int o=0; omoveAnim->ourImages.size(); ++o) + { + if(hc->moveAnim->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + hc->moveAnim->ourImages.push_back(nci); + } + o+=8; + } + if(hc->moveAnim->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); + nci.groupNumber = 11; + nci.imName = std::string(); + hc->moveAnim->ourImages.push_back(nci); + } + o+=8; + } + if(hc->moveAnim->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); + nci.groupNumber = 12; + nci.imName = std::string(); + hc->moveAnim->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int ff=0; ffmoveAnim->ourImages.size(); ++ff) + { + CSDL_Ext::fullAlphaTransform(hc->moveAnim->ourImages[ff].bitmap); + } + hc->moveAnim->alphaTransformed = true; heroClasses.push_back(hc); } } @@ -386,122 +441,21 @@ unsigned int CHeroInstance::getLowestCreatureSpeed() void CHeroHandler::initTerrainCosts() { - for(int i=0; i>tynum; + for(int i=0; i<2*tynum; i+=2) { - switch (i) + int catNum; + inp>>catNum; + for(int k=0; kterrCosts.push_back(100); //dirt - heroClasses[i]->terrCosts.push_back(150); //sand - heroClasses[i]->terrCosts.push_back(100); //grass - heroClasses[i]->terrCosts.push_back(150); //snow - heroClasses[i]->terrCosts.push_back(175); //swamp - heroClasses[i]->terrCosts.push_back(125); //rough - heroClasses[i]->terrCosts.push_back(100); //subterrain - heroClasses[i]->terrCosts.push_back(100); //lava - heroClasses[i]->terrCosts.push_back(-1); //water - heroClasses[i]->terrCosts.push_back(-1); //rock - break; - } - case EHeroClasses::HERO_RANGER: case EHeroClasses::HERO_DRUID: - { - heroClasses[i]->terrCosts.push_back(100); //dirt - heroClasses[i]->terrCosts.push_back(150); //sand - heroClasses[i]->terrCosts.push_back(100); //grass - heroClasses[i]->terrCosts.push_back(150); //snow - heroClasses[i]->terrCosts.push_back(175); //swamp - heroClasses[i]->terrCosts.push_back(125); //rough - heroClasses[i]->terrCosts.push_back(100); //subterrain - heroClasses[i]->terrCosts.push_back(100); //lava - heroClasses[i]->terrCosts.push_back(-1); //water - heroClasses[i]->terrCosts.push_back(-1); //rock - break; - } - case EHeroClasses::HERO_ALCHEMIST: case EHeroClasses::HERO_WIZARD: - { - heroClasses[i]->terrCosts.push_back(100); //dirt - heroClasses[i]->terrCosts.push_back(150); //sand - heroClasses[i]->terrCosts.push_back(100); //grass - heroClasses[i]->terrCosts.push_back(100); //snow - heroClasses[i]->terrCosts.push_back(175); //swamp - heroClasses[i]->terrCosts.push_back(125); //rough - heroClasses[i]->terrCosts.push_back(100); //subterrain - heroClasses[i]->terrCosts.push_back(100); //lava - heroClasses[i]->terrCosts.push_back(-1); //water - heroClasses[i]->terrCosts.push_back(-1); //rock - break; - } - case EHeroClasses::HERO_DEMONIAC: case EHeroClasses::HERO_HERETIC: - { - heroClasses[i]->terrCosts.push_back(100); //dirt - heroClasses[i]->terrCosts.push_back(150); //sand - heroClasses[i]->terrCosts.push_back(100); //grass - heroClasses[i]->terrCosts.push_back(150); //snow - heroClasses[i]->terrCosts.push_back(175); //swamp - heroClasses[i]->terrCosts.push_back(125); //rough - heroClasses[i]->terrCosts.push_back(100); //subterrain - heroClasses[i]->terrCosts.push_back(100); //lava - heroClasses[i]->terrCosts.push_back(-1); //water - heroClasses[i]->terrCosts.push_back(-1); //rock - break; - } - case EHeroClasses::HERO_DEATHKNIGHT: case EHeroClasses::HERO_NECROMANCER: - { - heroClasses[i]->terrCosts.push_back(100); //dirt - heroClasses[i]->terrCosts.push_back(150); //sand - heroClasses[i]->terrCosts.push_back(100); //grass - heroClasses[i]->terrCosts.push_back(150); //snow - heroClasses[i]->terrCosts.push_back(175); //swamp - heroClasses[i]->terrCosts.push_back(125); //rough - heroClasses[i]->terrCosts.push_back(100); //subterrain - heroClasses[i]->terrCosts.push_back(100); //lava - heroClasses[i]->terrCosts.push_back(-1); //water - heroClasses[i]->terrCosts.push_back(-1); //rock - break; - } - case EHeroClasses::HERO_WARLOCK: case EHeroClasses::HERO_OVERLORD: - { - heroClasses[i]->terrCosts.push_back(100); //dirt - heroClasses[i]->terrCosts.push_back(150); //sand - heroClasses[i]->terrCosts.push_back(100); //grass - heroClasses[i]->terrCosts.push_back(150); //snow - heroClasses[i]->terrCosts.push_back(175); //swamp - heroClasses[i]->terrCosts.push_back(125); //rough - heroClasses[i]->terrCosts.push_back(100); //subterrain - heroClasses[i]->terrCosts.push_back(100); //lava - heroClasses[i]->terrCosts.push_back(-1); //water - heroClasses[i]->terrCosts.push_back(-1); //rock - break; - } - case EHeroClasses::HERO_BARBARIAN: case EHeroClasses::HERO_BATTLEMAGE: - { - heroClasses[i]->terrCosts.push_back(100); //dirt - heroClasses[i]->terrCosts.push_back(150); //sand - heroClasses[i]->terrCosts.push_back(100); //grass - heroClasses[i]->terrCosts.push_back(150); //snow - heroClasses[i]->terrCosts.push_back(175); //swamp - heroClasses[i]->terrCosts.push_back(100); //rough - heroClasses[i]->terrCosts.push_back(100); //subterrain - heroClasses[i]->terrCosts.push_back(100); //lava - heroClasses[i]->terrCosts.push_back(-1); //water - heroClasses[i]->terrCosts.push_back(-1); //rock - break; - } - case EHeroClasses::HERO_BEASTMASTER: case EHeroClasses::HERO_WITCH: - { - heroClasses[i]->terrCosts.push_back(100); //dirt - heroClasses[i]->terrCosts.push_back(150); //sand - heroClasses[i]->terrCosts.push_back(100); //grass - heroClasses[i]->terrCosts.push_back(150); //snow - heroClasses[i]->terrCosts.push_back(100); //swamp - heroClasses[i]->terrCosts.push_back(125); //rough - heroClasses[i]->terrCosts.push_back(100); //subterrain - heroClasses[i]->terrCosts.push_back(100); //lava - heroClasses[i]->terrCosts.push_back(-1); //water - heroClasses[i]->terrCosts.push_back(-1); //rock - break; - } + int curCost; + inp>>curCost; + heroClasses[i]->terrCosts.push_back(curCost); + heroClasses[i+1]->terrCosts.push_back(curCost); } } + inp.close(); } diff --git a/hch/CHeroHandler.h b/hch/CHeroHandler.h index 67f1cc43d..3f1a6bb20 100644 --- a/hch/CHeroHandler.h +++ b/hch/CHeroHandler.h @@ -9,7 +9,7 @@ class CHeroClass; class CObjectInstance; - +class CDefHandler; class CHero { @@ -40,6 +40,7 @@ public: std::vector proSec; //probabilities of gaining secondary skills (out of 112), in id order int selectionProbability[9]; //probability of selection in towns std::vector terrCosts; //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterrain, lava, water, rock; -1 means terrain is imapassable + CDefHandler * moveAnim; //added group 10: up - left, 11 - left and 12 - left down }; class CHeroInstance diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index c2775380c..f17b88dfb 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -60,6 +60,7 @@ public: std::vector abilities; //hero's abilities std::vector abilityLevels; //hero ability levels bool defaultMainStats; //if true attack, defence, power and knowledge are typical + CHeroInstance * myInstance; //pointer to appropriate hero instance }; class CCreatureObjInfo : public CSpecObjInfo @@ -295,6 +296,8 @@ public: int id; //number of object in CObjectHandler's vector int3 pos; // position CSpecObjInfo * info; //pointer to something with additional information + bool isHero; //true if this is a hero + unsigned char moveDir; //direction of hero movement (0 - default; 1 - lt; 2 - t; 3 - tr; 4 - r; 5 - br; 6 - b; 7 - bl; 8 - l) bool operator<(const CObjectInstance & cmp) const; //screen printing priority comparing }; diff --git a/mapHandler.cpp b/mapHandler.cpp index 536981b7b..c278996a4 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -496,13 +496,131 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, sr.y = (by)*32; SDL_Rect pp = ttiles[x+bx][y+by][level].objects[h].second; - int imgVal = CGI->ac->map.defy[ - ttiles[x+bx][y+by][level].objects[h].first->defNumber] - .handler->ourImages.size(); - SDL_Surface * tb = CGI->ac->map.defy[ttiles[x+bx][y+by][level].objects[h].first->defNumber].handler->ourImages[anim%imgVal].bitmap; - SDL_BlitSurface( - CGI->ac->map.defy[ttiles[x+bx][y+by][level].objects[h].first->defNumber].handler->ourImages[anim%imgVal].bitmap, - &pp,su,&sr); + if(ttiles[x+bx][y+by][level].objects[h].first->isHero && ttiles[x+bx][y+by][level].objects[h].first->moveDir) + { + int imgVal = 8; + SDL_Surface * tb; + switch(ttiles[x+bx][y+by][level].objects[h].first->moveDir) + { + case 1: + { + std::vector & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages; + for(int gg=0; gg & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages; + for(int gg=0; gg & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages; + for(int gg=0; gg & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages; + for(int gg=0; gg & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages; + for(int gg=0; gg & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages; + for(int gg=0; gg & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages; + for(int gg=0; gg & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages; + for(int gg=0; ggac->map.defy[ttiles[x+bx][y+by][level].objects[h].first->defNumber].handler->ourImages.size(); + SDL_BlitSurface(CGI->ac->map.defy[ttiles[x+bx][y+by][level].objects[h].first->defNumber].handler->ourImages[anim%imgVal].bitmap,&pp,su,&sr); + } } } } @@ -823,8 +941,8 @@ int CMapHandler::getCost(int3 &a, int3 &b, CHeroInstance *hero) { int ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].malle]; if(!(a.x==b.x || a.y==b.y)) - ret*=1.4142; + ret*=1.41421; //TODO: use hero's pathfinding skill during calculating cost return ret; -} \ No newline at end of file +}