1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-24 03:47:18 +02:00

some warning & code cleanup - nothing significant

This commit is contained in:
Łukasz Wychrystenko 2008-12-21 19:17:35 +00:00
parent 6fc8ed9365
commit 633b0007ba
44 changed files with 3178 additions and 2878 deletions

View File

@ -1,15 +1,14 @@
#ifndef AIBASE_H
#define AIBASE_H
#ifdef _MSC_VER
#pragma once
#endif
#include <vector>
#include <iostream>
#include "CGameInterface.h"
#define AI_INTERFACE_VER 1
#endif //AIBASE_H

View File

@ -118,29 +118,31 @@ void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::
state=0;
hoverTexts = Name;
helpBox=HelpBox;
int est = LOCPLINT->playerID;
//int est = LOCPLINT->playerID; //TODO use me
CDefHandler * temp = CDefHandler::giveDef(defName);
temp->notFreeImgs = true;
for (int i=0;i<temp->ourImages.size();i++)
for (size_t i=0;i<temp->ourImages.size();i++)
{
imgs.resize(1);
imgs[0].push_back(temp->ourImages[i].bitmap);
if(playerColoredButton)
if(playerColoredButton) {
graphics->blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
}
}
delete temp;
if (add && add->size())
{
imgs.resize(imgs.size()+add->size());
for (int i=0; i<add->size();i++)
for (size_t i=0; i<add->size();i++)
{
temp = CDefHandler::giveDef((*add)[i]);
temp->notFreeImgs = true;
for (int j=0;j<temp->ourImages.size();j++)
for (size_t j=0;j<temp->ourImages.size();j++)
{
imgs[i+1].push_back(temp->ourImages[j].bitmap);
if(playerColoredButton)
if(playerColoredButton) {
graphics->blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
}
}
delete temp;
}
@ -220,25 +222,28 @@ CHighlightableButtonsGroup::CHighlightableButtonsGroup(const CFunctionList2<void
}
CHighlightableButtonsGroup::~CHighlightableButtonsGroup()
{
for(int i=0;i<buttons.size();i++)
delete buttons[i];
for(size_t i=0;i<buttons.size();i++) {
delete buttons[i]; //TODO smartpointers
}
}
void CHighlightableButtonsGroup::activate()
{
for(int i=0;i<buttons.size();i++)
for(size_t i=0;i<buttons.size();i++) {
buttons[i]->activate();
}
}
void CHighlightableButtonsGroup::deactivate()
{
for(int i=0;i<buttons.size();i++)
for(size_t i=0;i<buttons.size();i++) {
buttons[i]->deactivate();
}
}
void CHighlightableButtonsGroup::select(int id, bool mode)
{
CHighlightableButton *bt = NULL;
if(mode)
{
for(int i=0;i<buttons.size() && !bt;i++)
for(size_t i=0;i<buttons.size() && !bt; ++i)
if (buttons[i]->ID == id)
bt = buttons[i];
}
@ -252,15 +257,16 @@ void CHighlightableButtonsGroup::select(int id, bool mode)
void CHighlightableButtonsGroup::selectionChanged(int to)
{
for(int i=0;i<buttons.size();i++)
for(size_t i=0;i<buttons.size(); ++i)
if(buttons[i]->ID!=to && buttons[i]->selected)
buttons[i]->select(false);
onChange(to);
}
void CHighlightableButtonsGroup::show(SDL_Surface * to )
{
for(int i=0;i<buttons.size();i++)
for(size_t i=0;i<buttons.size(); ++i) {
buttons[i]->show();
}
}
void CSlider::sliderClicked()

View File

@ -1,4 +1,11 @@
#ifndef ADVENTUREMAPBUTTON_H
#define ADVENTUREMAPBUTTON_H
#ifdef _MSC_VER
#pragma once
#endif
#include "CPlayerInterface.h"
#include "client/FunctionList.h"
#include <boost/bind.hpp>
@ -91,3 +98,4 @@ public:
int Value=0, bool Horizontal=true);
~CSlider();
};
#endif //ADVENTUREMAPBUTTON_H

View File

@ -27,8 +27,13 @@
#include <boost/assign/std/vector.hpp>
#include <boost/thread.hpp>
#include <sstream>
#pragma warning (disable : 4355)
#ifdef _MSC_VER
#pragma warning (disable : 4355)
#endif
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
#define ADVOPT (conf.go()->ac)
using namespace boost::logic;
using namespace boost::assign;
@ -113,7 +118,7 @@ void CMinimap::draw()
int mw = map[0]->w, mh = map[0]->h,
wo = mw/mapSizes.x, ho = mh/mapSizes.y;
for (int i=0; i<hh.size();i++)
for (size_t i=0; i < hh.size(); ++i)
{
int3 hpos = hh[i]->getPosition(false);
if(hpos.z!=LOCPLINT->adventureInt->position.z)
@ -136,7 +141,7 @@ void CMinimap::draw()
for(int y=0; y<mapSizes.y; ++y)
{
std::vector < const CGObjectInstance * > oo = LOCPLINT->cb->getFlaggableObjects(int3(x, y, LOCPLINT->adventureInt->position.z));
for(int v=0; v<oo.size(); ++v)
for(size_t v=0; v<oo.size(); ++v)
{
if(!dynamic_cast< const CGHeroInstance * >(oo[v])) //heroes have been printed
{
@ -170,7 +175,7 @@ void CMinimap::draw()
void CMinimap::redraw(int level)// (level==-1) => redraw all levels
{
int3 mapSizes = LOCPLINT->cb->getMapSize();
for (int i=0; i<CGI->mh->sizes.z; i++)
for (size_t i=0; i<CGI->mh->sizes.z; i++)
{
SDL_Surface * pom ;
if ((level>=0) && (i!=level))
@ -194,8 +199,8 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels
}
//FoW
int mw = map[0]->w, mh = map[0]->h,
wo = mw/mapSizes.x, ho = mh/mapSizes.y;
int mw = map[0]->w, mh = map[0]->h;//,
//wo = mw/mapSizes.x, ho = mh/mapSizes.y; //TODO use me
for(int d=0; d<CGI->mh->map->twoLevel+1; ++d)
{
if(level>=0 && d!=level)
@ -302,7 +307,7 @@ CTerrainRect::CTerrainRect():currentPath(NULL)
pos.h=tilesh*32 - ADVOPT.advmapTrimY;
moveX = moveY = 0;
arrows = CDefHandler::giveDef("ADAG.DEF");
for(int y=0; y<arrows->ourImages.size(); ++y)
for(size_t y=0; y < arrows->ourImages.size(); ++y)
{
arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap);
}
@ -338,7 +343,7 @@ void CTerrainRect::clickLeft(tribool down)
currentPath = NULL;
}
objs = LOCPLINT->cb->getBlockingObjs(mp);
for(int i=0; i<objs.size();i++)
for(size_t i=0; i < objs.size(); ++i)
{
if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
{
@ -363,13 +368,13 @@ void CTerrainRect::clickLeft(tribool down)
else
{
objs = LOCPLINT->cb->getVisitableObjs(mp);
for(int i=0; i<objs.size();i++)
for(size_t i=0; i < objs.size(); ++i)
{
if(objs[i]->ID == 98)
goto endchkpt;
}
objs = LOCPLINT->cb->getBlockingObjs(mp);
for(int i=0; i<objs.size();i++)
for(size_t i=0; i < objs.size(); ++i)
{
if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
{
@ -451,7 +456,7 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
}
}
objs = LOCPLINT->cb->getBlockingObjs(pom);
for(int i=0; i<objs.size();i++)
for(size_t i=0; i < objs.size(); ++i)
{
if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
{
@ -475,7 +480,7 @@ void CTerrainRect::hover(bool on)
}
void CTerrainRect::showPath()
{
for (int i=0;i<currentPath->nodes.size()-1;i++)
for (size_t i=0; i < currentPath->nodes.size()-1; ++i)
{
int pn=-1;//number of picture
if (i==0) //last tile
@ -728,7 +733,7 @@ void CTerrainRect::showPath()
}
void CTerrainRect::show()
{
SDL_Surface * teren = CGI->mh->terrainRect
SDL_Surface * teren = CGI->mh->terrainRect //TODO use me
(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
&LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
@ -1028,8 +1033,8 @@ nextHero(CGI->generaltexth->zelp[301].first,CGI->generaltexth->zelp[301].second,
endTurn(CGI->generaltexth->zelp[302].first,CGI->generaltexth->zelp[302].second,
boost::bind(&CAdvMapInt::fendTurn,this), &ADVOPT.endTurn, SDLK_e),
townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD),//(5,&genRect(192,48,747,196),747,196,747,372),
heroList(ADVOPT.hlistSize)
heroList(ADVOPT.hlistSize),
townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD)//(5,&genRect(192,48,747,196),747,196,747,372),
{
selection = NULL;
townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
@ -1339,7 +1344,7 @@ void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * c
}
else
{
for (int i=0;i<LOCPLINT->objsToBlit.size();i++)
for (size_t i=0; i < LOCPLINT->objsToBlit.size(); ++i)
{
//TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down)
CSimpleWindow * pom = dynamic_cast<CSimpleWindow*>(LOCPLINT->objsToBlit[i]);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,11 @@
#ifndef CBATTLEINTERFACE_H
#define CBATTLEINTERFACE_H
#ifdef _MSC_VER
#pragma once
#endif
#include "global.h"
#include "CPlayerInterface.h"
#include <list>
@ -251,3 +258,4 @@ public:
friend class CBattleReslutWindow;
friend class CPlayerInterface;
};
#endif //CBATTLEINTERFACE_H

View File

@ -61,7 +61,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
}
else if (idtype==1 && player>=0) //looking for it in local area
{
for (int i=0; i<gs->players[player].heroes.size();i++)
for (size_t i=0; i < gs->players[player].heroes.size(); ++i)
{
if (gs->players[player].heroes[i]->type->ID == ID)
hero = gs->players[player].heroes[i];
@ -72,7 +72,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
for(std::map<ui8, PlayerState>::iterator j=gs->players.begin(); j!=gs->players.end(); ++j)
{
for (int i=0; i<(*j).second.heroes.size();i++)
for (size_t i=0; i < (*j).second.heroes.size(); ++i)
{
if ((*j).second.heroes[i]->type->ID == ID)
{
@ -193,19 +193,23 @@ int CCallback::howManyHeroes() const
}
const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) const //mode = 0 -> val = serial; mode = 1 -> val = ID
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me?
//if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
// return NULL;
if (!mode) //esrial id
if(val<gs->players[player].heroes.size())
if(val<gs->players[player].heroes.size()) {
return gs->players[player].heroes[val];
else return NULL;
}
else {
return NULL;
}
else if(mode==1) //it's hero type id
{
for (int i=0; i<gs->players[player].heroes.size();i++)
for (size_t i=0; i < gs->players[player].heroes.size(); ++i)
{
if (gs->players[player].heroes[i]->type->ID==val)
if (gs->players[player].heroes[i]->type->ID==val) {
return gs->players[player].heroes[i];
}
}
}
else //object id
@ -242,7 +246,7 @@ std::vector < std::string > CCallback::getObjDescriptions(int3 pos) const
}
bool CCallback::verifyPath(CPath * path, bool blockSea) const
{
for (int i=0;i<path->nodes.size();i++)
for (size_t i=0; i < path->nodes.size(); ++i)
{
if ( CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->blocked
&& (! (CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->visitable)))
@ -292,7 +296,7 @@ std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) cons
std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>();
for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
{
for (int j=0;j<(*i).second.towns.size();j++)
for (size_t j=0; j < (*i).second.towns.size(); ++j)
{
if ( ( isVisible((*i).second.towns[j],player) ) || (*i).first==player)
{
@ -306,7 +310,7 @@ std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur) con
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
std::vector < const CGHeroInstance *> ret;
for(int i=0;i<gs->map->heroes.size();i++)
for(size_t i=0;i<gs->map->heroes.size();i++)
{
if( (gs->map->heroes[i]->tempOwner==player) ||
(isVisible(gs->map->heroes[i]->getPosition(false),player) && !onlyOur) )
@ -346,7 +350,7 @@ int CCallback::getMyColor() const
int CCallback::getHeroSerial(const CGHeroInstance * hero) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
for (int i=0; i<gs->players[player].heroes.size();i++)
for (size_t i=0; i<gs->players[player].heroes.size();i++)
{
if (gs->players[player].heroes[i]==hero)
return i;
@ -467,7 +471,7 @@ CStack* CCallback::battleGetStackByPos(int pos)
int CCallback::battleGetPos(int stack)
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
for(int g=0; g<gs->curB->stacks.size(); ++g)
for(size_t g=0; g<gs->curB->stacks.size(); ++g)
{
if(gs->curB->stacks[g]->ID == stack)
return gs->curB->stacks[g]->position;
@ -484,7 +488,7 @@ std::map<int, CStack> CCallback::battleGetStacks()
return ret;
}
for(int g=0; g<gs->curB->stacks.size(); ++g)
for(size_t g=0; g<gs->curB->stacks.size(); ++g)
{
ret[gs->curB->stacks[g]->ID] = *(gs->curB->stacks[g]);
}
@ -498,8 +502,8 @@ std::vector<CStack> CCallback::battleGetStackQueue()
CCreature CCallback::battleGetCreature(int number)
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
for(int h=0; h<gs->curB->stacks.size(); ++h)
boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me?
for(size_t h=0; h<gs->curB->stacks.size(); ++h)
{
if(gs->curB->stacks[h]->ID == number) //creature found
return *(gs->curB->stacks[h]->creature);
@ -520,8 +524,8 @@ std::vector<int> CCallback::battleGetAvailableHexes(int ID)
bool CCallback::battleIsStackMine(int ID)
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
for(int h=0; h<gs->curB->stacks.size(); ++h)
boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me ?
for(size_t h=0; h<gs->curB->stacks.size(); ++h)
{
if(gs->curB->stacks[h]->ID == ID) //creature found
return gs->curB->stacks[h]->owner == player;
@ -530,11 +534,11 @@ bool CCallback::battleIsStackMine(int ID)
}
bool CCallback::battleCanShoot(int ID, int dest)
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me?
CStack *our = battleGetStackByID(ID), *dst = battleGetStackByPos(dest);
if(!our || !dst) return false;
for(int g=0; g<our->effects.size(); ++g)
for(size_t g=0; g<our->effects.size(); ++g)
{
if(61 == our->effects[g].id) //forgetfulness
return false;
@ -611,7 +615,7 @@ std::vector < const CGObjectInstance * > CCallback::getFlaggableObjects(int3 pos
std::vector < const CGObjectInstance * > ret;
std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & objs = CGI->mh->ttiles[pos.x][pos.y][pos.z].objects;
for(int b=0; b<objs.size(); ++b)
for(size_t b=0; b<objs.size(); ++b)
{
if(objs[b].first->tempOwner!=254 && !((objs[b].first->defInfo->blockMap[pos.y - objs[b].first->pos.y + 5] >> (objs[b].first->pos.x - pos.x)) & 1))
ret.push_back(CGI->mh->ttiles[pos.x][pos.y][pos.z].objects[b].first);

View File

@ -5,7 +5,9 @@
#ifdef _WIN32
#include "tchar.h"
#else
#include "tchar_amigaos4.h"
#include "tchar_amigaos4.h" //XXX this is mingw header are we need this for something? for 'true'
//support of unicode we should use ICU or some boost wraper areound it
//(boost using this lib during compilation i dont know what for exactly)
#endif
#include "CGameState.h"
@ -101,7 +103,7 @@ struct HeroMoveDetails
class CCallback : public ICallback
{
private:
CCallback(CGameState * GS, int Player, CClient *C):gs(GS),player(Player),cl(C){};
CCallback(CGameState * GS, int Player, CClient *C):gs(GS), cl(C), player(Player){};
CGameState * gs;
CClient *cl;
bool isVisible(int3 pos, int Player) const;
@ -175,7 +177,7 @@ public:
bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest
//XXX hmmm _tmain on _GNUC_ wtf?
//friends
friend class CClient;
#ifndef __GNUC__

View File

@ -27,7 +27,7 @@ using namespace CSDL_Ext;
extern TTF_Font * GEOR16;
CBuildingRect::CBuildingRect(Structure *Str)
:str(Str), moi(false), offset(0)
:moi(false), offset(0), str(Str)
{
def = CDefHandler::giveDef(Str->defName);
max = def->ourImages.size();
@ -49,14 +49,18 @@ CBuildingRect::CBuildingRect(Structure *Str)
area = border = NULL;
return;
}
if (border = BitmapHandler::loadBitmap(str->borderName))
if (border = BitmapHandler::loadBitmap(str->borderName)) {//FIXME hmmm if '=' use () else '==' fatal mistake
SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
else
}
else {
tlog2 << "Warning: no border for "<<Str->ID<<std::endl;
if (area = BitmapHandler::loadBitmap(str->areaName))
}
if (area = BitmapHandler::loadBitmap(str->areaName)) { //FIXME look up
;//SDL_SetColorKey(area,SDL_SRCCOLORKEY,SDL_MapRGB(area->format,0,255,255));
else
}
else {
tlog2 << "Warning: no area for "<<Str->ID<<std::endl;
}
}
CBuildingRect::~CBuildingRect()
@ -297,7 +301,7 @@ CHeroGSlot::CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, CCastl
CHeroGSlot::~CHeroGSlot()
{
}
std::string getBgName(int type) //TODO - co z tym zrobiæ?
std::string getBgName(int type) //TODO - co z tym zrobi?
{
switch (type)
{
@ -438,7 +442,7 @@ CCastleInterface::~CCastleInterface()
delete townlist;
delete statusbar;
delete resdatabar;
for(int i=0;i<buildings.size();i++)
for(size_t i=0;i<buildings.size();i++)
{
delete buildings[i];
}
@ -676,7 +680,7 @@ void CCastleInterface::show(SDL_Surface * to)
//blit buildings
for(int i=0;i<buildings.size();i++)
for(size_t i=0;i<buildings.size();i++)
{
int frame = ((animval)%(buildings[i]->max - buildings[i]->offset)) + buildings[i]->offset;
if(frame)
@ -706,8 +710,9 @@ void CCastleInterface::activate()
LOCPLINT->statusbar = statusbar;
exit->activate();
split->activate();
for(int i=0;i<buildings.size();i++)
for(size_t i=0;i<buildings.size();i++) { //XXX pls use iterators or at() but not []
buildings[i]->activate();
}
hslotdown.activate();
hslotup.activate();
showAll(0,true);
@ -724,8 +729,9 @@ void CCastleInterface::deactivate()
garr->deactivate();
exit->deactivate();
split->deactivate();
for(int i=0;i<buildings.size();i++)
for(size_t i=0;i<buildings.size();i++) { //XXX iterators
buildings[i]->deactivate();
}
hslotdown.deactivate();
hslotup.deactivate();
}
@ -746,7 +752,7 @@ void CCastleInterface::removeBuilding(int bid)
void CCastleInterface::recreateBuildings()
{
for(int i=0;i<buildings.size();i++)
for(size_t i=0;i<buildings.size();i++)
{
if(showing)
buildings[i]->deactivate();
@ -784,14 +790,14 @@ void CCastleInterface::recreateBuildings()
{
if((*(CGI->townh->structures[town->subID][obecny->second])) < (*(CGI->townh->structures[town->subID][st->ID]))) //we have to replace old building with current one
{
for(int itpb = 0; itpb<buildings.size(); itpb++)
for(size_t itpb = 0; itpb<buildings.size(); itpb++)
{
if(buildings[itpb]->str->ID == obecny->second)
{
delete buildings[itpb];
buildings.erase(buildings.begin() + itpb);
#ifndef __GNUC__
obecny->second = st->ID;
obecny->second = st->ID; //XXX look closer!
#else
*(const_cast<int*>(&(obecny->second))) = st->ID;
#endif
@ -818,7 +824,7 @@ void CCastleInterface::recreateBuildings()
if((town->subID == 5) && (town->builtBuildings.find(21)!=town->builtBuildings.end()))
{
CBuildingRect *vortex = NULL;
for(int i=0;i<buildings.size();i++)
for(size_t i=0;i<buildings.size();i++)
{
if(buildings[i]->str->ID==21)
{
@ -841,7 +847,7 @@ void CCastleInterface::recreateBuildings()
else if((town->subID == 0) && (town->builtBuildings.find(6)!=town->builtBuildings.end()))
{
CBuildingRect *shipyard = NULL;
for(int i=0;i<buildings.size();i++)
for(size_t i=0;i<buildings.size();i++)
{
if(buildings[i]->str->ID==6)
{
@ -995,11 +1001,11 @@ CHallInterface::CHallInterface(CCastleInterface * owner)
//preparing boxes with buildings//
boxes.resize(5);
for(int i=0;i<5;i++) //for each row
for(size_t i=0;i<5;i++) //for each row
{
for(int j=0; j<CGI->buildh->hall[owner->town->subID].second[i].size();j++) //for each box
for(size_t j=0; j<CGI->buildh->hall[owner->town->subID].second[i].size();j++) //for each box
{
int k=0;
size_t k=0;
for(;k<CGI->buildh->hall[owner->town->subID].second[i][j].size();k++)//we are looking for the first not build structure
{
if(
@ -1064,9 +1070,9 @@ CHallInterface::~CHallInterface()
delete bars;
delete status;
SDL_FreeSurface(bg);
for(int i=0;i<boxes.size();i++)
for(int j=0;j<boxes[i].size();j++)
delete boxes[i][j];
for(size_t i=0;i<boxes.size();i++)
for(size_t j=0;j<boxes[i].size();j++)
delete boxes[i][j]; //TODO whats wrong with smartpointers?
delete exit;
}
void CHallInterface::close()
@ -1076,29 +1082,30 @@ void CHallInterface::close()
delete this;
LOCPLINT->castleInt->activate();
}
void CHallInterface::show(SDL_Surface * to)
void CHallInterface::show(SDL_Surface * to) //TODO use me
{
blitAt(bg,pos);
resdatabar.show();
exit->show();
for(int i=0; i<5; i++)
{
for(int j=0;j<boxes[i].size();j++)
for(size_t j=0;j<boxes[i].size(); ++j)
boxes[i][j]->show();
}
}
void CHallInterface::activate()
{
for(int i=0;i<5;i++)
for(int j=0;j<boxes[i].size();j++)
for(size_t j=0; j < boxes[i].size(); ++j) {
boxes[i][j]->activate();
}
exit->activate();
}
void CHallInterface::deactivate()
{
for(int i=0;i<5;i++)
{
for(int j=0;j<boxes[i].size();j++)
for(size_t j=0;j<boxes[i].size();++j)
{
boxes[i][j]->deactivate();
}
@ -1187,7 +1194,7 @@ std::string CHallInterface::CBuildWindow::getTextForState(int state)
}
while(true)
{
int czystych=0;
size_t czystych=0;
for(std::set<int>::iterator i=reqs.begin();i!=reqs.end();i++)
{
if(used.find(*i)==used.end()) //we haven't added requirements for this building
@ -1223,7 +1230,7 @@ std::string CHallInterface::CBuildWindow::getTextForState(int state)
return ret;
}
CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mode)
:tid(Tid),bid(Bid),mode(Mode), state(State)
:tid(Tid), bid(Bid), state(State), mode(Mode)
{
SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPUBUILD.bmp");
graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
@ -1237,7 +1244,13 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod
CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->description,197,168,GEOR16,40,zwykly,bitmap);
CSDL_Ext::printAtMiddleWB(getTextForState(state),197,248,GEOR13,50,zwykly,bitmap);
CSDL_Ext::printAtMiddle(CSDL_Ext::processStr(CGI->townh->hcommands[7],pom),197,30,GEOR16,tytulowy,bitmap);
int resamount=0; for(int i=0;i<7;i++) if(CGI->buildh->buildings[tid][bid]->resources[i]) resamount++;
int resamount=0;
for(int i=0;i<7;i++) {
if(CGI->buildh->buildings[tid][bid]->resources[i]) {
resamount++;
}
}
int ah = (resamount>4) ? 304 : 341;
int cn=-1, it=0;
int row1w = std::min(resamount,4) * 32 + (std::min(resamount,4)-1) * 45,
@ -1286,9 +1299,9 @@ CHallInterface::CBuildWindow::~CBuildWindow()
CFortScreen::~CFortScreen()
{
LOCPLINT->curint->subInt = NULL;
for(int i=0;i<crePics.size();i++)
for(size_t i=0;i<crePics.size();i++)
delete crePics[i];
for (int i=0;i<recAreas.size();i++)
for (size_t i=0;i<recAreas.size();i++)
delete recAreas[i];
SDL_FreeSurface(bg);
delete exit;
@ -1312,7 +1325,7 @@ void CFortScreen::activate()
{
LOCPLINT->curint->subInt = this;
exit->activate();
for (int i=0;i<recAreas.size();i++)
for (size_t i=0;i<recAreas.size(); ++i)
{
recAreas[i]->activate();
}
@ -1323,7 +1336,7 @@ void CFortScreen::activate()
void CFortScreen::deactivate()
{
exit->deactivate();
for (int i=0;i<recAreas.size();i++)
for (size_t i=0;i<recAreas.size();i++)
{
recAreas[i]->deactivate();
}
@ -1435,7 +1448,7 @@ void CFortScreen::RecArea::clickLeft (tribool down)
if(!down && pressedL)
{
LOCPLINT->curint->deactivate();
CRecrutationWindow *rw = LOCPLINT->castleInt->showRecruitmentWindow(bid);
//CRecrutationWindow *rw = LOCPLINT->castleInt->showRecruitmentWindow(bid); //TODO use me
}
ClickableL::clickLeft(down);
}
@ -1467,10 +1480,10 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
positions[3] += genRect(61,83,183,42), genRect(61,83,183,148), genRect(61,83,183,253);
positions[4] += genRect(61,83,491,325), genRect(61,83,591,325);
blitAt(view,332,76,bg);
for(int i=0; i<owner->town->town->mageLevel; i++)
for(size_t i=0; i<owner->town->town->mageLevel; i++)
{
int sp = owner->town->spellsAtLevel(i+1,false);
for(int j=0; j<sp; j++)
size_t sp = owner->town->spellsAtLevel(i+1,false); //spell at level with -1 hmmm?
for(size_t j=0; j<sp; j++)
{
if(i<owner->town->mageGuildLevel() && owner->town->spells[i].size()>j)
{
@ -1485,7 +1498,7 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
}
}
SDL_FreeSurface(view);
for(int i=0;i<spells.size();i++)
for(size_t i=0;i<spells.size();i++)
{
spells[i].pos.x += pos.x;
spells[i].pos.y += pos.y;
@ -1505,7 +1518,7 @@ void CMageGuildScreen::close()
LOCPLINT->castleInt->subInt = NULL;
LOCPLINT->castleInt->activate();
}
void CMageGuildScreen::show(SDL_Surface * to)
void CMageGuildScreen::show(SDL_Surface * to) //TODO use me
{
blitAt(bg,pos);
resdatabar.show();
@ -1517,15 +1530,17 @@ void CMageGuildScreen::activate()
LOCPLINT->objsToBlit += this;
LOCPLINT->castleInt->subInt = this;
exit->activate();
for(int i=0;i<spells.size();i++)
for(size_t i=0;i<spells.size();i++) {
spells[i].activate();
}
}
void CMageGuildScreen::deactivate()
{
LOCPLINT->objsToBlit -= this;
exit->deactivate();
for(int i=0;i<spells.size();i++)
for(size_t i=0;i<spells.size();i++) {
spells[i].deactivate();
}
}
void CMageGuildScreen::Scroll::clickLeft (tribool down)
{

View File

@ -1,6 +1,13 @@
#ifndef CCASTLEINTERFACE_H
#define CCASTLEINTERFACE_H
#ifdef _MSC_VER
#pragma once
#endif
#include "global.h"
#include "SDL.h"
#include <SDL.h>
#include "CPlayerInterface.h"
//#include "boost/tuple/tuple.hpp"
class CGTownInstance;
@ -220,4 +227,5 @@ public:
void show(SDL_Surface * to=NULL);
void activate();
void deactivate();
};
};
#endif //CCASTLEINTERFACE_H

View File

@ -43,7 +43,7 @@ void CCursorHandler::draw1()
x-=12;
y-=10;
}
SDL_BlitSurface(screen,&genRect(32,32,x,y),help,&genRect(32,32,0,0));
SDL_BlitSurface(screen, &genRect(32,32,x,y), help, &genRect(32,32,0,0));
blitAt(cursors[mode]->ourImages[number].bitmap,x,y);
}
void CCursorHandler::draw2()

View File

@ -27,8 +27,8 @@ CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname)
char temp[50];
dllname = "AI/"+dllname;
CGlobalAI * ret=NULL;
CGlobalAI*(*getAI)();
void(*getName)(char*);
CGlobalAI*(*getAI)(); //TODO use me
void(*getName)(char*); //TODO use me
#ifdef _WIN32
HINSTANCE dll = LoadLibraryA(dllname.c_str());

View File

@ -131,23 +131,25 @@ CHeroWindow::~CHeroWindow()
delete leftArtRoll;
delete rightArtRoll;
for(int g=0; g<heroListMi.size(); ++g)
for(size_t g=0; g<heroListMi.size(); ++g) {
delete heroListMi[g];
}
if(curBack)
if(curBack) {
SDL_FreeSurface(curBack);
}
delete flags;
delete garInt;
delete ourBar;
for(int g=0; g<artWorn.size(); ++g)
for(size_t g=0; g<artWorn.size(); ++g)
{
delete artWorn[g];
}
artWorn.clear();
for(int g=0; g<backpack.size(); ++g)
for(size_t g=0; g<backpack.size(); ++g)
{
delete backpack[g];
}
@ -156,11 +158,11 @@ CHeroWindow::~CHeroWindow()
delete portraitArea;
delete expArea;
delete spellPointsArea;
for(int v=0; v<primSkillAreas.size(); ++v)
for(size_t v=0; v<primSkillAreas.size(); ++v)
{
delete primSkillAreas[v];
}
for(int v=0; v<secSkillAreas.size(); ++v)
for(size_t v=0; v<secSkillAreas.size(); ++v)
{
delete secSkillAreas[v];
}
@ -184,11 +186,11 @@ void CHeroWindow::show(SDL_Surface *to)
garInt->show();
ourBar->show();
for(int d=0; d<artWorn.size(); ++d)
for(size_t d=0; d<artWorn.size(); ++d)
{
artWorn[d]->show(to);
}
for(int d=0; d<backpack.size(); ++d)
for(size_t d=0; d<backpack.size(); ++d)
{
backpack[d]->show(to);
}
@ -223,11 +225,11 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
garInt->update = false;
gar4button->callback = boost::bind(&CGarrisonInt::splitClick,garInt);//actualization of callback function
for(int g=0; g<primSkillAreas.size(); ++g)
for(size_t g=0; g<primSkillAreas.size(); ++g)
{
primSkillAreas[g]->bonus = hero->getPrimSkillLevel(g);
}
for(int g=0; g<hero->secSkills.size(); ++g)
for(size_t g=0; g<hero->secSkills.size(); ++g)
{
secSkillAreas[g]->type = hero->secSkills[g].first;
secSkillAreas[g]->bonus = hero->secSkills[g].second;
@ -244,11 +246,11 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
sprintf(bufor, CGI->generaltexth->allTexts[205].substr(1, CGI->generaltexth->allTexts[205].size()-2).c_str(), hero->name.c_str(), hero->mana, hero->getPrimSkillLevel(3)*10);
spellPointsArea->text = std::string(bufor);
for(int g=0; g<artWorn.size(); ++g)
for(size_t g=0; g<artWorn.size(); ++g)
{
delete artWorn[g];
}
for(int g=0; g<backpack.size(); ++g)
for(size_t g=0; g<backpack.size(); ++g)
{
delete backpack[g];
}
@ -273,7 +275,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
artWorn[g]->ourWindow = this;
}
for(int g=0; g<artWorn.size(); ++g)
for(size_t g=0; g<artWorn.size(); ++g)
{
artWorn[g]->slotID = g;
if(artWorn[g]->ourArt)
@ -287,7 +289,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
}
}
for(int s=0; s<5; ++s)
for(size_t s=0; s<5; ++s)
{
CArtPlace * add;
if( s < curHero->artifacts.size() )
@ -304,10 +306,12 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
add->pos.x = pos.x + 403 + 46*s;
add->pos.y = pos.y + 365;
add->pos.h = add->pos.w = 44;
if(s<hero->artifacts.size() && hero->artifacts[s])
if(s<hero->artifacts.size() && hero->artifacts[s]) {
add->text = hero->getArt(19+s)->Description();
else
}
else {
add->text = std::string();
}
add->ourWindow = this;
add->slotID = 19+s;
backpack.push_back(add);
@ -347,12 +351,12 @@ void CHeroWindow::quit()
SDL_FreeSurface(curBack);
curBack = NULL;
for(int g=0; g<artWorn.size(); ++g)
for(size_t g=0; g<artWorn.size(); ++g)
{
delete artWorn[g];
artWorn[g] = NULL;
}
for(int g=0; g<backpack.size(); ++g)
for(size_t g=0; g<backpack.size(); ++g)
{
delete backpack[g];
backpack[g] = NULL;
@ -379,27 +383,27 @@ void CHeroWindow::activate()
garInt->activate();
LOCPLINT->statusbar = ourBar;
for(int v=0; v<primSkillAreas.size(); ++v)
for(size_t v=0; v<primSkillAreas.size(); ++v)
{
primSkillAreas[v]->activate();
}
for(int v=0; v<curHero->secSkills.size(); ++v)
for(size_t v=0; v<curHero->secSkills.size(); ++v)
{
secSkillAreas[v]->activate();
}
redrawCurBack();
for(int f=0; f<artWorn.size(); ++f)
for(size_t f=0; f<artWorn.size(); ++f)
{
if(artWorn[f])
artWorn[f]->activate();
}
for(int f=0; f<backpack.size(); ++f)
for(size_t f=0; f<backpack.size(); ++f)
{
if(backpack[f])
backpack[f]->activate();
}
for(int e=0; e<heroListMi.size(); ++e)
for(size_t e=0; e<heroListMi.size(); ++e)
{
heroListMi[e]->activate();
}
@ -423,26 +427,26 @@ void CHeroWindow::deactivate()
garInt->deactivate();
for(int v=0; v<primSkillAreas.size(); ++v)
for(size_t v=0; v<primSkillAreas.size(); ++v)
{
primSkillAreas[v]->deactivate();
}
for(int v=0; v<curHero->secSkills.size(); ++v)
for(size_t v=0; v<curHero->secSkills.size(); ++v)
{
secSkillAreas[v]->deactivate();
}
for(int f=0; f<artWorn.size(); ++f)
for(size_t f=0; f<artWorn.size(); ++f)
{
if(artWorn[f])
artWorn[f]->deactivate();
}
for(int f=0; f<backpack.size(); ++f)
for(size_t f=0; f<backpack.size(); ++f)
{
if(backpack[f])
backpack[f]->deactivate();
}
for(int e=0; e<heroListMi.size(); ++e)
for(size_t e=0; e<heroListMi.size(); ++e)
{
heroListMi[e]->deactivate();
}
@ -464,7 +468,7 @@ void CHeroWindow::leftArtRoller()
{
backpackPos+=curHero->artifacts.size()-1; //set new offset
for(int s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
for(size_t s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
{
backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]];
if(backpack[s]->ourArt)
@ -481,7 +485,7 @@ void CHeroWindow::rightArtRoller()
{
backpackPos+=1; //set new offset
for(int s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
for(size_t s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
{
backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ] ];
if(backpack[s]->ourArt)
@ -665,7 +669,7 @@ void CHeroWindow::redrawCurBack()
CSDL_Ext::printAt(manastr.str(), 212, 247, GEOR16, zwykly, curBack);
}
CArtPlace::CArtPlace(const CArtifact* Art): ourArt(Art), active(false), clicked(false)/*,
CArtPlace::CArtPlace(const CArtifact* Art): active(false), clicked(false), ourArt(Art)/*,
spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false),
warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false),
misc5(false), feet(false), lRing(false), rRing(false), torso(false),
@ -733,7 +737,7 @@ void CArtPlace::clickLeft(boost::logic::tribool down)
else
{
int backID = -1;
for(int g=0; g<ourWindow->backpack.size(); ++g)
for(size_t g=0; g<ourWindow->backpack.size(); ++g)
{
if(ourWindow->backpack[g]==this) //if user wants to put something to backpack
{

View File

@ -1,4 +1,10 @@
#ifndef CHEROWINDOW_H
#define CHEROWINDOW_H
#ifdef _MSC_VER
#pragma once
#endif
#include "CPlayerInterface.h"
class AdventureMapButton;
@ -127,3 +133,4 @@ public:
friend void CArtPlace::clickLeft(tribool down);
friend class CPlayerInterface;
};
#endif //CHEROWINDOW_H

12
CMT.cpp
View File

@ -11,8 +11,8 @@
#include <boost/interprocess/mapped_region.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/thread.hpp>
#include "SDL_ttf.h"
#include "SDL_mixer.h"
#include <SDL_ttf.h>
#include <SDL_mixer.h>
#include "SDL_Extensions.h"
#include "SDL_framerate.h"
#include "CGameInfo.h"
@ -45,6 +45,8 @@
#include "lib/Connection.h"
#include "lib/Interprocess.h"
#include "lib/VCMI_Lib.h"
#include <cstdlib>
std::string NAME = NAME_VER + std::string(" (client)");
DLL_EXPORT void initDLL(CLodHandler *b);
SDL_Surface * screen, * screen2;
@ -210,7 +212,7 @@ int main(int argc, char** argv)
LOCPLINT->pim->lock();
SDL_Delay(750);
tlog0 << "Ending...\n";
exit(0);
exit(EXIT_SUCCESS);
}
eventsM.lock();
events.push(ev);
@ -232,11 +234,11 @@ void processCommand(const std::string &message, CClient *&client)
readed >> cn;
int3 src, dst;
int heronum;
// int heronum;//TODO use me
int3 dest;
if(message==std::string("die, fool"))
exit(0);
exit(EXIT_SUCCESS);
else if(cn==std::string("activate"))
{
int what;

View File

@ -51,12 +51,12 @@ void CMessage::init()
piecesOfBox.push_back(n);
if (i==1)
{
for (int j=0;j<bluePieces->ourImages.size();j++)
for (size_t j=0;j<bluePieces->ourImages.size();++j)
{
piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
}
}
for (int j=0;j<bluePieces->ourImages.size();j++)
for (size_t j=0;j<bluePieces->ourImages.size();++j)
{
graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i);
piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
@ -74,7 +74,7 @@ void CMessage::dispose()
{
for (int i=0;i<PLAYER_LIMIT;i++)
{
for (int j=0;j<piecesOfBox[i].size();j++)
for (size_t j=0; j<piecesOfBox[i].size(); ++j)
{
SDL_FreeSurface(piecesOfBox[i][j]);
}
@ -89,21 +89,22 @@ SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for
SDL_Surface * ret = SDL_CreateRGBSurface(screen->flags, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
for (int i=0; i<h; i+=background->h)//background
{
for (int j=0; j<w; j+=background->w-1)
SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i));
for (int j=0; j<w; j+=background->w-1) {
SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i)); //FIXME taking address of temporary
}
}
drawBorder(playerColor, ret, w, h);
return ret;
}
std::vector<std::string> * CMessage::breakText(std::string text, int line, bool userBreak, bool ifor)
std::vector<std::string> * CMessage::breakText(std::string text, size_t line, bool userBreak, bool ifor) //TODO userBreak -- use me
{
std::vector<std::string> * ret = new std::vector<std::string>();
while (text.length()>line)
{
int whereCut = -1, braces=0;
bool pom = true, opened=false;
for (int i=0; i<line+braces; i++)
for (size_t i=0; i<line+braces; i++)
{
if (text[i]==10) //end of line sign
{
@ -111,7 +112,7 @@ std::vector<std::string> * CMessage::breakText(std::string text, int line, bool
pom=false;
break;
}
else if (ifor && (text[i]=='{') || (text[i]=='}')) // ignore braces
else if (ifor && ((text[i]=='{') || (text[i]=='}'))) // ignore braces
{
if (text[i]=='{')
opened=true;
@ -141,7 +142,7 @@ std::vector<std::string> * CMessage::breakText(std::string text, int line, bool
text.insert(0,"{");
}
}
for (int i=0;i<text.length();i++)
for (size_t i=0;i<text.length();i++)
{
if (text[i]==10) //end of line sign
{
@ -152,7 +153,7 @@ std::vector<std::string> * CMessage::breakText(std::string text, int line, bool
}
if (text.length() > 0)
ret->push_back(text);
for (int i=0; i<ret->size(); i++)
for (size_t i=0; i<ret->size(); i++)
{
boost::algorithm::trim((*ret)[i]);
}
@ -161,11 +162,11 @@ std::vector<std::string> * CMessage::breakText(std::string text, int line, bool
std::pair<int, int> CMessage::getMaxSizes(std::vector< std::vector<SComponent*> > * komp)
{
std::pair<int,int> ret;
for (int i=0;i<komp->size();i++)
for (size_t i=0;i<komp->size();i++)
{
int sumaw=0;
int maxh=0;
for(int j=0;j<(*komp)[i].size();j++)
for(size_t j=0;j<(*komp)[i].size();j++)
{
sumaw += (*komp)[i][j]->getImg()->w;
if (maxh < (*komp)[i][j]->getImg()->h)
@ -184,10 +185,10 @@ std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> >
std::pair<int,int> ret;
ret.first = -1;
ret.second=0;
for (int i=0; i<txtg->size();i++) //szukamy najszerszej linii i lacznej wysokosci
for (size_t i=0; i<txtg->size();i++) //szukamy najszerszej linii i lacznej wysokosci
{
int lw=0;
for (int j=0;j<(*txtg)[i].size();j++)
for (size_t j=0;j<(*txtg)[i].size();j++)
{
lw+=(*txtg)[i][j]->w;
ret.second+=(*txtg)[i][j]->h;
@ -201,16 +202,16 @@ std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> >
}
SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret)
{
for (int i=0; i<txtg->size();i++)
for (size_t i=0; i<txtg->size();i++)
{
int lw=0;
for (int j=0;j<(*txtg)[i].size();j++)
for (size_t j=0;j<(*txtg)[i].size();j++)
lw+=(*txtg)[i][j]->w; //lw - laczna szerokosc linii
int pw = ret->w/2;
pw -= lw/2; //poczatek tekstu (x)
int tw = pw;
for (int j=0;j<(*txtg)[i].size();j++) //blit text
for (size_t j=0;j<(*txtg)[i].size();j++) //blit text
{
blitAt((*txtg)[i][j],tw,curh+i*19,ret);
tw+=(*txtg)[i][j]->w;
@ -223,15 +224,17 @@ SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > *
SDL_Surface * CMessage::blitCompsOnSur(std::vector<SComponent*> & comps, int maxw, int inter, int & curh, SDL_Surface * ret)
{
std::vector<std::string> * brdtext;
if (comps.size())
if (comps.size()) {
brdtext = breakText(comps[0]->subtitle,12,true,true);
else
}
else {
brdtext = NULL;
}
comps[0]->pos.x = (ret->w/2) - ((comps[0]->getImg()->w)/2);
comps[0]->pos.y = curh;
blitAt(comps[0]->getImg(),comps[0]->pos.x,comps[0]->pos.y,ret);
curh += comps[0]->getImg()->h + 5; //obrazek + przerwa
for (int i=0; i<brdtext->size();i++) //descr.
for (size_t i=0; i < brdtext->size(); ++i) //descr.
{
SDL_Surface * tesu = TTF_RenderText_Blended(GEOR13,(*brdtext)[i].c_str(),zwykly);
blitAt(tesu,((comps[0]->getImg()->w - tesu->w)/2)+comps[0]->pos.x,curh,ret);
@ -242,23 +245,26 @@ SDL_Surface * CMessage::blitCompsOnSur(std::vector<SComponent*> & comps, int max
}
SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * _or, std::vector< std::vector<SComponent*> > * komp, int inter, int &curh, SDL_Surface *ret)
{
for (int i=0;i<komp->size();i++)
for (size_t i=0;i<komp->size();i++)
{
int totalw=0, maxh=0;
for(int j=0;j<(*komp)[i].size();j++)
for(size_t j=0;j<(*komp)[i].size();j++)
{
totalw+=(*komp)[i][j]->getImg()->w;
if(maxh<(*komp)[i][j]->getImg()->h)
if(maxh<(*komp)[i][j]->getImg()->h) {
maxh=(*komp)[i][j]->getImg()->h;
}
}
if(_or)
if(_or) {
totalw += (inter*2+_or->w) * ((*komp)[i].size() - 1);
else
}
else {
totalw += (inter) * ((*komp)[i].size() - 1);
}
curh+=maxh/2;
int curw = (ret->w/2)-(totalw/2);
for(int j=0;j<(*komp)[i].size();j++)
for(size_t j=0;j<(*komp)[i].size();j++)
{
blitAt((*komp)[i][j]->getImg(),curw,curh-((*komp)[i][j]->getImg()->h/2),ret);
(*komp)[i][j]->pos.x = curw;
@ -285,11 +291,11 @@ std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::st
{
std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
txtg->resize(brtext->size());
for (int i=0; i<brtext->size();i++) //foreach line
for (size_t i=0; i<brtext->size();i++) //foreach line
{
while((*brtext)[i].length()) //jesli zostalo cos
{
int z=0; bool br=true;
size_t z=0; bool br=true;
while( ((*brtext)[i][z]) != ('{') )
{
if (z >= (((*brtext)[i].length())-1))
@ -339,7 +345,7 @@ std::vector< std::vector<SComponent*> > * CMessage::breakComps(std::vector<SComp
ret->resize(1);
int rvi = 0;
int curw = 0;
for(int i=0;i<comps.size();i++)
for(size_t i=0;i<comps.size();i++)
{
curw += (comps[i]->getImg()->w + 12 + (_or ? _or->w : 0));
if (curw > maxw)
@ -421,17 +427,17 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int
{
curh += 20; //to buttton
int bw = 20*(ret->buttons.size()-1); //total width of buttons - start with distance between them
for(int i=0; i<ret->buttons.size(); i++) //and add buttons width
for(size_t i=0; i<ret->buttons.size(); i++) //and add buttons width
bw+=ret->buttons[i]->imgs[0][0]->w;
bw = (ret->bitmap->w/2) - (bw/2);
for(int i=0; i<ret->buttons.size(); i++)
for(size_t i=0; i<ret->buttons.size(); i++)
{
ret->buttons[i]->pos.x = bw + ret->pos.x;
ret->buttons[i]->pos.y = curh + ret->pos.y;
bw += ret->buttons[i]->imgs[0][0]->w + 20;
}
}
for(int i=0; i<ret->components.size(); i++)
for(size_t i=0; i<ret->components.size(); i++)
{
ret->components[i]->pos.x += ret->pos.x;
ret->components[i]->pos.y += ret->pos.y;
@ -510,7 +516,7 @@ SDL_Surface * CMessage::genMessage
SDL_FreeSurface(titleText);
}
//draw text
for (int i=0; i<tekst->size(); i++)
for (size_t i=0; i<tekst->size(); i++)
{
int by = 37+i*21;
if (title.length()) by+=40;

View File

@ -3,7 +3,7 @@
#include "global.h"
#include <SDL_ttf.h>
#include "SDL.h"
#include <SDL.h>
#include "CPreGame.h"
enum EWindowType {infoOnly, infoOK, yesOrNO};
@ -41,7 +41,7 @@ public:
static SDL_Surface * drawBox1(int w, int h, int playerColor=1);
static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0);
static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55);
static std::vector<std::string> * breakText(std::string text, int line=30, bool userBreak=true, bool ifor=true); //line - chars per line
static std::vector<std::string> * breakText(std::string text, size_t line=30, bool userBreak=true, bool ifor=true); //line - chars per line
CMessage();
static void init();
static void dispose();

View File

@ -49,28 +49,33 @@ CPath * CPathfinder::getPath(int3 src, int3 dest, const CGHeroInstance * hero, u
//graph initialization
graph.resize(CGI->mh->sizes.x);
for(int i=0; i<graph.size(); ++i)
for(size_t i=0; i<graph.size(); ++i)
{
graph[i].resize(CGI->mh->sizes.y);
for(int j=0; j<graph[i].size(); ++j)
for(size_t j=0; j<graph[i].size(); ++j)
{
graph[i][j].accesible = !CGI->mh->ttiles[i][j][src.z].tileInfo->blocked;
if(i==dest.x && j==dest.y && CGI->mh->ttiles[i][j][src.z].tileInfo->visitable)
if(i==dest.x && j==dest.y && CGI->mh->ttiles[i][j][src.z].tileInfo->visitable) {
graph[i][j].accesible = true; //for allowing visiting objects
}
graph[i][j].dist = -1;
graph[i][j].theNodeBefore = NULL;
graph[i][j].visited = false;
graph[i][j].coord.x = i;
graph[i][j].coord.y = j;
graph[i][j].coord.z = dest.z;
if (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==rock)
if (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==rock) {
graph[i][j].accesible = false;
if ((blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==water))
}
if ((blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==water)) {
graph[i][j].accesible = false;
else if ((!blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype!=water))
}
else if ((!blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype!=water)) {
graph[i][j].accesible = false;
if(graph[i][j].accesible)
}
if(graph[i][j].accesible) {
graph[i][j].accesible = CGI->state->players[hero->tempOwner].fogOfWarMap[i][j][src.z];
}
}
}
@ -81,7 +86,7 @@ CPath * CPathfinder::getPath(int3 src, int3 dest, const CGHeroInstance * hero, u
std::queue<CPathNode> mq;
mq.push(graph[src.x][src.y]);
unsigned int curDist = 4000000000;
unsigned int curDist = 4000000000; //XXX 2 147 483 648 // only in C90 //but numeric limit shows 0-4294967295...confused
while(!mq.empty())
{

View File

@ -311,14 +311,16 @@ CGarrisonInt::~CGarrisonInt()
{
if(sup)
{
for(int i=0;i<sup->size();i++)
for(size_t i=0;i<sup->size();i++) {
delete (*sup)[i];
}
delete sup;
}
if(sdown)
{
for(int i=0;i<sdown->size();i++)
delete (*sdown)[i];
for(size_t i=0;i<sdown->size();i++) {
delete (*sdown)[i]; //XXX what about smartpointers? boost or auto_ptr from std
}
delete sdown;
}
}
@ -327,15 +329,18 @@ void CGarrisonInt::show()
{
if(sup)
{
for(int i = 0; i<sup->size(); i++)
if((*sup)[i])
for(size_t i = 0; i<sup->size(); i++)
if((*sup)[i]) {
(*sup)[i]->show();
}
}
if(sdown)
{
for(int i = 0; i<sdown->size(); i++)
if((*sdown)[i])
for(size_t i = 0; i<sdown->size(); i++) {
if((*sdown)[i]){
(*sdown)[i]->show();
}
}
}
}
void CGarrisonInt::deactiveteSlots()

View File

@ -1,11 +1,11 @@
#include "stdafx.h"
#include "CPreGame.h"
#include "hch/CDefHandler.h"
#include "SDL.h"
#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
#include "boost/algorithm/string.hpp"
#include <SDL.h>
#include <boost/filesystem.hpp> // includes all needed Boost.Filesystem declarations
#include <boost/algorithm/string.hpp>
//#include "boost/foreach.hpp"
#include "zlib.h"
#include <zlib.h>
#include "timeHandler.h"
#include <sstream>
#include "SDL_Extensions.h"
@ -19,9 +19,12 @@
#include "client/Graphics.h"
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <cstdlib>
extern SDL_Surface * screen;
extern SDL_Color tytulowy, tlo, zwykly ;
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
#ifdef min
#undef min
#endif
@ -270,7 +273,10 @@ void Slider::handleIt(SDL_Event sEvent)
case (SDLK_DOWN):
CPG->ourScenSel->mapsel.moveByOne(false);
break;
}
default:
//TODO do something nasty here like logs entry..
break;
}
}
else if (moving && sEvent.type==SDL_MOUSEMOTION)
{
@ -538,13 +544,13 @@ void Options::OptionSwitch::press(bool down)
void Options::PlayerFlag::press(bool down)
{
HighButton::press(down);
int i=0;
size_t i=0;
for(;i<CPG->ret.playerInfos.size();i++)
if(CPG->ret.playerInfos[i].color==color)
break;
if (CPG->ret.playerInfos[i].human || (!CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].players[CPG->ret.playerInfos[i].color].canHumanPlay))
return; //if this is already human player, or if human is forbidden
int j=0;
size_t j=0;
for(;j<CPG->ret.playerInfos.size();j++)
if(CPG->ret.playerInfos[j].human)
break;
@ -583,7 +589,7 @@ void Options::showIcon (int what, int nr, bool abs) //what: -1=castle, 0=hero, 1
else
{
ab = nr;
for (int i=0; i<CPG->ret.playerInfos.size();i++)
for (size_t i=0; i<CPG->ret.playerInfos.size();++i)
{
if (CPG->ret.playerInfos[i].color==nr)
{
@ -661,11 +667,15 @@ void Options::showIcon (int what, int nr, bool abs) //what: -1=castle, 0=hero, 1
}
Options::~Options()
{
if (!inited) return;
for (int i=0; i<bgs.size();i++)
if (!inited) {
return;
}
for (size_t i=0; i<bgs.size();i++) {
SDL_FreeSurface(bgs[i]);
for (int i=0; i<flags.size();i++)
}
for (size_t i=0; i<flags.size();i++) {
delete flags[i];
}
SDL_FreeSurface(bg);
SDL_FreeSurface(rHero);
SDL_FreeSurface(rCastle);
@ -716,7 +726,7 @@ void Options::show()
MapSel & ms = CPG->ourScenSel->mapsel;
blitAt(bg,3,6);
CPG->ourScenSel->listShowed=false;
for (int i=0;i<CPG->btns.size();i++)
for (size_t i=0; i < CPG->btns.size(); ++i)
{
if (CPG->btns[i]->ID!=10) //leave only right panel buttons
{
@ -728,12 +738,13 @@ void Options::show()
CSDL_Ext::printAtMiddle("Advanced Options",225,35,GEORXX);
CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[521],224,544,GEOR13); // Player Turn Duration
int playersSoFar=0;
for (int i=0;i<PLAYER_LIMIT;i++)
for (size_t i=0; i < PLAYER_LIMIT; ++i)
{
if (!(ms.ourMaps[ms.selected].players[i].canComputerPlay || ms.ourMaps[ms.selected].players[i].canComputerPlay))
continue;
for (int hi=0; hi<ms.ourMaps[ms.selected].players[i].heroesNames.size(); hi++)
for (size_t hi=0; hi<ms.ourMaps[ms.selected].players[i].heroesNames.size(); hi++) {
usedHeroes.insert(ms.ourMaps[ms.selected].players[i].heroesNames[hi].heroID);
}
blitAt(bgs[i],57,128+playersSoFar*50);
poptions.push_back(new PlayerOptions(playersSoFar,i));
poptions[poptions.size()-1]->nr=playersSoFar;
@ -755,14 +766,17 @@ void Options::show()
{
poptions[poptions.size()-1]->flag.show();
CPG->btns.push_back(&poptions[poptions.size()-1]->flag);
if (ms.ourMaps[ms.selected].players[i].canComputerPlay)
if (ms.ourMaps[ms.selected].players[i].canComputerPlay) {
CSDL_Ext::printAtMiddleWB("Human or CPU",86,163+playersSoFar*50,GEORM,7,zwykly);
else
}
else {
CSDL_Ext::printAtMiddleWB("Human",86,163+playersSoFar*50,GEORM,6,zwykly);
}
}
else
else {
CSDL_Ext::printAtMiddleWB("CPU",86,163+playersSoFar*50,GEORM,6,zwykly);
}
playersSoFar++;
}
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->allTexts[516],221,63,GEOR13,55,zwykly);
@ -771,8 +785,9 @@ void Options::show()
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[260].second),275,109,GEOR13,10);
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[261].second),354,109,GEOR13,10);
turnLength->activate();
for (int i=0;i<poptions.size();i++)
for (size_t i=0; i < poptions.size(); ++i) {
showIcon(-2,i,false);
}
for(int i=0;i<12;i++)
turnLength->moveDown();
//SDL_Flip(screen);
@ -780,23 +795,28 @@ void Options::show()
}
void Options::hide()
{
if (!showed) return;
if (!showed) {
return;
}
PreGameTab::hide();
for (int i=0; i<CPG->btns.size();i++)
for (size_t i=0; i < CPG->btns.size(); ++i)
if (CPG->btns[i]->ID==7)
CPG->btns.erase(CPG->btns.begin()+i--);
for (int i=0;i<poptions.size();i++)
for (size_t i=0;i<poptions.size();i++) {
delete poptions[i];
}
poptions.clear();
turnLength->deactivate();
}
MapSel::~MapSel()
{
SDL_FreeSurface(bg);
for (int i=0;i<scenImgs.size();i++)
for (size_t i=0; i < scenImgs.size(); ++i) {
SDL_FreeSurface(scenImgs[i]);
for (int i=0;i<scenList.size();i++)
}
for (size_t i=0; i < scenList.size(); ++i) {
delete scenList[i];
}
delete sFlags;
}
int MapSel::countWL()
@ -804,9 +824,12 @@ int MapSel::countWL()
int ret=0;
for (int i=0;i<ourMaps.size();i++)
{
if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
if (sizeFilter && ((ourMaps[i].width) != sizeFilter)) {
continue;
else ret++;
}
else {
ret++;
}
}
return ret;
}
@ -815,11 +838,14 @@ void MapSel::printMaps(int from, int to, int at, bool abs)
if (true)//
{
int help=-1;
for (int i=0;i<ourMaps.size();i++)
for (size_t i=0; i < ourMaps.size(); ++i)
{
if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
if (sizeFilter && ((ourMaps[i].width) != sizeFilter)) {
continue;
else help++;
}
else {
help++;
}
if (help==from)
{
from=i;
@ -1468,7 +1494,7 @@ void CPreGame::showScenSel()
ourScenSel->mapsel.select(0,false);
for (int i=0;i<btns.size();i++)
for (size_t i=0; i < btns.size(); ++i)
{
btns[i]->pos.w=btns[i]->imgs->ourImages[0].bitmap->w;
btns[i]->pos.h=btns[i]->imgs->ourImages[0].bitmap->h;
@ -1704,7 +1730,7 @@ void CPreGame::hideBox ()
SDL_BlitSurface(behindCurMes,NULL,screen,currentMessage);
SDL_UpdateRect
(screen,currentMessage->x,currentMessage->y,currentMessage->w,currentMessage->h);
for (int i=0;i<btns.size();i++)
for (size_t i=0; i < btns.size(); ++i)
{
if (btns[i]->ID==2)
{
@ -1742,7 +1768,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent)
if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
{
for (int i=0;i<btns.size(); i++)
for (size_t i=0; i < btns.size(); ++i)
{
if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
{
@ -1766,7 +1792,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent)
ourScenSel->pressed->press(false);
ourScenSel->pressed=NULL;
}
for (int i=0;i<btns.size(); i++)
for (size_t i=0; i < btns.size(); ++i)
{
if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
{
@ -1802,7 +1828,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent)
highlighted = NULL;
}
}
for (int i=0;i<btns.size();i++)
for (size_t i=0; i < btns.size(); ++i)
{
if (!btns[i]->highlightable)
continue;
@ -1829,11 +1855,12 @@ StartInfo CPreGame::runLoop()
menuItems * current = currentItems();
if(sEvent.type==SDL_QUIT)
{
exit(0);
exit(EXIT_SUCCESS);
return ret;
}
for (int i=0;i<interested.size();i++)
for (size_t i=0; i < interested.size(); ++i) {
interested[i]->handleIt(sEvent);
}
if (!current)
{
(this->*handleOther)(sEvent);
@ -1842,11 +1869,11 @@ StartInfo CPreGame::runLoop()
{
if (sEvent.key.keysym.sym==SDLK_q)
{
exit(0);
exit(EXIT_SUCCESS);
}
if(sEvent.key.keysym.sym==SDLK_F4 && (sEvent.key.keysym.mod & KMOD_LALT)) //Alt+F4
{
exit(0);
exit(EXIT_SUCCESS);
}
/*if (state==EState::newGame)
{
@ -1972,7 +1999,7 @@ StartInfo CPreGame::runLoop()
else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
{
mush->playClick();
for (int i=0;i<btns.size(); i++)
for (size_t i=0; i < btns.size(); ++i)
{
if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
{
@ -2010,7 +2037,7 @@ StartInfo CPreGame::runLoop()
}
else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
{
for (int i=0;i<btns.size(); i++)
for (size_t i=0; i < btns.size(); ++i)
{
if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
((Button*)btns[i])->fun();
@ -2312,12 +2339,38 @@ ScenSel::ScenSel()
selectedDiff=-77;
difficulty->gdzie = &selectedDiff;
for (int i=0; i<bScens.imgs->ourImages.size(); i++)
CSDL_Ext::printAt(CGI->generaltexth->allTexts[500],25+i,2+i,GEOR13,zwykly,bScens.imgs->ourImages[i].bitmap); //"Show Available Scenarios"
for (int i=0; i<bRandom.imgs->ourImages.size(); i++)
CSDL_Ext::printAt(CGI->generaltexth->allTexts[740],25+i,2+i,GEOR13,zwykly,bRandom.imgs->ourImages[i].bitmap);
for (int i=0; i<bOptions.imgs->ourImages.size(); i++)
CSDL_Ext::printAt(CGI->generaltexth->allTexts[501],25+i,2+i,GEOR13,zwykly,bOptions.imgs->ourImages[i].bitmap); //"Show Advanced Options"
for (size_t i=0; i < bScens.imgs->ourImages.size(); ++i) {
CSDL_Ext::printAt(
CGI->generaltexth->allTexts[500],
25+i,
2+i,
GEOR13,
zwykly,
bScens.imgs->ourImages[i].bitmap
); //"Show Available Scenarios"
}
for (size_t i=0; i < bRandom.imgs->ourImages.size(); ++i) {
CSDL_Ext::printAt(
CGI->generaltexth->allTexts[740],
25+i,
2+i,
GEOR13,
zwykly,
bRandom.imgs->ourImages[i].bitmap
);
}
for (size_t i=0; i < bOptions.imgs->ourImages.size(); ++i) {
CSDL_Ext::printAt(
CGI->generaltexth->allTexts[501],
25+i,
2+i,
GEOR13,
zwykly,
bOptions.imgs->ourImages[i].bitmap
); //"Show Advanced Options"
}
}
ScenSel::~ScenSel()

View File

@ -2,13 +2,15 @@
#define CPREGAME_H
#include "global.h"
#include <set>
#include "SDL.h"
#include <SDL.h>
#include "StartInfo.h"
#include "CMessage.h"
#include "map.h"
#include "hch/CMusicHandler.h"
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <cstdlib>
class CPreGame;
class CDefHandler;
extern CPreGame * CPG;
@ -94,7 +96,7 @@ public:
class CPoinGroup :public CGroup
{
public:
int * gdzie; //where (po polsku, bo by by這 s這wo kluczowe :/)
int * gdzie; //where (po polsku, bo by by�o s�owo kluczowe :/)
void setYour(IntSelBut * your);
};
struct IntSelBut: public Button
@ -268,7 +270,7 @@ public:
void scenHandleEv(SDL_Event& sEvent);
void begin(){run=false;ret.difficulty=ourScenSel->selectedDiff;};
void quitAskBox();
void quit(){exit(0);};
void quit(){exit(EXIT_SUCCESS);};
void initScenSel();
void showScenSel();
void showScenList();

View File

@ -1,3 +1,6 @@
#ifndef CTHREADHELPER_H
#define CTHREADHELPER_H
#include "global.h"
#include <boost/function.hpp>
#include <boost/thread.hpp>
@ -36,3 +39,4 @@ template <typename T> inline void setData(T * data, boost::function<T()> func)
(GET_DATA \
(CDefEssential*,DESTINATION,\
boost::function<CDefEssential*()>(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL))))
#endif //CTHREADHELPER_H

View File

@ -74,18 +74,19 @@ void CSDL_Ext::printAtMiddleWB(const std::string & text, int x, int y, TTF_Font
std::vector<std::string> * ws = CMessage::breakText(text,charpr);
std::vector<SDL_Surface*> wesu;
wesu.resize(ws->size());
for (int i=0;i<wesu.size();i++)
for (size_t i=0; i < wesu.size(); ++i) {
wesu[i]=TTF_RenderText_Blended(font,(*ws)[i].c_str(),kolor);
}
int tox=0, toy=0;
for (int i=0;i<wesu.size();i++)
for (size_t i=0; i < wesu.size(); ++i)
{
toy+=wesu[i]->h;
if (tox < wesu[i]->w)
tox=wesu[i]->w;
}
int evx, evy = y - (toy/2);
for (int i=0;i<wesu.size();i++)
for (size_t i=0; i < wesu.size(); ++i)
{
evx = (x - (tox/2)) + ((tox-wesu[i]->w)/2);
blitAt(wesu[i],evx,evy,dst);
@ -93,7 +94,7 @@ void CSDL_Ext::printAtMiddleWB(const std::string & text, int x, int y, TTF_Font
}
for (int i=0;i<wesu.size();i++)
for (size_t i=0; i < wesu.size(); ++i)
SDL_FreeSurface(wesu[i]);
delete ws;
}
@ -102,17 +103,17 @@ void CSDL_Ext::printAtWB(const std::string & text, int x, int y, TTF_Font * font
std::vector<std::string> * ws = CMessage::breakText(text,charpr);
std::vector<SDL_Surface*> wesu;
wesu.resize(ws->size());
for (int i=0;i<wesu.size();i++)
for (size_t i=0; i < wesu.size(); ++i)
wesu[i]=TTF_RenderText_Blended(font,(*ws)[i].c_str(),kolor);
int evy = y;
for (int i=0;i<wesu.size();i++)
for (size_t i=0; i < wesu.size(); ++i)
{
blitAt(wesu[i],x,evy,dst);
evy+=wesu[i]->h;
}
for (int i=0;i<wesu.size();i++)
for (size_t i=0; i < wesu.size(); ++i)
SDL_FreeSurface(wesu[i]);
delete ws;
}
@ -783,7 +784,7 @@ int readNormalNr (std::istream &in, int bytCon)
std::string CSDL_Ext::processStr(std::string str, std::vector<std::string> & tor)
{
for (int i=0;(i<tor.size())&&(boost::find_first(str,"%s"));i++)
for (size_t i=0; (i<tor.size())&&(boost::find_first(str,"%s")); ++i)
{
boost::replace_first(str,"%s",tor[i]);
}

View File

@ -55,7 +55,7 @@ void CPCXConv::convert()
BMPHeader bh;
BMPPalette pal[256];
Epcxformat format;
int fSize,i,y;
int fSize,y;//,i; //TODO use me 'i'
bool check1, check2;
unsigned char add;
int it=0;
@ -157,7 +157,7 @@ void CPCXConv::convert()
std::string temp = out.str();
bmp = new unsigned char[temp.length()];
bmps=temp.length();
for (int a=0;a<temp.length();a++)
for (size_t a=0;a<temp.length();++a)
{
bmp[a]=temp[a];
}
@ -169,7 +169,7 @@ SDL_Surface * CPCXConv::getSurface()
BMPHeader bh;
Epcxformat format;
int fSize,i,y;
int fSize,y;//,i; //TODO use me 'i'
bool check1, check2;
unsigned char add;
int it=0;
@ -314,7 +314,7 @@ SDL_Surface * BitmapHandler::loadBitmap(std::string fname, bool setKey)
CPCXConv cp;
pcx = new unsigned char[e->realSize];
memcpy(pcx,sign,3);
int res = fread((char*)pcx+3, 1, e->realSize-3, f);
int res = fread((char*)pcx+3, 1, e->realSize-3, f); //TODO use me
fclose(f);
cp.openPCX((char*)pcx,e->realSize);
return cp.getSurface();

View File

@ -1,4 +1,11 @@
#ifndef CBITMAPHANDLER_H
#define CBITMAPHANDLER_H
#ifdef _MSC_VER
#pragma once
#endif
#include "../global.h"
struct SDL_Surface;
class CLodHandler;
@ -36,4 +43,5 @@ namespace BitmapHandler
{
extern CLodHandler *bitmaph;
SDL_Surface * loadBitmap(std::string fname, bool setKey=false);
};
};
#endif //CBITMAPHANDLER_H

View File

@ -1,3 +1,5 @@
#ifndef CCONFIGHANDLER_H
#define CCONFIGHANDLER_H
#pragma once
#include "../global.h"
class CAdvMapInt;
@ -61,4 +63,5 @@ namespace config
~CConfigHandler(void);
};
}
extern config::CConfigHandler conf;
extern config::CConfigHandler conf;
#endif //CCONFIGHANDLER_H

View File

@ -14,7 +14,7 @@ void CCreatureAnimation::setType(int type)
if(SEntries[curFrame].group!=type) //rewind
{
int j=-1; //first frame in displayed group
for(int g=0; g<SEntries.size(); ++g)
for(size_t g=0; g<SEntries.size(); ++g)
{
if(SEntries[g].group==type && j==-1)
{
@ -22,14 +22,16 @@ void CCreatureAnimation::setType(int type)
break;
}
}
if(curFrame!=-1)
if(curFrame != -1) {
curFrame = j;
}
}
}
else
{
if(curFrame>=frames)
if(curFrame>=frames) {
curFrame = 0;
}
}
}
@ -67,8 +69,8 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL)
SEntries.push_back(SEntry());
SEntries[j].group = group;
}
int unknown2 = readNormalNr(i,4); i+=4;
int unknown3 = readNormalNr(i,4); i+=4;
int unknown2 = readNormalNr(i,4); i+=4; //TODO use me
int unknown3 = readNormalNr(i,4); i+=4; //TODO use me
for (j=0; j<totalInBlock; j++)
{
for (int k=0;k<13;k++) Buffer[k]=FDef[i+k];
@ -78,7 +80,7 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL)
for (j=0; j<totalInBlock; j++)
{
SEntries[totalEntries+j].offset = readNormalNr(i,4);
int unknown4 = readNormalNr(i,4); i+=4;
int unknown4 = readNormalNr(i,4); i+=4; //TODO use me
}
//totalEntries+=totalInBlock;
for(int hh=0; hh<totalInBlock; ++hh)
@ -132,7 +134,7 @@ void CCreatureAnimation::incrementFrame()
if(curFrame==SEntries.size() || SEntries[curFrame].group!=type) //rewind
{
int j=-1; //first frame in displayed group
for(int g=0; g<SEntries.size(); ++g)
for(size_t g=0; g<SEntries.size(); ++g)
{
if(SEntries[g].group==type)
{
@ -175,7 +177,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
unsigned char SegmentType, SegmentLength;
i=BaseOffset=SEntries[SIndex].offset;
int prSize=readNormalNr(i,4,FDef);i+=4;
int prSize=readNormalNr(i,4,FDef);i+=4;//TODO use me
int defType2 = readNormalNr(i,4,FDef);i+=4;
FullWidth = readNormalNr(i,4,FDef);i+=4;
FullHeight = readNormalNr(i,4,FDef);i+=4;
@ -261,7 +263,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
int CCreatureAnimation::framesInGroup(int group) const
{
int ret = 0; //number of frames in given group
for(int g=0; g<SEntries.size(); ++g)
for(size_t g=0; g<SEntries.size(); ++g)
{
if(SEntries[g].group == group)
++ret;
@ -276,10 +278,15 @@ CCreatureAnimation::~CCreatureAnimation()
delete [] RLEntries;
}
void CCreatureAnimation::putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const
{
if(palc!=0)
{
inline void CCreatureAnimation::putPixel(
SDL_Surface * dest,
const int & ftcp,
const BMPPalette & color,
const unsigned char & palc,
const bool & yellowBorder
) const {
if(palc!=0) {
Uint8 * p = (Uint8*)dest->pixels + ftcp*3;
if(palc > 7) //normal color
{

View File

@ -1,4 +1,10 @@
#ifndef CCREATUREANIMATION_H
#define CCREATUREANIMATION_H
#ifdef _MSC_VER
#pragma once
#endif
#include "../global.h"
#include "../CPlayerInterface.h"
#include "../hch/CDefHandler.h"
@ -19,12 +25,18 @@ private:
std::vector<SEntry> SEntries ;
std::string defName, curDir;
int readNormalNr (int pos, int bytCon, unsigned char * str=NULL) const;
void inline putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const;
void putPixel(
SDL_Surface * dest,
const int & ftcp,
const BMPPalette & color,
const unsigned char & palc,
const bool & yellowBorder
) const;
////////////
unsigned char * FDef; //animation raw data
unsigned int curFrame; //number of currently displayed frame
int curFrame; //number of currently displayed frame
unsigned int frames; //number of frames
public:
int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
@ -42,3 +54,4 @@ public:
int framesInGroup(int group) const; //retirns number of fromes in given group
};
#endif //CCREATUREANIMATION_H

View File

@ -65,9 +65,14 @@ void SpellbookInteractiveArea::deactivate()
Hoverable::deactivate();
}
CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero): selectedTab(4), spellSite(0), battleSpellsOnly(true)
CSpellWindow::CSpellWindow(
const SDL_Rect & myRect,
const CGHeroInstance * myHero):
battleSpellsOnly(true),
selectedTab(4),
spellSite(0)
{
//for testing only
//XXX for testing only
//mySpells = myHero->spells;
for(ui32 v=0; v<CGI->spellh->spells.size(); ++v)
{
@ -76,7 +81,7 @@ CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHer
}
for(int b=0; b<4; ++b) schoolLvls[b] = 0;
for(int b=0; b<myHero->secSkills.size(); ++b)
for(size_t b=0; b<myHero->secSkills.size(); ++b)
{
switch(myHero->secSkills[b].first)
{
@ -304,7 +309,7 @@ void CSpellWindow::fexitb()
{
deactivate();
for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
for(size_t g=0; g<LOCPLINT->objsToBlit.size(); ++g) //TODO what about
{
if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
{
@ -415,7 +420,7 @@ void CSpellWindow::show(SDL_Surface *to)
{
if(spellAreas[b]->mySpell == -1)
continue;
int b2 = -1;
//int b2 = -1; //TODO use me
blitAt(spells->ourImages[spellAreas[b]->mySpell].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
@ -540,19 +545,21 @@ void CSpellWindow::computeSpellsPerArea()
//applying
if(selectedTab == 4 || spellSite != 0)
{
for(int c=0; c<12; ++c)
for(size_t c=0; c<12; ++c)
{
if(c<spellsCurSite.size())
if(c<spellsCurSite.size()) {
spellAreas[c]->mySpell = spellsCurSite[c];
else
}
else {
spellAreas[c]->mySpell = -1;
}
}
}
else
{
spellAreas[0]->mySpell = -1;
spellAreas[1]->mySpell = -1;
for(int c=0; c<10; ++c)
for(size_t c=0; c<10; ++c)
{
if(c<spellsCurSite.size())
spellAreas[c+2]->mySpell = spellsCurSite[c];

View File

@ -1,4 +1,10 @@
#ifndef CSPELLWINDOW_H
#define CSPELLWINDOW_H
#ifdef _MSC_VER
#pragma once
#endif
#include "../global.h"
#include "../CPlayerInterface.h"
@ -86,3 +92,4 @@ public:
void deactivate();
void show(SDL_Surface * to = NULL);
};
#endif //CSPELLWINDOW_H

View File

@ -23,7 +23,7 @@ CSharedCond<std::set<IPack*> > mess(new std::set<IPack*>);
std::string toString(MetaString &ms)
{
std::string ret;
for(int i=0;i<ms.message.size();i++)
for(size_t i=0;i<ms.message.size();++i)
{
if(ms.message[i]>0)
{
@ -87,7 +87,7 @@ std::string toString(MetaString &ms)
}
}
}
for(int i=0;i<ms.replacements.size();i++)
for(size_t i=0; i < ms.replacements.size(); ++i)
{
ret.replace(ret.find("%s"),2,ms.replacements[i]);
}
@ -111,8 +111,9 @@ CClient::CClient(CConnection *con, StartInfo *si)
c >> pom8;
if(pom8) throw "Server cannot open the map!";
c << ui8(si->playerInfos.size()+1); //number of players + neutral
for(int i=0;i<si->playerInfos.size();i++)
for(size_t i=0;i<si->playerInfos.size();i++) {
c << ui8(si->playerInfos[i].color); //players
}
c << ui8(255); // neutrals
@ -144,14 +145,16 @@ CClient::CClient(CConnection *con, StartInfo *si)
CGI->mh->init();
tlog0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
for (int i=0; i<CGI->state->scenarioOps->playerInfos.size();i++) //initializing interfaces for players
for (size_t i=0; i<CGI->state->scenarioOps->playerInfos.size();++i) //initializing interfaces for players
{
ui8 color = gs->scenarioOps->playerInfos[i].color;
CCallback *cb = new CCallback(gs,color,this);
if(!gs->scenarioOps->playerInfos[i].human)
if(!gs->scenarioOps->playerInfos[i].human) {
playerint[color] = static_cast<CGameInterface*>(CAIHandler::getNewAI(cb,conf.cc.defaultAI));
else
}
else {
playerint[color] = new CPlayerInterface(color,i);
}
gs->currentPlayer = color;
playerint[color]->init(cb);
}
@ -200,8 +203,9 @@ void CClient::process(int what)
InfoWindow iw;
*serv >> iw;
std::vector<Component*> comps;
for(int i=0;i<iw.components.size();i++)
for(size_t i=0;i<iw.components.size();i++) {
comps.push_back(&iw.components[i]);
}
std::string str = toString(iw.text);
playerint[iw.player]->showInfoDialog(str,comps);
break;
@ -496,8 +500,9 @@ void CClient::process(int what)
*serv >> sd;
tlog5 << "Showing selection dialog " <<std::endl;
std::vector<Component*> comps;
for(int i=0;i<sd.components.size();i++)
for(size_t i=0; i < sd.components.size(); ++i) {
comps.push_back(&sd.components[i]);
}
std::string str = toString(sd.text);
playerint[sd.player]->showSelDialog(str,comps,sd.id);
break;
@ -508,8 +513,9 @@ void CClient::process(int what)
*serv >> ynd;
tlog5 << "Showing yes/no dialog " <<std::endl;
std::vector<Component*> comps;
for(int i=0;i<ynd.components.size();i++)
for(size_t i=0; i < ynd.components.size(); ++i) {
comps.push_back(&ynd.components[i]);
}
std::string str = toString(ynd.text);
playerint[ynd.player]->showYesNoDialog(str,comps,ynd.id);
break;

View File

@ -1,4 +1,10 @@
#ifndef CLIENT_H
#define CLIENT_H
#ifdef _MSC_VER
#pragma once
#endif
#include "../global.h"
#include <boost/thread.hpp>
struct StartInfo;
@ -56,3 +62,4 @@ public:
friend class CScriptCallback; //for objects scripts
friend void processCommand(const std::string &message, CClient *&client); //handling console
};
#endif //CLIENT_H

View File

@ -1,4 +1,10 @@
#ifndef FUNCTIONLIST_H
#define FUNCTIONLIST_H
#ifdef _MSC_VER
#pragma once
#endif
#include <boost/function.hpp>
template<typename Signature>
@ -38,15 +44,17 @@ public:
void operator()() const
{
std::vector<boost::function<Signature> > funcs2 = funcs; //backup
for(int i=0;i<funcs2.size(); i++)
for(size_t i=0;i<funcs2.size(); ++i) {
funcs2[i]();
}
}
template <typename Arg>
void operator()(const Arg & a) const
{
std::vector<boost::function<Signature> > funcs2 = funcs; //backup
for(int i=0;i<funcs2.size(); i++)
for(int i=0;i<funcs2.size(); i++) {
funcs2[i](a);
}
}
};
@ -88,7 +96,10 @@ public:
void operator()(const Arg & a) const
{
std::vector<boost::function<Signature> > funcs2 = funcs; //backup
for(int i=0;i<funcs2.size(); i++)
for(size_t i=0;i<funcs2.size(); ++i) {
funcs2[i](a);
}
}
};
};
#endif //FUNCTIONLISt_H

View File

@ -236,13 +236,13 @@ Graphics::Graphics()
//handling 32x32px imgs
smi->notFreeImgs = true;
for (int i=0; i<smi->ourImages.size(); i++)
for (size_t i=0; i<smi->ourImages.size(); ++i)
{
smallImgs[i-2] = smi->ourImages[i].bitmap;
}
delete smi;
smi2->notFreeImgs = true;
for (int i=0; i<smi2->ourImages.size(); i++)
for (size_t i=0; i<smi2->ourImages.size(); ++i)
{
bigImgs[i-2] = smi2->ourImages[i].bitmap;
}
@ -260,7 +260,7 @@ void Graphics::loadHeroPortraits()
std::string path;
of>>path;
portraitSmall.push_back(BitmapHandler::loadBitmap(path));
for(int ff=0; ff<path.size(); ++ff) //size letter is usually third one, but there are exceptions an it should fix the problem
for(size_t ff=0; ff<path.size(); ++ff) //size letter is usually third one, but there are exceptions an it should fix the problem
{
if(path[ff]=='S')
{
@ -279,7 +279,7 @@ void Graphics::loadHeroAnim(std::vector<CDefHandler **> & anims)
std::vector<std::pair<int,int> > rotations; //first - group number to be rotated1, second - group number after rotation1
rotations += std::make_pair(6,10), std::make_pair(7,11), std::make_pair(8,12), std::make_pair(1,13),
std::make_pair(2,14), std::make_pair(3,15);
for(int i=0; i<anims.size();i++)
for(size_t i=0; i<anims.size(); ++i)
{
std::stringstream nm;
nm << "AH" << std::setw(2) << std::setfill('0') << i << "_.DEF";
@ -312,7 +312,7 @@ void Graphics::loadHeroAnim(std::vector<CDefHandler **> & anims)
}
}
}
for(int ff=0; ff<(*anims[i])->ourImages.size(); ++ff)
for(size_t ff=0; ff<(*anims[i])->ourImages.size(); ++ff)
{
CSDL_Ext::alphaTransform((*anims[i])->ourImages[ff].bitmap);
}
@ -328,9 +328,9 @@ void Graphics::loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, s
rotations += std::make_pair(6,10), std::make_pair(7,11), std::make_pair(8,12);
for(int q=0; q<8; ++q)
{
for(int o=0; o<(this->*pr.first)[q]->ourImages.size(); ++o)
for(size_t o=0; o<(this->*pr.first)[q]->ourImages.size(); ++o)
{
for(int p=0;p<rotations.size();p++)
for(size_t p=0;p<rotations.size();p++)
{
if((this->*pr.first)[q]->ourImages[o].groupNumber==rotations[p].first)
{
@ -348,7 +348,7 @@ void Graphics::loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, s
}
if (mode)
{
for(int o=0; o<flags4[q]->ourImages.size(); ++o)
for(size_t o=0; o<flags4[q]->ourImages.size(); ++o)
{
if(flags4[q]->ourImages[o].groupNumber==1)
{
@ -388,7 +388,7 @@ void Graphics::loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, s
}
}
}
for(int ff=0; ff<(this->*pr.first)[q]->ourImages.size(); ++ff)
for(size_t ff=0; ff<(this->*pr.first)[q]->ourImages.size(); ++ff)
{
SDL_SetColorKey((this->*pr.first)[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB((this->*pr.first)[q]->ourImages[ff].bitmap->format, 0, 255, 255)
@ -402,7 +402,7 @@ void Graphics::loadHeroFlags()
{
using namespace boost::assign;
timeHandler th;
std::vector<CDefHandler *> Graphics::*point;
// std::vector<CDefHandler *> Graphics::*point; //TODO use me
std::pair<std::vector<CDefHandler *> Graphics::*, std::vector<const char *> > pr[4];
pr[0].first = &Graphics::flags1;
pr[0].second+=("ABF01L.DEF"),("ABF01G.DEF"),("ABF01R.DEF"),("ABF01D.DEF"),("ABF01B.DEF"),

View File

@ -1,5 +1,13 @@
#ifndef GRAPHICS_H
#define GRAPHICS_H
#ifdef _MSC_VER
#pragma once
#endif
#include "../global.h"
class CDefEssential;
struct SDL_Surface;
class CGHeroInstance;
@ -57,4 +65,5 @@ public:
void blueToPlayersAdv(SDL_Surface * sur, int player); //replaces blue interface colour with a color of player
};
extern Graphics * graphics;
extern Graphics * graphics;
#endif //GRAPHICS_H

View File

@ -1,6 +1,7 @@
#ifndef GLOBAL_H
#define GLOBAL_H
#include <iostream>
#include <algorithm> //std::find
#include <boost/logic/tribool.hpp>
#include <boost/cstdint.hpp>
typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes)
@ -127,7 +128,7 @@ namespace vstd
template <typename T1, typename T2>
int findPos(const std::vector<T1> & c, const T2 &s)
{
for(int i=0;i<c.size();i++)
for(size_t i=0; i < c.size(); ++i)
if(c[i] == s)
return i;
return -1;
@ -135,7 +136,7 @@ namespace vstd
template <typename T1, typename T2, typename Func>
int findPos(const std::vector<T1> & c, const T2 &s, const Func &f) //Func(T1,T2) must say if these elements matches
{
for(int i=0;i<c.size();i++)
for(size_t i=0; i < c.size(); ++i)
if(f(c[i],s))
return i;
return -1;
@ -214,13 +215,17 @@ public:
template<typename T>
CLogger<lvl> & operator<<(const T & data)
{
if(lvl < CONSOLE_LOGGING_LEVEL)
if(console)
if(lvl < CONSOLE_LOGGING_LEVEL) {
if(console) {
console->print(data,lvl);
else
}
else {
std::cout << data << std::flush;
if((lvl < FILE_LOGGING_LEVEL) && logfile)
}
}
if((lvl < FILE_LOGGING_LEVEL) && logfile) {
*logfile << data << std::flush;
}
return *this;
}
};
@ -232,6 +237,7 @@ extern DLL_EXPORT CLogger<3> tlog3; //yellow - minor warnings
extern DLL_EXPORT CLogger<4> tlog4; //white - detailed log info
extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info
//XXX pls dont - 'debug macros' are usually more trubble then its worth
#define HANDLE_EXCEPTION \
catch (const std::exception& e) { \
tlog1 << e.what() << std::endl; \

View File

@ -26,7 +26,7 @@ CDefHandler::~CDefHandler()
delete [] RWEntries;
if (notFreeImgs)
return;
for (int i=0; i<ourImages.size(); i++)
for (size_t i=0; i<ourImages.size(); ++i)
{
if (ourImages[i].bitmap)
{
@ -37,7 +37,7 @@ CDefHandler::~CDefHandler()
}
CDefEssential::~CDefEssential()
{
for(int i=0;i<ourImages.size();i++)
for(size_t i=0; i < ourImages.size(); ++i)
SDL_FreeSurface(ourImages[i].bitmap);
}
void CDefHandler::openDef(std::string name)
@ -103,7 +103,7 @@ void CDefHandler::openDef(std::string name)
{
SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4);
}
for(int i=0; i<SEntries.size(); ++i)
for(size_t i=0; i < SEntries.size(); ++i)
{
Cimage nimg;
nimg.bitmap = getSprite(i, FDef, palette);
@ -140,12 +140,14 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name)
totalEntries=0;
for (int z=0; z<totalBlocks; z++)
{
int unknown1 = readNormalNr(i,4,table); i+=4;
int unknown1 = readNormalNr(i,4,table); i+=4; //TODO use me
totalInBlock = readNormalNr(i,4,table); i+=4;
for (j=SEntries.size(); j<totalEntries+totalInBlock; j++)
SEntries.push_back(SEntry());
int unknown2 = readNormalNr(i,4,table); i+=4;
int unknown3 = readNormalNr(i,4,table); i+=4;
int unknown2 = readNormalNr(i,4,table); //TODO use me
i+=4;
int unknown3 = readNormalNr(i,4,table); //TODO use me
i+=4;
for (j=0; j<totalInBlock; j++)
{
for (int k=0;k<13;k++) Buffer[k]=table[i+k];
@ -155,7 +157,8 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name)
for (j=0; j<totalInBlock; j++)
{
SEntries[totalEntries+j].offset = readNormalNr(i,4,table);
int unknown4 = readNormalNr(i,4,table); i+=4;
int unknown4 = readNormalNr(i,4,table); //TODO use me
i+=4;
}
//totalEntries+=totalInBlock;
for(int hh=0; hh<totalInBlock; ++hh)
@ -169,7 +172,7 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name)
SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4);
}
RWEntries = new unsigned int[height];
for(int i=0; i<SEntries.size(); ++i)
for(size_t i=0; i < SEntries.size(); ++i)
{
Cimage nimg;
nimg.bitmap = getSprite(i, table, palette);
@ -248,12 +251,12 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet
LeftMargin, RightMargin, TopMargin,BottomMargin,
i, add, FullHeight,FullWidth,
TotalRowLength, // dlugosc przeczytanego segmentu
NextSpriteOffset, RowAdd;
RowAdd;//, NextSpriteOffset; //TODO use me
unsigned char SegmentType, SegmentLength, BL, BR;
unsigned char SegmentType, SegmentLength;//, BL, BR; //TODO use me
i=BaseOffset=SEntries[SIndex].offset;
int prSize=readNormalNr(i,4,FDef);i+=4;
// int prSize=readNormalNr(i,4,FDef);i+=4; //TODO use me
int defType2 = readNormalNr(i,4,FDef);i+=4;
FullWidth = readNormalNr(i,4,FDef);i+=4;
FullHeight = readNormalNr(i,4,FDef);i+=4;

View File

@ -1,7 +1,7 @@
#ifndef CMUSICHANDLER_H
#define CMUSICHANDLER_H
#include "SDL_mixer.h"
#include <SDL_mixer.h>
#include "CSndHandler.h"
class CMusicHandler

View File

@ -19,16 +19,17 @@ extern boost::rand48 ran;
void CObjectHandler::loadObjects()
{
VLC->objh = this;
int ID=0;
// int ID=0; //TODO use me
tlog5 << "\t\tReading OBJNAMES \n";
std::string buf = bitmaph->getTextFile("OBJNAMES.TXT");
int it=0;
int it=0; //hope that -1 will not break this
while (it<buf.length()-1)
{
std::string nobj;
loadToIt(nobj,buf,it,3);
if(nobj.size() && (nobj[nobj.size()-1]==(char)10 || nobj[nobj.size()-1]==(char)13 || nobj[nobj.size()-1]==(char)9))
loadToIt(nobj, buf, it, 3);
if(nobj.size() && (nobj[nobj.size()-1]==(char)10 || nobj[nobj.size()-1]==(char)13 || nobj[nobj.size()-1]==(char)9)) {
nobj = nobj.substr(0, nobj.size()-1);
}
names.push_back(nobj);
}
@ -39,8 +40,9 @@ void CObjectHandler::loadObjects()
while (it<buf.length()-1)
{
loadToIt(temp,buf,it,3);
if (temp[0]=='\"')
if (temp[0]=='\"') {
temp = temp.substr(1,temp.length()-2);
}
boost::algorithm::replace_all(temp,"\"\"","\"");
advobtxt.push_back(temp);
}
@ -85,8 +87,9 @@ void CObjectHandler::loadObjects()
tlog5 << "\t\tReading cregens \n";
cregens.resize(110); //TODO: hardcoded value - change
for(int i=0; i<cregens.size();i++)
for(size_t i=0; i < cregens.size(); ++i) {
cregens[i]=-1;
}
std::ifstream ifs("config/cregens.txt");
while(!ifs.eof())
{
@ -199,23 +202,34 @@ unsigned int CGHeroInstance::getTileCost(const EterrainType & ttype, const Eroad
if(ret>150)
ret = 150;
break;
default:
//TODO do something nasty here throw maybe? or some def value asing
break;
}
break;
case 2: //advanced
switch(ttype)
{
case rough: case sand: case snow:
case rough:
case sand:
case snow:
ret = 100;
break;
case swamp:
if(ret>125)
ret = 125;
break;
default:
//TODO look up
break;
}
break;
case 3: //expert
ret = 100;
break;
default:
//TODO look up
break;
}
//calculating road influence
@ -230,13 +244,16 @@ unsigned int CGHeroInstance::getTileCost(const EterrainType & ttype, const Eroad
case cobblestoneRoad:
ret*=0.5;
break;
default:
//TODO killllll me
break;
}
return ret;
}
unsigned int CGHeroInstance::getLowestCreatureSpeed()
{
unsigned int sl = 100;
for(int h=0; h<army.slots.size(); ++h)
for(size_t h=0; h < army.slots.size(); ++h)
{
if(VLC->creh->creatures[army.slots[h].first].speed<sl)
sl = VLC->creh->creatures[army.slots[h].first].speed;
@ -258,9 +275,12 @@ int3 CGHeroInstance::convertPosition(int3 src, bool toh3m) //toh3m=true: manifes
}
int3 CGHeroInstance::getPosition(bool h3m) const //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
{
if (h3m)
if (h3m) {
return pos;
else return convertPosition(pos,false);
}
else {
return convertPosition(pos,false);
}
}
int CGHeroInstance::getSightDistance() const //returns sight distance of this hero
{
@ -307,7 +327,7 @@ int CGHeroInstance::getPrimSkillLevel(int id) const
}
int CGHeroInstance::getSecSkillLevel(const int & ID) const
{
for(int i=0;i<secSkills.size();i++)
for(size_t i=0; i < secSkills.size(); ++i)
if(secSkills[i].first==ID)
return secSkills[i].second;
return 0;

View File

@ -79,7 +79,7 @@ void CSndHandler::extract(std::string srcfile, std::string dstfile, bool caseSen
{
if (caseSens)
{
for (int i=0;i<entries.size();i++)
for (size_t i=0;i<entries.size();++i)
{
if (entries[i].name==srcfile)
extract(i,dstfile);
@ -88,7 +88,7 @@ void CSndHandler::extract(std::string srcfile, std::string dstfile, bool caseSen
else
{
std::transform(srcfile.begin(),srcfile.end(),srcfile.begin(),tolower);
for (int i=0;i<entries.size();i++)
for (size_t i=0;i<entries.size();++i)
{
if (entries[i].name==srcfile)
{
@ -104,7 +104,7 @@ MemberFile CSndHandler::getFile(std::string name)
{
MemberFile ret;
std::transform(name.begin(),name.end(),name.begin(),tolower);
for (int i=0;i<entries.size();i++)
for (size_t i=0;i<entries.size();++i)
{
if (entries[i].name==name)
{
@ -219,7 +219,7 @@ void CVidHandler::extract(std::string srcfile, std::string dstfile, bool caseSen
{
if (caseSens)
{
for (int i=0;i<entries.size();i++)
for (size_t i=0;i<entries.size();++i)
{
if (entries[i].name==srcfile)
extract(i,dstfile);
@ -228,7 +228,7 @@ void CVidHandler::extract(std::string srcfile, std::string dstfile, bool caseSen
else
{
std::transform(srcfile.begin(),srcfile.end(),srcfile.begin(),tolower);
for (int i=0;i<entries.size();i++)
for (size_t i=0;i<entries.size();++i)
{
if (entries[i].name==srcfile)
{
@ -244,7 +244,7 @@ MemberFile CVidHandler::getFile(std::string name)
{
MemberFile ret;
std::transform(name.begin(),name.end(),name.begin(),tolower);
for (int i=0;i<entries.size();i++)
for (size_t i=0;i<entries.size();++i)
{
if (entries[i].name==name)
{

17
int3.h
View File

@ -3,6 +3,8 @@
#include <map>
#include <vector>
#include <cmath>
class CCreature;
class CCreatureSet //seven combined creatures
{
@ -10,14 +12,15 @@ public:
std::map<si32,std::pair<ui32,si32> > slots; //slots[slot_id]=> pair(creature_id,creature_quantity)
bool formation; //false - wide, true - tight
si32 getSlotFor(ui32 creature, ui32 slotsAmount=7) //returns -1 if no slot available
{
for(std::map<si32,std::pair<ui32,si32> >::iterator i=slots.begin(); i!=slots.end(); i++)
if(i->second.first == creature)
{
for(std::map<si32,std::pair<ui32,si32> >::iterator i=slots.begin(); i!=slots.end(); ++i)
if(i->second.first == creature) {
return i->first; //if there is already such creature we return its slot id
for(si32 i=0; i<slotsAmount; i++)
if(slots.find(i) == slots.end())
}
for(ui32 i=0; i<slotsAmount; i++)
if(slots.find(i) == slots.end()) {
return i; //return first free slot
}
return -1; //no slot available
}
template <typename Handler> void serialize(Handler &h, const int version)
@ -34,7 +37,7 @@ public:
inline int3(const si32 & X, const si32 & Y, const si32 & Z):x(X),y(Y),z(Z){}; //c-tor
inline int3(const int3 & val) : x(val.x), y(val.y), z(val.z){} //copy c-tor
inline int3 operator=(const int3 & val) {x = val.x; y = val.y; z = val.z; return *this;} //assignemt operator
inline ~int3(){} // d-tor - does nothing
~int3() {} // d-tor - does nothing
inline int3 operator+(const int3 & i) const //returns int3 with coordinates increased by corresponding coordinate of given int3
{return int3(x+i.x,y+i.y,z+i.z);}
inline int3 operator+(const si32 i) const //returns int3 with coordinates increased by given numer

2
map.h
View File

@ -1,6 +1,8 @@
#ifndef MAPD_H
#define MAPD_H
#ifdef _MSC_VER
#pragma warning (disable : 4482)
#endif
#include <cstring>
#include <vector>
#include <map>

View File

@ -70,6 +70,12 @@ std::string nameFromType (int typ)
return std::string("ROCKTL.DEF");
break;
}
case border:
//TODO use me
break;
default:
//TODO do something here
break;
}
return std::string();
}
@ -134,23 +140,24 @@ void CMapHandler::prepareFOWDefs()
partialHide->ourImages.push_back(nw);
//necessaary rotations added
for(int i=0; i<partialHide->ourImages.size(); ++i)
for(size_t i=0; i<partialHide->ourImages.size(); ++i)
{
CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap);
}
hideBitmap.resize(CGI->mh->map->width);
for (int i=0;i<hideBitmap.size();i++)
for (size_t i=0;i<hideBitmap.size();i++)
{
hideBitmap[i].resize(CGI->mh->map->height);
}
for (int i=0; i<hideBitmap.size(); ++i)
for (size_t i=0; i<hideBitmap.size(); ++i)
{
for (int j=0; j<CGI->mh->map->height; ++j)
for (int j=0; j < CGI->mh->map->height; ++j)
{
hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1);
for(int k=0; k<CGI->mh->map->twoLevel+1; ++k)
for(int k=0; k<CGI->mh->map->twoLevel+1; ++k) {
hideBitmap[i][j][k] = rand()%fullHide->ourImages.size();
}
}
}
}
@ -166,16 +173,16 @@ void CMapHandler::roadsRiverTerrainInit()
staticRiverDefs.push_back(CDefHandler::giveDef("icyrvr.def"));
staticRiverDefs.push_back(CDefHandler::giveDef("mudrvr.def"));
staticRiverDefs.push_back(CDefHandler::giveDef("lavrvr.def"));
for(int g=0; g<staticRiverDefs.size(); ++g)
for(size_t g=0; g<staticRiverDefs.size(); ++g)
{
for(int h=0; h<staticRiverDefs[g]->ourImages.size(); ++h)
for(size_t h=0; h < staticRiverDefs[g]->ourImages.size(); ++h)
{
CSDL_Ext::alphaTransform(staticRiverDefs[g]->ourImages[h].bitmap);
}
}
for(int g=0; g<roadDefs.size(); ++g)
for(size_t g=0; g<roadDefs.size(); ++g)
{
for(int h=0; h<roadDefs[g]->ourImages.size(); ++h)
for(size_t h=0; h < roadDefs[g]->ourImages.size(); ++h)
{
CSDL_Ext::alphaTransform(roadDefs[g]->ourImages[h].bitmap);
}
@ -280,7 +287,7 @@ void CMapHandler::borderAndTerrainBitmapInit()
CDefHandler *hlp = CDefHandler::giveDef(nameFromType(i));
terrainGraphics[i].resize(hlp->ourImages.size());
hlp->notFreeImgs = true;
for(int j=0; j<hlp->ourImages.size();j++)
for(size_t j=0; j < hlp->ourImages.size(); ++j)
terrainGraphics[i][j] = hlp->ourImages[j].bitmap;
delete hlp;
}
@ -347,7 +354,7 @@ void CMapHandler::borderAndTerrainBitmapInit()
void CMapHandler::initObjectRects()
{
//initializing objects / rects
for(int f=0; f<map->objects.size(); ++f)
for(size_t f=0; f < map->objects.size(); ++f)
{
if((map->objects[f]->ID==34 && static_cast<CGHeroInstance*>(map->objects[f])->inTownGarrison)
|| !map->objects[f]->defInfo)
@ -410,7 +417,7 @@ void processDef (CGDefInfo* def)
tlog3 << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl;
if(!def->handler->alphaTransformed)
{
for(int yy=0; yy<def->handler->ourImages.size(); ++yy)
for(size_t yy=0; yy < def->handler->ourImages.size(); ++yy)
{
def->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(def->handler->ourImages[yy].bitmap);
def->handler->alphaTransformed = true;
@ -462,7 +469,7 @@ void CMapHandler::init()
for(int i=0;i<PLAYER_LIMIT;i++)
{
for(int j=0; j<map->players[i].heroesNames.size();j++)
for(size_t j=0; j < map->players[i].heroesNames.size(); ++j)
{
usedHeroes.insert(map->players[i].heroesNames[j].heroID);
}
@ -471,7 +478,7 @@ void CMapHandler::init()
for(int h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info {
for(size_t h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info {
CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler));
tlog0<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl;
@ -582,7 +589,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
{
for (int by=0; by<dy; by++)
{
for(int h=0; h<ttiles[x+bx][y+by][level].objects.size(); ++h)
for(int h=0; h < ttiles[x+bx][y+by][level].objects.size(); ++h)
{
SDL_Rect sr;
sr.w = 32;
@ -605,7 +612,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
continue;
std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
int gg;
size_t gg;
for(gg=0; gg<iv.size(); ++gg)
{
if(iv[gg].groupNumber==getHeroFrameNum(themp->moveDir, !themp->isStanding))
@ -628,8 +635,8 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
continue;
std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
int gg;
for(gg=0; gg<iv.size(); ++gg)
size_t gg;
for(gg=0; gg < iv.size(); ++gg)
{
if(iv[gg].groupNumber==getHeroFrameNum(themp->moveDir, !themp->isStanding))
{
@ -752,7 +759,7 @@ SDL_Surface * CMapHandler::getVisBitmap(int x, int y, const std::vector< std::ve
d8 = (y>0) ? visibilityMap[x][y-1][lvl] : 0, //456
d9 = (y>0 && x<size) ? visibilityMap[x+1][y-1][lvl] : 0,//123
d4 = (x>0) ? visibilityMap[x-1][y][lvl] : 0,
d5 = visibilityMap[x][y][lvl],
d5 = visibilityMap[x][y][lvl], //TODO use me - OMFG
d6 = (x<size) ? visibilityMap[x+1][y][lvl] : 0,
d1 = (x>0 && y<size) ? visibilityMap[x-1][y+1][lvl] : 0,
d2 = (y<size) ? visibilityMap[x][y+1][lvl] : 0,
@ -1063,7 +1070,7 @@ bool CMapHandler::printObject(const CGObjectInstance *obj)
std::pair<const CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(obj, cr);
if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
{
TerrainTile2 & curt =
TerrainTile2 & curt = //TODO use me
ttiles
[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32]
[obj->pos.y + fy - curd->ourImages[0].bitmap->h/32]
@ -1088,7 +1095,7 @@ bool CMapHandler::hideObject(const CGObjectInstance *obj)
if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
{
std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & ctile = ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects;
for(int dd=0; dd<ctile.size(); ++dd)
for(size_t dd=0; dd < ctile.size(); ++dd)
{
if(ctile[dd].first->id==obj->id)
ctile.erase(ctile.begin() + dd);
@ -1247,7 +1254,7 @@ unsigned char CMapHandler::getDir(const int3 &a, const int3 &b)
void CMapHandler::updateWater() //shift colors in palettes of water tiles
{
SDL_Color palette[14];
for(int j=0; j<terrainGraphics[8].size(); j++)
for(size_t j=0; j < terrainGraphics[8].size(); ++j)
{
for(int i=0; i<12; ++i)
{

View File

@ -1,9 +1,13 @@
#ifndef _ZJEBANYNAGLOWEKWINDOWEGOVISUALAKTORENIKTNIEUZYWA_H
#define _ZJEBANYNAGLOWEKWINDOWEGOVISUALAKTORENIKTNIEUZYWA_H
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#ifdef _MSC_VER
#pragma once
#endif
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <cstdio>
@ -19,3 +23,5 @@
#include <fstream>
#include "global.h"
// TODO: reference additional headers your program requires here
#endif //_ZJEBANYNAGLOWEKWINDOWEGOVISUALAKTORENIKTNIEUZYWA_H