mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-01 12:57:51 +02:00
Merged most of the changes from trunk.
Because of really huge amount of modifications here I've probably missed some minor stuff. I doubt if it's still compatible with gcc - some changes should be reapplied.
This commit is contained in:
parent
dc82232e70
commit
cc7be20b07
@ -618,13 +618,13 @@ void CResDataBar::draw()
|
||||
char * buf = new char[15];
|
||||
for (int i=0;i<7;i++)
|
||||
{
|
||||
itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
|
||||
SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
|
||||
printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
|
||||
}
|
||||
std::vector<std::string> temp;
|
||||
itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
|
||||
itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
|
||||
itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
|
||||
SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
|
||||
SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
|
||||
SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
|
||||
printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
|
||||
temp.clear();
|
||||
//updateRect(&pos,screen);
|
||||
|
@ -15,13 +15,15 @@
|
||||
#include <queue>
|
||||
#include <sstream>
|
||||
|
||||
const double M_PI = 3.14159265358979323846;
|
||||
|
||||
extern SDL_Surface * screen;
|
||||
extern TTF_Font * GEOR13;
|
||||
extern SDL_Color zwykly;
|
||||
SDL_Surface * CBattleInterface::cellBorder, * CBattleInterface::cellShade;
|
||||
|
||||
CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2)
|
||||
: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL)
|
||||
: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL), myTurn(false)
|
||||
{
|
||||
//initializing armies
|
||||
this->army1 = army1;
|
||||
@ -120,6 +122,30 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
|
||||
bfield[it->second.position].accesible = false;
|
||||
}
|
||||
|
||||
//loading projectiles for units
|
||||
for(std::map<int, CStack>::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] = CDefHandler::giveDef(CGI->creh->idToProjectile[g->second.creature->idNumber]);
|
||||
|
||||
if(idToProjectile[g->second.creature->idNumber]->ourImages.size() > 2) //add symmetric images
|
||||
{
|
||||
for(int k = idToProjectile[g->second.creature->idNumber]->ourImages.size()-2; k > 1; --k)
|
||||
{
|
||||
Cimage ci;
|
||||
ci.bitmap = CSDL_Ext::rotate01(idToProjectile[g->second.creature->idNumber]->ourImages[k].bitmap);
|
||||
ci.groupNumber = 0;
|
||||
ci.imName = std::string();
|
||||
idToProjectile[g->second.creature->idNumber]->ourImages.push_back(ci);
|
||||
}
|
||||
}
|
||||
for(int s=0; s<idToProjectile[g->second.creature->idNumber]->ourImages.size(); ++s) //alpha transforming
|
||||
{
|
||||
CSDL_Ext::alphaTransform(idToProjectile[g->second.creature->idNumber]->ourImages[s].bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CBattleInterface::~CBattleInterface()
|
||||
@ -147,6 +173,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()
|
||||
@ -241,7 +270,7 @@ void CBattleInterface::show(SDL_Surface * to)
|
||||
if(defendingHero)
|
||||
defendingHero->show(to);
|
||||
|
||||
//showing units //a lot of work...
|
||||
////showing units //a lot of work...
|
||||
std::vector<int> stackAliveByHex[187];
|
||||
//double loop because dead stacks should be printed first
|
||||
for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
|
||||
@ -309,6 +338,7 @@ void CBattleInterface::show(SDL_Surface * to)
|
||||
}
|
||||
}
|
||||
//units shown
|
||||
projectileShowHelper(to);//showing projectiles
|
||||
}
|
||||
|
||||
bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
|
||||
@ -404,8 +434,36 @@ void CBattleInterface::stackRemoved(CStack stack)
|
||||
creAnims.erase(stack.ID);
|
||||
}
|
||||
|
||||
void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby)
|
||||
void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting)
|
||||
{
|
||||
if(creAnims[ID]->getType() != 2)
|
||||
{
|
||||
return; //something went wrong
|
||||
}
|
||||
if(byShooting) //delay hit animation
|
||||
{
|
||||
CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
|
||||
while(true)
|
||||
{
|
||||
bool found = false;
|
||||
for(std::list<SProjectileInfo>::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it)
|
||||
{
|
||||
if(it->creID == attacker.creature->idNumber)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
break;
|
||||
else
|
||||
{
|
||||
show();
|
||||
CSDL_Ext::update();
|
||||
SDL_framerateDelay(LOCPLINT->mainFPSmng);
|
||||
}
|
||||
}
|
||||
}
|
||||
creAnims[ID]->setType(5); //death
|
||||
for(int i=0; i<creAnims[ID]->framesInGroup(5)-1; ++i)
|
||||
{
|
||||
@ -421,6 +479,8 @@ void CBattleInterface::stackActivated(int number)
|
||||
{
|
||||
givenCommand = NULL;
|
||||
activeStack = number;
|
||||
shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(number);
|
||||
myTurn = true;
|
||||
}
|
||||
|
||||
void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, bool endMoving)
|
||||
@ -599,8 +659,36 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
|
||||
creAnims[number]->pos.y = coords.second;
|
||||
}
|
||||
|
||||
void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby)
|
||||
void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting)
|
||||
{
|
||||
if(creAnims[ID]->getType() != 2)
|
||||
{
|
||||
return; //something went wrong
|
||||
}
|
||||
if(byShooting) //delay hit animation
|
||||
{
|
||||
CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
|
||||
while(true)
|
||||
{
|
||||
bool found = false;
|
||||
for(std::list<SProjectileInfo>::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it)
|
||||
{
|
||||
if(it->creID == attacker.creature->idNumber)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
break;
|
||||
else
|
||||
{
|
||||
show();
|
||||
CSDL_Ext::update();
|
||||
SDL_framerateDelay(LOCPLINT->mainFPSmng);
|
||||
}
|
||||
}
|
||||
}
|
||||
creAnims[ID]->setType(3); //getting hit
|
||||
for(int i=0; i<creAnims[ID]->framesInGroup(3); ++i)
|
||||
{
|
||||
@ -615,6 +703,10 @@ void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby)
|
||||
|
||||
void CBattleInterface::stackAttacking(int ID, int dest)
|
||||
{
|
||||
if(attackingInfo != NULL)
|
||||
{
|
||||
return; //something went wrong
|
||||
}
|
||||
CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
|
||||
if(aStack.creature->isDoubleWide())
|
||||
{
|
||||
@ -664,9 +756,8 @@ void CBattleInterface::stackAttacking(int ID, int dest)
|
||||
attackingInfo->frame = 0;
|
||||
attackingInfo->ID = ID;
|
||||
attackingInfo->reversing = false;
|
||||
attackingInfo->shooting = false;
|
||||
|
||||
if(aStack.creature->isDoubleWide())
|
||||
{
|
||||
switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
|
||||
{
|
||||
case 0:
|
||||
@ -688,31 +779,6 @@ void CBattleInterface::stackAttacking(int ID, int dest)
|
||||
attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else //else for if(aStack.creature->isDoubleWide())
|
||||
{
|
||||
switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
|
||||
{
|
||||
case 0:
|
||||
attackingInfo->maxframe = creAnims[ID]->framesInGroup(10);
|
||||
break;
|
||||
case 1:
|
||||
attackingInfo->maxframe = creAnims[ID]->framesInGroup(10);
|
||||
break;
|
||||
case 2:
|
||||
attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
|
||||
break;
|
||||
case 3:
|
||||
attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
|
||||
break;
|
||||
case 4:
|
||||
attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
|
||||
break;
|
||||
case 5:
|
||||
attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CBattleInterface::newRound(int number)
|
||||
@ -724,6 +790,9 @@ void CBattleInterface::hexLclicked(int whichOne)
|
||||
{
|
||||
if((whichOne%17)!=0 && (whichOne%17)!=16) //if player is trying to attack enemey unit or move creature stack
|
||||
{
|
||||
if(!myTurn)
|
||||
return; //we are not permit to do anything
|
||||
|
||||
int atCre = LOCPLINT->cb->battleGetStack(whichOne); //creature at destination tile; -1 if there is no one
|
||||
//LOCPLINT->cb->battleGetCreature();
|
||||
if(atCre==-1) //normal move action
|
||||
@ -734,6 +803,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
|
||||
@ -745,9 +823,80 @@ void CBattleInterface::hexLclicked(int whichOne)
|
||||
}
|
||||
}
|
||||
|
||||
void CBattleInterface::stackIsShooting(int ID, int dest)
|
||||
{
|
||||
if(attackingInfo != NULL)
|
||||
{
|
||||
return; //something went wrong
|
||||
}
|
||||
//projectile
|
||||
float projectileAngle; //in radians; if positive, projectiles goes up
|
||||
float straightAngle = 0.2f; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value)
|
||||
int fromHex = LOCPLINT->cb->battleGetPos(ID);
|
||||
projectileAngle = atan2(float(abs(dest - fromHex)/17), float(abs(dest - fromHex)%17));
|
||||
if(fromHex < dest)
|
||||
projectileAngle = -projectileAngle;
|
||||
|
||||
SProjectileInfo spi;
|
||||
spi.creID = LOCPLINT->cb->battleGetStackByID(ID)->creature->idNumber;
|
||||
|
||||
spi.step = 0;
|
||||
spi.frameNum = 0;
|
||||
spi.spin = CGI->creh->idToProjectileSpin[spi.creID];
|
||||
|
||||
std::pair<int, int> xycoord = CBattleHex::getXYUnitAnim(LOCPLINT->cb->battleGetPos(ID), true, &LOCPLINT->cb->battleGetCreature(ID));
|
||||
std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(dest, false, &LOCPLINT->cb->battleGetCreature(ID));
|
||||
destcoord.first += 250; destcoord.second += 210; //TODO: find a better place to shoot
|
||||
|
||||
if(projectileAngle > straightAngle) //upper shot
|
||||
{
|
||||
spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetX;
|
||||
spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetY;
|
||||
}
|
||||
else if(projectileAngle < -straightAngle) //lower shot
|
||||
{
|
||||
spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetX;
|
||||
spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetY;
|
||||
}
|
||||
else //straight shot
|
||||
{
|
||||
spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetX;
|
||||
spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetY;
|
||||
}
|
||||
spi.lastStep = sqrt((float)((destcoord.first - spi.x)*(destcoord.first - spi.x) + (destcoord.second - spi.y) * (destcoord.second - spi.y))) / 40;
|
||||
spi.dx = (destcoord.first - spi.x) / spi.lastStep;
|
||||
spi.dy = (destcoord.second - spi.y) / spi.lastStep;
|
||||
//set starting frame
|
||||
if(spi.spin)
|
||||
{
|
||||
spi.frameNum = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
spi.frameNum = ((M_PI/2.0f - projectileAngle) / (2.0f *M_PI) + 1/((float)(2*(idToProjectile[spi.creID]->ourImages.size()-1)))) * (idToProjectile[spi.creID]->ourImages.size()-1);
|
||||
}
|
||||
//set delay
|
||||
spi.animStartDelay = CGI->creh->creatures[spi.creID].attackClimaxFrame;
|
||||
projectiles.push_back(spi);
|
||||
|
||||
//attack aniamtion
|
||||
attackingInfo = new CAttHelper;
|
||||
attackingInfo->dest = dest;
|
||||
attackingInfo->frame = 0;
|
||||
attackingInfo->ID = ID;
|
||||
attackingInfo->reversing = false;
|
||||
attackingInfo->shooting = true;
|
||||
if(projectileAngle > straightAngle) //upper shot
|
||||
attackingInfo->shootingGroup = 14;
|
||||
else if(projectileAngle < -straightAngle) //lower shot
|
||||
attackingInfo->shootingGroup = 15;
|
||||
else //straight shot
|
||||
attackingInfo->shootingGroup = 16;
|
||||
attackingInfo->maxframe = creAnims[ID]->framesInGroup(attackingInfo->shootingGroup);
|
||||
}
|
||||
|
||||
void CBattleInterface::showRange(SDL_Surface * to, int ID)
|
||||
{
|
||||
std::vector<int> shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(ID);
|
||||
for(int i=0; i<shadedHexes.size(); ++i)
|
||||
{
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(CBattleInterface::cellShade, NULL, to, &bfield[shadedHexes[i]].pos);
|
||||
@ -762,6 +911,12 @@ void CBattleInterface::attackingShowHelper()
|
||||
if(attackingInfo->frame == 0)
|
||||
{
|
||||
CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
|
||||
if(attackingInfo->shooting)
|
||||
{
|
||||
creAnims[attackingInfo->ID]->setType(attackingInfo->shootingGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(aStack.creature->isDoubleWide())
|
||||
{
|
||||
switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
|
||||
@ -811,6 +966,7 @@ void CBattleInterface::attackingShowHelper()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(attackingInfo->frame == (attackingInfo->maxframe - 1))
|
||||
{
|
||||
attackingInfo->reversing = true;
|
||||
@ -892,6 +1048,47 @@ void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDb
|
||||
console->addText(std::string(tabh));
|
||||
}
|
||||
|
||||
void CBattleInterface::projectileShowHelper(SDL_Surface * to)
|
||||
{
|
||||
if(to == NULL)
|
||||
to = screen;
|
||||
std::list< std::list<SProjectileInfo>::iterator > toBeDeleted;
|
||||
for(std::list<SProjectileInfo>::iterator it=projectiles.begin(); it!=projectiles.end(); ++it)
|
||||
{
|
||||
if(it->animStartDelay>0)
|
||||
{
|
||||
--(it->animStartDelay);
|
||||
continue;
|
||||
}
|
||||
SDL_Rect dst;
|
||||
dst.h = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->h;
|
||||
dst.w = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->w;
|
||||
dst.x = it->x;
|
||||
dst.y = it->y;
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(idToProjectile[it->creID]->ourImages[it->frameNum].bitmap, NULL, to, &dst);
|
||||
//actualizing projectile
|
||||
++it->step;
|
||||
if(it->step == it->lastStep)
|
||||
{
|
||||
toBeDeleted.insert(toBeDeleted.end(), it);
|
||||
}
|
||||
else
|
||||
{
|
||||
it->x += it->dx;
|
||||
it->y += it->dy;
|
||||
if(it->spin)
|
||||
{
|
||||
++(it->frameNum);
|
||||
it->frameNum %= idToProjectile[it->creID]->ourImages.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
for(std::list< std::list<SProjectileInfo>::iterator >::iterator it = toBeDeleted.begin(); it!= toBeDeleted.end(); ++it)
|
||||
{
|
||||
projectiles.erase(*it);
|
||||
}
|
||||
}
|
||||
|
||||
void CBattleHero::show(SDL_Surface *to)
|
||||
{
|
||||
//animation of flag
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "global.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include <list>
|
||||
|
||||
class CCreatureSet;
|
||||
class CGHeroInstance;
|
||||
@ -79,9 +80,11 @@ 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; // <creatureID, if false reverse creature's animation>
|
||||
unsigned char animCount;
|
||||
int activeStack; //number of active stack; -1 - no one
|
||||
std::vector<int> shadedHexes; //hexes available for active stack
|
||||
void showRange(SDL_Surface * to, int ID); //show helper funtion ot mark range of a unit
|
||||
|
||||
class CAttHelper
|
||||
@ -91,10 +94,25 @@ private:
|
||||
int dest; //atacked hex
|
||||
int frame, maxframe; //frame of animation, number of frames of animation
|
||||
bool reversing;
|
||||
bool shooting;
|
||||
int shootingGroup; //if shooting is true, print this animation group
|
||||
} * attackingInfo;
|
||||
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
|
||||
int animStartDelay; //how many times projectile must be attempted to be shown till it's really show (decremented after hit)
|
||||
};
|
||||
std::list<SProjectileInfo> projectiles;
|
||||
void projectileShowHelper(SDL_Surface * to=NULL); //prints projectiles present on the battlefield
|
||||
|
||||
public:
|
||||
CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor
|
||||
~CBattleInterface(); //d-tor
|
||||
@ -105,6 +123,7 @@ public:
|
||||
std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield
|
||||
static SDL_Surface * cellBorder, * cellShade;
|
||||
BattleAction * givenCommand; //true if we have i.e. moved current unit
|
||||
bool myTurn; //if true, interface is active (commands can be ordered
|
||||
|
||||
//button handle funcs:
|
||||
void bOptionsf();
|
||||
@ -126,13 +145,14 @@ public:
|
||||
//call-ins
|
||||
void newStack(CStack stack); //new stack appeared on battlefield
|
||||
void stackRemoved(CStack stack); //stack disappeared from batlefiled
|
||||
void stackKilled(int ID, int dmg, int killed, int IDby); //stack has been killed (but corpses remain)
|
||||
void stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting); //stack has been killed (but corpses remain)
|
||||
void stackActivated(int number); //active stack has been changed
|
||||
void stackMoved(int number, int destHex, bool startMoving, bool endMoving); //stack with id number moved to destHex
|
||||
void stackIsAttacked(int ID, int dmg, int killed, int IDby); //called when stack id attacked by stack with id IDby
|
||||
void stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting); //called when stack id attacked by stack with id IDby
|
||||
void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest
|
||||
void newRound(int number); //caled when round is ended; number is the number of round
|
||||
void hexLclicked(int whichOne); //hex only call-in
|
||||
void stackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest
|
||||
|
||||
friend CBattleHex;
|
||||
friend class CBattleHex;
|
||||
};
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include "lib/NetPacks.h"
|
||||
//LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
|
||||
extern CSharedCond<std::set<IPack*> > mess;
|
||||
|
||||
HeroMoveDetails::HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho)
|
||||
@ -79,7 +78,6 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
|
||||
int3 stpos(ourPath->nodes[i].coord.x, ourPath->nodes[i].coord.y, hero->pos.z),
|
||||
endpos(ourPath->nodes[i-1].coord.x, ourPath->nodes[i-1].coord.y, hero->pos.z);
|
||||
HeroMoveDetails curd(stpos,endpos,hero);
|
||||
|
||||
*cl->serv << ui16(501) << hero->id << stpos << endpos;
|
||||
{//wait till there is server answer
|
||||
boost::unique_lock<boost::mutex> lock(*mess.mx);
|
||||
@ -288,6 +286,29 @@ std::vector<si32> CCallback::getResourceAmount()
|
||||
int CCallback::getDate(int mode)
|
||||
{
|
||||
return gs->getDate(mode);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
std::vector < std::string > CCallback::getObjDescriptions(int3 pos)
|
||||
{
|
||||
@ -310,15 +331,15 @@ bool CCallback::verifyPath(CPath * path, bool blockSea)
|
||||
continue;
|
||||
|
||||
if (
|
||||
((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype==EterrainType::water)
|
||||
((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype==water)
|
||||
&&
|
||||
(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype!=EterrainType::water))
|
||||
(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype!=water))
|
||||
||
|
||||
((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype!=EterrainType::water)
|
||||
((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype!=water)
|
||||
&&
|
||||
(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==EterrainType::water))
|
||||
(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==water))
|
||||
||
|
||||
(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==EterrainType::rock)
|
||||
(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==rock)
|
||||
|
||||
)
|
||||
return false;
|
||||
@ -401,6 +422,9 @@ const CCreatureSet* CCallback::getGarrison(const CGObjectInstance *obj)
|
||||
int CCallback::swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)
|
||||
{
|
||||
if(s1->tempOwner != player || s2->tempOwner != player)
|
||||
|
||||
|
||||
|
||||
return -1;
|
||||
|
||||
*cl->serv << ui16(502) << ui8(1) << s1->id << ui8(p1) << s2->id << ui8(p2);
|
||||
@ -493,18 +517,7 @@ int CCallback::battleGetObstaclesAtTile(int tile) //returns bitfield
|
||||
}
|
||||
int CCallback::battleGetStack(int pos)
|
||||
{
|
||||
for(int g=0; g<CGI->state->curB->stacks.size(); ++g)
|
||||
{
|
||||
if(CGI->state->curB->stacks[g]->position == pos ||
|
||||
( CGI->state->curB->stacks[g]->creature->isDoubleWide() &&
|
||||
( (CGI->state->curB->stacks[g]->attackerOwned && CGI->state->curB->stacks[g]->position-1 == pos) ||
|
||||
(!CGI->state->curB->stacks[g]->attackerOwned && CGI->state->curB->stacks[g]->position+1 == pos)
|
||||
)
|
||||
)
|
||||
)
|
||||
return CGI->state->curB->stacks[g]->ID;
|
||||
}
|
||||
return -1;
|
||||
return CGI->state->battleGetStack(pos);
|
||||
}
|
||||
|
||||
CStack* CCallback::battleGetStackByID(int ID)
|
||||
@ -566,3 +579,12 @@ 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
|
||||
&& battleGetStackByPos(dest)->alive)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
15
CCallback.h
15
CCallback.h
@ -2,8 +2,13 @@
|
||||
#define CCALLBACK_H
|
||||
|
||||
#include "global.h"
|
||||
#ifdef _WIN32
|
||||
#include "tchar.h"
|
||||
#include <set>
|
||||
#else
|
||||
#include "tchar_amigaos4.h"
|
||||
#endif
|
||||
#include "CGameState.h"
|
||||
|
||||
class CGHeroInstance;
|
||||
class CGameState;
|
||||
struct CPath;
|
||||
@ -74,6 +79,7 @@ public:
|
||||
//virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible
|
||||
virtual std::vector<int> 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
|
||||
@ -147,9 +153,16 @@ public:
|
||||
//bool battleMoveCreature(int ID, int dest); //moves creature with id ID to dest if possible
|
||||
std::vector<int> 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
|
||||
friend class CClient;
|
||||
#ifndef __GNUC__
|
||||
friend int _tmain(int argc, _TCHAR* argv[]);
|
||||
#else
|
||||
friend int main(int argc, _TCHAR* argv[]);
|
||||
#endif
|
||||
};
|
||||
#endif //CCALLBACK_H
|
@ -194,7 +194,11 @@ std::string getBgName(int type) //TODO - co z tym zrobi
|
||||
case 8:
|
||||
return "TBELBACK.bmp";
|
||||
default:
|
||||
#ifndef __GNUC__
|
||||
throw new std::exception("std::string getBgName(int type): invalid type");
|
||||
#else
|
||||
throw new std::exception();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
class SORTHELP
|
||||
@ -283,7 +287,11 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
|
||||
defname = "HALLELEM.DEF";
|
||||
break;
|
||||
default:
|
||||
#ifndef __GNUC__
|
||||
throw new std::exception("Bad town subID");
|
||||
#else
|
||||
throw new std::exception();
|
||||
#endif
|
||||
}
|
||||
bicons = CDefHandler::giveDefEss(defname);
|
||||
//blit buildings on bg
|
||||
@ -426,7 +434,7 @@ void CCastleInterface::showAll(SDL_Surface * to)
|
||||
//print name and income
|
||||
CSDL_Ext::printAt(town->name,85,389,GEOR13,zwykly,to);
|
||||
char temp[10];
|
||||
itoa(town->dailyIncome(),temp,10);
|
||||
SDL_itoa(town->dailyIncome(),temp,10);
|
||||
CSDL_Ext::printAtMiddle(temp,195,442,GEOR13,zwykly,to);
|
||||
|
||||
//blit town icon
|
||||
@ -567,7 +575,11 @@ void CCastleInterface::recreateBuildings()
|
||||
{
|
||||
delete buildings[itpb];
|
||||
buildings.erase(buildings.begin() + itpb);
|
||||
#ifndef __GNUC__
|
||||
obecny->second = st->ID;
|
||||
#else
|
||||
*(const_cast<int*>(&(obecny->second))) = st->ID;
|
||||
#endif
|
||||
buildings.push_back(new CBuildingRect(st));
|
||||
}
|
||||
}
|
||||
@ -640,13 +652,13 @@ void CHallInterface::CResDataBar::show(SDL_Surface * to)
|
||||
char * buf = new char[15];
|
||||
for (int i=0;i<7;i++)
|
||||
{
|
||||
itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
|
||||
SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
|
||||
CSDL_Ext::printAtMiddle(buf,pos.x + 50 + 76*i,pos.y+pos.h/2,GEOR13,zwykly);
|
||||
}
|
||||
std::vector<std::string> temp;
|
||||
itoa(LOCPLINT->cb->getDate(3),buf,10); temp.push_back(std::string(buf));
|
||||
itoa(LOCPLINT->cb->getDate(2),buf,10); temp.push_back(buf);
|
||||
itoa(LOCPLINT->cb->getDate(1),buf,10); temp.push_back(buf);
|
||||
SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp.push_back(std::string(buf));
|
||||
SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp.push_back(buf);
|
||||
SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp.push_back(buf);
|
||||
CSDL_Ext::printAtMiddle(CSDL_Ext::processStr(
|
||||
CGI->generaltexth->allTexts[62]
|
||||
+": %s, "
|
||||
@ -1012,12 +1024,12 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod
|
||||
:tid(Tid),bid(Bid),mode(Mode), state(State)
|
||||
{
|
||||
SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPUBUILD.bmp");
|
||||
graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
|
||||
bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo
|
||||
SDL_SetColorKey(hhlp,SDL_SRCCOLORKEY,SDL_MapRGB(hhlp->format,0,255,255));
|
||||
SDL_FreeSurface(hhlp);
|
||||
pos.x = screen->w/2 - bitmap->w/2;
|
||||
pos.y = screen->h/2 - bitmap->h/2;
|
||||
graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID);
|
||||
blitAt(LOCPLINT->castleInt->bicons->ourImages[bid].bitmap,125,50,bitmap);
|
||||
std::vector<std::string> pom; pom.push_back(CGI->buildh->buildings[tid][bid]->name);
|
||||
CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->description,197,168,GEOR16,40,zwykly,bitmap);
|
||||
@ -1033,7 +1045,7 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod
|
||||
{
|
||||
if(!CGI->buildh->buildings[tid][bid]->resources[cn])
|
||||
continue;
|
||||
itoa(CGI->buildh->buildings[tid][bid]->resources[cn],buf,10);
|
||||
SDL_itoa(CGI->buildh->buildings[tid][bid]->resources[cn],buf,10);
|
||||
if(it<4)
|
||||
{
|
||||
CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row1w/2)+77*it+16,ah+42,GEOR16,zwykly,bitmap);
|
||||
|
@ -53,7 +53,7 @@ int internalFunc(void * callback)
|
||||
boost::filesystem::create_directory("Extracted_txts");
|
||||
std::cout<<"Command accepted. Opening .lod file...\t";
|
||||
CLodHandler * txth = new CLodHandler;
|
||||
txth->init(std::string("Data\\H3bitmap.lod"),"data");
|
||||
txth->init(std::string(DATA_DIR "Data" PATHSEPARATOR "H3bitmap.lod"),"data");
|
||||
std::cout<<"done.\nScanning .lod file\n";
|
||||
int curp=0;
|
||||
std::string pattern = ".TXT";
|
||||
@ -74,6 +74,9 @@ int internalFunc(void * callback)
|
||||
std::cout<<"\rExtracting done :)\n";
|
||||
}
|
||||
vector<Coordinate>* p;
|
||||
int heroX;
|
||||
int heroY;
|
||||
int heroZ;
|
||||
switch (*cn.c_str())
|
||||
{
|
||||
//case 'P':
|
||||
@ -144,6 +147,7 @@ int internalFunc(void * callback)
|
||||
//SDL_Delay(100);
|
||||
//delete p;
|
||||
}
|
||||
SDL_Delay(10);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -8,6 +8,12 @@ public:
|
||||
void runConsole();
|
||||
|
||||
friend class CClient;
|
||||
|
||||
#ifndef __GNUC__
|
||||
friend int _tmain(int argc, _TCHAR* argv[]);
|
||||
#else
|
||||
friend int main(int argc, _TCHAR* argv[]);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif //CCONSOLEHANDLER_H
|
@ -2,6 +2,10 @@
|
||||
#define CGAMEINFO_H
|
||||
#include "global.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
#include "stdafx.h"
|
||||
#include "CGameInterface.h"
|
||||
#include "CAdvMapInterface.h"
|
||||
#include "CAdvmapInterface.h"
|
||||
#include "CMessage.h"
|
||||
#include "mapHandler.h"
|
||||
#include "SDL_Extensions.h"
|
||||
#include "SDL_framerate.h"
|
||||
#include "CScreenHandler.h"
|
||||
#include "CCursorHandler.h"
|
||||
#include "CCallback.h"
|
||||
#include "SDL_Extensions.h"
|
||||
@ -14,6 +13,7 @@
|
||||
#include <sstream>
|
||||
#include "hch/CHeroHandler.h"
|
||||
#include "SDL_framerate.h"
|
||||
#include "AI/EmptyAI/CEmptyAI.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h> //for .dll libs
|
||||
@ -28,6 +28,7 @@ CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname)
|
||||
CGlobalAI * ret=NULL;
|
||||
CGlobalAI*(*getAI)();
|
||||
void(*getName)(char*);
|
||||
|
||||
#ifdef _WIN32
|
||||
HINSTANCE dll = LoadLibraryA(dllname.c_str());
|
||||
if (!dll)
|
||||
@ -42,11 +43,17 @@ CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname)
|
||||
; //TODO: handle AI library on Linux
|
||||
#endif
|
||||
char * temp = new char[50];
|
||||
#if !defined(__amigaos4__) && !defined(__unix__)
|
||||
getName(temp);
|
||||
#endif
|
||||
std::cout << "Loaded .dll with AI named " << temp << std::endl;
|
||||
delete temp;
|
||||
#if !defined(__amigaos4__) && !defined(__unix__)
|
||||
ret = getAI();
|
||||
ret->init(cb);
|
||||
#else
|
||||
//ret = new CEmptyAI();
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
//CGlobalAI::CGlobalAI()
|
||||
|
@ -50,12 +50,12 @@ public:
|
||||
bool human;
|
||||
int playerID, serialID;
|
||||
|
||||
virtual void init(ICallback * CB)=0{};
|
||||
virtual void yourTurn()=0{};
|
||||
virtual void heroKilled(const CGHeroInstance*)=0{};
|
||||
virtual void heroCreated(const CGHeroInstance*)=0{};
|
||||
virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)=0{};
|
||||
virtual void heroMoved(const HeroMoveDetails & details)=0{};
|
||||
virtual void init(ICallback * CB){};
|
||||
virtual void yourTurn(){};
|
||||
virtual void heroKilled(const CGHeroInstance*){};
|
||||
virtual void heroCreated(const CGHeroInstance*){};
|
||||
virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val){};
|
||||
virtual void heroMoved(const HeroMoveDetails & details){};
|
||||
virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};
|
||||
virtual void tileRevealed(int3 pos){};
|
||||
virtual void tileHidden(int3 pos){};
|
||||
@ -74,8 +74,8 @@ public:
|
||||
virtual void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner){};
|
||||
virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving)=0;
|
||||
virtual void battleStackAttacking(int ID, int dest)=0;
|
||||
virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby)=0;
|
||||
virtual void battleStackKilled(int ID, int dmg, int killed, int IDby)=0;
|
||||
virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting)=0;
|
||||
virtual void battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting)=0;
|
||||
//
|
||||
|
||||
};
|
||||
@ -93,8 +93,8 @@ public:
|
||||
virtual void heroCreated(const CGHeroInstance*){};
|
||||
virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving){};
|
||||
virtual void battleStackAttacking(int ID, int dest){};
|
||||
virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby){};
|
||||
virtual void battleStackKilled(int ID, int dmg, int killed, int IDby){};
|
||||
virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting){};
|
||||
virtual void battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting){};
|
||||
virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;};
|
||||
};
|
||||
#endif //CGAMEINTERFACE_H
|
206
CGameState.cpp
206
CGameState.cpp
@ -922,6 +922,11 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
|
||||
battleAttackCreatureStack(ba.stackNumber, ba.destinationTile);
|
||||
break;
|
||||
}
|
||||
case 7: //shoot
|
||||
{
|
||||
battleShootCreatureStack(ba.stackNumber, ba.destinationTile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1030,7 +1035,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)
|
||||
@ -1111,16 +1116,150 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
|
||||
{
|
||||
LOCPLINT->battleStackAttacking(ID, path[v]);
|
||||
//counting dealt damage
|
||||
int numberOfCres = curStack->amount; //number of attacking creatures
|
||||
int attackDefenseBonus = curStack->creature->attack - curB->stacks[numberOfStackAtEnd]->creature->defence;
|
||||
int damageBase = 0;
|
||||
if(curStack->creature->damageMax == curStack->creature->damageMin) //constant damage
|
||||
int finalDmg = calculateDmg(curStack, curB->stacks[numberOfStackAtEnd]);
|
||||
|
||||
//applying damages
|
||||
int cresKilled = finalDmg / curB->stacks[numberOfStackAtEnd]->creature->hitPoints;
|
||||
int damageFirst = finalDmg % curB->stacks[numberOfStackAtEnd]->creature->hitPoints;
|
||||
|
||||
if( curB->stacks[numberOfStackAtEnd]->firstHPleft <= damageFirst )
|
||||
{
|
||||
damageBase = curStack->creature->damageMin;
|
||||
curB->stacks[numberOfStackAtEnd]->amount -= 1;
|
||||
curB->stacks[numberOfStackAtEnd]->firstHPleft += curB->stacks[numberOfStackAtEnd]->creature->hitPoints - damageFirst;
|
||||
}
|
||||
else
|
||||
{
|
||||
damageBase = ran()%(curStack->creature->damageMax - curStack->creature->damageMin) + curStack->creature->damageMin + 1;
|
||||
curB->stacks[numberOfStackAtEnd]->firstHPleft -= damageFirst;
|
||||
}
|
||||
|
||||
int cresInstackBefore = curB->stacks[numberOfStackAtEnd]->amount;
|
||||
curB->stacks[numberOfStackAtEnd]->amount -= cresKilled;
|
||||
if(curB->stacks[numberOfStackAtEnd]->amount<=0) //stack killed
|
||||
{
|
||||
curB->stacks[numberOfStackAtEnd]->amount = 0;
|
||||
LOCPLINT->battleStackKilled(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore) , ID, false);
|
||||
curB->stacks[numberOfStackAtEnd]->alive = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOCPLINT->battleStackIsAttacked(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID, false);
|
||||
}
|
||||
|
||||
//damage applied
|
||||
}
|
||||
}
|
||||
curB->stackActionPerformed = true;
|
||||
LOCPLINT->actionFinished(BattleAction());*/
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGameState::battleAttackCreatureStack(int ID, int dest)
|
||||
{
|
||||
int attackedCreaure = -1; //-1 - there is no attacked creature
|
||||
for(int b=0; b<curB->stacks.size(); ++b) //TODO: make upgrades for two-hex cres.
|
||||
{
|
||||
if(curB->stacks[b]->position == dest)
|
||||
{
|
||||
attackedCreaure = curB->stacks[b]->ID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(attackedCreaure == -1)
|
||||
return false;
|
||||
//LOCPLINT->cb->
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGameState::battleShootCreatureStack(int ID, int dest)
|
||||
{/*
|
||||
CStack * curStack = NULL;
|
||||
for(int y=0; y<curB->stacks.size(); ++y)
|
||||
{
|
||||
if(curB->stacks[y]->ID == ID)
|
||||
{
|
||||
curStack = curB->stacks[y];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!curStack)
|
||||
return false;
|
||||
int IDOfStackAtEnd = battleGetStack(dest);
|
||||
int numberOfStackAtEnd = -1;
|
||||
for(int v=0; v<curB->stacks.size(); ++v)
|
||||
{
|
||||
if(curB->stacks[v]->ID == IDOfStackAtEnd)
|
||||
{
|
||||
numberOfStackAtEnd = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(IDOfStackAtEnd == -1 || curB->stacks[numberOfStackAtEnd]->owner == curStack->owner || !curB->stacks[numberOfStackAtEnd]->alive)
|
||||
return false;
|
||||
|
||||
LOCPLINT->battleStackIsShooting(ID, dest);
|
||||
|
||||
//counting dealt damage
|
||||
int finalDmg = calculateDmg(curStack, curB->stacks[numberOfStackAtEnd]);
|
||||
|
||||
//applying damages
|
||||
int cresKilled = finalDmg / curB->stacks[ID]->creature->hitPoints;
|
||||
int damageFirst = finalDmg % curB->stacks[ID]->creature->hitPoints;
|
||||
|
||||
if( curB->stacks[numberOfStackAtEnd]->firstHPleft <= damageFirst )
|
||||
{
|
||||
curB->stacks[numberOfStackAtEnd]->amount -= 1;
|
||||
curB->stacks[numberOfStackAtEnd]->firstHPleft += curB->stacks[numberOfStackAtEnd]->creature->hitPoints - damageFirst;
|
||||
}
|
||||
else
|
||||
{
|
||||
curB->stacks[numberOfStackAtEnd]->firstHPleft -= damageFirst;
|
||||
}
|
||||
|
||||
int cresInstackBefore = curB->stacks[numberOfStackAtEnd]->amount;
|
||||
curB->stacks[numberOfStackAtEnd]->amount -= cresKilled;
|
||||
if(curB->stacks[numberOfStackAtEnd]->amount<=0) //stack killed
|
||||
{
|
||||
curB->stacks[numberOfStackAtEnd]->amount = 0;
|
||||
LOCPLINT->battleStackKilled(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID, true);
|
||||
curB->stacks[numberOfStackAtEnd]->alive = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOCPLINT->battleStackIsAttacked(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID, true);
|
||||
}
|
||||
|
||||
//damage applied*/
|
||||
return true;
|
||||
}
|
||||
|
||||
int CGameState::battleGetStack(int pos)
|
||||
{
|
||||
for(int g=0; g<curB->stacks.size(); ++g)
|
||||
{
|
||||
if(curB->stacks[g]->position == pos ||
|
||||
( curB->stacks[g]->creature->isDoubleWide() &&
|
||||
( (curB->stacks[g]->attackerOwned && curB->stacks[g]->position-1 == pos) ||
|
||||
(!curB->stacks[g]->attackerOwned && curB->stacks[g]->position+1 == pos)
|
||||
)
|
||||
)
|
||||
)
|
||||
return curB->stacks[g]->ID;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CGameState::calculateDmg(const CStack* attacker, const CStack* defender)
|
||||
{
|
||||
int attackDefenseBonus = attacker->creature->attack - defender->creature->defence;
|
||||
int damageBase = 0;
|
||||
if(attacker->creature->damageMax == attacker->creature->damageMin) //constant damage
|
||||
{
|
||||
damageBase = attacker->creature->damageMin;
|
||||
}
|
||||
else
|
||||
{
|
||||
damageBase = rand()%(attacker->creature->damageMax - attacker->creature->damageMin) + attacker->creature->damageMin + 1;
|
||||
}
|
||||
|
||||
float dmgBonusMultiplier = 1.0;
|
||||
@ -1147,58 +1286,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
|
||||
}
|
||||
}
|
||||
|
||||
int finalDmg = (float)damageBase * (float)curStack->amount * dmgBonusMultiplier;
|
||||
|
||||
//applying damages
|
||||
int cresKilled = finalDmg / curB->stacks[numberOfStackAtEnd]->creature->hitPoints;
|
||||
int damageFirst = finalDmg % curB->stacks[numberOfStackAtEnd]->creature->hitPoints;
|
||||
|
||||
if( curB->stacks[numberOfStackAtEnd]->firstHPleft <= damageFirst )
|
||||
{
|
||||
curB->stacks[numberOfStackAtEnd]->amount -= 1;
|
||||
curB->stacks[numberOfStackAtEnd]->firstHPleft += curB->stacks[numberOfStackAtEnd]->creature->hitPoints - damageFirst;
|
||||
}
|
||||
else
|
||||
{
|
||||
curB->stacks[numberOfStackAtEnd]->firstHPleft -= damageFirst;
|
||||
}
|
||||
|
||||
int cresInstackBefore = curB->stacks[numberOfStackAtEnd]->amount;
|
||||
curB->stacks[numberOfStackAtEnd]->amount -= cresKilled;
|
||||
if(curB->stacks[numberOfStackAtEnd]->amount<=0) //stack killed
|
||||
{
|
||||
curB->stacks[numberOfStackAtEnd]->amount = 0;
|
||||
LOCPLINT->battleStackKilled(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore) , ID);
|
||||
curB->stacks[numberOfStackAtEnd]->alive = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOCPLINT->battleStackIsAttacked(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID);
|
||||
}
|
||||
|
||||
//damage applied
|
||||
}
|
||||
}
|
||||
curB->stackActionPerformed = true;
|
||||
LOCPLINT->actionFinished(BattleAction());*/
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGameState::battleAttackCreatureStack(int ID, int dest)
|
||||
{
|
||||
int attackedCreaure = -1; //-1 - there is no attacked creature
|
||||
for(int b=0; b<curB->stacks.size(); ++b) //TODO: make upgrades for two-hex cres.
|
||||
{
|
||||
if(curB->stacks[b]->position == dest)
|
||||
{
|
||||
attackedCreaure = curB->stacks[b]->ID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(attackedCreaure == -1)
|
||||
return false;
|
||||
//LOCPLINT->cb->
|
||||
return true;
|
||||
return (float)damageBase * (float)attacker->amount * dmgBonusMultiplier;
|
||||
}
|
||||
|
||||
std::vector<int> CGameState::battleGetRange(int ID)
|
||||
|
@ -3,7 +3,11 @@
|
||||
#include "global.h"
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#ifdef _WIN32
|
||||
#include <tchar.h>
|
||||
#else
|
||||
#include "tchar_amigaos4.h"
|
||||
#endif
|
||||
|
||||
class CScriptCallback;
|
||||
class CCallback;
|
||||
@ -78,7 +82,6 @@ private:
|
||||
ui32 day; //total number of days in game
|
||||
Mapa * map;
|
||||
std::map<ui8,PlayerState> players; //ID <-> playerstate
|
||||
|
||||
std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics
|
||||
|
||||
boost::shared_mutex *mx;
|
||||
@ -94,6 +97,9 @@ private:
|
||||
void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2);
|
||||
bool battleMoveCreatureStack(int ID, int dest);
|
||||
bool battleAttackCreatureStack(int ID, int dest);
|
||||
bool battleShootCreatureStack(int ID, int dest);
|
||||
int battleGetStack(int pos); //returns ID of stack at given tile
|
||||
static int calculateDmg(const CStack* attacker, const CStack* defender); //TODO: add additional conditions and require necessary data
|
||||
std::vector<int> battleGetRange(int ID); //called by std::vector<int> CCallback::battleGetAvailableHexes(int ID);
|
||||
public:
|
||||
int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
|
@ -47,7 +47,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<void()>(), 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);
|
||||
|
||||
@ -737,7 +736,7 @@ void CHeroWindow::redrawCurBack()
|
||||
blitAt(skillpics->ourImages[4].bitmap, 20, 230, curBack);
|
||||
blitAt(skillpics->ourImages[3].bitmap, 162, 230, curBack);
|
||||
|
||||
blitAt(graphics->portraitLarge[curHero->subID], 19, 19, curBack);
|
||||
blitAt(graphics->portraitLarge[curHero->portrait], 19, 19, curBack);
|
||||
|
||||
CSDL_Ext::printAtMiddle(curHero->name, 190, 40, GEORXX, tytulowy, curBack);
|
||||
|
||||
@ -802,14 +801,14 @@ void CHeroWindow::redrawCurBack()
|
||||
for(int g=0; g<LOCPLINT->cb->howManyHeroes(); ++g)
|
||||
{
|
||||
const CGHeroInstance * cur = LOCPLINT->cb->getHeroInfo(player, g, false);
|
||||
blitAt(graphics->portraitSmall[cur->subID], 611, 87+g*54, curBack);
|
||||
blitAt(graphics->portraitSmall[cur->portrait], 611, 87+g*54, curBack);
|
||||
//printing yellow border
|
||||
if(cur->name == curHero->name)
|
||||
{
|
||||
for(int f=0; f<graphics->portraitSmall[cur->subID]->w; ++f)
|
||||
for(int f=0; f<graphics->portraitSmall[cur->portrait]->w; ++f)
|
||||
{
|
||||
for(int h=0; h<graphics->portraitSmall[cur->subID]->h; ++h)
|
||||
if(f==0 || h==0 || f==graphics->portraitSmall[cur->subID]->w-1 || h==graphics->portraitSmall[cur->subID]->h-1)
|
||||
for(int h=0; h<graphics->portraitSmall[cur->portrait]->h; ++h)
|
||||
if(f==0 || h==0 || f==graphics->portraitSmall[cur->portrait]->w-1 || h==graphics->portraitSmall[cur->portrait]->h-1)
|
||||
{
|
||||
CSDL_Ext::SDL_PutPixel(curBack, 611+f, 87+g*54+h, 240, 220, 120);
|
||||
}
|
||||
@ -1038,6 +1037,10 @@ void LClickableArea::clickLeft(boost::logic::tribool down)
|
||||
//{
|
||||
// LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RClickableArea::activate()
|
||||
@ -1054,13 +1057,21 @@ void RClickableArea::clickRight(boost::logic::tribool down)
|
||||
//{
|
||||
// LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void LRClickableAreaWText::clickLeft(boost::logic::tribool down)
|
||||
{
|
||||
if(!down)
|
||||
{
|
||||
#ifndef __amigaos4__
|
||||
LOCPLINT->showInfoDialog(text, std::vector<SComponent*>());
|
||||
#else
|
||||
#warning error here!
|
||||
#endif
|
||||
}
|
||||
}
|
||||
void LRClickableAreaWText::clickRight(boost::logic::tribool down)
|
||||
@ -1104,7 +1115,11 @@ void LRClickableAreaWTextComp::clickLeft(boost::logic::tribool down)
|
||||
{
|
||||
if((!down) && pressedL)
|
||||
{
|
||||
#ifndef __amigaos4__
|
||||
LOCPLINT->showInfoDialog(text, std::vector<SComponent*>(1, new SComponent(SComponent::Etype(baseType), type, bonus)));
|
||||
#else
|
||||
#warning error here!
|
||||
#endif
|
||||
}
|
||||
ClickableL::clickLeft(down);
|
||||
}
|
||||
|
@ -135,5 +135,5 @@ public:
|
||||
|
||||
//friends
|
||||
friend void CArtPlace::clickLeft(tribool down);
|
||||
friend CPlayerInterface;
|
||||
friend class CPlayerInterface;
|
||||
};
|
||||
|
77
CLua.cpp
77
CLua.cpp
@ -32,7 +32,7 @@ bool getGlobalFunc(lua_State * L, std::string fname)
|
||||
|
||||
CObjectScript::CObjectScript()
|
||||
{
|
||||
language = ESLan::UNDEF;
|
||||
language = UNDEF;
|
||||
//std::cout << "Tworze obiekt objectscript "<<this<<std::endl;
|
||||
}
|
||||
|
||||
@ -77,6 +77,10 @@ void CLua::open(std::string initpath)
|
||||
// temp += initpath;
|
||||
// throw std::exception(temp.c_str());
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
void CLua::registerCLuaCallback()
|
||||
{
|
||||
@ -109,12 +113,16 @@ void CLua::findFS(std::string fname)
|
||||
// lua_settop(is, 0);
|
||||
// throw new std::exception((fname + ": function not defined").c_str()); // the call is not defined
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
#undef LST
|
||||
|
||||
CLuaObjectScript::CLuaObjectScript(std::string filename)
|
||||
{
|
||||
language = ESLan::LUA;
|
||||
language = LUA;
|
||||
open(filename);
|
||||
//binit = bnewobject = bonherovisit = brightext = false;
|
||||
//std::cout << "Tworze obiekt CLuaObjectScript "<<this<<std::endl;
|
||||
@ -145,6 +153,10 @@ void CLuaObjectScript::newObject(int objid)
|
||||
// throw new std::exception(("Failed to call "+genFN("newObject",os->ID)+" function in lua script.").c_str());
|
||||
//}
|
||||
//lua_settop(is, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
void CLuaObjectScript::onHeroVisit(int objid, int heroID)
|
||||
@ -158,6 +170,10 @@ void CLuaObjectScript::onHeroVisit(int objid, int heroID)
|
||||
// throw new std::exception(("Failed to call "+genFN("heroVisit",os->ID)+" function in lua script.").c_str());
|
||||
//}
|
||||
//lua_settop(is, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
//std::string CLuaObjectScript::hoverText(int objid)
|
||||
//{
|
||||
@ -276,6 +292,8 @@ void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited)
|
||||
//weko.push_back(new SComponent(SComponent::primskill,w,vvv));
|
||||
//cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&weko);
|
||||
//break;
|
||||
|
||||
|
||||
}
|
||||
case 100:
|
||||
{
|
||||
@ -284,6 +302,8 @@ void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited)
|
||||
//weko.push_back(new SComponent(SComponent::experience,0,vvv));
|
||||
//cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&weko);
|
||||
//break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -308,6 +328,46 @@ std::vector<int> CVisitableOPH::yourObjects()
|
||||
void CVisitableOPW::onNAHeroVisit(int objid, int heroID, bool alreadyVisited)
|
||||
{
|
||||
DEFOS;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int mid;
|
||||
switch (os->ID)
|
||||
{
|
||||
@ -450,6 +510,15 @@ void CMines::onHeroVisit(int objid, int heroID)
|
||||
iw.player = h->tempOwner;
|
||||
iw.components.push_back(Component(2,os->subID,vv,-1));
|
||||
cb->showInfoDialog(&iw);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
std::vector<int> CMines::yourObjects()
|
||||
{
|
||||
@ -595,6 +664,10 @@ void CPickable::chosen(int which)
|
||||
//for (int i=0;i<tempStore.size();i++)
|
||||
// delete tempStore[i];
|
||||
//tempStore.clear();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::vector<int> CPickable::yourObjects() //returns IDs of objects which are handled by script
|
||||
|
5
CLua.h
5
CLua.h
@ -1,6 +1,11 @@
|
||||
#pragma once
|
||||
#include "global.h"
|
||||
//#include "lstate.h"
|
||||
|
||||
#ifndef _MSC_VER
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
class CLua;
|
||||
|
@ -1,8 +1,17 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifndef _MSC_VER
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#ifndef _MSC_VER
|
||||
}
|
||||
#endif
|
||||
|
||||
//#include <luabind/luabind.hpp>
|
||||
//#include <luabind/function.hpp>
|
||||
//#include <luabind/class.hpp>
|
||||
@ -38,6 +47,30 @@ void CLuaHandler::test()
|
||||
// }
|
||||
//}
|
||||
//lua_close (lua);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
23
CMT.cpp
23
CMT.cpp
@ -17,7 +17,6 @@
|
||||
#include "CPreGame.h"
|
||||
#include "CConsoleHandler.h"
|
||||
#include "CCursorHandler.h"
|
||||
#include "CScreenHandler.h"
|
||||
#include "CPathfinder.h"
|
||||
#include "CGameState.h"
|
||||
#include "CCallback.h"
|
||||
@ -44,12 +43,9 @@ std::string NAME = NAME_VER + std::string(" (client)");
|
||||
DLL_EXPORT void initDLL(CLodHandler *b);
|
||||
SDL_Surface * screen, * screen2;
|
||||
extern SDL_Surface * CSDL_Ext::std32bppSurface;
|
||||
|
||||
std::queue<SDL_Event> events;
|
||||
boost::mutex eventsM;
|
||||
|
||||
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
|
||||
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
std::cout.flags(ios::unitbuf);
|
||||
@ -97,7 +93,6 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
cgi->bitmaph->init("Data\\H3bitmap.lod","Data");
|
||||
THC std::cout<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
|
||||
initDLL(cgi->bitmaph);
|
||||
|
||||
CGI->arth = VLC->arth;
|
||||
CGI->creh = VLC->creh;
|
||||
CGI->townh = VLC->townh;
|
||||
@ -105,9 +100,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
CGI->objh = VLC->objh;
|
||||
CGI->dobjinfo = VLC->dobjinfo;
|
||||
CGI->buildh = VLC->buildh;
|
||||
|
||||
THC std::cout<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
|
||||
|
||||
//cgi->curh->initCursor();
|
||||
//cgi->curh->showGraphicCursor();
|
||||
pomtime.getDif();
|
||||
@ -116,12 +109,10 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
//cgi->screenh = new CScreenHandler;
|
||||
//cgi->screenh->initScreen();
|
||||
THC std::cout<<"\tScreen handler: "<<pomtime.getDif()<<std::endl;
|
||||
|
||||
CAbilityHandler * abilh = new CAbilityHandler;
|
||||
abilh->loadAbilities();
|
||||
cgi->abilh = abilh;
|
||||
THC std::cout<<"\tAbility handler: "<<pomtime.getDif()<<std::endl;
|
||||
|
||||
THC std::cout<<"Preparing first handlers: "<<tmh.getDif()<<std::endl;
|
||||
pomtime.getDif();
|
||||
graphics = new Graphics();
|
||||
@ -142,31 +133,23 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
cpg->mush = mush;
|
||||
StartInfo *options = new StartInfo(cpg->runLoop());
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boost::thread servthr(boost::bind(system,"VCMI_server.exe > server_log.txt")); //runs server executable;
|
||||
//TODO: will it work on non-windows platforms?
|
||||
THC tmh.getDif();pomtime.getDif();//reset timers
|
||||
|
||||
|
||||
CSpellHandler * spellh = new CSpellHandler;
|
||||
spellh->loadSpells();
|
||||
cgi->spellh = spellh;
|
||||
THC std::cout<<"\tSpell handler: "<<pomtime.getDif()<<std::endl;
|
||||
|
||||
|
||||
cgi->pathf = new CPathfinder();
|
||||
THC std::cout<<"\tPathfinder: "<<pomtime.getDif()<<std::endl;
|
||||
cgi->consoleh->runConsole();
|
||||
THC std::cout<<"\tCallback and console: "<<pomtime.getDif()<<std::endl;
|
||||
THC std::cout<<"Handlers initialization (together): "<<tmh.getDif()<<std::endl;
|
||||
|
||||
std::ofstream lll("client_log.txt");
|
||||
CConnection c("localhost","3030",NAME,lll);
|
||||
THC std::cout<<"\tConnecting to the server: "<<tmh.getDif()<<std::endl;
|
||||
|
||||
CClient cl(&c,options);
|
||||
boost::thread t(boost::bind(&CClient::run,&cl));
|
||||
|
||||
SDL_Event ev;
|
||||
while(1) //main SDL events loop
|
||||
{
|
||||
@ -180,7 +163,6 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
events.push(ev);
|
||||
eventsM.unlock();
|
||||
}
|
||||
|
||||
///claculating FoWs for minimap
|
||||
/****************************Minimaps' FoW******************************************/
|
||||
//for(int g=0; g<cgi->playerint.size(); ++g)
|
||||
@ -188,20 +170,16 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
// if(!cgi->playerint[g]->human)
|
||||
// continue;
|
||||
// CMinimap & mm = ((CPlayerInterface*)cgi->playerint[g])->adventureInt->minimap;
|
||||
|
||||
// int mw = mm.map[0]->w, mh = mm.map[0]->h,
|
||||
// wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
|
||||
|
||||
// for(int d=0; d<cgi->mh->map->twoLevel+1; ++d)
|
||||
// {
|
||||
// SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface);
|
||||
|
||||
// for (int i=0; i<mw; i++)
|
||||
// {
|
||||
// for (int j=0; j<mh; j++)
|
||||
// {
|
||||
// int3 pp( ((i*CGI->mh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d );
|
||||
|
||||
// if ( !((CPlayerInterface*)cgi->playerint[g])->cb->isVisible(pp) )
|
||||
// {
|
||||
// CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0);
|
||||
@ -211,7 +189,6 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
// CSDL_Ext::update(pt);
|
||||
// mm.FoW.push_back(pt);
|
||||
// }
|
||||
|
||||
//}
|
||||
}
|
||||
else
|
||||
|
28
CMessage.cpp
28
CMessage.cpp
@ -1,6 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "CMessage.h"
|
||||
#include "SDL_TTF.h"
|
||||
#include "SDL_ttf.h"
|
||||
#include "hch/CDefHandler.h"
|
||||
#include "CGameInfo.h"
|
||||
#include "SDL_Extensions.h"
|
||||
@ -269,7 +269,7 @@ SDL_Surface * CMessage::blitCompsOnSur(std::vector<SComponent*> & comps, int max
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * or, std::vector< std::vector<CSelectableComponent*> > * komp, int inter, int &curh, SDL_Surface *ret)
|
||||
SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * _or, std::vector< std::vector<CSelectableComponent*> > * komp, int inter, int &curh, SDL_Surface *ret)
|
||||
{
|
||||
for (int i=0;i<komp->size();i++)
|
||||
{
|
||||
@ -280,7 +280,7 @@ SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * or, std::vector< std::vector
|
||||
if(maxh<(*komp)[i][j]->getImg()->h)
|
||||
maxh=(*komp)[i][j]->getImg()->h;
|
||||
}
|
||||
totalw += (inter*2+or->w) * ((*komp)[i].size() - 1);
|
||||
totalw += (inter*2+_or->w) * ((*komp)[i].size() - 1);
|
||||
curh+=maxh/2;
|
||||
int curw = (ret->w/2)-(totalw/2);
|
||||
for(int j=0;j<(*komp)[i].size();j++)
|
||||
@ -293,8 +293,8 @@ SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * or, std::vector< std::vector
|
||||
if(j<((*komp)[i].size()-1))
|
||||
{
|
||||
curw+=inter;
|
||||
blitAt(or,curw,curh-(or->h/2),ret);
|
||||
curw+=or->w;
|
||||
blitAt(_or,curw,curh-(_or->h/2),ret);
|
||||
curw+=_or->w;
|
||||
curw+=inter;
|
||||
}
|
||||
}
|
||||
@ -406,21 +406,21 @@ CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline
|
||||
curh+=ret->okb.imgs[0][0]->h;
|
||||
return ret;
|
||||
}
|
||||
std::vector< std::vector<CSelectableComponent*> > * CMessage::breakComps(std::vector<CSelectableComponent*> & comps,int maxw, SDL_Surface* or)
|
||||
std::vector< std::vector<CSelectableComponent*> > * CMessage::breakComps(std::vector<CSelectableComponent*> & comps,int maxw, SDL_Surface* _or)
|
||||
{
|
||||
std::vector< std::vector<CSelectableComponent*> > * ret = new std::vector< std::vector<CSelectableComponent*> >();
|
||||
ret->resize(1);
|
||||
bool wywalicOr=false;
|
||||
if (!or)
|
||||
if (!_or)
|
||||
{
|
||||
or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
|
||||
_or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
|
||||
wywalicOr=true;
|
||||
}
|
||||
int rvi = 0;
|
||||
int curw = 0;
|
||||
for(int i=0;i<comps.size();i++)
|
||||
{
|
||||
curw += (comps[i]->getImg()->w + 12 + or->w);
|
||||
curw += (comps[i]->getImg()->w + 12 + _or->w);
|
||||
if (curw > maxw)
|
||||
{
|
||||
curw = 0;
|
||||
@ -431,7 +431,7 @@ std::vector< std::vector<CSelectableComponent*> > * CMessage::breakComps(std::ve
|
||||
}
|
||||
if (wywalicOr)
|
||||
{
|
||||
SDL_FreeSurface(or);
|
||||
SDL_FreeSurface(_or);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -474,8 +474,8 @@ CSelWindow * CMessage::genSelWindow(std::string text, int player, int charperlin
|
||||
std::pair<int,int> txts = getMaxSizes(txtg);
|
||||
txts.first+=45; //side margins
|
||||
int curh = 50; //top margin
|
||||
SDL_Surface * or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
|
||||
std::vector< std::vector<CSelectableComponent*> > * komp = breakComps(comps,500,or);
|
||||
SDL_Surface * _or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
|
||||
std::vector< std::vector<CSelectableComponent*> > * komp = breakComps(comps,500,_or);
|
||||
std::pair<int,int> txts2 = getMaxSizes(komp);
|
||||
ret->pos.h = txts.second //wys. tekstu
|
||||
+ txts2.second //wys komponentow
|
||||
@ -489,13 +489,13 @@ CSelWindow * CMessage::genSelWindow(std::string text, int player, int charperlin
|
||||
ret->bitmap = drawBox1(ret->pos.w,ret->pos.h,player);
|
||||
blitTextOnSur(txtg,curh,ret->bitmap);
|
||||
curh += 50;
|
||||
blitCompsOnSur(or,komp,10,curh,ret->bitmap);
|
||||
blitCompsOnSur(_or,komp,10,curh,ret->bitmap);
|
||||
curh += 30; //to buttton
|
||||
ret->okb.posr.x = (ret->bitmap->w/2) - (ret->okb.imgs[0][0]->w/2);
|
||||
ret->okb.posr.y = curh;
|
||||
ret->okb.show();
|
||||
curh+=ret->okb.imgs[0][0]->h;
|
||||
SDL_FreeSurface(or);
|
||||
SDL_FreeSurface(_or);
|
||||
delete komp;
|
||||
delete tekst;
|
||||
return ret;
|
||||
|
10
CMessage.h
10
CMessage.h
@ -2,8 +2,10 @@
|
||||
#define CMESSAGE_H
|
||||
|
||||
#include "global.h"
|
||||
#include "SDL_TTF.h"
|
||||
#include <SDL_ttf.h>
|
||||
#include "SDL.h"
|
||||
#include "CPreGame.h"
|
||||
|
||||
enum EWindowType {infoOnly, infoOK, yesOrNO};
|
||||
class CPreGame;
|
||||
class MapSel;
|
||||
@ -29,9 +31,9 @@ public:
|
||||
static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext);
|
||||
static SDL_Surface * blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret);
|
||||
static SDL_Surface * blitCompsOnSur(std::vector<SComponent*> & comps, int maxw, int inter, int & curh, SDL_Surface * ret);
|
||||
static SDL_Surface* blitCompsOnSur(SDL_Surface * or, std::vector< std::vector<CSelectableComponent*> > * komp, int inter, int &curh, SDL_Surface *ret);
|
||||
static CInfoWindow * genIWindow(std::string text, int player, int charperline, std::vector<SComponent*> & comps);
|
||||
static std::vector< std::vector<CSelectableComponent*> > * breakComps(std::vector<CSelectableComponent*> & comps,int maxw, SDL_Surface* or=NULL);
|
||||
static SDL_Surface * blitCompsOnSur(SDL_Surface *_or, std::vector< std::vector<CSelectableComponent*> > *komp, int inter, int &curh, SDL_Surface *ret);
|
||||
static CInfoWindow * genIWindow(std::string text, int player, int charperline, std::vector<SComponent*> &comps);
|
||||
static std::vector< std::vector<CSelectableComponent*> > * breakComps(std::vector<CSelectableComponent*> &comps, int maxw, SDL_Surface* _or=NULL);
|
||||
static CSelWindow * genSelWindow(std::string text, int player, int charperline, std::vector<CSelectableComponent*> & comps, int owner);
|
||||
static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins
|
||||
static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,
|
||||
|
@ -35,14 +35,14 @@ vector<Coordinate>* CPathfinder::GetPath(const CGHeroInstance* hero)
|
||||
Hero = hero;
|
||||
|
||||
//Reset the queues
|
||||
Open = priority_queue < vector<Coordinate>, vector<vector<Coordinate>>, Compare>();
|
||||
Open = priority_queue < vector<Coordinate>, vector<vector<Coordinate> >, Compare>();
|
||||
Closed.clear();
|
||||
|
||||
//Determine if the hero can move on water
|
||||
int3 hpos = Hero->getPosition(false);
|
||||
if (!Hero->canWalkOnSea())
|
||||
{
|
||||
if (CGI->mh->ttiles[hpos.x][hpos.y][hpos.z].tileInfo->tertype==EterrainType::water)
|
||||
if (CGI->mh->ttiles[hpos.x][hpos.y][hpos.z].tileInfo->tertype==water)
|
||||
blockLandSea=false;
|
||||
else
|
||||
blockLandSea=true;
|
||||
@ -193,10 +193,10 @@ void CPathfinder::CalcH(Coordinate* node)
|
||||
* => Impossible to move there.
|
||||
*/
|
||||
if( (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->blocked && !(node->x==End.x && node->y==End.y && CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->visitable)) ||
|
||||
(CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==EterrainType::rock) ||
|
||||
((blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==EterrainType::water)) ||
|
||||
(CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==rock) ||
|
||||
((blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==water)) ||
|
||||
(!CGI->state->players[Hero->tempOwner].fogOfWarMap[node->x][node->y][node->z]) ||
|
||||
((!blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype!=EterrainType::water)))
|
||||
((!blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype!=water)))
|
||||
{
|
||||
//Impossible.
|
||||
|
||||
|
@ -84,7 +84,7 @@ private:
|
||||
|
||||
public:
|
||||
//Contains nodes to be searched
|
||||
priority_queue < vector<Coordinate>, vector<vector<Coordinate>>, Compare> Open;
|
||||
priority_queue < vector<Coordinate>, vector<vector<Coordinate> >, Compare > Open;
|
||||
|
||||
//History of nodes you have been to before
|
||||
vector<Coordinate> Closed;
|
||||
|
@ -239,7 +239,7 @@ void CGarrisonSlot::show()
|
||||
if(creature)
|
||||
{
|
||||
char* buf = new char[15];
|
||||
itoa(count,buf,10);
|
||||
SDL_itoa(count,buf,10);
|
||||
blitAt(graphics->bigImgs[creature->idNumber],pos);
|
||||
printTo(buf,pos.x+56,pos.y+62,GEOR16,zwykly);
|
||||
if(owner->highlighted==this)
|
||||
@ -772,16 +772,16 @@ template <typename T> void CSCButton<T>::clickLeft (tribool down)
|
||||
if (delg)
|
||||
(delg->*func)(down);
|
||||
}
|
||||
template <typename T> void CSCButton<typename T>::activate()
|
||||
template <typename T> void CSCButton<T>::activate()
|
||||
{
|
||||
ClickableL::activate();
|
||||
}
|
||||
template <typename T> void CSCButton<typename T>::deactivate()
|
||||
template <typename T> void CSCButton<T>::deactivate()
|
||||
{
|
||||
ClickableL::deactivate();
|
||||
}
|
||||
|
||||
template <typename T> void CSCButton<typename T>::show(SDL_Surface * to)
|
||||
template <typename T> void CSCButton<T>::show(SDL_Surface * to)
|
||||
{
|
||||
if (delg) //we blit on our owner's bitmap
|
||||
{
|
||||
@ -1082,7 +1082,7 @@ void CPlayerInterface::yourTurn()
|
||||
cb->endTurn();
|
||||
}
|
||||
|
||||
inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
|
||||
inline void subRect(const int & x, const int & y, const int & z, const SDL_Rect & r, const int & hid)
|
||||
{
|
||||
TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
|
||||
for(int h=0; h<hlp.objects.size(); ++h)
|
||||
@ -2007,6 +2007,7 @@ BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn
|
||||
BattleAction ret = *(dynamic_cast<CBattleInterface*>(curint)->givenCommand);
|
||||
delete dynamic_cast<CBattleInterface*>(curint)->givenCommand;
|
||||
dynamic_cast<CBattleInterface*>(curint)->givenCommand = NULL;
|
||||
dynamic_cast<CBattleInterface*>(curint)->myTurn = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2029,14 +2030,19 @@ void CPlayerInterface::battleStackAttacking(int ID, int dest)
|
||||
dynamic_cast<CBattleInterface*>(curint)->stackAttacking(ID, dest);
|
||||
}
|
||||
|
||||
void CPlayerInterface::battleStackIsAttacked(int ID, int dmg, int killed, int IDby)
|
||||
void CPlayerInterface::battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting)
|
||||
{
|
||||
dynamic_cast<CBattleInterface*>(curint)->stackIsAttacked(ID, dmg, killed, IDby);
|
||||
dynamic_cast<CBattleInterface*>(curint)->stackIsAttacked(ID, dmg, killed, IDby, byShooting);
|
||||
}
|
||||
|
||||
void CPlayerInterface::battleStackKilled(int ID, int dmg, int killed, int IDby)
|
||||
void CPlayerInterface::battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting)
|
||||
{
|
||||
dynamic_cast<CBattleInterface*>(curint)->stackKilled(ID, dmg, killed, IDby);
|
||||
dynamic_cast<CBattleInterface*>(curint)->stackKilled(ID, dmg, killed, IDby, byShooting);
|
||||
}
|
||||
|
||||
void CPlayerInterface::battleStackIsShooting(int ID, int dest)
|
||||
{
|
||||
dynamic_cast<CBattleInterface*>(curint)->stackIsShooting(ID, dest);
|
||||
}
|
||||
|
||||
void CPlayerInterface::showComp(SComponent comp)
|
||||
@ -2398,7 +2404,7 @@ void CHeroList::draw()
|
||||
if (pom>25) pom=25;
|
||||
if (pom<0) pom=0;
|
||||
blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana
|
||||
SDL_Surface * temp = graphics->portraitSmall[LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->subID];
|
||||
SDL_Surface * temp = graphics->portraitSmall[LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->portrait];
|
||||
blitAt(temp,posporx,pospory+i*32);
|
||||
if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
|
||||
{
|
||||
@ -2735,9 +2741,9 @@ void CRecrutationWindow::show(SDL_Surface * to)
|
||||
cancel->show();
|
||||
slider->show();
|
||||
char pom[15];
|
||||
itoa(creatures[which].amount,pom,10); //available
|
||||
SDL_itoa(creatures[which].amount,pom,10); //available
|
||||
printAtMiddle(pom,pos.x+205,pos.y+252,GEOR13,zwykly,screen);
|
||||
itoa(slider->value,pom,10); //recruit
|
||||
SDL_itoa(slider->value,pom,10); //recruit
|
||||
printAtMiddle(pom,pos.x+279,pos.y+252,GEOR13,zwykly,screen);
|
||||
printAtMiddle(CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures[creatures[which].ID].namePl,pos.x+243,pos.y+32,GEOR16,tytulowy,screen); //eg "Recruit Dragon flies"
|
||||
int curx = pos.x+115-creatures[which].res.size()*16;
|
||||
@ -2745,9 +2751,9 @@ void CRecrutationWindow::show(SDL_Surface * to)
|
||||
{
|
||||
blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx,pos.y+243,screen);
|
||||
blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx+258,pos.y+243,screen);
|
||||
itoa(creatures[which].res[i].second,pom,10);
|
||||
SDL_itoa(creatures[which].res[i].second,pom,10);
|
||||
printAtMiddle(pom,curx+12,pos.y+286,GEOR13,zwykly,screen);
|
||||
itoa(creatures[which].res[i].second * slider->value,pom,10);
|
||||
SDL_itoa(creatures[which].res[i].second * slider->value,pom,10);
|
||||
printAtMiddle(pom,curx+12+258,pos.y+286,GEOR13,zwykly,screen);
|
||||
curx+=32;
|
||||
}
|
||||
@ -2908,9 +2914,9 @@ void CSplitWindow::show(SDL_Surface * to)
|
||||
ok->show();
|
||||
cancel->show();
|
||||
slider->show();
|
||||
itoa(a1,pom,10);
|
||||
SDL_itoa(a1,pom,10);
|
||||
printAtMiddle(pom,pos.x+70,pos.y+237,GEOR16,zwykly,screen);
|
||||
itoa(a2,pom,10);
|
||||
SDL_itoa(a2,pom,10);
|
||||
printAtMiddle(pom,pos.x+233,pos.y+237,GEOR16,zwykly,screen);
|
||||
anim->blitPic(screen,pos.x+20,pos.y+54,false);
|
||||
anim->blitPic(screen,pos.x+177,pos.y+54,false);
|
||||
@ -2954,12 +2960,12 @@ CCreInfoWindow::CCreInfoWindow
|
||||
|
||||
//atttack
|
||||
printAt(CGI->preth->zelp[435].first,155,48,GEOR13,zwykly,bitmap);
|
||||
itoa(c->attack,pom,10);
|
||||
SDL_itoa(c->attack,pom,10);
|
||||
if(State && State->attackBonus)
|
||||
{
|
||||
int hlp = log10f(c->attack)+2;
|
||||
pom[hlp-1] = ' '; pom[hlp] = '(';
|
||||
itoa(c->attack+State->attackBonus,pom+hlp+1,10);
|
||||
SDL_itoa(c->attack+State->attackBonus,pom+hlp+1,10);
|
||||
hlp += 2+(int)log10f(State->attackBonus+c->attack);
|
||||
pom[hlp] = ')'; pom[hlp+1] = '\0';
|
||||
}
|
||||
@ -2967,12 +2973,12 @@ CCreInfoWindow::CCreInfoWindow
|
||||
|
||||
//defense
|
||||
printAt(CGI->preth->zelp[436].first,155,67,GEOR13,zwykly,bitmap);
|
||||
itoa(c->defence,pom,10);
|
||||
SDL_itoa(c->defence,pom,10);
|
||||
if(State && State->defenseBonus)
|
||||
{
|
||||
int hlp = log10f(c->defence)+2;
|
||||
pom[hlp-1] = ' '; pom[hlp] = '(';
|
||||
itoa(c->defence+State->defenseBonus,pom+hlp+1,10);
|
||||
SDL_itoa(c->defence+State->defenseBonus,pom+hlp+1,10);
|
||||
pom[hlp+2+(int)log10f(State->defenseBonus+c->defence)] = ')';
|
||||
}
|
||||
printToWR(pom,276,80,GEOR13,zwykly,bitmap);
|
||||
@ -2981,21 +2987,21 @@ CCreInfoWindow::CCreInfoWindow
|
||||
if(c->shots)
|
||||
{
|
||||
printAt(CGI->generaltexth->allTexts[198],155,86,GEOR13,zwykly,bitmap);
|
||||
itoa(c->shots,pom,10);
|
||||
SDL_itoa(c->shots,pom,10);
|
||||
printToWR(pom,276,99,GEOR13,zwykly,bitmap);
|
||||
}
|
||||
|
||||
//damage
|
||||
printAt(CGI->generaltexth->allTexts[199],155,105,GEOR13,zwykly,bitmap);
|
||||
itoa(c->damageMin,pom,10);
|
||||
SDL_itoa(c->damageMin,pom,10);
|
||||
hlp=log10f(c->damageMin)+2;
|
||||
pom[hlp-1]=' '; pom[hlp]='-'; pom[hlp+1]=' ';
|
||||
itoa(c->damageMax,pom+hlp+2,10);
|
||||
SDL_itoa(c->damageMax,pom+hlp+2,10);
|
||||
printToWR(pom,276,118,GEOR13,zwykly,bitmap);
|
||||
|
||||
//health
|
||||
printAt(CGI->preth->zelp[439].first,155,124,GEOR13,zwykly,bitmap);
|
||||
itoa(c->hitPoints,pom,10);
|
||||
SDL_itoa(c->hitPoints,pom,10);
|
||||
printToWR(pom,276,137,GEOR13,zwykly,bitmap);
|
||||
|
||||
//remaining health - TODO: show during the battles
|
||||
@ -3003,7 +3009,7 @@ CCreInfoWindow::CCreInfoWindow
|
||||
|
||||
//speed
|
||||
printAt(CGI->preth->zelp[441].first,155,162,GEOR13,zwykly,bitmap);
|
||||
itoa(c->speed,pom,10);
|
||||
SDL_itoa(c->speed,pom,10);
|
||||
printToWR(pom,276,175,GEOR13,zwykly,bitmap);
|
||||
|
||||
|
||||
|
@ -342,8 +342,9 @@ public:
|
||||
void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner);
|
||||
void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving);
|
||||
void battleStackAttacking(int ID, int dest);
|
||||
void battleStackIsAttacked(int ID, int dmg, int killed, int IDby);
|
||||
void battleStackKilled(int ID, int dmg, int killed, int IDby);
|
||||
void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting);
|
||||
void battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting);
|
||||
void battleStackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest
|
||||
|
||||
|
||||
//-------------//
|
||||
|
BIN
CPreGame.cpp
BIN
CPreGame.cpp
Binary file not shown.
15
CPreGame.h
15
CPreGame.h
@ -9,6 +9,7 @@
|
||||
#include "map.h"
|
||||
#include "hch/CMusicHandler.h"
|
||||
class CPreGame;
|
||||
class CDefHandler;
|
||||
extern CPreGame * CPG;
|
||||
|
||||
typedef void(CPreGame::*ttt)();
|
||||
@ -47,7 +48,7 @@ template <class T=ttt> struct SetrButton: public Button<T>
|
||||
{
|
||||
int key, * poin;
|
||||
virtual void press(bool down=true);
|
||||
SetrButton(){type=1;selectable=selected=false;state=0;highlightable=false;}
|
||||
SetrButton(){int type=1;bool selectable=false;bool selected=false;int state=0;bool highlightable=false;}
|
||||
};
|
||||
template<class T=CPreGame> class Slider
|
||||
{ //
|
||||
@ -78,7 +79,7 @@ template<class T=ttt> struct IntBut: public Button<T>
|
||||
public:
|
||||
int key;
|
||||
int * what;
|
||||
IntBut(){type=2;fun=NULL;highlightable=false;};
|
||||
IntBut(){int type=2;int fun=NULL;bool highlightable=false;};
|
||||
void set(){*what=key;};
|
||||
};
|
||||
template<class T=ttt> struct IntSelBut: public Button<T>
|
||||
@ -88,8 +89,14 @@ public:
|
||||
int key;
|
||||
IntSelBut(){};
|
||||
IntSelBut( SDL_Rect Pos, T Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup<T>* gr=NULL, int My=-1)
|
||||
: Button(Pos,Fun,Imgs,Sel,gr),key(My){ourPoinGroup=gr;};
|
||||
void select(bool on=true) {(*this).Button::select(on);ourPoinGroup->setYour(this);CPG->printRating();}
|
||||
: Button<T>(Pos,Fun,Imgs,Sel,gr),key(My){ourPoinGroup=gr;};
|
||||
void select(bool on=true) {(*this).Button<T>::select(on);ourPoinGroup->setYour(this);
|
||||
#if !defined(__amigaos4__) && !defined(__unix__)
|
||||
CPG->printRating();
|
||||
#else
|
||||
#warning not compile here
|
||||
#endif
|
||||
}
|
||||
};
|
||||
template <class T> class CPoinGroup :public CGroup<T>
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "SDL_Extensions.h"
|
||||
#include "SDL_TTF.h"
|
||||
#include "SDL_ttf.h"
|
||||
#include "CGameInfo.h"
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
@ -234,34 +234,38 @@ void CSDL_Ext::printToWR(std::string text, int x, int y, TTF_Font * font, SDL_Co
|
||||
void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A)
|
||||
{
|
||||
Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC;
|
||||
/*
|
||||
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
p[0] = R;
|
||||
p[1] = G;
|
||||
p[2] = B;
|
||||
#else
|
||||
*/
|
||||
p[0] = B;
|
||||
p[1] = G;
|
||||
p[2] = R;
|
||||
if(ekran->format->BytesPerPixel==4)
|
||||
p[3] = A;
|
||||
#endif
|
||||
//#endif
|
||||
SDL_UpdateRect(ekran, x, y, 1, 1);
|
||||
}
|
||||
|
||||
void CSDL_Ext::SDL_PutPixelWithoutRefresh(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A)
|
||||
{
|
||||
Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC;
|
||||
/*
|
||||
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
p[0] = B;
|
||||
p[1] = G;
|
||||
p[2] = R;
|
||||
#else
|
||||
*/
|
||||
p[0] = R;
|
||||
p[1] = G;
|
||||
p[2] = B;
|
||||
if(ekran->format->BytesPerPixel==4)
|
||||
p[3] = A;
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
///**************/
|
||||
@ -279,11 +283,14 @@ SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot, int myC)
|
||||
{
|
||||
{
|
||||
Uint8 *p = (Uint8 *)toRot->pixels + j * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel;
|
||||
/*
|
||||
|
||||
#if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], myC);
|
||||
#else
|
||||
*/
|
||||
CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], myC);
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -316,11 +323,13 @@ SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot)
|
||||
{
|
||||
Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j -1) * toRot->pitch + i * toRot->format->BytesPerPixel;
|
||||
//int k=2;
|
||||
/*
|
||||
#if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2]);
|
||||
#else
|
||||
*/
|
||||
CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0]);
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -354,11 +363,13 @@ SDL_Surface * CSDL_Ext::rotate02(SDL_Surface * toRot)
|
||||
{
|
||||
{
|
||||
Uint8 *p = (Uint8 *)toRot->pixels + i * toRot->pitch + j * toRot->format->BytesPerPixel;
|
||||
/*
|
||||
#if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
SDL_PutPixel(ret, i, j, p[0], p[1], p[2]);
|
||||
#else
|
||||
*/
|
||||
SDL_PutPixel(ret, i, j, p[2], p[1], p[0]);
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -380,11 +391,13 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot)
|
||||
{
|
||||
{
|
||||
Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j - 1) * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel+2;
|
||||
/*
|
||||
#if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
SDL_PutPixel(ret, i, j, p[0], p[1], p[2], 2);
|
||||
#else
|
||||
*/
|
||||
SDL_PutPixel(ret, i, j, p[2], p[1], p[0], 2);
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -421,11 +434,13 @@ Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y
|
||||
return *(Uint16 *)p;
|
||||
|
||||
case 3:
|
||||
/*
|
||||
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
return p[0] << 16 | p[1] << 8 | p[2];
|
||||
#else
|
||||
*/
|
||||
return p[0] | p[1] << 8 | p[2] << 16;
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
case 4:
|
||||
return *(Uint32 *)p;
|
||||
|
@ -42,7 +42,11 @@ struct StartInfo
|
||||
for(unsigned int i=0; i<playerInfos.size(); ++i)
|
||||
if(playerInfos[i].color == no)
|
||||
return playerInfos[i];
|
||||
#ifndef __GNUC__
|
||||
throw new std::exception("Cannot find info about player");
|
||||
#else
|
||||
throw new std::exception();
|
||||
#endif
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
|
@ -201,9 +201,15 @@ SDL_Surface * CPCXConv::getSurface()
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
int bmask = 0xff0000;
|
||||
int gmask = 0x00ff00;
|
||||
int rmask = 0x0000ff;
|
||||
#else
|
||||
int bmask = 0x0000ff;
|
||||
int gmask = 0x00ff00;
|
||||
int rmask = 0xff0000;
|
||||
#endif
|
||||
ret = SDL_CreateRGBSurface(SDL_SWSURFACE, bh.x+add, bh.y, 24, rmask, gmask, bmask, 0);
|
||||
}
|
||||
if (format==PCX8B)
|
||||
@ -212,9 +218,15 @@ SDL_Surface * CPCXConv::getSurface()
|
||||
for (int i=0;i<256;i++)
|
||||
{
|
||||
SDL_Color tp;
|
||||
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
tp.b = pcx[it++];
|
||||
tp.g = pcx[it++];
|
||||
tp.r = pcx[it++];
|
||||
#else
|
||||
tp.r = pcx[it++];
|
||||
tp.g = pcx[it++];
|
||||
tp.b = pcx[it++];
|
||||
#endif
|
||||
tp.unused = 0;
|
||||
*(ret->format->palette->colors+i) = tp;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh)
|
||||
itoa((*i).second.second,buf,10);
|
||||
printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
|
||||
}
|
||||
blitAt(graphics->portraitLarge[curh->subID],11,12,ret);
|
||||
blitAt(graphics->portraitLarge[curh->portrait],11,12,ret);
|
||||
itoa(curh->mana,buf,10);
|
||||
printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
|
||||
delete[] buf;
|
||||
@ -205,7 +205,9 @@ Graphics::Graphics()
|
||||
void Graphics::loadHeroPortraits()
|
||||
{
|
||||
std::ifstream of("config/portrety.txt");
|
||||
for (int j=0;j<HEROES_QUANTITY;j++)
|
||||
int numberOfPortraits;
|
||||
of>>numberOfPortraits;
|
||||
for (int j=0; j<numberOfPortraits; j++)
|
||||
{
|
||||
int ID;
|
||||
of>>ID;
|
||||
|
40
config/cr_shots.txt
Normal file
40
config/cr_shots.txt
Normal file
@ -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
|
@ -1,3 +1,4 @@
|
||||
163
|
||||
0 HPS000KN.bmp
|
||||
1 HPS001KN.bmp
|
||||
2 HPS002KN.bmp
|
||||
@ -154,3 +155,10 @@
|
||||
153 HPS008SH.bmp
|
||||
154 HPS001SH.bmp
|
||||
155 HPS131DM.bmp
|
||||
156 HPS129MK.bmp
|
||||
157 HPS002SH.bmp
|
||||
158 HPS132Wl.bmp
|
||||
159 HPS133Nc.bmp
|
||||
160 HPS134Nc.bmp
|
||||
161 HPS135Wi.bmp
|
||||
162 HPS136Wi.bmp
|
9
global.h
9
global.h
@ -18,6 +18,15 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte)
|
||||
|
||||
#define NAME_VER ("VCMI \"Altanatse\" 0.7")
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PATHSEPARATOR "\\"
|
||||
#define DATA_DIR ""
|
||||
#else
|
||||
#define PATHSEPARATOR "/"
|
||||
#define DATA_DIR "/progdir/"
|
||||
#endif
|
||||
|
||||
enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors
|
||||
enum EterrainType {border=-1, dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock};
|
||||
enum Eriver {noRiver=0, clearRiver, icyRiver, muddyRiver, lavaRiver};
|
||||
|
@ -26,4 +26,4 @@ public:
|
||||
void loadAbilities();
|
||||
};
|
||||
|
||||
#endif CABILITYHANDLER_H
|
||||
#endif //CABILITYHANDLER_H
|
||||
|
@ -19,7 +19,11 @@ unsigned int readNr(std::string &in, unsigned int &it)
|
||||
if(in[last]=='\t' || in[last]=='\n' || in[last]==' ' || in[last]=='\r' || in[last]=='\n')
|
||||
break;
|
||||
if(last==in.size())
|
||||
#ifndef __GNUC__
|
||||
throw new std::exception("Cannot read number...");
|
||||
#else
|
||||
throw new std::exception();
|
||||
#endif
|
||||
std::stringstream ss(in.substr(it,last-it));
|
||||
it+=(1+last-it);
|
||||
ss >> last;
|
||||
|
@ -45,6 +45,10 @@ bool CCreature::isFlying()
|
||||
{
|
||||
return boost::algorithm::find_first(abilityRefs, "FLYING_ARMY");
|
||||
}
|
||||
bool CCreature::isShooting()
|
||||
{
|
||||
return boost::algorithm::find_first(abilityRefs, "SHOOTING_ARMY");
|
||||
}
|
||||
si32 CCreature::maxAmount(const std::vector<si32> &res) const //how many creatures can be bought
|
||||
{
|
||||
int ret = 2147483645;
|
||||
@ -378,7 +382,11 @@ void CCreatureHandler::loadCreatures()
|
||||
inp.read((char*)bufor, andame2); // read map file to buffer
|
||||
inp.close();
|
||||
buf = std::string(bufor);
|
||||
#ifndef __GNUC__
|
||||
delete [andame2] bufor;
|
||||
#else
|
||||
delete [] bufor;
|
||||
#endif
|
||||
|
||||
i = 0; //buf iterator
|
||||
hmcr = 0;
|
||||
@ -410,6 +418,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()
|
||||
|
@ -40,8 +40,8 @@ public:
|
||||
|
||||
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
|
||||
si32 maxAmount(const std::vector<si32> &res) const; //how many creatures can be bought
|
||||
|
||||
static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion
|
||||
};
|
||||
|
||||
@ -52,6 +52,8 @@ public:
|
||||
std::vector<CCreature> creatures; //creature ID -> creature info
|
||||
std::map<int,std::vector<CCreature*> > levelCreatures; //level -> list of creatures
|
||||
std::map<std::string,int> nameToID;
|
||||
std::map<int,std::string> idToProjectile;
|
||||
std::map<int,bool> idToProjectileSpin; //if true, appropriate projectile is spinning during flight
|
||||
void loadCreatures();
|
||||
void loadAnimationInfo();
|
||||
void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
|
||||
|
Binary file not shown.
@ -14,6 +14,7 @@ void CGeneralTextHandler::load()
|
||||
if(buf[i]=='\r')
|
||||
break;
|
||||
}
|
||||
|
||||
i+=2;
|
||||
for(int jj=0; jj<764; ++jj)
|
||||
{
|
||||
@ -22,8 +23,8 @@ void CGeneralTextHandler::load()
|
||||
allTexts.push_back(buflet);
|
||||
}
|
||||
|
||||
|
||||
std::string strs = CGI->bitmaph->getTextFile("ARRAYTXT.TXT");
|
||||
|
||||
int itr=0;
|
||||
while(itr<strs.length()-1)
|
||||
{
|
||||
|
@ -218,7 +218,7 @@ void CLodHandler::extract(std::string FName)
|
||||
for (int i=0;i<totalFiles;i++)
|
||||
{
|
||||
fseek(FLOD, entries[i].offset, 0);
|
||||
std::string bufff = (FName.substr(0, FName.size()-4) + "\\" + (char*)entries[i].name);
|
||||
std::string bufff = (DATA_DIR + FName.substr(0, FName.size()-4) + PATHSEPARATOR + (char*)entries[i].name);
|
||||
unsigned char * outp;
|
||||
if (entries[i].size==0) //file is not compressed
|
||||
{
|
||||
|
@ -12,53 +12,53 @@ void CMusicHandler::initMusics()
|
||||
}
|
||||
atexit(Mix_CloseAudio);
|
||||
|
||||
//AITheme0 = Mix_LoadMUS("MP3\\AITheme0.mp3");
|
||||
//AITheme1 = Mix_LoadMUS("MP3\\AITHEME1.mp3");
|
||||
//AITheme2 = Mix_LoadMUS("MP3\\AITHEME2.mp3");
|
||||
//buildTown = Mix_LoadWAV("MP3\\BUILDTWN.wav");
|
||||
//combat1 = Mix_LoadMUS("MP3\\COMBAT01.mp3");
|
||||
//combat2 = Mix_LoadMUS("MP3\\COMBAT02.mp3");
|
||||
//combat3 = Mix_LoadMUS("MP3\\COMBAT03.mp3");
|
||||
//combat4 = Mix_LoadMUS("MP3\\COMBAT04.mp3");
|
||||
//castleTown = Mix_LoadMUS("MP3\\CstleTown.mp3");
|
||||
//defendCastle = Mix_LoadMUS("MP3\\Defend Castle.mp3");
|
||||
//dirt = Mix_LoadMUS("MP3\\DIRT.mp3");
|
||||
//dungeon = Mix_LoadMUS("MP3\\DUNGEON.mp3");
|
||||
//elemTown = Mix_LoadMUS("MP3\\ElemTown.mp3");
|
||||
//evilTheme = Mix_LoadMUS("MP3\\EvilTheme.mp3");
|
||||
//fortressTown = Mix_LoadMUS("MP3\\FortressTown.mp3");
|
||||
//goodTheme = Mix_LoadMUS("MP3\\GoodTheme.mp3");
|
||||
//grass = Mix_LoadMUS("MP3\\GRASS.mp3");
|
||||
//infernoTown = Mix_LoadMUS("MP3\\InfernoTown.mp3");
|
||||
//lava = Mix_LoadMUS("MP3\\LAVA.mp3");
|
||||
//loopLepr = Mix_LoadMUS("MP3\\LoopLepr.mp3");
|
||||
//loseCampain = Mix_LoadMUS("MP3\\Lose Campain.mp3");
|
||||
//loseCastle = Mix_LoadMUS("MP3\\LoseCastle.mp3");
|
||||
//loseCombat = Mix_LoadMUS("MP3\\LoseCombat.mp3");
|
||||
//mainMenu = Mix_LoadMUS("MP3\\MAINMENU.mp3");
|
||||
//mainMenuWoG = Mix_LoadMUS("MP3\\MainMenuWoG.mp3");
|
||||
//necroTown = Mix_LoadMUS("MP3\\necroTown.mp3");
|
||||
//neutralTheme = Mix_LoadMUS("MP3\\NeutralTheme.mp3");
|
||||
//rampart = Mix_LoadMUS("MP3\\RAMPART.mp3");
|
||||
//retreatBattle = Mix_LoadMUS("MP3\\Retreat Battle.mp3");
|
||||
//rough = Mix_LoadMUS("MP3\\ROUGH.mp3");
|
||||
//sand = Mix_LoadMUS("MP3\\SAND.mp3");
|
||||
//secretTheme = Mix_LoadMUS("MP3\\SecretTheme.mp3");
|
||||
//snow = Mix_LoadMUS("MP3\\SNOW.mp3");
|
||||
//stronghold = Mix_LoadMUS("MP3\\StrongHold.mp3");
|
||||
//surrenderBattle = Mix_LoadMUS("MP3\\Surrender Battle.mp3");
|
||||
//swamp = Mix_LoadMUS("MP3\\SWAMP.mp3");
|
||||
//towerTown = Mix_LoadMUS("MP3\\TowerTown.mp3");
|
||||
//ultimateLose = Mix_LoadMUS("MP3\\UltimateLose.mp3");
|
||||
//underground = Mix_LoadMUS("MP3\\Underground.mp3");
|
||||
//water = Mix_LoadMUS("MP3\\WATER.mp3");
|
||||
//winBattle = Mix_LoadMUS("MP3\\Win Battle.mp3");
|
||||
//winScenario = Mix_LoadMUS("MP3\\Win Scenario.mp3");
|
||||
//AITheme0 = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "AITheme0.mp3");
|
||||
//AITheme1 = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "AITHEME1.mp3");
|
||||
//AITheme2 = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "AITHEME2.mp3");
|
||||
//buildTown = Mix_LoadWAV("MP3" PATHSEPARATOR "BUILDTWN.wav");
|
||||
//combat1 = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "COMBAT01.mp3");
|
||||
//combat2 = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "COMBAT02.mp3");
|
||||
//combat3 = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "COMBAT03.mp3");
|
||||
//combat4 = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "COMBAT04.mp3");
|
||||
//castleTown = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "CstleTown.mp3");
|
||||
//defendCastle = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "Defend Castle.mp3");
|
||||
//dirt = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "DIRT.mp3");
|
||||
//dungeon = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "DUNGEON.mp3");
|
||||
//elemTown = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "ElemTown.mp3");
|
||||
//evilTheme = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "EvilTheme.mp3");
|
||||
//fortressTown = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "FortressTown.mp3");
|
||||
//goodTheme = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "GoodTheme.mp3");
|
||||
//grass = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "GRASS.mp3");
|
||||
//infernoTown = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "InfernoTown.mp3");
|
||||
//lava = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "LAVA.mp3");
|
||||
//loopLepr = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "LoopLepr.mp3");
|
||||
//loseCampain = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "Lose Campain.mp3");
|
||||
//loseCastle = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "LoseCastle.mp3");
|
||||
//loseCombat = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "LoseCombat.mp3");
|
||||
//mainMenu = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "MAINMENU.mp3");
|
||||
//mainMenuWoG = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "MainMenuWoG.mp3");
|
||||
//necroTown = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "necroTown.mp3");
|
||||
//neutralTheme = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "NeutralTheme.mp3");
|
||||
//rampart = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "RAMPART.mp3");
|
||||
//retreatBattle = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "Retreat Battle.mp3");
|
||||
//rough = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "ROUGH.mp3");
|
||||
//sand = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "SAND.mp3");
|
||||
//secretTheme = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "SecretTheme.mp3");
|
||||
//snow = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "SNOW.mp3");
|
||||
//stronghold = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "StrongHold.mp3");
|
||||
//surrenderBattle = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "Surrender Battle.mp3");
|
||||
//swamp = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "SWAMP.mp3");
|
||||
//towerTown = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "TowerTown.mp3");
|
||||
//ultimateLose = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "UltimateLose.mp3");
|
||||
//underground = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "Underground.mp3");
|
||||
//water = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "WATER.mp3");
|
||||
//winBattle = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "Win Battle.mp3");
|
||||
//winScenario = Mix_LoadMUS(DATA_DIR "MP3" PATHSEPARATOR "Win Scenario.mp3");
|
||||
|
||||
click = Mix_LoadWAV("MP3\\snd1.wav");
|
||||
click = Mix_LoadWAV(DATA_DIR "MP3" PATHSEPARATOR "snd1.wav");
|
||||
click->volume = 30;
|
||||
|
||||
this->sndh = new CSndHandler(std::string("Data\\Heroes3.snd"));
|
||||
this->sndh = new CSndHandler(std::string(DATA_DIR "Data" PATHSEPARATOR "Heroes3.snd"));
|
||||
}
|
||||
|
||||
void CMusicHandler::playClick()
|
||||
@ -90,7 +90,7 @@ void CMusicHandler::playLodSnd(std::string sndname)
|
||||
channel = Mix_PlayChannel(-1, chunk, 0);
|
||||
if(channel == -1)
|
||||
{
|
||||
fprintf(stderr, "Unable to play WAV file(Data\\Heroes3.wav::%s): %s\n",
|
||||
fprintf(stderr, "Unable to play WAV file("DATA_DIR "Data" PATHSEPARATOR "Heroes3.wav::%s): %s\n",
|
||||
sndname.c_str(),Mix_GetError());
|
||||
}
|
||||
ops->close(ops);
|
||||
|
@ -12,7 +12,11 @@ CSndHandler::CSndHandler(std::string fname):CHUNK(65535)
|
||||
{
|
||||
file.open(fname.c_str(),std::ios::binary);
|
||||
if (!file.is_open())
|
||||
#ifndef __GNUC__
|
||||
throw new std::exception((std::string("Cannot open ")+fname).c_str());
|
||||
#else
|
||||
throw new std::exception();
|
||||
#endif
|
||||
int nr = readNormalNr(0,4);
|
||||
char tempc;
|
||||
for (int i=0;i<nr;i++)
|
||||
@ -149,7 +153,11 @@ CVidHandler::CVidHandler(std::string fname):CHUNK(65535)
|
||||
{
|
||||
file.open(fname.c_str(),std::ios::binary);
|
||||
if (!file.is_open())
|
||||
#ifndef __GNUC__
|
||||
throw new std::exception((std::string("Cannot open ")+fname).c_str());
|
||||
#else
|
||||
throw new std::exception();
|
||||
#endif
|
||||
int nr = readNormalNr(0,4);
|
||||
char tempc;
|
||||
for (int i=0;i<nr;i++)
|
||||
|
@ -2,9 +2,14 @@
|
||||
#include <iostream>
|
||||
#include "CVideoHandler.h"
|
||||
#include "SDL.h"
|
||||
|
||||
void DLLHandler::Instantiate(const char *filename)
|
||||
{
|
||||
#ifdef WIN32
|
||||
dll = LoadLibraryA(filename);
|
||||
#else
|
||||
dll = dlopen(filename,RTLD_LOCAL | RTLD_LAZY);
|
||||
#endif
|
||||
}
|
||||
const char *DLLHandler::GetLibExtension()
|
||||
{
|
||||
@ -21,14 +26,22 @@ const char *DLLHandler::GetLibExtension()
|
||||
|
||||
void *DLLHandler::FindAddress234(const char *symbol)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if ((int)symbol == 0x00001758)
|
||||
return NULL;
|
||||
std::cout<<"co ja tu robie"<<std::endl;
|
||||
return (void*) GetProcAddress(dll,symbol);
|
||||
#else
|
||||
return (void *)dlsym(dll, symbol);
|
||||
#endif
|
||||
}
|
||||
DLLHandler::~DLLHandler()
|
||||
{
|
||||
#ifdef WIN32
|
||||
FreeLibrary(dll);
|
||||
#else
|
||||
dlclose(dll);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -53,13 +66,15 @@ int readNormalNr2 (unsigned char* bufor, int &iter, int bytCon)
|
||||
}
|
||||
void RaiseLastOSErrorAt(char * offset)
|
||||
{
|
||||
#ifdef WIN32
|
||||
int * lastError = new int;
|
||||
std::exception * error;
|
||||
*lastError = GetLastError();
|
||||
if (*lastError)
|
||||
throw lastError;
|
||||
|
||||
|
||||
#else
|
||||
throw new std::exception();
|
||||
#endif
|
||||
}
|
||||
//var
|
||||
// LastError: Integer;
|
||||
@ -93,10 +108,7 @@ void RaiseLastOSErrorAt(char * offset)
|
||||
//}
|
||||
void CBIKHandler::open(std::string name)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
hBinkFile = CreateFile
|
||||
(
|
||||
L"CSECRET.BIK", // file name
|
||||
@ -143,7 +155,9 @@ void CBIKHandler::open(std::string name)
|
||||
{
|
||||
printf("cos nie tak");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//void CBIKHandler::close()
|
||||
//{
|
||||
// void *binkClose;
|
||||
|
@ -2,7 +2,12 @@
|
||||
#define CVIDEOHANDLEER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
//
|
||||
#define BINKNOTHREADEDIO 0x00800000
|
||||
//
|
||||
@ -109,8 +114,11 @@ struct SMKStruct
|
||||
class DLLHandler
|
||||
{
|
||||
public:
|
||||
#if !defined(__amigaos4__) && !defined(__unix__)
|
||||
HINSTANCE dll;
|
||||
|
||||
#else
|
||||
void *dll;
|
||||
#endif
|
||||
void Instantiate(const char *filename);
|
||||
const char *GetLibExtension();
|
||||
void *FindAddress234(const char *symbol);
|
||||
@ -123,7 +131,11 @@ class CBIKHandler
|
||||
public:
|
||||
DLLHandler ourLib;
|
||||
int newmode;
|
||||
#if !defined(__amigaos4__) && !defined(__unix__)
|
||||
HANDLE hBinkFile;
|
||||
#else
|
||||
void *hBinkFile;
|
||||
#endif
|
||||
HBINK hBink;
|
||||
BINK_STRUCT data;
|
||||
unsigned char * buffer;
|
||||
|
34
map.cpp
34
map.cpp
@ -220,7 +220,7 @@ CMapHeader::CMapHeader(unsigned char *map)
|
||||
for (pom=0;pom<length;pom++)
|
||||
this->description+=map[i++];
|
||||
this->difficulty = map[i++]; // reading map difficulty
|
||||
if(version!=Eformat::RoE)
|
||||
if(version!=RoE)
|
||||
{
|
||||
this->levelLimit = map[i++]; // hero level limit
|
||||
}
|
||||
@ -236,13 +236,13 @@ CMapHeader::CMapHeader(unsigned char *map)
|
||||
{
|
||||
switch(version)
|
||||
{
|
||||
case Eformat::SoD: case Eformat::WoG:
|
||||
case SoD: case WoG:
|
||||
i+=13;
|
||||
break;
|
||||
case Eformat::AB:
|
||||
case AB:
|
||||
i+=12;
|
||||
break;
|
||||
case Eformat::RoE:
|
||||
case RoE:
|
||||
i+=6;
|
||||
break;
|
||||
}
|
||||
@ -251,19 +251,19 @@ CMapHeader::CMapHeader(unsigned char *map)
|
||||
|
||||
this->players[pom].AITactic = map[i++];
|
||||
|
||||
if(version == Eformat::SoD || version == Eformat::WoG)
|
||||
if(version == SoD || version == WoG)
|
||||
i++;
|
||||
|
||||
this->players[pom].allowedFactions = 0;
|
||||
this->players[pom].allowedFactions += map[i++];
|
||||
if(version != Eformat::RoE)
|
||||
if(version != RoE)
|
||||
this->players[pom].allowedFactions += (map[i++])*256;
|
||||
|
||||
this->players[pom].isFactionRandom = map[i++];
|
||||
this->players[pom].hasMainTown = map[i++];
|
||||
if (this->players[pom].hasMainTown)
|
||||
{
|
||||
if(version != Eformat::RoE)
|
||||
if(version != RoE)
|
||||
{
|
||||
this->players[pom].generateHeroAtMainTown = map[i++];
|
||||
this->players[pom].generateHero = map[i++];
|
||||
@ -283,7 +283,7 @@ CMapHeader::CMapHeader(unsigned char *map)
|
||||
players[pom].mainHeroName+=map[i++];
|
||||
}
|
||||
|
||||
if(version!=Eformat::RoE)
|
||||
if(version!=RoE)
|
||||
{
|
||||
i++; ////heroes placeholders //domostwa
|
||||
int heroCount = map[i++];
|
||||
@ -462,7 +462,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
|
||||
name = readString(bufor,i);
|
||||
description= readString(bufor,i);
|
||||
difficulty = readChar(bufor,i); // reading map difficulty
|
||||
if(version != Eformat::RoE)
|
||||
if(version != RoE)
|
||||
levelLimit = readChar(bufor,i); // hero level limit
|
||||
else
|
||||
levelLimit = 0;
|
||||
@ -474,13 +474,13 @@ void Mapa::initFromBytes(unsigned char * bufor)
|
||||
{
|
||||
switch(version)
|
||||
{
|
||||
case Eformat::SoD: case Eformat::WoG:
|
||||
case SoD: case WoG:
|
||||
i+=13;
|
||||
break;
|
||||
case Eformat::AB:
|
||||
case AB:
|
||||
i+=12;
|
||||
break;
|
||||
case Eformat::RoE:
|
||||
case RoE:
|
||||
i+=6;
|
||||
break;
|
||||
}
|
||||
@ -489,19 +489,19 @@ void Mapa::initFromBytes(unsigned char * bufor)
|
||||
|
||||
players[pom].AITactic = bufor[i++];
|
||||
|
||||
if(version == Eformat::SoD || version == Eformat::WoG)
|
||||
if(version == SoD || version == WoG)
|
||||
players[pom].p7= bufor[i++];
|
||||
|
||||
players[pom].allowedFactions = 0;
|
||||
players[pom].allowedFactions += bufor[i++];
|
||||
if(version != Eformat::RoE)
|
||||
if(version != RoE)
|
||||
players[pom].allowedFactions += (bufor[i++])*256;
|
||||
|
||||
players[pom].isFactionRandom = bufor[i++];
|
||||
players[pom].hasMainTown = bufor[i++];
|
||||
if (players[pom].hasMainTown)
|
||||
{
|
||||
if(version != Eformat::RoE)
|
||||
if(version != RoE)
|
||||
{
|
||||
players[pom].generateHeroAtMainTown = bufor[i++];
|
||||
players[pom].generateHero = bufor[i++];
|
||||
@ -529,7 +529,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
|
||||
players[pom].mainHeroName+=bufor[i++];
|
||||
}
|
||||
|
||||
if(version != Eformat::RoE)
|
||||
if(version != RoE)
|
||||
{
|
||||
i++; ////unknown byte
|
||||
int heroCount = bufor[i++];
|
||||
@ -699,7 +699,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
|
||||
for(int xx=0;xx<HEROES_QUANTITY;xx++)
|
||||
allowedHeroes[xx] = true;
|
||||
|
||||
for(i; i<ist+ (version == Eformat::RoE ? 16 : 20) ; ++i)
|
||||
for(i; i<ist+ (version == RoE ? 16 : 20) ; ++i)
|
||||
{
|
||||
unsigned char c = bufor[i];
|
||||
for(int yy=0; yy<8; ++yy)
|
||||
|
16
map.h
16
map.h
@ -10,7 +10,7 @@ class CGDefInfo;
|
||||
class CGObjectInstance;
|
||||
class CGHeroInstance;
|
||||
class CGTownInstance;
|
||||
enum ESortBy{name,playerAm,size,format, viccon,loscon};
|
||||
enum ESortBy{_name, _playerAm, _size, _format, _viccon, _loscon};
|
||||
enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF,
|
||||
EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF,
|
||||
SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF,
|
||||
@ -410,17 +410,17 @@ class DLL_EXPORT mapSorter
|
||||
{
|
||||
public:
|
||||
ESortBy sortBy;
|
||||
bool operator()(CMapHeader & a, CMapHeader& b)
|
||||
bool operator()(const CMapHeader & a, const CMapHeader& b)
|
||||
{
|
||||
switch (sortBy)
|
||||
{
|
||||
case ESortBy::format:
|
||||
case _format:
|
||||
return (a.version<b.version);
|
||||
break;
|
||||
case ESortBy::loscon:
|
||||
case _loscon:
|
||||
return (a.lossCondition.typeOfLossCon<b.lossCondition.typeOfLossCon);
|
||||
break;
|
||||
case ESortBy::playerAm:
|
||||
case _playerAm:
|
||||
int playerAmntB,humenPlayersB,playerAmntA,humenPlayersA;
|
||||
playerAmntB=humenPlayersB=playerAmntA=humenPlayersA=0;
|
||||
for (int i=0;i<8;i++)
|
||||
@ -435,13 +435,13 @@ public:
|
||||
else
|
||||
return (humenPlayersA<humenPlayersB);
|
||||
break;
|
||||
case ESortBy::size:
|
||||
case _size:
|
||||
return (a.width<b.width);
|
||||
break;
|
||||
case ESortBy::viccon:
|
||||
case _viccon:
|
||||
return (a.victoryCondition<b.victoryCondition);
|
||||
break;
|
||||
case ESortBy::name:
|
||||
case _name:
|
||||
return (a.name<b.name);
|
||||
break;
|
||||
default:
|
||||
|
47
nodrze.h
47
nodrze.h
@ -6,9 +6,12 @@
|
||||
//ignore comment above, it is simply TowDragon's envy. Everything (without removing) is working fine
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define CLOG(x)
|
||||
|
||||
const bool CZERWONY=true, CZARNY=false;
|
||||
template <typename T> class wezel
|
||||
{
|
||||
@ -140,7 +143,7 @@ template <typename T> void nodrze<T>::wypisuj(wezel<T> * w, std::ostream & strum
|
||||
if (w==NIL) return;
|
||||
wypisuj(w->lewy, strum);
|
||||
|
||||
strum << "Informacje o wezle: "<<flush<<w<<flush;
|
||||
strum << "Informacje o wezle: "<<std::flush<<w<<std::flush;
|
||||
if (w->ojciec!=NIL)
|
||||
strum <<"\n\tOjciec: "<<(w->ojciec)<<" - "<<*(w->ojciec->zawart);
|
||||
else strum <<"\n\tOjciec: NIL";
|
||||
@ -159,7 +162,7 @@ template <typename T> void nodrze<T>::wypisujPre(wezel<T> * w, std::ostream & st
|
||||
{
|
||||
if (w==NIL) return;
|
||||
|
||||
strum << "Informacje o wezle: "<<flush<<w<<flush;
|
||||
strum << "Informacje o wezle: "<<std::flush<<w<<std::flush;
|
||||
if (w->ojciec!=NIL)
|
||||
strum <<"\n\tOjciec: "<<(w->ojciec)<<" - "<<*(w->ojciec->zawart);
|
||||
else strum <<"\n\tOjciec: NIL";
|
||||
@ -179,14 +182,16 @@ template <typename T> void nodrze<T>::wypiszObficie(std::ostream & strum)
|
||||
{
|
||||
strum << "Nodrze " <<this<<" ma " << ile << " elementów."<<std::endl;
|
||||
strum << "NIL to " << NIL <<std::endl;
|
||||
strum << "Ostatnio bralismy "<<ktory<<flush<<" element, czyli "<<" ("<<ostatnio<<")"<<flush<<*ostatnio<<flush<<std::endl;
|
||||
strum << "Ostatnio bralismy "<<ktory<<std::flush<<" element, czyli "<<" ("<<ostatnio<<")"<<std::flush<<*ostatnio<<std::flush<<std::endl;
|
||||
strum << "Nasze wezly in-order"<<std::endl;
|
||||
wypisujPre(korzen,strum);
|
||||
};
|
||||
template <typename T, class X> T* operator%(nodrze<T> & drzewko, X co)
|
||||
{
|
||||
CLOG ("Szukam " <<co <<std::endl);
|
||||
#if !defined(__amigaos4__) && !defined(__unix__)
|
||||
drzewko.wypiszObficie(*C->gl->loguj);
|
||||
#endif
|
||||
wezel<T> * w = drzewko.korzen;
|
||||
while (w!=drzewko.NIL && (*w->zawart)!=co)
|
||||
{
|
||||
@ -494,10 +499,10 @@ template <typename T> void nodrze<T>::naprawUsun (wezel<T> * x)
|
||||
wezel<T> *w;
|
||||
while ( (x != korzen) && (x->kolor == CZARNY) )
|
||||
{
|
||||
CLOG("6... "<<flush);
|
||||
CLOG("6... "<<std::flush);
|
||||
if (x == x->ojciec->lewy)
|
||||
{
|
||||
CLOG("7... "<<flush);
|
||||
CLOG("7... "<<std::flush);
|
||||
w = x->ojciec->prawy;
|
||||
if (w->kolor == CZERWONY)
|
||||
{
|
||||
@ -506,38 +511,38 @@ template <typename T> void nodrze<T>::naprawUsun (wezel<T> * x)
|
||||
rotacjaLewa(x->ojciec);
|
||||
w = x->ojciec->prawy;
|
||||
}
|
||||
CLOG("8... "<<flush);
|
||||
CLOG("8... "<<std::flush);
|
||||
if ( (w->lewy->kolor == CZARNY) && (w->prawy->kolor == CZARNY) )
|
||||
{
|
||||
CLOG("8,1... "<<flush);
|
||||
CLOG("8,1... "<<std::flush);
|
||||
w->kolor = CZERWONY;
|
||||
x = x->ojciec;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLOG("9... "<<flush);
|
||||
CLOG("9... "<<std::flush);
|
||||
if (w->prawy->kolor == CZARNY)
|
||||
{
|
||||
CLOG("9,1... "<<flush);
|
||||
CLOG("9,1... "<<std::flush);
|
||||
w->lewy->kolor = CZARNY;
|
||||
w->kolor = CZERWONY;
|
||||
rotacjaPrawa(w);
|
||||
w = x->ojciec->prawy;
|
||||
CLOG("9,2... "<<flush);
|
||||
CLOG("9,2... "<<std::flush);
|
||||
}
|
||||
CLOG("9,3... "<<flush);
|
||||
CLOG("9,3... "<<std::flush);
|
||||
w->kolor = x->ojciec->kolor;
|
||||
x->ojciec->kolor = CZARNY;
|
||||
w->prawy->kolor = CZARNY;
|
||||
rotacjaLewa(x->ojciec);
|
||||
x=korzen;
|
||||
CLOG("9,4... "<<flush);
|
||||
CLOG("9,4... "<<std::flush);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CLOG("10... "<<flush);
|
||||
CLOG("10... "<<std::flush);
|
||||
w = x->ojciec->lewy;
|
||||
if (w->kolor == CZERWONY)
|
||||
{
|
||||
@ -546,7 +551,7 @@ template <typename T> void nodrze<T>::naprawUsun (wezel<T> * x)
|
||||
rotacjaPrawa(x->ojciec);
|
||||
w = x->ojciec->lewy;
|
||||
}
|
||||
CLOG("11... "<<flush);
|
||||
CLOG("11... "<<std::flush);
|
||||
if ( (w->lewy->kolor == CZARNY) && (w->prawy->kolor == CZARNY) )
|
||||
{
|
||||
w->kolor = CZERWONY;
|
||||
@ -566,12 +571,12 @@ template <typename T> void nodrze<T>::naprawUsun (wezel<T> * x)
|
||||
w->lewy->kolor = CZARNY;
|
||||
rotacjaPrawa(x->ojciec);
|
||||
x=korzen;
|
||||
CLOG("12... "<<flush);
|
||||
CLOG("12... "<<std::flush);
|
||||
}
|
||||
}
|
||||
}
|
||||
x->kolor = CZARNY;
|
||||
CLOG("13... "<<flush);
|
||||
CLOG("13... "<<std::flush);
|
||||
};
|
||||
template <typename T> wezel<T> * nodrze<T>::usunRBT (wezel<T> * nowy)
|
||||
{
|
||||
@ -597,27 +602,27 @@ template <typename T> wezel<T> * nodrze<T>::usunRBT (wezel<T> * nowy)
|
||||
}
|
||||
CLOG(*ostatnio->zawart<<std::endl);
|
||||
}
|
||||
CLOG("1... "<<flush);
|
||||
CLOG("1... "<<std::flush);
|
||||
wezel<T> *y, *x;
|
||||
if ( (nowy->lewy == NIL) || (nowy->prawy == NIL) )
|
||||
y=nowy;
|
||||
else y = nastepnik(nowy);
|
||||
CLOG("2... "<<flush);
|
||||
CLOG("2... "<<std::flush);
|
||||
if (y->lewy != NIL)
|
||||
x = y->lewy;
|
||||
else x = y->prawy;
|
||||
x->ojciec = y->ojciec;
|
||||
CLOG("3... "<<flush);
|
||||
CLOG("3... "<<std::flush);
|
||||
if (y->ojciec == NIL)
|
||||
korzen = x;
|
||||
else if (y == y->ojciec->lewy)
|
||||
y->ojciec->lewy = x;
|
||||
else
|
||||
y->ojciec->prawy = x;
|
||||
CLOG("4... "<<flush);
|
||||
CLOG("4... "<<std::flush);
|
||||
if (y != nowy)
|
||||
(*nowy) = (*y); // skopiowanie
|
||||
CLOG("5... "<<flush);
|
||||
CLOG("5... "<<std::flush);
|
||||
if (y->kolor == CZARNY)
|
||||
naprawUsun(x);
|
||||
CLOG ("koniec usuwania"<<std::endl);
|
||||
|
4
stdafx.h
4
stdafx.h
@ -7,7 +7,11 @@
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#include <cstdio>
|
||||
#ifdef _WIN32
|
||||
#include <tchar.h>
|
||||
#else
|
||||
#include "tchar_amigaos4.h"
|
||||
#endif
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
238
tchar_amigaos4.h
Normal file
238
tchar_amigaos4.h
Normal file
@ -0,0 +1,238 @@
|
||||
/*
|
||||
* tchar.h
|
||||
*
|
||||
* Unicode mapping layer for the standard C library. By including this
|
||||
* file and using the 't' names for string functions
|
||||
* (eg. _tprintf) you can make code which can be easily adapted to both
|
||||
* Unicode and non-unicode environments. In a unicode enabled compile define
|
||||
* _UNICODE before including tchar.h, otherwise the standard non-unicode
|
||||
* library functions will be used.
|
||||
*
|
||||
* Note that you still need to include string.h or stdlib.h etc. to define
|
||||
* the appropriate functions. Also note that there are several defines
|
||||
* included for non-ANSI functions which are commonly available (but using
|
||||
* the convention of prepending an underscore to non-ANSI library function
|
||||
* names).
|
||||
*
|
||||
* This file is part of the Mingw32 package.
|
||||
*
|
||||
* Contributors:
|
||||
* Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
|
||||
*
|
||||
* THIS SOFTWARE IS NOT COPYRIGHTED
|
||||
*
|
||||
* This source code is offered for use in the public domain. You may
|
||||
* use, modify or distribute it freely.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful but
|
||||
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
|
||||
* DISCLAMED. This includes but is not limited to warranties of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Revision: 1.1.1.1 $
|
||||
* $Author: brandon6684 $
|
||||
* $Date: 2001/12/18 22:54:08 $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _TCHAR_H_
|
||||
#define _TCHAR_H_
|
||||
|
||||
/*
|
||||
* NOTE: This tests _UNICODE, which is different from the UNICODE define
|
||||
* used to differentiate Win32 API calls.
|
||||
*/
|
||||
#ifdef __unix__
|
||||
#define _TCHAR char*
|
||||
#endif
|
||||
#ifdef _UNICODE
|
||||
|
||||
|
||||
/*
|
||||
* Use TCHAR instead of char or wchar_t. It will be appropriately translated
|
||||
* if _UNICODE is correctly defined (or not).
|
||||
*/
|
||||
#ifndef _TCHAR_DEFINED
|
||||
#ifndef RC_INVOKED
|
||||
typedef wchar_t TCHAR;
|
||||
#endif /* Not RC_INVOKED */
|
||||
#define _TCHAR_DEFINED
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Enclose constant strings and literal characters in the _TEXT and _T macro to make
|
||||
* them unicode constant strings when _UNICODE is defined.
|
||||
*/
|
||||
#define _TEXT(x) L ## x
|
||||
#define _T(x) L ## x
|
||||
|
||||
/*
|
||||
* Unicode functions
|
||||
*/
|
||||
|
||||
#define _tprintf wprintf
|
||||
#define _ftprintf fwprintf
|
||||
#define _stprintf swprintf
|
||||
#define _sntprintf _snwprintf
|
||||
#define _vtprintf vwprintf
|
||||
#define _vftprintf vfwprintf
|
||||
#define _vstprintf vswprintf
|
||||
#define _vsntprintf _vsnwprintf
|
||||
#define _tscanf wscanf
|
||||
#define _ftscanf fwscanf
|
||||
#define _stscanf swscanf
|
||||
#define _fgettc fgetwc
|
||||
#define _fgettchar _fgetwchar
|
||||
#define _fgetts fgetws
|
||||
#define _fputtc fputwc
|
||||
#define _fputtchar _fputwchar
|
||||
#define _fputts fputws
|
||||
#define _gettc getwc
|
||||
#define _getts getws
|
||||
#define _puttc putwc
|
||||
#define _putts putws
|
||||
#define _ungettc ungetwc
|
||||
#define _tcstod wcstod
|
||||
#define _tcstol wcstol
|
||||
#define _tcstoul wcstoul
|
||||
#define _tcscat wcscat
|
||||
#define _tcschr wcschr
|
||||
#define _tcscmp wcscmp
|
||||
#define _tcscpy wcscpy
|
||||
#define _tcscspn wcscspn
|
||||
#define _tcslen wcslen
|
||||
#define _tcsncat wcsncat
|
||||
#define _tcsncmp wcsncmp
|
||||
#define _tcsncpy wcsncpy
|
||||
#define _tcspbrk wcspbrk
|
||||
#define _tcsrchr wcsrchr
|
||||
#define _tcsspn wcsspn
|
||||
#define _tcsstr wcsstr
|
||||
#define _tcstok wcstok
|
||||
#define _tcsdup _wcsdup
|
||||
#define _tcsicmp _wcsicmp
|
||||
#define _tcsnicmp _wcsnicmp
|
||||
#define _tcsnset _wcsnset
|
||||
#define _tcsrev _wcsrev
|
||||
#define _tcsset _wcsset
|
||||
#define _tcslwr _wcslwr
|
||||
#define _tcsupr _wcsupr
|
||||
#define _tcsxfrm wcsxfrm
|
||||
#define _tcscoll wcscoll
|
||||
#define _tcsicoll _wcsicoll
|
||||
#define _istalpha iswalpha
|
||||
#define _istupper iswupper
|
||||
#define _istlower iswlower
|
||||
#define _istdigit iswdigit
|
||||
#define _istxdigit iswxdigit
|
||||
#define _istspace iswspace
|
||||
#define _istpunct iswpunct
|
||||
#define _istalnum iswalnum
|
||||
#define _istprint iswprint
|
||||
#define _istgraph iswgraph
|
||||
#define _istcntrl iswcntrl
|
||||
#define _istascii iswascii
|
||||
#define _totupper towupper
|
||||
#define _totlower towlower
|
||||
#define _ttoi _wtoi
|
||||
#define _tcsftime wcsftime
|
||||
|
||||
#else /* Not _UNICODE */
|
||||
|
||||
/*
|
||||
* TCHAR, the type you should use instead of char.
|
||||
*/
|
||||
#ifndef _TCHAR_DEFINED
|
||||
#ifndef RC_INVOKED
|
||||
typedef char TCHAR;
|
||||
#endif
|
||||
#define _TCHAR_DEFINED
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enclose constant strings and characters in the _TEXT and _T macro.
|
||||
*/
|
||||
#define _TEXT(x) x
|
||||
#define _T(x) x
|
||||
|
||||
|
||||
/*
|
||||
* Non-unicode (standard) functions
|
||||
*/
|
||||
|
||||
#define _tprintf printf
|
||||
#define _ftprintf fprintf
|
||||
#define _stprintf sprintf
|
||||
#define _sntprintf _snprintf
|
||||
#define _vtprintf vprintf
|
||||
#define _vftprintf vfprintf
|
||||
#define _vstprintf vsprintf
|
||||
#define _vsntprintf _vsnprintf
|
||||
#define _tscanf scanf
|
||||
#define _ftscanf fscanf
|
||||
#define _stscanf sscanf
|
||||
#define _fgettc fgetc
|
||||
#define _fgettchar _fgetchar
|
||||
#define _fgetts fgets
|
||||
#define _fputtc fputc
|
||||
#define _fputtchar _fputchar
|
||||
#define _fputts fputs
|
||||
#define _gettc getc
|
||||
#define _getts gets
|
||||
#define _puttc putc
|
||||
#define _putts puts
|
||||
#define _ungettc ungetc
|
||||
#define _tcstod strtod
|
||||
#define _tcstol strtol
|
||||
#define _tcstoul strtoul
|
||||
#define _tcscat strcat
|
||||
#define _tcschr strchr
|
||||
#define _tcscmp strcmp
|
||||
#define _tcscpy strcpy
|
||||
#define _tcscspn strcspn
|
||||
#define _tcslen strlen
|
||||
#define _tcsncat strncat
|
||||
#define _tcsncmp strncmp
|
||||
#define _tcsncpy strncpy
|
||||
#define _tcspbrk strpbrk
|
||||
#define _tcsrchr strrchr
|
||||
#define _tcsspn strspn
|
||||
#define _tcsstr strstr
|
||||
#define _tcstok strtok
|
||||
#define _tcsdup _strdup
|
||||
#define _tcsicmp _stricmp
|
||||
#define _tcsnicmp _strnicmp
|
||||
#define _tcsnset _strnset
|
||||
#define _tcsrev _strrev
|
||||
#define _tcsset _strset
|
||||
#define _tcslwr _strlwr
|
||||
#define _tcsupr _strupr
|
||||
#define _tcsxfrm strxfrm
|
||||
#define _tcscoll strcoll
|
||||
#define _tcsicoll _stricoll
|
||||
#define _istalpha isalpha
|
||||
#define _istupper isupper
|
||||
#define _istlower islower
|
||||
#define _istdigit isdigit
|
||||
#define _istxdigit isxdigit
|
||||
#define _istspace isspace
|
||||
#define _istpunct ispunct
|
||||
#define _istalnum isalnum
|
||||
#define _istprint isprint
|
||||
#define _istgraph isgraph
|
||||
#define _istcntrl iscntrl
|
||||
#define _istascii isascii
|
||||
#define _totupper toupper
|
||||
#define _totlower tolower
|
||||
#define _ttoi atoi
|
||||
#define _tcsftime strftime
|
||||
|
||||
#ifdef __amigaos4__
|
||||
#define _TCHAR wchar_t
|
||||
#endif
|
||||
|
||||
#endif /* Not _UNICODE */
|
||||
|
||||
#endif /* Not _TCHAR_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user