1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Common changes (ours):

* Improvements for console
* Speed bonus support
* Minor improvements
This commit is contained in:
mateuszb
2009-04-04 19:26:41 +00:00
parent 1983aee1b2
commit 47bc007d8c
12 changed files with 269 additions and 209 deletions

View File

@@ -39,7 +39,7 @@ struct CMP_stack2
{
inline bool operator ()(const CStack& a, const CStack& b)
{
return (a.speed())>(b.speed());
return (a.Speed())>(b.Speed());
}
} cmpst2 ;
@@ -1759,6 +1759,7 @@ void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse)
{
displayEffect(spellToEffect[sse.effect.id], LOCPLINT->cb->battleGetStackByID(*ci)->position);
}
redrawBackgroundWithHexes(activeStack);
}
void CBattleInterface::castThisSpell(int spellID)
@@ -2433,7 +2434,7 @@ void CBattleHex::clickRight(boost::logic::tribool down)
pom->defenseBonus = h->getPrimSkillLevel(1);
pom->luck = myst.Luck();
pom->morale = myst.Morale();
pom->speedBonus = myst.speed() - myst.creature->speed;
pom->speedBonus = myst.Speed() - myst.creature->speed;
}
pom->shotsLeft = myst.shots;

View File

@@ -705,4 +705,11 @@ CPath * CCallback::getPath( int3 src, int3 dest, const CGHeroInstance * hero )
void CCallback::save( const std::string &fname )
{
cl->save(fname);
}
void CCallback::sendMessage(const std::string &mess)
{
PlayerMessage pm(player, mess);
*cl->serv << &pm;
}

View File

@@ -48,6 +48,7 @@ public:
virtual void setSelection(const CArmedInstance * obj)=0;
virtual void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero)=0;
virtual void save(const std::string &fname) = 0;
virtual void sendMessage(const std::string &mess) = 0;
//get info
virtual bool verifyPath(CPath * path, bool blockSea)const =0;
@@ -138,6 +139,7 @@ public:
void setSelection(const CArmedInstance * obj);
void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero);
void save(const std::string &fname);
void sendMessage(const std::string &mess);
//get info
bool verifyPath(CPath * path, bool blockSea) const;

View File

@@ -327,7 +327,7 @@ std::vector<int> BattleInfo::getAccessibility(int stackID, bool addOccupiable)
std::vector<int> rem;
for(int b=0; b<BFIELD_SIZE; ++b)
{
if( ac[b] && (!ac[b-1] || dist[b-1] > s->speed() ) && ( !ac[b+1] || dist[b+1] > s->speed() ) && b%BFIELD_WIDTH != 0 && b%BFIELD_WIDTH != (BFIELD_WIDTH-1))
if( ac[b] && (!ac[b-1] || dist[b-1] > s->Speed() ) && ( !ac[b+1] || dist[b+1] > s->Speed() ) && b%BFIELD_WIDTH != 0 && b%BFIELD_WIDTH != (BFIELD_WIDTH-1))
{
rem.push_back(b);
}
@@ -341,7 +341,7 @@ std::vector<int> BattleInfo::getAccessibility(int stackID, bool addOccupiable)
}
for(int i=0;i<BFIELD_SIZE;i++)
if(dist[i] <= s->speed() && ac[i])
if(dist[i] <= s->Speed() && ac[i])
{
ret.push_back(i);
}
@@ -438,11 +438,12 @@ CStack::CStack(CCreature * C, int A, int O, int I, bool AO, int S)
:creature(C),amount(A), baseAmount(A), owner(O), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints),
shots(C->shots), slot(S), counterAttacks(1), effects(), state()
{
speed = creature->speed;
abilities = C->abilities;
state.insert(ALIVE);
}
ui32 CStack::speed() const
ui32 CStack::Speed() const
{
int premy=0;
const StackEffect *effect = 0;
@@ -465,7 +466,7 @@ ui32 CStack::speed() const
premy = creature->speed; //don't use '- creature->speed' - speed is unsigned!
premy = -premy;
}
return creature->speed + premy;
return speed + premy;
}
const CStack::StackEffect * CStack::getEffect(ui16 id) const
@@ -1896,10 +1897,10 @@ std::vector<CStack> BattleInfo::getStackQueue()
&& taken[i]==0
&& !vstd::contains(stacks[i]->abilities,NOT_ACTIVE)) //eg. Ammo Cart
{
if(speed == -1 || stacks[i]->speed() > speed)
if(speed == -1 || stacks[i]->Speed() > speed)
{
id = i;
speed = stacks[i]->speed();
speed = stacks[i]->Speed();
}
}
}
@@ -1920,10 +1921,10 @@ std::vector<CStack> BattleInfo::getStackQueue()
&& taken[i]==0
&& !vstd::contains(stacks[i]->abilities,NOT_ACTIVE)) //eg. Ammo Cart
{
if(stacks[i]->speed() < speed) //slowest one
if(stacks[i]->Speed() < speed) //slowest one
{
id = i;
speed = stacks[i]->speed();
speed = stacks[i]->Speed();
}
}
}

View File

@@ -141,6 +141,7 @@ public:
ui16 position; //position on battlefield
ui8 counterAttacks; //how many counter attacks can be performed more in this turn (by default set at the beginning of the round to 1)
si16 shots; //how many shots left
ui8 speed;
si8 morale, luck; //base stack luck/morale
std::set<EAbilities> abilities;
@@ -161,7 +162,7 @@ public:
CStack() : creature(NULL),amount(-1),owner(255), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1), slot(255), baseAmount(-1), counterAttacks(1), effects(), state(), abilities(){}
const StackEffect * getEffect(ui16 id) const; //effect id (SP)
bool willMove(); //if stack has remaining move this turn
ui32 speed() const;
ui32 Speed() const;
si8 Morale() const;
si8 Luck() const;
template <typename Handler> void save(Handler &h, const int version)
@@ -178,7 +179,7 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & ID & amount & baseAmount & firstHPleft & owner & slot & attackerOwned & position & state & counterAttacks
& shots & morale & luck;
& shots & morale & luck & speed;
if(h.saving)
save(h,version);
else

View File

@@ -1,135 +1,135 @@
#ifndef __CHEROWINDOW_H__
#define __CHEROWINDOW_H__
#include "CPlayerInterface.h"
class AdventureMapButton;
struct SDL_Surface;
class CGHeroInstance;
class CDefHandler;
class CArtifact;
class CHeroWindow;
class LClickableArea: public ClickableL
{
public:
virtual void clickLeft (tribool down);
virtual void activate();
virtual void deactivate();
};
class RClickableArea: public ClickableR
{
public:
virtual void clickRight (tribool down);
virtual void activate();
virtual void deactivate();
};
class LClickableAreaHero : public LClickableArea
{
public:
int id;
CHeroWindow * owner;
virtual void clickLeft (tribool down);
};
class LRClickableAreaWText: public LClickableArea, public RClickableArea, public Hoverable
{
public:
std::string text, hoverText;
virtual void activate();
virtual void deactivate();
virtual void clickLeft (tribool down);
virtual void clickRight (tribool down);
virtual void hover(bool on);
};
class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea, public Hoverable
{
public:
std::string text, hoverText;
int baseType;
int bonus, type;
virtual void activate();
virtual void deactivate();
virtual void clickLeft (tribool down);
virtual void clickRight (tribool down);
virtual void hover(bool on);
};
class CArtPlace: public IShowable, public LRClickableAreaWTextComp
{
private:
bool active;
public:
//bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4,
// misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso,
// lHand, rHand, neck, shoulders, head; //my types
ui16 slotID; //0 head 1 shoulders 2 neck 3 right hand 4 left hand 5 torso 6 right ring 7 left ring 8 feet 9 misc. slot 1 10 misc. slot 2 11 misc. slot 3 12 misc. slot 4 13 ballista (war machine 1) 14 ammo cart (war machine 2) 15 first aid tent (war machine 3) 16 catapult 17 spell book 18 misc. slot 5 19+ backpack slots
bool clicked;
CHeroWindow * ourWindow;
const CArtifact * ourArt;
CArtPlace(const CArtifact * Art);
void clickLeft (tribool down);
void clickRight (tribool down);
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
bool fitsHere(const CArtifact * art); //returns true if given artifact can be placed here
~CArtPlace();
};
class CHeroWindow: public IShowActivable, public virtual CIntObject
{
SDL_Surface * background, * curBack;
const CGHeroInstance * curHero;
CGarrisonInt * garInt;
CStatusBar * ourBar; //heroWindow's statusBar
//general graphics
CDefHandler *flags;
//buttons
AdventureMapButton * gar4button; //splitting
std::vector<LClickableAreaHero *> heroListMi; //new better list of heroes
std::vector<CArtPlace *> artWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
int backpackPos; //unmber of first art visible in backpack (in hero's vector)
CArtPlace * activeArtPlace;
//clickable areas
LRClickableAreaWText * portraitArea;
std::vector<LRClickableAreaWTextComp *> primSkillAreas;
LRClickableAreaWText * expArea;
LRClickableAreaWText * spellPointsArea;
LRClickableAreaWTextComp * luck;
LRClickableAreaWTextComp * morale;
std::vector<LRClickableAreaWTextComp *> secSkillAreas;
public:
AdventureMapButton * quitButton, * dismissButton, * questlogButton, //general
* leftArtRoll, * rightArtRoll;
CHighlightableButton *gar2button; //garrison / formation handling;
CHighlightableButtonsGroup *formations;
int player;
CHeroWindow(int playerColor); //c-tor
~CHeroWindow(); //d-tor
void setHero(const CGHeroInstance * Hero); //sets main displayed hero
void activate(); //activates hero window;
void deactivate(); //activates hero window;
virtual void show(SDL_Surface * to = NULL); //shows hero window
void redrawCurBack(); //redraws curBAck from scratch
void quit(); //stops displaying hero window
void dismissCurrent(); //dissmissed currently displayed hero (curHero)
#ifndef __CHEROWINDOW_H__
#define __CHEROWINDOW_H__
#include "CPlayerInterface.h"
class AdventureMapButton;
struct SDL_Surface;
class CGHeroInstance;
class CDefHandler;
class CArtifact;
class CHeroWindow;
class LClickableArea: public ClickableL
{
public:
virtual void clickLeft (tribool down);
virtual void activate();
virtual void deactivate();
};
class RClickableArea: public ClickableR
{
public:
virtual void clickRight (tribool down);
virtual void activate();
virtual void deactivate();
};
class LClickableAreaHero : public LClickableArea
{
public:
int id;
CHeroWindow * owner;
virtual void clickLeft (tribool down);
};
class LRClickableAreaWText: public LClickableArea, public RClickableArea, public Hoverable
{
public:
std::string text, hoverText;
virtual void activate();
virtual void deactivate();
virtual void clickLeft (tribool down);
virtual void clickRight (tribool down);
virtual void hover(bool on);
};
class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea, public Hoverable
{
public:
std::string text, hoverText;
int baseType;
int bonus, type;
virtual void activate();
virtual void deactivate();
virtual void clickLeft (tribool down);
virtual void clickRight (tribool down);
virtual void hover(bool on);
};
class CArtPlace: public IShowable, public LRClickableAreaWTextComp
{
private:
bool active;
public:
//bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4,
// misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso,
// lHand, rHand, neck, shoulders, head; //my types
ui16 slotID; //0 head 1 shoulders 2 neck 3 right hand 4 left hand 5 torso 6 right ring 7 left ring 8 feet 9 misc. slot 1 10 misc. slot 2 11 misc. slot 3 12 misc. slot 4 13 ballista (war machine 1) 14 ammo cart (war machine 2) 15 first aid tent (war machine 3) 16 catapult 17 spell book 18 misc. slot 5 19+ backpack slots
bool clicked;
CHeroWindow * ourWindow;
const CArtifact * ourArt;
CArtPlace(const CArtifact * Art);
void clickLeft (tribool down);
void clickRight (tribool down);
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
bool fitsHere(const CArtifact * art); //returns true if given artifact can be placed here
~CArtPlace();
};
class CHeroWindow: public IShowActivable, public virtual CIntObject
{
SDL_Surface * background, * curBack;
const CGHeroInstance * curHero;
CGarrisonInt * garInt;
CStatusBar * ourBar; //heroWindow's statusBar
//general graphics
CDefHandler *flags;
//buttons
AdventureMapButton * gar4button; //splitting
std::vector<LClickableAreaHero *> heroListMi; //new better list of heroes
std::vector<CArtPlace *> artWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
int backpackPos; //unmber of first art visible in backpack (in hero's vector)
CArtPlace * activeArtPlace;
//clickable areas
LRClickableAreaWText * portraitArea;
std::vector<LRClickableAreaWTextComp *> primSkillAreas;
LRClickableAreaWText * expArea;
LRClickableAreaWText * spellPointsArea;
LRClickableAreaWTextComp * luck;
LRClickableAreaWTextComp * morale;
std::vector<LRClickableAreaWTextComp *> secSkillAreas;
public:
AdventureMapButton * quitButton, * dismissButton, * questlogButton, //general
* leftArtRoll, * rightArtRoll;
CHighlightableButton *gar2button; //garrison / formation handling;
CHighlightableButtonsGroup *formations;
int player;
CHeroWindow(int playerColor); //c-tor
~CHeroWindow(); //d-tor
void setHero(const CGHeroInstance * Hero); //sets main displayed hero
void activate(); //activates hero window;
void deactivate(); //activates hero window;
virtual void show(SDL_Surface * to = NULL); //shows hero window
void redrawCurBack(); //redraws curBAck from scratch
void quit(); //stops displaying hero window
void dismissCurrent(); //dissmissed currently displayed hero (curHero)
void questlog(); //show quest log in hero window
void scrollBackpack(int dir); //dir==-1 => to left; dir==-2 => to right
void switchHero(); //changes displayed hero
//friends
friend void CArtPlace::clickLeft(tribool down);
friend class CPlayerInterface;
};
#endif // __CHEROWINDOW_H__
void scrollBackpack(int dir); //dir==-1 => to left; dir==-2 => to right
void switchHero(); //changes displayed hero
//friends
friend void CArtPlace::clickLeft(tribool down);
friend class CPlayerInterface;
};
#endif // __CHEROWINDOW_H__

View File

@@ -142,6 +142,7 @@ int main(int argc, char** argv)
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(conf.cc.resx,conf.cc.resy,conf.cc.bpp,SDL_SWSURFACE|SDL_DOUBLEBUF|(conf.cc.fullscreen?SDL_FULLSCREEN:0)); //initializing important global surface
SDL_EnableUNICODE(1);
SDL_WM_SetCaption(NAME.c_str(),""); //set window title
SDL_ShowCursor(SDL_DISABLE);
}
@@ -245,6 +246,9 @@ void processCommand(const std::string &message, CClient *&client)
// int heronum;//TODO use me
int3 dest;
if(LOCPLINT && LOCPLINT->cingconsole)
LOCPLINT->cingconsole->print(message);
if(message==std::string("die, fool"))
exit(EXIT_SUCCESS);
else if(cn==std::string("activate"))
@@ -327,6 +331,7 @@ void processCommand(const std::string &message, CClient *&client)
}
else if(client && client->serv && client->serv->connected) //send to server
{
*client->serv << &PlayerMessage(LOCPLINT->playerID,message);
PlayerMessage pm(LOCPLINT->playerID,message);
*client->serv << &pm;
}
}

View File

@@ -52,6 +52,7 @@ extern TTF_Font * GEOR16;
CPlayerInterface * LOCPLINT;
extern std::queue<SDL_Event*> events;
extern boost::mutex eventsM;
void processCommand(const std::string &message, CClient *&client);
struct OCM_HLP_CGIN
@@ -160,12 +161,14 @@ StackState* getStackState(const CGObjectInstance *obj, int pos, bool town)
{
const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(obj);
if(!h) return NULL;
StackState *pom = new StackState();
pom->currentHealth = 0;
pom->attackBonus = h->getPrimSkillLevel(0);
pom->defenseBonus = h->getPrimSkillLevel(1);
pom->luck = h->getCurrentLuck();
pom->morale = h->getCurrentMorale(pos,town);
pom->speedBonus = h->valOfBonuses(HeroBonus::STACKS_SPEED);
return pom;
}
@@ -4292,6 +4295,7 @@ CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &pos, CPlayerInterface
quitGame = new AdventureMapButton (CGI->generaltexth->zelp[324].first, CGI->generaltexth->zelp[324].second, boost::bind(&CSystemOptionsWindow::bquitf, this), 405, 471, "soquit.def", SDLK_q);
std::swap(quitGame->imgs[0][0], quitGame->imgs[0][1]);
backToMap = new AdventureMapButton (CGI->generaltexth->zelp[325].first, CGI->generaltexth->zelp[325].second, boost::bind(&CSystemOptionsWindow::breturnf, this), 516, 471, "soretrn.def", SDLK_RETURN);
backToMap->assignedKeys.insert(SDLK_ESCAPE);
std::swap(backToMap->imgs[0][0], backToMap->imgs[0][1]);
heroMoveSpeed = new CHighlightableButtonsGroup(0);
@@ -4606,7 +4610,12 @@ void CInGameConsole::show(SDL_Surface * to)
for(std::list< std::pair< std::string, int > >::iterator it = texts.begin(); it != texts.end(); ++it, ++number)
{
SDL_Color green = {0,0xff,0,0};
CSDL_Ext::printAtWR(it->first, 50, conf.cc.resy - texts.size() * 30 - 80 + number*30, GEOR16, green);
Point leftBottomCorner(0, screen->h);
if(LOCPLINT->battleInt == LOCPLINT->curint)
{
leftBottomCorner = LOCPLINT->battleInt->pos.bottomLeft();
}
CSDL_Ext::printAtWR(it->first, leftBottomCorner.x + 50, leftBottomCorner.y - texts.size() * 20 - 80 + number*20, TNRB16, green);
if(SDL_GetTicks() - it->second > defaultTimeout)
{
toDel.push_back(it);
@@ -4619,58 +4628,67 @@ void CInGameConsole::show(SDL_Surface * to)
}
}
void CInGameConsole::print(const std::string &txt)
{
texts.push_back(std::make_pair(txt, SDL_GetTicks()));
if(texts.size() > maxDisplayedTexts)
{
texts.pop_front();
}
}
void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)
{
if(key.type == SDL_KEYDOWN)
if(key.type != SDL_KEYDOWN) return;
switch(key.keysym.sym)
{
switch(key.keysym.sym)
case SDLK_TAB:
{
case SDLK_TAB:
if(captureAllKeys)
{
if(captureAllKeys)
{
captureAllKeys = false;
endEnteringText(false);
}
else
{
captureAllKeys = true;
startEnteringText();
}
break;
captureAllKeys = false;
endEnteringText(false);
}
case SDLK_RETURN: //enter key
else
{
if(enteredText.size() > 0)
{
if(captureAllKeys)
{
captureAllKeys = false;
endEnteringText(true);
}
}
break;
captureAllKeys = true;
startEnteringText();
}
default:
break;
}
case SDLK_RETURN: //enter key
{
if(enteredText.size() > 0 && captureAllKeys)
{
if(enteredText.size() > 0)
{
if( key.keysym.unicode < 0x80 && key.keysym.unicode > 0 )
{
enteredText[enteredText.size()-1] = (char)key.keysym.unicode;
enteredText += "_";
if(LOCPLINT->curint == LOCPLINT->adventureInt)
{
LOCPLINT->statusbar->print(enteredText);
}
else if(LOCPLINT->curint == LOCPLINT->battleInt)
{
LOCPLINT->battleInt->console->ingcAlter = enteredText;
}
}
}
break;
captureAllKeys = false;
endEnteringText(true);
}
break;
}
case SDLK_BACKSPACE:
{
if(enteredText.size() > 1)
{
enteredText.resize(enteredText.size()-1);
enteredText[enteredText.size()-1] = '_';
refreshEnteredText();
}
break;
}
default:
{
if(enteredText.size() > 0)
{
if( key.keysym.unicode < 0x80 && key.keysym.unicode > 0 )
{
enteredText[enteredText.size()-1] = (char)key.keysym.unicode;
enteredText += "_";
refreshEnteredText();
}
}
break;
}
}
}
@@ -4692,11 +4710,9 @@ void CInGameConsole::endEnteringText(bool printEnteredText)
{
if(printEnteredText)
{
texts.push_back(std::make_pair(enteredText.substr(0, enteredText.size()-1), SDL_GetTicks()));
if(texts.size() > maxDisplayedTexts)
{
texts.pop_front();
}
std::string txt = enteredText.substr(0, enteredText.size()-1);
LOCPLINT->cb->sendMessage(txt);
print(txt);
}
enteredText = "";
if(LOCPLINT->curint == LOCPLINT->adventureInt)
@@ -4710,6 +4726,18 @@ void CInGameConsole::endEnteringText(bool printEnteredText)
}
void CInGameConsole::refreshEnteredText()
{
if(LOCPLINT->curint == LOCPLINT->adventureInt)
{
LOCPLINT->statusbar->print(enteredText);
}
else if(LOCPLINT->curint == LOCPLINT->battleInt)
{
LOCPLINT->battleInt->console->ingcAlter = enteredText;
}
}
CInGameConsole::CInGameConsole() : defaultTimeout(10000), maxDisplayedTexts(10)
{
}

View File

@@ -913,10 +913,12 @@ public:
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
void print(const std::string &txt);
void keyPressed (const SDL_KeyboardEvent & key); //call-in
void startEnteringText();
void endEnteringText(bool printEnteredText);
void refreshEnteredText();
CInGameConsole(); //c-tor
};

View File

@@ -416,7 +416,12 @@ void EndAction::applyCl( CClient *cl )
void SystemMessage::applyCl( CClient *cl )
{
tlog4 << "System message from server: " << text << std::endl;
std::ostringstream str;
str << "System message from server: " << text;
tlog4 << str.str() << std::endl;
if(LOCPLINT)
LOCPLINT->cingconsole->print(str.str());
}
void YourTurn::applyCl( CClient *cl )
@@ -432,7 +437,12 @@ void SaveGame::applyCl(CClient *cl)
void PlayerMessage::applyCl(CClient *cl)
{
tlog4 << "Player "<<(int)player<<" sends a message: " << text << std::endl;
std::ostringstream str;
str << "Player "<<(int)player<<" sends a message: " << text;
tlog4 << str.str() << std::endl;
if(LOCPLINT)
LOCPLINT->cingconsole->print(str.str());
}
void ShowInInfobox::applyCl(CClient *cl)

View File

@@ -1014,17 +1014,15 @@ void Mapa::readHeader( unsigned char * bufor, int &i)
ist=i; //starting i for loop
allowedHeroes.resize(HEROES_QUANTITY);
for(int xx=0;xx<HEROES_QUANTITY;xx++)
allowedHeroes[xx] = true;
allowedHeroes.resize(HEROES_QUANTITY,false);
for(i; i<ist+ (version == RoE ? 16 : 20) ; ++i)
{
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
if((i-ist)*8+yy < HEROES_QUANTITY)
if(c != (c|((unsigned char)intPow(2, yy))))
allowedHeroes[(i-ist)*8+yy] = false;
if(c == (c|((unsigned char)intPow(2, yy))))
allowedHeroes[(i-ist)*8+yy] = true;
}
if(version>RoE) //probably reserved for further heroes
i+=4;

View File

@@ -84,7 +84,7 @@ class CMP_stack
public:
inline bool operator ()(const CStack* a, const CStack* b)
{
return (a->speed())>(b->speed());
return (a->Speed())>(b->Speed());
}
} cmpst ;
@@ -290,8 +290,8 @@ void CGameHandler::changePrimSkill(int ID, int which, int val, bool abs)
}
else if(hlu.skills.size() == 1) //apply, give only possible skill and send info
{
changeSecSkill(ID,hlu.skills.back(),1,false);
sendAndApply(&hlu);
changeSecSkill(ID,hlu.skills.back(),1,false);
}
else //apply and send info
{
@@ -552,7 +552,7 @@ void CGameHandler::moveStack(int stack, int dest)
std::pair< std::vector<int>, int > path = gs->curB->getPath(curStack->position, dest, accessibility, curStack->creature->isFlying());
if(curStack->creature->isFlying())
{
if(path.second <= curStack->speed() && path.first.size() > 0)
if(path.second <= curStack->Speed() && path.first.size() > 0)
{
//inform clients about move
BattleStackMoved sm;
@@ -565,7 +565,7 @@ void CGameHandler::moveStack(int stack, int dest)
}
else //for non-flying creatures
{
int tilesToMove = std::max((int)(path.first.size() - curStack->speed()), 0);
int tilesToMove = std::max((int)(path.first.size() - curStack->Speed()), 0);
for(int v=path.first.size()-1; v>=tilesToMove; --v)
{
//inform clients about move
@@ -666,6 +666,10 @@ void CGameHandler::newTurn()
r.res[6] += 500;
break;
}
for(std::list<HeroBonus>::iterator i = h->bonuses.begin(); i != h->bonuses.end(); i++)
if(i->type == HeroBonus::GENERATE_RESOURCE)
r.res[i->subtype] += i->val;
}
for(std::vector<CGTownInstance *>::iterator j=i->second.towns.begin();j!=i->second.towns.end();j++)//handle towns
{
@@ -810,11 +814,11 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, CCreatureSet &army
for(std::map<si32,std::pair<ui32,si32> >::iterator i = army1.slots.begin(); i!=army1.slots.end(); i++)
{
stacks.push_back(new CStack(&VLC->creh->creatures[i->second.first],i->second.second,hero1->tempOwner, stacks.size(), true,i->first));
//base luck/morale calculations
//TODO: check if terrain is native, add bonuses for neutral stacks, bonuses from town
if(hero1)
{
stacks.back()->speed += hero1->valOfBonuses(HeroBonus::STACKS_SPEED);
//base luck/morale calculations
//TODO: check if terrain is native, add bonuses for neutral stacks, bonuses from town
stacks.back()->morale = hero1->getCurrentMorale(i->first,false);
stacks.back()->luck = hero1->getCurrentLuck(i->first,false);
}
@@ -863,6 +867,7 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, CCreatureSet &army
//TODO: check if terrain is native, add bonuses for neutral stacks, bonuses from town
if(hero2)
{
stacks.back()->speed += hero2->valOfBonuses(HeroBonus::STACKS_SPEED);
stacks.back()->morale = hero2->getCurrentMorale(i->first,false);
stacks.back()->luck = hero2->getCurrentLuck(i->first,false);
}