From 4bd39202c2e71c2fb9813f1f55b68ce1c8d55d77 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Fri, 11 Jul 2008 09:43:13 +0000 Subject: [PATCH] * first part shooting in battles (units cannot shoot yet) * minor improvements --- CBattleInterface.cpp | 27 ++++++++++++++++++++++++++- CBattleInterface.h | 14 ++++++++++++++ CCallback.cpp | 9 +++++++++ CCallback.h | 2 ++ CGameState.cpp | 6 +++++- CHeroWindow.cpp | 1 - config/cr_shots.txt | 40 ++++++++++++++++++++++++++++++++++++++++ hch/CCreatureHandler.cpp | 27 +++++++++++++++++++++++++++ hch/CCreatureHandler.h | 3 +++ 9 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 config/cr_shots.txt diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 061505b30..6a9df43ae 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -116,7 +116,15 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C { bfield[it->second.position].accesible = false; } - + + //loading projectiles for units + for(std::map::iterator g = stacks.begin(); g != stacks.end(); ++g) + { + if(g->second.creature->isShooting() && CGI->creh->idToProjectile[g->second.creature->idNumber] != std::string()) + { + idToProjectile[g->second.creature->idNumber] = CGI->spriteh->giveDef(CGI->creh->idToProjectile[g->second.creature->idNumber]); + } + } } CBattleInterface::~CBattleInterface() @@ -144,6 +152,9 @@ CBattleInterface::~CBattleInterface() for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g) delete g->second; + + for(std::map< int, CDefHandler * >::iterator g=idToProjectile.begin(); g!=idToProjectile.end(); ++g) + delete g->second; } void CBattleInterface::activate() @@ -306,6 +317,7 @@ void CBattleInterface::show(SDL_Surface * to) } } //units shown + projectileShowHelper(to);//showing projectiles } bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick) @@ -731,6 +743,15 @@ void CBattleInterface::hexLclicked(int whichOne) ba->stackNumber = activeStack; givenCommand = ba; } + else if(LOCPLINT->cb->battleGetStackByID(atCre).owner != attackingHeroInstance->tempOwner + && LOCPLINT->cb->battleCanShoot(activeStack, whichOne)) //shooting + { + BattleAction * ba = new BattleAction(); //to be deleted by engine + ba->actionType = 7; + ba->destinationTile = whichOne; + ba->stackNumber = activeStack; + givenCommand = ba; + } else if(LOCPLINT->cb->battleGetStackByID(atCre).owner != attackingHeroInstance->tempOwner) //attacking { BattleAction * ba = new BattleAction(); //to be deleted by engine @@ -889,6 +910,10 @@ void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDb console->addText(std::string(tabh)); } +void CBattleInterface::projectileShowHelper(SDL_Surface * to) +{ +} + void CBattleHero::show(SDL_Surface *to) { //animation of flag diff --git a/CBattleInterface.h b/CBattleInterface.h index 534b83e6a..559e9a396 100644 --- a/CBattleInterface.h +++ b/CBattleInterface.h @@ -1,6 +1,7 @@ #pragma once #include "global.h" #include "CPlayerInterface.h" +#include class CCreatureSet; class CGHeroInstance; @@ -79,6 +80,7 @@ private: CCreatureSet * army1, * army2; //fighting armies CGHeroInstance * attackingHeroInstance, * defendingHeroInstance; std::map< int, CCreatureAnimation * > creAnims; //animations of creatures from fighting armies (order by BattleInfo's stacks' ID) + std::map< int, CDefHandler * > idToProjectile; //projectiles of creaures (creatureID, defhandler) std::map< int, bool > creDir; // unsigned char animCount; int activeStack; //number of active stack; -1 - no one @@ -95,6 +97,18 @@ private: void attackingShowHelper(); void printConsoleAttacked(int ID, int dmg, int killed, int IDby); + struct SProjectileInfo + { + int x, y; //position on the screen + int dx, dy; //change in position in one step + int step, lastStep; //to know when finish showing this projectile + int creID; //ID of creature that shot this projectile + int frameNum; //frame to display form projectile animation + bool spin; //if true, frameNum will be increased + }; + std::list projectiles; + void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield + public: CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor ~CBattleInterface(); //d-tor diff --git a/CCallback.cpp b/CCallback.cpp index 3df700c98..95af88f86 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -838,6 +838,15 @@ bool CCallback::battleIsStackMine(int ID) return false; } +bool CCallback::battleCanShoot(int ID, int dest) //TODO: finish +{ + if(battleGetStackByID(ID).creature->isShooting() + && battleGetStack(dest) != -1 + && battleGetStackByPos(dest).owner != battleGetStackByID(ID).owner) + return true; + return false; +} + int3 CScriptCallback::getPos(CGObjectInstance * ob) { return ob->pos; diff --git a/CCallback.h b/CCallback.h index fee79a0d9..8cbb1ac82 100644 --- a/CCallback.h +++ b/CCallback.h @@ -68,6 +68,7 @@ public: //virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible virtual std::vector battleGetAvailableHexes(int ID)=0; //reutrns numbers of hexes reachable by creature with id ID virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller + virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest }; struct HeroMoveDetails @@ -140,6 +141,7 @@ public: //bool battleMoveCreature(int ID, int dest); //moves creature with id ID to dest if possible std::vector battleGetAvailableHexes(int ID); //reutrns numbers of hexes reachable by creature with id ID bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller + bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest //friends diff --git a/CGameState.cpp b/CGameState.cpp index 9488b39f4..1be21a060 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -237,6 +237,10 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C battleAttackCreatureStack(ba.stackNumber, ba.destinationTile); break; } + case 7: //shoot + { + break; + } } } else @@ -345,7 +349,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) if(curStack->attackerOwned ? (v%17)==1 : (v%17)==15) accessibility[v] = false; } - if(!accessibility[dest]) + if(!stackAtEnd && !accessibility[dest]) return false; int predecessor[187]; //for getting the Path for(int b=0; b<187; ++b) diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index a5793ae8a..783be48e6 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -43,7 +43,6 @@ CHeroWindow::CHeroWindow(int playerColor): gar3button = new AdventureMapButton(CGI->generaltexth->heroscrn[24], CGI->generaltexth->heroscrn[30], boost::bind(&CHeroWindow::gar3,this), 546, 527, "hsbtns7.def", false, NULL, false); gar4button = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[32], boost::function(), 604, 527, "hsbtns9.def", false, NULL, false); - //boost::bind(&CGarrisonInt::splitClick,garInt) leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::leftArtRoller,this), 379, 364, "hsbtns3.def", false, NULL, false); rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::rightArtRoller,this), 632, 364, "hsbtns5.def", false, NULL, false); diff --git a/config/cr_shots.txt b/config/cr_shots.txt new file mode 100644 index 000000000..7c0b4b5e1 --- /dev/null +++ b/config/cr_shots.txt @@ -0,0 +1,40 @@ +//here are defs with things shot by different units - don't delete this line; format: unit_ID def_name spin_projectile +2 PLCBOWX.DEF 0 +3 PLCBOWX.DEF 0 +8 SMBALX.DEF 1 +9 SMBALX.DEF 1 +18 PELFX.DEF 0 +19 PELFX.DEF 0 +29 CPGRE.DEF 1 +34 PMAGX.DEF 1 +35 PMAGX.DEF 1 +41 SMBALX.DEF 0 +44 CPRGOGX.DEF 1 +45 CPRGOGX.DEF 1 +64 PLICH.DEF 0 +65 PLICH.DEF 0 +74 SMBALX.DEF 0 +75 SMBALX.DEF 0 +76 PMEDUSX.DEF 0 +77 PMEDUSX.DEF 0 +88 PORCHX.DEF 1 +89 PORCHX.DEF 1 +94 PCYCLBX.DEF 1 +95 PCYCLBX.DEF 1 +100 PPLIZAX.DEF 0 +101 PPLIZAX.DEF 0 +123 PICEE.DEF 0 +127 SMBALX.DEF 0 +136 SMBALX.DEF 0 +137 PLCBOWX.DEF 0 +138 PHALF.DEF 1 +145 SMBALX.DEF 0 +146 SMBALX.DEF 0 +152 SMBALX.DEF 0 +169 SMBALX.DEF 0 +170 PLCBOWX.DEF 0 +171 PLCBOWX.DEF 0 +173 CPGRE.DEF 1 +193 SMBALX.DEF 0 +196 SMBALX.DEF 0 +-1 \ No newline at end of file diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index 30ee3afab..f94f4a4e6 100644 --- a/hch/CCreatureHandler.cpp +++ b/hch/CCreatureHandler.cpp @@ -42,6 +42,12 @@ bool CCreature::isFlying() { return boost::algorithm::find_first(abilityRefs, "FLYING_ARMY"); } + +bool CCreature::isShooting() +{ + return boost::algorithm::find_first(abilityRefs, "SHOOTING_ARMY"); +} + int CCreature::maxAmount(const std::vector &res) const //how many creatures can be bought { int ret = 2147483645; @@ -437,6 +443,27 @@ void CCreatureHandler::loadCreatures() creatures[s].animDefName = defName; } loadAnimationInfo(); + + //loading id to projectile mapping + + std::ifstream inp2("config/cr_shots.TXT", std::ios::in | std::ios::binary); //this file is not in lod + char dump [200]; + inp2.getline(dump, 200); + while(true) + { + int id; + std::string name; + bool spin; + + inp2>>id; + if(id == -1) + break; + inp2>>name; + idToProjectile[id] = name; + inp2>>spin; + idToProjectileSpin[id] = spin; + } + inp2.close(); } void CCreatureHandler::loadAnimationInfo() diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index ea1c0e137..def4ab2b2 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -44,6 +44,7 @@ public: static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion bool isDoubleWide(); //returns true if unit is double wide on battlefield bool isFlying(); //returns true if it is a flying unit + bool isShooting(); //returns true if unit can shoot int maxAmount(const std::vector &res) const; //how many creatures can be bought }; @@ -65,6 +66,8 @@ public: std::vector creatures; //creature ID -> creature info std::map > levelCreatures; //level -> list of creatures std::map nameToID; + std::map idToProjectile; + std::map idToProjectileSpin; //if true, appropriate projectile is spinning during flight void loadCreatures(); void loadAnimationInfo(); void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);