From 7f04ed990b7e6c1489933d2f8816cada1e22094b Mon Sep 17 00:00:00 2001 From: beegee1 Date: Tue, 13 Dec 2011 21:23:17 +0000 Subject: [PATCH 1/5] Major refactoring. First part: BattleInterface Introduction of pre compiled headers,... --- AI/EmptyAI/CEmptyAI.cpp | 3 +- AI/EmptyAI/CEmptyAI.h | 2 + AI/EmptyAI/Makefile.am | 5 +- AI/EmptyAI/Makefile.in | 43 ++- AI/EmptyAI/exp_funcs.cpp | 18 +- AI/GeniusAI/AIPriorities.cpp | 24 +- AI/GeniusAI/AIPriorities.h | 19 +- AI/GeniusAI/BattleHelper.cpp | 46 ++- AI/GeniusAI/BattleHelper.h | 7 +- AI/GeniusAI/BattleLogic.cpp | 49 ++- AI/GeniusAI/BattleLogic.h | 9 +- AI/GeniusAI/CGeniusAI.cpp | 33 +- AI/GeniusAI/CGeniusAI.h | 26 +- AI/GeniusAI/Common.h | 9 +- AI/GeniusAI/DLLMain.cpp | 18 +- AI/GeniusAI/ExpertSystem.cpp | 3 +- AI/GeniusAI/ExpertSystem.h | 4 +- AI/GeniusAI/GeneralAI.cpp | 2 + AI/GeniusAI/GeneralAI.h | 7 +- AI/GeniusAI/Makefile.am | 4 + AI/GeniusAI/Makefile.in | 97 +++++- AI/GeniusAI/genius.vcxproj | 10 +- AI/GeniusAI/neuralNetwork.cpp | 17 +- AI/GeniusAI/neuralNetwork.h | 10 +- AI/StupidAI/Makefile.am | 7 +- AI/StupidAI/Makefile.in | 46 ++- AI/StupidAI/StupidAI.cpp | 35 +- AI/StupidAI/StupidAI.h | 6 +- AI/StupidAI/StupidAI.vcxproj | 12 +- AI/StupidAI/main.cpp | 15 +- CCallback.cpp | 9 +- CCallback.h | 13 +- Scripting/ERM/ERM.vcxproj | 9 +- Scripting/ERM/ERMInterpreter.cpp | 20 +- Scripting/ERM/ERMInterpreter.h | 11 +- Scripting/ERM/ERMParser.cpp | 5 +- Scripting/ERM/ERMParser.h | 4 +- Scripting/ERM/ERMScriptModule.cpp | 6 +- Scripting/ERM/Makefile.am | 5 +- Scripting/ERM/Makefile.in | 17 +- VCMI_global.props | 4 +- aclocal.m4 | 4 +- client/AdventureMapButton.cpp | 33 +- client/AdventureMapButton.h | 8 +- client/CAdvmapInterface.cpp | 55 ++-- client/CAdvmapInterface.h | 14 +- client/CAnimation.cpp | 79 +++-- client/CAnimation.h | 34 +- client/CBitmapHandler.cpp | 19 +- client/CBitmapHandler.h | 11 +- client/CCastleInterface.cpp | 144 ++++---- client/CCastleInterface.h | 12 +- client/CConfigHandler.cpp | 17 +- client/CConfigHandler.h | 9 +- client/CCreatureAnimation.cpp | 29 +- client/CCreatureAnimation.h | 20 +- client/CCreatureWindow.cpp | 19 +- client/CCreatureWindow.h | 4 +- client/CCursorHandler.cpp | 3 +- client/CCursorHandler.h | 12 +- client/CDefHandler.cpp | 66 ++-- client/CDefHandler.h | 27 +- client/CGameInfo.cpp | 3 +- client/CGameInfo.h | 19 +- client/CHeroWindow.cpp | 15 +- client/CHeroWindow.h | 6 +- client/CKingdomInterface.cpp | 37 +-- client/CKingdomInterface.h | 5 +- client/CMT.cpp | 71 ++-- client/CMessage.cpp | 49 ++- client/CMessage.h | 12 +- client/CMusicBase.h | 5 +- client/CMusicHandler.cpp | 29 +- client/CMusicHandler.h | 18 +- client/CPlayerInterface.cpp | 62 ++-- client/CPlayerInterface.h | 16 +- client/CPreGame.cpp | 91 +++-- client/CPreGame.h | 17 +- client/CSndHandler.cpp | 15 +- client/CSndHandler.h | 13 +- client/CSoundBase.h | 7 +- client/CSpellWindow.cpp | 29 +- client/CSpellWindow.h | 7 +- client/CVideoHandler.cpp | 35 +- client/CVideoHandler.h | 9 +- client/Client.cpp | 54 ++- client/Client.h | 11 +- client/FontBase.h | 11 +- client/FunctionList.h | 9 +- client/GUIBase.cpp | 20 +- client/GUIBase.h | 16 +- client/GUIClasses.cpp | 297 ++++++++--------- client/GUIClasses.h | 32 +- client/Graphics.cpp | 63 ++-- client/Graphics.h | 12 +- client/Makefile.am | 50 ++- client/Makefile.in | 432 +++++++++++++++++++++--- client/NetPacksClient.cpp | 13 +- client/SDL_Extensions.cpp | 24 +- client/SDL_Extensions.h | 17 +- client/SDL_framerate.cpp | 72 ++-- client/SDL_framerate.h | 47 ++- client/VCMI_client.vcxproj | 62 +++- client/mapHandler.cpp | 56 ++-- client/mapHandler.h | 25 +- configure | 91 +++-- configure.ac | 6 +- lib/BattleAction.cpp | 7 +- lib/BattleAction.h | 15 +- lib/BattleState.cpp | 529 +++++++++++++++--------------- lib/BattleState.h | 91 ++--- lib/CArtHandler.cpp | 71 ++-- lib/CArtHandler.h | 46 +-- lib/CBuildingHandler.cpp | 26 +- lib/CBuildingHandler.h | 15 +- lib/CCampaignHandler.cpp | 36 +- lib/CCampaignHandler.h | 38 +-- lib/CCreatureHandler.cpp | 36 +- lib/CCreatureHandler.h | 27 +- lib/CCreatureSet.cpp | 37 +-- lib/CCreatureSet.h | 25 +- lib/CDefObjInfoHandler.cpp | 9 +- lib/CDefObjInfoHandler.h | 14 +- lib/CFileUtility.cpp | 4 +- lib/CFileUtility.h | 5 +- lib/CGameInterface.cpp | 16 +- lib/CGameInterface.h | 22 +- lib/CGameState.cpp | 195 ++++++----- lib/CGameState.h | 58 ++-- lib/CGeneralTextHandler.cpp | 34 +- lib/CGeneralTextHandler.h | 16 +- lib/CHeroHandler.cpp | 59 ++-- lib/CHeroHandler.h | 36 +- lib/CLodHandler.cpp | 54 ++- lib/CLodHandler.h | 31 +- lib/CMapInfo.cpp | 11 +- lib/CMapInfo.h | 8 +- lib/CObjectHandler.cpp | 329 +++++++++---------- lib/CObjectHandler.h | 189 +++++------ lib/CObstacleInstance.h | 2 +- lib/CScriptingModule.h | 13 +- lib/CSpellHandler.cpp | 14 +- lib/CSpellHandler.h | 18 +- lib/CTownHandler.cpp | 15 +- lib/CTownHandler.h | 17 +- lib/CondSh.h | 5 +- lib/Connection.cpp | 13 +- lib/Connection.h | 51 ++- lib/ConstTransitivePtr.h | 10 + lib/HeroBonus.cpp | 96 +++--- lib/HeroBonus.h | 97 +++--- lib/IGameCallback.cpp | 114 +++---- lib/IGameCallback.h | 63 ++-- lib/IGameEventsReceiver.h | 12 +- lib/Interprocess.h | 2 + lib/JsonNode.cpp | 22 +- lib/JsonNode.h | 16 +- lib/Makefile.am | 15 +- lib/Makefile.in | 87 +++-- lib/NetPacks.h | 172 +++++----- lib/NetPacksLib.cpp | 225 +++++++------ lib/RegisterTypes.h | 244 +++++++++++++- lib/ResourceSet.cpp | 17 +- lib/ResourceSet.h | 24 +- lib/VCMIDirs.h | 11 +- lib/VCMI_Lib.cpp | 58 ++-- lib/VCMI_Lib.h | 19 +- lib/VCMI_lib.vcxproj | 31 +- lib/map.cpp | 261 ++++++++------- lib/map.h | 107 +++--- lib/vcmi_endian.h | 78 +++-- server/CGameHandler.cpp | 326 +++++++++--------- server/CGameHandler.h | 15 +- server/CVCMIServer.cpp | 38 ++- server/CVCMIServer.h | 11 +- server/Makefile.am | 13 +- server/Makefile.in | 83 +---- server/NetPacksServer.cpp | 27 +- server/VCMI_server.vcxproj | 12 +- 179 files changed, 4076 insertions(+), 3765 deletions(-) diff --git a/AI/EmptyAI/CEmptyAI.cpp b/AI/EmptyAI/CEmptyAI.cpp index 0e19deaab..5991ccd3f 100644 --- a/AI/EmptyAI/CEmptyAI.cpp +++ b/AI/EmptyAI/CEmptyAI.cpp @@ -1,5 +1,6 @@ +#include "StdInc.h" #include "CEmptyAI.h" -#include + void CEmptyAI::init(CCallback * CB) { cb = CB; diff --git a/AI/EmptyAI/CEmptyAI.h b/AI/EmptyAI/CEmptyAI.h index c42a1bf8f..3ffb12124 100644 --- a/AI/EmptyAI/CEmptyAI.h +++ b/AI/EmptyAI/CEmptyAI.h @@ -1,3 +1,5 @@ +#pragma once + #include "../../AI_Base.h" #include "../../CCallback.h" diff --git a/AI/EmptyAI/Makefile.am b/AI/EmptyAI/Makefile.am index 3bda0893e..127353970 100644 --- a/AI/EmptyAI/Makefile.am +++ b/AI/EmptyAI/Makefile.am @@ -1,10 +1,13 @@ vcmiaidir = $(VCMI_AI_LIBS_DIR) +BUILT_SOURCES = StdInc.h.gch +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< vcmiai_LTLIBRARIES = libEmptyAI.la libEmptyAI_la_LIBADD = $(top_builddir)/lib/libvcmi.la +libEmptyAI_la_CXXFLAGS = -DVCMI_DLL libEmptyAI_la_LDFLAGS = -L$(top_builddir)/lib -module -avoid-version libEmptyAI_la_SOURCES = \ CEmptyAI.cpp \ CEmptyAI.h \ exp_funcs.cpp - diff --git a/AI/EmptyAI/Makefile.in b/AI/EmptyAI/Makefile.in index 70e5a6cfd..7513bc9f3 100644 --- a/AI/EmptyAI/Makefile.in +++ b/AI/EmptyAI/Makefile.in @@ -79,15 +79,16 @@ am__base_list = \ am__installdirs = "$(DESTDIR)$(vcmiaidir)" LTLIBRARIES = $(vcmiai_LTLIBRARIES) libEmptyAI_la_DEPENDENCIES = $(top_builddir)/lib/libvcmi.la -am_libEmptyAI_la_OBJECTS = CEmptyAI.lo exp_funcs.lo +am_libEmptyAI_la_OBJECTS = libEmptyAI_la-CEmptyAI.lo \ + libEmptyAI_la-exp_funcs.lo libEmptyAI_la_OBJECTS = $(am_libEmptyAI_la_OBJECTS) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) am__v_lt_0 = --silent libEmptyAI_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ - $(AM_CXXFLAGS) $(CXXFLAGS) $(libEmptyAI_la_LDFLAGS) $(LDFLAGS) \ - -o $@ + $(libEmptyAI_la_CXXFLAGS) $(CXXFLAGS) $(libEmptyAI_la_LDFLAGS) \ + $(LDFLAGS) -o $@ DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -270,15 +271,18 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ vcmiaidir = $(VCMI_AI_LIBS_DIR) +BUILT_SOURCES = StdInc.h.gch vcmiai_LTLIBRARIES = libEmptyAI.la libEmptyAI_la_LIBADD = $(top_builddir)/lib/libvcmi.la +libEmptyAI_la_CXXFLAGS = -DVCMI_DLL libEmptyAI_la_LDFLAGS = -L$(top_builddir)/lib -module -avoid-version libEmptyAI_la_SOURCES = \ CEmptyAI.cpp \ CEmptyAI.h \ exp_funcs.cpp -all: all-am +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .cpp .lo .o .obj @@ -352,8 +356,8 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CEmptyAI.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exp_funcs.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libEmptyAI_la-CEmptyAI.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libEmptyAI_la-exp_funcs.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -379,6 +383,22 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< +libEmptyAI_la-CEmptyAI.lo: CEmptyAI.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libEmptyAI_la_CXXFLAGS) $(CXXFLAGS) -MT libEmptyAI_la-CEmptyAI.lo -MD -MP -MF $(DEPDIR)/libEmptyAI_la-CEmptyAI.Tpo -c -o libEmptyAI_la-CEmptyAI.lo `test -f 'CEmptyAI.cpp' || echo '$(srcdir)/'`CEmptyAI.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libEmptyAI_la-CEmptyAI.Tpo $(DEPDIR)/libEmptyAI_la-CEmptyAI.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='CEmptyAI.cpp' object='libEmptyAI_la-CEmptyAI.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libEmptyAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libEmptyAI_la-CEmptyAI.lo `test -f 'CEmptyAI.cpp' || echo '$(srcdir)/'`CEmptyAI.cpp + +libEmptyAI_la-exp_funcs.lo: exp_funcs.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libEmptyAI_la_CXXFLAGS) $(CXXFLAGS) -MT libEmptyAI_la-exp_funcs.lo -MD -MP -MF $(DEPDIR)/libEmptyAI_la-exp_funcs.Tpo -c -o libEmptyAI_la-exp_funcs.lo `test -f 'exp_funcs.cpp' || echo '$(srcdir)/'`exp_funcs.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libEmptyAI_la-exp_funcs.Tpo $(DEPDIR)/libEmptyAI_la-exp_funcs.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='exp_funcs.cpp' object='libEmptyAI_la-exp_funcs.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libEmptyAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libEmptyAI_la-exp_funcs.lo `test -f 'exp_funcs.cpp' || echo '$(srcdir)/'`exp_funcs.cpp + mostlyclean-libtool: -rm -f *.lo @@ -468,13 +488,15 @@ distdir: $(DISTFILES) fi; \ done check-am: all-am -check: check-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am all-am: Makefile $(LTLIBRARIES) installdirs: for dir in "$(DESTDIR)$(vcmiaidir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-am +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -499,6 +521,7 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am clean-am: clean-generic clean-libtool clean-vcmiaiLTLIBRARIES \ @@ -570,7 +593,7 @@ ps-am: uninstall-am: uninstall-vcmiaiLTLIBRARIES -.MAKE: install-am install-strip +.MAKE: all check install install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ clean-libtool clean-vcmiaiLTLIBRARIES ctags distclean \ @@ -586,6 +609,8 @@ uninstall-am: uninstall-vcmiaiLTLIBRARIES mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags uninstall uninstall-am uninstall-vcmiaiLTLIBRARIES +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/AI/EmptyAI/exp_funcs.cpp b/AI/EmptyAI/exp_funcs.cpp index 1c700fe5d..e9d7f3175 100644 --- a/AI/EmptyAI/exp_funcs.cpp +++ b/AI/EmptyAI/exp_funcs.cpp @@ -1,31 +1,31 @@ -#define VCMI_DLL +#include "StdInc.h" + #include "../../AI_Base.h" #include "CEmptyAI.h" -#include -#include + std::set ais; -extern "C" DLL_EXPORT int GetGlobalAiVersion() +extern "C" DLL_LINKAGE int GetGlobalAiVersion() { return AI_INTERFACE_VER; } -extern "C" DLL_EXPORT void GetAiName(char* name) +extern "C" DLL_LINKAGE void GetAiName(char* name) { strcpy(name,NAME); } -extern "C" DLL_EXPORT char * GetAiNameS() +extern "C" DLL_LINKAGE char * GetAiNameS() { char * ret = new char[50]; strcpy(ret,NAME); return ret; } -extern "C" DLL_EXPORT CGlobalAI * GetNewAI() +extern "C" DLL_LINKAGE CGlobalAI * GetNewAI() { return new CEmptyAI(); // return } -extern "C" DLL_EXPORT void ReleaseAI(CGlobalAI * i) +extern "C" DLL_LINKAGE void ReleaseAI(CGlobalAI * i) { delete (CEmptyAI*)i; ais.erase(i); -} \ No newline at end of file +} diff --git a/AI/GeniusAI/AIPriorities.cpp b/AI/GeniusAI/AIPriorities.cpp index 3937646f0..11b1a0382 100644 --- a/AI/GeniusAI/AIPriorities.cpp +++ b/AI/GeniusAI/AIPriorities.cpp @@ -1,13 +1,12 @@ -#ifndef AI_PRIORITIES -#define AI_PRIORITIES +#include "StdInc.h" #include "AIPriorities.h" -#include + // TODO: No using namespace!! using namespace geniusai; Network::Network() {} -Network::Network(vector whichFeatures)// random network +Network::Network(vector whichFeatures)// random network : whichFeatures(whichFeatures), net(whichFeatures.size(), whichFeatures.size() * 0.601 + 2, @@ -34,15 +33,15 @@ Network::Network(istream & input) } -float Network::feedForward(const vector & stateFeatures) +double Network::feedForward(const vector & stateFeatures) { // TODO: Should comment/rewrite it... - return (rand() % 1000) / 800.0f; + return (rand() % 1000) / 800.0; double * input = new double[whichFeatures.size()]; for (int i = 0; i < whichFeatures.size(); i++) input[i] = stateFeatures[whichFeatures[i]]; - float ans = net.feedForwardPattern(input)[0]; + double ans = net.feedForwardPattern(input)[0]; delete input; return ans; @@ -98,18 +97,18 @@ void Priorities::fillFeatures(const CGeniusAI::HypotheticalGameState & hgs) } -float Priorities::getCost(vector &resourceCosts,const CGHeroInstance * moved,int distOutOfTheWay) +double Priorities::getCost(vector &resourceCosts,const CGHeroInstance * moved,int distOutOfTheWay) { if(!resourceCosts.size())return -1; //TODO: replace with ann - float cost = resourceCosts[0]/4.0+resourceCosts[1]/2.0+resourceCosts[2]/4.0+resourceCosts[3]/2.0+resourceCosts[4]/2.0+resourceCosts[5]/2.0+resourceCosts[6]/3000.0; + double cost = resourceCosts[0]/4.0+resourceCosts[1]/2.0+resourceCosts[2]/4.0+resourceCosts[3]/2.0+resourceCosts[4]/2.0+resourceCosts[5]/2.0+resourceCosts[6]/3000.0; if(moved) //TODO: multiply by importance of hero cost+=distOutOfTheWay/10000.0; return cost; } -float Priorities::getValue(const CGeniusAI::AIObjective & obj) +double Priorities::getValue(const CGeniusAI::AIObjective & obj) { //resource vector resourceAmounts(8,0); @@ -117,7 +116,7 @@ float Priorities::getValue(const CGeniusAI::AIObjective & obj) if(obj.type==CGeniusAI::AIObjective::finishTurn) //TODO: replace with value of visiting that object divided by days till completed return .0001; //small nonzero - float a; + double a; if(obj.type==CGeniusAI::AIObjective::attack) return 100; if(dynamic_cast(&obj)) @@ -249,5 +248,4 @@ float Priorities::getValue(const CGeniusAI::AIObjective & obj) return 0; -} -#endif +} \ No newline at end of file diff --git a/AI/GeniusAI/AIPriorities.h b/AI/GeniusAI/AIPriorities.h index b7b6c8189..08ca5319c 100644 --- a/AI/GeniusAI/AIPriorities.h +++ b/AI/GeniusAI/AIPriorities.h @@ -1,7 +1,5 @@ -#ifndef AIP_H -#define AIP_H +#pragma once -#include #include "CGeniusAI.h" #include "neuralNetwork.h" @@ -11,10 +9,10 @@ class Network { public: Network(); - Network(vector whichFeatures);// random network + Network(vector whichFeatures);// random network Network(istream & input); - vector whichFeatures; - float feedForward(const vector & stateFeatures); + vector whichFeatures; + double feedForward(const vector & stateFeatures); neuralNetwork net; //a network with whichFeatures.size() inputs, and 1 output }; @@ -25,15 +23,14 @@ public: Priorities(const string & filename); //read brain from file - vector stateFeatures; + vector stateFeatures; int specialFeaturesStart; int numSpecialFeatures; void fillFeatures(const CGeniusAI::HypotheticalGameState & AI); - float getValue(const CGeniusAI::AIObjective & obj); - float getCost(vector &resourceCosts,const CGHeroInstance * moved,int distOutOfTheWay); + double getValue(const CGeniusAI::AIObjective & obj); + double getCost(vector &resourceCosts,const CGHeroInstance * moved,int distOutOfTheWay); vector > objectNetworks; vector > buildingNetworks; }; -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/AI/GeniusAI/BattleHelper.cpp b/AI/GeniusAI/BattleHelper.cpp index a8d060489..32fcece6e 100644 --- a/AI/GeniusAI/BattleHelper.cpp +++ b/AI/GeniusAI/BattleHelper.cpp @@ -1,11 +1,5 @@ +#include "StdInc.h" #include "BattleHelper.h" -#include -#include -#include -#include -#include -#include -#include using namespace geniusai::BattleAI; using namespace std; @@ -13,8 +7,8 @@ using namespace std; CBattleHelper::CBattleHelper(): InfiniteDistance(0xffff), - BattlefieldWidth(BFIELD_WIDTH-2), - BattlefieldHeight(BFIELD_HEIGHT), + BattlefieldWidth(GameConstants::BFIELD_WIDTH-2), + BattlefieldHeight(GameConstants::BFIELD_HEIGHT), m_voteForMaxDamage(10), m_voteForMinDamage(10), m_voteForMaxSpeed(10), @@ -106,21 +100,21 @@ CBattleHelper::~CBattleHelper() int CBattleHelper::GetBattleFieldPosition(int x, int y) { - return x + BFIELD_WIDTH * (y - 1); + return x + GameConstants::BFIELD_WIDTH * (y - 1); } int CBattleHelper::DecodeXPosition(int battleFieldPosition) { - int x = battleFieldPosition%BFIELD_WIDTH; - assert( x > 0 && x < BFIELD_WIDTH-1 ); + int x = battleFieldPosition%GameConstants::BFIELD_WIDTH; + assert( x > 0 && x < GameConstants::BFIELD_WIDTH-1 ); return x; } int CBattleHelper::DecodeYPosition(int battleFieldPosition) { - int y=battleFieldPosition/BFIELD_WIDTH +1; - assert( y > 0 && y <= BFIELD_HEIGHT); + int y=battleFieldPosition/GameConstants::BFIELD_WIDTH +1; + assert( y > 0 && y <= GameConstants::BFIELD_HEIGHT); return y; } @@ -133,34 +127,34 @@ int CBattleHelper::StepLeft(int pos){ } int CBattleHelper::StepUpleft(int pos){ - if((pos/BFIELD_WIDTH)%2==0){ - return pos-BFIELD_WIDTH; + if((pos/GameConstants::BFIELD_WIDTH)%2==0){ + return pos-GameConstants::BFIELD_WIDTH; }else{ - return pos-BFIELD_WIDTH-1; + return pos-GameConstants::BFIELD_WIDTH-1; } } int CBattleHelper::StepUpright(int pos){ - if((pos/BFIELD_WIDTH)%2==0){ - return pos-BFIELD_WIDTH+1; + if((pos/GameConstants::BFIELD_WIDTH)%2==0){ + return pos-GameConstants::BFIELD_WIDTH+1; }else{ - return pos-BFIELD_WIDTH; + return pos-GameConstants::BFIELD_WIDTH; } } int CBattleHelper::StepDownleft(int pos){ - if((pos/BFIELD_WIDTH)%2==0){ - return pos+BFIELD_WIDTH; + if((pos/GameConstants::BFIELD_WIDTH)%2==0){ + return pos+GameConstants::BFIELD_WIDTH; }else{ - return pos+BFIELD_WIDTH-1; + return pos+GameConstants::BFIELD_WIDTH-1; } } int CBattleHelper::StepDownright(int pos){ - if((pos/BFIELD_WIDTH)%2==0){ - return pos+BFIELD_WIDTH+1; + if((pos/GameConstants::BFIELD_WIDTH)%2==0){ + return pos+GameConstants::BFIELD_WIDTH+1; }else{ - return pos+BFIELD_WIDTH; + return pos+GameConstants::BFIELD_WIDTH; } } diff --git a/AI/GeniusAI/BattleHelper.h b/AI/GeniusAI/BattleHelper.h index e1f4ffeeb..592983959 100644 --- a/AI/GeniusAI/BattleHelper.h +++ b/AI/GeniusAI/BattleHelper.h @@ -1,5 +1,4 @@ -#ifndef __BATTLE_HELPER__ -#define __BATTLE_HELPER__ +#pragma once #include "Common.h" @@ -47,6 +46,4 @@ private: CBattleHelper &operator=(const CBattleHelper &); }; -}} - -#endif/*__BATTLE_HELPER__*/ \ No newline at end of file +}} \ No newline at end of file diff --git a/AI/GeniusAI/BattleLogic.cpp b/AI/GeniusAI/BattleLogic.cpp index ffbb70550..0579ae29e 100644 --- a/AI/GeniusAI/BattleLogic.cpp +++ b/AI/GeniusAI/BattleLogic.cpp @@ -1,11 +1,10 @@ +#include "StdInc.h" #include "BattleLogic.h" + #include "../../lib/BattleState.h" -#include -#include #include #include #include -#include #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing @@ -152,27 +151,27 @@ void CBattleLogic::MakeStatistics(int currentCreatureId) //CGHeroInstance *defendingHero = (m_side)? m_hero2 : m_hero1; int attackDefenseBonus = currentStack->Attack() - st->Defense(); - float damageFactor = 1.0f; + double damageFactor = 1.0; if(attackDefenseBonus < 0) //decreasing dmg { - if(0.02f * (-attackDefenseBonus) > 0.3f) + if(0.02 * (-attackDefenseBonus) > 0.3) { - damageFactor += -0.3f; + damageFactor += -0.3; } else { - damageFactor += 0.02f * attackDefenseBonus; + damageFactor += 0.02 * attackDefenseBonus; } } else //increasing dmg { - if(0.05f * attackDefenseBonus > 4.0f) + if(0.05 * attackDefenseBonus > 4.0) { - damageFactor += 4.0f; + damageFactor += 4.0; } else { - damageFactor += 0.05f * attackDefenseBonus; + damageFactor += 0.05 * attackDefenseBonus; } } @@ -222,8 +221,8 @@ void CBattleLogic::MakeStatistics(int currentCreatureId) totalHitPoints += hitPoints; } } - if ((float)totalDamage / (float)totalEnemyDamage < 0.5f && - (float)totalHitPoints / (float)totalEnemyHitPoints < 0.5f) + if (totalDamage / static_cast(totalEnemyDamage) < 0.5 && + totalHitPoints / static_cast(totalEnemyHitPoints) < 0.5) { m_bEnemyDominates = true; DbgBox("** EnemyDominates!"); @@ -240,29 +239,29 @@ void CBattleLogic::MakeStatistics(int currentCreatureId) // sort max damage std::sort(m_statMaxDamage.begin(), m_statMaxDamage.end(), - bind((IntPtr)&creature_stat::value_type::second, _1) > bind((IntPtr)&creature_stat::value_type::second, _2)); + bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) > bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); // sort min damage std::sort(m_statMinDamage.begin(), m_statMinDamage.end(), - bind((IntPtr)&creature_stat::value_type::second, _1) > bind((IntPtr)&creature_stat::value_type::second, _2)); + bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) > bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); // sort max speed std::sort(m_statMaxSpeed.begin(), m_statMaxSpeed.end(), - bind((IntPtr)&creature_stat::value_type::second, _1) > bind((IntPtr)&creature_stat::value_type::second, _2)); + bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) > bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); // sort distance std::sort(m_statDistance.begin(), m_statDistance.end(), - bind((IntPtr)&creature_stat::value_type::second, _1) < bind((IntPtr)&creature_stat::value_type::second, _2)); + bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) < bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); // sort distance from shooters std::sort(m_statDistanceFromShooters.begin(), m_statDistanceFromShooters.end(), - bind((IntPtr)&creature_stat::value_type::second, _1) < bind((IntPtr)&creature_stat::value_type::second, _2)); + bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) < bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); // sort hit points std::sort(m_statHitPoints.begin(), m_statHitPoints.end(), - bind((IntPtr)&creature_stat::value_type::second, _1) > bind((IntPtr)&creature_stat::value_type::second, _2)); + bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) > bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); // sort casualties std::sort(m_statCasualties.begin(), m_statCasualties.end(), bind((CreaPtr)&creature_stat_casualties::value_type::second_type::damage_max, - bind((CreaPairPtr)&creature_stat_casualties::value_type::second, _1)) + bind((CreaPairPtr)&creature_stat_casualties::value_type::second, boost::lambda::_1)) > bind((CreaPtr)&creature_stat_casualties::value_type::second_type::damage_max, - bind((CreaPairPtr)&creature_stat_casualties::value_type::second, _2))); + bind((CreaPairPtr)&creature_stat_casualties::value_type::second, boost::lambda::_2))); } BattleAction CBattleLogic::MakeDecision(int stackID) @@ -527,7 +526,7 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) } } - std::vector fields = m_cb->battleGetAvailableHexes(m_cb->battleGetStackByID(attackerID), false); + std::vector fields = m_cb->battleGetAvailableHexes(m_cb->battleGetStackByID(attackerID), false); if(fields.size() == 0) { @@ -541,11 +540,11 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) ba.destinationTile = static_cast(dest_tile); //simplified checking for possibility of attack (previous was too simplified) int destStackPos = m_cb->battleGetPos(destinationID); - if(THex::mutualPosition(dest_tile, destStackPos) != -1) + if(SHexField::mutualPosition(dest_tile, destStackPos) != -1) ba.additionalInfo = destStackPos; - else if(THex::mutualPosition(dest_tile, destStackPos+1) != -1) + else if(SHexField::mutualPosition(dest_tile, destStackPos+1) != -1) ba.additionalInfo = destStackPos+1; - else if(THex::mutualPosition(dest_tile, destStackPos-1) != -1) + else if(SHexField::mutualPosition(dest_tile, destStackPos-1) != -1) ba.additionalInfo = destStackPos-1; else return BattleAction::makeDefend(attackerStack); @@ -582,7 +581,7 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) } } - for (std::vector::const_iterator it = fields.begin(); it != fields.end(); ++it) + for (std::vector::const_iterator it = fields.begin(); it != fields.end(); ++it) { if (*it == dest_tile) { diff --git a/AI/GeniusAI/BattleLogic.h b/AI/GeniusAI/BattleLogic.h index 2388ba8ee..e9c0130ac 100644 --- a/AI/GeniusAI/BattleLogic.h +++ b/AI/GeniusAI/BattleLogic.h @@ -1,11 +1,10 @@ -#ifndef __BATTLE_LOGIC_H__ -#define __BATTLE_LOGIC_H__ +#pragma once #include "Common.h" #include "BattleHelper.h" #pragma warning (disable: 4100 4251 4245 4018 4081) -#include "../../global.h" + #include "../../CCallback.h" #include "../../lib/CCreatureHandler.h" #include "../../lib/CObjectHandler.h" @@ -129,6 +128,4 @@ private: void PrintBattleAction(const BattleAction &action); }; -}} - -#endif/*__BATTLE_LOGIC_H__*/ \ No newline at end of file +}} \ No newline at end of file diff --git a/AI/GeniusAI/CGeniusAI.cpp b/AI/GeniusAI/CGeniusAI.cpp index 1011759a2..de8d3551f 100644 --- a/AI/GeniusAI/CGeniusAI.cpp +++ b/AI/GeniusAI/CGeniusAI.cpp @@ -1,8 +1,6 @@ +#include "StdInc.h" #include "CGeniusAI.h" -#include -#include - #include "../../lib/BattleState.h" #include "../../lib/CBuildingHandler.h" #include "../../lib/CHeroHandler.h" @@ -10,6 +8,7 @@ #include "../../lib/NetPacks.h" #include "AIPriorities.h" #include "../../lib/CGameState.h" +#include "../../lib/GameConstants.h" using std::endl; using geniusai::CGeniusAI; @@ -150,7 +149,7 @@ CGeniusAI::HeroObjective::HeroObjective(const HypotheticalGameState &hgs, } -float CGeniusAI::HeroObjective::getValue() const +double CGeniusAI::HeroObjective::getValue() const { if (_value >= 0) return _value - _cost; @@ -165,7 +164,7 @@ float CGeniusAI::HeroObjective::getValue() const resourceCosts[6] += 1000; // TODO: Add some meaningful (and not exploitable) number here. - float bestCost = 9e9f; + double bestCost = 9e9f; HypotheticalGameState::HeroModel* bestHero = NULL; if (type != AIObjective::finishTurn) { @@ -195,7 +194,7 @@ float CGeniusAI::HeroObjective::getValue() const distOutOfTheWay-=path3.nodes[0].dist; } - float cost = AI->m_priorities->getCost(resourceCosts, + double cost = AI->m_priorities->getCost(resourceCosts, whoCanAchieve[i]->h, distOutOfTheWay); if (cost < bestCost) @@ -269,7 +268,7 @@ CGeniusAI::TownObjective::TownObjective( _value = -1; } -float CGeniusAI::TownObjective::getValue() const +double CGeniusAI::TownObjective::getValue() const { if (_value >= 0) return _value - _cost; @@ -278,7 +277,7 @@ float CGeniusAI::TownObjective::getValue() const vector resourceCosts(8,0); CBuilding* b = NULL; CCreature* creature = NULL; - float cost = 0; // TODO: Needed? + double cost = 0; // TODO: Needed? int ID = 0; int newID = 0; int howMany = 0; @@ -310,7 +309,7 @@ float CGeniusAI::TownObjective::getValue() const else creatures_max = INT_MAX; // TODO: Will have to rewrite it. // TODO: Buy the best units (the least I can buy)? - amin(howMany, creatures_max); + vstd::amin(howMany, creatures_max); } // The cost of recruiting the stack of creatures. for (int i = 0; creature && (i < creature->cost.size() ); ++i) @@ -401,7 +400,7 @@ void CGeniusAI::TownObjective::print() const creatures_max = hgs.resourceAmounts[i]/creature->cost[i]; else creatures_max = INT_MAX; - amin(howMany, creatures_max); + vstd::amin(howMany, creatures_max); } tlog6 << "recruit " << howMany << " " << creature->namePl << " (Total AI Strength " << creature->AIValue*howMany @@ -503,7 +502,7 @@ void CGeniusAI::addHeroObjectives(CGeniusAI::HypotheticalGameState::HeroModel& h // maybe the hero wants to visit a seemingly unguarded enemy town, // but there is a hero on top of it. // if(i->o->) - if (i->o->ID != HEROI_TYPE) + if (i->o->ID != GameConstants::HEROI_TYPE) {// Unless you are trying to visit a hero. bool heroThere = false; for(int j = 0; j < hgs.heroModels.size(); j++) @@ -514,7 +513,7 @@ void CGeniusAI::addHeroObjectives(CGeniusAI::HypotheticalGameState::HeroModel& h if (heroThere) // It won't work if there is already someone visiting that spot. continue; } - if (i->o->ID == HEROI_TYPE && // Visiting friendly heroes not yet supported. + if (i->o->ID == GameConstants::HEROI_TYPE && // Visiting friendly heroes not yet supported. i->o->getOwner() == m_cb->getMyColor()) continue; if (i->o->id == h.h->id) // Don't visit yourself (should be caught by above). @@ -541,7 +540,7 @@ void CGeniusAI::addHeroObjectives(CGeniusAI::HypotheticalGameState::HeroModel& h // TODO: Make constants of those 1.2 & 2.5. if (dynamic_cast (i->o)) enemyStrength = static_cast((dynamic_cast (i->o))->getArmyStrength() * 1.2); - float heroStrength = h.h->getTotalStrength(); + double heroStrength = h.h->getTotalStrength(); // TODO: ballence these numbers using objective cost formula. // TODO: it would be nice to do a battle simulation. if (enemyStrength * 2.5 > heroStrength) @@ -945,7 +944,7 @@ void CGeniusAI::TownObjective::fulfill(CGeniusAI& cg, creature = VLC->creh->creatures[ID]; howMany = whichTown->creaturesToRecruit[which].first; for (int i = 0; i < creature->cost.size(); i++) - amin(howMany, creature->cost[i] ? hgs.resourceAmounts[i]/creature->cost[i] : INT_MAX); + vstd::amin(howMany, creature->cost[i] ? hgs.resourceAmounts[i]/creature->cost[i] : INT_MAX); if (howMany == 0) { tlog6 << "tried to recruit without enough money."; @@ -1262,7 +1261,7 @@ void CGeniusAI::battleStart(const CCreatureSet *army1, const CCreatureSet *army2 // TODO: Battle logic what... assert(!m_battleLogic); // We have been informed that battle will start (or we are neutral AI) - assert( (playerID > PLAYER_LIMIT) || (m_state.get() == UPCOMING_BATTLE) ); + assert( (playerID > GameConstants::PLAYER_LIMIT) || (m_state.get() == UPCOMING_BATTLE) ); m_state.setn(ONGOING_BATTLE); m_battleLogic = new BattleAI::CBattleLogic(m_cb, army1, army2, tile, hero1, @@ -1312,7 +1311,7 @@ void CGeniusAI::battleNewRound(int round) /** * */ -void CGeniusAI::battleStackMoved(int ID, std::vector dest, int distance) +void CGeniusAI::battleStackMoved(int ID, std::vector dest, int distance) { std::string message("\t\t\tCGeniusAI::battleStackMoved ID("); message += boost::lexical_cast(ID); @@ -1346,7 +1345,7 @@ void CGeniusAI::battleSpellCast(const BattleSpellCast *sc) * */ // void CGeniusAI::battleStackMoved(int ID, -// THex dest, +// SHexField dest, // bool startMoving, // bool endMoving) // { diff --git a/AI/GeniusAI/CGeniusAI.h b/AI/GeniusAI/CGeniusAI.h index f79d6fc7a..747ea024b 100644 --- a/AI/GeniusAI/CGeniusAI.h +++ b/AI/GeniusAI/CGeniusAI.h @@ -1,13 +1,9 @@ -#ifndef __CGENIUSAI_H__ -#define __CGENIUSAI_H__ +#pragma once #include "Common.h" #include "BattleLogic.h" #include "GeneralAI.h" #include "../../lib/CondSh.h" -#include -#include -#include class CBuilding; @@ -101,7 +97,7 @@ private: virtual void fulfill(CGeniusAI &,HypotheticalGameState & hgs)=0; virtual HypotheticalGameState pretend(const HypotheticalGameState&) =0; virtual void print() const=0; - virtual float getValue() const=0; //how much is it worth to the AI to achieve + virtual double getValue() const=0; //how much is it worth to the AI to achieve }; class HeroObjective: public AIObjective @@ -122,11 +118,11 @@ private: bool operator< (const HeroObjective &other) const; void fulfill(CGeniusAI &,HypotheticalGameState & hgs); HypotheticalGameState pretend(const HypotheticalGameState &hgs){return hgs;}; - float getValue() const; + double getValue() const; void print() const; private: - mutable float _value; - mutable float _cost; + mutable double _value; + mutable double _cost; }; //town objectives @@ -147,11 +143,11 @@ private: bool operator < (const TownObjective &other)const; void fulfill(CGeniusAI &,HypotheticalGameState & hgs); HypotheticalGameState pretend(const HypotheticalGameState &hgs){return hgs;}; - float getValue() const; + double getValue() const; void print() const; private: - mutable float _value; - mutable float _cost; + mutable double _value; + mutable double _cost; }; class AIObjectivePtrCont @@ -205,7 +201,7 @@ public: virtual void battleStacksAttacked(const std::set & bsa); //called when stack receives damage (after battleAttack()) virtual void battleEnd(const BattleResult *br); virtual void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackMoved(int ID, std::vector dest, int distance); + virtual void battleStackMoved(int ID, std::vector dest, int distance); virtual void battleSpellCast(const BattleSpellCast *sc); virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right //virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles); //called when battlefield is prepared, prior the battle beginning @@ -217,6 +213,4 @@ public: void battleResultsApplied(); friend class Priorities; }; -} - -#endif // __CGENIUSAI_H__ +} \ No newline at end of file diff --git a/AI/GeniusAI/Common.h b/AI/GeniusAI/Common.h index e65f9ce06..bf669cb51 100644 --- a/AI/GeniusAI/Common.h +++ b/AI/GeniusAI/Common.h @@ -1,14 +1,11 @@ -#ifndef __GENIUS_COMMON__ -#define __GENIUS_COMMON__ +#pragma once #ifdef __GNUC__ #define strcpy_s(a, b, c) strncpy(a, c, b) #endif #pragma warning (disable: 4100 4244) -#include "../../AI_Base.h" +#include "../../lib/AI_Base.h" #pragma warning (default: 4100 4244) -void DbgBox(const char *msg, bool messageBox = false); - -#endif/*__GENIUS_COMMON__*/ \ No newline at end of file +void DbgBox(const char *msg, bool messageBox = false); \ No newline at end of file diff --git a/AI/GeniusAI/DLLMain.cpp b/AI/GeniusAI/DLLMain.cpp index 2868295d9..da73785dc 100644 --- a/AI/GeniusAI/DLLMain.cpp +++ b/AI/GeniusAI/DLLMain.cpp @@ -1,40 +1,38 @@ -#pragma warning (disable: 4100 4251 4245 4018 4081) -#include "../../AI_Base.h" -#pragma warning (default: 4100 4251 4245 4018 4081) - +#include "StdInc.h" +#include "../../lib/AI_Base.h" #include "CGeniusAI.h" using namespace geniusai; const char *g_cszAiName = "Genius 1.0"; -extern "C" DLL_F_EXPORT int GetGlobalAiVersion() +extern "C" DLL_EXPORT int GetGlobalAiVersion() { return AI_INTERFACE_VER; } -extern "C" DLL_F_EXPORT void GetAiName(char* name) +extern "C" DLL_EXPORT void GetAiName(char* name) { strcpy_s(name, strlen(g_cszAiName) + 1, g_cszAiName); } -extern "C" DLL_F_EXPORT char* GetAiNameS() +extern "C" DLL_EXPORT char* GetAiNameS() { // need to be defined return NULL; } -extern "C" DLL_F_EXPORT CGlobalAI* GetNewAI() +extern "C" DLL_EXPORT CGlobalAI* GetNewAI() { return new CGeniusAI(); } -extern "C" DLL_F_EXPORT void ReleaseAI(CGlobalAI* i) +extern "C" DLL_EXPORT void ReleaseAI(CGlobalAI* i) { delete (CGeniusAI*)i; } -extern "C" DLL_F_EXPORT CBattleGameInterface* GetNewBattleAI() +extern "C" DLL_EXPORT CBattleGameInterface* GetNewBattleAI() { return new CGeniusAI(); } \ No newline at end of file diff --git a/AI/GeniusAI/ExpertSystem.cpp b/AI/GeniusAI/ExpertSystem.cpp index daadf842d..8fe840eb3 100644 --- a/AI/GeniusAI/ExpertSystem.cpp +++ b/AI/GeniusAI/ExpertSystem.cpp @@ -1,3 +1,4 @@ +#include "StdInc.h" #include "GeneralAI.h" #include "../../CCallback.h" #include "ExpertSystem.h" @@ -139,4 +140,4 @@ bool BonusCondition::matchesFact(Bonus &fact) if (object(&fact)) //Bonus(fact) matches local Selector(object) return true; return false; -} +} \ No newline at end of file diff --git a/AI/GeniusAI/ExpertSystem.h b/AI/GeniusAI/ExpertSystem.h index 75ab50e77..a1b20aa7d 100644 --- a/AI/GeniusAI/ExpertSystem.h +++ b/AI/GeniusAI/ExpertSystem.h @@ -1,4 +1,4 @@ -#include "../../global.h" + #include "../../CCallback.h" #include "../../lib/HeroBonus.h" #include @@ -101,7 +101,7 @@ public: template class Weight : public Rule { public: - float multiplier; //multiply input by value and return to output + double multiplier; //multiply input by value and return to output void fireTule(){}; }; diff --git a/AI/GeniusAI/GeneralAI.cpp b/AI/GeniusAI/GeneralAI.cpp index c9dee7984..d9521cb60 100644 --- a/AI/GeniusAI/GeneralAI.cpp +++ b/AI/GeniusAI/GeneralAI.cpp @@ -1,4 +1,6 @@ +#include "StdInc.h" #include "GeneralAI.h" + #include "../../CCallback.h" using namespace geniusai::GeneralAI; diff --git a/AI/GeniusAI/GeneralAI.h b/AI/GeniusAI/GeneralAI.h index 0a9bb99e5..48315b3cd 100644 --- a/AI/GeniusAI/GeneralAI.h +++ b/AI/GeniusAI/GeneralAI.h @@ -1,5 +1,4 @@ -#ifndef __GENERAL_AI_H__ -#define __GENERAL_AI_H__ +#pragma once #include "Common.h" @@ -16,6 +15,4 @@ namespace geniusai { namespace GeneralAI { CCallback *m_cb; }; -}} - -#endif/*__GENERAL_AI_H__*/ \ No newline at end of file +}} \ No newline at end of file diff --git a/AI/GeniusAI/Makefile.am b/AI/GeniusAI/Makefile.am index acdeb81a1..9f6699658 100644 --- a/AI/GeniusAI/Makefile.am +++ b/AI/GeniusAI/Makefile.am @@ -1,7 +1,11 @@ vcmiaidir = $(VCMI_AI_LIBS_DIR) +BUILT_SOURCES = StdInc.h.gch +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< vcmiai_LTLIBRARIES = libGeniusAI.la libGeniusAI_la_LIBADD = $(top_builddir)/lib/libvcmi.la +libGeniusAI_la_CXXFLAGS = -DVCMI_DLL libGeniusAI_la_LDFLAGS = -L$(top_builddir)/lib -module -avoid-version libGeniusAI_la_SOURCES = \ AIPriorities.cpp \ diff --git a/AI/GeniusAI/Makefile.in b/AI/GeniusAI/Makefile.in index be1a90d28..912bc462d 100644 --- a/AI/GeniusAI/Makefile.in +++ b/AI/GeniusAI/Makefile.in @@ -79,17 +79,18 @@ am__base_list = \ am__installdirs = "$(DESTDIR)$(vcmiaidir)" LTLIBRARIES = $(vcmiai_LTLIBRARIES) libGeniusAI_la_DEPENDENCIES = $(top_builddir)/lib/libvcmi.la -am_libGeniusAI_la_OBJECTS = AIPriorities.lo BattleHelper.lo \ - BattleLogic.lo CGeniusAI.lo DLLMain.lo GeneralAI.lo \ - neuralNetwork.lo +am_libGeniusAI_la_OBJECTS = libGeniusAI_la-AIPriorities.lo \ + libGeniusAI_la-BattleHelper.lo libGeniusAI_la-BattleLogic.lo \ + libGeniusAI_la-CGeniusAI.lo libGeniusAI_la-DLLMain.lo \ + libGeniusAI_la-GeneralAI.lo libGeniusAI_la-neuralNetwork.lo libGeniusAI_la_OBJECTS = $(am_libGeniusAI_la_OBJECTS) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) am__v_lt_0 = --silent libGeniusAI_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ - $(AM_CXXFLAGS) $(CXXFLAGS) $(libGeniusAI_la_LDFLAGS) \ - $(LDFLAGS) -o $@ + $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) \ + $(libGeniusAI_la_LDFLAGS) $(LDFLAGS) -o $@ DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -272,8 +273,10 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ vcmiaidir = $(VCMI_AI_LIBS_DIR) +BUILT_SOURCES = StdInc.h.gch vcmiai_LTLIBRARIES = libGeniusAI.la libGeniusAI_la_LIBADD = $(top_builddir)/lib/libvcmi.la +libGeniusAI_la_CXXFLAGS = -DVCMI_DLL libGeniusAI_la_LDFLAGS = -L$(top_builddir)/lib -module -avoid-version libGeniusAI_la_SOURCES = \ AIPriorities.cpp \ @@ -291,7 +294,8 @@ libGeniusAI_la_SOURCES = \ neuralNetwork.cpp \ neuralNetwork.h -all: all-am +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .cpp .lo .o .obj @@ -365,13 +369,13 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AIPriorities.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BattleHelper.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BattleLogic.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CGeniusAI.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DLLMain.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GeneralAI.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/neuralNetwork.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-AIPriorities.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-BattleHelper.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-BattleLogic.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-CGeniusAI.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-DLLMain.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-GeneralAI.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-neuralNetwork.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -397,6 +401,62 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< +libGeniusAI_la-AIPriorities.lo: AIPriorities.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-AIPriorities.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-AIPriorities.Tpo -c -o libGeniusAI_la-AIPriorities.lo `test -f 'AIPriorities.cpp' || echo '$(srcdir)/'`AIPriorities.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-AIPriorities.Tpo $(DEPDIR)/libGeniusAI_la-AIPriorities.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='AIPriorities.cpp' object='libGeniusAI_la-AIPriorities.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-AIPriorities.lo `test -f 'AIPriorities.cpp' || echo '$(srcdir)/'`AIPriorities.cpp + +libGeniusAI_la-BattleHelper.lo: BattleHelper.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-BattleHelper.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-BattleHelper.Tpo -c -o libGeniusAI_la-BattleHelper.lo `test -f 'BattleHelper.cpp' || echo '$(srcdir)/'`BattleHelper.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-BattleHelper.Tpo $(DEPDIR)/libGeniusAI_la-BattleHelper.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='BattleHelper.cpp' object='libGeniusAI_la-BattleHelper.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-BattleHelper.lo `test -f 'BattleHelper.cpp' || echo '$(srcdir)/'`BattleHelper.cpp + +libGeniusAI_la-BattleLogic.lo: BattleLogic.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-BattleLogic.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-BattleLogic.Tpo -c -o libGeniusAI_la-BattleLogic.lo `test -f 'BattleLogic.cpp' || echo '$(srcdir)/'`BattleLogic.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-BattleLogic.Tpo $(DEPDIR)/libGeniusAI_la-BattleLogic.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='BattleLogic.cpp' object='libGeniusAI_la-BattleLogic.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-BattleLogic.lo `test -f 'BattleLogic.cpp' || echo '$(srcdir)/'`BattleLogic.cpp + +libGeniusAI_la-CGeniusAI.lo: CGeniusAI.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-CGeniusAI.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-CGeniusAI.Tpo -c -o libGeniusAI_la-CGeniusAI.lo `test -f 'CGeniusAI.cpp' || echo '$(srcdir)/'`CGeniusAI.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-CGeniusAI.Tpo $(DEPDIR)/libGeniusAI_la-CGeniusAI.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='CGeniusAI.cpp' object='libGeniusAI_la-CGeniusAI.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-CGeniusAI.lo `test -f 'CGeniusAI.cpp' || echo '$(srcdir)/'`CGeniusAI.cpp + +libGeniusAI_la-DLLMain.lo: DLLMain.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-DLLMain.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-DLLMain.Tpo -c -o libGeniusAI_la-DLLMain.lo `test -f 'DLLMain.cpp' || echo '$(srcdir)/'`DLLMain.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-DLLMain.Tpo $(DEPDIR)/libGeniusAI_la-DLLMain.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='DLLMain.cpp' object='libGeniusAI_la-DLLMain.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-DLLMain.lo `test -f 'DLLMain.cpp' || echo '$(srcdir)/'`DLLMain.cpp + +libGeniusAI_la-GeneralAI.lo: GeneralAI.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-GeneralAI.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-GeneralAI.Tpo -c -o libGeniusAI_la-GeneralAI.lo `test -f 'GeneralAI.cpp' || echo '$(srcdir)/'`GeneralAI.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-GeneralAI.Tpo $(DEPDIR)/libGeniusAI_la-GeneralAI.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='GeneralAI.cpp' object='libGeniusAI_la-GeneralAI.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-GeneralAI.lo `test -f 'GeneralAI.cpp' || echo '$(srcdir)/'`GeneralAI.cpp + +libGeniusAI_la-neuralNetwork.lo: neuralNetwork.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-neuralNetwork.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-neuralNetwork.Tpo -c -o libGeniusAI_la-neuralNetwork.lo `test -f 'neuralNetwork.cpp' || echo '$(srcdir)/'`neuralNetwork.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-neuralNetwork.Tpo $(DEPDIR)/libGeniusAI_la-neuralNetwork.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='neuralNetwork.cpp' object='libGeniusAI_la-neuralNetwork.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-neuralNetwork.lo `test -f 'neuralNetwork.cpp' || echo '$(srcdir)/'`neuralNetwork.cpp + mostlyclean-libtool: -rm -f *.lo @@ -486,13 +546,15 @@ distdir: $(DISTFILES) fi; \ done check-am: all-am -check: check-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am all-am: Makefile $(LTLIBRARIES) installdirs: for dir in "$(DESTDIR)$(vcmiaidir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-am +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -517,6 +579,7 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am clean-am: clean-generic clean-libtool clean-vcmiaiLTLIBRARIES \ @@ -588,7 +651,7 @@ ps-am: uninstall-am: uninstall-vcmiaiLTLIBRARIES -.MAKE: install-am install-strip +.MAKE: all check install install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ clean-libtool clean-vcmiaiLTLIBRARIES ctags distclean \ @@ -604,6 +667,8 @@ uninstall-am: uninstall-vcmiaiLTLIBRARIES mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags uninstall uninstall-am uninstall-vcmiaiLTLIBRARIES +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/AI/GeniusAI/genius.vcxproj b/AI/GeniusAI/genius.vcxproj index 67391a19f..d05f272d7 100644 --- a/AI/GeniusAI/genius.vcxproj +++ b/AI/GeniusAI/genius.vcxproj @@ -107,11 +107,11 @@ true EnableFastChecks MultiThreadedDebugDLL - - + Use Level4 EditAndContinue 4512;%(DisableSpecificWarnings) + StdInc.h VCMI_lib.lib;%(AdditionalDependencies) @@ -216,6 +216,11 @@ + + Create + StdInc.h + %(PreprocessorDefinitions) + @@ -225,6 +230,7 @@ + diff --git a/AI/GeniusAI/neuralNetwork.cpp b/AI/GeniusAI/neuralNetwork.cpp index 03758217d..c6f0cc45e 100644 --- a/AI/GeniusAI/neuralNetwork.cpp +++ b/AI/GeniusAI/neuralNetwork.cpp @@ -1,5 +1,4 @@ -#include -#include +#include "StdInc.h" #include "neuralNetwork.h" //using namespace std; @@ -8,18 +7,18 @@ #define M_PI 3.14159265358979323846 #endif -static float norm(void)//add desired mean, multiply to get desired SD +static double norm(void)//add desired mean, multiply to get desired SD { - static float kept = 0; + static double kept = 0; static bool in = 0; if(!in) { - float x = (rand()+1)/float(RAND_MAX+1); - float f = sqrtf( - 2.0f * log(x) ); - x = (rand()+1)/float(RAND_MAX+1); - kept = f * cosf( 2.0f * M_PI * x ); + double x = (rand() + 1) / static_cast(RAND_MAX + 1); + double f = sqrtf( - 2.0 * log(x) ); + x = (rand() + 1) / static_cast(RAND_MAX + 1); + kept = f * cosf( 2.0 * M_PI * x ); in = true; - return f * sinf( 2.0f * M_PI * x ); + return f * sinf( 2.0 * M_PI * x ); } else { diff --git a/AI/GeniusAI/neuralNetwork.h b/AI/GeniusAI/neuralNetwork.h index b4da08e44..9002a93df 100644 --- a/AI/GeniusAI/neuralNetwork.h +++ b/AI/GeniusAI/neuralNetwork.h @@ -8,13 +8,8 @@ * Bobby Anguelov - takinginitiative.wordpress.com (2008) * MSN & email: banguelov@cs.up.ac.za ********************************************************************/ -#ifndef NEURAL_NETWORK_H -#define NEURAL_NETWORK_H +#pragma once //standard includes -#include -#include -#include -#include #include @@ -63,5 +58,4 @@ private: }; std::istream & operator >> (std::istream &, neuralNetwork & ann); -std::ostream & operator << (std::ostream &, const neuralNetwork & ann); -#endif \ No newline at end of file +std::ostream & operator << (std::ostream &, const neuralNetwork & ann); \ No newline at end of file diff --git a/AI/StupidAI/Makefile.am b/AI/StupidAI/Makefile.am index f0fce2304..5e196c8ef 100644 --- a/AI/StupidAI/Makefile.am +++ b/AI/StupidAI/Makefile.am @@ -1,12 +1,13 @@ vcmiaidir = $(VCMI_AI_LIBS_DIR) +BUILT_SOURCES = StdInc.h.gch +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< vcmiai_LTLIBRARIES = libStupidAI.la libStupidAI_la_LIBADD = $(top_builddir)/lib/libvcmi.la +libStupidAI_la_CXXFLAGS = -DVCMI_DLL libStupidAI_la_LDFLAGS = -L$(top_builddir)/lib -module -avoid-version libStupidAI_la_SOURCES = \ main.cpp\ - stdafx.cpp\ - stdafx.h\ StupidAI.cpp\ StupidAI.h - diff --git a/AI/StupidAI/Makefile.in b/AI/StupidAI/Makefile.in index f55921793..82126315f 100644 --- a/AI/StupidAI/Makefile.in +++ b/AI/StupidAI/Makefile.in @@ -79,15 +79,16 @@ am__base_list = \ am__installdirs = "$(DESTDIR)$(vcmiaidir)" LTLIBRARIES = $(vcmiai_LTLIBRARIES) libStupidAI_la_DEPENDENCIES = $(top_builddir)/lib/libvcmi.la -am_libStupidAI_la_OBJECTS = main.lo stdafx.lo StupidAI.lo +am_libStupidAI_la_OBJECTS = libStupidAI_la-main.lo \ + libStupidAI_la-StupidAI.lo libStupidAI_la_OBJECTS = $(am_libStupidAI_la_OBJECTS) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) am__v_lt_0 = --silent libStupidAI_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ - $(AM_CXXFLAGS) $(CXXFLAGS) $(libStupidAI_la_LDFLAGS) \ - $(LDFLAGS) -o $@ + $(libStupidAI_la_CXXFLAGS) $(CXXFLAGS) \ + $(libStupidAI_la_LDFLAGS) $(LDFLAGS) -o $@ DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -270,17 +271,18 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ vcmiaidir = $(VCMI_AI_LIBS_DIR) +BUILT_SOURCES = StdInc.h.gch vcmiai_LTLIBRARIES = libStupidAI.la libStupidAI_la_LIBADD = $(top_builddir)/lib/libvcmi.la +libStupidAI_la_CXXFLAGS = -DVCMI_DLL libStupidAI_la_LDFLAGS = -L$(top_builddir)/lib -module -avoid-version libStupidAI_la_SOURCES = \ main.cpp\ - stdafx.cpp\ - stdafx.h\ StupidAI.cpp\ StupidAI.h -all: all-am +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .cpp .lo .o .obj @@ -354,9 +356,8 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StupidAI.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdafx.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libStupidAI_la-StupidAI.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libStupidAI_la-main.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -382,6 +383,22 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< +libStupidAI_la-main.lo: main.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libStupidAI_la_CXXFLAGS) $(CXXFLAGS) -MT libStupidAI_la-main.lo -MD -MP -MF $(DEPDIR)/libStupidAI_la-main.Tpo -c -o libStupidAI_la-main.lo `test -f 'main.cpp' || echo '$(srcdir)/'`main.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libStupidAI_la-main.Tpo $(DEPDIR)/libStupidAI_la-main.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='main.cpp' object='libStupidAI_la-main.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libStupidAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libStupidAI_la-main.lo `test -f 'main.cpp' || echo '$(srcdir)/'`main.cpp + +libStupidAI_la-StupidAI.lo: StupidAI.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libStupidAI_la_CXXFLAGS) $(CXXFLAGS) -MT libStupidAI_la-StupidAI.lo -MD -MP -MF $(DEPDIR)/libStupidAI_la-StupidAI.Tpo -c -o libStupidAI_la-StupidAI.lo `test -f 'StupidAI.cpp' || echo '$(srcdir)/'`StupidAI.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libStupidAI_la-StupidAI.Tpo $(DEPDIR)/libStupidAI_la-StupidAI.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='StupidAI.cpp' object='libStupidAI_la-StupidAI.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libStupidAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libStupidAI_la-StupidAI.lo `test -f 'StupidAI.cpp' || echo '$(srcdir)/'`StupidAI.cpp + mostlyclean-libtool: -rm -f *.lo @@ -471,13 +488,15 @@ distdir: $(DISTFILES) fi; \ done check-am: all-am -check: check-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am all-am: Makefile $(LTLIBRARIES) installdirs: for dir in "$(DESTDIR)$(vcmiaidir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-am +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -502,6 +521,7 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am clean-am: clean-generic clean-libtool clean-vcmiaiLTLIBRARIES \ @@ -573,7 +593,7 @@ ps-am: uninstall-am: uninstall-vcmiaiLTLIBRARIES -.MAKE: install-am install-strip +.MAKE: all check install install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ clean-libtool clean-vcmiaiLTLIBRARIES ctags distclean \ @@ -589,6 +609,8 @@ uninstall-am: uninstall-vcmiaiLTLIBRARIES mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags uninstall uninstall-am uninstall-vcmiaiLTLIBRARIES +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/AI/StupidAI/StupidAI.cpp b/AI/StupidAI/StupidAI.cpp index 51ee36ec6..59a1a0c70 100644 --- a/AI/StupidAI/StupidAI.cpp +++ b/AI/StupidAI/StupidAI.cpp @@ -1,12 +1,9 @@ -#include "stdafx.h" +#include "StdInc.h" +#include "../../lib/AI_Base.h" #include "StupidAI.h" #include "../../lib/BattleState.h" #include "../../CCallback.h" -#include -#include #include "../../lib/CCreatureHandler.h" -#include -//#include CBattleCallback * cbc; @@ -42,7 +39,7 @@ struct EnemyInfo { const CStack * s; int adi, adr; - std::vector attackFrom; //for melee fight + std::vector attackFrom; //for melee fight EnemyInfo(const CStack * _s) : s(_s) {} void calcDmg(const CStack * ourStack) @@ -63,10 +60,10 @@ bool isMoreProfitable(const EnemyInfo &ei1, const EnemyInfo& ei2) return (ei1.adi-ei1.adr) < (ei2.adi - ei2.adr); } -int distToNearestNeighbour(THex hex, const std::vector & dists, THex *chosenHex = NULL) +int distToNearestNeighbour(SHexField hex, const std::vector & dists, SHexField *chosenHex = NULL) { int ret = 1000000; - BOOST_FOREACH(THex n, hex.neighbouringTiles()) + BOOST_FOREACH(SHexField n, hex.neighbouringTiles()) { if(dists[n] >= 0 && dists[n] < ret) { @@ -84,12 +81,12 @@ bool isCloser(const EnemyInfo & ei1, const EnemyInfo & ei2, const std::vectorposition, dists) < distToNearestNeighbour(ei2.s->position, dists); } -static bool willSecondHexBlockMoreEnemyShooters(const THex &h1, const THex &h2) +static bool willSecondHexBlockMoreEnemyShooters(const SHexField &h1, const SHexField &h2) { int shooters[2] = {0}; //count of shooters on hexes for(int i = 0; i < 2; i++) - BOOST_FOREACH(THex neighbour, (i ? h2 : h1).neighbouringTiles()) + BOOST_FOREACH(SHexField neighbour, (i ? h2 : h1).neighbouringTiles()) if(const CStack *s = cbc->battleGetStackByPos(neighbour)) if(s->getCreature()->isShooting()) shooters[i]++; @@ -101,7 +98,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack ) { //boost::this_thread::sleep(boost::posix_time::seconds(2)); print("activeStack called"); - std::vector avHexes = cb->battleGetAvailableHexes(stack, false); + std::vector avHexes = cb->battleGetAvailableHexes(stack, false); std::vector dists = cb->battleGetDistances(stack); std::vector enemiesShootable, enemiesReachable, enemiesUnreachable; @@ -113,7 +110,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack ) } else { - BOOST_FOREACH(THex hex, avHexes) + BOOST_FOREACH(SHexField hex, avHexes) { if(CStack::isMeleeAttackPossible(stack, s, hex)) { @@ -146,7 +143,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack ) else { const EnemyInfo &ei= *std::min_element(enemiesUnreachable.begin(), enemiesUnreachable.end(), boost::bind(isCloser, _1, _2, boost::ref(dists))); - if(distToNearestNeighbour(ei.s->position, dists) < BFIELD_SIZE) + if(distToNearestNeighbour(ei.s->position, dists) < GameConstants::BFIELD_SIZE) { return goTowards(stack, ei.s->position); } @@ -185,7 +182,7 @@ void CStupidAI::battleNewRound(int round) print("battleNewRound called"); } -void CStupidAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) +void CStupidAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) { print("battleStackMoved called");; } @@ -236,19 +233,19 @@ void CStupidAI::print(const std::string &text) const tlog0 << "CStupidAI [" << this <<"]: " << text << std::endl; } -BattleAction CStupidAI::goTowards(const CStack * stack, THex hex) +BattleAction CStupidAI::goTowards(const CStack * stack, SHexField hex) { - THex realDest = hex; - THex predecessors[BFIELD_SIZE]; + SHexField realDest = hex; + SHexField predecessors[GameConstants::BFIELD_SIZE]; std::vector dists = cb->battleGetDistances(stack, hex); - if(distToNearestNeighbour(hex, dists, &realDest) > BFIELD_SIZE) + if(distToNearestNeighbour(hex, dists, &realDest) > GameConstants::BFIELD_SIZE) { print("goTowards: Cannot reach"); return BattleAction::makeDefend(stack); } dists = cb->battleGetDistances(stack, realDest, predecessors); - std::vector avHexes = cb->battleGetAvailableHexes(stack, false); + std::vector avHexes = cb->battleGetAvailableHexes(stack, false); if(!avHexes.size()) { diff --git a/AI/StupidAI/StupidAI.h b/AI/StupidAI/StupidAI.h index 9f2413393..663c399e9 100644 --- a/AI/StupidAI/StupidAI.h +++ b/AI/StupidAI/StupidAI.h @@ -1,5 +1,7 @@ #pragma once +#include "../../lib/SHexField.h" + class CStupidAI : public CBattleGameInterface { int side; @@ -21,7 +23,7 @@ public: //void battleResultsApplied() OVERRIDE; //called when all effects of last battle are applied void battleNewRoundFirst(int round) OVERRIDE; //called at the beginning of each turn before changes are applied; void battleNewRound(int round) OVERRIDE; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; + void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; void battleSpellCast(const BattleSpellCast *sc) OVERRIDE; void battleStacksEffectsSet(const SetStackEffect & sse) OVERRIDE;//called when a specific effect is set to stacks //void battleTriggerEffect(const BattleTriggerEffect & bte) OVERRIDE; @@ -32,6 +34,6 @@ public: void battleCatapultAttacked(const CatapultAttack & ca) OVERRIDE; //called when catapult makes an attack void battleStacksRemoved(const BattleStacksRemoved & bsr) OVERRIDE; //called when certain stack is completely removed from battlefield - BattleAction goTowards(const CStack * stack, THex hex ); + BattleAction goTowards(const CStack * stack, SHexField hex ); }; diff --git a/AI/StupidAI/StupidAI.vcxproj b/AI/StupidAI/StupidAI.vcxproj index 022a23eab..7ff466078 100644 --- a/AI/StupidAI/StupidAI.vcxproj +++ b/AI/StupidAI/StupidAI.vcxproj @@ -91,7 +91,8 @@ Disabled %(AdditionalIncludeDirectories) Use - stdafx.h + StdInc.h + %(PreprocessorDefinitions) true @@ -155,16 +156,15 @@ - + + %(PreprocessorDefinitions) Create - Create - Create - Create + StdInc.h - + diff --git a/AI/StupidAI/main.cpp b/AI/StupidAI/main.cpp index 3963b80b2..3fb39db00 100644 --- a/AI/StupidAI/main.cpp +++ b/AI/StupidAI/main.cpp @@ -1,6 +1,7 @@ -#include "stdafx.h" +#include "StdInc.h" + +#include "../../lib/AI_Base.h" #include "StupidAI.h" -#include #ifdef __GNUC__ #define strcpy_s(a, b, c) strncpy(a, c, b) @@ -8,28 +9,28 @@ const char *g_cszAiName = "Stupid AI 0.1"; -extern "C" DLL_F_EXPORT int GetGlobalAiVersion() +extern "C" DLL_EXPORT int GetGlobalAiVersion() { return AI_INTERFACE_VER; } -extern "C" DLL_F_EXPORT void GetAiName(char* name) +extern "C" DLL_EXPORT void GetAiName(char* name) { strcpy_s(name, strlen(g_cszAiName) + 1, g_cszAiName); } -extern "C" DLL_F_EXPORT char* GetAiNameS() +extern "C" DLL_EXPORT char* GetAiNameS() { // need to be defined return NULL; } -extern "C" DLL_F_EXPORT CBattleGameInterface* GetNewBattleAI() +extern "C" DLL_EXPORT CBattleGameInterface* GetNewBattleAI() { return new CStupidAI(); } -extern "C" DLL_F_EXPORT void ReleaseBattleAI(CBattleGameInterface* i) +extern "C" DLL_EXPORT void ReleaseBattleAI(CBattleGameInterface* i) { delete (CStupidAI*)i; } diff --git a/CCallback.cpp b/CCallback.cpp index 7dc4fa427..762e046cf 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -1,5 +1,6 @@ -#include "stdafx.h" +#include "StdInc.h" #include "CCallback.h" + #include "lib/CCreatureHandler.h" #include "client/CGameInfo.h" #include "lib/CGameState.h" @@ -15,11 +16,9 @@ #include "lib/Connection.h" #include "lib/NetPacks.h" #include "client/mapHandler.h" -#include -#include -#include #include "lib/CSpellHandler.h" #include "lib/CArtHandler.h" +#include "lib/GameConstants.h" #ifdef min #undef min #endif @@ -247,7 +246,7 @@ void CCallback::setSelection(const CArmedInstance * obj) ss.id = obj->id; sendRequest(&(CPackForClient&)ss); - if(obj->ID == HEROI_TYPE) + if(obj->ID == GameConstants::HEROI_TYPE) { if(cl->pathInfo->hero != obj) //calculate new paths only if we selected a different hero cl->calculatePaths(static_cast(obj)); diff --git a/CCallback.h b/CCallback.h index 71e99c1cd..28ea9492a 100644 --- a/CCallback.h +++ b/CCallback.h @@ -1,14 +1,5 @@ -#ifndef __CCALLBACK_H__ -#define __CCALLBACK_H__ +#pragma once -#include "global.h" -#ifdef _WIN32 -#include "tchar.h" -#else -#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 "lib/IGameCallback.h" @@ -148,5 +139,3 @@ public: //friends friend class CClient; }; - -#endif // __CCALLBACK_H__ diff --git a/Scripting/ERM/ERM.vcxproj b/Scripting/ERM/ERM.vcxproj index 9caf824a7..b3fa4a53b 100644 --- a/Scripting/ERM/ERM.vcxproj +++ b/Scripting/ERM/ERM.vcxproj @@ -90,8 +90,8 @@ Level3 Disabled %(AdditionalIncludeDirectories) - NotUsing - stdafx.h + Use + StdInc.h true @@ -132,11 +132,16 @@ + + + Create + StdInc.h + diff --git a/Scripting/ERM/ERMInterpreter.cpp b/Scripting/ERM/ERMInterpreter.cpp index 332ef6458..7e44eb99b 100644 --- a/Scripting/ERM/ERMInterpreter.cpp +++ b/Scripting/ERM/ERMInterpreter.cpp @@ -1,13 +1,7 @@ +#include "StdInc.h" #include "ERMInterpreter.h" -#include -#include -#include -#include -#include -#include // for 'operator+=()' -#include -#include +#include #include "../../lib/CObjectHandler.h" #include "../../lib/CHeroHandler.h" #include "../../lib/CCreatureHandler.h" @@ -372,13 +366,13 @@ void ERMInterpreter::scanForScripts() { using namespace boost::filesystem; //parser checking - if(!exists(DATA_DIR "/Data/s/")) + if(!exists(GameConstants::DATA_DIR + "/Data/s/")) { - tlog3 << "Warning: Folder " DATA_DIR "/Data/s/ doesn't exist!\n"; + tlog3 << "Warning: Folder " << GameConstants::DATA_DIR << "/Data/s/ doesn't exist!\n"; return; } directory_iterator enddir; - for (directory_iterator dir(DATA_DIR "/Data/s"); dir!=enddir; dir++) + for (directory_iterator dir(GameConstants::DATA_DIR + "/Data/s"); dir!=enddir; dir++) { if(is_regular(dir->status())) { @@ -2293,7 +2287,7 @@ void IexpValStr::setTo( int val ) } } -void IexpValStr::setTo( float val ) +void IexpValStr::setTo( double val ) { DBG_PRINT("setting " << getName() << " to " << val); switch(type) @@ -2337,7 +2331,7 @@ int IexpValStr::getInt() const } } -float IexpValStr::getFloat() const +double IexpValStr::getFloat() const { switch(type) { diff --git a/Scripting/ERM/ERMInterpreter.h b/Scripting/ERM/ERMInterpreter.h index 6be683f6f..99177de4b 100644 --- a/Scripting/ERM/ERMInterpreter.h +++ b/Scripting/ERM/ERMInterpreter.h @@ -1,5 +1,6 @@ #pragma once -#include "../../global.h" + + #include "ERMParser.h" #include "ERMScriptModule.h" @@ -135,7 +136,7 @@ namespace VERMInterpreter static const int NUM_LOCALS = 100; static const int NUM_STRINGS = 10; static const int NUM_FLOATINGS = 100; - + int & getParam(int num); int & getLocal(int num); std::string & getString(int num); @@ -621,10 +622,10 @@ public: enum {WRONGVAL, INT, INTVAR, FLOATVAR, STRINGVAR} type; void setTo(const IexpValStr & second); void setTo(int val); - void setTo(float val); + void setTo(double val); void setTo(const std::string & val); int getInt() const; - float getFloat() const; + double getFloat() const; std::string getString() const; IexpValStr() : type(WRONGVAL) @@ -796,7 +797,7 @@ class ERMInterpreter : public CScriptingModule VERMInterpreter::Trigger * curTrigger; VERMInterpreter::FunctionLocalVars * curFunc; static const int TRIG_FUNC_NUM = 30000; - VERMInterpreter::FunctionLocalVars funcVars[TRIG_FUNC_NUM+1]; //+1 because we use [0] as a global set of y-vars + VERMInterpreter::FunctionLocalVars funcVars[TRIG_FUNC_NUM + 1]; //+1 because we use [0] as a global set of y-vars VERMInterpreter::FunctionLocalVars * getFuncVars(int funNum); //0 is a global func-like set IexpValStr getIexp(const ERM::TIexp & iexp) const; diff --git a/Scripting/ERM/ERMParser.cpp b/Scripting/ERM/ERMParser.cpp index eff6cc4f0..1526e3a17 100644 --- a/Scripting/ERM/ERMParser.cpp +++ b/Scripting/ERM/ERMParser.cpp @@ -1,19 +1,18 @@ +#include "StdInc.h" #include "ERMParser.h" + #include //To make compilation with older boost versions possible //Don't know exact version - 1.46 works while 1.42 not #if BOOST_VERSION >= 104600 #include -#include #include #include #include #include #include #include -#include -#include namespace spirit = boost::spirit; namespace qi = boost::spirit::qi; diff --git a/Scripting/ERM/ERMParser.h b/Scripting/ERM/ERMParser.h index 16efa2175..cde879b44 100644 --- a/Scripting/ERM/ERMParser.h +++ b/Scripting/ERM/ERMParser.h @@ -1,6 +1,6 @@ #pragma once -#include "../../global.h" -#include + + #include #include #include diff --git a/Scripting/ERM/ERMScriptModule.cpp b/Scripting/ERM/ERMScriptModule.cpp index 8954a4fbb..c835c89ca 100644 --- a/Scripting/ERM/ERMScriptModule.cpp +++ b/Scripting/ERM/ERMScriptModule.cpp @@ -1,4 +1,6 @@ +#include "StdInc.h" #include "ERMScriptModule.h" + #include "ERMInterpreter.h" /* @@ -21,12 +23,12 @@ CPrivilagedInfoCallback *icb; const char *g_cszAiName = "(V)ERM interpreter"; -extern "C" DLL_F_EXPORT void GetAiName(char* name) +extern "C" DLL_EXPORT void GetAiName(char* name) { strcpy_s(name, strlen(g_cszAiName) + 1, g_cszAiName); } -extern "C" DLL_F_EXPORT CScriptingModule* GetNewModule() +extern "C" DLL_EXPORT CScriptingModule* GetNewModule() { return new ERMInterpreter(); } \ No newline at end of file diff --git a/Scripting/ERM/Makefile.am b/Scripting/ERM/Makefile.am index 56a1a4315..0400fdf47 100644 --- a/Scripting/ERM/Makefile.am +++ b/Scripting/ERM/Makefile.am @@ -1,8 +1,11 @@ vcmiscriptingdir = $(VCMI_SCRIPTING_LIBS_DIR) +BUILT_SOURCES = StdInc.h.gch +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< vcmiscripting_LTLIBRARIES = libvcmiERM.la libvcmiERM_la_LIBADD = @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ @BOOST_IOSTREAMS_LIB@ -libvcmiERM_la_CXXFLAGS = +libvcmiERM_la_CXXFLAGS = -DVCMI_DLL libvcmiERM_la_SOURCES = \ ERMInterpreter.cpp \ ERMInterpreter.h \ diff --git a/Scripting/ERM/Makefile.in b/Scripting/ERM/Makefile.in index ce5564219..c53682f3b 100644 --- a/Scripting/ERM/Makefile.in +++ b/Scripting/ERM/Makefile.in @@ -271,9 +271,10 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ vcmiscriptingdir = $(VCMI_SCRIPTING_LIBS_DIR) +BUILT_SOURCES = StdInc.h.gch vcmiscripting_LTLIBRARIES = libvcmiERM.la libvcmiERM_la_LIBADD = @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ @BOOST_IOSTREAMS_LIB@ -libvcmiERM_la_CXXFLAGS = +libvcmiERM_la_CXXFLAGS = -DVCMI_DLL libvcmiERM_la_SOURCES = \ ERMInterpreter.cpp \ ERMInterpreter.h \ @@ -282,7 +283,8 @@ libvcmiERM_la_SOURCES = \ ERMScriptModule.cpp \ ERMScriptModule.h -all: all-am +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .cpp .lo .o .obj @@ -497,13 +499,15 @@ distdir: $(DISTFILES) fi; \ done check-am: all-am -check: check-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am all-am: Makefile $(LTLIBRARIES) installdirs: for dir in "$(DESTDIR)$(vcmiscriptingdir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-am +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -528,6 +532,7 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am clean-am: clean-generic clean-libtool clean-vcmiscriptingLTLIBRARIES \ @@ -599,7 +604,7 @@ ps-am: uninstall-am: uninstall-vcmiscriptingLTLIBRARIES -.MAKE: install-am install-strip +.MAKE: all check install install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ clean-libtool clean-vcmiscriptingLTLIBRARIES ctags distclean \ @@ -615,6 +620,8 @@ uninstall-am: uninstall-vcmiscriptingLTLIBRARIES mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags uninstall uninstall-am uninstall-vcmiscriptingLTLIBRARIES +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/VCMI_global.props b/VCMI_global.props index 8f2fe710f..771b10fde 100644 --- a/VCMI_global.props +++ b/VCMI_global.props @@ -4,8 +4,8 @@ <_PropertySheetDisplayName>VCMI_global - $(SolutionDir)..\libs\$(PlatformShortName);$(LibraryPath) - $(SolutionDir)..\include;$(IncludePath) + D:\Programme\Boost\boost_1_48_0\stage\lib;$(SolutionDir)..\libs\$(PlatformShortName);$(LibraryPath) + D:\Programme\Boost\boost_1_48_0;$(SolutionDir)..\include;$(IncludePath) diff --git a/aclocal.m4 b/aclocal.m4 index ea740a707..549e03ad1 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -13,8 +13,8 @@ m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl -m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.67],, -[m4_warning([this file was generated for autoconf 2.67. +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.66],, +[m4_warning([this file was generated for autoconf 2.66. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically `autoreconf'.])]) diff --git a/client/AdventureMapButton.cpp b/client/AdventureMapButton.cpp index a3ac6dfcf..da7b46ae6 100644 --- a/client/AdventureMapButton.cpp +++ b/client/AdventureMapButton.cpp @@ -1,14 +1,13 @@ +#include "StdInc.h" #include "AdventureMapButton.h" + #include "CAnimation.h" -//#include "CAdvmapInterface.h" #include "SDL_Extensions.h" #include "CGameInfo.h" -//#include "../lib/CGeneralTextHandler.h" -//#include "../lib/CTownHandler.h" #include "../CCallback.h" #include "CConfigHandler.h" -//#include "Graphics.h" -#include "CBattleInterface.h" +#include "BattleInterface/CBattleInterface.h" +#include "BattleInterface/CBattleConsole.h" #include "CPlayerInterface.h" #include "CMessage.h" #include "CMusicHandler.h" @@ -444,7 +443,7 @@ void CSlider::sliderClicked() void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent) { - float v = 0; + double v = 0; if(horizontal) { if( std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2+40 || std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2 ) @@ -461,7 +460,7 @@ void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent) v *= positions; v /= (pos.h - 48); } - v += 0.5f; + v += 0.5; if(v!=value) { moveTo(v); @@ -486,8 +485,8 @@ void CSlider::moveRight() void CSlider::moveTo(int to) { - amax(to, 0); - amin(to, positions); + vstd::amax(to, 0); + vstd::amin(to, positions); //same, old position? if(value == to) @@ -498,7 +497,7 @@ void CSlider::moveTo(int to) { if(positions) { - float part = (float)to/positions; + double part = static_cast(to) / positions; part*=(pos.w-48); int newPos = part + pos.x + 16 - slider->pos.x; slider->moveBy(Point(newPos, 0)); @@ -510,7 +509,7 @@ void CSlider::moveTo(int to) { if(positions) { - float part = (float)to/positions; + double part = static_cast(to) / positions; part*=(pos.h-48); int newPos = part + pos.y + 16 - slider->pos.y; slider->moveBy(Point(0, newPos)); @@ -527,24 +526,24 @@ void CSlider::clickLeft(tribool down, bool previousState) { if(down && !slider->isBlocked()) { - float pw = 0; - float rw = 0; + double pw = 0; + double rw = 0; if(horizontal) { pw = GH.current->motion.x-pos.x-25; - rw = pw / ((float)(pos.w-48)); + rw = pw / static_cast(pos.w - 48); } else { pw = GH.current->motion.y-pos.y-24; - rw = pw / ((float)(pos.h-48)); + rw = pw / (pos.h-48); } if(pw < -8 || pw > (horizontal ? pos.w : pos.h) - 40) return; // if (rw>1) return; // if (rw<0) return; slider->clickLeft(true, slider->pressedL); - moveTo(rw * positions + 0.5f); + moveTo(rw * positions + 0.5); return; } if(active & MOVE) @@ -645,7 +644,7 @@ void CSlider::setAmount( int to ) { amount = to; positions = to - capacity; - amax(positions, 0); + vstd::amax(positions, 0); } void CSlider::showAll(SDL_Surface * to) diff --git a/client/AdventureMapButton.h b/client/AdventureMapButton.h index 8226e8bf4..00146094e 100644 --- a/client/AdventureMapButton.h +++ b/client/AdventureMapButton.h @@ -1,8 +1,6 @@ -#ifndef __ADVENTUREMAPBUTTON_H__ -#define __ADVENTUREMAPBUTTON_H__ +#pragma once #include "FunctionList.h" -#include #include "GUIBase.h" /* @@ -163,6 +161,4 @@ public: int Value=0, bool Horizontal=true, int style = 0); //style 0 - brown, 1 - blue ~CSlider(); void moveToMax(); -}; - -#endif // __ADVENTUREMAPBUTTON_H__ +}; diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index 455661881..66e44e760 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -1,5 +1,7 @@ -#include "AdventureMapButton.h" +#include "StdInc.h" #include "CAdvmapInterface.h" + +#include "AdventureMapButton.h" #include "../CCallback.h" #include "CCastleInterface.h" #include "CCursorHandler.h" @@ -21,16 +23,9 @@ #include "../lib/map.h" #include "../lib/JsonNode.h" #include "mapHandler.h" -#include "../stdafx.h" -#include -#include -#include -#include -#include #include "CPreGame.h" #include "../lib/VCMI_Lib.h" #include "../lib/CSpellHandler.h" -#include #include "CSoundBase.h" #include "../lib/CGameState.h" #include "CMusicHandler.h" @@ -71,7 +66,7 @@ CMinimap::CMinimap() temps = newSurface(pos.w,pos.h); aiShield = new CPicture("AISHIELD.bmp"); - const JsonNode config(DATA_DIR "/config/minimap.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/minimap.json"); const JsonVector &minimap_vec = config["MinimapColors"].Vector(); BOOST_FOREACH(const JsonNode &m, minimap_vec) { @@ -123,7 +118,7 @@ void CMinimap::draw(SDL_Surface * to) int3 hpos = hh[i]->getPosition(false); if(hpos.z!=adventureInt->position.z) continue; - //float zawx = ((float)hpos.x/CGI->mh->sizes.x), zawy = ((float)hpos.y/CGI->mh->sizes.y); + int3 maplgp ( (hpos.x*mw)/mapSizes.x, (hpos.y*mh)/mapSizes.y, hpos.z ); for (int ii=0; iiposition.x)/(((float)mapSizes.x)))*pos.w, - by = (((float)adventureInt->position.y)/(((float)mapSizes.y)))*pos.h, - rx = (((float)tilesw)/(mapSizes.x))*((float)pos.w), //width - ry = (((float)tilesh)/(mapSizes.y))*((float)pos.h); //height + int bx = static_cast((adventureInt->position.x / static_cast(mapSizes.x)) * pos.w), + by = static_cast((adventureInt->position.y / static_cast(mapSizes.y)) * pos.h), + rx = static_cast((tilesw / static_cast(mapSizes.x)) * pos.w), //width + ry = static_cast((tilesh / static_cast(mapSizes.y)) * pos.h); //height CSDL_Ext::drawDashedBorder(temps, Rect(bx, by, rx, ry), int3(255,75,125)); @@ -295,8 +290,8 @@ void CMinimap::clickLeft(tribool down, bool previousState) if (!((bool)down)) return; - float dx=((float)(GH.current->motion.x-pos.x))/((float)pos.w), - dy=((float)(GH.current->motion.y-pos.y))/((float)pos.h); + double dx = (GH.current->motion.x - pos.x) / static_cast(pos.w), + dy = (GH.current->motion.y - pos.y) / static_cast(pos.h); int3 newCPos; newCPos.x = (CGI->mh->sizes.x*dx); @@ -981,7 +976,7 @@ void CInfoBar::deactivate() void CInfoBar::updateSelection(const CGObjectInstance *obj) { - if(obj->ID == HEROI_TYPE) + if(obj->ID == GameConstants::HEROI_TYPE) curSel = static_cast(obj); else curSel = NULL; @@ -1593,9 +1588,9 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView /*= true*/) centerOn(sel); terrain.currentPath = NULL; - if(sel->ID==TOWNI_TYPE) + if(sel->ID==GameConstants::TOWNI_TYPE) { - int pos = vstd::findPos(LOCPLINT->towns,sel); + int pos = vstd::find_pos(LOCPLINT->towns,sel); townList.selected = pos; townList.fixPos(); updateSleepWake(NULL); @@ -1736,10 +1731,10 @@ void CAdvMapInt::tileLClicked(const int3 &mp) return; } //check if we can select this object - bool canSelect = topBlocking && topBlocking->ID == HEROI_TYPE && topBlocking->tempOwner == LOCPLINT->playerID; - canSelect |= topBlocking && topBlocking->ID == TOWNI_TYPE && LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, topBlocking->tempOwner); + bool canSelect = topBlocking && topBlocking->ID == GameConstants::HEROI_TYPE && topBlocking->tempOwner == LOCPLINT->playerID; + canSelect |= topBlocking && topBlocking->ID == GameConstants::TOWNI_TYPE && LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, topBlocking->tempOwner); - if (selection->ID != HEROI_TYPE) //hero is not selected (presumably town) + if (selection->ID != GameConstants::HEROI_TYPE) //hero is not selected (presumably town) { assert(!terrain.currentPath); //path can be active only when hero is selected if(selection == topBlocking) //selected town clicked @@ -1820,7 +1815,7 @@ void CAdvMapInt::tileHovered(const int3 &tile) bool accessible = pnode->turns < 255; int turns = pnode->turns; - amin(turns, 3); + vstd::amin(turns, 3); if(!selection) //may occur just at the start of game (fake move before full intiialization) return; @@ -1850,13 +1845,13 @@ void CAdvMapInt::tileHovered(const int3 &tile) const bool guardingCreature = CGI->mh->map->isInTheMap(LOCPLINT->cb->guardingCreaturePosition(tile)); - if(selection->ID == TOWNI_TYPE) + if(selection->ID == GameConstants::TOWNI_TYPE) { if(objAtTile) { - if(objAtTile->ID == TOWNI_TYPE && LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, objAtTile->tempOwner)) + if(objAtTile->ID == GameConstants::TOWNI_TYPE && LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, objAtTile->tempOwner)) CCS->curh->changeGraphic(0, 3); - else if(objAtTile->ID == HEROI_TYPE && objAtTile->tempOwner == LOCPLINT->playerID) + else if(objAtTile->ID == GameConstants::HEROI_TYPE && objAtTile->tempOwner == LOCPLINT->playerID) CCS->curh->changeGraphic(0, 2); } else @@ -1866,7 +1861,7 @@ void CAdvMapInt::tileHovered(const int3 &tile) { if(objAtTile) { - if(objAtTile->ID == HEROI_TYPE) + if(objAtTile->ID == GameConstants::HEROI_TYPE) { if(!LOCPLINT->cb->getPlayerRelations( LOCPLINT->playerID, objAtTile->tempOwner)) //enemy hero { @@ -1885,7 +1880,7 @@ void CAdvMapInt::tileHovered(const int3 &tile) CCS->curh->changeGraphic(0, 2); } } - else if(objAtTile->ID == TOWNI_TYPE) + else if(objAtTile->ID == GameConstants::TOWNI_TYPE) { if(!LOCPLINT->cb->getPlayerRelations( LOCPLINT->playerID, objAtTile->tempOwner)) //enemy town { @@ -2042,7 +2037,7 @@ void CAdvMapInt::leaveCastingMode(bool cast /*= false*/, int3 dest /*= int3(-1, const CGHeroInstance * CAdvMapInt::curHero() const { - if(selection && selection->ID == HEROI_TYPE) + if(selection && selection->ID == GameConstants::HEROI_TYPE) return static_cast(selection); else return NULL; @@ -2050,7 +2045,7 @@ const CGHeroInstance * CAdvMapInt::curHero() const const CGTownInstance * CAdvMapInt::curTown() const { - if(selection && selection->ID == TOWNI_TYPE) + if(selection && selection->ID == GameConstants::TOWNI_TYPE) return static_cast(selection); else return NULL; diff --git a/client/CAdvmapInterface.h b/client/CAdvmapInterface.h index 588dcf848..7e0d24386 100644 --- a/client/CAdvmapInterface.h +++ b/client/CAdvmapInterface.h @@ -1,11 +1,11 @@ -#ifndef __CADVMAPINTERFACE_H__ -#define __CADVMAPINTERFACE_H__ +#pragma once + #include -#include "../global.h" + #include "SDL.h" -#include #include "AdventureMapButton.h" #include "GUIClasses.h" + class CDefHandler; class CCallback; struct CGPath; @@ -176,8 +176,8 @@ public: enum{NA, INGAME, WAITING} state; bool updateScreen, updateMinimap ; - unsigned char anim, animValHitCount; //animation frame - unsigned char heroAnim, heroAnimValHitCount; //animation frame + ui8 anim, animValHitCount; //animation frame + ui8 heroAnim, heroAnimValHitCount; //animation frame SDL_Surface * bg; std::vector gems; @@ -256,5 +256,3 @@ public: }; extern CAdvMapInt *adventureInt; - -#endif // __CADVMAPINTERFACE_H__ diff --git a/client/CAnimation.cpp b/client/CAnimation.cpp index 84d0d0513..c5077c4cd 100644 --- a/client/CAnimation.cpp +++ b/client/CAnimation.cpp @@ -1,7 +1,4 @@ -#include -#include -#include - +#include "StdInc.h" #include #include "../lib/CLodHandler.h" @@ -23,8 +20,8 @@ * */ -extern DLL_EXPORT CLodHandler *spriteh; -extern DLL_EXPORT CLodHandler *bitmaph; +extern DLL_LINKAGE CLodHandler *spriteh; +extern DLL_LINKAGE CLodHandler *bitmaph; typedef std::map > source_map; typedef std::map image_map; @@ -53,7 +50,7 @@ class CompImageLoader CompImage * image; ui8 *position; ui8 *entry; - unsigned int currentLine; + ui32 currentLine; inline ui8 typeOf(ui8 color); inline void NewEntry(ui8 color, size_t size); @@ -97,15 +94,15 @@ CDefFile::CDefFile(std::string Name): palette = new SDL_Color[256]; int it = 0; - unsigned int type = read_le_u32(data + it); + ui32 type = read_le_u32(data + it); it+=4; //int width = read_le_u32(data + it); it+=4;//not used //int height = read_le_u32(data + it); it+=4; it+=8; - unsigned int totalBlocks = read_le_u32(data + it); + ui32 totalBlocks = read_le_u32(data + it); it+=4; - for (unsigned int i= 0; i<256; i++) + for (ui32 i= 0; i<256; i++) { palette[i].r = data[it++]; palette[i].g = data[it++]; @@ -117,7 +114,7 @@ CDefFile::CDefFile(std::string Name): else memcpy(palette, H3Palette, sizeof(SDL_Color)*8);//initialize shadow\selection colors - for (unsigned int i=0; i(FDef+currentOffset); currentOffset += sizeof(ui32) * sprite.height; - for (unsigned int i=0; ipalette, (void*)pal, 256*sizeof(SDL_Color)); //Allocate enought space for worst possible case, c-style malloc used due to resizing after load image->surf = (ui8*)malloc(SpriteSize.x*SpriteSize.y*3); - image->line = new unsigned int[SpriteSize.y+1]; + image->line = new ui32[SpriteSize.y+1]; image->line[0] = 0; position = image->surf; } @@ -591,7 +588,7 @@ SDLImage::SDLImage(std::string filename, bool compressed): } } -void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, unsigned char rotation) const +void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 rotation) const { if (!surf) return; @@ -751,7 +748,7 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha) for (size_t i=0; i::PutColorAlpha(dest, col); } return; @@ -811,7 +808,7 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha) void CompImage::playerColored(int player) { SDL_Color *pal = NULL; - if(player < PLAYER_LIMIT && player >= 0) + if(player < GameConstants::PLAYER_LIMIT && player >= 0) { pal = graphics->playerColorPalette + 32*player; } @@ -941,7 +938,7 @@ void CAnimation::init(CDefFile * file) if (spriteh->haveFile(name, FILE_TEXT)) { int size = 0; - unsigned char * configFile = spriteh->giveFile(name, FILE_TEXT, &size); + ui8 * configFile = spriteh->giveFile(name, FILE_TEXT, &size); const JsonNode config((char*)configFile, size); delete configFile; @@ -1118,7 +1115,7 @@ void CAnimation::getAnimInfo() } } -CAnimImage::CAnimImage(std::string name, size_t Frame, size_t Group, int x, int y, unsigned char Flags): +CAnimImage::CAnimImage(std::string name, size_t Frame, size_t Group, int x, int y, ui8 Flags): frame(Frame), group(Group), player(-1), @@ -1130,7 +1127,7 @@ CAnimImage::CAnimImage(std::string name, size_t Frame, size_t Group, int x, int init(); } -CAnimImage::CAnimImage(CAnimation *Anim, size_t Frame, size_t Group, int x, int y, unsigned char Flags): +CAnimImage::CAnimImage(CAnimation *Anim, size_t Frame, size_t Group, int x, int y, ui8 Flags): anim(Anim), frame(Frame), group(Group), @@ -1206,7 +1203,7 @@ void CAnimImage::playerColored(int currPlayer) anim->getImage(0, group)->playerColored(player); } -CShowableAnim::CShowableAnim(int x, int y, std::string name, unsigned char Flags, unsigned int Delay, size_t Group): +CShowableAnim::CShowableAnim(int x, int y, std::string name, ui8 Flags, ui32 Delay, size_t Group): anim(name, Flags & USE_RLE), group(Group), frame(0), @@ -1232,9 +1229,9 @@ CShowableAnim::~CShowableAnim() anim.unloadGroup(group); } -void CShowableAnim::setAlpha(unsigned int alphaValue) +void CShowableAnim::setAlpha(ui32 alphaValue) { - alpha = std::min(alphaValue, 255); + alpha = std::min(alphaValue, 255); } bool CShowableAnim::set(size_t Group, size_t from, size_t to) @@ -1320,14 +1317,14 @@ void CShowableAnim::blitImage(size_t frame, size_t group, SDL_Surface *to) void CShowableAnim::rotate(bool on, bool vertical) { - unsigned char flag = vertical? VERTICAL_FLIP:HORIZONTAL_FLIP; + ui8 flag = vertical? VERTICAL_FLIP:HORIZONTAL_FLIP; if (on) flags |= flag; else flags &= ~flag; } -CCreatureAnim::CCreatureAnim(int x, int y, std::string name, Rect picPos, unsigned char flags, EAnimType type): +CCreatureAnim::CCreatureAnim(int x, int y, std::string name, Rect picPos, ui8 flags, EAnimType type): CShowableAnim(x,y,name,flags,3,type) { xOffset = picPos.x; diff --git a/client/CAnimation.h b/client/CAnimation.h index 8d50f1d94..e17291137 100644 --- a/client/CAnimation.h +++ b/client/CAnimation.h @@ -1,14 +1,6 @@ -#ifndef __CANIMATION_H__ -#define __CANIMATION_H__ +#pragma once -#include -#include -#include -#include -#include - -#include "../global.h" #include "GUIBase.h" /* @@ -46,7 +38,7 @@ private: //offset[group][frame] - offset of frame data in file std::map > offset; - unsigned char * data; + ui8 * data; SDL_Color * palette; public: @@ -135,7 +127,7 @@ class CompImage : public IImage //RLE-d data ui8 * surf; //array of offsets for each line - unsigned int * line; + ui32 * line; //palette SDL_Color *palette; @@ -237,13 +229,13 @@ private: size_t frame; size_t group; int player; - unsigned char flags; + ui8 flags; void init(); public: - CAnimImage(std::string name, size_t Frame, size_t Group=0, int x=0, int y=0, unsigned char Flags=0); - CAnimImage(CAnimation* anim, size_t Frame, size_t Group=0, int x=0, int y=0, unsigned char Flags=0); + CAnimImage(std::string name, size_t Frame, size_t Group=0, int x=0, int y=0, ui8 Flags=0); + CAnimImage(CAnimation* anim, size_t Frame, size_t Group=0, int x=0, int y=0, ui8 Flags=0); ~CAnimImage();//d-tor //size of animation @@ -278,10 +270,10 @@ protected: size_t first, last; //animation range //TODO: replace with time delay(needed for battles) - unsigned int frameDelay;//delay in frames of each image - unsigned int value;//how many times current frame was showed + ui32 frameDelay;//delay in frames of each image + ui32 value;//how many times current frame was showed - unsigned char flags;//Flags from EFlags enum + ui8 flags;//Flags from EFlags enum //blit image with optional rotation, fitting into rect, etc void blitImage(size_t frame, size_t group, SDL_Surface *to); @@ -296,9 +288,9 @@ public: boost::function callback; //Set per-surface alpha, 0 = transparent, 255 = opaque - void setAlpha(unsigned int alphaValue); + void setAlpha(ui32 alphaValue); - CShowableAnim(int x, int y, std::string name, unsigned char flags=0, unsigned int Delay=4, size_t Group=0); + CShowableAnim(int x, int y, std::string name, ui8 flags=0, ui32 Delay=4, size_t Group=0); ~CShowableAnim(); //set animation to group or part of group @@ -376,8 +368,6 @@ public: void clearAndSet(EAnimType type); CCreatureAnim(int x, int y, std::string name, Rect picPos, - unsigned char flags= USE_RLE, EAnimType = HOLDING ); + ui8 flags= USE_RLE, EAnimType = HOLDING ); }; - -#endif // __CANIMATIONHANDLER_H__ diff --git a/client/CBitmapHandler.cpp b/client/CBitmapHandler.cpp index 5a3723fa3..63337fa0e 100644 --- a/client/CBitmapHandler.cpp +++ b/client/CBitmapHandler.cpp @@ -1,12 +1,11 @@ -#include "../stdafx.h" +#include "StdInc.h" + #include "SDL.h" #include "SDL_image.h" #include "CBitmapHandler.h" #include "CDefHandler.h" #include "../lib/CLodHandler.h" #include "../lib/vcmi_endian.h" -#include -#include /* * CBitmapHandler.cpp, part of VCMI engine @@ -18,14 +17,14 @@ * */ -extern DLL_EXPORT CLodHandler *bitmaph; -extern DLL_EXPORT CLodHandler *bitmaph_ab; -extern DLL_EXPORT CLodHandler *spriteh; +extern DLL_LINKAGE CLodHandler *bitmaph; +extern DLL_LINKAGE CLodHandler *bitmaph_ab; +extern DLL_LINKAGE CLodHandler *spriteh; void CPCXConv::openPCX(char * PCX, int len) { pcxs=len; - pcx=(unsigned char*)PCX; + pcx=(ui8*)PCX; } void CPCXConv::fromFile(std::string path) { @@ -34,7 +33,7 @@ void CPCXConv::fromFile(std::string path) is.seekg(0,std::ios::end); // to the end pcxs = is.tellg(); // read length is.seekg(0,std::ios::beg); // wracamy na poczatek - pcx = new unsigned char[pcxs]; // allocate memory + pcx = new ui8[pcxs]; // allocate memory is.read((char*)pcx, pcxs); // read map file to buffer is.close(); } @@ -119,7 +118,7 @@ SDL_Surface * CPCXConv::getSurface() const return ret; } -bool isPCX(const unsigned char *header)//check whether file can be PCX according to 1st 12 bytes +bool isPCX(const ui8 *header)//check whether file can be PCX according to 1st 12 bytes { int fSize = read_le_u32(header + 0); int width = read_le_u32(header + 4); @@ -142,7 +141,7 @@ SDL_Surface * BitmapHandler::loadBitmapFromLod(CLodHandler *lod, std::string fna SDL_Surface * ret=NULL; int size; - unsigned char * file = 0; + ui8 * file = 0; file = lod->giveFile(fname, FILE_GRAPHICS, &size); if (isPCX(file)) diff --git a/client/CBitmapHandler.h b/client/CBitmapHandler.h index 563b2fcb1..d8ceedf63 100644 --- a/client/CBitmapHandler.h +++ b/client/CBitmapHandler.h @@ -1,8 +1,7 @@ -#ifndef __CBITMAPHANDLER_H__ -#define __CBITMAPHANDLER_H__ +#pragma once + -#include "../global.h" struct SDL_Surface; class CLodHandler; @@ -21,14 +20,14 @@ enum Epcxformat {PCX8B, PCX24B}; /// Struct which stands for a simple rgba palette struct BMPPalette { - unsigned char R,G,B,F; + ui8 R,G,B,F; }; /// Class which converts pcx to bmp images class CPCXConv { public: - unsigned char * pcx, *bmp; + ui8 * pcx, *bmp; int pcxs, bmps; void fromFile(std::string path); void saveBMP(std::string path) const; @@ -52,5 +51,3 @@ namespace BitmapHandler //Load file from any LODs SDL_Surface * loadBitmap(std::string fname, bool setKey=true); }; - -#endif // __CBITMAPHANDLER_H__ diff --git a/client/CCastleInterface.cpp b/client/CCastleInterface.cpp index 6e4d5a46b..8ae467671 100644 --- a/client/CCastleInterface.cpp +++ b/client/CCastleInterface.cpp @@ -1,13 +1,6 @@ -#include "../stdafx.h" - -#include -#include -#include -#include -#include -#include - +#include "StdInc.h" #include "CCastleInterface.h" + #include "../CCallback.h" #include "../lib/CArtHandler.h" #include "../lib/CBuildingHandler.h" @@ -28,6 +21,7 @@ #include "CPlayerInterface.h" #include "Graphics.h" #include "SDL_Extensions.h" +#include "../lib/GameConstants.h" using namespace boost::assign; @@ -126,7 +120,7 @@ void CBuildingRect::clickRight(tribool down, bool previousState) { int bid = hordeToDwellingID(str->ID); const CBuilding *bld = CGI->buildh->buildings[str->townID].find(bid)->second; - if (bid < Buildings::DWELL_FIRST) + if (bid < EBuilding::DWELL_FIRST) { std::vector comps(1, new SComponent(SComponent::building, bld->tid, bld->bid, @@ -136,13 +130,13 @@ void CBuildingRect::clickRight(tribool down, bool previousState) } else { - int level = ( bid - Buildings::DWELL_FIRST ) % CREATURES_PER_TOWN; + int level = ( bid - EBuilding::DWELL_FIRST ) % GameConstants::CREATURES_PER_TOWN; GH.pushInt(new CDwellingInfoBox(parent->pos.x+parent->pos.w/2, parent->pos.y+parent->pos.h/2, town, level)); } } } -SDL_Color multiplyColors (const SDL_Color &b, const SDL_Color &a, float f) +SDL_Color multiplyColors (const SDL_Color &b, const SDL_Color &a, double f) { SDL_Color ret; ret.r = a.r*f + b.r*(1-f); @@ -153,12 +147,12 @@ SDL_Color multiplyColors (const SDL_Color &b, const SDL_Color &a, float f) void CBuildingRect::show(SDL_Surface *to) { - const unsigned int stageDelay = 16; + const ui32 stageDelay = 16; - const unsigned int S1_TRANSP = 16; //0.5 sec building appear 0->100 transparency - const unsigned int S2_WHITE_B = 32; //0.5 sec border glows from white to yellow - const unsigned int S3_YELLOW_B= 48; //0.5 sec border glows from yellow to normal - const unsigned int BUILDED = 80; // 1 sec delay, nothing happens + const ui32 S1_TRANSP = 16; //0.5 sec building appear 0->100 transparency + const ui32 S2_WHITE_B = 32; //0.5 sec border glows from white to yellow + const ui32 S3_YELLOW_B= 48; //0.5 sec border glows from yellow to normal + const ui32 BUILDED = 80; // 1 sec delay, nothing happens if (stateCounter < S1_TRANSP) { @@ -184,15 +178,15 @@ void CBuildingRect::show(SDL_Surface *to) SDL_Color c2 = {120, 100, 60, 255}; SDL_Color c3 = {200, 180, 110, 255}; - unsigned int colorID = SDL_MapRGB(border->format, c3.r, c3.g, c3.b); + ui32 colorID = SDL_MapRGB(border->format, c3.r, c3.g, c3.b); SDL_Color oldColor = border->format->palette->colors[colorID]; SDL_Color newColor; if (stateCounter < S2_WHITE_B) - newColor = multiplyColors(c1, c2, float(stateCounter%stageDelay)/stageDelay); + newColor = multiplyColors(c1, c2, static_cast(stateCounter % stageDelay) / stageDelay); else if (stateCounter < S3_YELLOW_B) - newColor = multiplyColors(c2, c3, float(stateCounter%stageDelay)/stageDelay); + newColor = multiplyColors(c2, c3, static_cast(stateCounter % stageDelay) / stageDelay); else newColor = oldColor; @@ -224,7 +218,7 @@ std::string getBuildingSubtitle(int tid, int bid)//hover text for building return CGI->buildh->buildings[tid].find(bid)->second->Name(); else//dwellings - recruit %creature% { - int creaID = t->creatures[(bid-30)%CREATURES_PER_TOWN].second.back();//taking last of available creatures + int creaID = t->creatures[(bid-30)%GameConstants::CREATURES_PER_TOWN].second.back();//taking last of available creatures return CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures[creaID]->namePl; } } @@ -272,7 +266,7 @@ CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstanc available = new CLabel(80,190, FONT_SMALL, CENTER, zwykly, CGI->generaltexth->allTexts[217] + text); costPerTroop = new CLabel(80, 227, FONT_SMALL, CENTER, zwykly, CGI->generaltexth->allTexts[346]); - for(int i = 0; icost[i]) { @@ -484,7 +478,7 @@ CCastleBuildings::CCastleBuildings(const CGTownInstance* Town): if(shipyard && vstd::contains(groups, shipyard->group)) { std::vector vobjs = LOCPLINT->cb->getVisitableObjs(town->bestLocation()); - if(!vobjs.empty() && (vobjs.front()->ID == 8 || vobjs.front()->ID == HEROI_TYPE)) //there is visitable obj at shipyard output tile and it's a boat or hero (on boat) + if(!vobjs.empty() && (vobjs.front()->ID == 8 || vobjs.front()->ID == GameConstants::HEROI_TYPE)) //there is visitable obj at shipyard output tile and it's a boat or hero (on boat) { groups[shipyard->group].push_back(CGI->townh->structures[town->subID][20]); } @@ -652,52 +646,52 @@ void CCastleBuildings::buildingClicked(int building) building = hordeToDwellingID(building); const CBuilding *b = CGI->buildh->buildings[town->subID].find(building)->second; - if(building >= Buildings::DWELL_FIRST) + if(building >= EBuilding::DWELL_FIRST) { - enterDwelling((building-Buildings::DWELL_FIRST)%CREATURES_PER_TOWN); + enterDwelling((building-EBuilding::DWELL_FIRST)%GameConstants::CREATURES_PER_TOWN); } else { switch(building) { - case Buildings::MAGES_GUILD_1: - case Buildings::MAGES_GUILD_2: - case Buildings::MAGES_GUILD_3: - case Buildings::MAGES_GUILD_4: - case Buildings::MAGES_GUILD_5: + case EBuilding::MAGES_GUILD_1: + case EBuilding::MAGES_GUILD_2: + case EBuilding::MAGES_GUILD_3: + case EBuilding::MAGES_GUILD_4: + case EBuilding::MAGES_GUILD_5: enterMagesGuild(); break; - case Buildings::TAVERN: + case EBuilding::TAVERN: LOCPLINT->showTavernWindow(town); break; - case Buildings::SHIPYARD: + case EBuilding::SHIPYARD: LOCPLINT->showShipyardDialog(town); break; - case Buildings::FORT: - case Buildings::CITADEL: - case Buildings::CASTLE: + case EBuilding::FORT: + case EBuilding::CITADEL: + case EBuilding::CASTLE: GH.pushInt(new CFortScreen(town)); break; - case Buildings::VILLAGE_HALL: - case Buildings::CITY_HALL: - case Buildings::TOWN_HALL: - case Buildings::CAPITOL: + case EBuilding::VILLAGE_HALL: + case EBuilding::CITY_HALL: + case EBuilding::TOWN_HALL: + case EBuilding::CAPITOL: enterTownHall(); break; - case Buildings::MARKETPLACE: + case EBuilding::MARKETPLACE: GH.pushInt(new CMarketplaceWindow(town, town->visitingHero)); break; - case Buildings::BLACKSMITH: + case EBuilding::BLACKSMITH: enterBlacksmith(town->town->warMachine); break; - case Buildings::SPECIAL_1: + case EBuilding::SPECIAL_1: switch(town->subID) { case 1://Mystic Pond @@ -706,7 +700,7 @@ void CCastleBuildings::buildingClicked(int building) case 2: case 5: case 8://Artifact Merchant if(town->visitingHero) - GH.pushInt(new CMarketplaceWindow(town, town->visitingHero, RESOURCE_ARTIFACT)); + GH.pushInt(new CMarketplaceWindow(town, town->visitingHero, EMarketMode::RESOURCE_ARTIFACT)); else LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[273]) % b->Name())); //Only visiting heroes may use the %s. break; @@ -717,11 +711,11 @@ void CCastleBuildings::buildingClicked(int building) } break; - case Buildings::SHIP: + case EBuilding::SHIP: LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[51]); //Cannot build another boat break; - case Buildings::SPECIAL_2: + case EBuilding::SPECIAL_2: switch(town->subID) { case 1: //Fountain of Fortune @@ -730,7 +724,7 @@ void CCastleBuildings::buildingClicked(int building) case 6: //Freelancer's Guild if(getHero()) - GH.pushInt(new CMarketplaceWindow(town, getHero(), CREATURE_RESOURCE)); + GH.pushInt(new CMarketplaceWindow(town, getHero(), EMarketMode::CREATURE_RESOURCE)); else LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[273]) % b->Name())); //Only visiting heroes may use the %s. break; @@ -748,7 +742,7 @@ void CCastleBuildings::buildingClicked(int building) } break; - case Buildings::SPECIAL_3: + case EBuilding::SPECIAL_3: switch(town->subID) { case 0: //Brotherhood of sword @@ -764,10 +758,10 @@ void CCastleBuildings::buildingClicked(int building) break; case 5: //Portal of Summoning - if (town->creatures[CREATURES_PER_TOWN].second.empty())//No creatures + if (town->creatures[GameConstants::CREATURES_PER_TOWN].second.empty())//No creatures LOCPLINT->showInfoDialog(CGI->generaltexth->tcommands[30]); else - enterDwelling(CREATURES_PER_TOWN); + enterDwelling(GameConstants::CREATURES_PER_TOWN); break; case 6: //Ballista Yard @@ -887,13 +881,13 @@ void CCastleBuildings::enterMagesGuild() void CCastleBuildings::enterTownHall() { if(town->visitingHero && town->visitingHero->hasArt(2) && - !vstd::contains(town->builtBuildings, Buildings::GRAIL)) //hero has grail, but town does not have it + !vstd::contains(town->builtBuildings, EBuilding::GRAIL)) //hero has grail, but town does not have it { - if(!vstd::contains(town->forbiddenBuildings, Buildings::GRAIL)) + if(!vstd::contains(town->forbiddenBuildings, EBuilding::GRAIL)) { LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[597], //Do you wish this to be the permanent home of the Grail? std::vector(), - boost::bind(&CCallback::buildBuilding, LOCPLINT->cb, town, Buildings::GRAIL), + boost::bind(&CCallback::buildBuilding, LOCPLINT->cb, town, EBuilding::GRAIL), boost::bind(&CCastleBuildings::openTownHall, this), true); } else @@ -954,11 +948,11 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, int listPos): townlist = new CTownList(3, 744, 414, "IAM014", "IAM015"); townlist->fun = boost::bind(&CCastleInterface::townChange, this); - townlist->selected = vstd::findPos(LOCPLINT->towns, Town); + townlist->selected = vstd::find_pos(LOCPLINT->towns, Town); townlist->from = townlist->selected - listPos; - amax(townlist->from, 0); - amin(townlist->from, LOCPLINT->towns.size() - townlist->SIZE); + vstd::amax(townlist->from, 0); + vstd::amin(townlist->from, LOCPLINT->towns.size() - townlist->SIZE); LOCPLINT->castleInt = this; recreateIcons(); @@ -1034,9 +1028,9 @@ void CCastleInterface::recreateIcons() size_t iconIndex = town->subID*2; if (!town->hasFort()) - iconIndex += F_NUMBER*2; + iconIndex += GameConstants::F_NUMBER*2; - if(town->builded >= MAX_BUILDING_PER_TURN) + if(town->builded >= GameConstants::MAX_BUILDING_PER_TURN) iconIndex++; icon->setFrame(iconIndex); @@ -1073,7 +1067,7 @@ CCreaInfo::CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool } used = LCLICK | RCLICK | HOVER; - unsigned int creatureID = town->creatures[level].second.back(); + ui32 creatureID = town->creatures[level].second.back(); creature = CGI->creh->creatures[creatureID]; picture = new CAnimImage("CPRSMALL", creatureID+2, 0, 8, 0); @@ -1297,9 +1291,9 @@ void CHallInterface::CBuildingBox::hover(bool on) if(on) { std::string toPrint; - if(state==Buildings::PREREQUIRES) + if(state==EBuildingState::PREREQUIRES) toPrint = CGI->generaltexth->hcommands[5]; - else if(state==Buildings::CANT_BUILD_TODAY) + else if(state==EBuildingState::CANT_BUILD_TODAY) toPrint = CGI->generaltexth->allTexts[223]; else toPrint = CGI->generaltexth->hcommands[state]; @@ -1334,7 +1328,7 @@ CHallInterface::CBuildingBox::CBuildingBox(int x, int y, const CGTownInstance * pos.h = 92; state = LOCPLINT->cb->canBuildStructure(town,building->bid); - assert(state < Buildings::ERROR); + assert(state < EBuildingState::BUILDING_ERROR); static int panelIndex[9] = { 3, 3, 3, 0, 0, 2, 2, 1, 2}; static int iconIndex[9] = {-1, -1, -1, 0, 0, 1, 2, -1, 1}; @@ -1359,7 +1353,7 @@ CHallInterface::CHallInterface(const CGTownInstance *Town): Rect barRect(5, 556, 740, 18); statusBar = new CGStatusBar(new CPicture(*background, barRect, 5, 556, false)); - title = new CLabel(399, 12, FONT_MEDIUM, CENTER, zwykly, CGI->buildh->buildings[town->subID][town->hallLevel()+Buildings::VILLAGE_HALL]->Name()); + title = new CLabel(399, 12, FONT_MEDIUM, CENTER, zwykly, CGI->buildh->buildings[town->subID][town->hallLevel()+EBuilding::VILLAGE_HALL]->Name()); exit = new AdventureMapButton(CGI->generaltexth->hcommands[8], "", boost::bind(&CHallInterface::close,this), 748, 556, "TPMAGE1.DEF", SDLK_RETURN); exit->assignedKeys.insert(SDLK_ESCAPE); @@ -1468,7 +1462,7 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin buildingState = new CTextBox(getTextForState(state), Rect(33, 216, 329, 67), 0, FONT_SMALL, CENTER); //Create objects for all required resources - for(int i = 0; iresources[i]) { @@ -1478,7 +1472,7 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin } } - unsigned int rowSize[2]; + ui32 rowSize[2]; int posY; if (resAmount.size() > 4) {//Resources will be placed in multiple rows @@ -1492,7 +1486,7 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin } rowSize[1] = resAmount.size() - rowSize[0]; - unsigned int index=0; + ui32 index=0; for (size_t row=0; row<2; row++) { int posX = pos.w/2 - rowSize[row] * 40 + 24; @@ -1532,11 +1526,11 @@ void CFortScreen::close() CFortScreen::CFortScreen(const CGTownInstance * town) { OBJ_CONSTRUCTION_CAPTURING_ALL; - unsigned int fortSize = town->creatures.size(); - if (fortSize > CREATURES_PER_TOWN && town->creatures.back().second.empty()) + ui32 fortSize = town->creatures.size(); + if (fortSize > GameConstants::CREATURES_PER_TOWN && town->creatures.back().second.empty()) fortSize--; - if (fortSize == CREATURES_PER_TOWN) + if (fortSize == GameConstants::CREATURES_PER_TOWN) background = new CPicture("TPCASTL7"); else background = new CPicture("TPCASTL8"); @@ -1554,20 +1548,20 @@ CFortScreen::CFortScreen(const CGTownInstance * town) Point(10, 155), Point(404,155), Point(10, 288), Point(404,288); - if (fortSize == CREATURES_PER_TOWN) + if (fortSize == GameConstants::CREATURES_PER_TOWN) positions += Point(206,421); else positions += Point(10, 421), Point(404,421); - for (unsigned int i=0; ibuiltBuildings, Buildings::DWELL_UP_FIRST+i)) - buildingID = Buildings::DWELL_UP_FIRST+i; + if (vstd::contains(town->builtBuildings, EBuilding::DWELL_UP_FIRST+i)) + buildingID = EBuilding::DWELL_UP_FIRST+i; else - buildingID = Buildings::DWELL_FIRST+i; + buildingID = EBuilding::DWELL_FIRST+i; } else buildingID = 22; @@ -1678,7 +1672,7 @@ CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance * if (vstd::contains(town->builtBuildings, buildingID)) { - unsigned int available = town->creatures[level].first; + ui32 available = town->creatures[level].first; std::string availableText = CGI->generaltexth->allTexts[217]+ boost::lexical_cast(available); availableCount = new CLabel(78, 119, FONT_SMALL, CENTER, zwykly, availableText); } diff --git a/client/CCastleInterface.h b/client/CCastleInterface.h index cff7d37ee..e5a80045c 100644 --- a/client/CCastleInterface.h +++ b/client/CCastleInterface.h @@ -1,7 +1,6 @@ -#ifndef __CCASTLEINTERFACE_H__ -#define __CCASTLEINTERFACE_H__ +#pragma once + -#include "../global.h" #include "CAnimation.h" #include "GUIBase.h" @@ -31,6 +30,7 @@ struct Structure; * */ + /// Building "button" class CBuildingRect : public CShowableAnim { @@ -41,7 +41,7 @@ public: SDL_Surface* border; SDL_Surface* area; - unsigned int stateCounter;//For building construction - current stage in animation + ui32 stateCounter;//For building construction - current stage in animation CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const Structure *Str); //c-tor ~CBuildingRect(); //d-tor @@ -234,7 +234,7 @@ class CHallInterface : public CIntObject const CGTownInstance * town; const CBuilding * building; - unsigned int state;//Buildings::EBuildStructure enum + ui32 state;//Buildings::EBuildStructure enum CAnimImage * picture; CAnimImage * panel; @@ -392,5 +392,3 @@ class CBlacksmithDialog : public CIntObject public: CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid); }; - -#endif // __CCASTLEINTERFACE_H__ diff --git a/client/CConfigHandler.cpp b/client/CConfigHandler.cpp index e060d9c46..f6e34c6c9 100644 --- a/client/CConfigHandler.cpp +++ b/client/CConfigHandler.cpp @@ -1,11 +1,9 @@ -//#define BOOST_SPIRIT_DEBUG -#include "CConfigHandler.h" -#include -#include +#include "StdInc.h" #include -#include -#include +#include "CConfigHandler.h" + #include "../lib/JsonNode.h" +#include "../lib/GameConstants.h" using namespace config; @@ -148,10 +146,11 @@ CConfigHandler::~CConfigHandler(void) void config::CConfigHandler::init() { std::vector settings; - std::ifstream ifs(DATA_DIR "/config/settings.txt"); + std::string settingsDir = GameConstants::DATA_DIR + "/config/settings.txt"; + std::ifstream ifs(settingsDir.c_str()); if(!ifs) { - tlog1 << "Cannot open " DATA_DIR "/config/settings.txt !" << std::endl; + tlog1 << "Cannot open " << GameConstants::DATA_DIR << "/config/settings.txt !" << std::endl; return; } ifs.unsetf(std::ios::skipws); // Turn of white space skipping on the stream @@ -170,7 +169,7 @@ void config::CConfigHandler::init() tlog2 << "Not entire config/settings.txt parsed!\n"; /* Read resolutions. */ - const JsonNode config(DATA_DIR "/config/resolutions.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/resolutions.json"); const JsonVector &guisettings_vec = config["GUISettings"].Vector(); BOOST_FOREACH(const JsonNode &g, guisettings_vec) { diff --git a/client/CConfigHandler.h b/client/CConfigHandler.h index 25dab51a8..6863bd03a 100644 --- a/client/CConfigHandler.h +++ b/client/CConfigHandler.h @@ -1,6 +1,7 @@ -#ifndef __CCONFIGHANDLER_H__ -#define __CCONFIGHANDLER_H__ -#include "../global.h" +#pragma once + + + class CAdvMapInt; /* @@ -95,5 +96,3 @@ namespace config }; } extern config::CConfigHandler conf; - -#endif // __CCONFIGHANDLER_H__ diff --git a/client/CCreatureAnimation.cpp b/client/CCreatureAnimation.cpp index b70208a7c..5b10a7e90 100644 --- a/client/CCreatureAnimation.cpp +++ b/client/CCreatureAnimation.cpp @@ -1,8 +1,9 @@ +#include "StdInc.h" #include "CCreatureAnimation.h" + #include "../lib/CLodHandler.h" #include "../lib/VCMI_Lib.h" #include "../lib/vcmi_endian.h" -#include #include "SDL_Extensions.h" /* @@ -95,7 +96,7 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : internalFrame(0), onc frames = totalEntries; } -int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool attacker, unsigned char animCount, bool incrementFrame, bool yellowBorder, bool blueBorder, SDL_Rect * destRect) +int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool attacker, ui8 animCount, bool incrementFrame, bool yellowBorder, bool blueBorder, SDL_Rect * destRect) { return nextFrame(dest, x-fullWidth/2, y-fullHeight/2, attacker, animCount, incrementFrame, yellowBorder, blueBorder, destRect); } @@ -159,7 +160,7 @@ void CCreatureAnimation::playOnce( CCreatureAnim::EAnimType type ) template -int CCreatureAnimation::nextFrameT(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool IncrementFrame /*= true*/, bool yellowBorder /*= false*/, bool blueBorder /*= false*/, SDL_Rect * destRect /*= NULL*/) +int CCreatureAnimation::nextFrameT(SDL_Surface * dest, int x, int y, bool attacker, ui8 animCount, bool IncrementFrame /*= true*/, bool yellowBorder /*= false*/, bool blueBorder /*= false*/, SDL_Rect * destRect /*= NULL*/) { //increasing frame number int SIndex = curFrame; @@ -172,17 +173,17 @@ int CCreatureAnimation::nextFrameT(SDL_Surface * dest, int x, int y, bool attack i, FullHeight, #endif - unsigned char SegmentType, SegmentLength; - unsigned int i; + ui8 SegmentType, SegmentLength; + ui32 i; i = SEntries[SIndex].offset; /*int prSize = read_le_u32(FDef + i);*/ i += 4; //TODO use me - const unsigned int defType2 = read_le_u32(FDef + i); i += 4; - const unsigned int FullWidth = read_le_u32(FDef + i); i += 4; - const unsigned int FullHeight = read_le_u32(FDef + i); i += 4; - const unsigned int SpriteWidth = read_le_u32(FDef + i); i += 4; - const unsigned int SpriteHeight = read_le_u32(FDef + i); i += 4; + const ui32 defType2 = read_le_u32(FDef + i); i += 4; + const ui32 FullWidth = read_le_u32(FDef + i); i += 4; + const ui32 FullHeight = read_le_u32(FDef + i); i += 4; + const ui32 SpriteWidth = read_le_u32(FDef + i); i += 4; + const ui32 SpriteHeight = read_le_u32(FDef + i); i += 4; const int LeftMargin = read_le_u32(FDef + i); i += 4; const int TopMargin = read_le_u32(FDef + i); i += 4; const int RightMargin = FullWidth - SpriteWidth - LeftMargin; @@ -224,7 +225,7 @@ int CCreatureAnimation::nextFrameT(SDL_Surface * dest, int x, int y, bool attack const int remainder = ftcp % FullWidth; int xB = (attacker ? remainder : FullWidth - remainder - 1) + x; - const unsigned char aCountMod = (animCount & 0x20) ? ((animCount & 0x1e) >> 1) << 4 : (0x0f - ((animCount & 0x1e) >> 1)) << 4; + const ui8 aCountMod = (animCount & 0x20) ? ((animCount & 0x1e) >> 1) << 4 : (0x0f - ((animCount & 0x1e) >> 1)) << 4; for (int k = 0; k <= SegmentLength; k++) { @@ -265,7 +266,7 @@ int CCreatureAnimation::nextFrameT(SDL_Surface * dest, int x, int y, bool attack return 0; } -int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker, unsigned char animCount, bool IncrementFrame, bool yellowBorder, bool blueBorder, SDL_Rect * destRect) +int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker, ui8 animCount, bool IncrementFrame, bool yellowBorder, bool blueBorder, SDL_Rect * destRect) { switch(dest->format->BytesPerPixel) { @@ -296,10 +297,10 @@ inline void CCreatureAnimation::putPixel( const int & ftcpX, const int & ftcpY, const BMPPalette & color, - const unsigned char & palc, + const ui8 & palc, const bool & yellowBorder, const bool & blueBorder, - const unsigned char & animCount + const ui8 & animCount ) const { if(palc!=0) diff --git a/client/CCreatureAnimation.h b/client/CCreatureAnimation.h index eca542fbe..dd8170afc 100644 --- a/client/CCreatureAnimation.h +++ b/client/CCreatureAnimation.h @@ -1,8 +1,6 @@ -#ifndef __CCREATUREANIMATION_H__ -#define __CCREATUREANIMATION_H__ +#pragma once -#include "../global.h" #include "CDefHandler.h" #include "GUIBase.h" #include "../client/CBitmapHandler.h" @@ -41,22 +39,22 @@ private: const int & ftcpX, const int & ftcpY, const BMPPalette & color, - const unsigned char & palc, + const ui8 & palc, const bool & yellowBorder, const bool & blueBorder, - const unsigned char & animCount + const ui8 & animCount ) const; //////////// - unsigned char * FDef; //animation raw data + ui8 * FDef; //animation raw data int curFrame, internalFrame; //number of currently displayed frame - unsigned int frames; //number of frames + ui32 frames; //number of frames CCreatureAnim::EAnimType type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1]) template - int nextFrameT(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next - int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool IncrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next + int nextFrameT(SDL_Surface * dest, int x, int y, bool attacker, ui8 animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next + int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, ui8 animCount, bool IncrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next std::map > frameGroups; //groups of frames; [groupID] -> vector of frame IDs in group bool once; @@ -69,7 +67,7 @@ public: void setType(CCreatureAnim::EAnimType type); //sets type of animation and cleares framecount CCreatureAnim::EAnimType getType() const; //returns type of animation - int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next + int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, ui8 animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next void incrementFrame(); int getFrame() const; // Gets the current frame ID relative to DEF file. int getAnimationFrame() const; // Gets the current frame ID relative to frame group. @@ -80,5 +78,3 @@ public: int framesInGroup(CCreatureAnim::EAnimType group) const; //retirns number of fromes in given group }; - -#endif // __CCREATUREANIMATION_H__ diff --git a/client/CCreatureWindow.cpp b/client/CCreatureWindow.cpp index 0e92183bf..7a83b02bc 100644 --- a/client/CCreatureWindow.cpp +++ b/client/CCreatureWindow.cpp @@ -1,4 +1,6 @@ +#include "StdInc.h" #include "CCreatureWindow.h" + #include "../lib/CCreatureSet.h" #include "CGameInfo.h" #include "../lib/CGeneralTextHandler.h" @@ -14,13 +16,6 @@ #include "CPlayerInterface.h" #include "CConfigHandler.h" -#include -#include -#include -#include -#include -#include -#include #include "../lib/CGameState.h" #include "../lib/BattleState.h" #include "../lib/CSpellHandler.h" @@ -180,8 +175,8 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * } bonusRows = std::min ((int)((bonusItems.size() + 1) / 2), (conf.cc.resy - 230) / 60); - amin(bonusRows, 4); - amax(bonusRows, 1); + vstd::amin(bonusRows, 4); + vstd::amax(bonusRows, 1); bitmap = new CPicture("CreWin" + boost::lexical_cast(bonusRows) + ".pcx"); //1 to 4 rows for now bitmap->colorizeAndConvert(LOCPLINT->playerID); @@ -206,7 +201,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * new CPicture(graphics->pskillsm->ourImages[4].bitmap, 335, 50, false); //exp icon - Print it always? if (type) //not in fort window { - if (STACK_EXP) + if (GameConstants::STACK_EXP) { int rank = std::min(stack->getExpRank(), 10); //hopefully nobody adds more printAtMiddle(CGI->generaltexth->zcrexp[rank] + " [" + boost::lexical_cast(rank) + "]", 436, 62, FONT_MEDIUM, tytulowy,*bitmap); @@ -214,7 +209,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * if (type > BATTLE) //we need it only on adv. map { int tier = stack->type->level; - if (!iswith(tier, 1, 7)) + if (!vstd::iswithin(tier, 1, 7)) tier = 0; int number; std::string expText = CGI->generaltexth->zcrexp[324]; @@ -253,7 +248,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * } } - if (STACK_ARTIFACT && type > BATTLE) + if (GameConstants::STACK_ARTIFACT && type > BATTLE) { //SDL_Rect rect = genRect(44,44,465,98); //creatureArtifact = new CArtPlace(NULL); diff --git a/client/CCreatureWindow.h b/client/CCreatureWindow.h index d3c001bc0..9358d79b0 100644 --- a/client/CCreatureWindow.h +++ b/client/CCreatureWindow.h @@ -1,4 +1,6 @@ -#include "../global.h" +#pragma once + + #include "GUIBase.h" #include "GUIClasses.h" #include "../lib/HeroBonus.h" diff --git a/client/CCursorHandler.cpp b/client/CCursorHandler.cpp index 74aae01b6..517005c45 100644 --- a/client/CCursorHandler.cpp +++ b/client/CCursorHandler.cpp @@ -1,5 +1,6 @@ -#include "../stdafx.h" +#include "StdInc.h" #include "CCursorHandler.h" + #include "SDL.h" #include "SDL_Extensions.h" #include "CGameInfo.h" diff --git a/client/CCursorHandler.h b/client/CCursorHandler.h index 0c7e54220..6dc668f47 100644 --- a/client/CCursorHandler.h +++ b/client/CCursorHandler.h @@ -1,7 +1,7 @@ -#ifndef __CCURSORHANDLER_H__ -#define __CCURSORHANDLER_H__ -#include "../global.h" -#include +#pragma once + + + struct SDL_Thread; class CDefHandler; struct SDL_Surface; @@ -41,7 +41,3 @@ public: void centerCursor(); ~CCursorHandler(); }; - - - -#endif // __CCURSORHANDLER_H__ diff --git a/client/CDefHandler.cpp b/client/CDefHandler.cpp index ddb72b6a5..19862e122 100644 --- a/client/CDefHandler.cpp +++ b/client/CDefHandler.cpp @@ -1,7 +1,7 @@ -#include "../stdafx.h" +#include "StdInc.h" #include "SDL.h" #include "CDefHandler.h" -#include + #include "../lib/CLodHandler.h" #include "../lib/VCMI_Lib.h" #include "../lib/vcmi_endian.h" @@ -51,19 +51,19 @@ CDefEssential::~CDefEssential() SDL_FreeSurface(ourImages[i].bitmap); } -void CDefHandler::openFromMemory(unsigned char *table, const std::string & name) +void CDefHandler::openFromMemory(ui8 *table, const std::string & name) { BMPPalette palette[256]; SDefEntry &de = * reinterpret_cast(table); - unsigned char *p; + ui8 *p; defName = name; DEFType = SDL_SwapLE32(de.DEFType); width = SDL_SwapLE32(de.width); height = SDL_SwapLE32(de.height); - unsigned int totalBlocks = SDL_SwapLE32(de.totalBlocks); + ui32 totalBlocks = SDL_SwapLE32(de.totalBlocks); - for (unsigned int it=0;it<256;it++) + for (ui32 it=0;it<256;it++) { palette[it].R = de.palette[it].R; palette[it].G = de.palette[it].G; @@ -72,22 +72,22 @@ void CDefHandler::openFromMemory(unsigned char *table, const std::string & name) } // The SDefEntryBlock starts just after the SDefEntry - p = reinterpret_cast(&de); + p = reinterpret_cast(&de); p += sizeof(de); int totalEntries=0; - for (unsigned int z=0; z(p); - unsigned int totalInBlock; + ui32 totalInBlock; totalInBlock = read_le_u32(&block.totalInBlock); - for (unsigned int j=SEntries.size(); j> 5; BR = N & 0x1F; } -SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, const BMPPalette * palette) const +SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const BMPPalette * palette) const { SDL_Surface * ret=NULL; - unsigned int BaseOffset, + ui32 BaseOffset, SpriteWidth, SpriteHeight, //format of sprite TotalRowLength, // length of read segment add, FullHeight,FullWidth, @@ -143,7 +143,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co int LeftMargin, RightMargin, TopMargin, BottomMargin; - unsigned char SegmentType;//, BL, BR; //TODO use me + ui8 SegmentType;//, BL, BR; //TODO use me BaseOffset = SEntries[SIndex].offset; SSpriteDef sd = * reinterpret_cast(FDef + BaseOffset); @@ -201,7 +201,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co { case 0: { - for (unsigned int i=0;i0) ftcp += LeftMargin; @@ -218,9 +218,9 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co case 1: { - const unsigned int * RWEntriesLoc = reinterpret_cast(FDef+BaseOffset); + const ui32 * RWEntriesLoc = reinterpret_cast(FDef+BaseOffset); BaseOffset += sizeof(int) * SpriteHeight; - for (unsigned int i=0;i0) @@ -229,7 +229,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co TotalRowLength=0; do { - unsigned int SegmentLength; + ui32 SegmentLength; SegmentType=FDef[BaseOffset++]; SegmentLength=FDef[BaseOffset++] + 1; @@ -262,7 +262,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co { BaseOffset = BaseOffsetor + read_le_u16(FDef + BaseOffsetor); - for (unsigned int i=0;i0) @@ -273,8 +273,8 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co do { SegmentType=FDef[BaseOffset++]; - unsigned char code = SegmentType / 32; - unsigned char value = (SegmentType & 31) + 1; + ui8 code = SegmentType / 32; + ui8 value = (SegmentType & 31) + 1; if(code==7) { memcpy(reinterpret_cast(ret->pixels)+ftcp, &FDef[BaseOffset], value); @@ -302,7 +302,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co case 3: { - for (unsigned int i=0;i0) @@ -313,11 +313,11 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co do { SegmentType=FDef[BaseOffset++]; - unsigned char code = SegmentType / 32; - unsigned char value = (SegmentType & 31) + 1; + ui8 code = SegmentType / 32; + ui8 value = (SegmentType & 31) + 1; - int len = std::min(value, SpriteWidth - TotalRowLength) - std::max(0, -LeftMargin); - amax(len, 0); + int len = std::min(value, SpriteWidth - TotalRowLength) - std::max(0, -LeftMargin); + vstd::amax(len, 0); if(code==7) { @@ -365,7 +365,7 @@ CDefEssential * CDefHandler::essentialize() CDefHandler * CDefHandler::giveDef(const std::string & defName) { - unsigned char * data = spriteh->giveFile(defName, FILE_ANIMATION); + ui8 * data = spriteh->giveFile(defName, FILE_ANIMATION); if(!data) throw "bad def name!"; CDefHandler * nh = new CDefHandler(); diff --git a/client/CDefHandler.h b/client/CDefHandler.h index 7bac7a388..a1c6f5706 100644 --- a/client/CDefHandler.h +++ b/client/CDefHandler.h @@ -1,7 +1,6 @@ -#ifndef __CDEFHANDLER_H__ -#define __CDEFHANDLER_H__ +#pragma once + -#include "../global.h" struct SDL_Surface; struct BMPPalette; @@ -30,7 +29,7 @@ struct SDefEntryBlock { ui32 totalInBlock; ui32 unknown2; ui32 unknown3; - unsigned char data[0]; + ui8 data[0]; }; // Def entry in file. Integer fields are all little endian and will @@ -42,9 +41,9 @@ struct SDefEntry { ui32 totalBlocks; struct { - unsigned char R; - unsigned char G; - unsigned char B; + ui8 R; + ui8 G; + ui8 B; } palette[256]; // SDefEntry is followed by a series of SDefEntryBlock @@ -75,9 +74,9 @@ public: class CDefHandler { private: - unsigned int DEFType; + ui32 DEFType; int length; - //unsigned int * RWEntries; + //ui32 * RWEntries; struct SEntry { std::string name; @@ -94,15 +93,11 @@ public: CDefHandler(); //c-tor ~CDefHandler(); //d-tor - SDL_Surface * getSprite (int SIndex, const unsigned char * FDef, const BMPPalette * palette) const; //saves picture with given number to "testtt.bmp" - static void expand(unsigned char N,unsigned char & BL, unsigned char & BR); - void openFromMemory(unsigned char * table, const std::string & name); + SDL_Surface * getSprite (int SIndex, const ui8 * FDef, const BMPPalette * palette) const; //saves picture with given number to "testtt.bmp" + static void expand(ui8 N,ui8 & BL, ui8 & BR); + void openFromMemory(ui8 * table, const std::string & name); CDefEssential * essentialize(); static CDefHandler * giveDef(const std::string & defName); static CDefEssential * giveDefEss(const std::string & defName); }; - - - -#endif // __CDEFHANDLER_H__ diff --git a/client/CGameInfo.cpp b/client/CGameInfo.cpp index f929cedaf..e2fb7c2a0 100644 --- a/client/CGameInfo.cpp +++ b/client/CGameInfo.cpp @@ -1,5 +1,6 @@ -#include "../stdafx.h" +#include "StdInc.h" #include "CGameInfo.h" + #include "../lib/VCMI_Lib.h" /* diff --git a/client/CGameInfo.h b/client/CGameInfo.h index c24d98f29..1b945fd43 100644 --- a/client/CGameInfo.h +++ b/client/CGameInfo.h @@ -1,9 +1,8 @@ -#ifndef __CGAMEINFO_H__ -#define __CGAMEINFO_H__ -#include "../global.h" -#include "../lib/ConstTransitivePtr.h" +#pragma once +#include "../lib/ConstTransitivePtr.h" + /* * CGameInfo.h, part of VCMI engine * @@ -42,6 +41,7 @@ public: CCursorHandler * curh; IMainVideoPlayer * videoh; }; +extern CClientState * CCS; struct Mapa; @@ -70,13 +70,4 @@ public: CGameInfo(); }; - -// -// public: -// -// ConstTransitivePtr generaltexth; - - - - -#endif // __CGAMEINFO_H__ +extern const CGameInfo* CGI; diff --git a/client/CHeroWindow.cpp b/client/CHeroWindow.cpp index 8e714107f..778acfefe 100644 --- a/client/CHeroWindow.cpp +++ b/client/CHeroWindow.cpp @@ -1,4 +1,5 @@ -#include "../stdafx.h" +#include "StdInc.h" + #include "AdventureMapButton.h" #include "CAdvmapInterface.h" #include "../CCallback.h" @@ -13,21 +14,13 @@ #include "CSpellWindow.h" #include "CConfigHandler.h" #include "CPlayerInterface.h" -#include "../global.h" + #include "../lib/CArtHandler.h" #include "CDefHandler.h" #include "../lib/CGeneralTextHandler.h" #include "../lib/CHeroHandler.h" #include "../lib/CLodHandler.h" #include "../lib/CObjectHandler.h" -#include -#include -#include -#include -#include -#include -#include -#include #undef min @@ -131,7 +124,7 @@ CHeroWindow::CHeroWindow(const CGHeroInstance *hero) //areas portraitArea = new LRClickableAreaWText(Rect(18, 18, 58, 64)); - for(int v=0; vtext = CGI->generaltexth->arraytxt[2+v]; diff --git a/client/CHeroWindow.h b/client/CHeroWindow.h index 46a418bc0..2059b225d 100644 --- a/client/CHeroWindow.h +++ b/client/CHeroWindow.h @@ -1,5 +1,5 @@ -#ifndef __CHEROWINDOW_H__ -#define __CHEROWINDOW_H__ +#pragma once + #include "../lib/HeroBonus.h" @@ -95,5 +95,3 @@ public: friend void CArtPlace::clickLeft(tribool down, bool previousState); friend class CPlayerInterface; }; - -#endif // __CHEROWINDOW_H__ diff --git a/client/CKingdomInterface.cpp b/client/CKingdomInterface.cpp index 73d5ff035..d9f21225b 100644 --- a/client/CKingdomInterface.cpp +++ b/client/CKingdomInterface.cpp @@ -1,11 +1,6 @@ +#include "StdInc.h" #include "CKingdomInterface.h" -#include -#include -#include -#include -#include - #include "../CCallback.h" #include "../lib/CCreatureHandler.h" //creatures name for objects list #include "../lib/CGeneralTextHandler.h" @@ -472,7 +467,7 @@ CKingdomInterface::CKingdomInterface() background = new CPicture(conf.go()->ac.overviewBg); background->colorize(LOCPLINT->playerID); pos = background->center(); - unsigned int footerPos = conf.go()->ac.overviewSize * 116; + ui32 footerPos = conf.go()->ac.overviewSize * 116; tabArea = new CTabbedInt(boost::bind(&CKingdomInterface::createMainTab, this, _1), CTabbedInt::DestroyFunc(), Point(4,4)); @@ -487,7 +482,7 @@ CKingdomInterface::CKingdomInterface() void CKingdomInterface::generateObjectsList(const std::vector &ownedObjects) { - unsigned int footerPos = conf.go()->ac.overviewSize * 116; + ui32 footerPos = conf.go()->ac.overviewSize * 116; size_t dwellSize = (footerPos - 64)/57; //Map used to determine image number for several objects @@ -563,8 +558,8 @@ CIntObject * CKingdomInterface::createMainTab(size_t index) void CKingdomInterface::generateMinesList(const std::vector &ownedObjects) { - unsigned int footerPos = conf.go()->ac.overviewSize * 116; - std::vector minesCount(RESOURCE_QUANTITY, 0); + ui32 footerPos = conf.go()->ac.overviewSize * 116; + std::vector minesCount(GameConstants::RESOURCE_QUANTITY, 0); int totalIncome=0; BOOST_FOREACH(const CGObjectInstance * object, ownedObjects) @@ -609,7 +604,7 @@ void CKingdomInterface::generateMinesList(const std::vectorac.overviewSize * 116; + ui32 footerPos = conf.go()->ac.overviewSize * 116; //Main control buttons btnHeroes = new AdventureMapButton (CGI->generaltexth->overview[11], CGI->generaltexth->overview[6], @@ -692,8 +687,8 @@ CKingdHeroList::CKingdHeroList(size_t maxSize) heroLabel = new CLabel(150, 10, FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->overview[0]); skillsLabel = new CLabel(500, 10, FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->overview[1]); - unsigned int townCount = LOCPLINT->cb->howManyHeroes(false); - unsigned int size = conf.go()->ac.overviewSize*116 + 19; + ui32 townCount = LOCPLINT->cb->howManyHeroes(false); + ui32 size = conf.go()->ac.overviewSize*116 + 19; heroes = new CListBox(boost::bind(&CKingdHeroList::createHeroItem, this, _1), boost::bind(&CKingdHeroList::destroyHeroItem, this, _1), Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size) ); } @@ -710,7 +705,7 @@ void CKingdHeroList::updateGarrisons() CIntObject* CKingdHeroList::createHeroItem(size_t index) { - unsigned int picCount = conf.go()->ac.overviewPics; + ui32 picCount = conf.go()->ac.overviewPics; size_t heroesCount = LOCPLINT->cb->howManyHeroes(false); if (index < heroesCount) @@ -745,8 +740,8 @@ CKingdTownList::CKingdTownList(size_t maxSize) garrHeroLabel = new CLabel(375,10,FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->overview[4]); visitHeroLabel = new CLabel(608,10,FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->overview[5]); - unsigned int townCount = LOCPLINT->cb->howManyTowns(); - unsigned int size = conf.go()->ac.overviewSize*116 + 19; + ui32 townCount = LOCPLINT->cb->howManyTowns(); + ui32 size = conf.go()->ac.overviewSize*116 + 19; towns = new CListBox(boost::bind(&CKingdTownList::createTownItem, this, _1), CListBox::DestroyFunc(), Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size) ); } @@ -774,7 +769,7 @@ void CKingdTownList::updateGarrisons() CIntObject* CKingdTownList::createTownItem(size_t index) { - unsigned int picCount = conf.go()->ac.overviewPics; + ui32 picCount = conf.go()->ac.overviewPics; size_t townsCount = LOCPLINT->cb->howManyTowns(); if (index < townsCount) @@ -799,9 +794,9 @@ CTownItem::CTownItem(const CGTownInstance* Town): size_t iconIndex = town->subID*2; if (!town->hasFort()) - iconIndex += F_NUMBER*2; + iconIndex += GameConstants::F_NUMBER*2; - if(town->builded >= MAX_BUILDING_PER_TURN) + if(town->builded >= GameConstants::MAX_BUILDING_PER_TURN) iconIndex++; picture = new CAnimImage("ITPT", iconIndex, 0, 5, 6); @@ -929,11 +924,11 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart * name = new CLabel(73, 7, FONT_SMALL, TOPLEFT, zwykly, hero->name); artsText = new CLabel(320, 55, FONT_SMALL, CENTER, zwykly, CGI->generaltexth->overview[2]); - for (size_t i=0; i #include "GUIBase.h" #include "GUIClasses.h" @@ -202,7 +199,7 @@ private: struct OwnedObjectInfo { int imageID; - unsigned int count; + ui32 count; std::string hoverText; }; std::vector objects; diff --git a/client/CMT.cpp b/client/CMT.cpp index 89a38795a..5f4a9871c 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -1,23 +1,16 @@ // CMT.cpp : Defines the entry point for the console application. // -#include "../stdafx.h" -#include -#include -#include -#include -#include -#include +#include "StdInc.h" #include -#include #include #include "SDL_Extensions.h" #include "SDL_framerate.h" #include "CGameInfo.h" #include "mapHandler.h" -#include "../global.h" + #include "CPreGame.h" #include "CCastleInterface.h" -#include "../CConsoleHandler.h" +#include "../lib/CConsoleHandler.h" #include "CCursorHandler.h" #include "../lib/CGameState.h" #include "../CCallback.h" @@ -39,18 +32,16 @@ #include "../lib/Connection.h" #include "../lib/VCMI_Lib.h" #include "../lib/VCMIDirs.h" -#include #include "../lib/NetPacks.h" #include "CMessage.h" #include "../lib/CObjectHandler.h" -#include #include "../lib/CArtHandler.h" #include "../lib/CScriptingModule.h" +#include "../lib/GameConstants.h" #ifdef _WIN32 #include "SDL_syswm.h" #endif -#include #include "../lib/CDefObjInfoHandler.h" #if __MINGW32__ @@ -70,7 +61,7 @@ namespace po = boost::program_options; */ std::string NAME_AFFIX = "client"; -std::string NAME = NAME_VER + std::string(" (") + NAME_AFFIX + ')'; //application name +std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')'; //application name CGuiHandler GH; static CClient *client; SDL_Surface *screen = NULL, //main screen surface @@ -104,14 +95,14 @@ void startGame(StartInfo * options, CConnection *serv = NULL); void init() { - timeHandler tmh, pomtime; + StopWatch tmh, pomtime; #if SDL_BYTEORDER == SDL_BIG_ENDIAN int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff; #else int rmask = 0x000000ff; int gmask = 0x0000ff00; int bmask = 0x00ff0000; int amask = 0xff000000; #endif CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask); - tlog0 << "\tInitializing minors: " << pomtime.getDif() << std::endl; + tlog0 << "\tInitializing minors: " << pomtime.getDiff() << std::endl; { //read system options CLoadFile settings(GVCMIDirs.UserPath + "/config/sysopts.bin", 727); @@ -128,7 +119,7 @@ void init() GDefaultOptions.settingsChanged(); } } - THC tlog0<<"\tLoading default system settings: "<musich = new CMusicHandler; CCS->musich->init(); CCS->musich->setVolume(GDefaultOptions.musicVolume); - tlog0<<"\tInitializing sound: "<(CGI)->setFromLib(); CCS->soundh->initCreaturesSounds(CGI->creh->creatures); CCS->soundh->initSpellsSounds(CGI->spellh->spells); - tlog0<<"Initializing VCMI_Lib: "<curh = new CCursorHandler; CCS->curh->initCursor(); CCS->curh->show(); - tlog0<<"Screen handler: "<loadHeroAnims(); - tlog0<<"\tMain graphics: "<cb = boost::bind(&processCommand, _1); console->start(); atexit(dispose); - tlog0 <<"Creating console and logfile: "< cannot load 32-bit DLLs for video handling @@ -263,7 +254,7 @@ int main(int argc, char** argv) #else CCS->videoh = new CVideoPlayer; #endif - tlog0<<"\tInitializing video: "<init(std::string(DATA_DIR "/Data/H3bitmap.lod"),""); + txth->init(GameConstants::DATA_DIR + "/Data/H3bitmap.lod",""); tlog0<<"done.\nScanning .lod file\n"; BOOST_FOREACH(Entry e, txth->entries) @@ -543,8 +534,8 @@ void dispose() static void setScreenRes(int w, int h, int bpp, bool fullscreen) { // VCMI will only work with 2, 3 or 4 bytes per pixel - amax(bpp, 16); - amin(bpp, 32); + vstd::amax(bpp, 16); + vstd::amin(bpp, 32); // Try to use the best screen depth for the display int suggestedBpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0)); diff --git a/client/CMessage.cpp b/client/CMessage.cpp index bca0f3613..e479fc02c 100644 --- a/client/CMessage.cpp +++ b/client/CMessage.cpp @@ -1,14 +1,12 @@ -#include "../stdafx.h" +#include "StdInc.h" #include "CMessage.h" + #include "SDL_ttf.h" #include "CDefHandler.h" #include "CAnimation.h" #include "CGameInfo.h" #include "SDL_Extensions.h" #include "../lib/CLodHandler.h" -#include -#include -#include #include "../lib/CGeneralTextHandler.h" #include "Graphics.h" #include "GUIClasses.h" @@ -59,8 +57,8 @@ namespace NMessage void CMessage::init() { { - piecesOfBox.resize(PLAYER_LIMIT); - for (int i=0;i CMessage::breakText( std::string text, size_t maxLineSi while (text.length()) { - unsigned int lineLength = 0; //in characters or given char metric - unsigned int z = 0; //our position in text + ui32 lineLength = 0; //in characters or given char metric + ui32 z = 0; //our position in text bool opened = false;//if we have an unclosed brace in current line bool lineManuallyBroken = false; @@ -153,10 +151,10 @@ std::vector CMessage::breakText( std::string text, size_t maxLineSi * possible. We backtrack on the line until we find a * suitable character. * Note: Cyrillic symbols have indexes 220-255 so we need - * to use unsigned char for comparison + * to use ui8 for comparison */ int pos = z-1; - while(pos > 0 && ((unsigned char)text[pos]) > ' ' ) + while(pos > 0 && ((ui8)text[pos]) > ' ' ) pos --; if (pos > 0) @@ -341,10 +339,10 @@ std::vector > * CMessage::drawText(std::vectorpos.x = GH.current->motion.x - ret->pos.w/2; // ret->pos.y = GH.current->motion.y - ret->pos.h/2; // // Put the window back on screen if necessary -// amax(ret->pos.x, 0); -// amax(ret->pos.y, 0); -// amin(ret->pos.x, conf.cc.resx - ret->pos.w); -// amin(ret->pos.y, conf.cc.resy - ret->pos.h); +// vstd::amax(ret->pos.x, 0); +// vstd::amax(ret->pos.y, 0); +// vstd::amin(ret->pos.x, conf.cc.resx - ret->pos.w); +// vstd::amin(ret->pos.y, conf.cc.resy - ret->pos.h); // } // else // { @@ -394,6 +392,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player) _or = FNT_RenderText(FONT_MEDIUM,CGI->generaltexth->allTexts[4],zwykly); const int sizes[][2] = {{400, 125}, {500, 150}, {600, 200}, {480, 400}}; + for(int i = 0; i < ARRAY_COUNT(sizes) && sizes[i][0] < conf.cc.resx - 150 @@ -425,12 +424,12 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player) } // Clip window size - amax(winSize.second, 50); - amax(winSize.first, 80); - amax(winSize.first, comps.w); - amax(winSize.first, bw); + vstd::amax(winSize.second, 50); + vstd::amax(winSize.first, 80); + vstd::amax(winSize.first, comps.w); + vstd::amax(winSize.first, bw); - amin(winSize.first, conf.cc.resx - 150); + vstd::amin(winSize.first, conf.cc.resx - 150); ret->bitmap = drawBox1 (winSize.first + 2*SIDE_MARGIN, winSize.second + 2*SIDE_MARGIN, player); ret->pos.h=ret->bitmap->h; @@ -596,14 +595,14 @@ ComponentsToBlit::ComponentsToBlit(std::vector & SComps, int maxw, if (curw + toadd > maxw) { curr++; - amax(w,curw); + vstd::amax(w,curw); curw = cur->comp->pos.w; comps.resize(curr+1); } else { curw += toadd; - amax(w,curw); + vstd::amax(w,curw); } comps[curr].push_back(cur); @@ -613,7 +612,7 @@ ComponentsToBlit::ComponentsToBlit(std::vector & SComps, int maxw, { int maxh = 0; for(size_t j=0;jcomp->pos.h); + vstd::amax(maxh,comps[i][j]->comp->pos.h); h += maxh + BETWEEN_COMPS_ROWS; } } @@ -627,7 +626,7 @@ void ComponentsToBlit::blitCompsOnSur( SDL_Surface * _or, int inter, int &curh, { ComponentResolved *cur = (comps)[i][j]; totalw += cur->comp->pos.w; - amax(maxh,cur->comp->getImg()->h);//subtitles height will added later + vstd::amax(maxh,cur->comp->getImg()->h);//subtitles height will added later } if(_or) { @@ -670,7 +669,7 @@ void ComponentsToBlit::blitCompsOnSur( SDL_Surface * _or, int inter, int &curh, } curw+=inter; } - amax(curh, textY); + vstd::amax(curh, textY); } curh += BETWEEN_COMPS_ROWS; } diff --git a/client/CMessage.h b/client/CMessage.h index 2af7423d4..d43fd034f 100644 --- a/client/CMessage.h +++ b/client/CMessage.h @@ -1,10 +1,7 @@ -#ifndef __CMESSAGE_H__ -#define __CMESSAGE_H__ +#pragma once #include "FontBase.h" -#include "../global.h" -//#include -#include + /* * CMessage.h, part of VCMI engine @@ -74,8 +71,3 @@ public: static void init(); static void dispose(); }; -// - - - -#endif // __CMESSAGE_H__ diff --git a/client/CMusicBase.h b/client/CMusicBase.h index dfa46bb8a..6dc6eb214 100644 --- a/client/CMusicBase.h +++ b/client/CMusicBase.h @@ -1,5 +1,4 @@ -#ifndef __CMUSICBASE_H__ -#define __CMUSICBASE_H__ +#pragma once /* * CMusicBase.h, part of VCMI engine @@ -87,6 +86,4 @@ public: #undef VCMI_MUSIC_FILE }; -#endif // __CMUSICBASE_H__ - diff --git a/client/CMusicHandler.cpp b/client/CMusicHandler.cpp index 3f07c6bfd..c5aec4b8d 100644 --- a/client/CMusicHandler.cpp +++ b/client/CMusicHandler.cpp @@ -1,11 +1,5 @@ -#include "../stdafx.h" - -#include -#include -#include +#include "StdInc.h" #include -#include - #include #include "CSndHandler.h" @@ -14,6 +8,7 @@ #include "../lib/CSpellHandler.h" #include "../client/CGameInfo.h" #include "../lib/JsonNode.h" +#include "../lib/GameConstants.h" /* * CMusicHandler.cpp, part of VCMI engine @@ -63,7 +58,7 @@ void CAudioBase::release() } } -void CAudioBase::setVolume(unsigned int percent) +void CAudioBase::setVolume(ui32 percent) { if (percent > 100) percent = 100; @@ -103,9 +98,9 @@ void CSoundHandler::init() if (initialized) { // Load sounds - sndh.add_file(std::string(DATA_DIR "/Data/Heroes3.snd")); - sndh.add_file(std::string(DATA_DIR "/Data/Heroes3-cd2.snd"), false); - sndh.add_file(std::string(DATA_DIR "/Data/H3ab_ahd.snd")); + sndh.add_file(std::string(GameConstants::DATA_DIR + "/Data/Heroes3.snd")); + sndh.add_file(std::string(GameConstants::DATA_DIR + "/Data/Heroes3-cd2.snd"), false); + sndh.add_file(std::string(GameConstants::DATA_DIR + "/Data/H3ab_ahd.snd")); Mix_ChannelFinished(soundFinishedCallbackC); } } @@ -172,7 +167,7 @@ soundBase::soundID CSoundHandler::getSoundID(const std::string &fileName) void CSoundHandler::initCreaturesSounds(const std::vector > &creatures) { tlog5 << "\t\tReading config/cr_sounds.json" << std::endl; - const JsonNode config(DATA_DIR "/config/cr_sounds.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/cr_sounds.json"); CBattleSounds.resize(creatures.size()); @@ -215,7 +210,7 @@ void CSoundHandler::initCreaturesSounds(const std::vector > &spells) { - const JsonNode config(DATA_DIR "/config/sp_sounds.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/sp_sounds.json"); if (!config["spell_sounds"].isNull()) { BOOST_FOREACH(const JsonNode &node, config["spell_sounds"].Vector()) { @@ -283,7 +278,7 @@ void CSoundHandler::stopSound( int handler ) } // Sets the sound volume, from 0 (mute) to 100 -void CSoundHandler::setVolume(unsigned int percent) +void CSoundHandler::setVolume(ui32 percent) { CAudioBase::setVolume(percent); @@ -420,7 +415,7 @@ void CMusicHandler::stopMusic(int fade_ms) } // Sets the music volume, from 0 (mute) to 100 -void CMusicHandler::setVolume(unsigned int percent) +void CMusicHandler::setVolume(ui32 percent) { CAudioBase::setVolume(percent); @@ -477,7 +472,7 @@ MusicEntry::~MusicEntry() void MusicEntry::load(musicBase::musicID ID) { currentID = ID; - filename = DATA_DIR "/Mp3/"; + filename = GameConstants::DATA_DIR + "/Mp3/"; filename += owner->musics[ID]; tlog5<<"Loading music file "< -#include - -#include +#pragma once #include "CSoundBase.h" #include "CMusicBase.h" @@ -62,8 +56,8 @@ public: virtual void init() = 0; virtual void release() = 0; - virtual void setVolume(unsigned int percent); - unsigned int getVolume() { return volume; }; + virtual void setVolume(ui32 percent); + ui32 getVolume() { return volume; }; }; class CSoundHandler: public CAudioBase @@ -88,7 +82,7 @@ public: void initCreaturesSounds(const std::vector > &creatures); void initSpellsSounds(const std::vector< ConstTransitivePtr > &spells); - void setVolume(unsigned int percent); + void setVolume(ui32 percent); // Sounds int playSound(soundBase::soundID soundID, int repeats=0); @@ -153,7 +147,7 @@ public: void init(); void release(); - void setVolume(unsigned int percent); + void setVolume(ui32 percent); // Musics std::map musics; @@ -167,5 +161,3 @@ public: void stopMusic(int fade_ms=1000); void musicFinishedCallback(void); }; - -#endif // __CMUSICHANDLER_H__ diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 0674fcc84..b34c91c99 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1,6 +1,8 @@ -#include "../stdafx.h" +#include "StdInc.h" + #include "CAdvmapInterface.h" -#include "CBattleInterface.h" +#include "BattleInterface/CBattleInterface.h" +#include "BattleInterface/CBattleConsole.h" #include "../CCallback.h" #include "CCastleInterface.h" #include "CCursorHandler.h" @@ -30,22 +32,10 @@ #include "../lib/map.h" #include "../lib/VCMIDirs.h" #include "mapHandler.h" -#include "../timeHandler.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../StartInfo.h" -#include +#include "../lib/StopWatch.h" +#include "../lib/StartInfo.h" #include "../lib/CGameState.h" +#include "../lib/GameConstants.h" #ifdef min #undef min @@ -116,7 +106,7 @@ CPlayerInterface::~CPlayerInterface() { howManyPeople--; //delete pim; - //delNull(pim); + //vstd::clear_pointer(pim); delete showingDialog; if(adventureInt) { @@ -383,14 +373,14 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe switch(specific->ID) { - case HEROI_TYPE: + case GameConstants::HEROI_TYPE: { InfoAboutHero iah; bool gotInfo = LOCPLINT->cb->getHeroInfo(specific, iah); assert(gotInfo); return graphics->drawHeroInfoWin(iah); } - case TOWNI_TYPE: + case GameConstants::TOWNI_TYPE: case 33: // Garrison case 219: { @@ -424,7 +414,7 @@ void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int if(CAltarWindow *ctw = dynamic_cast(GH.topInt())) ctw->setExpToLevel(); } - else if(which < PRIMARY_SKILLS) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4) + else if(which < GameConstants::PRIMARY_SKILLS) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4) updateInfo(hero); } @@ -729,7 +719,7 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i { boost::unique_lock un(*pim); - if(vstd::contains(stack->state,MOVED)) //this stack has moved and makes second action -> high morale + if(vstd::contains(stack->state,EBattleStackState::MOVED)) //this stack has moved and makes second action -> high morale { std::string hlp = CGI->generaltexth->allTexts[33]; boost::algorithm::replace_first(hlp,"%s",(stack->count != 1) ? stack->getCreature()->namePl : stack->getCreature()->nameSing); @@ -765,7 +755,7 @@ void CPlayerInterface::battleEnd(const BattleResult *br) battleInt->battleFinished(*br); } -void CPlayerInterface::battleStackMoved(const CStack * stack, std::vector dest, int distance) +void CPlayerInterface::battleStackMoved(const CStack * stack, std::vector dest, int distance) { if(LOCPLINT != this) { //another local interface should do this @@ -883,10 +873,10 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba) else { int shift = 0; - if(ba->counter() && THex::mutualPosition(curAction->destinationTile, attacker->position) < 0) + if(ba->counter() && SHexField::mutualPosition(curAction->destinationTile, attacker->position) < 0) { - int distp = THex::getDistance(curAction->destinationTile + 1, attacker->position); - int distm = THex::getDistance(curAction->destinationTile - 1, attacker->position); + int distp = SHexField::getDistance(curAction->destinationTile + 1, attacker->position); + int distm = SHexField::getDistance(curAction->destinationTile - 1, attacker->position); if( distp < distm ) shift = 1; @@ -1339,7 +1329,7 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop) adventureInt->minimap.showTile(*it); } - if(obj->ID == TOWNI_TYPE) + if(obj->ID == GameConstants::TOWNI_TYPE) { if(obj->tempOwner == playerID) towns.push_back(static_cast(obj)); @@ -1360,7 +1350,7 @@ void CPlayerInterface::recreateHeroTownList() //applying current heroes order to new heroes info int j; for (int i = 0; i < wanderingHeroes.size(); i++) - if ((j = vstd::findPos(allHeroes, wanderingHeroes[i])) >= 0) + if ((j = vstd::find_pos(allHeroes, wanderingHeroes[i])) >= 0) if (!allHeroes[j]->inTownGarrison) { newWanderingHeroes += allHeroes[j]; @@ -1377,7 +1367,7 @@ void CPlayerInterface::recreateHeroTownList() std::vector newTowns; std::vector allTowns = cb->getTownsInfo(); for (int i = 0; i < towns.size(); i++) - if ((j = vstd::findPos(allTowns, towns[i])) >= 0) + if ((j = vstd::find_pos(allTowns, towns[i])) >= 0) { newTowns += allTowns[j]; allTowns -= allTowns[j]; @@ -1456,7 +1446,7 @@ void CPlayerInterface::centerView (int3 pos, int focusTime) void CPlayerInterface::objectRemoved( const CGObjectInstance *obj ) { - if(obj->ID == HEROI_TYPE && obj->tempOwner == playerID) + if(obj->ID == GameConstants::HEROI_TYPE && obj->tempOwner == playerID) { const CGHeroInstance *h = static_cast(obj); heroKilled(h); @@ -2019,7 +2009,7 @@ void CPlayerInterface::showPuzzleMap() boost::unique_lock un(*pim); //TODO: interface should not know the real position of Grail... - float ratio = 0; + double ratio = 0; int3 grailPos = cb->getGrailPos(ratio); GH.pushInt(new CPuzzleWindow(grailPos, ratio)); @@ -2230,11 +2220,11 @@ void CPlayerInterface::showMarketWindow(const IMarket *market, const CGHeroInsta boost::unique_lock un(*pim); if(market->o->ID == 2) //Altar { - //EMarketMode mode = market->availableModes().front(); - if(market->allowsTrade(ARTIFACT_EXP) && visitor->getAlignment() != EVIL) - GH.pushInt(new CAltarWindow(market, visitor, ARTIFACT_EXP)); - else if(market->allowsTrade(CREATURE_EXP) && visitor->getAlignment() != GOOD) - GH.pushInt(new CAltarWindow(market, visitor, CREATURE_EXP)); + //EEMarketMode mode = market->availableModes().front(); + if(market->allowsTrade(EMarketMode::ARTIFACT_EXP) && visitor->getAlignment() != EAlignment::EVIL) + GH.pushInt(new CAltarWindow(market, visitor, EMarketMode::ARTIFACT_EXP)); + else if(market->allowsTrade(EMarketMode::CREATURE_EXP) && visitor->getAlignment() != EAlignment::GOOD) + GH.pushInt(new CAltarWindow(market, visitor, EMarketMode::CREATURE_EXP)); } else GH.pushInt(new CMarketplaceWindow(market, visitor, market->availableModes().front())); diff --git a/client/CPlayerInterface.h b/client/CPlayerInterface.h index db4473bb6..933bbf2a7 100644 --- a/client/CPlayerInterface.h +++ b/client/CPlayerInterface.h @@ -1,13 +1,10 @@ -#ifndef __CPLAYERINTERFACE_H__ -#define __CPLAYERINTERFACE_H__ -#include "../global.h" -#include "../lib/CGameInterface.h" +#pragma once + + #include "../lib/CondSh.h" -#include -#include -#include #include "GUIBase.h" #include "FunctionList.h" +#include "../lib/CGameInterface.h" #ifdef __GNUC__ #define sprintf_s snprintf @@ -221,7 +218,7 @@ public: void battleEnd(const BattleResult *br) OVERRIDE; //end of battle void battleNewRoundFirst(int round) OVERRIDE; //called at the beginning of each turn before changes are applied; used for HP regen handling void battleNewRound(int round) OVERRIDE; //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; + void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; void battleSpellCast(const BattleSpellCast *sc) OVERRIDE; void battleStacksEffectsSet(const SetStackEffect & sse) OVERRIDE; //called when a specific effect is set to stacks void battleTriggerEffect(const BattleTriggerEffect & bte) OVERRIDE; //various one-shot effect @@ -278,6 +275,3 @@ public: }; extern CPlayerInterface * LOCPLINT; - - -#endif // __CPLAYERINTERFACE_H__ diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index bb61de2b3..f6c9e0d4c 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -1,11 +1,8 @@ -#include "../stdafx.h" +#include "StdInc.h" #include "CPreGame.h" -#include -#include // includes all needed Boost.Filesystem declarations -#include + #include -#include "../timeHandler.h" -#include +#include "../lib/StopWatch.h" #include "SDL_Extensions.h" #include "CGameInfo.h" #include "CCursorHandler.h" @@ -22,17 +19,7 @@ #include "../lib/JsonNode.h" #include "CMusicHandler.h" #include "CVideoHandler.h" -#include #include "Graphics.h" -//#include -#include -#include -#include -#include -#include -#include - -#include #include "../lib/Connection.h" #include "../lib/VCMIDirs.h" #include "../lib/map.h" @@ -40,8 +27,6 @@ #include "GUIClasses.h" #include "CPlayerInterface.h" #include "../CCallback.h" -#include -#include #include "CMessage.h" #include "../lib/CSpellHandler.h" /*for campaign bonuses*/ #include "../lib/CArtHandler.h" /*for campaign bonuses*/ @@ -49,11 +34,11 @@ #include "CBitmapHandler.h" #include "Client.h" #include "../lib/NetPacks.h" -#include "../lib/RegisterTypes.cpp" -#include -#include "../CThreadHelper.h" +#include "../lib/RegisterTypes.h" +#include "../lib/CThreadHelper.h" #include "CConfigHandler.h" #include "../lib/CFileUtility.h" +#include "../lib/GameConstants.h" /* * CPreGame.cpp, part of VCMI engine @@ -93,8 +78,8 @@ struct EvilHlpStruct { if(strong) { - delNull(serv); - delNull(sInfo); + vstd::clear_pointer(serv); + vstd::clear_pointer(sInfo); } else { @@ -160,7 +145,7 @@ void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader * std::map::const_iterator namesIt = playerNames.begin(); - for (int i = 0; i < PLAYER_LIMIT; i++) + for (int i = 0; i < GameConstants::PLAYER_LIMIT; i++) { const PlayerInfo &pinfo = mapHeader->players[i]; @@ -410,7 +395,7 @@ void CreditsScreen::clickRight(tribool down, bool previousState) } CGPreGame::CGPreGame(): - pregameConfig(new JsonNode(DATA_DIR "/config/mainmenu.json")) + pregameConfig(new JsonNode(GameConstants::DATA_DIR + "/config/mainmenu.json")) { OBJ_CONSTRUCTION_CAPTURING_ALL; GH.defActionsDef = 63; @@ -672,7 +657,7 @@ CSelectionScreen::~CSelectionScreen() playerNames.clear(); assert(!serv); - delNull(applier); + vstd::clear_pointer(applier); delete mx; } @@ -713,7 +698,7 @@ void CSelectionScreen::changeSelection( const CMapInfo *to ) { if(multiPlayer == CMenuScreen::MULTI_NETWORK_GUEST) { - delNull(current); + vstd::clear_pointer(current); } current = to; @@ -981,7 +966,7 @@ void SelectionTab::getFiles(std::vector &out, const std::string &dirna void SelectionTab::parseMaps(std::vector &files, int start, int threads) { int read=0; - unsigned char mapBuffer[1500]; + ui8 mapBuffer[1500]; while(start < allItems.size()) { @@ -1080,11 +1065,11 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::functionvalue; - amax(py, 0); - amin(py, curItems.size()-1); + vstd::amax(py, 0); + vstd::amin(py, curItems.size()-1); selectionPos = py; @@ -1337,14 +1322,14 @@ void SelectionTab::printMaps(SDL_Surface *to) blitAt(format->ourImages[temp].bitmap, POS(88, 117), to); //victory conditions - if (currentItem->mapHeader->victoryCondition.condition == winStandard) + if (currentItem->mapHeader->victoryCondition.condition == EVictoryConditionType::WINSTANDARD) temp = 11; else temp = currentItem->mapHeader->victoryCondition.condition; blitAt(CGP->victory->ourImages[temp].bitmap, POS(306, 117), to); //loss conditions - if (currentItem->mapHeader->lossCondition.typeOfLossCon == lossStandard) + if (currentItem->mapHeader->lossCondition.typeOfLossCon == ELossConditionType::LOSSSTANDARD) temp=3; else temp=currentItem->mapHeader->lossCondition.typeOfLossCon; @@ -1784,7 +1769,7 @@ void InfoCard::showTeamsPopup() hlp.replace(hlp.find("%d"), 2, boost::lexical_cast(i+1)); CSDL_Ext::printAtMiddle(hlp, 128, 65 + 50*i, FONT_SMALL, zwykly, bmp); - for(int j = 0; j < PLAYER_LIMIT; j++) + for(int j = 0; j < GameConstants::PLAYER_LIMIT; j++) if((SEL->current->mapHeader->players[j].canHumanPlay || SEL->current->mapHeader->players[j].canComputerPlay) && SEL->current->mapHeader->players[j].team == i) flags.push_back(j); @@ -1876,8 +1861,8 @@ void OptionsTab::nextCastle( int player, int dir ) if (cur == -1) //random => first/last available { - int pom = (dir>0) ? (0) : (F_NUMBER-1); // last or first - for (;pom >= 0 && pom < F_NUMBER; pom+=dir) + int pom = (dir>0) ? (0) : (GameConstants::F_NUMBER-1); // last or first + for (;pom >= 0 && pom < GameConstants::F_NUMBER; pom+=dir) { if((1 << pom) & allowed) { @@ -1894,9 +1879,9 @@ void OptionsTab::nextCastle( int player, int dir ) if ((1 << cur) & allowed) break; - if (cur >= F_NUMBER || cur<0) + if (cur >= GameConstants::F_NUMBER || cur<0) { - double p1 = log((double)allowed) / log(2.0f)+0.000001f; + double p1 = log((double)allowed) / log(2.0)+0.000001; double check = p1 - ((int)p1); if (check < 0.001) cur = (int)p1; @@ -1933,16 +1918,16 @@ void OptionsTab::nextHero( int player, int dir ) if (s.hero == -1) //random => first/last available { - int max = (s.castle*HEROES_PER_TYPE*2+15), - min = (s.castle*HEROES_PER_TYPE*2); + int max = (s.castle*GameConstants::HEROES_PER_TYPE*2+15), + min = (s.castle*GameConstants::HEROES_PER_TYPE*2); s.hero = nextAllowedHero(min,max,0,dir); } else { if(dir > 0) - s.hero = nextAllowedHero(s.hero,(s.castle*HEROES_PER_TYPE*2+16),1,dir); + s.hero = nextAllowedHero(s.hero,(s.castle*GameConstants::HEROES_PER_TYPE*2+16),1,dir); else - s.hero = nextAllowedHero(s.castle*HEROES_PER_TYPE*2-1,s.hero,1,dir); + s.hero = nextAllowedHero(s.castle*GameConstants::HEROES_PER_TYPE*2-1,s.hero,1,dir); } if(old != s.hero) @@ -2046,7 +2031,7 @@ void OptionsTab::recreate() void OptionsTab::setTurnLength( int npos ) { static const int times[] = {1, 2, 4, 6, 8, 10, 15, 20, 25, 30, 0}; - amin(npos, ARRAY_COUNT(times) - 1); + vstd::amin(npos, ARRAY_COUNT(times) - 1); SEL->sInfo.turnTime = times[npos]; redraw(); @@ -2267,7 +2252,7 @@ SDL_Surface * OptionsTab::SelectedBox::getImg() const switch(which) { case TOWN: - if (s.castle < F_NUMBER && s.castle >= 0) + if (s.castle < GameConstants::F_NUMBER && s.castle >= 0) return graphics->getPic(s.castle, true, false); else if (s.castle == -1) return CGP->rTown; @@ -2323,7 +2308,7 @@ const std::string * OptionsTab::SelectedBox::getText() const switch(which) { case TOWN: - if (s.castle < F_NUMBER && s.castle >= 0) + if (s.castle < GameConstants::F_NUMBER && s.castle >= 0) return &CGI->townh->towns[s.castle].Name(); else if (s.castle == -1) return &CGI->generaltexth->allTexts[522]; @@ -2710,7 +2695,7 @@ void CHotSeatPlayers::enterSelectionScreen() CBonusSelection::CBonusSelection( CCampaignState * _ourCampaign ) : highlightedRegion(NULL), ourCampaign(_ourCampaign), ourHeader(NULL), - diffLb(NULL), diffRb(NULL), bonuses(NULL) + diffLb(NULL), diffRb(NULL), bonuses(NULL) { OBJ_CONSTRUCTION_CAPTURING_ALL; static const std::string bgNames [] = {"E1_BG.BMP", "G2_BG.BMP", "E2_BG.BMP", "G1_BG.BMP", "G3_BG.BMP", "N1_BG.BMP", @@ -2839,7 +2824,7 @@ void CBonusSelection::showAll( SDL_Surface * to ) void CBonusSelection::loadPositionsOfGraphics() { - const JsonNode config(DATA_DIR "/config/campaign_regions.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/campaign_regions.json"); int idx = 0; BOOST_FOREACH(const JsonNode &campaign, config["campaign_regions"].Vector()) @@ -3032,7 +3017,7 @@ void CBonusSelection::updateBonusSelection() int leadingSkill = -1; std::vector > toPrint; //primary skills to be listed const ui8* ptr = reinterpret_cast(&bonDescs[i].info2); - for (int g=0; g ptr[leadingSkill]) { @@ -3349,7 +3334,7 @@ void QuitMenuWithoutStarting::apply(CSelectionScreen *selScreen) GH.popIntTotally(selScreen); //will wait with deleting us before this thread ends } - delNull(selScreen->serv); + vstd::clear_pointer(selScreen->serv); } void PlayerJoined::apply(CSelectionScreen *selScreen) @@ -3467,7 +3452,7 @@ void StartWithCurrentSettings::apply(CSelectionScreen *selScreen) } selScreen->serv = NULL; //hide it so it won't be deleted - delNull(selScreen->serverHandlingThread); //detach us + vstd::clear_pointer(selScreen->serverHandlingThread); //detach us selectedName = selScreen->sInfo.mapname; GH.curInt = NULL; diff --git a/client/CPreGame.h b/client/CPreGame.h index cfa51269e..fa5a8676b 100644 --- a/client/CPreGame.h +++ b/client/CPreGame.h @@ -1,9 +1,8 @@ -#ifndef __CPREGAME_H__ -#define __CPREGAME_H__ -#include "../global.h" -#include +#pragma once + + #include -#include "../StartInfo.h" +#include "../lib/StartInfo.h" #include "GUIBase.h" #include "GUIClasses.h" #include "FunctionList.h" @@ -355,7 +354,7 @@ class CHotSeatPlayers : public CIntObject { CPicture *bg; CTextBox *title; - CTextInput *txt[8]; + CTextInput* txt[8]; AdventureMapButton *ok, *cancel; CGStatusBar *bar; @@ -395,7 +394,7 @@ class CBonusSelection : public CIntObject class CRegion : public CIntObject { CBonusSelection * owner; - SDL_Surface * graphics[3]; //[0] - not selected, [1] - selected, [2] - striped + SDL_Surface* graphics[3]; //[0] - not selected, [1] - selected, [2] - striped bool accessible; //false if region should be striped bool selectable; //true if region should be selectable int myNumber; //number of region @@ -416,7 +415,7 @@ class CBonusSelection : public CIntObject CCampaignState * ourCampaign; CMapHeader *ourHeader; CDefHandler *sizes; //icons of map sizes - SDL_Surface * diffPics[5]; //pictures of difficulties, user-selectable (or not if campaign locks this) + SDL_Surface* diffPics[5]; //pictures of difficulties, user-selectable (or not if campaign locks this) AdventureMapButton * diffLb, * diffRb; //buttons for changing difficulty void changeDiff(bool increase); //if false, then decrease @@ -506,5 +505,3 @@ public: }; extern CGPreGame *CGP; - -#endif // __CPREGAME_H__ diff --git a/client/CSndHandler.cpp b/client/CSndHandler.cpp index 53c1a5f87..a4dc7b8f1 100644 --- a/client/CSndHandler.cpp +++ b/client/CSndHandler.cpp @@ -1,8 +1,7 @@ -#include "../stdafx.h" -#include -#include "CSndHandler.h" +#include "StdInc.h" #include #include +#include "CSndHandler.h" /* * CSndHandler.cpp, part of VCMI engine @@ -153,10 +152,10 @@ void CSndHandler::add_file(std::string fname, bool important /*= true*/) } const char *data = mfile->data(); - unsigned int numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]); + ui32 numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]); struct soundEntry *se = (struct soundEntry *)&data[4]; - for (unsigned int i=0; idata(); - unsigned int numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]); + const ui8 *data = (const ui8 *)mfile->data(); + ui32 numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]); struct videoEntry *ve = (struct videoEntry *)&data[4]; - for (unsigned int i=0; i #include -#include #include @@ -52,8 +49,8 @@ protected: struct Entry { std::string name; - unsigned int size; - unsigned int offset; + ui32 size; + ui32 offset; const char *data; }; @@ -82,7 +79,3 @@ class CVidHandler: public CMediaHandler public: void add_file(std::string fname); }; - - - -#endif // __CSNDHANDLER_H__ diff --git a/client/CSoundBase.h b/client/CSoundBase.h index b2046031e..2f4d44cfb 100644 --- a/client/CSoundBase.h +++ b/client/CSoundBase.h @@ -1,5 +1,4 @@ -#ifndef __CSOUNDBASE_H__ -#define __CSOUNDBASE_H__ +#pragma once // Use some magic to keep the list of files and their code name in sync. @@ -1033,6 +1032,4 @@ public: }; #undef VCMI_SOUND_NAME #undef VCMI_SOUND_FILE -}; - -#endif // __CSOUNDBASE_H__ \ No newline at end of file +}; \ No newline at end of file diff --git a/client/CSpellWindow.cpp b/client/CSpellWindow.cpp index 8980ed9f4..cb8453351 100644 --- a/client/CSpellWindow.cpp +++ b/client/CSpellWindow.cpp @@ -1,4 +1,6 @@ +#include "StdInc.h" #include "CSpellWindow.h" + #include "Graphics.h" #include "CDefHandler.h" #include "../lib/CObjectHandler.h" @@ -6,21 +8,16 @@ #include "../lib/CGeneralTextHandler.h" #include "CVideoHandler.h" #include "CAdvmapInterface.h" -#include "CBattleInterface.h" +#include "BattleInterface/CBattleInterface.h" #include "CGameInfo.h" #include "SDL_Extensions.h" #include "CMessage.h" #include "CPlayerInterface.h" #include "../CCallback.h" -#include -#include -#include -#include -#include -#include #include "CBitmapHandler.h" #include "../lib/CHeroHandler.h" #include "../lib/BattleState.h" +#include "../lib/GameConstants.h" /* * CSpellWindow.cpp, part of VCMI engine @@ -217,7 +214,7 @@ CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * _myHe selectedTab = battleSpellsOnly ? LOCPLINT->spellbookSettings.spellbookLastTabBattle : LOCPLINT->spellbookSettings.spellbookLastTabAdvmap; currentPage = battleSpellsOnly ? LOCPLINT->spellbookSettings.spellbookLastPageBattle : LOCPLINT->spellbookSettings.spellbokLastPageAdvmap; - abetw(currentPage, 0, pagesWithinCurrentTab()); + vstd::abetween(currentPage, 0, pagesWithinCurrentTab()); computeSpellsPerArea(); } @@ -536,11 +533,11 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key) case SDLK_DOWN: { bool down = key.keysym.sym == SDLK_DOWN; - static const int schoolsOrder[] = {0, 3, 1, 2, 4}; + static const int schoolsOrder[] = { 0, 3, 1, 2, 4 }; int index = -1; while(schoolsOrder[++index] != selectedTab); index += (down ? 1 : -1); - abetw(index, 0, ARRAY_COUNT(schoolsOrder) - 1); + vstd::abetween(index, 0, ARRAY_COUNT(schoolsOrder) - 1); if(selectedTab != schoolsOrder[index]) selectSchool(schoolsOrder[index]); break; @@ -621,23 +618,23 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState) //we will cast a spell if(sp->combatSpell && owner->myInt->battleInt && owner->myInt->cb->battleCanCastSpell()) //if battle window is open { - SpellCasting::ESpellCastProblem problem = owner->myInt->cb->battleCanCastThisSpell(sp); + ESpellCastProblem::ESpellCastProblem problem = owner->myInt->cb->battleCanCastThisSpell(sp); switch (problem) { - case SpellCasting::OK: + case ESpellCastProblem::OK: { int spell = mySpell; owner->fexitb(); owner->myInt->battleInt->castThisSpell(spell); } break; - case SpellCasting::ANOTHER_ELEMENTAL_SUMMONED: + case ESpellCastProblem::ANOTHER_ELEMENTAL_SUMMONED: { std::string text = CGI->generaltexth->allTexts[538], summoner, elemental, caster; std::vector stacks = owner->myInt->cb->battleGetStacks(); BOOST_FOREACH(const CStack * s, stacks) { - if(vstd::contains(s->state, SUMMONED)) + if(vstd::contains(s->state, EBattleStackState::SUMMONED)) { elemental = s->getCreature()->namePl; summoner = owner->myInt->cb->battleGetFightingHero(!s->attackerOwned)->name; @@ -658,14 +655,14 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState) owner->myInt->showInfoDialog(text); } break; - case SpellCasting::SPELL_LEVEL_LIMIT_EXCEEDED: + case ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED: { std::string text = CGI->generaltexth->allTexts[541], caster = owner->myHero->name; text = boost::str(boost::format(text) % caster); owner->myInt->showInfoDialog(text); } break; - case SpellCasting::NO_APPROPRIATE_TARGET: + case ESpellCastProblem::NO_APPROPRIATE_TARGET: { owner->myInt->showInfoDialog(CGI->generaltexth->allTexts[185]); } diff --git a/client/CSpellWindow.h b/client/CSpellWindow.h index 70619b856..d5325b192 100644 --- a/client/CSpellWindow.h +++ b/client/CSpellWindow.h @@ -1,10 +1,7 @@ -#ifndef __CSPELLWINDOW_H__ -#define __CSPELLWINDOW_H__ +#pragma once -#include "../global.h" #include "GUIBase.h" -#include "boost/function.hpp" /* * CSpellWindow.h, part of VCMI engine @@ -114,5 +111,3 @@ public: void teleportTo(int town, const CGHeroInstance * hero); }; - -#endif // __CSPELLWINDOW_H__ diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index d75007872..0912f7d95 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -1,11 +1,10 @@ -#include "../stdafx.h" -#include +#include "StdInc.h" +#include #include "CSndHandler.h" #include "CVideoHandler.h" -#include + #include "SDL_Extensions.h" #include "CPlayerInterface.h" -#include extern SystemOptions GDefaultOptions; //reads events and returns true on key down @@ -393,8 +392,8 @@ void CSmackPlayer::redraw( int x, int y, SDL_Surface *dst, bool update ) CVideoPlayer::CVideoPlayer() { - vidh.add_file(std::string(DATA_DIR "/Data/VIDEO.VID")); - vidh.add_file(std::string(DATA_DIR "/Data/H3ab_ahd.vid")); + vidh.add_file(std::string(GameConstants::DATA_DIR + "/Data/VIDEO.VID")); + vidh.add_file(std::string(GameConstants::DATA_DIR + "/Data/H3ab_ahd.vid")); current = NULL; } @@ -600,11 +599,11 @@ static int lod_close(URLContext* h) } // Define a set of functions to read data -static int lod_read(URLContext *context, unsigned char *buf, int size) +static int lod_read(URLContext *context, ui8 *buf, int size) { CVideoPlayer *video = (CVideoPlayer *)context->priv_data; - amin(size, video->length - video->offset); + vstd::amin(size, video->length - video->offset); if (size < 0) return -1; @@ -617,14 +616,14 @@ static int lod_read(URLContext *context, unsigned char *buf, int size) return size; } -static int64_t lod_seek(URLContext *context, int64_t pos, int whence) +static si64 lod_seek(URLContext *context, si64 pos, int whence) { CVideoPlayer *video = (CVideoPlayer *)context->priv_data; // Not sure what the parameter whence is. Assuming it always // indicates an absolute value; video->offset = pos; - amin(video->offset, video->length); + vstd::amin(video->offset, video->length); return -1;//video->offset; } @@ -659,8 +658,8 @@ CVideoPlayer::CVideoPlayer() av_register_protocol(&lod_protocol); #endif - vidh.add_file(std::string(DATA_DIR "/Data/VIDEO.VID")); - vidh.add_file(std::string(DATA_DIR "/Data/H3ab_ahd.vid")); + vidh.add_file(GameConstants::DATA_DIR + "/Data/VIDEO.VID"); + vidh.add_file(GameConstants::DATA_DIR + "/Data/H3ab_ahd.vid"); } bool CVideoPlayer::open(std::string fname) @@ -699,12 +698,12 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay) } else { // File is not in a container #if LIBAVFORMAT_VERSION_MAJOR < 54 - int avfopen = av_open_input_file(&format, (DATA_DIR "/Data/video/" + fname).c_str(), NULL, 0, NULL); + int avfopen = av_open_input_file(&format, (GameConstants::DATA_DIR + "/Data/video/" + fname).c_str(), NULL, 0, NULL); #else - int avfopen = avformat_open_input(&format, (DATA_DIR "/Data/video/" + fname).c_str(), NULL, NULL); + int avfopen = avformat_open_input(&format, (GameConstants::DATA_DIR + "/Data/video/" + fname).c_str(), NULL, NULL); #endif if (avfopen != 0) { - // tlog1 << "Video file not found: " DATA_DIR "/Data/video/" + fname << std::endl; + // tlog1 << "Video file not found: " GameConstants::DATA_DIR + "/Data/video/" + fname << std::endl; return false; } } @@ -715,7 +714,7 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay) // Find the first video stream stream = -1; - for(unsigned int i=0; inb_streams; i++) { + for(ui32 i=0; inb_streams; i++) { #if LIBAVCODEC_VERSION_MAJOR < 53 if (format->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) #else @@ -850,7 +849,7 @@ bool CVideoPlayer::nextFrame() SDL_UnlockYUVOverlay(overlay); } else { - pict.data[0] = (uint8_t *)dest->pixels; + pict.data[0] = (ui8 *)dest->pixels; pict.linesize[0] = dest->pitch; sws_scale(sws, frame->data, frame->linesize, @@ -985,4 +984,4 @@ CVideoPlayer::~CVideoPlayer() close(); } -#endif \ No newline at end of file +#endif diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index 8ae59aa85..d6daa5d0c 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -1,7 +1,6 @@ -#ifndef __CVIDEOHANDLER_H__ -#define __CVIDEOHANDLER_H__ +#pragma once + -#include "../global.h" #include "CSndHandler.h" struct SDL_Surface; @@ -289,7 +288,7 @@ public: const char *data; // video buffer int length; // video size - unsigned int offset; // current data offset + ui32 offset; // current data offset }; #define VIDEO_TAVERN "tavern.mjpg" @@ -301,5 +300,3 @@ public: #define VIDEO_SURRENDER "surrender.mjpg" #endif - -#endif // __CVIDEOHANDLER_H__ diff --git a/client/Client.cpp b/client/Client.cpp index 039134993..c6b66a0af 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -1,11 +1,13 @@ +#include "StdInc.h" + #include "CMusicHandler.h" #include "../lib/CCampaignHandler.h" #include "../CCallback.h" -#include "../CConsoleHandler.h" +#include "../lib/CConsoleHandler.h" #include "CGameInfo.h" #include "../lib/CGameState.h" #include "CPlayerInterface.h" -#include "../StartInfo.h" +#include "../lib/StartInfo.h" #include "../lib/BattleState.h" #include "../lib/CArtHandler.h" #include "../lib/CDefObjInfoHandler.h" @@ -26,20 +28,12 @@ #include "CConfigHandler.h" #include "Client.h" #include "GUIBase.h" -#include -#include -#include -#include -#include -#include #include "CPreGame.h" -#include "CBattleInterface.h" -#include "../CThreadHelper.h" +#include "BattleInterface/CBattleInterface.h" +#include "../lib/CThreadHelper.h" #include "../lib/CScriptingModule.h" #include "../lib/CFileUtility.h" - -#define NOT_LIB -#include "../lib/RegisterTypes.cpp" +#include "../lib/RegisterTypes.h" extern std::string NAME; namespace intpr = boost::interprocess; @@ -228,7 +222,7 @@ void CClient::loadGame( const std::string & fname ) CServerHandler sh; sh.startServer(); - timeHandler tmh; + StopWatch tmh; { char sig[8]; CMapHeader dum; @@ -237,21 +231,21 @@ void CClient::loadGame( const std::string & fname ) CLoadFile lf(fname + ".vlgm1"); lf >> sig >> dum >> si; - tlog0 <<"Reading save signature: "<> *VLC; const_cast(CGI)->setFromLib(); - tlog0 <<"Reading handlers: "<> gs; - tlog0 <<"Reading gamestate: "<(CGI)->state = gs; const_cast(CGI)->mh->map = gs->map; pathInfo = new CPathsInfo(int3(gs->map->width, gs->map->height, gs->map->twoLevel+1)); CGI->mh->init(); - tlog0 <<"Initing maphandler: "<addStdVecItems(gs); @@ -273,7 +267,7 @@ void CClient::loadGame( const std::string & fname ) *serv << ui8(it->first); //players } *serv << ui8(255); // neutrals - tlog0 <<"Sent info to server: "<(CGI)->state = new CGameState(); - tlog0 <<"\tGamestate: "<> si >> sum >> seed; - tlog0 <<"\tSending/Getting info to/from the server: "<(CGI)->state; gs->scenarioOps = si; gs->init(si, sum, seed); - tlog0 <<"Initializing GameState (together): "<map) { const_cast(CGI)->mh = new CMapHandler(); CGI->mh->map = gs->map; - tlog0 <<"Creating mapHandler: "<mh->init(); pathInfo = new CPathsInfo(int3(gs->map->width, gs->map->height, gs->map->twoLevel+1)); - tlog0 <<"Initializing mapHandler (together): "<serialize(h, version); } - if(!vstd::contains(battleints, NEUTRAL_PLAYER)) + if(!vstd::contains(battleints, GameConstants::NEUTRAL_PLAYER)) loadNeutralBattleAI(); } } @@ -631,7 +625,7 @@ void CServerHandler::startServer() serverThread = new boost::thread(&CServerHandler::callServer, this); //runs server executable; if(verbose) - tlog0 << "Setting up thread calling server: " << th.getDif() << std::endl; + tlog0 << "Setting up thread calling server: " << th.getDiff() << std::endl; } void CServerHandler::waitForServer() @@ -646,7 +640,7 @@ void CServerHandler::waitForServer() shared->sr->cond.wait(slock); } if(verbose) - tlog0 << "Waiting for server: " << th.getDif() << std::endl; + tlog0 << "Waiting for server: " << th.getDiff() << std::endl; } CConnection * CServerHandler::connectToServer() @@ -658,7 +652,7 @@ CConnection * CServerHandler::connectToServer() CConnection *ret = justConnectToServer(conf.cc.server, port); if(verbose) - tlog0<<"\tConnecting to the server: "< " + logName; + std::string comm = GameConstants::BIN_DIR + GameConstants::PATH_SEPARATOR + GameConstants::SERVER_NAME + " " + port + " > " + logName; std::system(comm.c_str()); tlog0 << "Server finished\n"; } diff --git a/client/Client.h b/client/Client.h index 617ef3507..a26593800 100644 --- a/client/Client.h +++ b/client/Client.h @@ -1,12 +1,9 @@ -#ifndef __CLIENT_H__ -#define __CLIENT_H__ +#pragma once -#include "../global.h" -#include #include "../lib/IGameCallback.h" #include "../lib/CondSh.h" -#include +#include "../lib/StopWatch.h" /* * Client.h, part of VCMI engine @@ -41,7 +38,7 @@ class CServerHandler private: void callServer(); //calls server via system(), should be called as thread public: - timeHandler th; + StopWatch th; boost::thread *serverThread; //thread that called system to run server SharedMem *shared; //interprocess memory (for waiting for server) bool verbose; //whether to print log msgs @@ -175,5 +172,3 @@ public: template void serialize(Handler &h, const int version); }; - -#endif // __CLIENT_H__ diff --git a/client/FontBase.h b/client/FontBase.h index ee74a552a..7c18bba43 100644 --- a/client/FontBase.h +++ b/client/FontBase.h @@ -1,5 +1,4 @@ -#ifndef __FONTBASE_H__ -#define __FONTBASE_H__ +#pragma once /* * FontBase.h, part of VCMI engine @@ -22,19 +21,17 @@ struct Font struct Char { si32 unknown1, width, unknown2, offset; - unsigned char *pixels; + ui8 *pixels; }; Char chars[256]; ui8 height; - unsigned char *data; + ui8 *data; - Font(unsigned char *Data); + Font(ui8 *Data); ~Font(); int getWidth(const char *text) const; int getCharWidth(char c) const; }; - -#endif diff --git a/client/FunctionList.h b/client/FunctionList.h index 435f77c94..23695532a 100644 --- a/client/FunctionList.h +++ b/client/FunctionList.h @@ -1,8 +1,5 @@ -#ifndef FUNCTIONLIST_H -#define FUNCTIONLIST_H +#pragma once -#include -#include /* * FunctionList.h, part of VCMI engine @@ -120,6 +117,4 @@ public: funcs2[i](a); } } -}; - -#endif //FUNCTIONLISt_H \ No newline at end of file +}; \ No newline at end of file diff --git a/client/GUIBase.cpp b/client/GUIBase.cpp index db3051683..cffb9e8ca 100644 --- a/client/GUIBase.cpp +++ b/client/GUIBase.cpp @@ -1,16 +1,13 @@ +#include "StdInc.h" #include "SDL_Extensions.h" -#include -#include #include "GUIBase.h" -#include -#include + #include "CGameInfo.h" #include "CCursorHandler.h" #include "CBitmapHandler.h" #include "Graphics.h" -#include "../CThreadHelper.h" +#include "../lib/CThreadHelper.h" #include "CConfigHandler.h" -#include /* * GUIBase.cpp, part of VCMI engine @@ -25,6 +22,7 @@ extern std::queue events; extern boost::mutex eventsM; + SDL_Color Colors::MetallicGold = createColor(173, 142, 66); SDL_Color Colors::Yellow = createColor(242, 226, 110); @@ -124,7 +122,7 @@ void CGuiHandler::totalRedraw() void CGuiHandler::updateTime() { - int tv = th.getDif(); + int tv = th.getDiff(); std::list hlp = timeinterested; for (std::list::iterator i=hlp.begin(); i != hlp.end();i++) { @@ -756,10 +754,10 @@ const Rect & CIntObject::center(const Point &p, bool propagate /*= true*/) void CIntObject::fitToScreen(int borderWidth, bool propagate) { Point newPos = pos.topLeft(); - amax(newPos.x, borderWidth); - amax(newPos.y, borderWidth); - amin(newPos.x, screen->w - borderWidth - pos.w); - amin(newPos.y, screen->h - borderWidth - pos.h); + vstd::amax(newPos.x, borderWidth); + vstd::amax(newPos.y, borderWidth); + vstd::amin(newPos.x, screen->w - borderWidth - pos.w); + vstd::amin(newPos.y, screen->h - borderWidth - pos.h); if (newPos != pos.topLeft()) moveTo(newPos, propagate); } diff --git a/client/GUIBase.h b/client/GUIBase.h index 5451c98de..764c51ca1 100644 --- a/client/GUIBase.h +++ b/client/GUIBase.h @@ -1,11 +1,9 @@ -#ifndef __GUIBASE_H__ -#define __GUIBASE_H__ +#pragma once -#include "../global.h" + +#include "../lib/int3.h" #include "SDL.h" -#include -#include -#include "../timeHandler.h" +#include "../lib/StopWatch.h" #include "FontBase.h" #include "SDL_framerate.h" @@ -57,6 +55,8 @@ class CGTownInstance; class StackState; class CPlayerInterface; +using boost::logic::tribool; + /// A point with x/y coordinate, used mostly for graphic rendering struct Point { @@ -533,7 +533,7 @@ class CGuiHandler { public: FPSManager *mainFPSmng; //to keep const framerate - timeHandler th; + StopWatch th; std::list listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on) IStatusBar * statusbar; @@ -624,5 +624,3 @@ public: #define OBJ_CONSTRUCTION_CAPTURING_ALL defActions = 255; SetCaptureState obj__i1(true, 255); ObjectConstruction obj__i(this) #define BLOCK_CAPTURING SetCaptureState obj__i(false, 0) #define BLOCK_CAPTURING_DONT_TOUCH_REC_ACTIONS SetCaptureState obj__i(false, GH.defActionsDef) - -#endif //__GUIBASE_H__ diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index d84ccc836..7e082772c 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -1,9 +1,10 @@ +#include "StdInc.h" #include "GUIClasses.h" #include "SDL_Extensions.h" -#include "../stdafx.h" #include "CAdvmapInterface.h" -#include "CBattleInterface.h" +#include "BattleInterface/CBattleInterface.h" +#include "BattleInterface/CBattleConsole.h" #include "../CCallback.h" #include "CCastleInterface.h" #include "CCreatureWindow.h" @@ -29,30 +30,19 @@ #include "../lib/CondSh.h" #include "../lib/map.h" #include "mapHandler.h" -#include "../timeHandler.h" -#include -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#include +#include "../lib/StopWatch.h" #include "../lib/NetPacks.h" #include "CSpellWindow.h" #include "CHeroWindow.h" #include "CVideoHandler.h" -#include "../StartInfo.h" +#include "../lib/StartInfo.h" #include "CPreGame.h" #include "../lib/HeroBonus.h" #include "../lib/CCreatureHandler.h" #include "CMusicHandler.h" #include "../lib/BattleState.h" #include "../lib/CGameState.h" +#include "../lib/GameConstants.h" /* * GUIClasses.cpp, part of VCMI engine @@ -116,7 +106,7 @@ void CGarrisonSlot::hover (bool on) { temp = CGI->generaltexth->tcommands[32]; //Select %s (visiting) } - else if(owner->armedObjs[0] && owner->armedObjs[0]->ID == TOWNI_TYPE) + else if(owner->armedObjs[0] && owner->armedObjs[0]->ID == GameConstants::TOWNI_TYPE) { temp = CGI->generaltexth->tcommands[12]; //Select %s (in garrison) } @@ -702,10 +692,10 @@ void CInfoPopup::init(int x, int y) pos.w = bitmap->w; // Put the window back on screen if necessary - amax(pos.x, 0); - amax(pos.y, 0); - amin(pos.x, conf.cc.resx - bitmap->w); - amin(pos.y, conf.cc.resy - bitmap->h); + vstd::amax(pos.x, 0); + vstd::amax(pos.y, 0); + vstd::amin(pos.x, conf.cc.resx - bitmap->w); + vstd::amin(pos.y, conf.cc.resy - bitmap->h); } void SComponent::init(Etype Type, int Subtype, int Val) @@ -1295,8 +1285,8 @@ void CList::fixPos() else if(from + SIZE <= selected) from = selected - SIZE + 1; - amin(from, size() - SIZE); - amax(from, 0); + vstd::amin(from, size() - SIZE); + vstd::amax(from, 0); draw(screen); } @@ -1397,7 +1387,7 @@ void CHeroList::clickLeft(tribool down, bool previousState) int ny = hy/32; if (ny>=SIZE || ny<0) return; - if ( (ny+from)==selected && (adventureInt->selection->ID == HEROI_TYPE)) + if ( (ny+from)==selected && (adventureInt->selection->ID == GameConstants::HEROI_TYPE)) LOCPLINT->openHeroWindow(LOCPLINT->wanderingHeroes[selected]);//print hero screen select(ny+from); } @@ -1566,7 +1556,7 @@ void CHeroList::draw(SDL_Surface * to) blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32,to); //mana SDL_Surface * temp = graphics->portraitSmall[cur->portrait]; blitAt(temp,posporx,pospory+i*32,to); - if (adventureInt->selection && (selected == iT) && (adventureInt->selection->ID == HEROI_TYPE)) + if (adventureInt->selection && (selected == iT) && (adventureInt->selection->ID == GameConstants::HEROI_TYPE)) { blitAt(selection,posporx,pospory+i*32,to); } @@ -1585,7 +1575,7 @@ void CHeroList::draw(SDL_Surface * to) int CHeroList::getPosOfHero(const CGHeroInstance* h) { - return vstd::findPos(LOCPLINT->wanderingHeroes, h, std::equal_to()); + return vstd::find_pos(LOCPLINT->wanderingHeroes, h, std::equal_to()); } void CHeroList::show( SDL_Surface * to ) @@ -1722,7 +1712,7 @@ void CTownList::clickLeft(tribool down, bool previousState) return; if(GH.topInt() == adventureInt && (ny+from)==selected - && adventureInt->selection->ID == TOWNI_TYPE + && adventureInt->selection->ID == GameConstants::TOWNI_TYPE ) LOCPLINT->openTownWindow(LOCPLINT->towns[selected]);//print town screen else @@ -1813,7 +1803,7 @@ void CTownList::draw(SDL_Surface * to) blitAt(graphics->getPic(LOCPLINT->towns[iT]->subID,LOCPLINT->towns[iT]->hasFort(),LOCPLINT->towns[iT]->builded),posporx,pospory+i*32,to); - if (adventureInt->selection && (selected == iT) && (adventureInt->selection->ID == TOWNI_TYPE)) + if (adventureInt->selection && (selected == iT) && (adventureInt->selection->ID == GameConstants::TOWNI_TYPE)) { blitAt(graphics->getPic(-2),posporx,pospory+i*32,to); } @@ -1881,7 +1871,7 @@ void CRecruitmentWindow::Buy() if(dstslot < 0 && !vstd::contains(CGI->arth->bigArtifacts,CGI->arth->convertMachineID(crid, true))) //no available slot { std::string txt; - if(dst->ID == HEROI_TYPE) + if(dst->ID == GameConstants::HEROI_TYPE) { txt = CGI->generaltexth->allTexts[425]; //The %s would join your hero, but there aren't enough provisions to support them. boost::algorithm::replace_first(txt, "%s", slider->value > 1 ? CGI->creh->creatures[crid]->namePl : CGI->creh->creatures[crid]->nameSing); @@ -2895,7 +2885,7 @@ void CTradeWindow::CTradeableItem::setArtInstance(const CArtifactInstance *art) id = -1; } -CTradeWindow::CTradeWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode) +CTradeWindow::CTradeWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode) : market(Market), hero(Hero), arts(NULL), hLeft(NULL), hRight(NULL), readyToTrade(false) { type |= BLOCK_ADV_HOTKEYS; @@ -2907,31 +2897,31 @@ void CTradeWindow::initTypes() { switch(mode) { - case RESOURCE_RESOURCE: + case EMarketMode::RESOURCE_RESOURCE: itemsType[1] = RESOURCE; itemsType[0] = RESOURCE; break; - case RESOURCE_PLAYER: + case EMarketMode::RESOURCE_PLAYER: itemsType[1] = RESOURCE; itemsType[0] = PLAYER; break; - case CREATURE_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: itemsType[1] = CREATURE; itemsType[0] = RESOURCE; break; - case RESOURCE_ARTIFACT: + case EMarketMode::RESOURCE_ARTIFACT: itemsType[1] = RESOURCE; itemsType[0] = ARTIFACT_TYPE; break; - case ARTIFACT_RESOURCE: + case EMarketMode::ARTIFACT_RESOURCE: itemsType[1] = ARTIFACT_INSTANCE; itemsType[0] = RESOURCE; break; - case CREATURE_EXP: + case EMarketMode::CREATURE_EXP: itemsType[1] = CREATURE; itemsType[0] = CREATURE_PLACEHOLDER; break; - case ARTIFACT_EXP: + case EMarketMode::ARTIFACT_EXP: itemsType[1] = ARTIFACT_TYPE; itemsType[0] = ARTIFACT_PLACEHOLDER; break; @@ -2943,7 +2933,7 @@ void CTradeWindow::initItems(bool Left) if(Left && (itemsType[1] == ARTIFACT_TYPE || itemsType[1] == ARTIFACT_INSTANCE)) { int xOffset = 0, yOffset = 0; - if(mode == ARTIFACT_RESOURCE) + if(mode == EMarketMode::ARTIFACT_RESOURCE) { xOffset = -361; yOffset = +46; @@ -2969,7 +2959,7 @@ void CTradeWindow::initItems(bool Left) addChild(arts); artSets.push_back(arts); - if(mode == ARTIFACT_RESOURCE) + if(mode == EMarketMode::ARTIFACT_RESOURCE) arts->highlightModeCallback = boost::bind(&CTradeWindow::artifactSelected, this, _1); return; } @@ -2986,12 +2976,12 @@ void CTradeWindow::initItems(bool Left) amount = ids->size(); if(ids) - amin(amount, ids->size()); + vstd::amin(amount, ids->size()); for(int j=0; jsize()>j) ? (*ids)[j] : j; - if(id < 0 && mode != ARTIFACT_EXP) //when sacrificing artifacts we need to prepare empty slots + if(id < 0 && mode != EMarketMode::ARTIFACT_EXP) //when sacrificing artifacts we need to prepare empty slots continue; CTradeableItem *hlp = new CTradeableItem(itemsType[Left], id, Left, j); @@ -3006,7 +2996,7 @@ std::vector *CTradeWindow::getItemsIds(bool Left) { std::vector *ids = NULL; - if(mode == ARTIFACT_EXP) + if(mode == EMarketMode::ARTIFACT_EXP) return new std::vector(22, -1); if(Left) @@ -3031,7 +3021,7 @@ std::vector *CTradeWindow::getItemsIds(bool Left) { case PLAYER: ids = new std::vector; - for(int i = 0; i < PLAYER_LIMIT; i++) + for(int i = 0; i < GameConstants::PLAYER_LIMIT; i++) if(i != LOCPLINT->playerID && LOCPLINT->cb->getPlayerStatus(i) == PlayerState::INGAME) ids->push_back(i); break; @@ -3047,7 +3037,7 @@ std::vector *CTradeWindow::getItemsIds(bool Left) void CTradeWindow::getPositionsFor(std::vector &poss, bool Left, EType type) const { - if(mode == ARTIFACT_EXP && !Left) + if(mode == EMarketMode::ARTIFACT_EXP && !Left) { //22 boxes, 5 in row, last row: two boxes centered int h, w, x, y, dx, dy; @@ -3111,7 +3101,7 @@ void CTradeWindow::initSubs(bool Left) { int h1, h2; //hlp variables for getting offer market->getOffer(hLeft->id, t->id, h1, h2, mode); - if(t->id != hLeft->id || mode != RESOURCE_RESOURCE) //don't allow exchanging same resources + if(t->id != hLeft->id || mode != EMarketMode::RESOURCE_RESOURCE) //don't allow exchanging same resources { std::ostringstream oss; oss << h2; @@ -3171,7 +3161,7 @@ void CTradeWindow::getEmptySlots(std::set &toRemove) toRemove.insert(t); } -void CTradeWindow::setMode(EMarketMode Mode) +void CTradeWindow::setMode(EMarketMode::EMarketMode Mode) { const IMarket *m = market; const CGHeroInstance *h = hero; @@ -3181,8 +3171,8 @@ void CTradeWindow::setMode(EMarketMode Mode) switch(Mode) { - case CREATURE_EXP: - case ARTIFACT_EXP: + case EMarketMode::CREATURE_EXP: + case EMarketMode::ARTIFACT_EXP: nwindow = new CAltarWindow(m, h, Mode); break; default: @@ -3195,7 +3185,7 @@ void CTradeWindow::setMode(EMarketMode Mode) void CTradeWindow::artifactSelected(CArtPlace *slot) { - assert(mode == ARTIFACT_RESOURCE); + assert(mode == EMarketMode::ARTIFACT_RESOURCE); items[1][0]->setArtInstance(slot->ourArt); if(slot->ourArt) hLeft = items[1][0]; @@ -3205,7 +3195,7 @@ void CTradeWindow::artifactSelected(CArtPlace *slot) selectionChanged(true); } -CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode) +CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode) : CTradeWindow(Market, Hero, Mode) { OBJ_CONSTRUCTION_CAPTURING_ALL; @@ -3215,24 +3205,24 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan switch(Mode) { - case RESOURCE_RESOURCE: + case EMarketMode::RESOURCE_RESOURCE: bgName = "TPMRKRES.bmp"; break; - case RESOURCE_PLAYER: + case EMarketMode::RESOURCE_PLAYER: bgName = "TPMRKPTS.bmp"; break; - case CREATURE_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: bgName = "TPMRKCRS.bmp"; break; - case RESOURCE_ARTIFACT: + case EMarketMode::RESOURCE_ARTIFACT: bgName = "TPMRKABS.bmp"; sliderNeeded = false; break; - case ARTIFACT_RESOURCE: + case EMarketMode::ARTIFACT_RESOURCE: bgName = "TPMRKASS.bmp"; sliderNeeded = false; break; @@ -3252,16 +3242,16 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan { printAtMiddle(CGI->generaltexth->allTexts[159],300,27,FONT_BIG,tytulowy,*bg); //title } - else if(mode == CREATURE_RESOURCE) + else if(mode == EMarketMode::CREATURE_RESOURCE) { - if(market->o->ID == TOWNI_TYPE) + if(market->o->ID == GameConstants::TOWNI_TYPE) printAtMiddle(CGI->buildh->buildings[6][21]->Name(), 300, 27, FONT_BIG, tytulowy, *bg); //title else printAtMiddle(market->o->getHoverText(), 300, 27, FONT_BIG, tytulowy, *bg); //title } - else if(mode == RESOURCE_ARTIFACT || mode == ARTIFACT_RESOURCE) + else if(mode == EMarketMode::RESOURCE_ARTIFACT || mode == EMarketMode::ARTIFACT_RESOURCE) { - const std::string &title = market->o->ID == TOWNI_TYPE + const std::string &title = market->o->ID == GameConstants::TOWNI_TYPE ? CGI->buildh->buildings[market->o->subID][17]->Name() : market->o->getHoverText(); @@ -3301,15 +3291,15 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan //left side switch(Mode) { - case RESOURCE_RESOURCE: - case RESOURCE_PLAYER: - case RESOURCE_ARTIFACT: + case EMarketMode::RESOURCE_RESOURCE: + case EMarketMode::RESOURCE_PLAYER: + case EMarketMode::RESOURCE_ARTIFACT: printAtMiddle(CGI->generaltexth->allTexts[270],154,148,FONT_SMALL,zwykly,*bg); //kingdom res. break; - case CREATURE_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: printAtMiddle(boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->name), 152, 102, FONT_SMALL, zwykly, *bg); //%s's Creatures break; - case ARTIFACT_RESOURCE: + case EMarketMode::ARTIFACT_RESOURCE: printAtMiddle(boost::str(boost::format(CGI->generaltexth->allTexts[271]) % hero->name), 152, 57, FONT_SMALL, zwykly, *bg); //%s's Artifacts break; } @@ -3317,32 +3307,32 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan //right side switch(Mode) { - case RESOURCE_RESOURCE: - case CREATURE_RESOURCE: - case RESOURCE_ARTIFACT: - case ARTIFACT_RESOURCE: + case EMarketMode::RESOURCE_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: + case EMarketMode::RESOURCE_ARTIFACT: + case EMarketMode::ARTIFACT_RESOURCE: printAtMiddle(CGI->generaltexth->allTexts[168],445,148,FONT_SMALL,zwykly,*bg); //available for trade traderTextRect = Rect(316, 48, 260, 75); break; - case RESOURCE_PLAYER: + case EMarketMode::RESOURCE_PLAYER: printAtMiddle(CGI->generaltexth->allTexts[169],445,55,FONT_SMALL,zwykly,*bg); //players traderTextRect = Rect(28, 48, 260, 75); break; } traderText = new CTextBox("", traderTextRect, 0, FONT_SMALL, CENTER); - int specialOffset = mode == ARTIFACT_RESOURCE ? 35 : 0; //in selling artifacts mode we need to move res-res and art-res buttons down + int specialOffset = mode == EMarketMode::ARTIFACT_RESOURCE ? 35 : 0; //in selling artifacts mode we need to move res-res and art-res buttons down - if(printButtonFor(RESOURCE_PLAYER)) - new AdventureMapButton(CGI->generaltexth->zelp[612],boost::bind(&CMarketplaceWindow::setMode,this, RESOURCE_PLAYER), 18, 520,"TPMRKBU1.DEF"); - if(printButtonFor(RESOURCE_RESOURCE)) - new AdventureMapButton(CGI->generaltexth->zelp[605],boost::bind(&CMarketplaceWindow::setMode,this, RESOURCE_RESOURCE), 516, 450 + specialOffset,"TPMRKBU5.DEF"); - if(printButtonFor(CREATURE_RESOURCE)) - new AdventureMapButton(CGI->generaltexth->zelp[599],boost::bind(&CMarketplaceWindow::setMode,this, CREATURE_RESOURCE), 516, 485,"TPMRKBU4.DEF"); //was y=450, changed to not overlap res-res in some conditions - if(printButtonFor(RESOURCE_ARTIFACT)) - new AdventureMapButton(CGI->generaltexth->zelp[598],boost::bind(&CMarketplaceWindow::setMode,this, RESOURCE_ARTIFACT), 18, 450 + specialOffset,"TPMRKBU2.DEF"); - if(printButtonFor(ARTIFACT_RESOURCE)) - new AdventureMapButton(CGI->generaltexth->zelp[613],boost::bind(&CMarketplaceWindow::setMode,this, ARTIFACT_RESOURCE), 18, 485,"TPMRKBU3.DEF"); //was y=450, changed to not overlap res-art in some conditions + if(printButtonFor(EMarketMode::RESOURCE_PLAYER)) + new AdventureMapButton(CGI->generaltexth->zelp[612],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::RESOURCE_PLAYER), 18, 520,"TPMRKBU1.DEF"); + if(printButtonFor(EMarketMode::RESOURCE_RESOURCE)) + new AdventureMapButton(CGI->generaltexth->zelp[605],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::RESOURCE_RESOURCE), 516, 450 + specialOffset,"TPMRKBU5.DEF"); + if(printButtonFor(EMarketMode::CREATURE_RESOURCE)) + new AdventureMapButton(CGI->generaltexth->zelp[599],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::CREATURE_RESOURCE), 516, 485,"TPMRKBU4.DEF"); //was y=450, changed to not overlap res-res in some conditions + if(printButtonFor(EMarketMode::RESOURCE_ARTIFACT)) + new AdventureMapButton(CGI->generaltexth->zelp[598],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::RESOURCE_ARTIFACT), 18, 450 + specialOffset,"TPMRKBU2.DEF"); + if(printButtonFor(EMarketMode::ARTIFACT_RESOURCE)) + new AdventureMapButton(CGI->generaltexth->zelp[613],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::ARTIFACT_RESOURCE), 18, 485,"TPMRKBU3.DEF"); //was y=450, changed to not overlap res-art in some conditions updateTraderText(); } @@ -3380,9 +3370,9 @@ void CMarketplaceWindow::makeDeal() return; int leftIdToSend = -1; - if(mode == CREATURE_RESOURCE) + if(mode == EMarketMode::CREATURE_RESOURCE) leftIdToSend = hLeft->serial; - else if(mode == ARTIFACT_RESOURCE) + else if(mode == EMarketMode::ARTIFACT_RESOURCE) leftIdToSend = hLeft->getArtInstance()->id; else leftIdToSend = hLeft->id; @@ -3411,10 +3401,10 @@ void CMarketplaceWindow::sliderMoved( int to ) void CMarketplaceWindow::selectionChanged(bool side) { readyToTrade = hLeft && hRight; - if(mode == RESOURCE_RESOURCE) + if(mode == EMarketMode::RESOURCE_RESOURCE) readyToTrade = readyToTrade && (hLeft->id != hRight->id); //for resource trade, two DIFFERENT resources must be selected - if(mode == ARTIFACT_RESOURCE && !hLeft) + if(mode == EMarketMode::ARTIFACT_RESOURCE && !hLeft) arts->unmarkSlots(false); if(readyToTrade) @@ -3462,14 +3452,14 @@ void CMarketplaceWindow::selectionChanged(bool side) redraw(); } -bool CMarketplaceWindow::printButtonFor(EMarketMode M) const +bool CMarketplaceWindow::printButtonFor(EMarketMode::EMarketMode M) const { - return market->allowsTrade(M) && M != mode && (hero || ( M != CREATURE_RESOURCE && M != RESOURCE_ARTIFACT && M != ARTIFACT_RESOURCE )); + return market->allowsTrade(M) && M != mode && (hero || ( M != EMarketMode::CREATURE_RESOURCE && M != EMarketMode::RESOURCE_ARTIFACT && M != EMarketMode::ARTIFACT_RESOURCE )); } void CMarketplaceWindow::garrisonChanged() { - if(mode != CREATURE_RESOURCE) + if(mode != EMarketMode::CREATURE_RESOURCE) return; std::set toRemove; @@ -3483,7 +3473,7 @@ void CMarketplaceWindow::garrisonChanged() void CMarketplaceWindow::artifactsChanged(bool Left) { assert(!Left); - if(mode != RESOURCE_ARTIFACT) + if(mode != EMarketMode::RESOURCE_ARTIFACT) return; std::vector available = market->availableItemsIds(mode); @@ -3553,7 +3543,7 @@ Point CMarketplaceWindow::selectionOffset(bool Left) const switch(itemsType[0]) { case RESOURCE: - if(mode == ARTIFACT_RESOURCE) + if(mode == EMarketMode::ARTIFACT_RESOURCE) return Point(410, 469); else return Point(410, 446); @@ -3620,27 +3610,27 @@ void CMarketplaceWindow::updateTraderText() { if(readyToTrade) { - if(mode == RESOURCE_PLAYER) + if(mode == EMarketMode::RESOURCE_PLAYER) { //I can give %s to the %s player. traderText->setTxt(boost::str(boost::format(CGI->generaltexth->allTexts[165]) % hLeft->getName() % hRight->getName())); } - else if(mode == RESOURCE_ARTIFACT) + else if(mode == EMarketMode::RESOURCE_ARTIFACT) { //I can offer you the %s for %d %s of %s. traderText->setTxt(boost::str(boost::format(CGI->generaltexth->allTexts[267]) % hRight->getName() % r1 % CGI->generaltexth->allTexts[160 + (r1==1)] % hLeft->getName())); } - else if(mode == RESOURCE_RESOURCE) + else if(mode == EMarketMode::RESOURCE_RESOURCE) { //I can offer you %d %s of %s for %d %s of %s. traderText->setTxt(boost::str(boost::format(CGI->generaltexth->allTexts[157]) % r2 % CGI->generaltexth->allTexts[160 + (r2==1)] % hRight->getName() % r1 % CGI->generaltexth->allTexts[160 + (r1==1)] % hLeft->getName())); } - else if(mode == CREATURE_RESOURCE) + else if(mode == EMarketMode::CREATURE_RESOURCE) { //I can offer you %d %s of %s for %d %s. traderText->setTxt(boost::str(boost::format(CGI->generaltexth->allTexts[269]) % r2 % CGI->generaltexth->allTexts[160 + (r2==1)] % hRight->getName() % r1 % hLeft->getName(r1))); } - else if(mode == ARTIFACT_RESOURCE) + else if(mode == EMarketMode::ARTIFACT_RESOURCE) { //I can offer you %d %s of %s for your %s. traderText->setTxt(boost::str(boost::format(CGI->generaltexth->allTexts[268]) % r2 % CGI->generaltexth->allTexts[160 + (r2==1)] % hRight->getName() % hLeft->getName(r1))); @@ -3651,14 +3641,14 @@ void CMarketplaceWindow::updateTraderText() int gnrtxtnr = -1; if(madeTransaction) { - if(mode == RESOURCE_PLAYER) + if(mode == EMarketMode::RESOURCE_PLAYER) gnrtxtnr = 166; //Are there any other resources you'd like to give away? else gnrtxtnr = 162; //You have received quite a bargain. I expect to make no profit on the deal. Can I interest you in any of my other wares? } else { - if(mode == RESOURCE_PLAYER) + if(mode == EMarketMode::RESOURCE_PLAYER) gnrtxtnr = 167; //If you'd like to give any of your resources to another player, click on the item you wish to give and to whom. else gnrtxtnr = 163; //Please inspect our fine wares. If you feel like offering a trade, click on the items you wish to trade with and for. @@ -3666,18 +3656,18 @@ void CMarketplaceWindow::updateTraderText() traderText->setTxt(CGI->generaltexth->allTexts[gnrtxtnr]); } -CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*= NULL*/, EMarketMode Mode) +CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*= NULL*/, EMarketMode::EMarketMode Mode) :CTradeWindow(Market, Hero, Mode) { OBJ_CONSTRUCTION_CAPTURING_ALL; - bg = new CPicture(Mode == CREATURE_EXP ? "ALTARMON.bmp" : "ALTRART2.bmp"); + bg = new CPicture(Mode == EMarketMode::CREATURE_EXP ? "ALTARMON.bmp" : "ALTRART2.bmp"); bg->colorizeAndConvert(LOCPLINT->playerID); pos = bg->center(); - if(Mode == CREATURE_EXP) + if(Mode == EMarketMode::CREATURE_EXP) { printAtMiddle(boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->name), 155, 30, FONT_SMALL, tytulowy, *bg); //%s's Creatures printAtMiddle(CGI->generaltexth->allTexts[479], 450, 30, FONT_SMALL, tytulowy, *bg); //Altar of Sacrifice @@ -3687,7 +3677,7 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*= slider->moved = boost::bind(&CAltarWindow::sliderMoved,this,_1); max = new AdventureMapButton(CGI->generaltexth->zelp[578],boost::bind(&CSlider::moveToMax, slider),147,520,"IRCBTNS.DEF"); - sacrificedUnits.resize(ARMY_SIZE, 0); + sacrificedUnits.resize(GameConstants::ARMY_SIZE, 0); sacrificeAll = new AdventureMapButton(CGI->generaltexth->zelp[579],boost::bind(&CAltarWindow::SacrificeAll,this),393,520,"ALTARMY.DEF"); sacrificeBackpack = NULL; @@ -3720,12 +3710,12 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*= deal = new AdventureMapButton(CGI->generaltexth->zelp[585],boost::bind(&CAltarWindow::makeDeal,this),269,520,"ALTSACR.DEF"); - if(Hero->getAlignment() != EVIL && Mode == CREATURE_EXP) - new AdventureMapButton(CGI->generaltexth->zelp[580], boost::bind(&CTradeWindow::setMode,this, ARTIFACT_EXP), 516, 421, "ALTART.DEF"); - if(Hero->getAlignment() != GOOD && Mode == ARTIFACT_EXP) - new AdventureMapButton(CGI->generaltexth->zelp[572], boost::bind(&CTradeWindow::setMode,this, CREATURE_EXP), 516, 421, "ALTSACC.DEF"); + if(Hero->getAlignment() != ::EAlignment::EVIL && Mode == EMarketMode::CREATURE_EXP) + new AdventureMapButton(CGI->generaltexth->zelp[580], boost::bind(&CTradeWindow::setMode,this, EMarketMode::ARTIFACT_EXP), 516, 421, "ALTART.DEF"); + if(Hero->getAlignment() != ::EAlignment::GOOD && Mode == EMarketMode::ARTIFACT_EXP) + new AdventureMapButton(CGI->generaltexth->zelp[572], boost::bind(&CTradeWindow::setMode,this, EMarketMode::CREATURE_EXP), 516, 421, "ALTSACC.DEF"); - expPerUnit.resize(ARMY_SIZE, 0); + expPerUnit.resize(GameConstants::ARMY_SIZE, 0); getExpValues(); expToLevel = new CLabel(73, 475, FONT_SMALL, CENTER); @@ -3763,7 +3753,7 @@ void CAltarWindow::sliderMoved(int to) void CAltarWindow::makeDeal() { - if(mode == CREATURE_EXP) + if(mode == EMarketMode::CREATURE_EXP) { blockTrade(); slider->value = 0; @@ -3808,7 +3798,7 @@ void CAltarWindow::makeDeal() void CAltarWindow::SacrificeAll() { - if(mode == CREATURE_EXP) + if(mode == EMarketMode::CREATURE_EXP) { bool movedAnything = false; BOOST_FOREACH(CTradeableItem *t, items[1]) @@ -3841,7 +3831,7 @@ void CAltarWindow::SacrificeAll() void CAltarWindow::selectionChanged(bool side) { - if(mode != CREATURE_EXP) + if(mode != EMarketMode::CREATURE_EXP) return; CTradeableItem *&selected = side ? hLeft : hRight; @@ -3850,7 +3840,7 @@ void CAltarWindow::selectionChanged(bool side) theOther = *std::find_if(items[!side].begin(), items[!side].end(), boost::bind(&CTradeableItem::serial, _1) == selected->serial); int stackCount = 0; - for (int i = 0; i < ARMY_SIZE; i++) + for (int i = 0; i < GameConstants::ARMY_SIZE; i++) if(hero->getStackCount(i) > sacrificedUnits[i]) stackCount++; @@ -3900,7 +3890,7 @@ void CAltarWindow::artifactsChanged(bool left) void CAltarWindow::garrisonChanged() { - if(mode != CREATURE_EXP) + if(mode != EMarketMode::CREATURE_EXP) return; std::set empty; @@ -3921,13 +3911,13 @@ void CAltarWindow::getExpValues() int dump; BOOST_FOREACH(CTradeableItem *t, items[1]) if(t->id >= 0) - market->getOffer(t->id, 0, dump, expPerUnit[t->serial], CREATURE_EXP); + market->getOffer(t->id, 0, dump, expPerUnit[t->serial], EMarketMode::CREATURE_EXP); } void CAltarWindow::calcTotalExp() { int val = 0; - if(mode == CREATURE_EXP) + if(mode == EMarketMode::CREATURE_EXP) { for (int i = 0; i < sacrificedUnits.size(); i++) { @@ -3943,7 +3933,7 @@ void CAltarWindow::calcTotalExp() val += valOfArt; //WAS val += valOfArt * arts->artifactsOnAltar.count(*i); } } - val *=(100+hero->getSecSkillLevel(CGHeroInstance::LEARNING)*5)/100.0f; + val *=(100+hero->getSecSkillLevel(CGHeroInstance::LEARNING)*5)/100.0; expOnAltar->setTxt(boost::lexical_cast(val)); } @@ -4006,12 +3996,12 @@ void CAltarWindow::artifactPicked() void CAltarWindow::showAll(SDL_Surface * to) { CTradeWindow::showAll(to); - if(mode == ARTIFACT_EXP && arts && arts->commonInfo->src.art) + if(mode == EMarketMode::ARTIFACT_EXP && arts && arts->commonInfo->src.art) { blitAtLoc(graphics->artDefs->ourImages[arts->commonInfo->src.art->artType->id].bitmap, 281, 442, to); int dmp, val; - market->getOffer(arts->commonInfo->src.art->artType->id, 0, dmp, val, ARTIFACT_EXP); + market->getOffer(arts->commonInfo->src.art->artType->id, 0, dmp, val, EMarketMode::ARTIFACT_EXP); printAtMiddleLoc(boost::lexical_cast(val), 304, 498, FONT_SMALL, zwykly, to); } } @@ -4037,7 +4027,7 @@ bool CAltarWindow::putOnAltar(CTradeableItem* altarSlot, const CArtifactInstance } int dmp, val; - market->getOffer(artID, 0, dmp, val, ARTIFACT_EXP); + market->getOffer(artID, 0, dmp, val, EMarketMode::ARTIFACT_EXP); arts->artifactsOnAltar.insert(art); altarSlot->setArtInstance(art); @@ -4049,7 +4039,7 @@ bool CAltarWindow::putOnAltar(CTradeableItem* altarSlot, const CArtifactInstance void CAltarWindow::moveFromSlotToAltar(int slotID, CTradeableItem* altarSlot, const CArtifactInstance *art) { - int freeBackpackSlot = hero->artifactsInBackpack.size() + Arts::BACKPACK_START; + int freeBackpackSlot = hero->artifactsInBackpack.size() + GameConstants::BACKPACK_START; if(arts->commonInfo->src.art) { arts->commonInfo->dst.slotID = freeBackpackSlot; @@ -4058,7 +4048,7 @@ void CAltarWindow::moveFromSlotToAltar(int slotID, CTradeableItem* altarSlot, co if(putOnAltar(altarSlot, art)) { - if(slotID < Arts::BACKPACK_START) + if(slotID < GameConstants::BACKPACK_START) LOCPLINT->cb->swapArtifacts(hero, slotID, hero, freeBackpackSlot); else { @@ -4307,8 +4297,7 @@ void CTavernWindow::show(SDL_Surface * to) void CTavernWindow::HeroPortrait::clickLeft(tribool down, bool previousState) { if(previousState && !down && h) - as(); - //ClickableL::clickLeft(down); + *_sel = _id; } void CTavernWindow::HeroPortrait::clickRight(tribool down, bool previousState) @@ -4320,7 +4309,7 @@ void CTavernWindow::HeroPortrait::clickRight(tribool down, bool previousState) } CTavernWindow::HeroPortrait::HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H) -:as(sel,id), h(H) +: h(H), _id(id), _sel(&sel) { used = LCLICK | RCLICK | HOVER; h = H; @@ -4688,8 +4677,8 @@ void CArtPlace::activate() void CArtPlace::clickLeft(tribool down, bool previousState) { //LRClickableAreaWTextComp::clickLeft(down); - bool inBackpack = slotID >= Arts::BACKPACK_START, - srcInBackpack = ourOwner->commonInfo->src.slotID >= Arts::BACKPACK_START, + bool inBackpack = slotID >= GameConstants::BACKPACK_START, + srcInBackpack = ourOwner->commonInfo->src.slotID >= GameConstants::BACKPACK_START, srcInSameHero = ourOwner->commonInfo->src.AOH == ourOwner; if(ourOwner->highlightModeCallback && ourArt) @@ -4766,10 +4755,10 @@ void CArtPlace::clickLeft(tribool down, bool previousState) break; default: setMeAsDest(); - amin(ourOwner->commonInfo->dst.slotID, ourOwner->curHero->artifactsInBackpack.size() + Arts::BACKPACK_START); + vstd::amin(ourOwner->commonInfo->dst.slotID, ourOwner->curHero->artifactsInBackpack.size() + GameConstants::BACKPACK_START); if(srcInBackpack && srcInSameHero) { - if(!ourArt //cannot move from backpack to AFTER backpack -> combined with amin above it will guarantee that dest is at most the last artifact + if(!ourArt //cannot move from backpack to AFTER backpack -> combined with vstd::amin above it will guarantee that dest is at most the last artifact || ourOwner->commonInfo->src.slotID < ourOwner->commonInfo->dst.slotID) //rearranging arts in backpack after taking src artifact, the dest id will be shifted ourOwner->commonInfo->dst.slotID--; } @@ -4860,9 +4849,9 @@ void CArtPlace::select () return; picked = true; - if(ourArt->canBeDisassembled() && slotID < Arts::BACKPACK_START) //worn combined artifact -> locks have to disappear + if(ourArt->canBeDisassembled() && slotID < GameConstants::BACKPACK_START) //worn combined artifact -> locks have to disappear { - for(int i = 0; i < Arts::BACKPACK_START; i++) + for(int i = 0; i < GameConstants::BACKPACK_START; i++) { CArtPlace *ap = ourOwner->getArtPlace(i); ap->picked = ourArt->isPart(ap->ourArt); @@ -4875,7 +4864,7 @@ void CArtPlace::select () ourOwner->commonInfo->src.setTo(this, false); ourOwner->markPossibleSlots(ourArt); - if(slotID >= Arts::BACKPACK_START) + if(slotID >= GameConstants::BACKPACK_START) ourOwner->scrollBackpack(0); //will update slots ourOwner->updateParentWindow(); @@ -4890,14 +4879,14 @@ void CArtPlace::deselect () picked = false; if(ourArt && ourArt->canBeDisassembled()) //combined art returned to its slot -> restore locks { - for(int i = 0; i < Arts::BACKPACK_START; i++) + for(int i = 0; i < GameConstants::BACKPACK_START; i++) ourOwner->getArtPlace(i)->picked = false; } CCS->curh->dragAndDropCursor(NULL); ourOwner->unmarkSlots(); ourOwner->commonInfo->src.clear(); - if(slotID >= Arts::BACKPACK_START) + if(slotID >= GameConstants::BACKPACK_START) ourOwner->scrollBackpack(0); //will update slots @@ -5225,7 +5214,7 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero) void CArtifactsOfHero::dispose() { - //delNull(curHero); + //vstd::clear_pointer(curHero); //unmarkSlots(false); CCS->curh->dragAndDropCursor(NULL); } @@ -5339,7 +5328,7 @@ void CArtifactsOfHero::unmarkLocalSlots(bool withRedraw /*= true*/) */ void CArtifactsOfHero::setSlotData(CArtPlace* artPlace, int slotID) { - if(!artPlace && slotID >= Arts::BACKPACK_START) //spurious call from artifactMoved in attempt to update hidden backpack slot + if(!artPlace && slotID >= GameConstants::BACKPACK_START) //spurious call from artifactMoved in attempt to update hidden backpack slot { return; } @@ -5511,9 +5500,9 @@ void CArtifactsOfHero::realizeCurrentTransaction() void CArtifactsOfHero::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst) { - if(src.hero == curHero && src.slot >= Arts::BACKPACK_START) + if(src.hero == curHero && src.slot >= GameConstants::BACKPACK_START) updateSlot(src.slot); - if(dst.hero == curHero && dst.slot >= Arts::BACKPACK_START) + if(dst.hero == curHero && dst.slot >= GameConstants::BACKPACK_START) updateSlot(dst.slot); if(src.hero == curHero || dst.hero == curHero) //we need to update all slots, artifact might be combined and affect more slots updateWornSlots(false); @@ -5523,13 +5512,13 @@ void CArtifactsOfHero::artifactMoved(const ArtifactLocation &src, const Artifact if(commonInfo->src == src) //artifact was taken from us { - assert(commonInfo->dst == dst || dst.slot == dst.hero->artifactsInBackpack.size() + Arts::BACKPACK_START); + assert(commonInfo->dst == dst || dst.slot == dst.hero->artifactsInBackpack.size() + GameConstants::BACKPACK_START); commonInfo->reset(); unmarkSlots(); } else if(commonInfo->dst == src) //the dest artifact was moved -> we are picking it { - assert(dst.slot >= Arts::BACKPACK_START); + assert(dst.slot >= GameConstants::BACKPACK_START); commonInfo->reset(); CArtPlace *ap = NULL; @@ -5556,7 +5545,7 @@ void CArtifactsOfHero::artifactMoved(const ArtifactLocation &src, const Artifact markPossibleSlots(dst.getArt()); } } - else if(src.slot >= Arts::BACKPACK_START && + else if(src.slot >= GameConstants::BACKPACK_START && src.slot < commonInfo->src.slotID && src.hero == commonInfo->src.AOH->curHero) //artifact taken from before currently picked one { @@ -5577,13 +5566,13 @@ void CArtifactsOfHero::artifactMoved(const ArtifactLocation &src, const Artifact // if(dst.slot >= Arts::BACKPACK_START && dst.slot - Arts::BACKPACK_START < backpackPos) // shift++; // - if(src.slot < Arts::BACKPACK_START && dst.slot - Arts::BACKPACK_START < backpackPos) + if(src.slot < GameConstants::BACKPACK_START && dst.slot - GameConstants::BACKPACK_START < backpackPos) shift++; - if(dst.slot < Arts::BACKPACK_START && src.slot - Arts::BACKPACK_START < backpackPos) + if(dst.slot < GameConstants::BACKPACK_START && src.slot - GameConstants::BACKPACK_START < backpackPos) shift--; - if( (src.hero == curHero && src.slot >= Arts::BACKPACK_START) - || (dst.hero == curHero && dst.slot >= Arts::BACKPACK_START) ) + if( (src.hero == curHero && src.slot >= GameConstants::BACKPACK_START) + || (dst.hero == curHero && dst.slot >= GameConstants::BACKPACK_START) ) scrollBackpack(shift); //update backpack slots } @@ -5591,7 +5580,7 @@ void CArtifactsOfHero::artifactRemoved(const ArtifactLocation &al) { if(al.hero == curHero) { - if(al.slot < Arts::BACKPACK_START) + if(al.slot < GameConstants::BACKPACK_START) updateWornSlots(0); else scrollBackpack(0); //update backpack slots @@ -5600,7 +5589,7 @@ void CArtifactsOfHero::artifactRemoved(const ArtifactLocation &al) CArtPlace * CArtifactsOfHero::getArtPlace(int slot) { - if(slot < Arts::BACKPACK_START) + if(slot < GameConstants::BACKPACK_START) { return artWorn[slot]; } @@ -5899,7 +5888,7 @@ CShipyardWindow::CShipyardWindow(const std::vector &cost, int state, int b costLabel = new CLabel(164, 220, FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->jktexts[14]); } -CPuzzleWindow::CPuzzleWindow(const int3 &grailPos, float discoveredRatio) +CPuzzleWindow::CPuzzleWindow(const int3 &grailPos, double discoveredRatio) :animCount(0) { SDL_Surface * back = BitmapHandler::loadBitmap("PUZZLE.BMP", false); @@ -6059,7 +6048,7 @@ void CTransformerWindow::makeDeal() { for (int i=0; ileft) - LOCPLINT->cb->trade(town, CREATURE_UNDEAD, items[i]->id, 0, 0, hero); + LOCPLINT->cb->trade(town, EMarketMode::CREATURE_UNDEAD, items[i]->id, 0, 0, hero); } void CTransformerWindow::addAll() @@ -6137,7 +6126,7 @@ int CUniversityWindow::CItem::state() { if (parent->hero->getSecSkillLevel(static_cast(ID)))//hero know this skill return 1; - if (parent->hero->secSkills.size() >= SKILL_PER_HERO)//can't learn more skills + if (parent->hero->secSkills.size() >= GameConstants::SKILL_PER_HERO)//can't learn more skills return 0; if (parent->hero->type->heroClass->proSec[ID]==0)//can't learn this skill (like necromancy for most of non-necros) return 0; @@ -6207,7 +6196,7 @@ CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket printAtMiddleWBLoc(CGI->generaltexth->allTexts[603], 232, 153, FONT_SMALL, 70,zwykly,bg->bg);//Clerk speech printAtMiddleLoc (CGI->generaltexth->allTexts[602], 231, 26 , FONT_MEDIUM ,tytulowy,bg->bg);//University - std::vector list = market->availableItemsIds(RESOURCE_SKILL); + std::vector list = market->availableItemsIds(EMarketMode::RESOURCE_SKILL); if (list.size()!=4) tlog0<<"\t\tIncorrect size of available items vector!\n"; for (int i=0; icb->trade(parent->market->o, RESOURCE_SKILL, 6, skill, 1, parent->hero); + LOCPLINT->cb->trade(parent->market->o, EMarketMode::RESOURCE_SKILL, 6, skill, 1, parent->hero); GH.popIntTotally(this); } @@ -6285,7 +6274,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectIn currState.resize(slotsCount+1); costs.resize(slotsCount); - totalSumm.resize(RESOURCE_QUANTITY); + totalSumm.resize(GameConstants::RESOURCE_QUANTITY); std::vector files; files += "APHLF1R.DEF", "APHLF1Y.DEF", "APHLF1G.DEF"; for (int i=0; ipos; if(maxw < pos.w) { - amin(pos.w, maxw); + vstd::amin(pos.w, maxw); bg->srcRect = new Rect(0, 0, maxw, pos.h); } calcOffset(); diff --git a/client/GUIClasses.h b/client/GUIClasses.h index ef6de8413..ff1d8989e 100644 --- a/client/GUIClasses.h +++ b/client/GUIClasses.h @@ -1,13 +1,10 @@ -#ifndef __GUICLASSES_H__ -#define __GUICLASSES_H__ +#pragma once + -#include "../global.h" #include "GUIBase.h" #include "FunctionList.h" -#include -#include -#include #include "../lib/ResourceSet.h" +#include "../lib/GameConstants.h" #ifdef max #undef max @@ -761,12 +758,12 @@ public: CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight) EType itemsType[2]; - EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact + EMarketMode::EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact AdventureMapButton *ok, *max, *deal; CSlider *slider; //for choosing amount to be exchanged bool readyToTrade; - CTradeWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode); //c + CTradeWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c void showAll(SDL_Surface * to); @@ -778,7 +775,7 @@ public: void removeItems(const std::set &toRemove); void removeItem(CTradeableItem * t); void getEmptySlots(std::set &toRemove); - void setMode(EMarketMode Mode); //mode setter + void setMode(EMarketMode::EMarketMode Mode); //mode setter void artifactSelected(CArtPlace *slot); //used when selling artifacts -> called when user clicked on artifact slot @@ -792,7 +789,7 @@ public: class CMarketplaceWindow : public CTradeWindow { - bool printButtonFor(EMarketMode M) const; + bool printButtonFor(EMarketMode::EMarketMode M) const; public: int r1, r2; //suggested amounts of traded resources bool madeTransaction; //if player made at least one transaction @@ -802,7 +799,7 @@ public: void sliderMoved(int to); void makeDeal(); void selectionChanged(bool side); //true == left - CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = NULL, EMarketMode Mode = RESOURCE_RESOURCE); //c-tor + CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = NULL, EMarketMode::EMarketMode Mode = EMarketMode::RESOURCE_RESOURCE); //c-tor ~CMarketplaceWindow(); //d-tor Point selectionOffset(bool Left) const; @@ -820,7 +817,7 @@ public: class CAltarWindow : public CTradeWindow { public: - CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode); //c-tor + CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c-tor void getExpValues(); ~CAltarWindow(); //d-tor @@ -889,7 +886,6 @@ public: { public: std::string hoverName; - vstd::assigner as; const CGHeroInstance *h; char descr[100]; // "XXX is a level Y ZZZ with N artifacts" @@ -899,6 +895,10 @@ public: HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H); void show(SDL_Surface * to); + private: + int *_sel; + const int _id; + } *h1, *h2; //recruitable heroes CPicture *bg; //background @@ -1179,7 +1179,7 @@ class CExchangeWindow : public CWindowWithGarrison, public CWindowWithArtifacts public: - const CGHeroInstance * heroInst[2]; + const CGHeroInstance* heroInst[2]; CArtifactsOfHero * artifs[2]; void close(); @@ -1231,7 +1231,7 @@ public: void deactivate(); void show(SDL_Surface * to); - CPuzzleWindow(const int3 &grailPos, float discoveredRatio); + CPuzzleWindow(const int3 &grailPos, double discoveredRatio); ~CPuzzleWindow(); }; @@ -1367,5 +1367,3 @@ public: CIntObject *createCreWindow(const CStack *s); CIntObject *createCreWindow(int Cid, int Type, int creatureCount); CIntObject *createCreWindow(const CStackInstance *s, int type, boost::function Upg = 0, boost::function Dsm = 0, UpgradeInfo *ui = NULL); - -#endif //__GUICLASSES_H__ diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 139f37d44..e58d979e7 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -1,16 +1,10 @@ -#include "../stdafx.h" +#include "StdInc.h" #include "Graphics.h" + #include "CDefHandler.h" #include "SDL_Extensions.h" #include -#include -#include -#include -#include -#include -#include -#include -#include "../CThreadHelper.h" +#include "../lib/CThreadHelper.h" #include "CGameInfo.h" #include "../lib/CLodHandler.h" #include "../lib/VCMI_Lib.h" @@ -25,6 +19,7 @@ #include "../lib/CGameState.h" #include "../lib/JsonNode.h" #include "../lib/vcmi_endian.h" +#include "../lib/GameConstants.h" using namespace boost::assign; using namespace CSDL_Ext; @@ -74,7 +69,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const InfoAboutHero &curh) if(curh.details) { - for (int i = 0; i < PRIMARY_SKILLS; i++) + for (int i = 0; i < GameConstants::PRIMARY_SKILLS; i++) { SDL_itoa(curh.details->primskills[i], buf, 10); printAtMiddle(buf,84+28*i,70,FONT_SMALL,zwykly,ret); @@ -139,7 +134,7 @@ SDL_Surface * Graphics::drawTownInfoWin( const InfoAboutTown & curh ) if (curh.tType) { pom = curh.tType->typeID*2; if (!curh.fortLevel) - pom += F_NUMBER*2; + pom += GameConstants::F_NUMBER*2; if(curh.built) pom++; blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret); @@ -167,7 +162,7 @@ void Graphics::loadPaletteAndColors() std::string pals = bitmaph->getTextFile("PLAYERS.PAL", FILE_OTHER); playerColorPalette = new SDL_Color[256]; neutralColor = new SDL_Color; - playerColors = new SDL_Color[PLAYER_LIMIT]; + playerColors = new SDL_Color[GameConstants::PLAYER_LIMIT]; int startPoint = 24; //beginning byte; used to read for(int i=0; i<256; ++i) { @@ -181,7 +176,8 @@ void Graphics::loadPaletteAndColors() neutralColorPalette = new SDL_Color[32]; std::ifstream ncp; - ncp.open(DATA_DIR "/config/NEUTRAL.PAL", std::ios::binary); + std::string neutralFile = GameConstants::DATA_DIR + "/config/NEUTRAL.PAL"; + ncp.open(neutralFile.c_str(), std::ios::binary); for(int i=0; i<32; ++i) { ncp.read((char*)&neutralColorPalette[i].r,1); @@ -202,7 +198,7 @@ void Graphics::loadPaletteAndColors() playerColors[i].unused = 0; } neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84; neutralColor->unused = 0x0;//gray - const JsonNode config(DATA_DIR "/config/town_pictures.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/town_pictures.json"); BOOST_FOREACH(const JsonNode &p, config["town_pictures"].Vector()) { townBgs.push_back(p["town_background"].String()); @@ -213,7 +209,7 @@ void Graphics::loadPaletteAndColors() void Graphics::initializeBattleGraphics() { - const JsonNode config(DATA_DIR "/config/battles_graphics.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/battles_graphics.json"); // Reserve enough space for the terrains int idx = config["backgrounds"].Vector().size(); @@ -302,14 +298,14 @@ Graphics::Graphics() tasks += GET_DEF_ESS(spellscr,"SPELLSCR.DEF"); tasks += GET_DEF_ESS(heroMoveArrows,"ADAG.DEF"); - const JsonNode config(DATA_DIR "/config/creature_backgrounds.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/creature_backgrounds.json"); BOOST_FOREACH(const JsonNode &b, config["backgrounds"].Vector()) { const int id = b["id"].Float(); tasks += GET_SURFACE(backgrounds[id], b["bg130"].String()); tasks += GET_SURFACE(backgroundsm[id], b["bg120"].String()); } - CThreadHelper th(&tasks,std::max((unsigned int)1,boost::thread::hardware_concurrency())); + CThreadHelper th(&tasks,std::max((ui32)1,boost::thread::hardware_concurrency())); th.run(); for(size_t y=0; y < heroMoveArrows->ourImages.size(); ++y) @@ -336,7 +332,7 @@ Graphics::Graphics() } void Graphics::loadHeroPortraits() { - const JsonNode config(DATA_DIR "/config/portraits.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/portraits.json"); BOOST_FOREACH(const JsonNode &portrait_node, config["hero_portrait"].Vector()) { std::string filename = portrait_node["filename"].String(); @@ -362,7 +358,7 @@ void Graphics::loadHeroPortraits() void Graphics::loadWallPositions() { - const JsonNode config(DATA_DIR "/config/wall_pos.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/wall_pos.json"); BOOST_FOREACH(const JsonNode &town, config["towns"].Vector()) { int townID = town["id"].Float(); @@ -381,7 +377,7 @@ void Graphics::loadHeroAnims() std::vector > 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(size_t i=0; i Graphics::*, void Graphics::loadHeroFlags() { using namespace boost::assign; - timeHandler th; + StopWatch th; std::pair Graphics::*, std::vector > pr[4]; pr[0].first = &Graphics::flags1; pr[0].second+=("ABF01L.DEF"),("ABF01G.DEF"),("ABF01R.DEF"),("ABF01D.DEF"),("ABF01B.DEF"), @@ -508,7 +504,7 @@ void Graphics::loadHeroFlags() grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[g]),true)); } grupa.join_all(); - tlog0 << "Loading and transforming heroes' flags: "<ourImages[1].bitmap; else if (ID==-3) - return smallIcons->ourImages[2+F_NUMBER*4].bitmap; - else if (ID>F_NUMBER || ID<-3) + return smallIcons->ourImages[2+GameConstants::F_NUMBER*4].bitmap; + else if (ID>GameConstants::F_NUMBER || ID<-3) #ifndef __GNUC__ throw new std::exception("Invalid ID"); #else @@ -528,7 +524,7 @@ SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded) { int pom = 3; if(!fort) - pom+=F_NUMBER*2; + pom+=GameConstants::F_NUMBER*2; pom += ID*2; if (!builded) pom--; @@ -543,7 +539,7 @@ void Graphics::blueToPlayersAdv(SDL_Surface * sur, int player) if(sur->format->BitsPerPixel == 8) { SDL_Color *palette = NULL; - if(player < PLAYER_LIMIT && player >= 0) + if(player < GameConstants::PLAYER_LIMIT && player >= 0) { palette = playerColorPalette + 32*player; } @@ -633,7 +629,8 @@ void Graphics::loadTrueType() bool ttfPresent = false;//was TTF initialised or not for(int i = 0; i < FONTS_NUMBER; i++) fontsTrueType[i] = NULL; - std::ifstream ff(DATA_DIR "/config/fonts.txt"); + std::string fontsFile = GameConstants::DATA_DIR + "/config/fonts.txt"; + std::ifstream ff(fontsFile.c_str()); while(!ff.eof()) { int enabl, fntID, fntSize; @@ -653,7 +650,7 @@ void Graphics::loadTrueType() TTF_Init(); atexit(TTF_Quit); }; - fntName = DATA_DIR + ( "/Fonts/" + fntName); + fntName = GameConstants::DATA_DIR + ( "/Fonts/" + fntName); fontsTrueType[fntID] = TTF_OpenFont(fntName.c_str(),fntSize); } } @@ -664,7 +661,7 @@ void Graphics::loadTrueType() Font * Graphics::loadFont( const char * name ) { int len = 0; - unsigned char * hlp = bitmaph->giveFile(name, FILE_FONT, &len); + ui8 * hlp = bitmaph->giveFile(name, FILE_FONT, &len); if(!hlp || !len) { tlog1 << "Error: cannot load font: " << name << std::endl; @@ -707,7 +704,7 @@ CDefEssential * Graphics::getDef( const CGDefInfo * info ) void Graphics::loadErmuToPicture() { //loading ERMU to picture - const JsonNode config(DATA_DIR "/config/ERMU_to_picture.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/ERMU_to_picture.json"); int etp_idx = 0; BOOST_FOREACH(const JsonNode &etp, config["ERMU_to_picture"].Vector()) { int idx = 0; @@ -722,7 +719,7 @@ void Graphics::loadErmuToPicture() assert (etp_idx == 44); } -Font::Font(unsigned char *Data) +Font::Font(ui8 *Data) { data = Data; int i = 0; @@ -758,7 +755,7 @@ int Font::getWidth(const char *text ) const for(int i = 0; i < length; i++) { - unsigned char c = text[i]; + ui8 c = text[i]; ret += chars[c].width + chars[c].unknown1 + chars[c].unknown2; } @@ -767,7 +764,7 @@ int Font::getWidth(const char *text ) const int Font::getCharWidth( char c ) const { - const Char &C = chars[(unsigned char)c]; + const Char &C = chars[(ui8)c]; return C.width + C.unknown1 + C.unknown2;; } diff --git a/client/Graphics.h b/client/Graphics.h index 9f2a47829..1f3561b2c 100644 --- a/client/Graphics.h +++ b/client/Graphics.h @@ -1,9 +1,9 @@ -#ifndef __GRAPHICS_H__ -#define __GRAPHICS_H__ +#pragma once + -#include "../global.h" #include "FontBase.h" #include "GUIBase.h" +#include "../lib/GameConstants.h" /* * Graphics.h, part of VCMI engine @@ -80,13 +80,13 @@ public: std::vector< std::string > buildingPics;//filenames of def with building images (used rarely, too big to keep them loaded) std::vector< std::string > townBgs;//backgrounds of town std::vector< std::string > guildBgs;// name of bitmaps with imgs for mage guild screen - std::map ERMUtoPicture[F_NUMBER]; //maps building ID to it's picture's name for each town type + std::map ERMUtoPicture[GameConstants::F_NUMBER]; //maps building ID to it's picture's name for each town type //for battles std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle std::map< int, std::vector < std::string > > battleACToDef; //maps AC format to vector of appropriate def names CDefEssential * spellEffectsPics; //bitmaps representing spells affecting a stack in battle - std::vector< Point > wallPositions[F_NUMBER]; //positions of different pieces of wall + std::vector< Point > wallPositions[GameConstants::F_NUMBER]; //positions of different pieces of wall //abilities CDefEssential * abils32, * abils44, * abils82; //spells @@ -114,5 +114,3 @@ public: }; extern Graphics * graphics; - -#endif // __GRAPHICS_H__ diff --git a/client/Makefile.am b/client/Makefile.am index e42f4e101..84158f3b9 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -1,23 +1,59 @@ bin_PROGRAMS = vcmiclient +BUILT_SOURCES = StdInc.h.gch +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -c $< -vcmiclient_LDADD = $(top_builddir)/lib/libvcmi.la @SDL_LIBS@ @FFMPEG_LIBS@ @BOOST_PROGRAM_OPTIONS_LIB@ @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ @BOOST_IOSTREAMS_LIB@ -lrt +vcmiclient_LDADD = $(top_builddir)/lib/libvcmi.la @SDL_LIBS@ @FFMPEG_LIBS@ @BOOST_PROGRAM_OPTIONS_LIB@ @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ @BOOST_IOSTREAMS_LIB@ -lrt -lz vcmiclient_CXXFLAGS = @SDL_CFLAGS@ @FFMPEG_CXXFLAGS@ vcmiclient_LDFLAGS = -L$(top_builddir)/lib vcmiclient_SOURCES = \ ../CCallback.cpp \ ../CCallback.h \ - ../CConsoleHandler.cpp \ - ../CConsoleHandler.h \ - ../CThreadHelper.cpp \ - ../CThreadHelper.h \ + ./BattleInterface/CAttackAnimation.cpp \ + ./BattleInterface/CAttackAnimation.h \ + ./BattleInterface/CBattleAnimation.cpp \ + ./BattleInterface/CBattleAnimation.h \ + ./BattleInterface/CBattleConsole.cpp \ + ./BattleInterface/CBattleConsole.h \ + ./BattleInterface/CBattleHero.cpp \ + ./BattleInterface/CBattleHero.h \ + ./BattleInterface/CBattleInterface.cpp \ + ./BattleInterface/CBattleInterface.h \ + ./BattleInterface/CBattleOptionsWindow.cpp \ + ./BattleInterface/CBattleOptionsWindow.h \ + ./BattleInterface/CBattleResultWindow.cpp \ + ./BattleInterface/CBattleResultWindow.h \ + ./BattleInterface/CBattleStackAnimation.cpp \ + ./BattleInterface/CBattleStackAnimation.h \ + ./BattleInterface/CDefenceAnimation.cpp \ + ./BattleInterface/CDefenceAnimation.h \ + ./BattleInterface/CDummyAnimation.cpp \ + ./BattleInterface/CDummyAnimation.h \ + ./BattleInterface/CHexFieldControl.cpp \ + ./BattleInterface/CHexFieldControl.h \ + ./BattleInterface/CMeleeAttackAnimation.cpp \ + ./BattleInterface/CMeleeAttackAnimation.h \ + ./BattleInterface/CMovementAnimation.cpp \ + ./BattleInterface/CMovementAnimation.h \ + ./BattleInterface/CMovementEndAnimation.cpp \ + ./BattleInterface/CMovementEndAnimation.h \ + ./BattleInterface/CMovementStartAnimation.cpp \ + ./BattleInterface/CMovementStartAnimation.h \ + ./BattleInterface/CReverseAnimation.cpp \ + ./BattleInterface/CReverseAnimation.h \ + ./BattleInterface/CShootingAnimation.cpp \ + ./BattleInterface/CShootingAnimation.h \ + ./BattleInterface/CSpellEffectAnimation.cpp \ + ./BattleInterface/CSpellEffectAnimation.h \ + ./BattleInterface/CStackQueue.cpp \ + ./BattleInterface/CStackQueue.h \ + ./BattleInterface/SStackAttackedInfo.h \ AdventureMapButton.cpp \ AdventureMapButton.h \ CAdvmapInterface.cpp \ CAdvmapInterface.h \ CAnimation.cpp \ CAnimation.h \ - CBattleInterface.cpp \ - CBattleInterface.h \ CBitmapHandler.cpp \ CBitmapHandler.h \ CCastleInterface.cpp \ diff --git a/client/Makefile.in b/client/Makefile.in index 2d0f1ebc4..55377deea 100644 --- a/client/Makefile.in +++ b/client/Makefile.in @@ -59,12 +59,28 @@ CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) am_vcmiclient_OBJECTS = vcmiclient-CCallback.$(OBJEXT) \ - vcmiclient-CConsoleHandler.$(OBJEXT) \ - vcmiclient-CThreadHelper.$(OBJEXT) \ + vcmiclient-CAttackAnimation.$(OBJEXT) \ + vcmiclient-CBattleAnimation.$(OBJEXT) \ + vcmiclient-CBattleConsole.$(OBJEXT) \ + vcmiclient-CBattleHero.$(OBJEXT) \ + vcmiclient-CBattleInterface.$(OBJEXT) \ + vcmiclient-CBattleOptionsWindow.$(OBJEXT) \ + vcmiclient-CBattleResultWindow.$(OBJEXT) \ + vcmiclient-CBattleStackAnimation.$(OBJEXT) \ + vcmiclient-CDefenceAnimation.$(OBJEXT) \ + vcmiclient-CDummyAnimation.$(OBJEXT) \ + vcmiclient-CHexFieldControl.$(OBJEXT) \ + vcmiclient-CMeleeAttackAnimation.$(OBJEXT) \ + vcmiclient-CMovementAnimation.$(OBJEXT) \ + vcmiclient-CMovementEndAnimation.$(OBJEXT) \ + vcmiclient-CMovementStartAnimation.$(OBJEXT) \ + vcmiclient-CReverseAnimation.$(OBJEXT) \ + vcmiclient-CShootingAnimation.$(OBJEXT) \ + vcmiclient-CSpellEffectAnimation.$(OBJEXT) \ + vcmiclient-CStackQueue.$(OBJEXT) \ vcmiclient-AdventureMapButton.$(OBJEXT) \ vcmiclient-CAdvmapInterface.$(OBJEXT) \ vcmiclient-CAnimation.$(OBJEXT) \ - vcmiclient-CBattleInterface.$(OBJEXT) \ vcmiclient-CBitmapHandler.$(OBJEXT) \ vcmiclient-CCastleInterface.$(OBJEXT) \ vcmiclient-CConfigHandler.$(OBJEXT) \ @@ -276,24 +292,58 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -vcmiclient_LDADD = $(top_builddir)/lib/libvcmi.la @SDL_LIBS@ @FFMPEG_LIBS@ @BOOST_PROGRAM_OPTIONS_LIB@ @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ @BOOST_IOSTREAMS_LIB@ -lrt +BUILT_SOURCES = StdInc.h.gch +vcmiclient_LDADD = $(top_builddir)/lib/libvcmi.la @SDL_LIBS@ @FFMPEG_LIBS@ @BOOST_PROGRAM_OPTIONS_LIB@ @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ @BOOST_IOSTREAMS_LIB@ -lrt -lz vcmiclient_CXXFLAGS = @SDL_CFLAGS@ @FFMPEG_CXXFLAGS@ vcmiclient_LDFLAGS = -L$(top_builddir)/lib vcmiclient_SOURCES = \ ../CCallback.cpp \ ../CCallback.h \ - ../CConsoleHandler.cpp \ - ../CConsoleHandler.h \ - ../CThreadHelper.cpp \ - ../CThreadHelper.h \ + ./BattleInterface/CAttackAnimation.cpp \ + ./BattleInterface/CAttackAnimation.h \ + ./BattleInterface/CBattleAnimation.cpp \ + ./BattleInterface/CBattleAnimation.h \ + ./BattleInterface/CBattleConsole.cpp \ + ./BattleInterface/CBattleConsole.h \ + ./BattleInterface/CBattleHero.cpp \ + ./BattleInterface/CBattleHero.h \ + ./BattleInterface/CBattleInterface.cpp \ + ./BattleInterface/CBattleInterface.h \ + ./BattleInterface/CBattleOptionsWindow.cpp \ + ./BattleInterface/CBattleOptionsWindow.h \ + ./BattleInterface/CBattleResultWindow.cpp \ + ./BattleInterface/CBattleResultWindow.h \ + ./BattleInterface/CBattleStackAnimation.cpp \ + ./BattleInterface/CBattleStackAnimation.h \ + ./BattleInterface/CDefenceAnimation.cpp \ + ./BattleInterface/CDefenceAnimation.h \ + ./BattleInterface/CDummyAnimation.cpp \ + ./BattleInterface/CDummyAnimation.h \ + ./BattleInterface/CHexFieldControl.cpp \ + ./BattleInterface/CHexFieldControl.h \ + ./BattleInterface/CMeleeAttackAnimation.cpp \ + ./BattleInterface/CMeleeAttackAnimation.h \ + ./BattleInterface/CMovementAnimation.cpp \ + ./BattleInterface/CMovementAnimation.h \ + ./BattleInterface/CMovementEndAnimation.cpp \ + ./BattleInterface/CMovementEndAnimation.h \ + ./BattleInterface/CMovementStartAnimation.cpp \ + ./BattleInterface/CMovementStartAnimation.h \ + ./BattleInterface/CReverseAnimation.cpp \ + ./BattleInterface/CReverseAnimation.h \ + ./BattleInterface/CShootingAnimation.cpp \ + ./BattleInterface/CShootingAnimation.h \ + ./BattleInterface/CSpellEffectAnimation.cpp \ + ./BattleInterface/CSpellEffectAnimation.h \ + ./BattleInterface/CStackQueue.cpp \ + ./BattleInterface/CStackQueue.h \ + ./BattleInterface/SStackAttackedInfo.h \ AdventureMapButton.cpp \ AdventureMapButton.h \ CAdvmapInterface.cpp \ CAdvmapInterface.h \ CAnimation.cpp \ CAnimation.h \ - CBattleInterface.cpp \ - CBattleInterface.h \ CBitmapHandler.cpp \ CBitmapHandler.h \ CCastleInterface.cpp \ @@ -349,7 +399,8 @@ vcmiclient_SOURCES = \ SDL_framerate.cpp \ SDL_framerate.h -all: all-am +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .cpp .lo .o .obj @@ -439,27 +490,43 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-AdventureMapButton.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CAdvmapInterface.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CAnimation.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CAttackAnimation.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CBattleAnimation.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CBattleConsole.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CBattleHero.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CBattleInterface.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CBattleOptionsWindow.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CBattleResultWindow.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CBattleStackAnimation.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CBitmapHandler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CCallback.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CCastleInterface.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CConfigHandler.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CConsoleHandler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CCreatureAnimation.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CCreatureWindow.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CCursorHandler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CDefHandler.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CDefenceAnimation.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CDummyAnimation.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CGameInfo.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CHeroWindow.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CHexFieldControl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CKingdomInterface.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CMT.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CMeleeAttackAnimation.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CMessage.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CMovementAnimation.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CMovementEndAnimation.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CMovementStartAnimation.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CMusicHandler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CPlayerInterface.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CPreGame.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CReverseAnimation.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CShootingAnimation.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CSndHandler.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CSpellEffectAnimation.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CSpellWindow.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CThreadHelper.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CStackQueue.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CVideoHandler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-Client.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-GUIBase.Po@am__quote@ @@ -510,37 +577,309 @@ vcmiclient-CCallback.obj: ../CCallback.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CCallback.obj `if test -f '../CCallback.cpp'; then $(CYGPATH_W) '../CCallback.cpp'; else $(CYGPATH_W) '$(srcdir)/../CCallback.cpp'; fi` -vcmiclient-CConsoleHandler.o: ../CConsoleHandler.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CConsoleHandler.o -MD -MP -MF $(DEPDIR)/vcmiclient-CConsoleHandler.Tpo -c -o vcmiclient-CConsoleHandler.o `test -f '../CConsoleHandler.cpp' || echo '$(srcdir)/'`../CConsoleHandler.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CConsoleHandler.Tpo $(DEPDIR)/vcmiclient-CConsoleHandler.Po +vcmiclient-CAttackAnimation.o: ./BattleInterface/CAttackAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CAttackAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CAttackAnimation.Tpo -c -o vcmiclient-CAttackAnimation.o `test -f './BattleInterface/CAttackAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CAttackAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CAttackAnimation.Tpo $(DEPDIR)/vcmiclient-CAttackAnimation.Po @am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../CConsoleHandler.cpp' object='vcmiclient-CConsoleHandler.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CAttackAnimation.cpp' object='vcmiclient-CAttackAnimation.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CConsoleHandler.o `test -f '../CConsoleHandler.cpp' || echo '$(srcdir)/'`../CConsoleHandler.cpp +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CAttackAnimation.o `test -f './BattleInterface/CAttackAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CAttackAnimation.cpp -vcmiclient-CConsoleHandler.obj: ../CConsoleHandler.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CConsoleHandler.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CConsoleHandler.Tpo -c -o vcmiclient-CConsoleHandler.obj `if test -f '../CConsoleHandler.cpp'; then $(CYGPATH_W) '../CConsoleHandler.cpp'; else $(CYGPATH_W) '$(srcdir)/../CConsoleHandler.cpp'; fi` -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CConsoleHandler.Tpo $(DEPDIR)/vcmiclient-CConsoleHandler.Po +vcmiclient-CAttackAnimation.obj: ./BattleInterface/CAttackAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CAttackAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CAttackAnimation.Tpo -c -o vcmiclient-CAttackAnimation.obj `if test -f './BattleInterface/CAttackAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CAttackAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CAttackAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CAttackAnimation.Tpo $(DEPDIR)/vcmiclient-CAttackAnimation.Po @am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../CConsoleHandler.cpp' object='vcmiclient-CConsoleHandler.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CAttackAnimation.cpp' object='vcmiclient-CAttackAnimation.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CConsoleHandler.obj `if test -f '../CConsoleHandler.cpp'; then $(CYGPATH_W) '../CConsoleHandler.cpp'; else $(CYGPATH_W) '$(srcdir)/../CConsoleHandler.cpp'; fi` +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CAttackAnimation.obj `if test -f './BattleInterface/CAttackAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CAttackAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CAttackAnimation.cpp'; fi` -vcmiclient-CThreadHelper.o: ../CThreadHelper.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CThreadHelper.o -MD -MP -MF $(DEPDIR)/vcmiclient-CThreadHelper.Tpo -c -o vcmiclient-CThreadHelper.o `test -f '../CThreadHelper.cpp' || echo '$(srcdir)/'`../CThreadHelper.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CThreadHelper.Tpo $(DEPDIR)/vcmiclient-CThreadHelper.Po +vcmiclient-CBattleAnimation.o: ./BattleInterface/CBattleAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleAnimation.Tpo -c -o vcmiclient-CBattleAnimation.o `test -f './BattleInterface/CBattleAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleAnimation.Tpo $(DEPDIR)/vcmiclient-CBattleAnimation.Po @am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../CThreadHelper.cpp' object='vcmiclient-CThreadHelper.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleAnimation.cpp' object='vcmiclient-CBattleAnimation.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CThreadHelper.o `test -f '../CThreadHelper.cpp' || echo '$(srcdir)/'`../CThreadHelper.cpp +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleAnimation.o `test -f './BattleInterface/CBattleAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleAnimation.cpp -vcmiclient-CThreadHelper.obj: ../CThreadHelper.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CThreadHelper.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CThreadHelper.Tpo -c -o vcmiclient-CThreadHelper.obj `if test -f '../CThreadHelper.cpp'; then $(CYGPATH_W) '../CThreadHelper.cpp'; else $(CYGPATH_W) '$(srcdir)/../CThreadHelper.cpp'; fi` -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CThreadHelper.Tpo $(DEPDIR)/vcmiclient-CThreadHelper.Po +vcmiclient-CBattleAnimation.obj: ./BattleInterface/CBattleAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleAnimation.Tpo -c -o vcmiclient-CBattleAnimation.obj `if test -f './BattleInterface/CBattleAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleAnimation.Tpo $(DEPDIR)/vcmiclient-CBattleAnimation.Po @am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../CThreadHelper.cpp' object='vcmiclient-CThreadHelper.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleAnimation.cpp' object='vcmiclient-CBattleAnimation.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CThreadHelper.obj `if test -f '../CThreadHelper.cpp'; then $(CYGPATH_W) '../CThreadHelper.cpp'; else $(CYGPATH_W) '$(srcdir)/../CThreadHelper.cpp'; fi` +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleAnimation.obj `if test -f './BattleInterface/CBattleAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleAnimation.cpp'; fi` + +vcmiclient-CBattleConsole.o: ./BattleInterface/CBattleConsole.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleConsole.o -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleConsole.Tpo -c -o vcmiclient-CBattleConsole.o `test -f './BattleInterface/CBattleConsole.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleConsole.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleConsole.Tpo $(DEPDIR)/vcmiclient-CBattleConsole.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleConsole.cpp' object='vcmiclient-CBattleConsole.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleConsole.o `test -f './BattleInterface/CBattleConsole.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleConsole.cpp + +vcmiclient-CBattleConsole.obj: ./BattleInterface/CBattleConsole.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleConsole.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleConsole.Tpo -c -o vcmiclient-CBattleConsole.obj `if test -f './BattleInterface/CBattleConsole.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleConsole.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleConsole.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleConsole.Tpo $(DEPDIR)/vcmiclient-CBattleConsole.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleConsole.cpp' object='vcmiclient-CBattleConsole.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleConsole.obj `if test -f './BattleInterface/CBattleConsole.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleConsole.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleConsole.cpp'; fi` + +vcmiclient-CBattleHero.o: ./BattleInterface/CBattleHero.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleHero.o -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleHero.Tpo -c -o vcmiclient-CBattleHero.o `test -f './BattleInterface/CBattleHero.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleHero.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleHero.Tpo $(DEPDIR)/vcmiclient-CBattleHero.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleHero.cpp' object='vcmiclient-CBattleHero.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleHero.o `test -f './BattleInterface/CBattleHero.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleHero.cpp + +vcmiclient-CBattleHero.obj: ./BattleInterface/CBattleHero.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleHero.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleHero.Tpo -c -o vcmiclient-CBattleHero.obj `if test -f './BattleInterface/CBattleHero.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleHero.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleHero.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleHero.Tpo $(DEPDIR)/vcmiclient-CBattleHero.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleHero.cpp' object='vcmiclient-CBattleHero.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleHero.obj `if test -f './BattleInterface/CBattleHero.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleHero.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleHero.cpp'; fi` + +vcmiclient-CBattleInterface.o: ./BattleInterface/CBattleInterface.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleInterface.o -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleInterface.Tpo -c -o vcmiclient-CBattleInterface.o `test -f './BattleInterface/CBattleInterface.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleInterface.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleInterface.Tpo $(DEPDIR)/vcmiclient-CBattleInterface.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleInterface.cpp' object='vcmiclient-CBattleInterface.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleInterface.o `test -f './BattleInterface/CBattleInterface.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleInterface.cpp + +vcmiclient-CBattleInterface.obj: ./BattleInterface/CBattleInterface.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleInterface.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleInterface.Tpo -c -o vcmiclient-CBattleInterface.obj `if test -f './BattleInterface/CBattleInterface.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleInterface.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleInterface.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleInterface.Tpo $(DEPDIR)/vcmiclient-CBattleInterface.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleInterface.cpp' object='vcmiclient-CBattleInterface.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleInterface.obj `if test -f './BattleInterface/CBattleInterface.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleInterface.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleInterface.cpp'; fi` + +vcmiclient-CBattleOptionsWindow.o: ./BattleInterface/CBattleOptionsWindow.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleOptionsWindow.o -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleOptionsWindow.Tpo -c -o vcmiclient-CBattleOptionsWindow.o `test -f './BattleInterface/CBattleOptionsWindow.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleOptionsWindow.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleOptionsWindow.Tpo $(DEPDIR)/vcmiclient-CBattleOptionsWindow.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleOptionsWindow.cpp' object='vcmiclient-CBattleOptionsWindow.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleOptionsWindow.o `test -f './BattleInterface/CBattleOptionsWindow.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleOptionsWindow.cpp + +vcmiclient-CBattleOptionsWindow.obj: ./BattleInterface/CBattleOptionsWindow.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleOptionsWindow.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleOptionsWindow.Tpo -c -o vcmiclient-CBattleOptionsWindow.obj `if test -f './BattleInterface/CBattleOptionsWindow.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleOptionsWindow.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleOptionsWindow.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleOptionsWindow.Tpo $(DEPDIR)/vcmiclient-CBattleOptionsWindow.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleOptionsWindow.cpp' object='vcmiclient-CBattleOptionsWindow.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleOptionsWindow.obj `if test -f './BattleInterface/CBattleOptionsWindow.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleOptionsWindow.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleOptionsWindow.cpp'; fi` + +vcmiclient-CBattleResultWindow.o: ./BattleInterface/CBattleResultWindow.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleResultWindow.o -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleResultWindow.Tpo -c -o vcmiclient-CBattleResultWindow.o `test -f './BattleInterface/CBattleResultWindow.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleResultWindow.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleResultWindow.Tpo $(DEPDIR)/vcmiclient-CBattleResultWindow.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleResultWindow.cpp' object='vcmiclient-CBattleResultWindow.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleResultWindow.o `test -f './BattleInterface/CBattleResultWindow.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleResultWindow.cpp + +vcmiclient-CBattleResultWindow.obj: ./BattleInterface/CBattleResultWindow.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleResultWindow.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleResultWindow.Tpo -c -o vcmiclient-CBattleResultWindow.obj `if test -f './BattleInterface/CBattleResultWindow.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleResultWindow.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleResultWindow.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleResultWindow.Tpo $(DEPDIR)/vcmiclient-CBattleResultWindow.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleResultWindow.cpp' object='vcmiclient-CBattleResultWindow.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleResultWindow.obj `if test -f './BattleInterface/CBattleResultWindow.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleResultWindow.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleResultWindow.cpp'; fi` + +vcmiclient-CBattleStackAnimation.o: ./BattleInterface/CBattleStackAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleStackAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleStackAnimation.Tpo -c -o vcmiclient-CBattleStackAnimation.o `test -f './BattleInterface/CBattleStackAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleStackAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleStackAnimation.Tpo $(DEPDIR)/vcmiclient-CBattleStackAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleStackAnimation.cpp' object='vcmiclient-CBattleStackAnimation.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleStackAnimation.o `test -f './BattleInterface/CBattleStackAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CBattleStackAnimation.cpp + +vcmiclient-CBattleStackAnimation.obj: ./BattleInterface/CBattleStackAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleStackAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleStackAnimation.Tpo -c -o vcmiclient-CBattleStackAnimation.obj `if test -f './BattleInterface/CBattleStackAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleStackAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleStackAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleStackAnimation.Tpo $(DEPDIR)/vcmiclient-CBattleStackAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CBattleStackAnimation.cpp' object='vcmiclient-CBattleStackAnimation.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleStackAnimation.obj `if test -f './BattleInterface/CBattleStackAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CBattleStackAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CBattleStackAnimation.cpp'; fi` + +vcmiclient-CDefenceAnimation.o: ./BattleInterface/CDefenceAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CDefenceAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CDefenceAnimation.Tpo -c -o vcmiclient-CDefenceAnimation.o `test -f './BattleInterface/CDefenceAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CDefenceAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CDefenceAnimation.Tpo $(DEPDIR)/vcmiclient-CDefenceAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CDefenceAnimation.cpp' object='vcmiclient-CDefenceAnimation.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CDefenceAnimation.o `test -f './BattleInterface/CDefenceAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CDefenceAnimation.cpp + +vcmiclient-CDefenceAnimation.obj: ./BattleInterface/CDefenceAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CDefenceAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CDefenceAnimation.Tpo -c -o vcmiclient-CDefenceAnimation.obj `if test -f './BattleInterface/CDefenceAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CDefenceAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CDefenceAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CDefenceAnimation.Tpo $(DEPDIR)/vcmiclient-CDefenceAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CDefenceAnimation.cpp' object='vcmiclient-CDefenceAnimation.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CDefenceAnimation.obj `if test -f './BattleInterface/CDefenceAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CDefenceAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CDefenceAnimation.cpp'; fi` + +vcmiclient-CDummyAnimation.o: ./BattleInterface/CDummyAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CDummyAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CDummyAnimation.Tpo -c -o vcmiclient-CDummyAnimation.o `test -f './BattleInterface/CDummyAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CDummyAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CDummyAnimation.Tpo $(DEPDIR)/vcmiclient-CDummyAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CDummyAnimation.cpp' object='vcmiclient-CDummyAnimation.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CDummyAnimation.o `test -f './BattleInterface/CDummyAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CDummyAnimation.cpp + +vcmiclient-CDummyAnimation.obj: ./BattleInterface/CDummyAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CDummyAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CDummyAnimation.Tpo -c -o vcmiclient-CDummyAnimation.obj `if test -f './BattleInterface/CDummyAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CDummyAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CDummyAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CDummyAnimation.Tpo $(DEPDIR)/vcmiclient-CDummyAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CDummyAnimation.cpp' object='vcmiclient-CDummyAnimation.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CDummyAnimation.obj `if test -f './BattleInterface/CDummyAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CDummyAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CDummyAnimation.cpp'; fi` + +vcmiclient-CHexFieldControl.o: ./BattleInterface/CHexFieldControl.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CHexFieldControl.o -MD -MP -MF $(DEPDIR)/vcmiclient-CHexFieldControl.Tpo -c -o vcmiclient-CHexFieldControl.o `test -f './BattleInterface/CHexFieldControl.cpp' || echo '$(srcdir)/'`./BattleInterface/CHexFieldControl.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CHexFieldControl.Tpo $(DEPDIR)/vcmiclient-CHexFieldControl.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CHexFieldControl.cpp' object='vcmiclient-CHexFieldControl.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CHexFieldControl.o `test -f './BattleInterface/CHexFieldControl.cpp' || echo '$(srcdir)/'`./BattleInterface/CHexFieldControl.cpp + +vcmiclient-CHexFieldControl.obj: ./BattleInterface/CHexFieldControl.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CHexFieldControl.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CHexFieldControl.Tpo -c -o vcmiclient-CHexFieldControl.obj `if test -f './BattleInterface/CHexFieldControl.cpp'; then $(CYGPATH_W) './BattleInterface/CHexFieldControl.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CHexFieldControl.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CHexFieldControl.Tpo $(DEPDIR)/vcmiclient-CHexFieldControl.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CHexFieldControl.cpp' object='vcmiclient-CHexFieldControl.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CHexFieldControl.obj `if test -f './BattleInterface/CHexFieldControl.cpp'; then $(CYGPATH_W) './BattleInterface/CHexFieldControl.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CHexFieldControl.cpp'; fi` + +vcmiclient-CMeleeAttackAnimation.o: ./BattleInterface/CMeleeAttackAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CMeleeAttackAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CMeleeAttackAnimation.Tpo -c -o vcmiclient-CMeleeAttackAnimation.o `test -f './BattleInterface/CMeleeAttackAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CMeleeAttackAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CMeleeAttackAnimation.Tpo $(DEPDIR)/vcmiclient-CMeleeAttackAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CMeleeAttackAnimation.cpp' object='vcmiclient-CMeleeAttackAnimation.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CMeleeAttackAnimation.o `test -f './BattleInterface/CMeleeAttackAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CMeleeAttackAnimation.cpp + +vcmiclient-CMeleeAttackAnimation.obj: ./BattleInterface/CMeleeAttackAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CMeleeAttackAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CMeleeAttackAnimation.Tpo -c -o vcmiclient-CMeleeAttackAnimation.obj `if test -f './BattleInterface/CMeleeAttackAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CMeleeAttackAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CMeleeAttackAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CMeleeAttackAnimation.Tpo $(DEPDIR)/vcmiclient-CMeleeAttackAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CMeleeAttackAnimation.cpp' object='vcmiclient-CMeleeAttackAnimation.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CMeleeAttackAnimation.obj `if test -f './BattleInterface/CMeleeAttackAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CMeleeAttackAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CMeleeAttackAnimation.cpp'; fi` + +vcmiclient-CMovementAnimation.o: ./BattleInterface/CMovementAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CMovementAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CMovementAnimation.Tpo -c -o vcmiclient-CMovementAnimation.o `test -f './BattleInterface/CMovementAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CMovementAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CMovementAnimation.Tpo $(DEPDIR)/vcmiclient-CMovementAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CMovementAnimation.cpp' object='vcmiclient-CMovementAnimation.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CMovementAnimation.o `test -f './BattleInterface/CMovementAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CMovementAnimation.cpp + +vcmiclient-CMovementAnimation.obj: ./BattleInterface/CMovementAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CMovementAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CMovementAnimation.Tpo -c -o vcmiclient-CMovementAnimation.obj `if test -f './BattleInterface/CMovementAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CMovementAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CMovementAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CMovementAnimation.Tpo $(DEPDIR)/vcmiclient-CMovementAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CMovementAnimation.cpp' object='vcmiclient-CMovementAnimation.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CMovementAnimation.obj `if test -f './BattleInterface/CMovementAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CMovementAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CMovementAnimation.cpp'; fi` + +vcmiclient-CMovementEndAnimation.o: ./BattleInterface/CMovementEndAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CMovementEndAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CMovementEndAnimation.Tpo -c -o vcmiclient-CMovementEndAnimation.o `test -f './BattleInterface/CMovementEndAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CMovementEndAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CMovementEndAnimation.Tpo $(DEPDIR)/vcmiclient-CMovementEndAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CMovementEndAnimation.cpp' object='vcmiclient-CMovementEndAnimation.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CMovementEndAnimation.o `test -f './BattleInterface/CMovementEndAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CMovementEndAnimation.cpp + +vcmiclient-CMovementEndAnimation.obj: ./BattleInterface/CMovementEndAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CMovementEndAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CMovementEndAnimation.Tpo -c -o vcmiclient-CMovementEndAnimation.obj `if test -f './BattleInterface/CMovementEndAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CMovementEndAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CMovementEndAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CMovementEndAnimation.Tpo $(DEPDIR)/vcmiclient-CMovementEndAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CMovementEndAnimation.cpp' object='vcmiclient-CMovementEndAnimation.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CMovementEndAnimation.obj `if test -f './BattleInterface/CMovementEndAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CMovementEndAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CMovementEndAnimation.cpp'; fi` + +vcmiclient-CMovementStartAnimation.o: ./BattleInterface/CMovementStartAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CMovementStartAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CMovementStartAnimation.Tpo -c -o vcmiclient-CMovementStartAnimation.o `test -f './BattleInterface/CMovementStartAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CMovementStartAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CMovementStartAnimation.Tpo $(DEPDIR)/vcmiclient-CMovementStartAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CMovementStartAnimation.cpp' object='vcmiclient-CMovementStartAnimation.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CMovementStartAnimation.o `test -f './BattleInterface/CMovementStartAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CMovementStartAnimation.cpp + +vcmiclient-CMovementStartAnimation.obj: ./BattleInterface/CMovementStartAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CMovementStartAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CMovementStartAnimation.Tpo -c -o vcmiclient-CMovementStartAnimation.obj `if test -f './BattleInterface/CMovementStartAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CMovementStartAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CMovementStartAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CMovementStartAnimation.Tpo $(DEPDIR)/vcmiclient-CMovementStartAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CMovementStartAnimation.cpp' object='vcmiclient-CMovementStartAnimation.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CMovementStartAnimation.obj `if test -f './BattleInterface/CMovementStartAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CMovementStartAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CMovementStartAnimation.cpp'; fi` + +vcmiclient-CReverseAnimation.o: ./BattleInterface/CReverseAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CReverseAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CReverseAnimation.Tpo -c -o vcmiclient-CReverseAnimation.o `test -f './BattleInterface/CReverseAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CReverseAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CReverseAnimation.Tpo $(DEPDIR)/vcmiclient-CReverseAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CReverseAnimation.cpp' object='vcmiclient-CReverseAnimation.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CReverseAnimation.o `test -f './BattleInterface/CReverseAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CReverseAnimation.cpp + +vcmiclient-CReverseAnimation.obj: ./BattleInterface/CReverseAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CReverseAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CReverseAnimation.Tpo -c -o vcmiclient-CReverseAnimation.obj `if test -f './BattleInterface/CReverseAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CReverseAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CReverseAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CReverseAnimation.Tpo $(DEPDIR)/vcmiclient-CReverseAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CReverseAnimation.cpp' object='vcmiclient-CReverseAnimation.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CReverseAnimation.obj `if test -f './BattleInterface/CReverseAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CReverseAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CReverseAnimation.cpp'; fi` + +vcmiclient-CShootingAnimation.o: ./BattleInterface/CShootingAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CShootingAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CShootingAnimation.Tpo -c -o vcmiclient-CShootingAnimation.o `test -f './BattleInterface/CShootingAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CShootingAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CShootingAnimation.Tpo $(DEPDIR)/vcmiclient-CShootingAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CShootingAnimation.cpp' object='vcmiclient-CShootingAnimation.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CShootingAnimation.o `test -f './BattleInterface/CShootingAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CShootingAnimation.cpp + +vcmiclient-CShootingAnimation.obj: ./BattleInterface/CShootingAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CShootingAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CShootingAnimation.Tpo -c -o vcmiclient-CShootingAnimation.obj `if test -f './BattleInterface/CShootingAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CShootingAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CShootingAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CShootingAnimation.Tpo $(DEPDIR)/vcmiclient-CShootingAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CShootingAnimation.cpp' object='vcmiclient-CShootingAnimation.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CShootingAnimation.obj `if test -f './BattleInterface/CShootingAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CShootingAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CShootingAnimation.cpp'; fi` + +vcmiclient-CSpellEffectAnimation.o: ./BattleInterface/CSpellEffectAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CSpellEffectAnimation.o -MD -MP -MF $(DEPDIR)/vcmiclient-CSpellEffectAnimation.Tpo -c -o vcmiclient-CSpellEffectAnimation.o `test -f './BattleInterface/CSpellEffectAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CSpellEffectAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CSpellEffectAnimation.Tpo $(DEPDIR)/vcmiclient-CSpellEffectAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CSpellEffectAnimation.cpp' object='vcmiclient-CSpellEffectAnimation.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CSpellEffectAnimation.o `test -f './BattleInterface/CSpellEffectAnimation.cpp' || echo '$(srcdir)/'`./BattleInterface/CSpellEffectAnimation.cpp + +vcmiclient-CSpellEffectAnimation.obj: ./BattleInterface/CSpellEffectAnimation.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CSpellEffectAnimation.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CSpellEffectAnimation.Tpo -c -o vcmiclient-CSpellEffectAnimation.obj `if test -f './BattleInterface/CSpellEffectAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CSpellEffectAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CSpellEffectAnimation.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CSpellEffectAnimation.Tpo $(DEPDIR)/vcmiclient-CSpellEffectAnimation.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CSpellEffectAnimation.cpp' object='vcmiclient-CSpellEffectAnimation.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CSpellEffectAnimation.obj `if test -f './BattleInterface/CSpellEffectAnimation.cpp'; then $(CYGPATH_W) './BattleInterface/CSpellEffectAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CSpellEffectAnimation.cpp'; fi` + +vcmiclient-CStackQueue.o: ./BattleInterface/CStackQueue.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CStackQueue.o -MD -MP -MF $(DEPDIR)/vcmiclient-CStackQueue.Tpo -c -o vcmiclient-CStackQueue.o `test -f './BattleInterface/CStackQueue.cpp' || echo '$(srcdir)/'`./BattleInterface/CStackQueue.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CStackQueue.Tpo $(DEPDIR)/vcmiclient-CStackQueue.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CStackQueue.cpp' object='vcmiclient-CStackQueue.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CStackQueue.o `test -f './BattleInterface/CStackQueue.cpp' || echo '$(srcdir)/'`./BattleInterface/CStackQueue.cpp + +vcmiclient-CStackQueue.obj: ./BattleInterface/CStackQueue.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CStackQueue.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CStackQueue.Tpo -c -o vcmiclient-CStackQueue.obj `if test -f './BattleInterface/CStackQueue.cpp'; then $(CYGPATH_W) './BattleInterface/CStackQueue.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CStackQueue.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CStackQueue.Tpo $(DEPDIR)/vcmiclient-CStackQueue.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='./BattleInterface/CStackQueue.cpp' object='vcmiclient-CStackQueue.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CStackQueue.obj `if test -f './BattleInterface/CStackQueue.cpp'; then $(CYGPATH_W) './BattleInterface/CStackQueue.cpp'; else $(CYGPATH_W) '$(srcdir)/./BattleInterface/CStackQueue.cpp'; fi` vcmiclient-AdventureMapButton.o: AdventureMapButton.cpp @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-AdventureMapButton.o -MD -MP -MF $(DEPDIR)/vcmiclient-AdventureMapButton.Tpo -c -o vcmiclient-AdventureMapButton.o `test -f 'AdventureMapButton.cpp' || echo '$(srcdir)/'`AdventureMapButton.cpp @@ -590,22 +929,6 @@ vcmiclient-CAnimation.obj: CAnimation.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CAnimation.obj `if test -f 'CAnimation.cpp'; then $(CYGPATH_W) 'CAnimation.cpp'; else $(CYGPATH_W) '$(srcdir)/CAnimation.cpp'; fi` -vcmiclient-CBattleInterface.o: CBattleInterface.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleInterface.o -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleInterface.Tpo -c -o vcmiclient-CBattleInterface.o `test -f 'CBattleInterface.cpp' || echo '$(srcdir)/'`CBattleInterface.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleInterface.Tpo $(DEPDIR)/vcmiclient-CBattleInterface.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='CBattleInterface.cpp' object='vcmiclient-CBattleInterface.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleInterface.o `test -f 'CBattleInterface.cpp' || echo '$(srcdir)/'`CBattleInterface.cpp - -vcmiclient-CBattleInterface.obj: CBattleInterface.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBattleInterface.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CBattleInterface.Tpo -c -o vcmiclient-CBattleInterface.obj `if test -f 'CBattleInterface.cpp'; then $(CYGPATH_W) 'CBattleInterface.cpp'; else $(CYGPATH_W) '$(srcdir)/CBattleInterface.cpp'; fi` -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBattleInterface.Tpo $(DEPDIR)/vcmiclient-CBattleInterface.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='CBattleInterface.cpp' object='vcmiclient-CBattleInterface.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CBattleInterface.obj `if test -f 'CBattleInterface.cpp'; then $(CYGPATH_W) 'CBattleInterface.cpp'; else $(CYGPATH_W) '$(srcdir)/CBattleInterface.cpp'; fi` - vcmiclient-CBitmapHandler.o: CBitmapHandler.cpp @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CBitmapHandler.o -MD -MP -MF $(DEPDIR)/vcmiclient-CBitmapHandler.Tpo -c -o vcmiclient-CBitmapHandler.o `test -f 'CBitmapHandler.cpp' || echo '$(srcdir)/'`CBitmapHandler.cpp @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CBitmapHandler.Tpo $(DEPDIR)/vcmiclient-CBitmapHandler.Po @@ -1111,13 +1434,15 @@ distdir: $(DISTFILES) fi; \ done check-am: all-am -check: check-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am all-am: Makefile $(PROGRAMS) installdirs: for dir in "$(DESTDIR)$(bindir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-am +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -1142,6 +1467,7 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am @@ -1212,7 +1538,7 @@ ps-am: uninstall-am: uninstall-binPROGRAMS -.MAKE: install-am install-strip +.MAKE: all check install install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ clean-generic clean-libtool ctags distclean distclean-compile \ @@ -1228,6 +1554,8 @@ uninstall-am: uninstall-binPROGRAMS pdf pdf-am ps ps-am tags uninstall uninstall-am \ uninstall-binPROGRAMS +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -c $< # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index 401d7b70b..e8f271f8b 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -1,4 +1,6 @@ +#include "StdInc.h" #include "../lib/NetPacks.h" + #include "../CCallback.h" #include "Client.h" #include "CPlayerInterface.h" @@ -15,16 +17,13 @@ #include "CSoundBase.h" #include "mapHandler.h" #include "GUIClasses.h" -#include -#include -#include -#include #include "CConfigHandler.h" #include "SDL_Extensions.h" -#include "CBattleInterface.h" +#include "BattleInterface/CBattleInterface.h" #include "../lib/CCampaignHandler.h" #include "../lib/CGameState.h" #include "../lib/BattleState.h" +#include "../lib/GameConstants.h" //macros to avoid code duplication - calls given method with given arguments if interface for specific player is present @@ -337,7 +336,7 @@ void TryMoveHero::applyFirstCl( CClient *cl ) //check if playerint will have the knowledge about movement - if not, directly update maphandler for(std::map::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++) { - if(i->first >= PLAYER_LIMIT) + if(i->first >= GameConstants::PLAYER_LIMIT) continue; TeamState *t = GS(cl)->getPlayerTeam(i->first); if((t->fogOfWarMap[start.x-1][start.y][start.z] || t->fogOfWarMap[end.x-1][end.y][end.z]) @@ -376,7 +375,7 @@ void TryMoveHero::applyCl( CClient *cl ) //notify interfaces about move for(std::map::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++) { - if(i->first >= PLAYER_LIMIT) continue; + if(i->first >= GameConstants::PLAYER_LIMIT) continue; TeamState *t = GS(cl)->getPlayerTeam(i->first); if(t->fogOfWarMap[start.x-1][start.y][start.z] || t->fogOfWarMap[end.x-1][end.y][end.z]) { diff --git a/client/SDL_Extensions.cpp b/client/SDL_Extensions.cpp index fd37bd1c8..b44885291 100644 --- a/client/SDL_Extensions.cpp +++ b/client/SDL_Extensions.cpp @@ -1,14 +1,10 @@ -#include "../stdafx.h" +#include "StdInc.h" #include "SDL_Extensions.h" + #include "SDL_ttf.h" #include "CGameInfo.h" -#include -#include -#include #include "CMessage.h" -#include #include "CDefHandler.h" -#include #include "Graphics.h" #include "GUIBase.h" @@ -323,7 +319,7 @@ void CSDL_Ext::printAtMiddleWB( const std::string & text, int x, int y, EFonts f } } -void printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality=2) +void printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, ui8 quality=2) { if(text.length()==0) return; SDL_Surface * temp; @@ -366,7 +362,7 @@ void CSDL_Ext::printAtMiddle( const std::string & text, int x, int y, EFonts fon printAt(text, nx, ny, font, kolor, dst); } -void printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality=2, bool refresh=false) +void printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, ui8 quality=2, bool refresh=false) { if (text.length()==0) return; @@ -431,7 +427,7 @@ void CSDL_Ext::printAt( const std::string & text, int x, int y, EFonts font, SDL for(int txti = first; txti < beyondEnd; txti++) { - const unsigned char c = text[txti]; + const ui8 c = text[txti]; x += f->chars[c].unknown1; for(int i = std::max(0, -y); i < f->height && (y + i) < (dst->h - 1); i++) @@ -462,7 +458,7 @@ void CSDL_Ext::printAt( const std::string & text, int x, int y, EFonts font, SDL } } -void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality=2) +void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, ui8 quality=2) { if (text.length()==0) return; @@ -504,7 +500,7 @@ void CSDL_Ext::printTo( const std::string & text, int x, int y, EFonts font, SDL printAt(text, x - f->getWidth(text.c_str()), y - f->height, font, kolor, dst); } -void printToWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality=2) +void printToWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, ui8 quality=2) { if (text.length()==0) return; @@ -1049,7 +1045,7 @@ void CSDL_Ext::drawDashedBorder(SDL_Surface * sur, const Rect &r, const int3 &co } } -void CSDL_Ext::setPlayerColor(SDL_Surface * sur, unsigned char player) +void CSDL_Ext::setPlayerColor(SDL_Surface * sur, ui8 player) { if(player==254) return; @@ -1206,7 +1202,7 @@ void CSDL_Ext::applyEffect( SDL_Surface * surf, const SDL_Rect * rect, int mode { for(int yp = rect->y; yp < rect->y + rect->h; ++yp) { - unsigned char * pixels = (unsigned char*)surf->pixels + yp * surf->pitch + xp * surf->format->BytesPerPixel; + ui8 * pixels = (ui8*)surf->pixels + yp * surf->pitch + xp * surf->format->BytesPerPixel; int b = pixels[0]; int g = pixels[1]; @@ -1242,7 +1238,7 @@ void CSDL_Ext::applyEffect( SDL_Surface * surf, const SDL_Rect * rect, int mode { for(int yp = rect->y; yp < rect->y + rect->h; ++yp) { - unsigned char * pixels = (unsigned char*)surf->pixels + yp * surf->pitch + xp * surf->format->BytesPerPixel; + ui8 * pixels = (ui8*)surf->pixels + yp * surf->pitch + xp * surf->format->BytesPerPixel; int b = pixels[0]; int g = pixels[1]; diff --git a/client/SDL_Extensions.h b/client/SDL_Extensions.h index e666f9bee..466e0492f 100644 --- a/client/SDL_Extensions.h +++ b/client/SDL_Extensions.h @@ -1,11 +1,9 @@ -#ifndef __SDL_EXTENSIONS_H__ -#define __SDL_EXTENSIONS_H__ -#include "../global.h" +#pragma once + + +#include "../lib/int3.h" #include "SDL_video.h" #include "SDL_ttf.h" -#include -#include -#include #include "FontBase.h" /* @@ -61,7 +59,7 @@ std::string makeNumberShort(IntType number) //the output is a string containing return ost.str(); } - //make the number short + //make the number int char symbol[] = {'G', 'M', 'k'}; if(negative) number = (-number); //absolute value @@ -173,13 +171,10 @@ namespace CSDL_Ext void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color); void drawBorder(SDL_Surface * sur, const SDL_Rect &r, const int3 &color); void drawDashedBorder(SDL_Surface * sur, const Rect &r, const int3 &color); - void setPlayerColor(SDL_Surface * sur, unsigned char player); //sets correct color of flags; -1 for neutral + void setPlayerColor(SDL_Surface * sur, ui8 player); //sets correct color of flags; -1 for neutral std::string processStr(std::string str, std::vector & tor); //replaces %s in string SDL_Surface * newSurface(int w, int h, SDL_Surface * mod=screen); //creates new surface, with flags/format same as in surface given SDL_Surface * copySurface(SDL_Surface * mod); //returns copy of given surface void VflipSurf(SDL_Surface * surf); //fluipis given surface by vertical axis void applyEffect(SDL_Surface * surf, const SDL_Rect * rect, int mode); //mode: 0 - sepia, 1 - grayscale }; - - -#endif // __SDL_EXTENSIONS_H__ diff --git a/client/SDL_framerate.cpp b/client/SDL_framerate.cpp index d76b38776..bc25129f0 100644 --- a/client/SDL_framerate.cpp +++ b/client/SDL_framerate.cpp @@ -1,41 +1,31 @@ - -/* - * SDL_framerate.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -#include "../stdafx.h" -#include "SDL_framerate.h" -#include - - -FPSManager::FPSManager(int rate) -{ - this->rate = rate; - this->rateticks = (1000.0 / (double) rate); - this->fps = 0; -} - -void FPSManager::init() -{ - this->lastticks = SDL_GetTicks(); -} - -void FPSManager::framerateDelay() -{ - Uint32 currentTicks = SDL_GetTicks(); - double diff = currentTicks - this->lastticks; - - if (diff < this->rateticks) // FPS is higher than it should be, then wait some time - { - SDL_Delay(ceil(this->rateticks) - diff); - } - - this->fps = ceil(1000. / (SDL_GetTicks() - this->lastticks)); - this->lastticks = SDL_GetTicks(); -} +#include "StdInc.h" +#include "SDL_framerate.h" + +#include + + +FPSManager::FPSManager(int rate) +{ + this->rate = rate; + this->rateticks = (1000.0 / (double) rate); + this->fps = 0; +} + +void FPSManager::init() +{ + this->lastticks = SDL_GetTicks(); +} + +void FPSManager::framerateDelay() +{ + Uint32 currentTicks = SDL_GetTicks(); + double diff = currentTicks - this->lastticks; + + if (diff < this->rateticks) // FPS is higher than it should be, then wait some time + { + SDL_Delay(ceil(this->rateticks) - diff); + } + + this->fps = ceil(1000. / (SDL_GetTicks() - this->lastticks)); + this->lastticks = SDL_GetTicks(); +} diff --git a/client/SDL_framerate.h b/client/SDL_framerate.h index 17218f586..1f9087d0b 100644 --- a/client/SDL_framerate.h +++ b/client/SDL_framerate.h @@ -1,33 +1,28 @@ - +#pragma once + /* - * timeHandler.h, part of VCMI engine + * SDL_framerate.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -#ifndef _SDL_framerate_h -#define _SDL_framerate_h - - -/// A fps manager which holds game updates at a constant rate -class FPSManager -{ -private: - double rateticks; - unsigned int lastticks; - int rate; - -public: - int fps; // the actual fps value - - FPSManager(int rate); // initializes the manager with a given fps rate - void init(); // needs to be called directly before the main game loop to reset the internal timer - void framerateDelay(); // needs to be called every game update cycle -}; - - -#endif + */ + + +/// A fps manager which holds game updates at a constant rate +class FPSManager +{ +private: + double rateticks; + ui32 lastticks; + int rate; + +public: + int fps; // the actual fps value + + FPSManager(int rate); // initializes the manager with a given fps rate + void init(); // needs to be called directly before the main game loop to reset the internal timer + void framerateDelay(); // needs to be called every game update cycle +}; diff --git a/client/VCMI_client.vcxproj b/client/VCMI_client.vcxproj index 2b7cdbafd..8c6dc0515 100644 --- a/client/VCMI_client.vcxproj +++ b/client/VCMI_client.vcxproj @@ -83,9 +83,9 @@ - D:\Program Files\boost\boost_1_46_1;$(IncludePath) + $(IncludePath) $(IncludePath) - D:\Program Files\boost\boost_1_46_1\stage\lib;$(LibraryPath) + $(LibraryPath) $(LibraryPath) C:\C++\boost_1_42_0;$(IncludePath) C:\C++\boost_1_42_0;$(IncludePath) @@ -102,10 +102,12 @@ false EnableFastChecks MultiThreadedDebugDLL - Level1 + Level3 EditAndContinue 4251;%(DisableSpecificWarnings) NoListing + Use + StdInc.h SDL.lib;zlib.lib;SDL_image.lib;SDL_ttf.lib;SDL_mixer.lib;VCMI_lib.lib;%(AdditionalDependencies) @@ -221,11 +223,29 @@ false false + + + + + + + + + + + + + + + + + + + - - + @@ -251,13 +271,35 @@ + + Create + StdInc.h + - + + + + + + + + + + + + + + + + + + + + - @@ -281,18 +323,14 @@ - - - - - + diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index caf1f6b41..3b96ddad6 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -1,23 +1,20 @@ -#include "../stdafx.h" +#include "StdInc.h" #include "mapHandler.h" + #include "SDL_Extensions.h" #include "CGameInfo.h" -#include #include "../lib/CLodHandler.h" #include "../lib/CDefObjInfoHandler.h" -#include #include "../lib/CGameState.h" #include "../lib/CHeroHandler.h" #include "../lib/CTownHandler.h" #include "Graphics.h" -#include -#include #include "../lib/CObjectHandler.h" #include "../lib/map.h" #include "CDefHandler.h" #include "CConfigHandler.h" -#include #include "../lib/CGeneralTextHandler.h" +#include "../lib/GameConstants.h" /* * mapHandler.cpp, part of VCMI engine @@ -29,6 +26,9 @@ * */ +const bool MARK_BLOCKED_POSITIONS = false; +const bool MARK_VISITABLE_POSITIONS = false; + extern SDL_Surface * screen; #define ADVOPT (conf.go()->ac) @@ -110,23 +110,23 @@ void CMapHandler::prepareFOWDefs() //necessaary rotations added //alpha - transformation - for(size_t i=0; iFoWpartialHide->ourImages.size(); ++i) + for(size_t i = 0; i < graphics->FoWpartialHide->ourImages.size(); ++i) { CSDL_Ext::alphaTransform(graphics->FoWpartialHide->ourImages[i].bitmap); } //initialization of type of full-hide image hideBitmap.resize(sizes.x); - for (size_t i=0;iFoWfullHide->ourImages.size(); } @@ -247,7 +247,7 @@ void CMapHandler::initObjectRects() { const CGObjectInstance *obj = map->objects[f]; if( !obj - || (obj->ID==HEROI_TYPE && static_cast(obj)->inTownGarrison) //garrisoned hero + || (obj->ID==GameConstants::HEROI_TYPE && static_cast(obj)->inTownGarrison) //garrisoned hero || (obj->ID==8 && static_cast(obj)->hero) //boat with hero (hero graphics is used) || !obj->defInfo || !graphics->getDef(obj)) //no graphic... @@ -296,7 +296,7 @@ void CMapHandler::initObjectRects() } static void processDef (const CGDefInfo* def) { - if(def->id == EVENTI_TYPE) + if(def->id == GameConstants::EVENTI_TYPE) { graphics->advmapobjGraphics[def->id][def->subid][def->name] = NULL; return; @@ -335,8 +335,8 @@ void CMapHandler::initHeroDef(const CGHeroInstance * h) } void CMapHandler::init() { - timeHandler th; - th.getDif(); + StopWatch th; + th.getDiff(); graphics->advmapobjGraphics[8][0]["AB01_.DEF"] = graphics->boatAnims[0]; graphics->advmapobjGraphics[8][1]["AB02_.DEF"] = graphics->boatAnims[1]; @@ -379,7 +379,7 @@ void CMapHandler::init() } std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs - tlog0<<"\tUnpacking and handling defs: "< > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode, int3 grailPosRel ) const +void CMapHandler::terrainRect( int3 top_tile, ui8 anim, const std::vector< std::vector< std::vector > > * visibilityMap, bool otherHeroAnim, ui8 heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode, int3 grailPosRel ) const { // Width and height of the portion of the map to process. Units in tiles. - unsigned int dx = tilesW; - unsigned int dy = tilesH; + ui32 dx = tilesW; + ui32 dy = tilesH; // Basic rectangle for a tile. Should be a const but conflicts with SDL headers SDL_Rect rtile = { 0, 0, 32, 32 }; @@ -518,7 +518,7 @@ void CMapHandler::terrainRect( int3 top_tile, unsigned char anim, const std::vec ui8 color = obj->tempOwner; //checking if object has non-empty graphic on this tile - if(obj->ID != HEROI_TYPE && !obj->coveringAt(obj->pos.x - (top_tile.x + bx), top_tile.y + by - obj->pos.y + 5)) + if(obj->ID != GameConstants::HEROI_TYPE && !obj->coveringAt(obj->pos.x - (top_tile.x + bx), top_tile.y + by - obj->pos.y + 5)) continue; static const int notBlittedInPuzzleMode[] = {124}; @@ -533,7 +533,7 @@ void CMapHandler::terrainRect( int3 top_tile, unsigned char anim, const std::vec pp.h = sr.h; pp.w = sr.w; - const CGHeroInstance * themp = (obj->ID != HEROI_TYPE + const CGHeroInstance * themp = (obj->ID != GameConstants::HEROI_TYPE ? NULL : static_cast(obj)); @@ -780,7 +780,7 @@ void CMapHandler::terrainRect( int3 top_tile, unsigned char anim, const std::vec SDL_SetClipRect(extSurf, &prevClip); //restoring clip_rect } -std::pair CMapHandler::getVisBitmap( const int3 & pos, const std::vector< std::vector< std::vector > > & visibilityMap ) const +std::pair CMapHandler::getVisBitmap( const int3 & pos, const std::vector< std::vector< std::vector > > & visibilityMap ) const { static const int visBitmaps[256] = {-1, 34, -1, 4, 22, 22, 4, 4, 36, 36, 38, 38, 47, 47, 38, 38, 3, 25, 12, 12, 3, 25, 12, 12, 9, 9, 6, 6, 9, 9, 6, 6, 35, 34, 4, 4, 22, 22, 4, 4, 36, 36, 38, 38, 47, 47, 38, 38, 26, 49, 28, 28, 26, 49, 28, @@ -894,16 +894,16 @@ bool CMapHandler::removeObject(CGObjectInstance *obj) return true; } -unsigned char CMapHandler::getHeroFrameNum(unsigned char dir, bool isMoving) const +ui8 CMapHandler::getHeroFrameNum(ui8 dir, bool isMoving) const { if(isMoving) { - static const unsigned char frame [] = {0xff, 10, 5, 6, 7, 8, 9, 12, 11}; + static const ui8 frame [] = {0xff, 10, 5, 6, 7, 8, 9, 12, 11}; return frame[dir]; } else //if(isMoving) { - static const unsigned char frame [] = {0xff, 13, 0, 1, 2, 3, 4, 15, 14}; + static const ui8 frame [] = {0xff, 13, 0, 1, 2, 3, 4, 15, 14}; return frame[dir]; } } @@ -948,7 +948,7 @@ void CMapHandler::validateRectTerr(SDL_Rect * val, const SDL_Rect * ext) } } -unsigned char CMapHandler::getDir(const int3 &a, const int3 &b) +ui8 CMapHandler::getDir(const int3 &a, const int3 &b) { if(a.z!=b.z) return -1; //error! diff --git a/client/mapHandler.h b/client/mapHandler.h index 6286a6187..d0e823495 100644 --- a/client/mapHandler.h +++ b/client/mapHandler.h @@ -1,8 +1,7 @@ -#ifndef __MAPHANDLER_H__ -#define __MAPHANDLER_H__ -#include "../global.h" -#include -#include +#pragma once + + +#include "../lib/int3.h" /* * mapHandler.h, part of VCMI engine @@ -97,12 +96,15 @@ public: std::vector roadDefs; std::vector staticRiverDefs; - std::vector > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile + std::vector > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile + + static const bool MARK_BLOCKED_POSITIONS; + static const bool MARK_VISITABLE_POSITIONS; CMapHandler(); //c-tor ~CMapHandler(); //d-tor - std::pair getVisBitmap(const int3 & pos, const std::vector< std::vector< std::vector > > & visibilityMap) const; //returns appropriate bitmap and info if alpha blitting is necessary + std::pair getVisBitmap(const int3 & pos, const std::vector< std::vector< std::vector > > & visibilityMap) const; //returns appropriate bitmap and info if alpha blitting is necessary std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position void getTerrainDescr(const int3 &pos, std::string & out, bool terName); //if tername == false => empty string when tile is clear @@ -118,13 +120,10 @@ public: void roadsRiverTerrainInit(); void prepareFOWDefs(); - void terrainRect(int3 top_tile, unsigned char anim, const std::vector< std::vector< std::vector > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode, int3 grailPosRel) const; + void terrainRect(int3 top_tile, ui8 anim, const std::vector< std::vector< std::vector > > * visibilityMap, bool otherHeroAnim, ui8 heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode, int3 grailPosRel) const; void updateWater(); - unsigned char getHeroFrameNum(unsigned char dir, bool isMoving) const; //terrainRect helper function + ui8 getHeroFrameNum(ui8 dir, bool isMoving) const; //terrainRect helper function void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper - static unsigned char getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b] + static ui8 getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b] }; - - -#endif // __MAPHANDLER_H__ diff --git a/configure b/configure index b8681b40c..ceeff50b2 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.67 for vcmi 0.84b. +# Generated by GNU Autoconf 2.66 for vcmi 0.84b. # # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -834,9 +834,8 @@ do fi case $ac_option in - *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; - *=) ac_optarg= ;; - *) ac_optarg=yes ;; + *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. @@ -1526,7 +1525,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF vcmi configure 0.84b -generated by GNU Autoconf 2.67 +generated by GNU Autoconf 2.66 Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation @@ -1713,7 +1712,7 @@ $as_echo "$ac_try_echo"; } >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } > conftest.i && { + test $ac_status = 0; } >/dev/null && { test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err }; then : @@ -1859,7 +1858,7 @@ $as_echo "$ac_try_echo"; } >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } > conftest.i && { + test $ac_status = 0; } >/dev/null && { test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || test ! -s conftest.err }; then : @@ -2010,7 +2009,7 @@ if ac_fn_cxx_try_cpp "$LINENO"; then : else ac_header_preproc=no fi -rm -f conftest.err conftest.i conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 $as_echo "$ac_header_preproc" >&6; } @@ -2121,7 +2120,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by vcmi $as_me 0.84b, which was -generated by GNU Autoconf 2.67. Invocation command line was +generated by GNU Autoconf 2.66. Invocation command line was $ $0 $@ @@ -2379,7 +2378,7 @@ $as_echo "$as_me: loading site script $ac_site_file" >&6;} || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi done @@ -2467,7 +2466,7 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu - # Follow NAME_VER in global.h + # Follow VCMI_VERSION in GameConstants.h am__api_version='1.11' ac_aux_dir= @@ -2603,11 +2602,11 @@ am_lf=' ' case `pwd` in *[\\\"\#\$\&\'\`$am_lf]*) - as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5 ;; + as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;; esac case $srcdir in *[\\\"\#\$\&\'\`$am_lf\ \ ]*) - as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5 ;; + as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5;; esac # Do `set' in a subshell so we don't clobber the current shell's @@ -3208,7 +3207,7 @@ sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C++ compiler cannot create executables -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } @@ -3251,7 +3250,7 @@ else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 @@ -3310,7 +3309,7 @@ $as_echo "$ac_try_echo"; } >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C++ compiled programs. If you meant to cross compile, use \`--host'. -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi fi fi @@ -3362,7 +3361,7 @@ sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi @@ -3789,7 +3788,7 @@ fi $as_echo "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; -*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5 ;; +*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; esac build=$ac_cv_build ac_save_IFS=$IFS; IFS='-' @@ -3822,7 +3821,7 @@ fi $as_echo "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; -*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5 ;; +*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; esac host=$ac_cv_host ac_save_IFS=$IFS; IFS='-' @@ -4208,7 +4207,7 @@ fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 @@ -7717,7 +7716,7 @@ else # Broken: fails on valid input. continue fi -rm -f conftest.err conftest.i conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. @@ -7733,11 +7732,11 @@ else ac_preproc_ok=: break fi -rm -f conftest.err conftest.i conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext if $ac_preproc_ok; then : break fi @@ -7776,7 +7775,7 @@ else # Broken: fails on valid input. continue fi -rm -f conftest.err conftest.i conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. @@ -7792,18 +7791,18 @@ else ac_preproc_ok=: break fi -rm -f conftest.err conftest.i conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext if $ac_preproc_ok; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi ac_ext=c @@ -11926,7 +11925,7 @@ else # Broken: fails on valid input. continue fi -rm -f conftest.err conftest.i conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. @@ -11942,11 +11941,11 @@ else ac_preproc_ok=: break fi -rm -f conftest.err conftest.i conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext if $ac_preproc_ok; then : break fi @@ -11985,7 +11984,7 @@ else # Broken: fails on valid input. continue fi -rm -f conftest.err conftest.i conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. @@ -12001,18 +12000,18 @@ else ac_preproc_ok=: break fi -rm -f conftest.err conftest.i conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext +rm -f conftest.err conftest.$ac_ext if $ac_preproc_ok; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C++ preprocessor \"$CXXCPP\" fails sanity check -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi ac_ext=cpp @@ -15179,7 +15178,7 @@ fi # For gcc and compatible compilers, enable compilation warnings, but # selectively disable some because too many are generated. if test "x$GXX" = "xyes" ; then - CXXFLAGS="$CXXFLAGS -Wall -Wno-switch -Wno-sign-compare -Wcast-align -Wpointer-arith -Wno-unknown-pragmas" + CXXFLAGS="$CXXFLAGS -ftime-report -Wall -Wno-switch -Wno-sign-compare -Wcast-align -Wpointer-arith -Wno-unknown-pragmas" fi # extra clang parameters @@ -17468,7 +17467,7 @@ fi done -CXXFLAGS="$CXXFLAGS -DDATA_DIR=\\\"\$(pkgdatadir)\\\" -DBIN_DIR=\\\"\$(bindir)\\\" -DLIB_DIR=\\\"\$(pkglibdir)\\\"" +CXXFLAGS="$CXXFLAGS -DM_DATA_DIR=\\\"\$(pkgdatadir)\\\" -DM_BIN_DIR=\\\"\$(bindir)\\\" -DM_LIB_DIR=\\\"\$(pkglibdir)\\\"" @@ -18046,7 +18045,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # values after options handling. ac_log=" This file was extended by vcmi $as_me 0.84b, which was -generated by GNU Autoconf 2.67. Invocation command line was +generated by GNU Autoconf 2.66. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -18103,7 +18102,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ vcmi config.status 0.84b -configured by $0, generated by GNU Autoconf 2.67, +configured by $0, generated by GNU Autoconf 2.66, with options \\"\$ac_cs_config\\" Copyright (C) 2010 Free Software Foundation, Inc. @@ -18124,16 +18123,11 @@ ac_need_defaults=: while test $# != 0 do case $1 in - --*=?*) + --*=*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; - --*=) - ac_option=`expr "X$1" : 'X\([^=]*\)='` - ac_optarg= - ac_shift=: - ;; *) ac_option=$1 ac_optarg=$2 @@ -18155,7 +18149,6 @@ do $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; - '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; @@ -18609,7 +18602,7 @@ do "AI/EmptyAI/Makefile") CONFIG_FILES="$CONFIG_FILES AI/EmptyAI/Makefile" ;; "Scripting/ERM/Makefile") CONFIG_FILES="$CONFIG_FILES Scripting/ERM/Makefile" ;; - *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5 ;; + *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac done @@ -18816,7 +18809,7 @@ do esac case $ac_mode$ac_tag in :[FHL]*:*);; - :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5 ;; + :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac @@ -18844,7 +18837,7 @@ do [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || - as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5 ;; + as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" @@ -18871,7 +18864,7 @@ $as_echo "$as_me: creating $ac_file" >&6;} case $ac_tag in *:-:* | *:-) cat >"$tmp/stdin" \ - || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac diff --git a/configure.ac b/configure.ac index 689f7b139..e71f71b26 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.60) -AC_INIT(vcmi, 0.84b) # Follow NAME_VER in global.h +AC_INIT(vcmi, 0.84b) # Follow VCMI_VERSION in GameConstants.h AM_INIT_AUTOMAKE AC_CONFIG_MACRO_DIR([aclocal/m4]) @@ -32,7 +32,7 @@ fi # For gcc and compatible compilers, enable compilation warnings, but # selectively disable some because too many are generated. if test "x$GXX" = "xyes" ; then - CXXFLAGS="$CXXFLAGS -Wall -Wno-switch -Wno-sign-compare -Wcast-align -Wpointer-arith -Wno-unknown-pragmas" + CXXFLAGS="$CXXFLAGS -ftime-report -Wall -Wno-switch -Wno-sign-compare -Wcast-align -Wpointer-arith -Wno-unknown-pragmas" fi # extra clang parameters @@ -94,7 +94,7 @@ AC_CHECK_HEADERS([boost/filesystem.hpp boost/algorithm/string.hpp boost/algorith # Checks for library functions. AC_CHECK_FUNCS([atexit memset pow select sqrt]) -CXXFLAGS="$CXXFLAGS -DDATA_DIR=\\\"\$(pkgdatadir)\\\" -DBIN_DIR=\\\"\$(bindir)\\\" -DLIB_DIR=\\\"\$(pkglibdir)\\\"" +CXXFLAGS="$CXXFLAGS -DM_DATA_DIR=\\\"\$(pkgdatadir)\\\" -DM_BIN_DIR=\\\"\$(bindir)\\\" -DM_LIB_DIR=\\\"\$(pkglibdir)\\\"" AC_SUBST(SDL_LIBS) AC_SUBST(SDL_CXXFLAGS) diff --git a/lib/BattleAction.cpp b/lib/BattleAction.cpp index e4ab83070..cf7d54c33 100644 --- a/lib/BattleAction.cpp +++ b/lib/BattleAction.cpp @@ -1,5 +1,6 @@ -#define VCMI_DLL +#include "StdInc.h" #include "BattleAction.h" + #include "BattleState.h" /* @@ -31,7 +32,7 @@ BattleAction BattleAction::makeDefend(const CStack *stack) } -BattleAction BattleAction::makeMeleeAttack(const CStack *stack, const CStack * attacked, THex attackFrom /*= THex::INVALID*/) +BattleAction BattleAction::makeMeleeAttack(const CStack *stack, const CStack * attacked, SHexField attackFrom /*= SHexField::INVALID*/) { BattleAction ba; ba.side = !stack->attackerOwned; @@ -61,7 +62,7 @@ BattleAction BattleAction::makeShotAttack(const CStack *shooter, const CStack *t return ba; } -BattleAction BattleAction::makeMove(const CStack *stack, THex dest) +BattleAction BattleAction::makeMove(const CStack *stack, SHexField dest) { BattleAction ba; ba.side = !stack->attackerOwned; diff --git a/lib/BattleAction.h b/lib/BattleAction.h index 4df6d6f65..896bda764 100644 --- a/lib/BattleAction.h +++ b/lib/BattleAction.h @@ -1,8 +1,8 @@ #pragma once -#ifndef __BATTLEACTION_H__ -#define __BATTLEACTION_H__ -#include "../global.h" + +#include "SHexField.h" + /* * BattleAction.h, part of VCMI engine * @@ -16,7 +16,7 @@ /// A struct which handles battle actions like defending, walking,... - represents a creature stack in a battle class CStack; -struct DLL_EXPORT BattleAction +struct DLL_LINKAGE BattleAction { ui8 side; //who made this action: false - left, true - right player ui32 stackNumber;//stack ID, -1 left hero, -2 right hero, @@ -26,7 +26,7 @@ struct DLL_EXPORT BattleAction STACK_HEAL, DAEMON_SUMMONING }; si8 actionType; //use ActionType enum for values - THex destinationTile; + SHexField destinationTile; si32 additionalInfo; // e.g. spell number if type is 1 || 10; tile to attack if type is 6 template void serialize(Handler &h, const int version) { @@ -37,9 +37,8 @@ struct DLL_EXPORT BattleAction static BattleAction makeDefend(const CStack *stack); static BattleAction makeWait(const CStack *stack); - static BattleAction makeMeleeAttack(const CStack *stack, const CStack * attacked, THex attackFrom = THex::INVALID); + static BattleAction makeMeleeAttack(const CStack *stack, const CStack * attacked, SHexField attackFrom = SHexField::INVALID); static BattleAction makeShotAttack(const CStack *shooter, const CStack *target); - static BattleAction makeMove(const CStack *stack, THex dest); + static BattleAction makeMove(const CStack *stack, SHexField dest); static BattleAction makeEndOFTacticPhase(ui8 side); }; -#endif // __BATTLEACTION_H__ diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index 50b488f1f..e25c6c44b 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -1,14 +1,8 @@ -#define VCMI_DLL +#include "StdInc.h" #include "BattleState.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include "VCMI_Lib.h" #include "CObjectHandler.h" #include "CHeroHandler.h" @@ -18,6 +12,7 @@ #include "NetPacks.h" #include "../lib/JsonNode.h" + /* * BattleState.h, part of VCMI engine * @@ -95,7 +90,7 @@ static const CStack *takeStack(std::vector &st, int &curside, in CStack * BattleInfo::getStack(int stackID, bool onlyAlive) { - for(unsigned int g=0; gID == stackID && (!onlyAlive || stacks[g]->alive())) return stacks[g]; @@ -108,9 +103,9 @@ const CStack * BattleInfo::getStack(int stackID, bool onlyAlive) const return const_cast(this)->getStack(stackID, onlyAlive); } -CStack * BattleInfo::getStackT(THex tileID, bool onlyAlive) +CStack * BattleInfo::getStackT(SHexField tileID, bool onlyAlive) { - for(unsigned int g=0; gposition == tileID || (stacks[g]->doubleWide() && stacks[g]->attackerOwned && stacks[g]->position-1 == tileID) @@ -125,23 +120,23 @@ CStack * BattleInfo::getStackT(THex tileID, bool onlyAlive) return NULL; } -const CStack * BattleInfo::getStackT(THex tileID, bool onlyAlive) const +const CStack * BattleInfo::getStackT(SHexField tileID, bool onlyAlive) const { return const_cast(this)->getStackT(tileID, onlyAlive); } -void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack * stackToOmmit) const +void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack * stackToOmmit) const { - memset(accessibility, 1, BFIELD_SIZE); //initialize array with trues + memset(accessibility, 1, GameConstants::BFIELD_SIZE); //initialize array with trues //removing accessibility for side columns of hexes - for(int v = 0; v < BFIELD_SIZE; ++v) + for(int v = 0; v < GameConstants::BFIELD_SIZE; ++v) { - if( v % BFIELD_WIDTH == 0 || v % BFIELD_WIDTH == (BFIELD_WIDTH - 1) ) + if( v % GameConstants::BFIELD_WIDTH == 0 || v % GameConstants::BFIELD_WIDTH == (GameConstants::BFIELD_WIDTH - 1) ) accessibility[v] = false; } - for(unsigned int g=0; galive() || (stackToOmmit && stacks[g]->ID==stackToOmmit->ID) || stacks[g]->position < 0) //we don't want to lock position of this stack (eg. if it's a turret) continue; @@ -156,12 +151,12 @@ void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool atta } } //obstacles - for(unsigned int b=0; b blocked = VLC->heroh->obstacles[obstacles[b].ID].getBlocked(obstacles[b].pos); - for(unsigned int c=0; c blocked = VLC->heroh->obstacles[obstacles[b].ID].getBlocked(obstacles[b].pos); + for(ui32 c=0; c=0 && blocked[c] < BFIELD_SIZE) + if(blocked[c] >=0 && blocked[c] < GameConstants::BFIELD_SIZE) accessibility[blocked[c]] = false; } } @@ -175,9 +170,9 @@ void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool atta accessibility[permanentlyLocked[b]] = false; } - static const std::pair lockedIfNotDestroyed[] = //(which part of wall, which hex is blocked if this part of wall is not destroyed - {std::make_pair(2, THex(182)), std::make_pair(3, THex(130)), - std::make_pair(4, THex(62)), std::make_pair(5, THex(29))}; + static const std::pair lockedIfNotDestroyed[] = //(which part of wall, which hex is blocked if this part of wall is not destroyed + {std::make_pair(2, SHexField(182)), std::make_pair(3, SHexField(130)), + std::make_pair(4, SHexField(62)), std::make_pair(5, SHexField(29))}; for(int b=0; b rem; //tiles to unlock - for(int h=0; h rem; //tiles to unlock + for(int h=0; h > hexq; //bfs queue (second filed used only if fillPredecessors is true) + std::queue< std::pair > hexq; //bfs queue (second filed used only if fillPredecessors is true) hexq.push(std::make_pair(start, true)); dists[hexq.front().first] = 0; int curNext = -1; //for bfs loop only (helper var) while(!hexq.empty()) //bfs loop { - std::pair curHex = hexq.front(); - std::vector neighbours = curHex.first.neighbouringTiles(); + std::pair curHex = hexq.front(); + std::vector neighbours = curHex.first.neighbouringTiles(); hexq.pop(); - for(unsigned int nr=0; nr=dists[curNext]) bool accessible = isAccessible(curNext, accessibility, twoHex, attackerOwned, flying, dists[curHex.first]+1 == dists[curNext]); @@ -270,31 +265,31 @@ void BattleInfo::makeBFS(THex start, bool *accessibility, THex *predecessor, int } }; -std::vector BattleInfo::getAccessibility( const CStack * stack, bool addOccupiable, std::vector * attackable ) const +std::vector BattleInfo::getAccessibility( const CStack * stack, bool addOccupiable, std::vector * attackable ) const { - std::vector ret; - bool ac[BFIELD_SIZE]; + std::vector ret; + bool ac[GameConstants::BFIELD_SIZE]; if(stack->position < 0) //turrets - return std::vector(); + return std::vector(); - std::set occupyable; + std::set occupyable; getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, addOccupiable, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack); - THex pr[BFIELD_SIZE]; - int dist[BFIELD_SIZE]; + SHexField pr[GameConstants::BFIELD_SIZE]; + int dist[GameConstants::BFIELD_SIZE]; makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false); if(stack->doubleWide()) { if(!addOccupiable) { - std::vector rem; - for(int b=0; b rem; + for(int b=0; battackerOwned ? ac[b-1] : ac[b+1]) ) @@ -303,19 +298,19 @@ std::vector BattleInfo::getAccessibility( const CStack * stack, bool addOc } } - for(unsigned int g=0; gattackerOwned ? (v%BFIELD_WIDTH)==1 : (v%BFIELD_WIDTH)==(BFIELD_WIDTH - 2)) + for(int v=0; vattackerOwned ? (v%GameConstants::BFIELD_WIDTH)==1 : (v%GameConstants::BFIELD_WIDTH)==(GameConstants::BFIELD_WIDTH - 2)) ac[v] = false; } } - for (int i = 0; i < BFIELD_SIZE; ++i) + for (int i = 0; i < GameConstants::BFIELD_SIZE; ++i) { bool rangeFits; if (tacticDistance) @@ -336,11 +331,11 @@ std::vector BattleInfo::getAccessibility( const CStack * stack, bool addOc { struct HLP { - static bool meleeAttackable(THex hex, const std::vector & baseRng) + static bool meleeAttackable(SHexField hex, const std::vector & baseRng) { - BOOST_FOREACH(THex h, baseRng) + BOOST_FOREACH(SHexField h, baseRng) { - if(THex::mutualPosition(h, hex) > 0) + if(SHexField::mutualPosition(h, hex) > 0) return true; } @@ -352,7 +347,7 @@ std::vector BattleInfo::getAccessibility( const CStack * stack, bool addOc if(otherSt->owner == stack->owner) continue; - std::vector occupiedBySecond; + std::vector occupiedBySecond; occupiedBySecond.push_back(otherSt->position); if(otherSt->doubleWide()) occupiedBySecond.push_back(otherSt->occupiedHex()); @@ -365,7 +360,7 @@ std::vector BattleInfo::getAccessibility( const CStack * stack, bool addOc } - BOOST_FOREACH(THex he, occupiedBySecond) + BOOST_FOREACH(SHexField he, occupiedBySecond) { if(HLP::meleeAttackable(he, ret)) attackable->push_back(he); @@ -387,17 +382,17 @@ int BattleInfo::getAvaliableHex(TCreature creID, bool attackerOwned, int initial if (attackerOwned) pos = 0; //top left else - pos = BFIELD_WIDTH; //top right + pos = GameConstants::BFIELD_WIDTH; //top right } - bool ac[BFIELD_SIZE]; - std::set occupyable; + bool ac[GameConstants::BFIELD_SIZE]; + std::set occupyable; bool twoHex = VLC->creh->creatures[creID]->isDoubleWide(); bool flying = VLC->creh->creatures[creID]->isFlying();// vstd::contains(VLC->creh->creatures[creID]->bonuses, Bonus::FLYING); getAccessibilityMap(ac, twoHex, attackerOwned, true, occupyable, flying); - for (int g = pos; (-1 < g) && (g < BFIELD_SIZE); ) + for (int g = pos; (-1 < g) && (g < GameConstants::BFIELD_SIZE); ) { - if ((g % BFIELD_WIDTH != 0) && (g % BFIELD_WIDTH != BFIELD_WIDTH-1) && BattleInfo::isAccessible (g, ac, twoHex, attackerOwned, flying, true)) + if ((g % GameConstants::BFIELD_WIDTH != 0) && (g % GameConstants::BFIELD_WIDTH != GameConstants::BFIELD_WIDTH-1) && BattleInfo::isAccessible (g, ac, twoHex, attackerOwned, flying, true)) { pos = g; break; @@ -424,21 +419,21 @@ bool BattleInfo::isStackBlocked(const CStack * stack) const return false; } -std::pair< std::vector, int > BattleInfo::getPath(THex start, THex dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned) +std::pair< std::vector, int > BattleInfo::getPath(SHexField start, SHexField dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned) { - THex predecessor[BFIELD_SIZE]; //for getting the Path - int dist[BFIELD_SIZE]; //calculated distances + SHexField predecessor[GameConstants::BFIELD_SIZE]; //for getting the Path + int dist[GameConstants::BFIELD_SIZE]; //calculated distances makeBFS(start, accessibility, predecessor, dist, twoHex, attackerOwned, flyingCreature, false); if(predecessor[dest] == -1) //cannot reach destination { - return std::make_pair(std::vector(), 0); + return std::make_pair(std::vector(), 0); } //making the Path - std::vector path; - THex curElem = dest; + std::vector path; + SHexField curElem = dest; while(curElem != start) { path.push_back(curElem); @@ -451,7 +446,7 @@ std::pair< std::vector, int > BattleInfo::getPath(THex start, THex dest, b TDmgRange BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* defender, TQuantity attackerCount, TQuantity defenderCount, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky, bool deathBlow, bool ballistaDoubleDmg ) const { - float additiveBonus=1.0f, multBonus=1.0f, + double additiveBonus = 1.0, multBonus = 1.0, minDmg = attacker->getMinDamage() * attackerCount, maxDmg = attacker->getMaxDamage() * attackerCount; @@ -464,8 +459,8 @@ TDmgRange BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* d maxDmg = 15; break; case -3: case -4: //turrets - minDmg = 7.5f; - maxDmg = 7.5f; + minDmg = 7.5; + maxDmg = 7.5; break; } } @@ -479,7 +474,7 @@ TDmgRange BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* d int attackDefenceDifference = 0; if(attacker->hasBonusOfType(Bonus::GENERAL_ATTACK_REDUCTION)) { - float multAttackReduction = attacker->valOfBonuses(Bonus::GENERAL_ATTACK_REDUCTION, -1024) / 100.0f; + double multAttackReduction = attacker->valOfBonuses(Bonus::GENERAL_ATTACK_REDUCTION, -1024) / 100.0; attackDefenceDifference = attacker->Attack() * multAttackReduction; } else @@ -489,7 +484,7 @@ TDmgRange BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* d if(attacker->hasBonusOfType(Bonus::ENEMY_DEFENCE_REDUCTION)) { - float multDefenceReduction = (100.0f - attacker->valOfBonuses(Bonus::ENEMY_DEFENCE_REDUCTION, -1024)) / 100.0f; + double multDefenceReduction = (100 - attacker->valOfBonuses(Bonus::ENEMY_DEFENCE_REDUCTION, -1024)) / 100.0; attackDefenceDifference -= defender->Defense() * multDefenceReduction; } else @@ -524,7 +519,7 @@ TDmgRange BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* d } } - for(unsigned int g=0; ggetCreature()->idNumber == affectedIds[g]) { @@ -537,22 +532,22 @@ TDmgRange BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* d //bonus from attack/defense skills if(attackDefenceDifference < 0) //decreasing dmg { - float dec = 0.025f * (-attackDefenceDifference); - if(dec > 0.7f) + double dec = 0.025 * (-attackDefenceDifference); + if(dec > 0.7) { - multBonus *= 0.3f; //1.0 - 0.7 + multBonus *= 0.3; //1.0 - 0.7 } else { - multBonus *= 1.0f - dec; + multBonus *= 1.0 - dec; } } else //increasing dmg { - float inc = 0.05f * attackDefenceDifference; - if(inc > 4.0f) + double inc = 0.05 * attackDefenceDifference; + if(inc > 4.0) { - additiveBonus += 4.0f; + additiveBonus += 4.0; } else { @@ -563,7 +558,7 @@ TDmgRange BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* d //applying jousting bonus if( attacker->hasBonusOfType(Bonus::JOUSTING) && !defender->hasBonusOfType(Bonus::CHARGE_IMMUNITY) ) - additiveBonus += charge * 0.05f; + additiveBonus += charge * 0.05; //handling secondary abilities and artifacts giving premies to them @@ -571,47 +566,47 @@ TDmgRange BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* d { if(shooting) { - additiveBonus += attackerHero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::ARCHERY) / 100.0f; + additiveBonus += attackerHero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::ARCHERY) / 100.0; } else { - additiveBonus += attackerHero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::OFFENCE) / 100.0f; + additiveBonus += attackerHero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::OFFENCE) / 100.0; } } if(defendingHero) { - multBonus *= (std::max(0, 100-defendingHero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::ARMORER))) / 100.0f; + multBonus *= (std::max(0, 100-defendingHero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::ARMORER))) / 100.0; } //handling hate effect - additiveBonus += attacker->valOfBonuses(Bonus::HATE, defender->getCreature()->idNumber) / 100.f; + additiveBonus += attacker->valOfBonuses(Bonus::HATE, defender->getCreature()->idNumber) / 100.; //luck bonus if (lucky) { - additiveBonus += 1.0f; + additiveBonus += 1.0; } //ballista double dmg if(ballistaDoubleDmg) { - additiveBonus += 1.0f; + additiveBonus += 1.0; } if (deathBlow) //Dread Knight and many WoGified creatures { - additiveBonus += 1.0f; + additiveBonus += 1.0; } //handling spell effects if(!shooting && defender->hasBonusOfType(Bonus::GENERAL_DAMAGE_REDUCTION, 0)) //eg. shield { - multBonus *= float(defender->valOfBonuses(Bonus::GENERAL_DAMAGE_REDUCTION, 0)) / 100.0f; + multBonus *= defender->valOfBonuses(Bonus::GENERAL_DAMAGE_REDUCTION, 0) / 100.0; } else if(shooting && defender->hasBonusOfType(Bonus::GENERAL_DAMAGE_REDUCTION, 1)) //eg. air shield { - multBonus *= float(defender->valOfBonuses(Bonus::GENERAL_DAMAGE_REDUCTION, 1)) / 100.0f; + multBonus *= defender->valOfBonuses(Bonus::GENERAL_DAMAGE_REDUCTION, 1) / 100.0; } TBonusListPtr curseEffects = attacker->getBonuses(Selector::type(Bonus::ALWAYS_MINIMUM_DAMAGE)); //attacker->getEffect(42); @@ -682,8 +677,8 @@ TDmgRange BattleInfo::calculateDmgRange( const CStack* attacker, const CStack* d } //damage cannot be less than 1 - amax(returnedVal.first, 1); - amax(returnedVal.second, 1); + vstd::amax(returnedVal.first, 1); + vstd::amax(returnedVal.second, 1); return returnedVal; } @@ -716,17 +711,17 @@ ui32 BattleInfo::calculateDmg( const CStack* attacker, const CStack* defender, c void BattleInfo::calculateCasualties( std::map *casualties ) const { - for(unsigned int i=0; ialive() ? st->baseAmount - st->count : st->baseAmount); - amax(killed, 0); + vstd::amax(killed, 0); if(killed) casualties[!st->attackerOwned][st->getCreature()->idNumber] += killed; } } -std::set BattleInfo::getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, THex destinationTile ) +std::set BattleInfo::getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, SHexField destinationTile ) { std::set attackedHexes = s->rangeInHexes(destinationTile, skillLevel); std::set attackedCres; /*std::set to exclude multiple occurrences of two hex creatures*/ @@ -806,24 +801,24 @@ std::set BattleInfo::getAttackedCreatures(const CSpell * s, int skillLe } return attackedCres; } -void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, THex destinationTile, THex attackerPos) +void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, SHexField destinationTile, SHexField attackerPos) { - const int WN = BFIELD_WIDTH; - ui16 hex = (attackerPos != THex::INVALID) ? attackerPos.hex : attacker->position.hex; //real or hypothetical (cursor) position + const int WN = GameConstants::BFIELD_WIDTH; + ui16 hex = (attackerPos != SHexField::INVALID) ? attackerPos.hex : attacker->position.hex; //real or hypothetical (cursor) position if (attacker->hasBonusOfType(Bonus::ATTACKS_ALL_ADJACENT)) { - std::vector hexes = attacker->getSurroundingHexes(attackerPos); - BOOST_FOREACH (THex tile, hexes) + std::vector hexes = attacker->getSurroundingHexes(attackerPos); + BOOST_FOREACH (SHexField tile, hexes) { at.hostileCreaturePositions.insert(tile); } } if (attacker->hasBonusOfType(Bonus::THREE_HEADED_ATTACK)) { - std::vector hexes = attacker->getSurroundingHexes(attackerPos); - BOOST_FOREACH (THex tile, hexes) + std::vector hexes = attacker->getSurroundingHexes(attackerPos); + BOOST_FOREACH (SHexField tile, hexes) { - if ((THex::mutualPosition(tile, destinationTile) > -1 && THex::mutualPosition(tile, hex) > -1) //adjacent both to attacker's head and attacked tile + if ((SHexField::mutualPosition(tile, destinationTile) > -1 && SHexField::mutualPosition(tile, hex) > -1) //adjacent both to attacker's head and attacked tile || tile == destinationTile) //or simply attacked directly { CStack * st = getStackT(tile, true); @@ -836,26 +831,26 @@ void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack } if (attacker->hasBonusOfType(Bonus::TWO_HEX_ATTACK_BREATH)) { - std::vector hexes; //only one, in fact + std::vector hexes; //only one, in fact int pseudoVector = destinationTile.hex - hex; switch (pseudoVector) { case 1: case -1: - THex::checkAndPush(destinationTile.hex + pseudoVector, hexes); + SHexField::checkAndPush(destinationTile.hex + pseudoVector, hexes); break; case WN: //17 case WN + 1: //18 case -WN: //-17 case -WN + 1: //-16 - THex::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : -1 ), hexes); + SHexField::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : -1 ), hexes); break; case WN-1: //16 case -WN-1: //-18 - THex::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : 0), hexes); + SHexField::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : 0), hexes); break; } - BOOST_FOREACH (THex tile, hexes) + BOOST_FOREACH (SHexField tile, hexes) { CStack * st = getStackT(tile, true); if(st) //friendly stacks can also be damaged by Dragon Breath @@ -865,12 +860,12 @@ void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack } } } -std::set BattleInfo::getAttackedCreatures(const CStack* attacker, THex destinationTile, THex attackerPos) +std::set BattleInfo::getAttackedCreatures(const CStack* attacker, SHexField destinationTile, SHexField attackerPos) { //TODO: caching? AttackableTiles at; getPotentiallyAttackableHexes(at, attacker, destinationTile, attackerPos); std::set attackedCres; - BOOST_FOREACH (THex tile, at.hostileCreaturePositions) //all around & three-headed attack + BOOST_FOREACH (SHexField tile, at.hostileCreaturePositions) //all around & three-headed attack { CStack * st = getStackT(tile, true); if(st && st->owner != attacker->owner) //only hostile stacks - does it work well with Berserk? @@ -878,7 +873,7 @@ std::set BattleInfo::getAttackedCreatures(const CStack* attacker, THex attackedCres.insert(st); } } - BOOST_FOREACH (THex tile, at.friendlyCreaturePositions) + BOOST_FOREACH (SHexField tile, at.friendlyCreaturePositions) { CStack * st = getStackT(tile, true); if(st) //friendly stacks can also be damaged by Dragon Breath @@ -889,12 +884,12 @@ std::set BattleInfo::getAttackedCreatures(const CStack* attacker, THex return attackedCres; } -std::set BattleInfo::getAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos) +std::set BattleInfo::getAttackedHexes(const CStack* attacker, SHexField destinationTile, SHexField attackerPos) { AttackableTiles at; getPotentiallyAttackableHexes(at, attacker, destinationTile, attackerPos); - std::set attackedHexes; - BOOST_FOREACH (THex tile, at.hostileCreaturePositions) + std::set attackedHexes; + BOOST_FOREACH (SHexField tile, at.hostileCreaturePositions) { CStack * st = getStackT(tile, true); if(st && st->owner != attacker->owner) //only hostile stacks - does it work well with Berserk? @@ -902,7 +897,7 @@ std::set BattleInfo::getAttackedHexes(const CStack* attacker, THex destina attackedHexes.insert(tile); } } - BOOST_FOREACH (THex tile, at.friendlyCreaturePositions) + BOOST_FOREACH (SHexField tile, at.friendlyCreaturePositions) { CStack * st = getStackT(tile, true); if(st) //friendly stacks can also be damaged by Dragon Breath @@ -918,7 +913,7 @@ std::set BattleInfo::getAdjacentCreatures (const CStack * stack) const std::set stacks; CStack * localStack; - BOOST_FOREACH (THex hex, stack->getSurroundingHexes()) + BOOST_FOREACH (SHexField hex, stack->getSurroundingHexes()) { localStack = const_cast(getStackT(hex, true)); //only alive? if (localStack) @@ -945,17 +940,17 @@ int BattleInfo::calculateSpellDuration( const CSpell * spell, const CGHeroInstan } } -CStack * BattleInfo::generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, THex position) const +CStack * BattleInfo::generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, SHexField position) const { int owner = attackerOwned ? sides[0] : sides[1]; - assert((owner >= PLAYER_LIMIT) || + assert((owner >= GameConstants::PLAYER_LIMIT) || (base.armyObj && base.armyObj->tempOwner == owner)); CStack * ret = new CStack(&base, owner, stackID, attackerOwned, slot); ret->position = position; return ret; } -CStack * BattleInfo::generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, THex position) const +CStack * BattleInfo::generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, SHexField position) const { int owner = attackerOwned ? sides[0] : sides[1]; CStack * ret = new CStack(&base, owner, stackID, attackerOwned, slot); @@ -975,18 +970,18 @@ ui32 BattleInfo::getSpellCost(const CSpell * sp, const CGHeroInstance * caster) { if( stacks[g]->owner == caster->tempOwner && stacks[g]->hasBonusOfType(Bonus::CHANGES_SPELL_COST_FOR_ALLY) ) { - amax(manaReduction, stacks[g]->valOfBonuses(Bonus::CHANGES_SPELL_COST_FOR_ALLY)); + vstd::amax(manaReduction, stacks[g]->valOfBonuses(Bonus::CHANGES_SPELL_COST_FOR_ALLY)); } if( stacks[g]->owner != caster->tempOwner && stacks[g]->hasBonusOfType(Bonus::CHANGES_SPELL_COST_FOR_ENEMY) ) { - amax(manaIncrease, stacks[g]->valOfBonuses(Bonus::CHANGES_SPELL_COST_FOR_ENEMY)); + vstd::amax(manaIncrease, stacks[g]->valOfBonuses(Bonus::CHANGES_SPELL_COST_FOR_ENEMY)); } } return ret - manaReduction + manaIncrease; } -int BattleInfo::hexToWallPart(THex hex) const +int BattleInfo::hexToWallPart(SHexField hex) const { if(siege == 0) //there is no battle! return -1; @@ -1012,19 +1007,19 @@ int BattleInfo::lineToWallHex( int line ) const return lineToHex[line]; } -std::pair BattleInfo::getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const +std::pair BattleInfo::getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const { - bool ac[BFIELD_SIZE]; - std::set occupyable; + bool ac[GameConstants::BFIELD_SIZE]; + std::set occupyable; getAccessibilityMap(ac, closest->doubleWide(), closest->attackerOwned, false, occupyable, closest->hasBonusOfType(Bonus::FLYING), closest); - THex predecessor[BFIELD_SIZE]; - int dist[BFIELD_SIZE]; + SHexField predecessor[GameConstants::BFIELD_SIZE]; + int dist[GameConstants::BFIELD_SIZE]; makeBFS(closest->position, ac, predecessor, dist, closest->doubleWide(), closest->attackerOwned, closest->hasBonusOfType(Bonus::FLYING), true); std::vector< std::pair< std::pair, const CStack *> > stackPairs; //pairs <, stack> - for(int g=0; gID == closest->ID) //if there is not stack or we are the closest one @@ -1060,7 +1055,7 @@ std::pair BattleInfo::getNearestStack(const CStack * close return std::make_pair(minPair.second, predecessor[minPair.first.second]); } - return std::make_pair(NULL, THex::INVALID); + return std::make_pair(NULL, SHexField::INVALID); } ui32 BattleInfo::calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature) const { @@ -1068,20 +1063,20 @@ ui32 BattleInfo::calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const C //applying sorcery secondary skill if(caster) { - ret *= (100.f + caster->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::SORCERY)) / 100.0f; - ret *= (100.f + caster->valOfBonuses(Bonus::SPELL_DAMAGE) + caster->valOfBonuses(Bonus::SPECIFIC_SPELL_DAMAGE, sp->id)) / 100.0f; + ret *= (100.0 + caster->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::SORCERY)) / 100.0; + ret *= (100.0 + caster->valOfBonuses(Bonus::SPELL_DAMAGE) + caster->valOfBonuses(Bonus::SPECIFIC_SPELL_DAMAGE, sp->id)) / 100.0; if(sp->air) - ret *= (100.0f + caster->valOfBonuses(Bonus::AIR_SPELL_DMG_PREMY)) / 100.0f; + ret *= (100.0 + caster->valOfBonuses(Bonus::AIR_SPELL_DMG_PREMY)) / 100.0; else if(sp->fire) //only one type of bonus for Magic Arrow - ret *= (100.0f + caster->valOfBonuses(Bonus::FIRE_SPELL_DMG_PREMY)) / 100.0f; + ret *= (100.0 + caster->valOfBonuses(Bonus::FIRE_SPELL_DMG_PREMY)) / 100.0; else if(sp->water) - ret *= (100.0f + caster->valOfBonuses(Bonus::WATER_SPELL_DMG_PREMY)) / 100.0f; + ret *= (100.0 + caster->valOfBonuses(Bonus::WATER_SPELL_DMG_PREMY)) / 100.0; else if(sp->earth) - ret *= (100.0f + caster->valOfBonuses(Bonus::EARTH_SPELL_DMG_PREMY)) / 100.0f; + ret *= (100.0 + caster->valOfBonuses(Bonus::EARTH_SPELL_DMG_PREMY)) / 100.0; if (affectedCreature && affectedCreature->getCreature()->level) //Hero specials like Solmyr, Deemer - ret *= (100.f + ((caster->valOfBonuses(Bonus::SPECIAL_SPELL_LEV, sp->id) * caster->level) / affectedCreature->getCreature()->level)) / 100.0f; + ret *= (100. + ((caster->valOfBonuses(Bonus::SPECIAL_SPELL_LEV, sp->id) * caster->level) / affectedCreature->getCreature()->level)) / 100.0; } return ret; } @@ -1172,7 +1167,7 @@ void BattleInfo::getStackQueue( std::vector &out, int howMany, i const CStack *active = getStack(activeStack); //active stack hasn't taken any action yet - must be placed at the beginning of queue, no matter what - if(!turn && active && active->willMove() && !vstd::contains(active->state, WAITING)) + if(!turn && active && active->willMove() && !vstd::contains(active->state, EBattleStackState::WAITING)) { out.push_back(active); if(out.size() == howMany) @@ -1180,7 +1175,7 @@ void BattleInfo::getStackQueue( std::vector &out, int howMany, i } - for(unsigned int i=0; iwillMove()) //we are considering current round and stack won't move @@ -1191,9 +1186,9 @@ void BattleInfo::getStackQueue( std::vector &out, int howMany, i } int p = -1; //in which phase this tack will move? - if(turn <= 0 && vstd::contains(s->state, WAITING)) //consider waiting state only for ongoing round + if(turn <= 0 && vstd::contains(s->state, EBattleStackState::WAITING)) //consider waiting state only for ongoing round { - if(vstd::contains(s->state, HAD_MORALE)) + if(vstd::contains(s->state, EBattleStackState::HAD_MORALE)) p = 2; else p = 3; @@ -1256,13 +1251,13 @@ void BattleInfo::getStackQueue( std::vector &out, int howMany, i } } -si8 BattleInfo::hasDistancePenalty( const CStack * stack, THex destHex ) const +si8 BattleInfo::hasDistancePenalty( const CStack * stack, SHexField destHex ) const { struct HLP { - static bool lowerAnalyze(const CStack * stack, THex hex) + static bool lowerAnalyze(const CStack * stack, SHexField hex) { - int distance = THex::getDistance(hex, stack->position); + int distance = SHexField::getDistance(hex, stack->position); //I hope it's approximately correct return distance > 10 && !stack->hasBonusOfType(Bonus::NO_DISTANCE_PENALTY); @@ -1279,8 +1274,8 @@ si8 BattleInfo::hasDistancePenalty( const CStack * stack, THex destHex ) const si8 BattleInfo::sameSideOfWall(int pos1, int pos2) const { - int wallInStackLine = lineToWallHex(pos1/BFIELD_WIDTH); - int wallInDestLine = lineToWallHex(pos2/BFIELD_WIDTH); + int wallInStackLine = lineToWallHex(pos1/GameConstants::BFIELD_WIDTH); + int wallInDestLine = lineToWallHex(pos2/GameConstants::BFIELD_WIDTH); bool stackLeft = pos1 < wallInStackLine; bool destLeft = pos2 < wallInDestLine; @@ -1288,23 +1283,23 @@ si8 BattleInfo::sameSideOfWall(int pos1, int pos2) const return stackLeft != destLeft; } -si8 BattleInfo::hasWallPenalty( const CStack* stack, THex destHex ) const +si8 BattleInfo::hasWallPenalty( const CStack* stack, SHexField destHex ) const { if (!siege || stack->hasBonusOfType(Bonus::NO_WALL_PENALTY)) { return false; } - int wallInStackLine = lineToWallHex(stack->position/BFIELD_WIDTH); - int wallInDestLine = lineToWallHex(destHex/BFIELD_WIDTH); + int wallInStackLine = lineToWallHex(stack->position/GameConstants::BFIELD_WIDTH); + int wallInDestLine = lineToWallHex(destHex/GameConstants::BFIELD_WIDTH); bool stackLeft = stack->position < wallInStackLine; bool destRight = destHex > wallInDestLine; if (stackLeft && destRight) //shooting from outside to inside { - int row = (stack->position + destHex) / (2 * BFIELD_WIDTH); - if (stack->position > destHex && ((destHex & BFIELD_WIDTH - stack->position % BFIELD_WIDTH) < 2)) //shooting up high + int row = (stack->position + destHex) / (2 * GameConstants::BFIELD_WIDTH); + if (stack->position > destHex && ((destHex & GameConstants::BFIELD_WIDTH - stack->position % GameConstants::BFIELD_WIDTH) < 2)) //shooting up high row -= 2; int wallPos = lineToWallHex(row); if (hexToWallPart(wallPos) != -1) //wall still exists or is indestructible @@ -1313,11 +1308,11 @@ si8 BattleInfo::hasWallPenalty( const CStack* stack, THex destHex ) const return false; } -si8 BattleInfo::canTeleportTo(const CStack * stack, THex destHex, int telportLevel) const +si8 BattleInfo::canTeleportTo(const CStack * stack, SHexField destHex, int telportLevel) const { - bool ac[BFIELD_SIZE]; + bool ac[GameConstants::BFIELD_SIZE]; - std::set occupyable; + std::set occupyable; getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack); @@ -1332,7 +1327,7 @@ si8 BattleInfo::canTeleportTo(const CStack * stack, THex destHex, int telportLev } -bool BattleInfo::battleCanShoot(const CStack * stack, THex dest) const +bool BattleInfo::battleCanShoot(const CStack * stack, SHexField dest) const { const CStack *dst = getStackT(dest); @@ -1380,10 +1375,10 @@ bool BattleInfo::battleCanFlee(int player) const return true; } -const CStack * BattleInfo::battleGetStack(THex pos, bool onlyAlive) +const CStack * BattleInfo::battleGetStack(SHexField pos, bool onlyAlive) { CStack * stack = NULL; - for(unsigned int g=0; gposition == pos || (stacks[g]->doubleWide() @@ -1411,12 +1406,12 @@ si8 BattleInfo::battleMinSpellLevel() const if(const CGHeroInstance *h1 = heroes[0]) { - amax(levelLimit, h1->valOfBonuses(Bonus::LEVEL_SPELL_IMMUNITY)); + vstd::amax(levelLimit, h1->valOfBonuses(Bonus::LEVEL_SPELL_IMMUNITY)); } if(const CGHeroInstance *h2 = heroes[1]) { - amax(levelLimit, h2->valOfBonuses(Bonus::LEVEL_SPELL_IMMUNITY)); + vstd::amax(levelLimit, h2->valOfBonuses(Bonus::LEVEL_SPELL_IMMUNITY)); } return levelLimit; @@ -1502,7 +1497,7 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const //reading battleStartpos std::vector< std::vector > attackerLoose, defenderLoose, attackerTight, defenderTight, attackerCreBank, defenderCreBank; - const JsonNode config(DATA_DIR "/config/battleStartpos.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/battleStartpos.json"); const JsonVector &positions = config["battle_positions"].Vector(); CGH::readBattlePositions(positions[0]["levels"], attackerLoose); @@ -1548,12 +1543,12 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const //we should do that for creature bank too if(stacks[g]->doubleWide() && stacks[g]->attackerOwned) { - stacks[g]->position += THex::RIGHT; + stacks[g]->position += SHexField::RIGHT; } else if(stacks[g]->doubleWide() && !stacks[g]->attackerOwned) { if (stacks[g]->position.getX() > 1) - stacks[g]->position += THex::LEFT; + stacks[g]->position += SHexField::LEFT; } } @@ -1635,10 +1630,10 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const //randomize obstacles if(town == NULL && !creatureBank) //do it only when it's not siege and not creature bank { - bool obAv[BFIELD_SIZE]; //availability of hexes for obstacles; + bool obAv[GameConstants::BFIELD_SIZE]; //availability of hexes for obstacles; std::vector possibleObstacles; - for(int i=0; i 12) { @@ -1667,12 +1662,12 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const CObstacleInstance coi; coi.uniqueID = curB->obstacles.size(); coi.ID = possibleObstacles[rand()%possibleObstacles.size()]; - coi.pos = rand()%BFIELD_SIZE; - std::vector block = VLC->heroh->obstacles[coi.ID].getBlocked(coi.pos); + coi.pos = rand()%GameConstants::BFIELD_SIZE; + std::vector block = VLC->heroh->obstacles[coi.ID].getBlocked(coi.pos); bool badObstacle = false; for(int b=0; b= BFIELD_SIZE || !obAv[block[b]]) + if(block[b] < 0 || block[b] >= GameConstants::BFIELD_SIZE || !obAv[block[b]]) { badObstacle = true; break; @@ -1683,7 +1678,7 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const curB->obstacles.push_back(coi); for(int b=0; b= 0 && block[b] < BFIELD_SIZE) + if(block[b] >= 0 && block[b] < GameConstants::BFIELD_SIZE) obAv[block[b]] = false; } toBlock -= block.size(); @@ -1727,8 +1722,8 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const case 18: //holy ground { - curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, +1, Bonus::TERRAIN_OVERLAY)->addLimiter(new CreatureAlignmentLimiter(GOOD))); - curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, -1, Bonus::TERRAIN_OVERLAY)->addLimiter(new CreatureAlignmentLimiter(EVIL))); + curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, +1, Bonus::TERRAIN_OVERLAY)->addLimiter(new CreatureAlignmentLimiter(EAlignment::GOOD))); + curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, -1, Bonus::TERRAIN_OVERLAY)->addLimiter(new CreatureAlignmentLimiter(EAlignment::EVIL))); break; } case 19: //clover field @@ -1738,15 +1733,15 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const } case 20: //evil fog { - curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, -1, Bonus::TERRAIN_OVERLAY)->addLimiter(new CreatureAlignmentLimiter(GOOD))); - curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, +1, Bonus::TERRAIN_OVERLAY)->addLimiter(new CreatureAlignmentLimiter(EVIL))); + curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, -1, Bonus::TERRAIN_OVERLAY)->addLimiter(new CreatureAlignmentLimiter(EAlignment::GOOD))); + curB->addNewBonus(makeFeature(Bonus::MORALE, Bonus::ONE_BATTLE, 0, +1, Bonus::TERRAIN_OVERLAY)->addLimiter(new CreatureAlignmentLimiter(EAlignment::EVIL))); break; } case 22: //cursed ground { curB->addNewBonus(makeFeature(Bonus::NO_MORALE, Bonus::ONE_BATTLE, 0, 0, Bonus::TERRAIN_OVERLAY)); curB->addNewBonus(makeFeature(Bonus::NO_LUCK, Bonus::ONE_BATTLE, 0, 0, Bonus::TERRAIN_OVERLAY)); - Bonus * b = makeFeature(Bonus::LEVEL_SPELL_IMMUNITY, Bonus::ONE_BATTLE, SPELL_LEVELS, 1, Bonus::TERRAIN_OVERLAY); + Bonus * b = makeFeature(Bonus::LEVEL_SPELL_IMMUNITY, Bonus::ONE_BATTLE, GameConstants::SPELL_LEVELS, 1, Bonus::TERRAIN_OVERLAY); b->valType = Bonus::INDEPENDENT_MAX; curB->addNewBonus(b); break; @@ -1805,65 +1800,65 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const return curB; } -bool BattleInfo::isInTacticRange( THex dest ) const +bool BattleInfo::isInTacticRange( SHexField dest ) const { return ((!tacticsSide && dest.getX() > 0 && dest.getX() <= tacticDistance) - || (tacticsSide && dest.getX() < BFIELD_WIDTH - 1 && dest.getX() >= BFIELD_WIDTH - tacticDistance - 1)); + || (tacticsSide && dest.getX() < GameConstants::BFIELD_WIDTH - 1 && dest.getX() >= GameConstants::BFIELD_WIDTH - tacticDistance - 1)); } -SpellCasting::ESpellCastProblem BattleInfo::battleCanCastSpell(int player, SpellCasting::ECastingMode mode) const +ESpellCastProblem::ESpellCastProblem BattleInfo::battleCanCastSpell(int player, ECastingMode::ECastingMode mode) const { int side = sides[0] == player ? 0 : 1; switch (mode) { - case SpellCasting::HERO_CASTING: + case ECastingMode::HERO_CASTING: { if(castSpells[side] > 0) - return SpellCasting::ALREADY_CASTED_THIS_TURN; + return ESpellCastProblem::ALREADY_CASTED_THIS_TURN; if(!heroes[side]) - return SpellCasting::NO_HERO_TO_CAST_SPELL; + return ESpellCastProblem::NO_HERO_TO_CAST_SPELL; if(!heroes[side]->getArt(17)) - return SpellCasting::NO_SPELLBOOK; + return ESpellCastProblem::NO_SPELLBOOK; } break; } - return SpellCasting::OK; + return ESpellCastProblem::OK; } -SpellCasting::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int player, const CSpell * spell, SpellCasting::ECastingMode mode ) const +ESpellCastProblem::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int player, const CSpell * spell, ECastingMode::ECastingMode mode ) const { - SpellCasting::ESpellCastProblem genProblem = battleCanCastSpell(player, mode); - if(genProblem != SpellCasting::OK) + ESpellCastProblem::ESpellCastProblem genProblem = battleCanCastSpell(player, mode); + if(genProblem != ESpellCastProblem::OK) return genProblem; int cside = sides[0] == player ? 0 : 1; //caster's side switch(mode) { - case SpellCasting::HERO_CASTING: + case ECastingMode::HERO_CASTING: { const CGHeroInstance * caster = heroes[cside]; if(!caster->canCastThisSpell(spell)) - return SpellCasting::HERO_DOESNT_KNOW_SPELL; + return ESpellCastProblem::HERO_DOESNT_KNOW_SPELL; if(caster->mana < getSpellCost(spell, caster)) //not enough mana - return SpellCasting::NOT_ENOUGH_MANA; + return ESpellCastProblem::NOT_ENOUGH_MANA; } break; } if(spell->id < 10) //it's adventure spell (not combat)) - return SpellCasting::ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL; + return ESpellCastProblem::ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL; if(NBonus::hasOfType(heroes[1-cside], Bonus::SPELL_IMMUNITY, spell->id)) //non - casting hero provides immunity for this spell - return SpellCasting::SECOND_HEROS_SPELL_IMMUNITY; + return ESpellCastProblem::SECOND_HEROS_SPELL_IMMUNITY; if(battleMinSpellLevel() > spell->level) //non - casting hero stops caster from casting this spell - return SpellCasting::SPELL_LEVEL_LIMIT_EXCEEDED; - + return ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED; + int spellIDs[] = {66, 67, 68, 69}; //IDs of summon elemental spells (fire, earth, water, air) int creIDs[] = {114, 113, 115, 112}; //(fire, earth, water, air) @@ -1874,9 +1869,9 @@ SpellCasting::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int player, //check if there are summoned elementals of other type BOOST_FOREACH ( const CStack * st, stacks) { - if (vstd::contains(st->state, SUMMONED) && st->getCreature()->idNumber != creIDs[arpos]) + if (vstd::contains(st->state, EBattleStackState::SUMMONED) && st->getCreature()->idNumber != creIDs[arpos]) { - return SpellCasting::ANOTHER_ELEMENTAL_SUMMONED; + return ESpellCastProblem::ANOTHER_ELEMENTAL_SUMMONED; } } } @@ -1886,7 +1881,7 @@ SpellCasting::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int player, { case CSpell::CREATURE: case CSpell::CREATURE_EXPERT_MASSIVE: - if(mode == SpellCasting::HERO_CASTING) + if(mode == ECastingMode::HERO_CASTING) { const CGHeroInstance * caster = getHero(player); bool targetExists = false; @@ -1897,7 +1892,7 @@ SpellCasting::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int player, case 1: if(stack->owner == caster->getOwner()) { - if(battleIsImmune(caster, spell, mode, stack->position) == SpellCasting::OK) + if(battleIsImmune(caster, spell, mode, stack->position) == ESpellCastProblem::OK) { targetExists = true; break; @@ -1905,7 +1900,7 @@ SpellCasting::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int player, } break; case 0: - if(battleIsImmune(caster, spell, mode, stack->position) == SpellCasting::OK) + if(battleIsImmune(caster, spell, mode, stack->position) == ESpellCastProblem::OK) { targetExists = true; break; @@ -1914,7 +1909,7 @@ SpellCasting::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int player, case -1: if(stack->owner != caster->getOwner()) { - if(battleIsImmune(caster, spell, mode, stack->position) == SpellCasting::OK) + if(battleIsImmune(caster, spell, mode, stack->position) == ESpellCastProblem::OK) { targetExists = true; break; @@ -1925,7 +1920,7 @@ SpellCasting::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int player, } if(!targetExists) { - return SpellCasting::NO_APPROPRIATE_TARGET; + return ESpellCastProblem::NO_APPROPRIATE_TARGET; } } break; @@ -1933,16 +1928,16 @@ SpellCasting::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int player, break; } - return SpellCasting::OK; + return ESpellCastProblem::OK; } -SpellCasting::ESpellCastProblem BattleInfo::battleCanCastThisSpellHere( int player, const CSpell * spell, SpellCasting::ECastingMode mode, THex dest ) const +ESpellCastProblem::ESpellCastProblem BattleInfo::battleCanCastThisSpellHere( int player, const CSpell * spell, ECastingMode::ECastingMode mode, SHexField dest ) const { - SpellCasting::ESpellCastProblem moreGeneralProblem = battleCanCastThisSpell(player, spell, mode); - if(moreGeneralProblem != SpellCasting::OK) + ESpellCastProblem::ESpellCastProblem moreGeneralProblem = battleCanCastThisSpell(player, spell, mode); + if(moreGeneralProblem != ESpellCastProblem::OK) return moreGeneralProblem; - if (mode != SpellCasting::CREATURE_ACTIVE_CASTING && mode != SpellCasting::ENCHANTER_CASTING) + if (mode != ECastingMode::CREATURE_ACTIVE_CASTING && mode != ECastingMode::ENCHANTER_CASTING) return battleIsImmune(getHero(player), spell, mode, dest); else return battleIsImmune(NULL, spell, mode, dest); @@ -1952,13 +1947,13 @@ TSpell BattleInfo::getRandomBeneficialSpell(const CStack * subject) const { std::vector possibleSpells; CSpell * spell; - for (int i = 0; i < SPELLS_QUANTITY; ++i) //should not use future spells added by mods + for (int i = 0; i < GameConstants::SPELLS_QUANTITY; ++i) //should not use future spells added by mods { spell = VLC->spellh->spells[i]; if (spell->positiveness == 1) //only positive { if (subject->hasBonusFrom(Bonus::SPELL_EFFECT, i) || - battleCanCastThisSpellHere(subject->owner, spell, SpellCasting::CREATURE_ACTIVE_CASTING, subject->position) != SpellCasting::OK) + battleCanCastThisSpellHere(subject->owner, spell, ECastingMode::CREATURE_ACTIVE_CASTING, subject->position) != ESpellCastProblem::OK) continue; switch (i) { @@ -2098,38 +2093,38 @@ bool BattleInfo::battleTestElementalImmunity(const CStack * subject, const CSpel return false; } -SpellCasting::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, SpellCasting::ECastingMode mode, THex dest) const +ESpellCastProblem::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, ECastingMode::ECastingMode mode, SHexField dest) const { const CStack * subject = getStackT(dest, false); if(subject) { if (spell->positiveness == 1 && subject->hasBonusOfType(Bonus::RECEPTIVE)) //accept all positive spells - return SpellCasting::OK; + return ESpellCastProblem::OK; switch (spell->id) //TODO: more general logic for new spells? { case Spells::DESTROY_UNDEAD: if (!subject->hasBonusOfType(Bonus::UNDEAD)) - return SpellCasting::STACK_IMMUNE_TO_SPELL; + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; break; case Spells::DEATH_RIPPLE: if (subject->hasBonusOfType(Bonus::SIEGE_WEAPON)) - return SpellCasting::STACK_IMMUNE_TO_SPELL; //don't break here - undeads and war machines are immune, non-living are not + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; //don't break here - undeads and war machines are immune, non-living are not case Spells::BLESS: case Spells::CURSE: //undeads are immune to bless & curse if (subject->hasBonusOfType(Bonus::UNDEAD)) - return SpellCasting::STACK_IMMUNE_TO_SPELL; + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; break; case Spells::HASTE: case Spells::SLOW: case Spells::TELEPORT: case Spells::CLONE: if (subject->hasBonusOfType(Bonus::SIEGE_WEAPON)) - return SpellCasting::STACK_IMMUNE_TO_SPELL; //war machines are mmune to some spells than involve movement + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; //war machines are mmune to some spells than involve movement break; case Spells::FORGETFULNESS: if (!subject->hasBonusOfType(Bonus::SHOOTER)) - return SpellCasting::STACK_IMMUNE_TO_SPELL; + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; break; case Spells::DISPEL_HELPFUL_SPELLS: { @@ -2145,7 +2140,7 @@ SpellCasting::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInstance } if(!hasPositiveSpell) { - return SpellCasting::NO_SPELLS_TO_DISPEL; + return ESpellCastProblem::NO_SPELLS_TO_DISPEL; } } break; @@ -2154,33 +2149,33 @@ SpellCasting::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInstance bool damageSpell = (vstd::contains(VLC->spellh->damageSpells, spell->id)); if (damageSpell && subject->hasBonusOfType(Bonus::DIRECT_DAMAGE_IMMUNITY)) - return SpellCasting::STACK_IMMUNE_TO_SPELL; + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; if (spell->fire) { if (battleTestElementalImmunity(subject, spell, Bonus::FIRE_IMMUNITY, damageSpell)) - return SpellCasting::STACK_IMMUNE_TO_SPELL; + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; } if (spell->water) { if (battleTestElementalImmunity(subject, spell, Bonus::WATER_IMMUNITY, damageSpell)) - return SpellCasting::STACK_IMMUNE_TO_SPELL; + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; } if (spell->earth) { if (battleTestElementalImmunity(subject, spell, Bonus::EARTH_IMMUNITY, damageSpell)) - return SpellCasting::STACK_IMMUNE_TO_SPELL; + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; } if (spell->air) { if (battleTestElementalImmunity(subject, spell, Bonus::AIR_IMMUNITY, damageSpell)) - return SpellCasting::STACK_IMMUNE_TO_SPELL; + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; } if (vstd::contains(VLC->spellh->risingSpells, spell->id)) { if (subject->count >= subject->baseAmount) //TODO: calculate potential hp raised - return SpellCasting::STACK_IMMUNE_TO_SPELL; + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; } TBonusListPtr immunities = subject->getBonuses(Selector::type(Bonus::LEVEL_SPELL_IMMUNITY)); @@ -2193,27 +2188,27 @@ SpellCasting::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInstance if(subject->hasBonusOfType(Bonus::SPELL_IMMUNITY, spell->id) || ( immunities->size() > 0 && immunities->totalValue() >= spell->level && spell->level)) { - return SpellCasting::STACK_IMMUNE_TO_SPELL; + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; } } else { if(spell->getTargetType() == CSpell::CREATURE || - (spell->getTargetType() == CSpell::CREATURE_EXPERT_MASSIVE && mode == SpellCasting::HERO_CASTING && caster && caster->getSpellSchoolLevel(spell) < 3)) + (spell->getTargetType() == CSpell::CREATURE_EXPERT_MASSIVE && mode == ECastingMode::HERO_CASTING && caster && caster->getSpellSchoolLevel(spell) < 3)) { - return SpellCasting::WRONG_SPELL_TARGET; + return ESpellCastProblem::WRONG_SPELL_TARGET; } } - return SpellCasting::OK; + return ESpellCastProblem::OK; } -std::vector BattleInfo::calculateResistedStacks( const CSpell * sp, const CGHeroInstance * caster, const CGHeroInstance * hero2, const std::set affectedCreatures, int casterSideOwner, SpellCasting::ECastingMode mode ) const +std::vector BattleInfo::calculateResistedStacks( const CSpell * sp, const CGHeroInstance * caster, const CGHeroInstance * hero2, const std::set affectedCreatures, int casterSideOwner, ECastingMode::ECastingMode mode ) const { std::vector ret; for(std::set::const_iterator it = affectedCreatures.begin(); it != affectedCreatures.end(); ++it) { - if(battleIsImmune(caster, sp, mode, (*it)->position) != SpellCasting::OK) + if(battleIsImmune(caster, sp, mode, (*it)->position) != ESpellCastProblem::OK) { ret.push_back((*it)->ID); continue; @@ -2274,7 +2269,7 @@ int BattleInfo::getSurrenderingCost(int player) const discount += h->valOfBonuses(Bonus::SURRENDER_DISCOUNT); ret *= (100.0 - discount) / 100.0; - amax(ret, 0); //no negative costs for >100% discounts (impossible in original H3 mechanics, but some day...) + vstd::amax(ret, 0); //no negative costs for >100% discounts (impossible in original H3 mechanics, but some day...) return ret; } @@ -2325,7 +2320,7 @@ void CStack::init() owner = 255; slot = 255; attackerOwned = false; - position = THex(); + position = SHexField(); counterAttacks = -1; } @@ -2338,7 +2333,7 @@ void CStack::postInit() shots = getCreature()->valOfBonuses(Bonus::SHOTS); counterAttacks = 1 + valOfBonuses(Bonus::ADDITIONAL_RETALIATION); casts = valOfBonuses(Bonus::CASTS); //TODO: set them in cr_abils.txt - state.insert(ALIVE); //alive state indication + state.insert(EBattleStackState::ALIVE); //alive state indication } ui32 CStack::Speed( int turn /*= 0*/ , bool useBind /* = false*/) const @@ -2379,11 +2374,11 @@ si32 CStack::magicResistance() const { if (stack->owner == owner) { - amax(auraBonus, stack->valOfBonuses(Bonus::SPELL_RESISTANCE_AURA)); //max value + vstd::amax(auraBonus, stack->valOfBonuses(Bonus::SPELL_RESISTANCE_AURA)); //max value } } magicResistance += auraBonus; - amin (magicResistance, 100); + vstd::amin (magicResistance, 100); } else magicResistance = type->magicResistance(); @@ -2437,7 +2432,7 @@ void CStack::stackEffectToFeature(std::vector & sf, const Bonus & sse) sf.back().sid = sse.sid; break; case 34: //anti-magic - sf.push_back(featureGenerator(Bonus::LEVEL_SPELL_IMMUNITY, SPELL_LEVELS, power - 1, sse.turnsRemain)); + sf.push_back(featureGenerator(Bonus::LEVEL_SPELL_IMMUNITY, GameConstants::SPELL_LEVELS, power - 1, sse.turnsRemain)); sf.back().valType = Bonus::INDEPENDENT_MAX; sf.back().sid = sse.sid; break; @@ -2586,7 +2581,7 @@ ui8 CStack::howManyEffectsSet(ui16 id) const bool CStack::willMove(int turn /*= 0*/) const { - return ( turn ? true : !vstd::contains(state, DEFENDING) ) + return ( turn ? true : !vstd::contains(state, EBattleStackState::DEFENDING) ) && !moved(turn) && canMove(turn); } @@ -2600,7 +2595,7 @@ bool CStack::canMove( int turn /*= 0*/ ) const bool CStack::moved( int turn /*= 0*/ ) const { if(!turn) - return vstd::contains(state, MOVED); + return vstd::contains(state, EBattleStackState::MOVED); else return false; } @@ -2610,7 +2605,7 @@ bool CStack::doubleWide() const return getCreature()->doubleWide; } -THex CStack::occupiedHex() const +SHexField CStack::occupiedHex() const { if (doubleWide()) { @@ -2621,54 +2616,54 @@ THex CStack::occupiedHex() const } else { - return THex::INVALID; + return SHexField::INVALID; } } -std::vector CStack::getHexes() const +std::vector CStack::getHexes() const { - std::vector hexes; - hexes.push_back(THex(position)); - THex occupied = occupiedHex(); + std::vector hexes; + hexes.push_back(SHexField(position)); + SHexField occupied = occupiedHex(); if(occupied.isValid()) hexes.push_back(occupied); return hexes; } -bool CStack::coversPos(THex pos) const +bool CStack::coversPos(SHexField pos) const { return vstd::contains(getHexes(), pos); } -std::vector CStack::getSurroundingHexes(THex attackerPos) const +std::vector CStack::getSurroundingHexes(SHexField attackerPos) const { - THex hex = (attackerPos != THex::INVALID) ? attackerPos : position; //use hypothetical position - std::vector hexes; + SHexField hex = (attackerPos != SHexField::INVALID) ? attackerPos : position; //use hypothetical position + std::vector hexes; if (doubleWide()) { - const int WN = BFIELD_WIDTH; + const int WN = GameConstants::BFIELD_WIDTH; if(attackerOwned) { //position is equal to front hex - THex::checkAndPush(hex - ( (hex/WN)%2 ? WN+2 : WN+1 ), hexes); - THex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); - THex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); - THex::checkAndPush(hex - 2, hexes); - THex::checkAndPush(hex + 1, hexes); - THex::checkAndPush(hex + ( (hex/WN)%2 ? WN-2 : WN-1 ), hexes); - THex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); - THex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); + SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN+2 : WN+1 ), hexes); + SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); + SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); + SHexField::checkAndPush(hex - 2, hexes); + SHexField::checkAndPush(hex + 1, hexes); + SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN-2 : WN-1 ), hexes); + SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); + SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); } else { - THex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); - THex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); - THex::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN-2 ), hexes); - THex::checkAndPush(hex + 2, hexes); - THex::checkAndPush(hex - 1, hexes); - THex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); - THex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); - THex::checkAndPush(hex + ( (hex/WN)%2 ? WN+1 : WN+2 ), hexes); + SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); + SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); + SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN-2 ), hexes); + SHexField::checkAndPush(hex + 2, hexes); + SHexField::checkAndPush(hex - 1, hexes); + SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); + SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); + SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN+1 : WN+2 ), hexes); } return hexes; } @@ -2750,11 +2745,11 @@ void CStack::prepareAttacked(BattleStackAttacked &bsa) const { int resurrectedCount = base->count * resurrectFactor / 100; if (resurrectedCount) - resurrectedCount += ((base->count * resurrectFactor / 100.0f - resurrectedCount) > ran()%100 / 100.0f) ? 1 : 0; //last stack has proportional chance to rebirth + resurrectedCount += ((base->count * resurrectFactor / 100.0 - resurrectedCount) > ran()%100 / 100.0) ? 1 : 0; //last stack has proportional chance to rebirth else //only one unit - resurrectedCount += ((base->count * resurrectFactor / 100.0f) > ran()%100 / 100.0f) ? 1 : 0; + resurrectedCount += ((base->count * resurrectFactor / 100.0) > ran()%100 / 100.0) ? 1 : 0; if (hasBonusOfType(Bonus::REBIRTH, 1)) - amax (resurrectedCount, 1); //resurrect at least one Sacred Phoenix + vstd::amax (resurrectedCount, 1); //resurrect at least one Sacred Phoenix if (resurrectedCount) { bsa.flags |= BattleStackAttacked::REBIRTH; @@ -2769,7 +2764,7 @@ void CStack::prepareAttacked(BattleStackAttacked &bsa) const } } -bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defender, THex attackerPos /*= THex::INVALID*/, THex defenderPos /*= THex::INVALID*/) +bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defender, SHexField attackerPos /*= SHexField::INVALID*/, SHexField defenderPos /*= SHexField::INVALID*/) { if (!attackerPos.isValid()) { @@ -2781,13 +2776,13 @@ bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defen } return - (THex::mutualPosition(attackerPos, defenderPos) >= 0) //front <=> front + (SHexField::mutualPosition(attackerPos, defenderPos) >= 0) //front <=> front || (attacker->doubleWide() //back <=> front - && THex::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos) >= 0) + && SHexField::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos) >= 0) || (defender->doubleWide() //front <=> back - && THex::mutualPosition(attackerPos, defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0) + && SHexField::mutualPosition(attackerPos, defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0) || (defender->doubleWide() && attacker->doubleWide()//back <=> back - && THex::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0); + && SHexField::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0); } diff --git a/lib/BattleState.h b/lib/BattleState.h index f63a7804f..f4f6f29d0 100644 --- a/lib/BattleState.h +++ b/lib/BattleState.h @@ -1,12 +1,14 @@ #pragma once -#include "../global.h" + +#include "SHexField.h" #include "HeroBonus.h" #include "CCreatureSet.h" #include "CObjectHandler.h" #include "CCreatureHandler.h" #include "CObstacleInstance.h" #include "ConstTransitivePtr.h" +#include "GameConstants.h" /* * BattleState.h, part of VCMI engine @@ -25,35 +27,36 @@ class CGTownInstance; class CStackInstance; struct BattleStackAttacked; + //only for use in BattleInfo -struct DLL_EXPORT SiegeInfo +struct DLL_LINKAGE SiegeInfo { ui8 wallState[8]; //[0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; 1 - intact, 2 - damaged, 3 - destroyed - + template void serialize(Handler &h, const int version) { h & wallState; } }; -struct DLL_EXPORT AttackableTiles +struct DLL_LINKAGE AttackableTiles { - std::set hostileCreaturePositions; - std::set friendlyCreaturePositions; //for Dragon Breath + std::set hostileCreaturePositions; + std::set friendlyCreaturePositions; //for Dragon Breath template void serialize(Handler &h, const int version) { h & hostileCreaturePositions & friendlyCreaturePositions; } }; -struct DLL_EXPORT BattleInfo : public CBonusSystemNode +struct DLL_LINKAGE BattleInfo : public CBonusSystemNode { ui8 sides[2]; //sides[0] - attacker, sides[1] - defender si32 round, activeStack; ui8 siege; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle const CGTownInstance * town; //used during town siege - id of attacked town; -1 if not town defence int3 tile; //for background and bonuses - CGHeroInstance *heroes[2]; + CGHeroInstance* heroes[2]; CArmedInstance *belligerents[2]; //may be same as heroes std::vector stacks; std::vector obstacles; @@ -84,14 +87,14 @@ struct DLL_EXPORT BattleInfo : public CBonusSystemNode void getStackQueue(std::vector &out, int howMany, int turn = 0, int lastMoved = -1) const; //returns stack in order of their movement action CStack * getStack(int stackID, bool onlyAlive = true); const CStack * getStack(int stackID, bool onlyAlive = true) const; - CStack * getStackT(THex tileID, bool onlyAlive = true); - const CStack * getStackT(THex tileID, bool onlyAlive = true) const; - void getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack* stackToOmmit = NULL) const; //send pointer to at least 187 allocated bytes - static bool isAccessible(THex hex, bool * accessibility, bool twoHex, bool attackerOwned, bool flying, bool lastPos); //helper for makeBFS + CStack * getStackT(SHexField tileID, bool onlyAlive = true); + const CStack * getStackT(SHexField tileID, bool onlyAlive = true) const; + void getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack* stackToOmmit = NULL) const; //send pointer to at least 187 allocated bytes + static bool isAccessible(SHexField hex, bool * accessibility, bool twoHex, bool attackerOwned, bool flying, bool lastPos); //helper for makeBFS int getAvaliableHex(TCreature creID, bool attackerOwned, int initialPos = -1) const; //find place for summon / clone effects - void makeBFS(THex start, bool*accessibility, THex *predecessor, int *dists, bool twoHex, bool attackerOwned, bool flying, bool fillPredecessors) const; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result - std::pair< std::vector, int > getPath(THex start, THex dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned); //returned value: pair; length may be different than number of elements in path since flying vreatures jump between distant hexes - std::vector getAccessibility(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL) const; //returns vector of accessible tiles (taking into account the creature range) + void makeBFS(SHexField start, bool*accessibility, SHexField *predecessor, int *dists, bool twoHex, bool attackerOwned, bool flying, bool fillPredecessors) const; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result + std::pair< std::vector, int > getPath(SHexField start, SHexField dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned); //returned value: pair; length may be different than number of elements in path since flying vreatures jump between distant hexes + std::vector getAccessibility(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL) const; //returns vector of accessible tiles (taking into account the creature range) bool isStackBlocked(const CStack * stack) const; //returns true if there is neighboring enemy stack @@ -99,56 +102,56 @@ struct DLL_EXPORT BattleInfo : public CBonusSystemNode TDmgRange calculateDmgRange(const CStack* attacker, const CStack* defender, TQuantity attackerCount, TQuantity defenderCount, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky, bool deathBlow, bool ballistaDoubleDmg) const; //charge - number of hexes travelled before attack (for champion's jousting); returns pair TDmgRange calculateDmgRange(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky, bool deathBlow, bool ballistaDoubleDmg) const; //charge - number of hexes travelled before attack (for champion's jousting); returns pair void calculateCasualties(std::map *casualties) const; //casualties are array of maps size 2 (attacker, defeneder), maps are (crid => amount) - std::set getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, THex destinationTile); //calculates stack affected by given spell - void getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, THex destinationTile, THex attackerPos); //hexes around target that could be attacked in melee - std::set getAttackedCreatures(const CStack* attacker, THex destinationTile, THex attackerPos = THex::INVALID); //calculates range of multi-hex attacks - std::set getAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos = THex::INVALID); //calculates range of multi-hex attacks + std::set getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, SHexField destinationTile); //calculates stack affected by given spell + void getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, SHexField destinationTile, SHexField attackerPos); //hexes around target that could be attacked in melee + std::set getAttackedCreatures(const CStack* attacker, SHexField destinationTile, SHexField attackerPos = SHexField::INVALID); //calculates range of multi-hex attacks + std::set getAttackedHexes(const CStack* attacker, SHexField destinationTile, SHexField attackerPos = SHexField::INVALID); //calculates range of multi-hex attacks std::set getAdjacentCreatures (const CStack * stack) const; static int calculateSpellDuration(const CSpell * spell, const CGHeroInstance * caster, int usedSpellPower); - CStack * generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, THex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield - CStack * generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, THex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield + CStack * generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, SHexField position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield + CStack * generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, SHexField position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield ui32 getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //returns cost of given spell - int hexToWallPart(THex hex) const; //returns part of destructible wall / gate / keep under given hex or -1 if not found + int hexToWallPart(SHexField hex) const; //returns part of destructible wall / gate / keep under given hex or -1 if not found int lineToWallHex(int line) const; //returns hex with wall in given line - std::pair getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const; //if attackerOwned is indetermnate, returened stack is of any owner; hex is the number of hex we should be looking from; returns (nerarest creature, predecessorHex) + std::pair getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const; //if attackerOwned is indetermnate, returened stack is of any owner; hex is the number of hex we should be looking from; returns (nerarest creature, predecessorHex) ui32 calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature) const; ui32 calculateSpellDmg(const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature, int spellSchoolLevel, int usedSpellPower) const; //calculates damage inflicted by spell ui32 calculateHealedHP(const CGHeroInstance * caster, const CSpell * spell, const CStack * stack) const; ui32 calculateHealedHP(int healedHealth, const CSpell * spell, const CStack * stack) const; //for Archangel ui32 calculateHealedHP(const CSpell * spell, int usedSpellPower, int spellSchoolLevel, const CStack * stack) const; //unused bool resurrects(TSpell spellid) const; //TODO: move it to spellHandler? - si8 hasDistancePenalty(const CStack * stackID, THex destHex) const; //determines if given stack has distance penalty shooting given pos + si8 hasDistancePenalty(const CStack * stackID, SHexField destHex) const; //determines if given stack has distance penalty shooting given pos si8 sameSideOfWall(int pos1, int pos2) const; //determines if given positions are on the same side of wall - si8 hasWallPenalty(const CStack * stack, THex destHex) const; //determines if given stack has wall penalty shooting given pos - si8 canTeleportTo(const CStack * stack, THex destHex, int telportLevel) const; //determines if given stack can teleport to given place - bool battleCanShoot(const CStack * stack, THex dest) const; //determines if stack with given ID shoot at the selected destination + si8 hasWallPenalty(const CStack * stack, SHexField destHex) const; //determines if given stack has wall penalty shooting given pos + si8 canTeleportTo(const CStack * stack, SHexField destHex, int telportLevel) const; //determines if given stack can teleport to given place + bool battleCanShoot(const CStack * stack, SHexField dest) const; //determines if stack with given ID shoot at the selected destination const CGHeroInstance * getHero(int player) const; //returns fighting hero that belongs to given player - SpellCasting::ESpellCastProblem battleCanCastSpell(int player, SpellCasting::ECastingMode mode) const; //returns true if there are no general issues preventing from casting a spell - SpellCasting::ESpellCastProblem battleCanCastThisSpell(int player, const CSpell * spell, SpellCasting::ECastingMode mode) const; //checks if given player can cast given spell - SpellCasting::ESpellCastProblem battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, SpellCasting::ECastingMode mode, THex dest) const; //checks for creature immunity / anything that prevent casting *at given hex* - doesn't take into acount general problems such as not having spellbook or mana points etc. - SpellCasting::ESpellCastProblem battleCanCastThisSpellHere(int player, const CSpell * spell, SpellCasting::ECastingMode mode, THex dest) const; //checks if given player can cast given spell at given tile in given mode + ESpellCastProblem::ESpellCastProblem battleCanCastSpell(int player, ECastingMode::ECastingMode mode) const; //returns true if there are no general issues preventing from casting a spell + ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(int player, const CSpell * spell, ECastingMode::ECastingMode mode) const; //checks if given player can cast given spell + ESpellCastProblem::ESpellCastProblem battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, ECastingMode::ECastingMode mode, SHexField dest) const; //checks for creature immunity / anything that prevent casting *at given hex* - doesn't take into acount general problems such as not having spellbook or mana points etc. + ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(int player, const CSpell * spell, ECastingMode::ECastingMode mode, SHexField dest) const; //checks if given player can cast given spell at given tile in given mode bool battleTestElementalImmunity(const CStack * subject, const CSpell * spell, Bonus::BonusType element, bool damageSpell) const; TSpell getRandomBeneficialSpell(const CStack * subject) const; TSpell getRandomCastedSpell(const CStack * caster) const; //called at the beginning of turn for Faerie Dragon - std::vector calculateResistedStacks(const CSpell * sp, const CGHeroInstance * caster, const CGHeroInstance * hero2, const std::set affectedCreatures, int casterSideOwner, SpellCasting::ECastingMode mode) const; + std::vector calculateResistedStacks(const CSpell * sp, const CGHeroInstance * caster, const CGHeroInstance * hero2, const std::set affectedCreatures, int casterSideOwner, ECastingMode::ECastingMode mode) const; bool battleCanFlee(int player) const; //returns true if player can flee from the battle - const CStack * battleGetStack(THex pos, bool onlyAlive); //returns stack at given tile + const CStack * battleGetStack(SHexField pos, bool onlyAlive); //returns stack at given tile const CGHeroInstance * battleGetOwner(const CStack * stack) const; //returns hero that owns given stack; NULL if none si8 battleMinSpellLevel() const; //calculates minimum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned void localInit(); static BattleInfo * setupBattle( int3 tile, int terrain, int terType, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town ); - bool isInTacticRange( THex dest ) const; + bool isInTacticRange( SHexField dest ) const; int getSurrenderingCost(int player) const; int theOtherPlayer(int player) const; ui8 whatSide(int player) const; }; -class DLL_EXPORT CStack : public CBonusSystemNode, public CStackBasicDescriptor +class DLL_LINKAGE CStack : public CBonusSystemNode, public CStackBasicDescriptor { public: const CStackInstance *base; @@ -158,12 +161,12 @@ public: ui32 firstHPleft; //HP of first creature in stack ui8 owner, slot; //owner - player colour (255 for neutrals), slot - position in garrison (may be 255 for neutrals/called creatures) ui8 attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle) - THex position; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower + SHexField position; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower ui8 counterAttacks; //how many counter attacks can be performed more in this turn (by default set at the beginning of the round to 1) si16 shots; //how many shots left ui8 casts; //how many casts left - std::set state; + std::set state; //overrides const CCreature* getCreature() const {return type;} @@ -204,13 +207,13 @@ public: return ret; } - static bool isMeleeAttackPossible(const CStack * attacker, const CStack * defender, THex attackerPos = THex::INVALID, THex defenderPos = THex::INVALID); + static bool isMeleeAttackPossible(const CStack * attacker, const CStack * defender, SHexField attackerPos = SHexField::INVALID, SHexField defenderPos = SHexField::INVALID); bool doubleWide() const; - THex occupiedHex() const; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1 - std::vector getHexes() const; //up to two occupied hexes, starting from front - bool coversPos(THex position) const; //checks also if unit is double-wide - std::vector getSurroundingHexes(THex attackerPos = THex::INVALID) const; // get six or 8 surrounding hexes depending on creature size + SHexField occupiedHex() const; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1 + std::vector getHexes() const; //up to two occupied hexes, starting from front + bool coversPos(SHexField position) const; //checks also if unit is double-wide + std::vector getSurroundingHexes(SHexField attackerPos = SHexField::INVALID) const; // get six or 8 surrounding hexes depending on creature size void prepareAttacked(BattleStackAttacked &bsa) const; //requires bsa.damageAmout filled @@ -245,11 +248,11 @@ public: } bool alive() const //determines if stack is alive { - return vstd::contains(state,ALIVE); + return vstd::contains(state,EBattleStackState::ALIVE); } }; -class DLL_EXPORT CMP_stack +class DLL_LINKAGE CMP_stack { int phase; //rules of which phase will be used int turn; diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index 838df4443..e4b9e5230 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -1,16 +1,9 @@ -#define VCMI_DLL -#include "../stdafx.h" +#include "StdInc.h" #include "CArtHandler.h" + #include "CLodHandler.h" #include "CGeneralTextHandler.h" -#include -#include -#include -#include -#include -#include #include -#include #include "../lib/VCMI_Lib.h" #include "CSpellHandler.h" #include "CObjectHandler.h" @@ -226,10 +219,10 @@ void CArtHandler::loadArtifacts(bool onlyTxt) { loadToIt(dump,buf,it,3); } - VLC->generaltexth->artifNames.resize(ARTIFACTS_QUANTITY); - VLC->generaltexth->artifDescriptions.resize(ARTIFACTS_QUANTITY); + VLC->generaltexth->artifNames.resize(GameConstants::ARTIFACTS_QUANTITY); + VLC->generaltexth->artifDescriptions.resize(GameConstants::ARTIFACTS_QUANTITY); std::map::iterator itr; - for (int i=0; iisBig()) //discard big artifact - return Arts::BACKPACK_START + h->artifactsInBackpack.size(); + return GameConstants::BACKPACK_START + h->artifactsInBackpack.size(); return -1; } bool CArtifactInstance::canBePutAt(const ArtifactLocation &al, bool assumeDestRemoved /*= false*/) const { - if(al.slot >= Arts::BACKPACK_START) + if(al.slot >= GameConstants::BACKPACK_START) { if(artType->isBig()) return false; @@ -972,7 +965,7 @@ void CArtifactInstance::putAt(CGHeroInstance *h, ui16 slot) assert(canBePutAt(ArtifactLocation(h, slot))); h->setNewArtSlot(slot, this, false); - if(slot < Arts::BACKPACK_START) + if(slot < GameConstants::BACKPACK_START) h->attachTo(this); } @@ -980,7 +973,7 @@ void CArtifactInstance::removeFrom(CGHeroInstance *h, ui16 slot) { assert(h->CArtifactSet::getArt(slot) == this); h->eraseArtSlot(slot); - if(slot < Arts::BACKPACK_START) + if(slot < GameConstants::BACKPACK_START) h->detachFrom(this); //TODO delete me? @@ -1024,7 +1017,7 @@ void CArtifactInstance::move(ArtifactLocation &src, ArtifactLocation &dst) { removeFrom(src.hero, src.slot); putAt(dst.hero, dst.slot); - if (artType->id == 135 && dst.slot == Arts::RIGHT_HAND && !dst.hero->hasSpellbook()) //Titan's Thunder creates new spellbook on equip + if (artType->id == 135 && dst.slot == ArtifactPosition::RIGHT_HAND && !dst.hero->hasSpellbook()) //Titan's Thunder creates new spellbook on equip dst.hero->giveArtifact(0); } @@ -1071,7 +1064,7 @@ bool CCombinedArtifactInstance::canBePutAt(const ArtifactLocation &al, bool assu bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(al, assumeDestRemoved); if(!canMainArtifactBePlaced) return false; //no is no... - if(al.slot >= Arts::BACKPACK_START) + if(al.slot >= GameConstants::BACKPACK_START) return true; //we can always remove combined art to the backapck @@ -1087,7 +1080,7 @@ bool CCombinedArtifactInstance::canBePutAt(const ArtifactLocation &al, bool assu } //we iterate over all active slots and check if constituents fits them - for (int i = 0; i < Arts::BACKPACK_START; i++) + for (int i = 0; i < GameConstants::BACKPACK_START; i++) { for(std::vector::iterator art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++) { @@ -1137,7 +1130,7 @@ void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, int slo void CCombinedArtifactInstance::putAt(CGHeroInstance *h, ui16 slot) { - if(slot >= Arts::BACKPACK_START) + if(slot >= GameConstants::BACKPACK_START) { CArtifactInstance::putAt(h, slot); BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo) @@ -1153,12 +1146,12 @@ void CCombinedArtifactInstance::putAt(CGHeroInstance *h, ui16 slot) if(ci.art != mainConstituent) { int pos = -1; - if(isbetw(ci.slot, 0, Arts::BACKPACK_START) && ci.art->canBePutAt(ArtifactLocation(h, ci.slot))) //there is a valid suggestion where to place lock + if(vstd::isbetween(ci.slot, 0, GameConstants::BACKPACK_START) && ci.art->canBePutAt(ArtifactLocation(h, ci.slot))) //there is a valid suggestion where to place lock pos = ci.slot; else ci.slot = pos = ci.art->firstAvailableSlot(h); - assert(pos < Arts::BACKPACK_START); + assert(pos < GameConstants::BACKPACK_START); h->setNewArtSlot(pos, ci.art, true); //sets as lock } else @@ -1171,7 +1164,7 @@ void CCombinedArtifactInstance::putAt(CGHeroInstance *h, ui16 slot) void CCombinedArtifactInstance::removeFrom(CGHeroInstance *h, ui16 slot) { - if(slot >= Arts::BACKPACK_START) + if(slot >= GameConstants::BACKPACK_START) { CArtifactInstance::removeFrom(h, slot); } @@ -1292,7 +1285,7 @@ si32 CArtifactSet::getArtPos(int aid, bool onlyWorn /*= true*/) const for(int i = 0; i < artifactsInBackpack.size(); i++) if(artifactsInBackpack[i].artifact->artType->id == aid) - return Arts::BACKPACK_START + i; + return GameConstants::BACKPACK_START + i; return -1; } @@ -1305,7 +1298,7 @@ si32 CArtifactSet::getArtPos(const CArtifactInstance *art) const for(int i = 0; i < artifactsInBackpack.size(); i++) if(artifactsInBackpack[i].artifact == art) - return Arts::BACKPACK_START + i; + return GameConstants::BACKPACK_START + i; return -1; } @@ -1327,9 +1320,9 @@ const ArtSlotInfo * CArtifactSet::getSlot(ui16 pos) const { if(vstd::contains(artifactsWorn, pos)) return &artifactsWorn[pos]; - if(pos >= Arts::AFTER_LAST ) + if(pos >= ArtifactPosition::AFTER_LAST ) { - int backpackPos = (int)pos - Arts::BACKPACK_START; + int backpackPos = (int)pos - GameConstants::BACKPACK_START; if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size()) return NULL; else @@ -1358,22 +1351,22 @@ CArtifactSet::~CArtifactSet() ArtSlotInfo & CArtifactSet::retreiveNewArtSlot(ui16 slot) { assert(!vstd::contains(artifactsWorn, slot)); - ArtSlotInfo &ret = slot < Arts::BACKPACK_START + ArtSlotInfo &ret = slot < GameConstants::BACKPACK_START ? artifactsWorn[slot] - : *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - Arts::BACKPACK_START), ArtSlotInfo()); + : *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo()); return ret; } void CArtifactSet::eraseArtSlot(ui16 slot) { - if(slot < Arts::BACKPACK_START) + if(slot < GameConstants::BACKPACK_START) { artifactsWorn.erase(slot); } else { - slot -= Arts::BACKPACK_START; + slot -= GameConstants::BACKPACK_START; artifactsInBackpack.erase(artifactsInBackpack.begin() + slot); } } @@ -1381,7 +1374,7 @@ void CArtifactSet::eraseArtSlot(ui16 slot) ArtSlotInfo & CCreatureArtifactSet::retreiveNewArtSlot(ui16 slot) { assert(slot); //ke? - ArtSlotInfo &ret = slot <= Arts::CREATURE_ART + ArtSlotInfo &ret = slot <= GameConstants::CREATURE_ART ? activeArtifact : *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - 1), ArtSlotInfo()); @@ -1390,7 +1383,7 @@ ArtSlotInfo & CCreatureArtifactSet::retreiveNewArtSlot(ui16 slot) void CCreatureArtifactSet::eraseArtSlot(ui16 slot) { - if(slot == Arts::CREATURE_ART) + if(slot == GameConstants::CREATURE_ART) { activeArtifact.artifact = NULL; //hmm? } @@ -1403,9 +1396,9 @@ void CCreatureArtifactSet::eraseArtSlot(ui16 slot) const ArtSlotInfo * CCreatureArtifactSet::getSlot(ui16 pos) const { - if (pos == Arts::CREATURE_ART) + if (pos == GameConstants::CREATURE_ART) return &activeArtifact; - else if(pos > Arts::CREATURE_ART) + else if(pos > GameConstants::CREATURE_ART) { int backpackPos = (int)pos - 1; if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size()) @@ -1419,7 +1412,7 @@ const ArtSlotInfo * CCreatureArtifactSet::getSlot(ui16 pos) const si32 CCreatureArtifactSet::getArtPos(int aid, bool onlyWorn) const { if (aid == activeArtifact.artifact->artType->id ) - return Arts::CREATURE_ART; + return GameConstants::CREATURE_ART; if(onlyWorn) return -1; @@ -1436,11 +1429,11 @@ si32 CCreatureArtifactSet::getArtPos(int aid, bool onlyWorn) const si32 CCreatureArtifactSet::getArtPos(const CArtifactInstance *art) const { if (activeArtifact.artifact == art) - return Arts::CREATURE_ART; + return GameConstants::CREATURE_ART; for(int i = 0; i < artifactsInBackpack.size(); i++) if(artifactsInBackpack[i].artifact == art) - return Arts::BACKPACK_START + i; + return GameConstants::BACKPACK_START + i; return -1; } diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index 3682e74ca..5c9be27e3 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -1,10 +1,7 @@ -#ifndef __CARTHANDLER_H__ -#define __CARTHANDLER_H__ -#include "../global.h" -#include "../lib/HeroBonus.h" -#include -#include +#pragma once + +#include "../lib/HeroBonus.h" #include "../lib/ConstTransitivePtr.h" /* @@ -21,7 +18,18 @@ class CArtifact; class CGHeroInstance; struct ArtifactLocation; -class DLL_EXPORT CArtifact : public CBonusSystemNode //container for artifacts +namespace ArtifactPosition +{ + enum ArtifactPosition + { + PRE_FIRST = -1, + HEAD, SHOULDERS, NECK, RIGHT_HAND, LEFT_HAND, TORSO, RIGHT_RING, LEFT_RING, FEET, MISC1, MISC2, MISC3, MISC4, + MACH1, MACH2, MACH3, MACH4, SPELLBOOK, MISC5, + AFTER_LAST + }; +} + +class DLL_LINKAGE CArtifact : public CBonusSystemNode //container for artifacts { protected: std::string name, description; //set if custom @@ -54,7 +62,7 @@ public: //void getParents(TCNodes &out, const CBonusSystemNode *root = NULL) const; }; -class DLL_EXPORT CArtifactInstance : public CBonusSystemNode +class DLL_LINKAGE CArtifactInstance : public CBonusSystemNode { protected: void init(); @@ -96,7 +104,7 @@ public: static CArtifactInstance *createNewArtifactInstance(int aid); }; -class DLL_EXPORT CCombinedArtifactInstance : public CArtifactInstance +class DLL_LINKAGE CCombinedArtifactInstance : public CArtifactInstance { CCombinedArtifactInstance(CArtifact *Art); public: @@ -139,7 +147,7 @@ public: } }; -// class DLL_EXPORT IModableArt : public CArtifact //artifact which can have different properties, such as scroll or banner +// class DLL_LINKAGE IModableArt : public CArtifact //artifact which can have different properties, such as scroll or banner // { //used only for dynamic cast :P // public: // si32 ID; //used for smart serialization @@ -151,7 +159,7 @@ public: // } // }; // -// class DLL_EXPORT CScroll : public IModableArt // Spell Scroll +// class DLL_LINKAGE CScroll : public IModableArt // Spell Scroll // { // public: // CScroll(){spellid=0;}; @@ -166,7 +174,7 @@ public: // } // }; // -// class DLL_EXPORT CCustomizableArt : public IModableArt // Warlord's Banner with multiple options +// class DLL_LINKAGE CCustomizableArt : public IModableArt // Warlord's Banner with multiple options // { // public: // ui8 mode; @@ -180,7 +188,7 @@ public: // } // }; // -// class DLL_EXPORT CCommanderArt : public IModableArt // Growing with time +// class DLL_LINKAGE CCommanderArt : public IModableArt // Growing with time // { // public: // ui32 level; @@ -195,7 +203,7 @@ public: // } // }; -class DLL_EXPORT CArtHandler //handles artifacts +class DLL_LINKAGE CArtHandler //handles artifacts { void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER, ILimiter * limiter = NULL); void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype, IPropagator* propagator); @@ -231,7 +239,7 @@ public: } }; -struct DLL_EXPORT ArtSlotInfo +struct DLL_LINKAGE ArtSlotInfo { ConstTransitivePtr artifact; ui8 locked; //if locked, then artifact points to the combined artifact @@ -246,7 +254,7 @@ struct DLL_EXPORT ArtSlotInfo } }; -class DLL_EXPORT IArtifactSetBase +class DLL_LINKAGE IArtifactSetBase { ///artifacts container public: virtual void setNewArtSlot(ui16 slot, CArtifactInstance *art, bool locked); @@ -265,7 +273,7 @@ public: virtual si32 getArtTypeId(ui16 pos) const=0; }; -class DLL_EXPORT CArtifactSet : public IArtifactSetBase +class DLL_LINKAGE CArtifactSet : public IArtifactSetBase { ///hero artifacts public: std::vector artifactsInBackpack; //hero's artifacts from bag @@ -288,7 +296,7 @@ public: } }; -class DLL_EXPORT CCreatureArtifactSet : public IArtifactSetBase +class DLL_LINKAGE CCreatureArtifactSet : public IArtifactSetBase { ///creature artifacts public: std::vector artifactsInBackpack; //artifacts carried by creature - 4 max @@ -310,5 +318,3 @@ public: h & artifactsInBackpack & activeArtifact; } }; - -#endif // __CARTHANDLER_H__ diff --git a/lib/CBuildingHandler.cpp b/lib/CBuildingHandler.cpp index 061b94bcf..37201b7e8 100644 --- a/lib/CBuildingHandler.cpp +++ b/lib/CBuildingHandler.cpp @@ -1,15 +1,11 @@ -#define VCMI_DLL -#include "../stdafx.h" +#include "StdInc.h" #include "CBuildingHandler.h" + #include "CGeneralTextHandler.h" #include "CLodHandler.h" #include "../lib/VCMI_Lib.h" -#include -#include -#include -#include -#include #include "../lib/JsonNode.h" +#include "GameConstants.h" extern CLodHandler * bitmaph; @@ -23,7 +19,7 @@ extern CLodHandler * bitmaph; * */ -static unsigned int readNr(std::string &in, int &it) +static ui32 readNr(std::string &in, int &it) { int last=it; for(;lasttid = f; @@ -83,12 +79,12 @@ void CBuildingHandler::loadBuildings() } //create Grail entries - for(int i=0; i builtBu return campToERMU[camp]; } - static const std::vector hordeLvlsPerTType[F_NUMBER] = {list_of(2), list_of(1), list_of(1)(4), list_of(0)(2), + static const std::vector hordeLvlsPerTType[GameConstants::F_NUMBER] = {list_of(2), list_of(1), list_of(1)(4), list_of(0)(2), list_of(0), list_of(0), list_of(0), list_of(0), list_of(0)}; int curPos = campToERMU.size(); diff --git a/lib/CBuildingHandler.h b/lib/CBuildingHandler.h index 80a43148d..e36f0295f 100644 --- a/lib/CBuildingHandler.h +++ b/lib/CBuildingHandler.h @@ -1,9 +1,5 @@ -#ifndef __CBUILDINGHANDLER_H__ -#define __CBUILDINGHANDLER_H__ -#include "../global.h" -#include -#include -#include +#pragma once + #include "../lib/ConstTransitivePtr.h" #include "ResourceSet.h" @@ -19,7 +15,7 @@ */ //enum EbuildingType {NEUTRAL=-1, CASTLE, RAMPART, TOWER, INFERNO, NECROPOLIS, DUNGEON, STRONGHOLD, FORTRESS, CONFLUX}; -class DLL_EXPORT CBuilding //a typical building encountered in every castle ;] +class DLL_LINKAGE CBuilding //a typical building encountered in every castle ;] { public: si32 tid, bid; //town ID and structure ID @@ -37,7 +33,7 @@ public: CBuilding(int TID = -1, int BID = -1); }; -class DLL_EXPORT CBuildingHandler +class DLL_LINKAGE CBuildingHandler { public: std::vector< bmap > > buildings; ///< vector by castle ID, second the building ID (in ERM-U format) @@ -52,6 +48,3 @@ public: h & buildings & hall; } }; - - -#endif // __CBUILDINGHANDLER_H__ diff --git a/lib/CCampaignHandler.cpp b/lib/CCampaignHandler.cpp index 57958ab6f..4c9ad6404 100644 --- a/lib/CCampaignHandler.cpp +++ b/lib/CCampaignHandler.cpp @@ -1,18 +1,14 @@ -#define VCMI_DLL - +#include "StdInc.h" #include "CCampaignHandler.h" -#include -#include -#include + #include "CLodHandler.h" #include "../lib/VCMI_Lib.h" #include "../lib/vcmi_endian.h" #include "CGeneralTextHandler.h" -#include "../StartInfo.h" +#include "StartInfo.h" #include "CArtHandler.h" //for hero crossover #include "CObjectHandler.h" //for hero crossover #include "CHeroHandler.h" -#include namespace fs = boost::filesystem; @@ -31,7 +27,7 @@ std::vector CCampaignHandler::getCampaignHeaders(GetMode mode) { std::vector ret; - std::string dirname = DATA_DIR "/Maps"; + std::string dirname = GameConstants::DATA_DIR + "/Maps"; std::string ext = ".H3C"; if(!boost::filesystem::exists(dirname)) @@ -70,7 +66,7 @@ std::vector CCampaignHandler::getCampaignHeaders(GetMode mode) CCampaignHeader CCampaignHandler::getHeader( const std::string & name, bool fromLod ) { int realSize; - unsigned char * cmpgn = getFile(name, fromLod, realSize); + ui8 * cmpgn = getFile(name, fromLod, realSize); int it = 0;//iterator for reading CCampaignHeader ret = readHeaderFromMemory(cmpgn, it); @@ -87,7 +83,7 @@ CCampaign * CCampaignHandler::getCampaign( const std::string & name, bool fromLo CCampaign * ret = new CCampaign(); int realSize; - unsigned char * cmpgn = getFile(name, fromLod, realSize); + ui8 * cmpgn = getFile(name, fromLod, realSize); int it = 0; //iterator for reading ret->header = readHeaderFromMemory(cmpgn, it); @@ -139,7 +135,7 @@ CCampaign * CCampaignHandler::getCampaign( const std::string & name, bool fromLo return ret; } -CCampaignHeader CCampaignHandler::readHeaderFromMemory( const unsigned char *buffer, int & outIt ) +CCampaignHeader CCampaignHandler::readHeaderFromMemory( const ui8 *buffer, int & outIt ) { CCampaignHeader ret; ret.version = read_le_u32(buffer + outIt); outIt+=4; @@ -155,12 +151,12 @@ CCampaignHeader CCampaignHandler::readHeaderFromMemory( const unsigned char *buf return ret; } -CCampaignScenario CCampaignHandler::readScenarioFromMemory( const unsigned char *buffer, int & outIt, int version, int mapVersion ) +CCampaignScenario CCampaignHandler::readScenarioFromMemory( const ui8 *buffer, int & outIt, int version, int mapVersion ) { struct HLP { //reads prolog/epilog info from memory - static CCampaignScenario::SScenarioPrologEpilog prologEpilogReader( const unsigned char *buffer, int & outIt ) + static CCampaignScenario::SScenarioPrologEpilog prologEpilogReader( const ui8 *buffer, int & outIt ) { CCampaignScenario::SScenarioPrologEpilog ret; ret.hasPrologEpilog = buffer[outIt++]; @@ -196,7 +192,7 @@ CCampaignScenario CCampaignHandler::readScenarioFromMemory( const unsigned char return ret; } -CScenarioTravel CCampaignHandler::readScenarioTravelFromMemory( const unsigned char * buffer, int & outIt , int version ) +CScenarioTravel CCampaignHandler::readScenarioTravelFromMemory( const ui8 * buffer, int & outIt , int version ) { CScenarioTravel ret; @@ -328,7 +324,7 @@ CScenarioTravel CCampaignHandler::readScenarioTravelFromMemory( const unsigned c return ret; } -std::vector CCampaignHandler::locateH3mStarts( const unsigned char * buffer, int start, int size ) +std::vector CCampaignHandler::locateH3mStarts( const ui8 * buffer, int start, int size ) { std::vector ret; for(int g=start; g CCampaignHandler::locateH3mStarts( const unsigned char * buffe return ret; } -bool CCampaignHandler::startsAt( const unsigned char * buffer, int size, int pos ) +bool CCampaignHandler::startsAt( const ui8 * buffer, int size, int pos ) { struct HLP { - static unsigned char at(const unsigned char * buffer, int size, int place) + static ui8 at(const ui8 * buffer, int size, int place) { if(place < size) return buffer[place]; @@ -360,7 +356,7 @@ bool CCampaignHandler::startsAt( const unsigned char * buffer, int size, int pos HLP::at(buffer, size, 100); //check version - unsigned char tmp = HLP::at(buffer, size, pos); + ui8 tmp = HLP::at(buffer, size, pos); if(!(tmp == 0x0e || tmp == 0x15 || tmp == 0x1c || tmp == 0x33)) { return false; @@ -413,9 +409,9 @@ bool CCampaignHandler::startsAt( const unsigned char * buffer, int size, int pos return true; } -unsigned char * CCampaignHandler::getFile( const std::string & name, bool fromLod, int & outSize ) +ui8 * CCampaignHandler::getFile( const std::string & name, bool fromLod, int & outSize ) { - unsigned char * cmpgn = 0; + ui8 * cmpgn = 0; if(fromLod) { if (bitmaph->haveFile(name, FILE_CAMPAIGN)) diff --git a/lib/CCampaignHandler.h b/lib/CCampaignHandler.h index 5b1dabd9c..9170422b9 100644 --- a/lib/CCampaignHandler.h +++ b/lib/CCampaignHandler.h @@ -1,9 +1,6 @@ -#ifndef __CCAMPAIGNHANDLER_H__ -#define __CCAMPAIGNHANDLER_H__ +#pragma once + -#include "../global.h" -#include -#include /* * CCampaignHandler.h, part of VCMI engine @@ -29,7 +26,7 @@ namespace CampaignVersion }; } -class DLL_EXPORT CCampaignHeader +class DLL_LINKAGE CCampaignHeader { public: si32 version; //4 - RoE, 5 - AB, 6 - SoD and WoG @@ -47,7 +44,7 @@ public: } }; -class DLL_EXPORT CScenarioTravel +class DLL_LINKAGE CScenarioTravel { public: ui8 whatHeroKeeps; //bitfield [0] - experience, [1] - prim skills, [2] - sec skills, [3] - spells, [4] - artifacts @@ -58,7 +55,7 @@ public: ui8 playerColor; //only for startOptions == 1 - struct DLL_EXPORT STravelBonus + struct DLL_LINKAGE STravelBonus { ui8 type; //0 - spell, 1 - monster, 2 - building, 3 - artifact, 4 - spell scroll, 5 - prim skill, 6 - sec skill, 7 - resource, //8 - player from previous scenario, 9 - hero [???] @@ -81,7 +78,7 @@ public: }; -class DLL_EXPORT CCampaignScenario +class DLL_LINKAGE CCampaignScenario { public: std::string mapName; @@ -93,7 +90,7 @@ public: std::string regionText; - struct DLL_EXPORT SScenarioPrologEpilog + struct DLL_LINKAGE SScenarioPrologEpilog { ui8 hasPrologEpilog; ui8 prologVideo; // from CmpMovie.txt @@ -123,7 +120,7 @@ public: } }; -class DLL_EXPORT CCampaign +class DLL_LINKAGE CCampaign { public: CCampaignHeader header; @@ -140,7 +137,7 @@ public: CCampaign(); }; -class DLL_EXPORT CCampaignState +class DLL_LINKAGE CCampaignState { public: CCampaign *camp; @@ -157,14 +154,14 @@ public: } }; -class DLL_EXPORT CCampaignHandler +class DLL_LINKAGE CCampaignHandler { - static CCampaignHeader readHeaderFromMemory( const unsigned char *buffer, int & outIt ); - static CCampaignScenario readScenarioFromMemory( const unsigned char *buffer, int & outIt, int version, int mapVersion ); - static CScenarioTravel readScenarioTravelFromMemory( const unsigned char * buffer, int & outIt , int version); - static std::vector locateH3mStarts(const unsigned char * buffer, int start, int size); - static bool startsAt( const unsigned char * buffer, int size, int pos ); //a simple heuristic that checks if a h3m starts at given pos - static unsigned char * getFile(const std::string & name, bool fromLod, int & outSize); + static CCampaignHeader readHeaderFromMemory( const ui8 *buffer, int & outIt ); + static CCampaignScenario readScenarioFromMemory( const ui8 *buffer, int & outIt, int version, int mapVersion ); + static CScenarioTravel readScenarioTravelFromMemory( const ui8 * buffer, int & outIt , int version); + static std::vector locateH3mStarts(const ui8 * buffer, int start, int size); + static bool startsAt( const ui8 * buffer, int size, int pos ); //a simple heuristic that checks if a h3m starts at given pos + static ui8 * getFile(const std::string & name, bool fromLod, int & outSize); public: enum GetMode {RoE, AB, SoD, WoG, Custom, ALL}; static std::vector getCampaignHeaders(GetMode mode); @@ -172,6 +169,3 @@ public: static CCampaign * getCampaign(const std::string & name, bool fromLod); //name - name of appropriate file }; - - -#endif /* __CCAMPAIGNHANDLER_H__ */ diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index 25352d265..f4a86d311 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -1,19 +1,9 @@ -#define VCMI_DLL -#include "../stdafx.h" +#include "StdInc.h" #include "CCreatureHandler.h" + #include "CLodHandler.h" -#include -#include -#include -#include -#include -#include -#include -#include #include "../lib/VCMI_Lib.h" #include "../lib/CGameState.h" -#include -#include #include "../lib/JsonNode.h" using namespace boost::assign; @@ -77,7 +67,7 @@ int CCreature::getQuantityID(const int & quantity) return 8; } -int CCreature::estimateCreatureCount(unsigned int countID) +int CCreature::estimateCreatureCount(ui32 countID) { static const int creature_count[] = { 3, 8, 15, 35, 75, 175, 375, 750, 2500 }; @@ -179,7 +169,7 @@ int readNumber(int & befi, int & i, int andame, std::string & buf) //helper func return ret; } -float readFloat(int & befi, int & i, int andame, std::string & buf) //helper function for void CCreatureHandler::loadUnitAnimInfo() +double readFloat(int & befi, int & i, int andame, std::string & buf) //helper function for void CCreatureHandler::loadUnitAnimInfo() { befi=i; for(; i::const_iterator it_map; @@ -498,7 +488,7 @@ void CCreatureHandler::loadCreatures() //std::map >::iterator it = stackBonuses.find(Bonus::MAGIC_RESISTANCE); //stackBonuses[Bonus::SECONDARY_SKILL_PREMY] = std::pair(it->second.first, it->second.second); - if (STACK_EXP) //reading default stack experience bonuses + if (GameConstants::STACK_EXP) //reading default stack experience bonuses { buf = bitmaph->getTextFile("CREXPBON.TXT"); int it = 0; @@ -830,7 +820,7 @@ void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, std::string & src break; case ':': b.type = Bonus::LEVEL_SPELL_IMMUNITY; - b.val = SPELL_LEVELS; //in case someone adds higher level spells? + b.val = GameConstants::SPELL_LEVELS; //in case someone adds higher level spells? break; case 'F': b.type = Bonus::FIRE_IMMUNITY; @@ -1027,7 +1017,7 @@ int CCreatureHandler::pickRandomMonster(const boost::function &randGen, i } else { - assert(iswith(tier, 1, 7)); + assert(vstd::iswithin(tier, 1, 7)); std::vector allowed; BOOST_FOREACH(const CBonusSystemNode *b, creaturesOfLevel[tier].getChildrenNodes()) { @@ -1051,7 +1041,7 @@ int CCreatureHandler::pickRandomMonster(const boost::function &randGen, i void CCreatureHandler::addBonusForTier(int tier, Bonus *b) { - assert(iswith(tier, 1, 7)); + assert(vstd::iswithin(tier, 1, 7)); creaturesOfLevel[tier].addNewBonus(b); } @@ -1064,7 +1054,7 @@ void CCreatureHandler::buildBonusTreeForTiers() { BOOST_FOREACH(CCreature *c, creatures) { - if(isbetw(c->level, 0, ARRAY_COUNT(creaturesOfLevel))) + if(vstd::isbetween(c->level, 0, ARRAY_COUNT(creaturesOfLevel))) c->attachTo(&creaturesOfLevel[c->level]); else c->attachTo(&creaturesOfLevel[0]); diff --git a/lib/CCreatureHandler.h b/lib/CCreatureHandler.h index ce246aac1..6c6c8337e 100644 --- a/lib/CCreatureHandler.h +++ b/lib/CCreatureHandler.h @@ -1,14 +1,10 @@ -#ifndef __CCREATUREHANDLER_H__ -#define __CCREATUREHANDLER_H__ -#include "../global.h" -#include -#include -#include -#include +#pragma once + #include "../lib/HeroBonus.h" #include "../lib/ConstTransitivePtr.h" #include "ResourceSet.h" +#include "GameConstants.h" /* * CCreatureHandler.h, part of VCMI engine @@ -25,7 +21,7 @@ class CLodHandler; class CCreatureHandler; class CCreature; -class DLL_EXPORT CCreature : public CBonusSystemNode +class DLL_LINKAGE CCreature : public CBonusSystemNode { public: std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name @@ -44,9 +40,9 @@ public: ui8 doubleWide; ///animation info - float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance; + double timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance; int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY; - float missleFrameAngles[12]; + double missleFrameAngles[12]; int troopCountLocationOffset, attackClimaxFrame; ///end of anim info @@ -58,7 +54,7 @@ public: bool isEvil () const; si32 maxAmount(const std::vector &res) const; //how many creatures can be bought static int getQuantityID(const int & quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion - static int estimateCreatureCount(unsigned int countID); //reverse version of above function, returns middle of range + static int estimateCreatureCount(ui32 countID); //reverse version of above function, returns middle of range bool isMyUpgrade(const CCreature *anotherCre) const; bool valid() const; @@ -98,10 +94,11 @@ public: friend class CCreatureHandler; }; -class DLL_EXPORT CCreatureHandler +class DLL_LINKAGE CCreatureHandler { private: //? - CBonusSystemNode allCreatures, creaturesOfLevel[CREATURES_PER_TOWN + 1];//index 0 is used for creatures of unknown tier or outside <1-7> range + CBonusSystemNode allCreatures; + CBonusSystemNode creaturesOfLevel[GameConstants::CREATURES_PER_TOWN + 1];//index 0 is used for creatures of unknown tier or outside <1-7> range public: std::set notUsedMonsters; std::set doubledCreatures; //they get double week @@ -110,7 +107,7 @@ public: bmap idToProjectile; bmap idToProjectileSpin; //if true, appropriate projectile is spinning during flight std::vector factionAlignments; //1 for good, 0 for neutral and -1 for evil with faction ID as index - int factionToTurretCreature[F_NUMBER]; //which creature's animation should be used to dispaly creature in turret while siege + int factionToTurretCreature[GameConstants::F_NUMBER]; //which creature's animation should be used to dispaly creature in turret while siege std::map > stackBonuses; // bonus => name, description std::vector > expRanks; // stack experience needed for certain rank, index 0 for other tiers (?) @@ -147,5 +144,3 @@ public: BONUS_TREE_DESERIALIZATION_FIX } }; - -#endif // __CCREATUREHANDLER_H__ diff --git a/lib/CCreatureSet.cpp b/lib/CCreatureSet.cpp index 04e89acc3..a6eb92ced 100644 --- a/lib/CCreatureSet.cpp +++ b/lib/CCreatureSet.cpp @@ -1,16 +1,13 @@ -#define VCMI_DLL +#include "StdInc.h" #include "CCreatureSet.h" + #include "CCreatureHandler.h" #include "VCMI_Lib.h" -#include #include "CObjectHandler.h" #include "IGameCallback.h" #include "CGameState.h" #include "CGeneralTextHandler.h" -#include #include "CSpellHandler.h" -#include -#include const CStackInstance &CCreatureSet::operator[](TSlot slot) const { @@ -240,8 +237,8 @@ void CCreatureSet::setStackCount(TSlot slot, TQuantity count) { assert(hasStackAtSlot(slot)); assert(stacks[slot]->count + count > 0); - if (STACK_EXP && count > stacks[slot]->count) - stacks[slot]->experience *= (count/(float)stacks[slot]->count); + if (GameConstants::STACK_EXP && count > stacks[slot]->count) + stacks[slot]->experience *= (count / static_cast(stacks[slot]->count)); stacks[slot]->count = count; armyChanged(); } @@ -282,7 +279,7 @@ void CCreatureSet::eraseStack(TSlot slot) { assert(hasStackAtSlot(slot)); CStackInstance *toErase = detachStack(slot); - delNull(toErase); + vstd::clear_pointer(toErase); } bool CCreatureSet::contains(const CStackInstance *stack) const @@ -330,7 +327,7 @@ void CCreatureSet::joinStack(TSlot slot, CStackInstance * stack) //TODO move stuff changeStackCount(slot, stack->count); - delNull(stack); + vstd::clear_pointer(stack); } void CCreatureSet::changeStackCount(TSlot slot, TQuantity toAdd) @@ -396,7 +393,7 @@ bool CCreatureSet::canBeMergedWith(const CCreatureSet &cs, bool allowMergingStac { if(!allowMergingStacks) { - int freeSlots = stacksCount() - ARMY_SIZE; + int freeSlots = stacksCount() - GameConstants::ARMY_SIZE; std::set cresToAdd; for(TSlots::const_iterator i = cs.stacks.begin(); i != cs.stacks.end(); i++) { @@ -480,7 +477,7 @@ int CStackInstance::getQuantityID() const int CStackInstance::getExpRank() const { int tier = type->level; - if (iswith(tier, 1, 7)) + if (vstd::iswithin(tier, 1, 7)) { for (int i = VLC->creh->expRanks[tier].size()-2; i >-1; --i)//sic! { //exp values vary from 1st level to max exp at 11th level @@ -508,22 +505,22 @@ si32 CStackInstance::magicResistance() const //resistance skill val += hero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::RESISTANCE); } - amin (val, 100); + vstd::amin (val, 100); return val; } void CStackInstance::giveStackExp(expType exp) { int level = type->level; - if (!iswith(level, 1, 7)) + if (!vstd::iswithin(level, 1, 7)) level = 0; CCreatureHandler * creh = VLC->creh; ui32 maxExp = creh->expRanks[level].back(); - amin(exp, (expType)maxExp); //prevent exp overflow due to different types - amin(exp, (maxExp * creh->maxExpPerBattle[level])/100); - amin(experience += exp, maxExp); //can't get more exp than this limit + vstd::amin(exp, (expType)maxExp); //prevent exp overflow due to different types + vstd::amin(exp, (maxExp * creh->maxExpPerBattle[level])/100); + vstd::amin(experience += exp, maxExp); //can't get more exp than this limit } void CStackInstance::setType(int creID) @@ -539,8 +536,8 @@ void CStackInstance::setType(const CCreature *c) if(type) { detachFrom(const_cast(type)); - if (type->isMyUpgrade(c) && STACK_EXP) - experience *= VLC->creh->expAfterUpgrade / 100.0f; + if (type->isMyUpgrade(c) && GameConstants::STACK_EXP) + experience *= VLC->creh->expAfterUpgrade / 100.0; } type = c; @@ -840,7 +837,7 @@ std::string CStackInstance::bonusToGraphics(Bonus *bonus) const break; case Bonus::LEVEL_SPELL_IMMUNITY: { - if (iswith(bonus->val, 1 , 5)) + if (vstd::iswithin(bonus->val, 1 , 5)) { fileName = "E_SPLVL" + boost::lexical_cast(bonus->val) + ".bmp"; } @@ -961,7 +958,7 @@ CStackBasicDescriptor::CStackBasicDescriptor(const CCreature *c, TQuantity Count { } -DLL_EXPORT std::ostream & operator<<(std::ostream & str, const CStackInstance & sth) +DLL_LINKAGE std::ostream & operator<<(std::ostream & str, const CStackInstance & sth) { if(!sth.valid(true)) str << "an invalid stack!"; diff --git a/lib/CCreatureSet.h b/lib/CCreatureSet.h index 24561360d..070b43aee 100644 --- a/lib/CCreatureSet.h +++ b/lib/CCreatureSet.h @@ -1,16 +1,15 @@ -#ifndef __CCREATURESET_H__ -#define __CCREATURESET_H__ +#pragma once + -#include "../global.h" -#include #include "HeroBonus.h" +#include "GameConstants.h" class CCreature; class CGHeroInstance; class CArmedInstance; -class DLL_EXPORT CStackBasicDescriptor +class DLL_LINKAGE CStackBasicDescriptor { public: const CCreature *type; @@ -26,7 +25,7 @@ public: } }; -class DLL_EXPORT CStackInstance : public CBonusSystemNode, public CStackBasicDescriptor +class DLL_LINKAGE CStackInstance : public CBonusSystemNode, public CStackBasicDescriptor { const CArmedInstance *_armyObj; //stack must be part of some army, army must be part of some object public: @@ -70,7 +69,7 @@ public: void deserializationFix(); }; -DLL_EXPORT std::ostream & operator<<(std::ostream & str, const CStackInstance & sth); +DLL_LINKAGE std::ostream & operator<<(std::ostream & str, const CStackInstance & sth); typedef std::map TSlots; typedef std::map TSimpleSlots; @@ -83,7 +82,7 @@ public: }; //simplified version of CCreatureSet -class DLL_EXPORT CSimpleArmy : public IArmyDescriptor +class DLL_LINKAGE CSimpleArmy : public IArmyDescriptor { public: TSimpleSlots army; @@ -97,7 +96,7 @@ public: } }; -class DLL_EXPORT CCreatureSet : public IArmyDescriptor //seven combined creatures +class DLL_LINKAGE CCreatureSet : public IArmyDescriptor //seven combined creatures { CCreatureSet(const CCreatureSet&);; CCreatureSet &operator=(const CCreatureSet&); @@ -140,9 +139,9 @@ public: int getStackCount (TSlot slot) const; expType getStackExperience(TSlot slot) const; TSlot findStack(const CStackInstance *stack) const; //-1 if none - TSlot getSlotFor(TCreature creature, ui32 slotsAmount=ARMY_SIZE) const; //returns -1 if no slot available - TSlot getSlotFor(const CCreature *c, ui32 slotsAmount=ARMY_SIZE) const; //returns -1 if no slot available - TSlot getFreeSlot(ui32 slotsAmount=ARMY_SIZE) const; + TSlot getSlotFor(TCreature creature, ui32 slotsAmount = GameConstants::ARMY_SIZE) const; //returns -1 if no slot available + TSlot getSlotFor(const CCreature *c, ui32 slotsAmount = GameConstants::ARMY_SIZE) const; //returns -1 if no slot available + TSlot getFreeSlot(ui32 slotsAmount = GameConstants::ARMY_SIZE) const; bool mergableStacks(std::pair &out, TSlot preferable = -1) const; //looks for two same stacks, returns slot positions; bool validTypes(bool allowUnrandomized = false) const; //checks if all types of creatures are set properly bool slotEmpty(TSlot slot) const; @@ -166,5 +165,3 @@ public: } void sweep(); }; - -#endif // __CCREATURESET_H__ diff --git a/lib/CDefObjInfoHandler.cpp b/lib/CDefObjInfoHandler.cpp index 7a447a6bf..c82e09bd0 100644 --- a/lib/CDefObjInfoHandler.cpp +++ b/lib/CDefObjInfoHandler.cpp @@ -1,11 +1,10 @@ -#define VCMI_DLL -#include "../stdafx.h" +#include "StdInc.h" #include "CDefObjInfoHandler.h" + #include "../client/CGameInfo.h" #include "CLodHandler.h" -#include #include "../lib/VCMI_Lib.h" -#include +#include "GameConstants.h" extern CLodHandler * bitmaph; @@ -120,7 +119,7 @@ void CDefObjInfoHandler::load() gobjs[nobj->id][nobj->subid] = nobj; - if(nobj->id==TOWNI_TYPE) + if(nobj->id==GameConstants::TOWNI_TYPE) castles[nobj->subid]=nobj; } diff --git a/lib/CDefObjInfoHandler.h b/lib/CDefObjInfoHandler.h index f4d9a038d..93cdce8dd 100644 --- a/lib/CDefObjInfoHandler.h +++ b/lib/CDefObjInfoHandler.h @@ -1,8 +1,6 @@ -#ifndef __CDEFOBJINFOHANDLER_H__ -#define __CDEFOBJINFOHANDLER_H__ -#include -#include -#include "../global.h" +#pragma once + + #include "../lib/ConstTransitivePtr.h" /* @@ -17,7 +15,7 @@ class CDefEssential; class CLodHandler; -class DLL_EXPORT CGDefInfo +class DLL_LINKAGE CGDefInfo { public: std::string name; @@ -48,7 +46,7 @@ public: CGDefInfo(); void fetchInfoFromMSK(); }; -class DLL_EXPORT CDefObjInfoHandler +class DLL_LINKAGE CDefObjInfoHandler { public: bmap > > gobjs; @@ -63,5 +61,3 @@ public: h & castles; } }; - -#endif // __CDEFOBJINFOHANDLER_H__ diff --git a/lib/CFileUtility.cpp b/lib/CFileUtility.cpp index 3d7022290..1b016b19a 100644 --- a/lib/CFileUtility.cpp +++ b/lib/CFileUtility.cpp @@ -1,7 +1,5 @@ -#define VCMI_DLL +#include "StdInc.h" #include "CFileUtility.h" -#include // includes all needed Boost.Filesystem declarations -#include /* * CFileUtility.cpp, part of VCMI engine diff --git a/lib/CFileUtility.h b/lib/CFileUtility.h index 063040a7a..48d1fdaeb 100644 --- a/lib/CFileUtility.h +++ b/lib/CFileUtility.h @@ -1,5 +1,6 @@ #pragma once -#include "../global.h" + + /* * CFileUtility.cpp, part of VCMI engine @@ -19,7 +20,7 @@ struct FileInfo bool inLod; //tells if this file is located in Lod }; -class DLL_EXPORT CFileUtility +class DLL_LINKAGE CFileUtility { public: CFileUtility(void); diff --git a/lib/CGameInterface.cpp b/lib/CGameInterface.cpp index 278c0f98f..a7e09e895 100644 --- a/lib/CGameInterface.cpp +++ b/lib/CGameInterface.cpp @@ -1,6 +1,8 @@ -#define VCMI_DLL +#include "StdInc.h" #include "CGameInterface.h" + #include "BattleState.h" +#include "GameConstants.h" #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing @@ -63,12 +65,12 @@ rett * createAny(std::string dllname, std::string methodName) #ifdef _WIN32 std::string getAIFileName(std::string input) { - return input + '.' + LIB_EXT; + return input + '.' + GameConstants::LIB_EXT; } #else std::string getAIFileName(std::string input) { - return "lib" + input + '.' + LIB_EXT; + return "lib" + input + '.' + GameConstants::LIB_EXT; } #endif @@ -77,7 +79,7 @@ rett * createAnyAI(std::string dllname, std::string methodName) { tlog1<<"Opening "<(LIB_DIR "/AI/" + filename, methodName); + rett* ret = createAny(GameConstants::LIB_DIR + "/AI/" + filename, methodName); ret->dllName = dllname; return ret; } @@ -168,7 +170,7 @@ void CAdventureAI::battleNewStackAppeared(const CStack * stack) battleAI->battleNewStackAppeared(stack); } -void CAdventureAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) +void CAdventureAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) { battleAI->battleStackMoved(stack, dest, distance); } @@ -186,7 +188,7 @@ void CAdventureAI::battleSpellCast(const BattleSpellCast *sc) void CAdventureAI::battleEnd(const BattleResult *br) { battleAI->battleEnd(br); - delNull(battleAI); + vstd::clear_pointer(battleAI); } void CAdventureAI::battleStacksHealedRes(const std::vector > & healedStacks, bool lifeDrain, bool tentHeal, si32 lifeDrainFrom) @@ -202,4 +204,4 @@ BattleAction CAdventureAI::activeStack(const CStack * stack) void CAdventureAI::yourTacticPhase(int distance) { battleAI->yourTacticPhase(distance); -} \ No newline at end of file +} diff --git a/lib/CGameInterface.h b/lib/CGameInterface.h index cb6f41239..118ba2d71 100644 --- a/lib/CGameInterface.h +++ b/lib/CGameInterface.h @@ -1,8 +1,6 @@ -#ifndef __CGAMEINTERFACE_H__ -#define __CGAMEINTERFACE_H__ -#include "../global.h" -#include -#include +#pragma once + + #include "BattleAction.h" #include "IGameEventsReceiver.h" @@ -49,7 +47,6 @@ class CStack; class CCreature; class CLoadFile; class CSaveFile; -typedef si32 TQuantity; template class CISer; template class COSer; struct ArtifactLocation; @@ -83,7 +80,7 @@ public: virtual void serialize(CISer &h, const int version){}; //loading }; -class DLL_EXPORT CDynLibHandler +class DLL_LINKAGE CDynLibHandler { public: static CGlobalAI * getNewAI(std::string dllname); @@ -91,21 +88,21 @@ public: static CScriptingModule * getNewScriptingModule(std::string dllname); }; -class DLL_EXPORT CGlobalAI : public CGameInterface // AI class (to derivate) +class DLL_LINKAGE CGlobalAI : public CGameInterface // AI class (to derivate) { public: CGlobalAI(); virtual void yourTurn() OVERRIDE{}; virtual void heroKilled(const CGHeroInstance*){}; virtual void heroCreated(const CGHeroInstance*) OVERRIDE{}; - virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE{}; + virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE{}; virtual void battleStackAttacking(int ID, int dest) {}; virtual void battleStacksAttacked(const std::vector & bsa) OVERRIDE{}; virtual BattleAction activeStack(const CStack * stack) OVERRIDE; }; //class to be inherited by adventure-only AIs, it cedes battle actions to given battle-AI -class DLL_EXPORT CAdventureAI : public CGlobalAI +class DLL_LINKAGE CAdventureAI : public CGlobalAI { public: CAdventureAI() : battleAI(NULL), cbc(NULL) {}; @@ -130,12 +127,9 @@ public: virtual void battleStacksRemoved(const BattleStacksRemoved & bsr); virtual void battleObstaclesRemoved(const std::set & removedObstacles); virtual void battleNewStackAppeared(const CStack * stack); - virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance); + virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance); virtual void battleAttack(const BattleAttack *ba); virtual void battleSpellCast(const BattleSpellCast *sc); virtual void battleEnd(const BattleResult *br); virtual void battleStacksHealedRes(const std::vector > & healedStacks, bool lifeDrain, bool tentHeal, si32 lifeDrainFrom); }; - - -#endif // __CGAMEINTERFACE_H__ diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 1a2f50c9c..ce7729bb4 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1,10 +1,8 @@ -#define VCMI_DLL -#include "CCampaignHandler.h" -#include -#include -#include +#include "StdInc.h" #include "CGameState.h" + #include +#include "CCampaignHandler.h" #include "CDefObjInfoHandler.h" #include "CArtHandler.h" #include "CBuildingHandler.h" @@ -14,23 +12,16 @@ #include "CHeroHandler.h" #include "CObjectHandler.h" #include "CCreatureHandler.h" -//#include "../lib/IGameCallback.h" #include "VCMI_Lib.h" #include "Connection.h" #include "map.h" -#include "../StartInfo.h" +#include "StartInfo.h" #include "NetPacks.h" -#include -#include -#include -#include -#include -#include "RegisterTypes.cpp" -#include -#include +#include "RegisterTypes.h" #include "CMapInfo.h" #include "BattleState.h" #include "../lib/JsonNode.h" +#include "GameConstants.h" boost::rand48 ran; class CGObjectInstance; @@ -288,7 +279,7 @@ void MetaString::getLocalString(const std::pair &txt, std::string &dst } } -DLL_EXPORT void MetaString::toString(std::string &dst) const +DLL_LINKAGE void MetaString::toString(std::string &dst) const { size_t exSt = 0, loSt = 0, nums = 0; dst.clear(); @@ -333,14 +324,14 @@ DLL_EXPORT void MetaString::toString(std::string &dst) const } } -DLL_EXPORT std::string MetaString::toString() const +DLL_LINKAGE std::string MetaString::toString() const { std::string ret; toString(ret); return ret; } -DLL_EXPORT std::string MetaString::buildList () const +DLL_LINKAGE std::string MetaString::buildList () const ///used to handle loot from creature bank { @@ -413,7 +404,7 @@ static CGObjectInstance * createObject(int id, int subid, int3 pos, int owner) CGObjectInstance * nobj; switch(id) { - case HEROI_TYPE: //hero + case GameConstants::HEROI_TYPE: //hero { CGHeroInstance * nobj = new CGHeroInstance(); nobj->pos = pos; @@ -422,7 +413,7 @@ static CGObjectInstance * createObject(int id, int subid, int3 pos, int owner) //nobj->initHero(ran); return nobj; } - case TOWNI_TYPE: //town + case GameConstants::TOWNI_TYPE: //town nobj = new CGTownInstance; break; default: //rest of objects @@ -441,7 +432,7 @@ static CGObjectInstance * createObject(int id, int subid, int3 pos, int owner) nobj->defInfo->subid = subid; //assigning defhandler - if(nobj->ID==HEROI_TYPE || nobj->ID==TOWNI_TYPE) + if(nobj->ID==GameConstants::HEROI_TYPE || nobj->ID==GameConstants::TOWNI_TYPE) return nobj; nobj->defInfo = VLC->dobjinfo->gobjs[id][subid]; return nobj; @@ -451,7 +442,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co { CGHeroInstance *ret = NULL; - if(player<0 || player>=PLAYER_LIMIT) + if(player<0 || player>=GameConstants::PLAYER_LIMIT) { tlog1 << "Cannot pick hero for " << town->Name() << ". Wrong owner!\n"; return NULL; @@ -499,7 +490,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co } r = rand()%sum; - for (unsigned int i=0; itype->heroClass->selectionProbability[town->typeID]; if(r < 0) @@ -536,12 +527,12 @@ int CGameState::pickHero(int owner) do //try to find free hero of our faction { i++; - h = ps.castle*HEROES_PER_TYPE*2+(ran()%(HEROES_PER_TYPE*2));//->scenarioOps->playerInfos[pru].hero = VLC-> + h = ps.castle*GameConstants::HEROES_PER_TYPE*2+(ran()%(GameConstants::HEROES_PER_TYPE*2));//->scenarioOps->playerInfos[pru].hero = VLC-> } while( map->getHero(h) && i<175); if(i>174) //probably no free heroes - there's no point in further search, we'll take first free { tlog3 << "Warning: cannot find free hero - trying to get first available..."<getHero(j)) h=j; } @@ -564,7 +555,7 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) case 69: //random relic artifact return std::pair(5, VLC->arth->getRandomArt (CArtifact::ART_RELIC)); case 70: //random hero - return std::pair(HEROI_TYPE,pickHero(obj->tempOwner)); + return std::pair(GameConstants::HEROI_TYPE,pickHero(obj->tempOwner)); case 71: //random monster return std::pair(54,VLC->creh->pickRandomMonster(boost::ref(ran))); case 72: //random monster lvl1 @@ -581,9 +572,9 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) { int align = (static_cast(obj))->alignment, f; - if(align>PLAYER_LIMIT-1)//same as owner / random + if(align>GameConstants::PLAYER_LIMIT-1)//same as owner / random { - if(obj->tempOwner > PLAYER_LIMIT-1) + if(obj->tempOwner > GameConstants::PLAYER_LIMIT-1) f = -1; //random else f = scenarioOps->getIthPlayersSettings(obj->tempOwner).castle; @@ -593,7 +584,7 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) f = scenarioOps->getIthPlayersSettings(align).castle; } if(f<0) f = ran()%VLC->townh->towns.size(); - return std::pair(TOWNI_TYPE,f); + return std::pair(GameConstants::TOWNI_TYPE,f); } case 162: //random monster lvl5 return std::pair(54, VLC->creh->pickRandomMonster(boost::ref(ran), 5)); @@ -603,12 +594,12 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) return std::pair(54, VLC->creh->pickRandomMonster(boost::ref(ran), 7)); case 216: //random dwelling { - int faction = ran()%F_NUMBER; + int faction = ran()%GameConstants::F_NUMBER; CGDwelling * dwl = static_cast(obj); CCreGen2ObjInfo* info = static_cast(dwl->info); if (info->asCastle) { - for(unsigned int i=0;iobjects.size();i++) + for(ui32 i=0;iobjects.size();i++) { if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i].get())->identifier == info->identifier) { @@ -616,7 +607,7 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) faction = map->objects[i]->subID; break; } - else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast(map->objects[i].get())->identifier == info->identifier) + else if(map->objects[i]->ID==GameConstants::TOWNI_TYPE && dynamic_cast(map->objects[i].get())->identifier == info->identifier) { faction = map->objects[i]->subID; break; @@ -629,12 +620,12 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) { if((faction>7) && (info->castles[1]&(1<<(faction-8)))) break; - faction = ran()%F_NUMBER; + faction = ran()%GameConstants::F_NUMBER; } } int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel)); int cid = VLC->townh->towns[faction].basicCreatures[level]; - for(unsigned int i=0;iobjh->cregens.size();i++) + for(ui32 i=0;iobjh->cregens.size();i++) if(VLC->objh->cregens[i]==cid) return std::pair(17,i); tlog3 << "Cannot find a dwelling for creature "<< cid << std::endl; @@ -644,12 +635,12 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) } case 217: { - int faction = ran()%F_NUMBER; + int faction = ran()%GameConstants::F_NUMBER; CGDwelling * dwl = static_cast(obj); CCreGenObjInfo* info = static_cast(dwl->info); if (info->asCastle) { - for(unsigned int i=0;iobjects.size();i++) + for(ui32 i=0;iobjects.size();i++) { if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i].get())->identifier == info->identifier) { @@ -657,7 +648,7 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) faction = map->objects[i]->subID; break; } - else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast(map->objects[i].get())->identifier == info->identifier) + else if(map->objects[i]->ID==GameConstants::TOWNI_TYPE && dynamic_cast(map->objects[i].get())->identifier == info->identifier) { faction = map->objects[i]->subID; break; @@ -670,11 +661,11 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) { if((faction>7) && (info->castles[1]&(1<<(faction-8)))) break; - faction = ran()%F_NUMBER; + faction = ran()%GameConstants::F_NUMBER; } } int cid = VLC->townh->towns[faction].basicCreatures[obj->subID]; - for(unsigned int i=0;iobjh->cregens.size();i++) + for(ui32 i=0;iobjh->cregens.size();i++) if(VLC->objh->cregens[i]==cid) return std::pair(17,i); tlog3 << "Cannot find a dwelling for creature "< CGameState::pickObject (CGObjectInstance *obj) CCreGen3ObjInfo* info = static_cast(dwl->info); int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel)); int cid = VLC->townh->towns[obj->subID].basicCreatures[level]; - for(unsigned int i=0;iobjh->cregens.size();i++) + for(ui32 i=0;iobjh->cregens.size();i++) if(VLC->objh->cregens[i]==cid) return std::pair(17,i); tlog3 << "Cannot find a dwelling for creature "< ran = pickObject(cur); if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything { - if(cur->ID==TOWNI_TYPE) //town - set def + if(cur->ID==GameConstants::TOWNI_TYPE) //town - set def { CGTownInstance *t = dynamic_cast(cur); t->town = &VLC->townh->towns[t->subID]; @@ -718,7 +709,7 @@ void CGameState::randomizeObject(CGObjectInstance *cur) } return; } - else if(ran.first==HEROI_TYPE)//special code for hero + else if(ran.first==GameConstants::HEROI_TYPE)//special code for hero { CGHeroInstance *h = dynamic_cast(cur); if(!h) {tlog2<<"Wrong random hero at "<pos<heroes.push_back(h); return; //TODO: maybe we should do something with definfo? } - else if(ran.first==TOWNI_TYPE)//special code for town + else if(ran.first==GameConstants::TOWNI_TYPE)//special code for town { CGTownInstance *t = dynamic_cast(cur); if(!t) {tlog2<<"Wrong random town at "<pos<slotEmpty(i)) { @@ -864,7 +855,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) case 5: //prim skill { const ui8* ptr = reinterpret_cast(&curBonus.info2); - for (int g=0; gcamp->mapPieces[scenarioOps->whichMapInCampaign]; map = new Mapa(); - map->initFromBytes((const unsigned char*)mapContent.c_str(), mapContent.size()); + map->initFromBytes((const ui8*)mapContent.c_str(), mapContent.size()); } break; case StartInfo::DUEL: @@ -1037,7 +1028,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) } //remove tiles with holes - for(unsigned int no=0; noobjects.size(); ++no) + for(ui32 no=0; noobjects.size(); ++no) if(map->objects[no]->ID == 124) allowedPos -= map->objects[no]->pos; @@ -1056,7 +1047,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) int f; do { - f = ran()%F_NUMBER; + f = ran()%GameConstants::F_NUMBER; }while(!(map->players[it->first].allowedFactions & 1<second.castle = f; } @@ -1094,7 +1085,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) } /*********give starting hero****************************************/ - for(int i=0;iplayers[i]; bool generateHero = (p.generateHeroAtMainTown && p.hasMainTown); @@ -1107,7 +1098,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) if(scenarioOps->playerInfos[i].hero == -1) scenarioOps->playerInfos[i].hero = h; - CGHeroInstance * nnn = static_cast(createObject(HEROI_TYPE,h,hpos,i)); + CGHeroInstance * nnn = static_cast(createObject(GameConstants::HEROI_TYPE,h,hpos,i)); nnn->id = map->objects.size(); nnn->initHero(); map->heroes.push_back(nnn); @@ -1186,7 +1177,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) /******************RESOURCES****************************************************/ TResources startresAI, startresHuman; - const JsonNode config(DATA_DIR "/config/startres.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/startres.json"); const JsonVector &vector = config["difficulty"].Vector(); const JsonNode &level = vector[scenarioOps->difficulty]; const JsonNode &human = level["human"]; @@ -1259,11 +1250,11 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) /*************************HEROES************************************************/ std::set hids; //hero ids to create pool - for(unsigned int i=0; iallowedHeroes.size(); i++) //add to hids all allowed heroes + for(ui32 i=0; iallowedHeroes.size(); i++) //add to hids all allowed heroes if(map->allowedHeroes[i]) hids.insert(i); - for (unsigned int i=0; iheroes.size();i++) //heroes instances initialization + for (ui32 i=0; iheroes.size();i++) //heroes instances initialization { if (map->heroes[i]->getOwner()<0) { @@ -1276,13 +1267,13 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) hids.erase(vhi->subID); } - for (unsigned int i=0; iobjects.size();i++) //prisons + for (ui32 i=0; iobjects.size();i++) //prisons { if (map->objects[i]->ID == 62) hids.erase(map->objects[i]->subID); } - for(unsigned int i=0; ipredefinedHeroes.size(); i++) + for(ui32 i=0; ipredefinedHeroes.size(); i++) { if(!vstd::contains(hids,map->predefinedHeroes[i]->subID)) continue; @@ -1300,7 +1291,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) hpool.pavailable[hid] = 0xff; } - for(unsigned int i=0; idisposedHeroes.size(); i++) + for(ui32 i=0; idisposedHeroes.size(); i++) { hpool.pavailable[map->disposedHeroes[i].ID] = map->disposedHeroes[i].players; } @@ -1425,7 +1416,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) for ( int i=0; i<4; i++) CGTownInstance::universitySkills.push_back(14+i);//skills for university - for (unsigned int i=0;itowns.size();i++) + for (ui32 i=0;itowns.size();i++) { CGTownInstance * vti =(map->towns[i]); if(!vti->town) @@ -1448,7 +1439,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) vti->builtBuildings.erase(6);//if we have harbor without water - erase it (this is H3 behaviour) //init hordes - for (int i = 0; ibuiltBuildings,(-31-i))) //if we have horde for this level { vti->builtBuildings.erase(-31-i);//remove old ID @@ -1469,7 +1460,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) //town events BOOST_FOREACH(CCastleEvent *ev, vti->events) { - for (int i = 0; ibuildings,(-31-i))) //if we have horde for this level { ev->buildings.erase(-31-i); @@ -1480,9 +1471,9 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) } } //init spells - vti->spells.resize(SPELL_LEVELS); + vti->spells.resize(GameConstants::SPELL_LEVELS); CSpell *s; - for(unsigned int z=0; zobligatorySpells.size();z++) + for(ui32 z=0; zobligatorySpells.size();z++) { s = VLC->spellh->spells[vti->obligatorySpells[z]]; vti->spells[s->level-1].push_back(s->id); @@ -1493,10 +1484,10 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) ui32 total=0; int sel = -1; - for(unsigned int ps=0;pspossibleSpells.size();ps++) + for(ui32 ps=0;pspossibleSpells.size();ps++) total += VLC->spellh->spells[vti->possibleSpells[ps]]->probabilities[vti->subID]; int r = (total)? ran()%total : -1; - for(unsigned int ps=0; pspossibleSpells.size();ps++) + for(ui32 ps=0; pspossibleSpells.size();ps++) { r -= VLC->spellh->spells[vti->possibleSpells[ps]]->probabilities[vti->subID]; if(r<0) @@ -1657,7 +1648,7 @@ int CGameState::battleGetBattlefieldType(int3 tile) std::set > costDiff(const std::vector &a, const std::vector &b, const int modifier = 100) //modifer % { std::set > ret; - for(int j=0;j= b[j]); if(int dif = modifier * (a[j] - b[j]) / 100) @@ -1671,10 +1662,10 @@ UpgradeInfo CGameState::getUpgradeInfo(const CStackInstance &stack) UpgradeInfo ret; const CCreature *base = stack.type; - const CGHeroInstance *h = stack.armyObj->ID == HEROI_TYPE ? static_cast(stack.armyObj) : NULL; + const CGHeroInstance *h = stack.armyObj->ID == GameConstants::HEROI_TYPE ? static_cast(stack.armyObj) : NULL; const CGTownInstance *t = NULL; - if(stack.armyObj->ID == TOWNI_TYPE) + if(stack.armyObj->ID == GameConstants::TOWNI_TYPE) t = static_cast(stack.armyObj); else if(h) { //hero speciality @@ -1738,9 +1729,9 @@ int CGameState::getPlayerRelations( ui8 color1, ui8 color2 ) void CGameState::loadTownDInfos() { int i; - const JsonNode config(DATA_DIR "/config/towns_defs.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/towns_defs.json"); - assert(config["town_defnames"].Vector().size() == F_NUMBER); + assert(config["town_defnames"].Vector().size() == GameConstants::F_NUMBER); i = 0; BOOST_FOREACH(const JsonNode &t, config["town_defnames"].Vector()) @@ -1815,15 +1806,15 @@ int CGameState::getMovementCost(const CGHeroInstance *h, const int3 &src, const if(!freeFlying) { - ret *= 1.4f; //40% penalty for movement over blocked tile + ret *= 1.4; //40% penalty for movement over blocked tile } } else if (d.tertype == TerrainTile::water) { if(h->boat && s.hasFavourableWinds() && d.hasFavourableWinds()) //Favourable Winds - ret *= 0.666f; + ret *= 0.666; else if (!h->boat && h->getBonusesCount(Selector::typeSubtype(Bonus::WATER_WALKING, 1)) > 0) - ret *= 1.4f; //40% penalty for water walking + ret *= 1.4; //40% penalty for water walking } if(src.x != dest.x && src.y != dest.y) //it's diagonal move @@ -1970,7 +1961,7 @@ bool CGameState::checkForVisitableDir(const int3 & src, const int3 & dst) const bool CGameState::checkForVisitableDir( const int3 & src, const TerrainTile *pom, const int3 & dst ) const { - for(unsigned int b=0; bvisitableObjects.size(); ++b) //checking destination tile + for(ui32 b=0; bvisitableObjects.size(); ++b) //checking destination tile { if(!vstd::contains(pom->blockingObjects, pom->visitableObjects[b])) //this visitable object is not blocking, ignore continue; @@ -2016,7 +2007,7 @@ bool CGameState::checkForVisitableDir( const int3 & src, const TerrainTile *pom, int CGameState::victoryCheck( ui8 player ) const { const PlayerState *p = CGameInfoCallback::getPlayer(player); - if(map->victoryCondition.condition == winStandard || map->victoryCondition.allowNormalVictory) + if(map->victoryCondition.condition == EVictoryConditionType::WINSTANDARD || map->victoryCondition.allowNormalVictory) if(player == checkForStandardWin()) return -1; @@ -2029,7 +2020,7 @@ int CGameState::victoryCheck( ui8 player ) const { switch(map->victoryCondition.condition) { - case artifact: + case EVictoryConditionType::ARTIFACT: //check if any hero has winning artifact for(size_t i = 0; i < p->heroes.size(); i++) if(p->heroes[i]->hasArt(map->victoryCondition.ID)) @@ -2037,7 +2028,7 @@ int CGameState::victoryCheck( ui8 player ) const break; - case gatherTroop: + case EVictoryConditionType::GATHERTROOP: { //check if in players armies there is enough creatures int total = 0; //creature counter @@ -2059,13 +2050,13 @@ int CGameState::victoryCheck( ui8 player ) const } break; - case gatherResource: + case EVictoryConditionType::GATHERRESOURCE: if(p->resources[map->victoryCondition.ID] >= map->victoryCondition.count) return 1; break; - case buildCity: + case EVictoryConditionType::BUILDCITY: { const CGTownInstance *t = static_cast(map->victoryCondition.obj); if(t->tempOwner == player && t->fortLevel()-1 >= map->victoryCondition.ID && t->hallLevel()-1 >= map->victoryCondition.count) @@ -2073,7 +2064,7 @@ int CGameState::victoryCheck( ui8 player ) const } break; - case buildGrail: + case EVictoryConditionType::BUILDGRAIL: BOOST_FOREACH(const CGTownInstance *t, map->towns) if((t == map->victoryCondition.obj || !map->victoryCondition.obj) && t->tempOwner == player @@ -2081,21 +2072,21 @@ int CGameState::victoryCheck( ui8 player ) const return 1; break; - case beatHero: - if(map->victoryCondition.obj->tempOwner >= PLAYER_LIMIT) //target hero not present on map + case EVictoryConditionType::BEATHERO: + if(map->victoryCondition.obj->tempOwner >= GameConstants::PLAYER_LIMIT) //target hero not present on map return 1; break; - case captureCity: + case EVictoryConditionType::CAPTURECITY: { if(map->victoryCondition.obj->tempOwner == player) return 1; } break; - case beatMonster: + case EVictoryConditionType::BEATMONSTER: if(!map->objects[map->victoryCondition.obj->id]) //target monster not present on map return 1; break; - case takeDwellings: + case EVictoryConditionType::TAKEDWELLINGS: for(size_t i = 0; i < map->objects.size(); i++) { if(map->objects[i] && map->objects[i]->tempOwner != player) //check not flagged objs @@ -2110,7 +2101,7 @@ int CGameState::victoryCheck( ui8 player ) const } return 1; break; - case takeMines: + case EVictoryConditionType::TAKEMINES: for(size_t i = 0; i < map->objects.size(); i++) { if(map->objects[i] && map->objects[i]->tempOwner != player) //check not flagged objs @@ -2124,7 +2115,7 @@ int CGameState::victoryCheck( ui8 player ) const } return 1; break; - case transportItem: + case EVictoryConditionType::TRANSPORTITEM: { const CGTownInstance *t = static_cast(map->victoryCondition.obj); if((t->visitingHero && t->visitingHero->hasArt(map->victoryCondition.ID)) @@ -2147,7 +2138,7 @@ ui8 CGameState::checkForStandardWin() const ui8 supposedWinner = 255, winnerTeam = 255; for(std::map::const_iterator i = players.begin(); i != players.end(); i++) { - if(i->second.status == PlayerState::INGAME && i->first < PLAYER_LIMIT) + if(i->second.status == PlayerState::INGAME && i->first < GameConstants::PLAYER_LIMIT) { if(supposedWinner == 255) { @@ -2372,7 +2363,7 @@ int CGameState::lossCheck( ui8 player ) const { switch(map->lossCondition.typeOfLossCon) { - case lossCastle: + case ELossConditionType::LOSSCASTLE: { const CGTownInstance *t = dynamic_cast(map->lossCondition.obj); assert(t); @@ -2380,7 +2371,7 @@ int CGameState::lossCheck( ui8 player ) const return 1; } break; - case lossHero: + case ELossConditionType::LOSSHERO: { const CGHeroInstance *h = dynamic_cast(map->lossCondition.obj); assert(h); @@ -2388,7 +2379,7 @@ int CGameState::lossCheck( ui8 player ) const return 1; } break; - case timeExpires: + case ELossConditionType::TIMEEXPIRES: if(map->lossCondition.timeLimit < day) return 1; break; @@ -2464,7 +2455,7 @@ void CPath::convert(ui8 mode) //mode=0 -> from 'manifest' to 'object' { if (mode==0) { - for (unsigned int i=0;iluck = h->LuckVal(); details->morale = h->MoraleVal(); details->mana = h->mana; - details->primskills.resize(PRIMARY_SKILLS); + details->primskills.resize(GameConstants::PRIMARY_SKILLS); - for (int i = 0; i < PRIMARY_SKILLS ; i++) + for (int i = 0; i < GameConstants::PRIMARY_SKILLS ; i++) { details->primskills[i] = h->getPrimSkillLevel(i); } @@ -2774,7 +2765,7 @@ void CPathfinder::calculatePaths(int3 src /*= int3(-1,-1,-1)*/, int movement /*= neighbours.clear(); //handling subterranean gate => it's exit is the only neighbour - bool subterraneanEntry = (ct->topVisitableID() == SUBTERRANEAN_GATE_TYPE && useSubterraneanGates); + bool subterraneanEntry = (ct->topVisitableID() == GameConstants::SUBTERRANEAN_GATE_TYPE && useSubterraneanGates); if(subterraneanEntry) { //try finding the exit gate @@ -2793,7 +2784,7 @@ void CPathfinder::calculatePaths(int3 src /*= int3(-1,-1,-1)*/, int movement /*= gs->getNeighbours(*ct, cp->coord, neighbours, boost::logic::indeterminate, !cp->land); - for(unsigned int i=0; i < neighbours.size(); i++) + for(ui32 i=0; i < neighbours.size(); i++) { const int3 &n = neighbours[i]; //current neighbor dp = getNode(n); @@ -2815,13 +2806,13 @@ void CPathfinder::calculatePaths(int3 src /*= int3(-1,-1,-1)*/, int movement /*= continue; //special case -> hero embarked a boat standing on a guarded tile -> we must allow to move away from that tile - if(cp->accessible == CGPathNode::VISITABLE && guardedSource && cp->theNodeBefore->land && ct->topVisitableID() == BOATI_TYPE) + if(cp->accessible == CGPathNode::VISITABLE && guardedSource && cp->theNodeBefore->land && ct->topVisitableID() == GameConstants::BOATI_TYPE) guardedSource = false; int cost = gs->getMovementCost(hero, cp->coord, dp->coord, movement); //special case -> moving from src Subterranean gate to dest gate -> it's free - if(subterraneanEntry && destTopVisObjID == SUBTERRANEAN_GATE_TYPE && cp->coord.z != dp->coord.z) + if(subterraneanEntry && destTopVisObjID == GameConstants::SUBTERRANEAN_GATE_TYPE && cp->coord.z != dp->coord.z) cost = 0; int remains = movement - cost; @@ -2857,7 +2848,7 @@ void CPathfinder::calculatePaths(int3 src /*= int3(-1,-1,-1)*/, int movement /*= if (dp->accessible == CGPathNode::ACCESSIBLE || (useEmbarkCost && allowEmbarkAndDisembark) - || destTopVisObjID == SUBTERRANEAN_GATE_TYPE + || destTopVisObjID == GameConstants::SUBTERRANEAN_GATE_TYPE || (guardedDst && !guardedSource)) // Can step into a hostile tile once. { mq.push_back(dp); @@ -2896,7 +2887,7 @@ CGPathNode::EAccessibility CPathfinder::evaluateAccessibility(const TerrainTile if(tinfo->visitable) { - if(tinfo->visitableObjects.front()->ID == 80 && tinfo->visitableObjects.back()->ID == HEROI_TYPE && tinfo->visitableObjects.back()->tempOwner != hero->tempOwner) //non-owned hero stands on Sanctuary + if(tinfo->visitableObjects.front()->ID == 80 && tinfo->visitableObjects.back()->ID == GameConstants::HEROI_TYPE && tinfo->visitableObjects.back()->tempOwner != hero->tempOwner) //non-owned hero stands on Sanctuary { return CGPathNode::BLOCKED; } @@ -2912,7 +2903,7 @@ CGPathNode::EAccessibility CPathfinder::evaluateAccessibility(const TerrainTile { return CGPathNode::BLOCKVIS; } - else if(obj->ID != EVENTI_TYPE) //pathfinder should ignore placed events + else if(obj->ID != GameConstants::EVENTI_TYPE) //pathfinder should ignore placed events { ret = CGPathNode::VISITABLE; } @@ -2937,9 +2928,9 @@ bool CPathfinder::goodForLandSeaTransition() { if(dp->accessible == CGPathNode::ACCESSIBLE || destTopVisObjID < 0) //cannot enter empty water tile from land -> it has to be visitable return false; - if(destTopVisObjID != HEROI_TYPE && destTopVisObjID != BOATI_TYPE) //only boat or hero can be accessed from land + if(destTopVisObjID != GameConstants::HEROI_TYPE && destTopVisObjID != GameConstants::BOATI_TYPE) //only boat or hero can be accessed from land return false; - if(destTopVisObjID == BOATI_TYPE) + if(destTopVisObjID == GameConstants::BOATI_TYPE) useEmbarkCost = 1; } else //disembark diff --git a/lib/CGameState.h b/lib/CGameState.h index 457e8b895..1b0d4d3da 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -1,7 +1,6 @@ -#ifndef __CGAMESTATE_H__ -#define __CGAMESTATE_H__ -#include "../global.h" -#include +#pragma once + + #ifndef _MSC_VER #include "CCreatureHandler.h" @@ -9,21 +8,12 @@ #include "map.h" #endif -#include -#include -#include #include "HeroBonus.h" #include "CCreatureSet.h" - -#ifdef _WIN32 -#include -#else -#include "../tchar_amigaos4.h" -#endif - #include "ConstTransitivePtr.h" #include "IGameCallback.h" #include "ResourceSet.h" +#include "int3.h" /* @@ -67,6 +57,7 @@ class CCampaign; class CCampaignState; class IModableArt; class CGGarrison; +class CGameInfo; namespace boost { @@ -77,18 +68,18 @@ namespace boost struct ArmyDescriptor : public std::map { bool isDetailed; - DLL_EXPORT ArmyDescriptor(const CArmedInstance *army, bool detailed); //not detailed -> quantity ids as count - DLL_EXPORT ArmyDescriptor(); + DLL_LINKAGE ArmyDescriptor(const CArmedInstance *army, bool detailed); //not detailed -> quantity ids as count + DLL_LINKAGE ArmyDescriptor(); - DLL_EXPORT int getStrength() const; + DLL_LINKAGE int getStrength() const; }; -struct DLL_EXPORT InfoAboutHero +struct DLL_LINKAGE InfoAboutHero { private: void assign(const InfoAboutHero & iah); public: - struct DLL_EXPORT Details + struct DLL_LINKAGE Details { std::vector primskills; int mana, luck, morale; @@ -108,8 +99,8 @@ public: void initFromHero(const CGHeroInstance *h, bool detailed); }; -/// Struct which holds a short information about a town -struct DLL_EXPORT InfoAboutTown +/// Struct which holds a int information about a town +struct DLL_LINKAGE InfoAboutTown { struct Details { @@ -138,7 +129,7 @@ struct DLL_EXPORT InfoAboutTown // typedef std::vector TResourceVector; // typedef std::set TResourceSet; -struct DLL_EXPORT SThievesGuildInfo +struct DLL_LINKAGE SThievesGuildInfo { std::vector playerColors; //colors of players that are in-game @@ -157,7 +148,7 @@ struct DLL_EXPORT SThievesGuildInfo }; -struct DLL_EXPORT PlayerState : public CBonusSystemNode +struct DLL_LINKAGE PlayerState : public CBonusSystemNode { public: enum EStatus {INGAME, LOSER, WINNER}; @@ -192,7 +183,7 @@ public: } }; -struct DLL_EXPORT TeamState : public CBonusSystemNode +struct DLL_LINKAGE TeamState : public CBonusSystemNode { public: ui8 id; //position in gameState::teams @@ -246,7 +237,7 @@ struct CGPathNode }; -struct DLL_EXPORT CPath +struct DLL_LINKAGE CPath { std::vector nodes; //just get node by node @@ -255,7 +246,7 @@ struct DLL_EXPORT CPath void convert(ui8 mode); //mode=0 -> from 'manifest' to 'object' }; -struct DLL_EXPORT CGPath +struct DLL_LINKAGE CGPath { std::vector nodes; //just get node by node @@ -264,7 +255,7 @@ struct DLL_EXPORT CGPath void convert(ui8 mode); //mode=0 -> from 'manifest' to 'object' }; -struct DLL_EXPORT CPathsInfo +struct DLL_LINKAGE CPathsInfo { bool isValid; const CGHeroInstance *hero; @@ -277,7 +268,7 @@ struct DLL_EXPORT CPathsInfo ~CPathsInfo(); }; -struct DLL_EXPORT DuelParameters +struct DLL_LINKAGE DuelParameters { si32 terType, bfieldType; struct SideSettings @@ -293,7 +284,8 @@ struct DLL_EXPORT DuelParameters StackSettings(); StackSettings(si32 Type, si32 Count); - } stacks[ARMY_SIZE]; + }; + StackSettings stacks[GameConstants::ARMY_SIZE]; si32 heroId; //-1 if none std::set spells; @@ -349,7 +341,7 @@ public: struct BattleInfo; -class DLL_EXPORT CGameState : public CNonConstInfoCallback +class DLL_LINKAGE CGameState : public CNonConstInfoCallback { public: ConstTransitivePtr scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized) @@ -365,7 +357,7 @@ public: CBonusSystemNode globalEffects; bmap ongoingVisits; - struct DLL_EXPORT HeroesPool + struct DLL_LINKAGE HeroesPool { bmap > heroesPool; //[subID] - heroes available to buy; NULL if not available bmap pavailable; // [subid] -> which players can recruit hero (binary flags) @@ -389,7 +381,6 @@ public: int battleGetBattlefieldType(int3 tile = int3());// 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship UpgradeInfo getUpgradeInfo(const CStackInstance &stack); int getPlayerRelations(ui8 color1, ui8 color2);// 0 = enemy, 1 = ally, 2 = same player - //float getMarketEfficiency(int player, int mode=0); bool checkForVisitableDir(const int3 & src, const int3 & dst) const; //check if src tile is visitable from dst tile bool checkForVisitableDir(const int3 & src, const TerrainTile *pom, const int3 & dst) const; //check if src tile is visitable from dst tile bool getPath(int3 src, int3 dest, const CGHeroInstance * hero, CPath &ret); //calculates path between src and dest; returns pointer to newly allocated CPath or NULL if path does not exists @@ -435,7 +426,4 @@ public: friend class CMapHandler; friend class CGameHandler; }; - - -#endif // __CGAMESTATE_H__ diff --git a/lib/CGeneralTextHandler.cpp b/lib/CGeneralTextHandler.cpp index b1c1e8c2d..343b36f86 100644 --- a/lib/CGeneralTextHandler.cpp +++ b/lib/CGeneralTextHandler.cpp @@ -1,12 +1,9 @@ -#define VCMI_DLL -#include "../stdafx.h" -#include "../lib/VCMI_Lib.h" +#include "StdInc.h" #include "CGeneralTextHandler.h" + +#include "../lib/VCMI_Lib.h" #include "CLodHandler.h" -#include -#include -#include -#include +#include "GameConstants.h" /* * CGeneralTextHandler.cpp, part of VCMI engine @@ -87,7 +84,7 @@ void CGeneralTextHandler::load() i+=2; } - hTxts.resize(HEROES_QUANTITY); + hTxts.resize(GameConstants::HEROES_QUANTITY); buf = bitmaph->getTextFile("HEROSPEC.TXT"); i=0; @@ -120,7 +117,7 @@ void CGeneralTextHandler::load() { std::string name = readTo(buf,it,'\t'), description = readTo(buf,it,'\n'); - for(int fi=0;figetTextFile("BLDGSPEC.TXT"); andame = buf.size(), it=0; - for(int f=0;fgetTextFile("DWELLING.TXT"); andame = buf.size(), it=0; - for(int f=0;f -#include +#pragma once + + /* * CGeneralTextHandler.h, part of VCMI engine @@ -14,9 +12,9 @@ * */ -DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, int mode); +DLL_LINKAGE void loadToIt(std::string &dest, const std::string &src, int &iter, int mode); std::string readTo(const std::string &in, int &it, char end); -class DLL_EXPORT CGeneralTextHandler //Handles general texts +class DLL_LINKAGE CGeneralTextHandler //Handles general texts { public: class HeroTexts @@ -86,7 +84,3 @@ public: void load(); CGeneralTextHandler(); }; - - - -#endif // __CGENERALTEXTHANDLER_H__ diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 95a05681e..6203eb019 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -1,19 +1,16 @@ -#define VCMI_DLL -#include "../stdafx.h" +#include "StdInc.h" #include "CHeroHandler.h" + #include "CLodHandler.h" #include "../lib/VCMI_Lib.h" #include "../lib/JsonNode.h" -#include -#include -#include +#include "GameConstants.h" #include #if BOOST_VERSION >= 103800 #include #else #include #endif -#include using namespace boost::spirit; @@ -55,9 +52,9 @@ int CHeroClass::chooseSecSkill(const std::set & possibles) const //picks se throw std::string("Cannot pick secondary skill!"); } -EAlignment CHeroClass::getAlignment() +EAlignment::EAlignment CHeroClass::getAlignment() { - return (EAlignment)alignment; + return (EAlignment::EAlignment)alignment; } int CObstacleInfo::getWidth() const @@ -95,9 +92,9 @@ int CObstacleInfo::getHeight() const return ret; } -std::vector CObstacleInfo::getBlocked(THex hex) const +std::vector CObstacleInfo::getBlocked(SHexField hex) const { - std::vector ret; + std::vector ret; int cur = hex; //currently browsed hex int curBeg = hex; //beginning of current line for(int h=0; h CObstacleInfo::getBlocked(THex hex) const ++cur; break; case 'L': - cur = curBeg + BFIELD_WIDTH; - if((cur/BFIELD_WIDTH)%2 == 1) + cur = curBeg + GameConstants::BFIELD_WIDTH; + if((cur/GameConstants::BFIELD_WIDTH)%2 == 1) { cur--; } @@ -124,9 +121,9 @@ std::vector CObstacleInfo::getBlocked(THex hex) const return ret; } -THex CObstacleInfo::getMaxBlocked(THex hex) const +SHexField CObstacleInfo::getMaxBlocked(SHexField hex) const { - std::vector blocked = getBlocked(hex); + std::vector blocked = getBlocked(hex); return *std::max_element(blocked.begin(), blocked.end()); } @@ -144,7 +141,7 @@ CHeroHandler::CHeroHandler() void CHeroHandler::loadObstacles() { - const JsonNode config(DATA_DIR "/config/obstacles.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/obstacles.json"); BOOST_FOREACH(const JsonNode &obs, config["obstacles"].Vector()) { CObstacleInfo obi; @@ -163,7 +160,7 @@ void CHeroHandler::loadObstacles() void CHeroHandler::loadPuzzleInfo() { - const JsonNode config(DATA_DIR "/config/puzzle_map.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/puzzle_map.json"); int faction = 0; @@ -185,7 +182,7 @@ void CHeroHandler::loadPuzzleInfo() suffix << std::setfill('0') << std::setw(2); suffix << idx << ".BMP"; - static const std::string factionToInfix[F_NUMBER] = {"CAS", "RAM", "TOW", "INF", "NEC", "DUN", "STR", "FOR", "ELE"}; + static const std::string factionToInfix[GameConstants::F_NUMBER] = {"CAS", "RAM", "TOW", "INF", "NEC", "DUN", "STR", "FOR", "ELE"}; spi.filename = "PUZ" + factionToInfix[faction] + suffix.str(); puzzleInfo[faction].push_back(spi); @@ -198,7 +195,7 @@ void CHeroHandler::loadPuzzleInfo() faction ++; } - assert(faction == F_NUMBER); + assert(faction == GameConstants::F_NUMBER); } void CHeroHandler::loadHeroes() @@ -230,7 +227,7 @@ void CHeroHandler::loadHeroes() addTab[11] = CHero::DEMONIAC; - for (int i=0; i> intPart; str.ignore();//ignore decimal separator str >> fracPart; - hc->aggression = intPart + fracPart/100.0f; + hc->aggression = intPart + fracPart/100.0; str >> hc->initialAttack; str >> hc->initialDefence; str >> hc->initialPower; str >> hc->initialKnowledge; - hc->primChance.resize(PRIMARY_SKILLS); - for(int x=0; xprimChance.resize(GameConstants::PRIMARY_SKILLS); + for(int x=0; x> hc->primChance[x].first; } - for(int x=0; x> hc->primChance[x].second; } - hc->proSec.resize(SKILL_QUANTITY); - for(int dd=0; ddproSec.resize(GameConstants::SKILL_QUANTITY); + for(int dd=0; dd> hc->proSec[dd]; } @@ -426,7 +423,7 @@ void CHeroHandler::initHeroClasses() loadTerrains(); } -unsigned int CHeroHandler::level (ui64 experience) const +ui32 CHeroHandler::level (ui64 experience) const { int i; if (experience <= expPerLevel.back()) @@ -443,7 +440,7 @@ unsigned int CHeroHandler::level (ui64 experience) const } } -ui64 CHeroHandler::reqExp (unsigned int level) const +ui64 CHeroHandler::reqExp (ui32 level) const { if(!level) return 0; @@ -462,9 +459,9 @@ ui64 CHeroHandler::reqExp (unsigned int level) const void CHeroHandler::loadTerrains() { int faction = 0; - const JsonNode config(DATA_DIR "/config/terrains.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/terrains.json"); - nativeTerrains.resize(F_NUMBER); + nativeTerrains.resize(GameConstants::F_NUMBER); BOOST_FOREACH(const JsonNode &terrain, config["terrains"].Vector()) { @@ -480,7 +477,7 @@ void CHeroHandler::loadTerrains() faction ++; } - assert(faction == F_NUMBER); + assert(faction == GameConstants::F_NUMBER); } CHero::CHero() diff --git a/lib/CHeroHandler.h b/lib/CHeroHandler.h index a9acfac59..5cd4a069b 100644 --- a/lib/CHeroHandler.h +++ b/lib/CHeroHandler.h @@ -1,11 +1,9 @@ -#ifndef __CHEROHANDLER_H__ -#define __CHEROHANDLER_H__ -#include "../global.h" -#include -#include -#include +#pragma once + +#include "SHexField.h" #include "../lib/ConstTransitivePtr.h" +#include "GameConstants.h" /* * CHeroHandler.h, part of VCMI engine @@ -32,7 +30,7 @@ struct SSpecialtyInfo } }; -class DLL_EXPORT CHero +class DLL_LINKAGE CHero { public: enum EHeroClasses {KNIGHT, CLERIC, RANGER, DRUID, ALCHEMIST, WIZARD, @@ -60,13 +58,13 @@ public: } }; -class DLL_EXPORT CHeroClass +class DLL_LINKAGE CHeroClass { public: ui8 alignment; ui32 skillLimit; //how many secondary skills can hero learn std::string name; - float aggression; + double aggression; int initialAttack, initialDefence, initialPower, initialKnowledge; //initial values of primary skills std::vector > primChance;//primChance[PRIMARY_SKILL_ID] - first is for levels 2 - 9, second for 10+;;; probability (%) of getting point of primary skill when getting new level std::vector proSec; //probabilities of gaining secondary skills (out of 112), in id order @@ -82,10 +80,10 @@ public: h & skillLimit & name & aggression & initialAttack & initialDefence & initialPower & initialKnowledge & primChance & proSec & selectionProbability & terrCosts & alignment; } -EAlignment getAlignment(); + EAlignment::EAlignment getAlignment(); }; -struct DLL_EXPORT CObstacleInfo +struct DLL_LINKAGE CObstacleInfo { int ID; std::string defName, @@ -98,15 +96,15 @@ struct DLL_EXPORT CObstacleInfo std::pair posShift; //shift of obstacle's position in the battlefield , eg. if it's <-1, 2> obstacle will be printed one pixel to the left and two to the bottom int getWidth() const; //returns width of obstacle in hexes int getHeight() const; //returns height of obstacle in hexes - std::vector getBlocked(THex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex' - THex getMaxBlocked(THex hex) const; //returns maximal hex (max number) covered by this obstacle + std::vector getBlocked(SHexField hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex' + SHexField getMaxBlocked(SHexField hex) const; //returns maximal hex (max number) covered by this obstacle template void serialize(Handler &h, const int version) { h & ID & defName & blockmap & allowedTerrains & posShift; } }; -struct DLL_EXPORT SPuzzleInfo +struct DLL_LINKAGE SPuzzleInfo { ui16 number; //type of puzzle si16 x, y; //position @@ -121,7 +119,7 @@ struct DLL_EXPORT SPuzzleInfo const int PUZZLES_PER_FACTION = 48; -class DLL_EXPORT CHeroHandler +class DLL_LINKAGE CHeroHandler { public: std::vector< ConstTransitivePtr > heroes; //changed from nodrze @@ -146,11 +144,11 @@ public: void loadObstacles(); //loads info about obstacles - std::vector puzzleInfo[F_NUMBER]; //descriptions of puzzles + std::vector puzzleInfo[GameConstants::F_NUMBER]; //descriptions of puzzles void loadPuzzleInfo(); - unsigned int level(ui64 experience) const; //calculates level corresponding to given experience amount - ui64 reqExp(unsigned int level) const; //calculates experience required for given level + ui32 level(ui64 experience) const; //calculates level corresponding to given experience amount + ui64 reqExp(ui32 level) const; //calculates experience required for given level void loadHeroes(); void loadHeroClasses(); @@ -172,5 +170,3 @@ public: } } }; - -#endif // __CHEROHANDLER_H__ diff --git a/lib/CLodHandler.cpp b/lib/CLodHandler.cpp index 02e943f19..d557b8e45 100644 --- a/lib/CLodHandler.cpp +++ b/lib/CLodHandler.cpp @@ -1,17 +1,7 @@ -#define VCMI_DLL -#include "../stdafx.h" -#include "zlib.h" +#include "StdInc.h" #include "CLodHandler.h" -#include -#include -#include -#include -#include -#include "boost/filesystem.hpp" -#include -#include -#include -#include + +#include "zlib.h" #include "vcmi_endian.h" #include "VCMIDirs.h" #ifdef max @@ -30,7 +20,7 @@ VCMIDirs GVCMIDirs; * */ -std::string readString(const unsigned char * bufor, int &i) +std::string readString(const ui8 * bufor, int &i) { int len = read_le_u32(bufor + i); i+=4; assert(len >= 0 && len <= 500000); //not too long @@ -56,7 +46,7 @@ void CLodHandler::convertName(std::string &filename, std::string *extension) } } -unsigned char * CLodHandler::giveFile(std::string fname, LodFileType type, int * length) +ui8 * CLodHandler::giveFile(std::string fname, LodFileType type, int * length) { convertName(fname); boost::unordered_set::const_iterator en_it = entries.find(Entry(fname, type)); @@ -71,11 +61,11 @@ unsigned char * CLodHandler::giveFile(std::string fname, LodFileType type, int * if(length) *length = ourEntry.realSize; mutex->lock(); - unsigned char * outp; + ui8 * outp; if (ourEntry.offset<0) //file is in the sprites/ folder; no compression { int result; - outp = new unsigned char[ourEntry.realSize]; + outp = new ui8[ourEntry.realSize]; FILE * f = fopen((myDir + "/" + ourEntry.realName).c_str(), "rb"); if (f) { @@ -96,7 +86,7 @@ unsigned char * CLodHandler::giveFile(std::string fname, LodFileType type, int * } else if (ourEntry.size==0) //file is not compressed { - outp = new unsigned char[ourEntry.realSize]; + outp = new ui8[ourEntry.realSize]; LOD.seekg(ourEntry.offset, std::ios::beg); LOD.read((char*)outp, ourEntry.realSize); @@ -105,11 +95,11 @@ unsigned char * CLodHandler::giveFile(std::string fname, LodFileType type, int * } else //we will decompress file { - outp = new unsigned char[ourEntry.size]; + outp = new ui8[ourEntry.size]; LOD.seekg(ourEntry.offset, std::ios::beg); LOD.read((char*)outp, ourEntry.size); - unsigned char * decomp = NULL; + ui8 * decomp = NULL; infs2(outp, ourEntry.size, ourEntry.realSize, decomp); mutex->unlock(); delete[] outp; @@ -134,12 +124,12 @@ bool CLodHandler::haveFile(std::string name, LodFileType type) return vstd::contains(entries, Entry(name, type)); } -DLL_EXPORT int CLodHandler::infs2(unsigned char * in, int size, int realSize, unsigned char *& out, int wBits) +DLL_LINKAGE int CLodHandler::infs2(ui8 * in, int size, int realSize, ui8 *& out, int wBits) { int ret; unsigned have; z_stream strm; - out = new unsigned char [realSize]; + out = new ui8 [realSize]; int latPosOut = 0; /* allocate inflate state */ @@ -201,7 +191,7 @@ DLL_EXPORT int CLodHandler::infs2(unsigned char * in, int size, int realSize, un void CLodHandler::extractFile(const std::string FName, const std::string name, LodFileType type) { int len; //length of file to write - unsigned char * outp = giveFile(name, type, &len); + ui8 * outp = giveFile(name, type, &len); std::ofstream out; out.open(FName.c_str(), std::ios::binary); if(!out.is_open()) @@ -271,7 +261,7 @@ void CLodHandler::init(const std::string lodFile, const std::string dirName) struct LodEntry *lodEntries = new struct LodEntry[totalFiles]; LOD.read((char *)lodEntries, sizeof(struct LodEntry) * totalFiles); - for (unsigned int i=0; i mapstr; + std::vector mapstr; // Read a map by chunks // We could try to read the map size directly (cf RFC 1952) and then read // directly the whole map, but that would create more problems. do { - unsigned char *buf = new unsigned char[bufsize]; + ui8 *buf = new ui8[bufsize]; int ret = gzread(map, buf, bufsize); if (ret == 0 || ret == -1) { @@ -393,9 +383,9 @@ unsigned char * CLodHandler::getUnpackedFile( const std::string & path, int * si gzclose(map); // Now that we know the uncompressed size, reassemble the chunks - unsigned char *initTable = new unsigned char[mapsize]; + ui8 *initTable = new ui8[mapsize]; - std::vector::iterator it; + std::vector::iterator it; int offset; int tocopy = mapsize; for (it = mapstr.begin(), offset = 0; diff --git a/lib/CLodHandler.h b/lib/CLodHandler.h index e89a4b900..337436356 100644 --- a/lib/CLodHandler.h +++ b/lib/CLodHandler.h @@ -1,12 +1,6 @@ -#ifndef __CLODHANDLER_H__ -#define __CLODHANDLER_H__ -#include "../global.h" -#include -#include -#include -#include -#include -#include +#pragma once + + /* * CLodhandler.h, part of VCMI engine @@ -35,12 +29,12 @@ struct LodEntry { ui32 size; /* little endian */ }; -static inline char readChar(const unsigned char * bufor, int &i) +static inline char readChar(const ui8 * bufor, int &i) { return bufor[i++]; } -DLL_EXPORT std::string readString(const unsigned char * bufor, int &i); +DLL_LINKAGE std::string readString(const ui8 * bufor, int &i); enum LodFileType{ FILE_ANY, @@ -91,17 +85,17 @@ public: } -class DLL_EXPORT CLodHandler +class DLL_LINKAGE CLodHandler { std::map extMap;// to convert extensions to file type std::ifstream LOD; - unsigned int totalFiles; + ui32 totalFiles; boost::mutex *mutex; std::string myDir; //load files from this dir instead of .lod file void initEntry(Entry &e, const std::string name); - int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler + int infs2(ui8 * in, int size, int realSize, ui8*& out, int wBits=15); //zlib fast handler public: //convert string to upper case and remove extension. If extension!=NULL -> it will be copied here (including dot) @@ -113,16 +107,13 @@ public: ~CLodHandler(); void init(const std::string lodFile, const std::string dirName); std::string getFileName(std::string lodFile, LodFileType type=FILE_ANY); - unsigned char * giveFile(std::string defName, LodFileType type=FILE_ANY, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed! + ui8 * giveFile(std::string defName, LodFileType type=FILE_ANY, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed! bool haveFile(std::string name, LodFileType type=FILE_ANY);//check if file is present in lod std::string getTextFile(std::string name, LodFileType type=FILE_TEXT); //extracts one file void extractFile(const std::string FName, const std::string name, LodFileType type=FILE_ANY); //extracts a specific file //unpack data from memory, input data will be deleted - static unsigned char * getUnpackedData(unsigned char *data, size_t inputSize, int * outputSize); + static ui8 * getUnpackedData(ui8 *data, size_t inputSize, int * outputSize); //loads given file, decompresses and returns - static unsigned char * getUnpackedFile(const std::string & path, int * sizeOut); + static ui8 * getUnpackedFile(const std::string & path, int * sizeOut); }; - - -#endif // __CLODHANDLER_H__ diff --git a/lib/CMapInfo.cpp b/lib/CMapInfo.cpp index 93a802fc0..6f4bd169e 100644 --- a/lib/CMapInfo.cpp +++ b/lib/CMapInfo.cpp @@ -1,14 +1,15 @@ -#define VCMI_DLL - +#include "StdInc.h" #include "CMapInfo.h" -#include "../StartInfo.h" + +#include "StartInfo.h" #include "map.h" #include "CCampaignHandler.h" +#include "GameConstants.h" void CMapInfo::countPlayers() { actualHumanPlayers = playerAmnt = humenPlayers = 0; - for(int i=0;iplayers[i].canHumanPlay) { @@ -32,7 +33,7 @@ CMapInfo::CMapInfo(bool map) { } -void CMapInfo::mapInit(const std::string &fname, const unsigned char *map ) +void CMapInfo::mapInit(const std::string &fname, const ui8 *map ) { filename = fname; int i = 0; diff --git a/lib/CMapInfo.h b/lib/CMapInfo.h index 4f62ad143..9f5169d34 100644 --- a/lib/CMapInfo.h +++ b/lib/CMapInfo.h @@ -1,6 +1,6 @@ #pragma once -#include "../global.h" + class CMapHeader; class CCampaignHeader; @@ -8,7 +8,7 @@ struct StartInfo; /// A class which stores the count of human players and all players, the filename, /// scenario options, the map header information,... -class DLL_EXPORT CMapInfo +class DLL_LINKAGE CMapInfo { public: CMapHeader * mapHeader; //may be NULL if campaign @@ -22,9 +22,9 @@ public: int actualHumanPlayers; // >1 if multiplayer game CMapInfo(bool map = true); ~CMapInfo(); - //CMapInfo(const std::string &fname, const unsigned char *map); + //CMapInfo(const std::string &fname, const ui8 *map); void setHeader(CMapHeader *header); - void mapInit(const std::string &fname, const unsigned char *map); + void mapInit(const std::string &fname, const ui8 *map); void campaignInit(); void countPlayers(); diff --git a/lib/CObjectHandler.cpp b/lib/CObjectHandler.cpp index 546103d37..c2a442e6e 100644 --- a/lib/CObjectHandler.cpp +++ b/lib/CObjectHandler.cpp @@ -1,6 +1,6 @@ -#define VCMI_DLL -#include "../stdafx.h" +#include "StdInc.h" #include "CObjectHandler.h" + #include "CDefObjInfoHandler.h" #include "CLodHandler.h" #include "CGeneralTextHandler.h" @@ -8,10 +8,6 @@ #include "CHeroHandler.h" #include "CSpellHandler.h" #include "../client/CSoundBase.h" -#include -#include -#include -#include #include #include "CTownHandler.h" #include "CCreatureHandler.h" @@ -19,15 +15,12 @@ #include "IGameCallback.h" #include "CGameState.h" #include "NetPacks.h" -#include "../StartInfo.h" +#include "StartInfo.h" #include "map.h" -#include #include -#include -#include -#include #include "CBuildingHandler.h" #include "../lib/JsonNode.h" +#include "GameConstants.h" using namespace boost::assign; @@ -44,7 +37,7 @@ using namespace boost::assign; std::map > > CGTeleport::objs; std::vector > CGTeleport::gates; IGameCallback * IObjectInterface::cb = NULL; -DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, int mode); +DLL_LINKAGE void loadToIt(std::string &dest, const std::string &src, int &iter, int mode); extern CLodHandler * bitmaph; extern boost::rand48 ran; std::map > CGKeys::playerKeyMap; @@ -121,10 +114,10 @@ static void readCreatures(const JsonNode &creature, std::vector< std::pair pos.y>cmp.pos.y) return false; - if(cmp.ID==HEROI_TYPE && ID!=HEROI_TYPE) + if(cmp.ID==GameConstants::HEROI_TYPE && ID!=GameConstants::HEROI_TYPE) return true; - if(cmp.ID!=HEROI_TYPE && ID==HEROI_TYPE) + if(cmp.ID!=GameConstants::HEROI_TYPE && ID==GameConstants::HEROI_TYPE) return false; if(!defInfo->isVisitable() && cmp.defInfo->isVisitable()) return true; @@ -515,7 +508,7 @@ static int lowestSpeed(const CGHeroInstance * chi) return ret; } -unsigned int CGHeroInstance::getTileCost(const TerrainTile &dest, const TerrainTile &from) const +ui32 CGHeroInstance::getTileCost(const TerrainTile &dest, const TerrainTile &from) const { //TODO: check if all creatures are on its native terrain and change cost appropriately @@ -554,9 +547,9 @@ unsigned int CGHeroInstance::getTileCost(const TerrainTile &dest, const TerrainT // - for loop is wrong. will not find all creatures. must use iterator instead. // - -> is the slot number. use second->first for creature index // Is lowestSpeed() the correct equivalent ? -unsigned int CGHeroInstance::getLowestCreatureSpeed() const +ui32 CGHeroInstance::getLowestCreatureSpeed() const { - unsigned int sl = 100; + ui32 sl = 100; for(size_t h=0; h < stacksCount(); ++h) { if(VLC->creh->creatures[Slots().find(h)->first]->speedheroh->heroes[subID]; @@ -725,11 +718,11 @@ void CGHeroInstance::initHero() else //remove placeholder spells -= 0xffffffff; - if(!getArt(Arts::MACH4) && !getArt(Arts::SPELLBOOK) && type->startingSpell >= 0) //no catapult means we haven't read pre-existent set -> use default rules for spellbook - putArtifact(Arts::SPELLBOOK, CArtifactInstance::createNewArtifactInstance(0)); + if(!getArt(ArtifactPosition::MACH4) && !getArt(ArtifactPosition::SPELLBOOK) && type->startingSpell >= 0) //no catapult means we haven't read pre-existent set -> use default rules for spellbook + putArtifact(ArtifactPosition::SPELLBOOK, CArtifactInstance::createNewArtifactInstance(0)); - if(!getArt(Arts::MACH4)) - putArtifact(Arts::MACH4, CArtifactInstance::createNewArtifactInstance(3)); //everyone has a catapult + if(!getArt(ArtifactPosition::MACH4)) + putArtifact(ArtifactPosition::MACH4, CArtifactInstance::createNewArtifactInstance(3)); //everyone has a catapult if(portrait < 0 || portrait == 255) portrait = subID; @@ -803,7 +796,7 @@ void CGHeroInstance::initArmy(IArmyDescriptor *dst /*= NULL*/) switch (creID) { case 145: //catapult - slot = Arts::MACH4; + slot = ArtifactPosition::MACH4; aid = 3; break; default: @@ -823,10 +816,10 @@ void CGHeroInstance::initArmy(IArmyDescriptor *dst /*= NULL*/) } void CGHeroInstance::initHeroDefInfo() { - if(!defInfo || defInfo->id != HEROI_TYPE) + if(!defInfo || defInfo->id != GameConstants::HEROI_TYPE) { defInfo = new CGDefInfo(); - defInfo->id = HEROI_TYPE; + defInfo->id = GameConstants::HEROI_TYPE; defInfo->subid = subID; defInfo->printPriority = 0; defInfo->visitDir = 0xff; @@ -854,7 +847,7 @@ void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const { if(h == this) return; //exclude potential self-visiting - if (ID == HEROI_TYPE) //hero + if (ID == GameConstants::HEROI_TYPE) //hero { if( cb->gameState()->getPlayerRelations(tempOwner, h->tempOwner)) //our or ally hero { @@ -878,7 +871,7 @@ void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const if(cb->getHeroCount(h->tempOwner,false) < 8) //free hero slot { cb->changeObjPos(id,pos+int3(1,0,0),0); - cb->setObjProperty(id, ObjProperty::ID, HEROI_TYPE); //set ID to 34 + cb->setObjProperty(id, ObjProperty::ID, GameConstants::HEROI_TYPE); //set ID to 34 cb->giveHero(id,h->tempOwner); //recreates def and adds hero to player iw.text << std::pair(11,102); @@ -1046,7 +1039,7 @@ void CGHeroInstance::initObj() speciality.addNewBonus(bonus); bonus = new Bonus(*bonus); } - delNull(bonus); + vstd::clear_pointer(bonus); break; } case 10://resource generation @@ -1232,7 +1225,7 @@ ui64 CGHeroInstance::getTotalStrength() const expType CGHeroInstance::calculateXp(expType exp) const { - return exp * (100 + valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::LEARNING))/100.0f; + return exp * (100 + valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::LEARNING))/100.0; } ui8 CGHeroInstance::getSpellSchoolLevel(const CSpell * spell, int *outSelectedSchool) const @@ -1260,8 +1253,8 @@ ui8 CGHeroInstance::getSpellSchoolLevel(const CSpell * spell, int *outSelectedSc - amax(skill, valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 0)); //any school bonus - amax(skill, valOfBonuses(Bonus::SPELL, spell->id)); //given by artifact or other effect + vstd::amax(skill, valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 0)); //any school bonus + vstd::amax(skill, valOfBonuses(Bonus::SPELL, spell->id)); //given by artifact or other effect if (hasBonusOfType(Bonus::MAXED_SPELL, spell->id))//hero speciality (Daremyth, Melodia) skill = 3; assert(skill >= 0 && skill <= 3); @@ -1301,7 +1294,7 @@ CStackBasicDescriptor CGHeroInstance::calculateNecromancy (const BattleResult &b if (necromancyLevel > 0) { double necromancySkill = valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, NECROMANCY)/100.0; - amin(necromancySkill, 1.0); //it's impossible to raise more creatures than all... + vstd::amin(necromancySkill, 1.0); //it's impossible to raise more creatures than all... const std::map &casualties = battleResult.casualties[!battleResult.winner]; ui32 raisedUnits = 0; @@ -1431,7 +1424,7 @@ void CGHeroInstance::pushPrimSkill(int which, int val) addNewBonus(new Bonus(Bonus::PERMANENT, Bonus::PRIMARY_SKILL, Bonus::HERO_BASE_SKILL, val, id, which)); } -EAlignment CGHeroInstance::getAlignment() const +EAlignment::EAlignment CGHeroInstance::getAlignment() const { return type->heroClass->getAlignment(); } @@ -1460,7 +1453,7 @@ void CGHeroInstance::putInBackpack(CArtifactInstance *art) bool CGHeroInstance::hasSpellbook() const { - return getArt(Arts::SPELLBOOK); + return getArt(ArtifactPosition::SPELLBOOK); } void CGHeroInstance::deserializationFix() @@ -1488,7 +1481,7 @@ CBonusSystemNode * CGHeroInstance::whereShouldBeAttached(CGameState *gs) int CGHeroInstance::movementPointsAfterEmbark(int MPsBefore, int basicCost, bool disembark /*= false*/) const { if(hasBonusOfType(Bonus::FREE_SHIP_BOARDING)) - return (MPsBefore - basicCost) * ((float)(maxMovePoints(disembark)) / maxMovePoints(!disembark)); + return (MPsBefore - basicCost) * static_cast(maxMovePoints(disembark)) / maxMovePoints(!disembark); return 0; //take all MPs otherwise } @@ -1564,12 +1557,12 @@ void CGDwelling::setProperty(ui8 what, ui32 val) case ObjProperty::OWNER: //change owner if (ID == 17) //single generators { - if (tempOwner != NEUTRAL_PLAYER) + if (tempOwner != GameConstants::NEUTRAL_PLAYER) { std::vector >* dwellings = &cb->gameState()->players[tempOwner].dwellings; dwellings->erase (std::find(dwellings->begin(), dwellings->end(), this)); } - if (val != NEUTRAL_PLAYER) //can new owner be neutral? + if (val != GameConstants::NEUTRAL_PLAYER) //can new owner be neutral? cb->gameState()->players[val].dwellings.push_back (this); } break; @@ -1647,7 +1640,7 @@ void CGDwelling::newTurn() const return; //town growths and War Machines Factories are handled separately - if(ID == TOWNI_TYPE || ID == 106) + if(ID == GameConstants::TOWNI_TYPE || ID == 106) return; if(ID == 78) //if it's a refugee camp, we need to pick an available creature @@ -1666,7 +1659,7 @@ void CGDwelling::newTurn() const { CCreature *cre = VLC->creh->creatures[creatures[i].second[0]]; TQuantity amount = cre->growth * (1 + cre->valOfBonuses(Bonus::CREATURE_GROWTH_PERCENT)/100) + cre->valOfBonuses(Bonus::CREATURE_GROWTH); - if (DWELLINGS_ACCUMULATE_CREATURES) + if (GameConstants::DWELLINGS_ACCUMULATE_CREATURES) sac.creatures[i].first += amount; else sac.creatures[i].first = amount; @@ -1839,9 +1832,9 @@ int CGTownInstance::mageGuildLevel() const } bool CGTownInstance::creatureDwelling(const int & level, bool upgraded) const { - if ( level<0 || level >= CREATURES_PER_TOWN ) + if ( level<0 || level >= GameConstants::CREATURES_PER_TOWN ) return false; - return vstd::contains(builtBuildings, 30+level+upgraded*CREATURES_PER_TOWN); + return vstd::contains(builtBuildings, 30+level+upgraded*GameConstants::CREATURES_PER_TOWN); } int CGTownInstance::getHordeLevel(const int & HID) const//HID - 0 or 1; returns creature level or -1 if that horde structure is not present { @@ -1856,9 +1849,9 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const { GrowthInfo ret; - if (level<0 || level >=CREATURES_PER_TOWN) + if (level<0 || level >=GameConstants::CREATURES_PER_TOWN) return ret; - if (!vstd::contains(builtBuildings, Buildings::DWELL_FIRST+level)) + if (!vstd::contains(builtBuildings, EBuilding::DWELL_FIRST+level)) return ret; //no dwelling const CCreature *creature = VLC->creh->creatures[town->basicCreatures[level]]; @@ -1867,18 +1860,18 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const ret.entries.push_back(GrowthInfo::Entry(VLC->generaltexth->allTexts[590], base));// \n\nBasic growth %d" - if ( vstd::contains(builtBuildings, Buildings::CASTLE)) - ret.entries.push_back(GrowthInfo::Entry(subID, Buildings::CASTLE, castleBonus = base)); - else if ( vstd::contains(builtBuildings, Buildings::CITADEL)) - ret.entries.push_back(GrowthInfo::Entry(subID, Buildings::CITADEL, castleBonus = base / 2)); + if ( vstd::contains(builtBuildings, EBuilding::CASTLE)) + ret.entries.push_back(GrowthInfo::Entry(subID, EBuilding::CASTLE, castleBonus = base)); + else if ( vstd::contains(builtBuildings, EBuilding::CITADEL)) + ret.entries.push_back(GrowthInfo::Entry(subID, EBuilding::CITADEL, castleBonus = base / 2)); if(town->hordeLvl[0] == level)//horde 1 - if( vstd::contains(builtBuildings, Buildings::HORDE_1) || vstd::contains(builtBuildings, Buildings::HORDE_1_UPGR)) - ret.entries.push_back(GrowthInfo::Entry(subID, Buildings::HORDE_1, creature->hordeGrowth)); + if( vstd::contains(builtBuildings, EBuilding::HORDE_1) || vstd::contains(builtBuildings, EBuilding::HORDE_1_UPGR)) + ret.entries.push_back(GrowthInfo::Entry(subID, EBuilding::HORDE_1, creature->hordeGrowth)); if(town->hordeLvl[1] == level)//horde 2 - if(vstd::contains(builtBuildings, Buildings::HORDE_2) || vstd::contains(builtBuildings, Buildings::HORDE_2_UPGR)) - ret.entries.push_back(GrowthInfo::Entry(subID, Buildings::HORDE_2, creature->hordeGrowth)); + if(vstd::contains(builtBuildings, EBuilding::HORDE_2) || vstd::contains(builtBuildings, EBuilding::HORDE_2_UPGR)) + ret.entries.push_back(GrowthInfo::Entry(subID, EBuilding::HORDE_2, creature->hordeGrowth)); int dwellingBonus = 0; if(const PlayerState *p = cb->getPlayer(tempOwner, false)) @@ -1901,8 +1894,8 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const BOOST_FOREACH(const Bonus *b, *bonuses2) ret.entries.push_back(GrowthInfo::Entry(b->Description() + " %+d", b->val * (base + castleBonus) / 100)); - if(vstd::contains(builtBuildings, Buildings::GRAIL)) //grail - +50% to ALL (so far added) growth - ret.entries.push_back(GrowthInfo::Entry(subID, Buildings::GRAIL, ret.totalGrowth() / 2)); + if(vstd::contains(builtBuildings, EBuilding::GRAIL)) //grail - +50% to ALL (so far added) growth + ret.entries.push_back(GrowthInfo::Entry(subID, EBuilding::GRAIL, ret.totalGrowth() / 2)); return ret; } @@ -2008,10 +2001,10 @@ void CGTownInstance::initObj() hoverName = name + ", " + town->Name(); if (subID == 5) - creatures.resize(CREATURES_PER_TOWN+1);//extra dwelling for Dungeon + creatures.resize(GameConstants::CREATURES_PER_TOWN+1);//extra dwelling for Dungeon else - creatures.resize(CREATURES_PER_TOWN); - for (int i = 0; i < CREATURES_PER_TOWN; i++) + creatures.resize(GameConstants::CREATURES_PER_TOWN); + for (int i = 0; i < GameConstants::CREATURES_PER_TOWN; i++) { if(creatureDwelling(i,false)) creatures[i].second.push_back(town->basicCreatures[i]); @@ -2042,7 +2035,7 @@ void CGTownInstance::newTurn() const { if (cb->getDate(1) == 1) //reset on new week { - if (vstd::contains(builtBuildings,17) && subID == 1 && cb->getDate(0) != 1 && (tempOwner < PLAYER_LIMIT) )//give resources for Rampart, Mystic Pond + if (vstd::contains(builtBuildings,17) && subID == 1 && cb->getDate(0) != 1 && (tempOwner < GameConstants::PLAYER_LIMIT) )//give resources for Rampart, Mystic Pond { int resID = rand()%4+2;//bonus to random rare resource resID = (resID==2)?1:resID; @@ -2059,7 +2052,7 @@ void CGTownInstance::newTurn() const cb->setObjProperty (id, 12, (*i)->id); //reset visitors for Mana Vortex } - if (tempOwner == NEUTRAL_PLAYER) //garrison growth for neutral towns + if (tempOwner == GameConstants::NEUTRAL_PLAYER) //garrison growth for neutral towns { std::vector nativeCrits; //slots for (TSlots::const_iterator it = Slots().begin(); it != Slots().end(); it++) @@ -2084,9 +2077,9 @@ void CGTownInstance::newTurn() const cb->changeStackType(sl, VLC->creh->creatures[*c->upgrades.begin()]); } } - if ((stacksCount() < ARMY_SIZE && rand()%100 < 25) || Slots().empty()) //add new stack + if ((stacksCount() < GameConstants::ARMY_SIZE && rand()%100 < 25) || Slots().empty()) //add new stack { - int i = rand() % std::min (ARMY_SIZE, cb->getDate(3)<<1); + int i = rand() % std::min (GameConstants::ARMY_SIZE, cb->getDate(3)<<1); TCreature c = town->basicCreatures[i]; TSlot n = -1; @@ -2118,7 +2111,7 @@ int3 CGTownInstance::getSightCenter() const ui8 CGTownInstance::getPassableness() const { if (!armedGarrison())//empty castle - anyone can visit - return ALL_PLAYERS; + return GameConstants::ALL_PLAYERS; if ( tempOwner == 255 )//neutral guarded - no one can visit return 0; @@ -2196,21 +2189,21 @@ int CGTownInstance::getMarketEfficiency() const return marketCount; } -bool CGTownInstance::allowsTrade(EMarketMode mode) const +bool CGTownInstance::allowsTrade(EMarketMode::EMarketMode mode) const { switch(mode) { - case RESOURCE_RESOURCE: - case RESOURCE_PLAYER: + case EMarketMode::RESOURCE_RESOURCE: + case EMarketMode::RESOURCE_PLAYER: return vstd::contains(builtBuildings, 14); // marketplace - case ARTIFACT_RESOURCE: - case RESOURCE_ARTIFACT: + case EMarketMode::ARTIFACT_RESOURCE: + case EMarketMode::RESOURCE_ARTIFACT: return (subID == 2 || subID == 5 || subID == 8) && vstd::contains(builtBuildings, 17);//artifact merchants - case CREATURE_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: return subID == 6 && vstd::contains(builtBuildings, 21); //Freelancer's guild - case CREATURE_UNDEAD: + case EMarketMode::CREATURE_UNDEAD: return subID == 4 && vstd::contains(builtBuildings, 22);//Skeleton transformer - case RESOURCE_SKILL: + case EMarketMode::RESOURCE_SKILL: return subID == 8 && vstd::contains(builtBuildings, 21);//Magic University default: assert(0); @@ -2218,9 +2211,9 @@ bool CGTownInstance::allowsTrade(EMarketMode mode) const } } -std::vector CGTownInstance::availableItemsIds(EMarketMode mode) const +std::vector CGTownInstance::availableItemsIds(EMarketMode::EMarketMode mode) const { - if(mode == RESOURCE_ARTIFACT) + if(mode == EMarketMode::RESOURCE_ARTIFACT) { std::vector ret; BOOST_FOREACH(const CArtifact *a, merchantArtifacts) @@ -2230,7 +2223,7 @@ std::vector CGTownInstance::availableItemsIds(EMarketMode mode) const ret.push_back(-1); return ret; } - else if ( mode == RESOURCE_SKILL ) + else if ( mode == EMarketMode::RESOURCE_SKILL ) { return universitySkills; } @@ -2823,7 +2816,7 @@ void CTownBonus::onHeroVisit (const CGHeroInstance * h) const break; case 5://academy of battle scholars what = 4; - val = 1000*(100+h->getSecSkillLevel(CGHeroInstance::LEARNING)*5)/100.0f; + val = 1000*(100+h->getSecSkillLevel(CGHeroInstance::LEARNING)*5)/100.0; mid = 583; iw.components.push_back (Component(Component::EXPERIENCE, 0, val, 0)); break; @@ -3012,13 +3005,13 @@ void CGCreature::initObj() } void CGCreature::newTurn() const {//Works only for stacks of single type of size up to 2 millions - if (stacks.begin()->second->count < CREEP_SIZE && cb->getDate(1) == 1 && cb->getDate(0) > 1) + if (stacks.begin()->second->count < GameConstants::CREEP_SIZE && cb->getDate(1) == 1 && cb->getDate(0) > 1) { - ui32 power = temppower * (100 + WEEKLY_GROWTH)/100; - cb->setObjProperty(id, ObjProperty::MONSTER_COUNT, std::min (power/1000 , (ui32)CREEP_SIZE)); //set new amount + ui32 power = temppower * (100 + GameConstants::WEEKLY_GROWTH)/100; + cb->setObjProperty(id, ObjProperty::MONSTER_COUNT, std::min (power/1000 , (ui32)GameConstants::CREEP_SIZE)); //set new amount cb->setObjProperty(id, ObjProperty::MONSTER_POWER, power); //increase temppower } - if (STACK_EXP) + if (GameConstants::STACK_EXP) cb->setObjProperty(id, ObjProperty::MONSTER_EXP, 10000); //for testing purpose } void CGCreature::setPropertyDer(ui8 what, ui32 val) @@ -3168,7 +3161,7 @@ void CGCreature::fight( const CGHeroInstance *h ) const int basicType = stacks.begin()->second->type->idNumber; cb->setObjProperty(id, ObjProperty::MONSTER_RESTORE_TYPE, basicType); //store info about creature stack - float relativePower = ((float)h->getTotalStrength() / getArmyStrength()); + double relativePower = static_cast(h->getTotalStrength()) / getArmyStrength(); int stacksCount; //TODO: number depends on tile type if (relativePower < 0.5) @@ -3270,7 +3263,7 @@ void CGMine::newTurn() const if(cb->getDate() == 1) return; - if (tempOwner == NEUTRAL_PLAYER) + if (tempOwner == GameConstants::NEUTRAL_PLAYER) return; cb->giveResource(tempOwner, producedResource, producedQuantity); @@ -3293,7 +3286,7 @@ void CGMine::initObj() assert(possibleResources.size()); producedResource = possibleResources[ran()%possibleResources.size()]; - tempOwner = NEUTRAL_PLAYER; + tempOwner = GameConstants::NEUTRAL_PLAYER; hoverName = VLC->generaltexth->mines[7].first + "\n" + VLC->generaltexth->allTexts[202] + " " + troglodytes->getQuantityTXT(false) + " " + troglodytes->type->namePl; } else @@ -3302,8 +3295,8 @@ void CGMine::initObj() MetaString ms; ms << std::pair(9,producedResource); - if(tempOwner >= PLAYER_LIMIT) - tempOwner = NEUTRAL_PLAYER; + if(tempOwner >= GameConstants::PLAYER_LIMIT) + tempOwner = GameConstants::NEUTRAL_PLAYER; else ms << " (" << std::pair(6,23+tempOwner) << ")"; ms.toString(hoverName); @@ -3569,7 +3562,7 @@ void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const } TQuantity countToTake = h->getStackCount(targetstack) * 0.5; - amax(countToTake, 1); + vstd::amax(countToTake, 1); InfoWindow iw; @@ -4402,7 +4395,7 @@ void CGSeerHut::onHeroVisit( const CGHeroInstance * h ) const switch (rewardType) { - case 1: bd.components.push_back(Component (Component::EXPERIENCE, 0, rVal*(100+h->getSecSkillLevel(CGHeroInstance::LEARNING)*5)/100.0f, 0)); + case 1: bd.components.push_back(Component (Component::EXPERIENCE, 0, rVal*(100+h->getSecSkillLevel(CGHeroInstance::LEARNING)*5)/100.0, 0)); break; case 2: bd.components.push_back(Component (Component::PRIM_SKILL, 5, rVal, 0)); break; @@ -4556,7 +4549,7 @@ const CGHeroInstance * CGSeerHut::getHeroToKill(bool allowNull) const const CGObjectInstance *o = cb->getObjByQuestIdentifier(m13489val); if(allowNull && !o) return NULL; - assert(o && o->ID == HEROI_TYPE); + assert(o && o->ID == GameConstants::HEROI_TYPE); return static_cast(o); } @@ -4625,7 +4618,7 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const iw.text << std::pair(11,172); iw.text.addReplacement(MetaString::SEC_SKILL_NAME, ability); } - else if(h->secSkills.size() >= SKILL_PER_HERO) //already all skills slots used + else if(h->secSkills.size() >= GameConstants::SKILL_PER_HERO) //already all skills slots used { iw.text << std::pair(11,173); iw.text.addReplacement(MetaString::SEC_SKILL_NAME, ability); @@ -5025,7 +5018,7 @@ void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) con int curLev = h->getSecSkillLevel(static_cast(abilities[i])); if( (curLev && curLev < abilityLevels[i]) - || (h->secSkills.size() < SKILL_PER_HERO) ) + || (h->secSkills.size() < GameConstants::SKILL_PER_HERO) ) { cb->changeSecSkill(h->id,abilities[i],abilityLevels[i],true); } @@ -5380,13 +5373,13 @@ void CGScholar::onHeroVisit( const CGHeroInstance * h ) const //check if the bonus if applicable, if not - give primary skill (always possible) int ssl = h->getSecSkillLevel(static_cast(bid)); //current sec skill level, used if bonusType == 1 if((type == 1 - && ((ssl == 3) || (!ssl && h->secSkills.size() == SKILL_PER_HERO))) ////hero already has expert level in the skill or (don't know skill and doesn't have free slot) + && ((ssl == 3) || (!ssl && h->secSkills.size() == GameConstants::SKILL_PER_HERO))) ////hero already has expert level in the skill or (don't know skill and doesn't have free slot) || (type == 2 && (!h->getArt(17) || vstd::contains(h->spells, (ui32) bid) || (VLC->spellh->spells[bid]->level > h->getSecSkillLevel(CGHeroInstance::WISDOM) + 2) ))) //hero doesn't have a spellbook or already knows the spell or doesn't have Wisdom { type = 0; - bid = ran() % PRIMARY_SKILLS; + bid = ran() % GameConstants::PRIMARY_SKILLS; } @@ -5431,10 +5424,10 @@ void CGScholar::initObj() switch(bonusType) { case 0: - bonusID = ran() % PRIMARY_SKILLS; + bonusID = ran() % GameConstants::PRIMARY_SKILLS; break; case 1: - bonusID = ran() % SKILL_QUANTITY; + bonusID = ran() % GameConstants::SKILL_QUANTITY; break; case 2: std::vector possibilities; @@ -5471,7 +5464,7 @@ void CGGarrison::fightOver (const CGHeroInstance *h, BattleResult *result) const ui8 CGGarrison::getPassableness() const { if ( !stacksCount() )//empty - anyone can visit - return ALL_PLAYERS; + return GameConstants::ALL_PLAYERS; if ( tempOwner == 255 )//neutral guarded - no one can visit return 0; @@ -5748,7 +5741,7 @@ void CBank::setPropertyDer (ui8 what, ui32 val) daycounter++; break; case 12: //multiplier, in percent - multiplier = ((float)val)/100; + multiplier = val / 100.0; break; case 13: //bank preset bc = VLC->objh->banksInfo[index][val]; @@ -6127,7 +6120,7 @@ void CGPyramid::endBattle (const CGHeroInstance *h, const BattleResult *result) } void CGKeys::setPropertyDer (ui8 what, ui32 val) //101-108 - enable key for player 1-8 { - if (what >= 101 && what <= (100 + PLAYER_LIMIT)) + if (what >= 101 && what <= (100 + GameConstants::PLAYER_LIMIT)) playerKeyMap.find(what-101)->second.insert((ui8)val); } @@ -6219,7 +6212,7 @@ void CGBorderGate::onHeroVisit( const CGHeroInstance * h ) const //TODO: passabi ui8 CGBorderGate::getPassableness() const { ui8 ret = 0; - for (int i = 0; i < PLAYER_LIMIT; i++) + for (int i = 0; i < GameConstants::PLAYER_LIMIT; i++) ret |= wasMyColorVisited(i)< &cost ) const { - cost.resize(RESOURCE_QUANTITY); + cost.resize(GameConstants::RESOURCE_QUANTITY); cost[0] = 10; cost[6] = 1000; } @@ -6419,7 +6412,7 @@ IShipyard * IShipyard::castFrom( CGObjectInstance *obj ) if(!obj) return NULL; - if(obj->ID == TOWNI_TYPE) + if(obj->ID == GameConstants::TOWNI_TYPE) { return static_cast(obj); } @@ -6597,7 +6590,7 @@ void CGObelisk::setPropertyDer( ui8 what, ui32 val ) switch(what) { case 20: - assert(val < PLAYER_LIMIT); + assert(val < GameConstants::PLAYER_LIMIT); visited[val]++; if(visited[val] > obeliskCount) @@ -6626,7 +6619,7 @@ void CGLighthouse::onHeroVisit( const CGHeroInstance * h ) const giveBonusTo(h->tempOwner); - if(oldOwner < PLAYER_LIMIT) //remove bonus from old owner + if(oldOwner < GameConstants::PLAYER_LIMIT) //remove bonus from old owner { RemoveBonus rb(RemoveBonus::PLAYER); rb.whoID = oldOwner; @@ -6639,7 +6632,7 @@ void CGLighthouse::onHeroVisit( const CGHeroInstance * h ) const void CGLighthouse::initObj() { - if(tempOwner < PLAYER_LIMIT) + if(tempOwner < GameConstants::PLAYER_LIMIT) { giveBonusTo(tempOwner); } @@ -6758,7 +6751,7 @@ void CArmedInstance::armyChanged() CBonusSystemNode * CArmedInstance::whereShouldBeAttached(CGameState *gs) { - if(tempOwner < PLAYER_LIMIT) + if(tempOwner < GameConstants::PLAYER_LIMIT) return gs->getPlayer(tempOwner); else return &gs->globalEffects; @@ -6769,15 +6762,15 @@ CBonusSystemNode * CArmedInstance::whatShouldBeAttached() return this; } -bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode) const +bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode::EMarketMode mode) const { switch(mode) { - case RESOURCE_RESOURCE: + case EMarketMode::RESOURCE_RESOURCE: { - float effectiveness = std::min(((float)getMarketEfficiency()+1.0f) / 20.0f, 0.5f); + double effectiveness = std::min((getMarketEfficiency() + 1.0) / 20.0, 0.5); - float r = VLC->objh->resVals[id1], //value of given resource + double r = VLC->objh->resVals[id1], //value of given resource g = VLC->objh->resVals[id2] / effectiveness; //value of wanted resource if(r>g) //if given resource is more expensive than wanted @@ -6787,17 +6780,17 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode) } else //if wanted resource is more expensive { - val1 = (g / r) + 0.5f; + val1 = (g / r) + 0.5; val2 = 1; } } break; - case CREATURE_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: { - const float effectivenessArray[] = {0, 0.3, 0.45, 0.50, 0.65, 0.7, 0.85, 0.9, 1}; - float effectiveness = effectivenessArray[std::min(getMarketEfficiency(), 8)]; + const double effectivenessArray[] = {0.0, 0.3, 0.45, 0.50, 0.65, 0.7, 0.85, 0.9, 1.0}; + double effectiveness = effectivenessArray[std::min(getMarketEfficiency(), 8)]; - float r = VLC->creh->creatures[id1]->cost[6], //value of given creature in gold + double r = VLC->creh->creatures[id1]->cost[6], //value of given creature in gold g = VLC->objh->resVals[id2] / effectiveness; //value of wanted resource if(r>g) //if given resource is more expensive than wanted @@ -6807,49 +6800,49 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode) } else //if wanted resource is more expensive { - val1 = (g / r) + 0.5f; + val1 = (g / r) + 0.5; val2 = 1; } } break; - case RESOURCE_PLAYER: + case EMarketMode::RESOURCE_PLAYER: val1 = 1; val2 = 1; break; - case RESOURCE_ARTIFACT: + case EMarketMode::RESOURCE_ARTIFACT: { - float effectiveness = std::min(((float)getMarketEfficiency()+3.0f) / 20.0f, 0.6f); - float r = VLC->objh->resVals[id1], //value of offered resource + double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6); + double r = VLC->objh->resVals[id1], //value of offered resource g = VLC->arth->artifacts[id2]->price / effectiveness; //value of bought artifact in gold if(id1 != 6) //non-gold prices are doubled r /= 2; assert(g >= r); //should we allow artifacts cheaper than unit of resource? - val1 = (g / r) + 0.5f; + val1 = (g / r) + 0.5; val2 = 1; } break; - case ARTIFACT_RESOURCE: + case EMarketMode::ARTIFACT_RESOURCE: { - float effectiveness = std::min(((float)getMarketEfficiency()+3.0f) / 20.0f, 0.6f); - float r = VLC->arth->artifacts[id1]->price * effectiveness, + double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6); + double r = VLC->arth->artifacts[id1]->price * effectiveness, g = VLC->objh->resVals[id2]; // if(id2 != 6) //non-gold prices are doubled // r /= 2; val1 = 1; - val2 = (r / g) + 0.5f; + val2 = (r / g) + 0.5; } break; - case CREATURE_EXP: + case EMarketMode::CREATURE_EXP: { val1 = 1; val2 = (VLC->creh->creatures[id1]->AIValue / 40) * 5; } break; - case ARTIFACT_EXP: + case EMarketMode::ARTIFACT_EXP: { val1 = 1; @@ -6872,32 +6865,32 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode) return true; } -bool IMarket::allowsTrade(EMarketMode mode) const +bool IMarket::allowsTrade(EMarketMode::EMarketMode mode) const { return false; } -int IMarket::availableUnits(EMarketMode mode, int marketItemSerial) const +int IMarket::availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const { switch(mode) { - case RESOURCE_RESOURCE: - case ARTIFACT_RESOURCE: - case CREATURE_RESOURCE: + case EMarketMode::RESOURCE_RESOURCE: + case EMarketMode::ARTIFACT_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: return -1; default: return 1; } } -std::vector IMarket::availableItemsIds(EMarketMode mode) const +std::vector IMarket::availableItemsIds(EMarketMode::EMarketMode mode) const { std::vector ret; switch(mode) { - case RESOURCE_RESOURCE: - case ARTIFACT_RESOURCE: - case CREATURE_RESOURCE: + case EMarketMode::RESOURCE_RESOURCE: + case EMarketMode::ARTIFACT_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: for (int i = 0; i < 7; i++) ret.push_back(i); default: @@ -6910,7 +6903,7 @@ const IMarket * IMarket::castFrom(const CGObjectInstance *obj) { switch(obj->ID) { - case TOWNI_TYPE: + case GameConstants::TOWNI_TYPE: return static_cast(obj); case 2: //Altar of Sacrifice case 7: //Black Market @@ -6932,12 +6925,12 @@ IMarket::IMarket(const CGObjectInstance *O) } -std::vector IMarket::availableModes() const +std::vector IMarket::availableModes() const { - std::vector ret; - for (int i = 0; i < MARTKET_AFTER_LAST_PLACEHOLDER; i++) - if(allowsTrade((EMarketMode)i)) - ret.push_back((EMarketMode)i); + std::vector ret; + for (int i = 0; i < EMarketMode::MARTKET_AFTER_LAST_PLACEHOLDER; i++) + if(allowsTrade((EMarketMode::EMarketMode)i)) + ret.push_back((EMarketMode::EMarketMode)i); return ret; } @@ -6956,12 +6949,12 @@ int CGMarket::getMarketEfficiency() const return 5; } -bool CGMarket::allowsTrade(EMarketMode mode) const +bool CGMarket::allowsTrade(EMarketMode::EMarketMode mode) const { switch(mode) { - case RESOURCE_RESOURCE: - case RESOURCE_PLAYER: + case EMarketMode::RESOURCE_RESOURCE: + case EMarketMode::RESOURCE_PLAYER: switch(ID) { case 99: //Trading Post @@ -6970,32 +6963,32 @@ bool CGMarket::allowsTrade(EMarketMode mode) const default: return false; } - case CREATURE_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: return ID == 213; //Freelancer's Guild //case ARTIFACT_RESOURCE: - case RESOURCE_ARTIFACT: + case EMarketMode::RESOURCE_ARTIFACT: return ID == 7; //Black Market - case ARTIFACT_EXP: - case CREATURE_EXP: + case EMarketMode::ARTIFACT_EXP: + case EMarketMode::CREATURE_EXP: return ID == 2; //TODO? check here for alignment of visiting hero? - would not be coherent with other checks here - case RESOURCE_SKILL: + case EMarketMode::RESOURCE_SKILL: return ID == 104;//University default: return false; } } -int CGMarket::availableUnits(EMarketMode mode, int marketItemSerial) const +int CGMarket::availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const { return -1; } -std::vector CGMarket::availableItemsIds(EMarketMode mode) const +std::vector CGMarket::availableItemsIds(EMarketMode::EMarketMode mode) const { switch(mode) { - case RESOURCE_RESOURCE: - case RESOURCE_PLAYER: + case EMarketMode::RESOURCE_RESOURCE: + case EMarketMode::RESOURCE_PLAYER: return IMarket::availableItemsIds(mode); default: return std::vector(); @@ -7007,13 +7000,13 @@ CGMarket::CGMarket() { } -std::vector CGBlackMarket::availableItemsIds(EMarketMode mode) const +std::vector CGBlackMarket::availableItemsIds(EMarketMode::EMarketMode mode) const { switch(mode) { - case ARTIFACT_RESOURCE: + case EMarketMode::ARTIFACT_RESOURCE: return IMarket::availableItemsIds(mode); - case RESOURCE_ARTIFACT: + case EMarketMode::RESOURCE_ARTIFACT: { std::vector ret; BOOST_FOREACH(const CArtifact *a, artifacts) @@ -7042,7 +7035,7 @@ void CGBlackMarket::newTurn() const void CGUniversity::initObj() { std::vector toChoose; - for (int i=0; iisAllowed(2,i)) toChoose.push_back(i); if (toChoose.size() < 4) @@ -7059,11 +7052,11 @@ void CGUniversity::initObj() } } -std::vector CGUniversity::availableItemsIds(EMarketMode mode) const +std::vector CGUniversity::availableItemsIds(EMarketMode::EMarketMode mode) const { switch (mode) { - case RESOURCE_SKILL: + case EMarketMode::RESOURCE_SKILL: return skills; default: @@ -7086,7 +7079,7 @@ GrowthInfo::Entry::Entry(const std::string &format, int _count) description = boost::str(boost::format(format) % count); } -GrowthInfo::Entry::Entry(int subID, Buildings::EBuilding building, int _count) +GrowthInfo::Entry::Entry(int subID, EBuilding::EBuilding building, int _count) : count(_count) { description = boost::str(boost::format("%s %+d") % VLC->buildh->buildings[subID][building]->Name() % count); diff --git a/lib/CObjectHandler.h b/lib/CObjectHandler.h index 19c01f9a5..af012e208 100644 --- a/lib/CObjectHandler.h +++ b/lib/CObjectHandler.h @@ -1,11 +1,6 @@ -#ifndef __COBJECTHANDLER_H__ -#define __COBJECTHANDLER_H__ -#include "../global.h" -#include -#include -#include -#include -#include +#pragma once + + #ifndef _MSC_VER #include "CHeroHandler.h" #include "CTownHandler.h" @@ -14,7 +9,8 @@ #include "../lib/CCreatureSet.h" #include "CArtHandler.h" #include "../lib/ConstTransitivePtr.h" -#include +#include "int3.h" +#include "GameConstants.h" /* * CObjectHandler.h, part of VCMI engine @@ -56,7 +52,7 @@ struct NewArtifact; class CGBoat; class CArtifactSet; -class DLL_EXPORT CQuest +class DLL_LINKAGE CQuest { public: enum Emission {MISSION_NONE = 0, MISSION_LEVEL = 1, MISSION_PRIMARY_STAT = 2, MISSION_KILL_HERO = 3, MISSION_KILL_CREATURE = 4, @@ -84,7 +80,7 @@ public: } }; -class DLL_EXPORT IObjectInterface +class DLL_LINKAGE IObjectInterface { public: static IGameCallback *cb; @@ -102,7 +98,7 @@ public: static void postInit();//caleed after objs receive their initObj }; -class DLL_EXPORT IBoatGenerator +class DLL_LINKAGE IBoatGenerator { public: const CGObjectInstance *o; @@ -115,7 +111,7 @@ public: void getProblemText(MetaString &out, const CGHeroInstance *visitor = NULL) const; }; -class DLL_EXPORT IShipyard : public IBoatGenerator +class DLL_LINKAGE IShipyard : public IBoatGenerator { public: IShipyard(const CGObjectInstance *O); @@ -125,24 +121,24 @@ public: static IShipyard *castFrom(CGObjectInstance *obj); }; -class DLL_EXPORT IMarket +class DLL_LINKAGE IMarket { virtual int getMarketEfficiency() const =0; public: const CGObjectInstance *o; IMarket(const CGObjectInstance *O); - virtual bool allowsTrade(EMarketMode mode) const; - virtual int availableUnits(EMarketMode mode, int marketItemSerial) const; //-1 if unlimited - virtual std::vector availableItemsIds(EMarketMode mode) const; + virtual bool allowsTrade(EMarketMode::EMarketMode mode) const; + virtual int availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const; //-1 if unlimited + virtual std::vector availableItemsIds(EMarketMode::EMarketMode mode) const; - bool getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode) const; //val1 - how many units of id1 player has to give to receive val2 units - std::vector availableModes() const; + bool getOffer(int id1, int id2, int &val1, int &val2, EMarketMode::EMarketMode mode) const; //val1 - how many units of id1 player has to give to receive val2 units + std::vector availableModes() const; static const IMarket *castFrom(const CGObjectInstance *obj); }; -class DLL_EXPORT CGObjectInstance : public IObjectInterface +class DLL_LINKAGE CGObjectInstance : public IObjectInterface { protected: void getNameVis(std::string &hname) const; @@ -209,7 +205,7 @@ public: } }; -class DLL_EXPORT CPlayersVisited: public CGObjectInstance +class DLL_LINKAGE CPlayersVisited: public CGObjectInstance { public: std::set players; //players that visited this object @@ -224,7 +220,7 @@ public: } }; -class DLL_EXPORT CArmedInstance: public CGObjectInstance, public CBonusSystemNode, public CCreatureSet +class DLL_LINKAGE CArmedInstance: public CGObjectInstance, public CBonusSystemNode, public CCreatureSet { public: BattleInfo *battle; //set to the current battle, if engaged @@ -250,7 +246,7 @@ public: } }; -class DLL_EXPORT CGHeroInstance : public CArmedInstance, public IBoatGenerator, public CArtifactSet +class DLL_LINKAGE CGHeroInstance : public CArmedInstance, public IBoatGenerator, public CArtifactSet { public: enum SecondarySkill @@ -289,7 +285,7 @@ public: std::set spells; //known spells (spell IDs) - struct DLL_EXPORT Patrol + struct DLL_LINKAGE Patrol { Patrol(){patrolling=false;patrolRadious=-1;}; ui8 patrolling; @@ -300,7 +296,7 @@ public: } } patrol; - struct DLL_EXPORT HeroSpecial : CBonusSystemNode + struct DLL_LINKAGE HeroSpecial : CBonusSystemNode { bool growthsWithLevel; template void serialize(Handler &h, const int version) @@ -339,11 +335,11 @@ public: ////////////////////////////////////////////////////////////////////////// bool hasSpellbook() const; - EAlignment getAlignment() const; + EAlignment::EAlignment getAlignment() const; const std::string &getBiography() const; bool needsLastStack()const; - unsigned int getTileCost(const TerrainTile &dest, const TerrainTile &from) const; //move cost - applying pathfinding skill, road and terrain modifiers. NOT includes diagonal move penalty, last move levelling - unsigned int getLowestCreatureSpeed() const; + ui32 getTileCost(const TerrainTile &dest, const TerrainTile &from) const; //move cost - applying pathfinding skill, road and terrain modifiers. NOT includes diagonal move penalty, last move levelling + ui32 getLowestCreatureSpeed() const; int3 getPosition(bool h3m = false) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation' si32 manaRegain() const; //how many points of mana can hero regain "naturally" in one day bool canWalkOnSea() const; @@ -399,37 +395,37 @@ public: void onHeroVisit(const CGHeroInstance * h) const; }; -class DLL_EXPORT CSpecObjInfo +class DLL_LINKAGE CSpecObjInfo { public: virtual ~CSpecObjInfo(){}; }; -class DLL_EXPORT CCreGenObjInfo : public CSpecObjInfo +class DLL_LINKAGE CCreGenObjInfo : public CSpecObjInfo { public: - unsigned char player; //owner + ui8 player; //owner bool asCastle; ui32 identifier; - unsigned char castles[2]; //allowed castles + ui8 castles[2]; //allowed castles }; -class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo +class DLL_LINKAGE CCreGen2ObjInfo : public CSpecObjInfo { public: - unsigned char player; //owner + ui8 player; //owner bool asCastle; ui32 identifier; - unsigned char castles[2]; //allowed castles - unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> + ui8 castles[2]; //allowed castles + ui8 minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> }; -class DLL_EXPORT CCreGen3ObjInfo : public CSpecObjInfo +class DLL_LINKAGE CCreGen3ObjInfo : public CSpecObjInfo { public: - unsigned char player; //owner - unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> + ui8 player; //owner + ui8 minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> }; -class DLL_EXPORT CGDwelling : public CArmedInstance +class DLL_LINKAGE CGDwelling : public CArmedInstance { public: CSpecObjInfo * info; //h3m info about dewlling @@ -450,7 +446,7 @@ public: }; -class DLL_EXPORT CGVisitableOPH : public CGObjectInstance //objects visitable only once per hero +class DLL_LINKAGE CGVisitableOPH : public CGObjectInstance //objects visitable only once per hero { public: std::set visitors; //ids of heroes who have visited this obj @@ -471,7 +467,7 @@ public: h & visitors & ttype; } }; -class DLL_EXPORT CGTownBuilding : public IObjectInterface +class DLL_LINKAGE CGTownBuilding : public IObjectInterface { ///basic class for town structures handled as map objects public: @@ -484,7 +480,7 @@ public: h & ID & id; } }; -class DLL_EXPORT COPWBonus : public CGTownBuilding +class DLL_LINKAGE COPWBonus : public CGTownBuilding {///used for OPW bonusing structures public: std::set visitors; @@ -500,7 +496,7 @@ public: } }; -class DLL_EXPORT CTownBonus : public CGTownBuilding +class DLL_LINKAGE CTownBonus : public CGTownBuilding { ///used for one-time bonusing structures ///feel free to merge inheritance tree @@ -518,27 +514,27 @@ public: } }; -class DLL_EXPORT CTownAndVisitingHero : public CBonusSystemNode +class DLL_LINKAGE CTownAndVisitingHero : public CBonusSystemNode { public: CTownAndVisitingHero(); }; -struct DLL_EXPORT GrowthInfo +struct DLL_LINKAGE GrowthInfo { struct Entry { int count; std::string description; Entry(const std::string &format, int _count); - Entry(int subID, Buildings::EBuilding building, int _count); + Entry(int subID, EBuilding::EBuilding building, int _count); }; std::vector entries; int totalGrowth() const; }; -class DLL_EXPORT CGTownInstance : public CGDwelling, public IShipyard, public IMarket +class DLL_LINKAGE CGTownInstance : public CGDwelling, public IShipyard, public IMarket { public: CTownAndVisitingHero townAndVis; @@ -594,8 +590,8 @@ public: int getBoatType() const; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral void getOutOffsets(std::vector &offsets) const; //offsets to obj pos when we boat can be placed int getMarketEfficiency() const; //=market count - bool allowsTrade(EMarketMode mode) const; - std::vector availableItemsIds(EMarketMode mode) const; + bool allowsTrade(EMarketMode::EMarketMode mode) const; + std::vector availableItemsIds(EMarketMode::EMarketMode mode) const; void setPropertyDer(ui8 what, ui32 val); void newTurn() const; @@ -627,7 +623,7 @@ public: void onHeroLeave(const CGHeroInstance * h) const; void initObj(); }; -class DLL_EXPORT CGPandoraBox : public CArmedInstance +class DLL_LINKAGE CGPandoraBox : public CArmedInstance { public: std::string message; @@ -661,7 +657,7 @@ public: } }; -class DLL_EXPORT CGEvent : public CGPandoraBox //event objects +class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects { public: ui8 removeAfterVisit; //true if event is removed after occurring @@ -680,7 +676,7 @@ public: }; -class DLL_EXPORT CGCreature : public CArmedInstance //creatures on map +class DLL_LINKAGE CGCreature : public CArmedInstance //creatures on map { public: ui32 identifier; //unique code for this monster (used in missions) @@ -705,7 +701,7 @@ public: void setPropertyDer(ui8 what, ui32 val); int takenAction(const CGHeroInstance *h, bool allowJoin=true) const; //action on confrontation: -2 - fight, -1 - flee, >=0 - will join for given value of gold (may be 0) - struct DLL_EXPORT RestoredCreature // info about merging stacks after battle back into one + struct DLL_LINKAGE RestoredCreature // info about merging stacks after battle back into one { si32 basicType; template void serialize(Handler &h, const int version) @@ -722,7 +718,7 @@ public: }; -class DLL_EXPORT CGSignBottle : public CGObjectInstance //signs and ocean bottles +class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles { public: std::string message; @@ -737,7 +733,7 @@ public: } }; -class DLL_EXPORT CGSeerHut : public CArmedInstance, public CQuest //army is used when giving reward +class DLL_LINKAGE CGSeerHut : public CArmedInstance, public CQuest //army is used when giving reward { public: ui8 rewardType; //type of reward: 0 - no reward; 1 - experience; 2 - mana points; 3 - morale bonus; 4 - luck bonus; 5 - resources; 6 - main ability bonus (attak, defence etd.); 7 - secondary ability gain; 8 - artifact; 9 - spell; 10 - creature @@ -776,7 +772,7 @@ public: } }; -class DLL_EXPORT CGQuestGuard : public CGSeerHut +class DLL_LINKAGE CGQuestGuard : public CGSeerHut { public: void initObj(); @@ -788,7 +784,7 @@ public: } }; -class DLL_EXPORT CGWitchHut : public CPlayersVisited +class DLL_LINKAGE CGWitchHut : public CPlayersVisited { public: std::vector allowedAbilities; @@ -805,7 +801,7 @@ public: }; -class DLL_EXPORT CGScholar : public CGObjectInstance +class DLL_LINKAGE CGScholar : public CGObjectInstance { public: ui8 bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell @@ -821,7 +817,7 @@ public: } }; -class DLL_EXPORT CGGarrison : public CArmedInstance +class DLL_LINKAGE CGGarrison : public CArmedInstance { public: ui8 removableUnits; @@ -837,7 +833,7 @@ public: } }; -class DLL_EXPORT CGArtifact : public CArmedInstance +class DLL_LINKAGE CGArtifact : public CArmedInstance { public: CArtifactInstance *storedArtifact; @@ -856,7 +852,7 @@ public: } }; -class DLL_EXPORT CGResource : public CArmedInstance +class DLL_LINKAGE CGResource : public CArmedInstance { public: ui32 amount; //0 if random @@ -875,7 +871,7 @@ public: } }; -class DLL_EXPORT CGPickable : public CGObjectInstance //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest +class DLL_LINKAGE CGPickable : public CGObjectInstance //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest { public: ui32 type, val1, val2; @@ -891,7 +887,7 @@ public: } }; -class DLL_EXPORT CGShrine : public CPlayersVisited +class DLL_LINKAGE CGShrine : public CPlayersVisited { public: ui8 spell; //number of spell or 255 if random @@ -906,7 +902,7 @@ public: } }; -class DLL_EXPORT CGMine : public CArmedInstance +class DLL_LINKAGE CGMine : public CArmedInstance { public: ui8 producedResource; @@ -929,7 +925,7 @@ public: ui32 defaultResProduction(); }; -class DLL_EXPORT CGVisitableOPW : public CGObjectInstance //objects visitable OPW +class DLL_LINKAGE CGVisitableOPW : public CGObjectInstance //objects visitable OPW { public: ui8 visited; //true if object has been visited this week @@ -945,7 +941,7 @@ public: } }; -class DLL_EXPORT CGTeleport : public CGObjectInstance //teleports and subterranean gates +class DLL_LINKAGE CGTeleport : public CGObjectInstance //teleports and subterranean gates { public: static std::map > > objs; //teleports: map[ID][subID] => vector of ids @@ -961,7 +957,7 @@ public: } }; -class DLL_EXPORT CGBonusingObject : public CGObjectInstance //objects giving bonuses to luck/morale/movement +class DLL_LINKAGE CGBonusingObject : public CGObjectInstance //objects giving bonuses to luck/morale/movement { public: void onHeroVisit(const CGHeroInstance * h) const; @@ -974,7 +970,7 @@ public: } }; -class DLL_EXPORT CGMagicSpring : public CGVisitableOPW +class DLL_LINKAGE CGMagicSpring : public CGVisitableOPW {///unfortunatelly, this one is quite different than others public: void onHeroVisit(const CGHeroInstance * h) const; @@ -987,7 +983,7 @@ public: } }; -class DLL_EXPORT CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement +class DLL_LINKAGE CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement { public: void onHeroVisit(const CGHeroInstance * h) const; @@ -999,7 +995,7 @@ public: } }; -class DLL_EXPORT CGSirens : public CGObjectInstance +class DLL_LINKAGE CGSirens : public CGObjectInstance { public: void onHeroVisit(const CGHeroInstance * h) const; @@ -1012,7 +1008,7 @@ public: } }; -class DLL_EXPORT CGObservatory : public CGObjectInstance //Redwood observatory +class DLL_LINKAGE CGObservatory : public CGObjectInstance //Redwood observatory { public: void onHeroVisit(const CGHeroInstance * h) const; @@ -1024,7 +1020,7 @@ public: }; -class DLL_EXPORT CGKeys : public CGObjectInstance //Base class for Keymaster and guards +class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards { public: static std::map > playerKeyMap; //[players][keysowned] @@ -1038,7 +1034,7 @@ public: } }; -class DLL_EXPORT CGKeymasterTent : public CGKeys +class DLL_LINKAGE CGKeymasterTent : public CGKeys { public: void onHeroVisit(const CGHeroInstance * h) const; @@ -1050,7 +1046,7 @@ public: } }; -class DLL_EXPORT CGBorderGuard : public CGKeys +class DLL_LINKAGE CGBorderGuard : public CGKeys { public: void initObj(); @@ -1065,14 +1061,14 @@ public: } }; -class DLL_EXPORT CGBorderGate : public CGBorderGuard //not fully imlemented, waiting for garrison +class DLL_LINKAGE CGBorderGate : public CGBorderGuard //not fully imlemented, waiting for garrison { public: void onHeroVisit(const CGHeroInstance * h) const; ui8 getPassableness() const; }; -class DLL_EXPORT CGBoat : public CGObjectInstance +class DLL_LINKAGE CGBoat : public CGObjectInstance { public: ui8 direction; @@ -1091,7 +1087,7 @@ public: } }; -class DLL_EXPORT CGOnceVisitable : public CPlayersVisited +class DLL_LINKAGE CGOnceVisitable : public CPlayersVisited ///wagon, corpse, lean to, warriors tomb { public: @@ -1111,12 +1107,12 @@ public: } }; -class DLL_EXPORT CBank : public CArmedInstance +class DLL_LINKAGE CBank : public CArmedInstance { public: int index; //banks have unusal numbering - see ZCRBANK.txt and initObj() BankConfig *bc; - float multiplier; //for improved banks script + double multiplier; //for improved banks script std::vector artifacts; //fixed and deterministic ui32 daycounter; @@ -1136,7 +1132,7 @@ class DLL_EXPORT CBank : public CArmedInstance h & index & multiplier & artifacts & daycounter & bc; } }; -class DLL_EXPORT CGPyramid : public CBank +class DLL_LINKAGE CGPyramid : public CBank { public: ui16 spell; @@ -1162,7 +1158,7 @@ public: void onHeroVisit(const CGHeroInstance * h) const; }; -class DLL_EXPORT CGMagi : public CGObjectInstance +class DLL_LINKAGE CGMagi : public CGObjectInstance { public: static std::map > eyelist; //[subID][id], supports multiple sets as in H5 @@ -1178,7 +1174,7 @@ public: -class DLL_EXPORT CCartographer : public CPlayersVisited +class DLL_LINKAGE CCartographer : public CPlayersVisited { ///behaviour varies depending on surface and floor public: @@ -1191,12 +1187,12 @@ public: } }; -class DLL_EXPORT CGDenOfthieves : public CGObjectInstance +class DLL_LINKAGE CGDenOfthieves : public CGObjectInstance { void onHeroVisit (const CGHeroInstance * h) const; }; -class DLL_EXPORT CGObelisk : public CPlayersVisited +class DLL_LINKAGE CGObelisk : public CPlayersVisited { public: static ui8 obeliskCount; //how many obelisks are on map @@ -1213,7 +1209,7 @@ public: } }; -class DLL_EXPORT CGLighthouse : public CGObjectInstance +class DLL_LINKAGE CGLighthouse : public CGObjectInstance { public: void onHeroVisit(const CGHeroInstance * h) const; @@ -1227,16 +1223,16 @@ public: void giveBonusTo( ui8 player ) const; }; -class DLL_EXPORT CGMarket : public CGObjectInstance, public IMarket +class DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket { public: CGMarket(); void onHeroVisit(const CGHeroInstance * h) const; //open trading window int getMarketEfficiency() const; - bool allowsTrade(EMarketMode mode) const; - int availableUnits(EMarketMode mode, int marketItemSerial) const; //-1 if unlimited - std::vector availableItemsIds(EMarketMode mode) const; + bool allowsTrade(EMarketMode::EMarketMode mode) const; + int availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const; //-1 if unlimited + std::vector availableItemsIds(EMarketMode::EMarketMode mode) const; template void serialize(Handler &h, const int version) { @@ -1244,13 +1240,13 @@ public: } }; -class DLL_EXPORT CGBlackMarket : public CGMarket +class DLL_LINKAGE CGBlackMarket : public CGMarket { public: std::vector artifacts; //available artifacts void newTurn() const; //reset artifacts for black market every month - std::vector availableItemsIds(EMarketMode mode) const; + std::vector availableItemsIds(EMarketMode::EMarketMode mode) const; template void serialize(Handler &h, const int version) { @@ -1259,12 +1255,12 @@ public: } }; -class DLL_EXPORT CGUniversity : public CGMarket +class DLL_LINKAGE CGUniversity : public CGMarket { public: std::vector skills; //available skills - std::vector availableItemsIds(EMarketMode mode) const; + std::vector availableItemsIds(EMarketMode::EMarketMode mode) const; void initObj();//set skills for trade void onHeroVisit(const CGHeroInstance * h) const; //open window @@ -1296,7 +1292,7 @@ struct BankConfig } }; -class DLL_EXPORT CObjectHandler +class DLL_LINKAGE CObjectHandler { public: std::vector cregens; //type 17. dwelling subid -> creature ID @@ -1311,6 +1307,3 @@ public: h & cregens & banksInfo & creBanksNames & resVals; } }; - - -#endif // __COBJECTHANDLER_H__ diff --git a/lib/CObstacleInstance.h b/lib/CObstacleInstance.h index 0e99b237d..f80907245 100644 --- a/lib/CObstacleInstance.h +++ b/lib/CObstacleInstance.h @@ -1,6 +1,6 @@ #pragma once -struct DLL_EXPORT CObstacleInstance +struct DLL_LINKAGE CObstacleInstance { int uniqueID; int ID; //ID of obstacle (defines type of it) diff --git a/lib/CScriptingModule.h b/lib/CScriptingModule.h index 773505056..cfb6402cb 100644 --- a/lib/CScriptingModule.h +++ b/lib/CScriptingModule.h @@ -1,8 +1,19 @@ #pragma once -#include "../global.h" + + #include "IGameEventsReceiver.h" #include "IGameCallback.h" +/* + * CScriptingModule.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + class CScriptingModule : public IGameEventsReceiver, public IBattleEventsReceiver { public: diff --git a/lib/CSpellHandler.cpp b/lib/CSpellHandler.cpp index 435f1d578..e71ffad3f 100644 --- a/lib/CSpellHandler.cpp +++ b/lib/CSpellHandler.cpp @@ -1,14 +1,12 @@ -#define VCMI_DLL -#include "../stdafx.h" +#include "StdInc.h" #include "CSpellHandler.h" + + #include "CLodHandler.h" #include "../lib/VCMI_Lib.h" #include "../lib/JsonNode.h" -#include -#include -#include #include - +#include "GameConstants.h" extern CLodHandler *bitmaph; @@ -212,7 +210,7 @@ static bool startsWithX(const std::string &s) return s.size() && s[0] == 'x'; } -bool DLL_EXPORT isInScreenRange(const int3 ¢er, const int3 &pos) +bool DLL_LINKAGE isInScreenRange(const int3 ¢er, const int3 &pos) { int3 diff = pos - center; if(diff.x >= -9 && diff.x <= 9 && diff.y >= -8 && diff.y <= 8) @@ -298,7 +296,7 @@ void CSpellHandler::loadSpells() boost::replace_first (spells[47]->attributes, "2", ""); // disrupting ray will now affect single creature //loading of additional spell traits - const JsonNode config(DATA_DIR "/config/spell_info.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/spell_info.json"); BOOST_FOREACH(const JsonNode &spell, config["spells"].Vector()) { diff --git a/lib/CSpellHandler.h b/lib/CSpellHandler.h index ee280838e..f23964335 100644 --- a/lib/CSpellHandler.h +++ b/lib/CSpellHandler.h @@ -1,11 +1,8 @@ -#ifndef __CSPELLHANDLER_H__ -#define __CSPELLHANDLER_H__ - -#include -#include -#include +#pragma once #include "../lib/ConstTransitivePtr.h" +#include "int3.h" +#include "GameConstants.h" /* * CSpellHandler.h, part of VCMI engine @@ -17,7 +14,7 @@ * */ -class DLL_EXPORT CSpell +class DLL_LINKAGE CSpell { public: enum ETargetType {NO_TARGET, CREATURE, CREATURE_EXPERT_MASSIVE, OBSTACLE}; @@ -77,9 +74,9 @@ namespace Spells }; } -bool DLL_EXPORT isInScreenRange(const int3 ¢er, const int3 &pos); //for spells like Dimension Door +bool DLL_LINKAGE isInScreenRange(const int3 ¢er, const int3 &pos); //for spells like Dimension Door -class DLL_EXPORT CSpellHandler +class DLL_LINKAGE CSpellHandler { public: CSpellHandler(); @@ -93,6 +90,3 @@ public: h & spells & damageSpells & risingSpells; } }; - - -#endif // __CSPELLHANDLER_H__ diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 920e66f57..b256fbbf7 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -1,12 +1,11 @@ -#define VCMI_DLL -#include "../stdafx.h" +#include "StdInc.h" #include "CTownHandler.h" + #include "CLodHandler.h" -#include #include "../lib/VCMI_Lib.h" #include "CGeneralTextHandler.h" #include "../lib/JsonNode.h" -#include +#include "GameConstants.h" /* * CTownHandler.cpp, part of VCMI engine @@ -32,7 +31,7 @@ void CTownHandler::loadStructures() { int townID; - for (townID=0; townID &requires = requirements[townID][node["id"].Float()]; diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 4aa9be0e6..2e560da68 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -1,7 +1,7 @@ -#ifndef __CTOWNHANDLER_H__ -#define __CTOWNHANDLER_H__ -#include "../global.h" -#include +#pragma once + + +#include "int3.h" /* * CTownHandler.h, part of VCMI engine @@ -17,7 +17,7 @@ class CBuilding; class CSpell; class CHero; class CGTownInstance; -class DLL_EXPORT CTown +class DLL_LINKAGE CTown { std::string name; //name of type public: @@ -44,7 +44,7 @@ public: } }; -struct DLL_EXPORT Structure +struct DLL_LINKAGE Structure { int ID; int3 pos; @@ -60,7 +60,7 @@ struct DLL_EXPORT Structure } }; -class DLL_EXPORT CTownHandler +class DLL_LINKAGE CTownHandler { public: std::vector towns; @@ -78,6 +78,3 @@ public: loadStructures(); } }; - - -#endif // __CTOWNHANDLER_H__ diff --git a/lib/CondSh.h b/lib/CondSh.h index 227b02da1..73189e3e7 100644 --- a/lib/CondSh.h +++ b/lib/CondSh.h @@ -1,6 +1,4 @@ -#ifndef __CONDSH_H__ -#define __CONDSH_H__ -#include +#pragma once /* * CondSh.h, part of VCMI engine @@ -69,4 +67,3 @@ template struct CondSh cond.wait(un); } }; -#endif // __CONDSH_H__ diff --git a/lib/Connection.cpp b/lib/Connection.cpp index be39255c4..6257d14b2 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -1,17 +1,13 @@ -#define VCMI_DLL -#pragma warning(disable:4355) +#include "StdInc.h" #include "Connection.h" -#include -#include -#include #ifndef _MSC_VER -#include "../lib/RegisterTypes.cpp" +#include "../lib/RegisterTypes.h" #endif //for smart objs serialization over net #include "../lib/CMapInfo.h" -#include "../StartInfo.h" +#include "StartInfo.h" #include "BattleState.h" #include "CGameState.h" #include "map.h" @@ -25,6 +21,7 @@ #include "CCampaignHandler.h" #include "NetPacks.h" +#include /* * Connection.cpp, part of VCMI engine @@ -38,7 +35,7 @@ using namespace boost; using namespace boost::asio::ip; -template DLL_EXPORT void registerTypes(Serializer &s); //defined elsewhere and explicitly instantiated for used serializers +template DLL_LINKAGE void registerTypes(Serializer &s); //defined elsewhere and explicitly instantiated for used serializers CTypeList typeList; diff --git a/lib/Connection.h b/lib/Connection.h index b7b00148b..a22087bcf 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -1,12 +1,7 @@ -#ifndef __CONNECTION_H__ -#define __CONNECTION_H__ -#include "../global.h" -#include -#include -#include -#include +#pragma once + + #include //XXX this is in namespace std if you want w/o use typeinfo.h? -#include #include #include @@ -16,7 +11,6 @@ #include #include #include -#include #include #include @@ -34,7 +28,7 @@ class CCreature; class LibClasses; class CHero; struct CPack; -extern DLL_EXPORT LibClasses * VLC; +extern DLL_LINKAGE LibClasses * VLC; namespace mpl = boost::mpl; /* @@ -86,7 +80,7 @@ struct TypeComparer } }; -class DLL_EXPORT CTypeList +class DLL_LINKAGE CTypeList { typedef std::multimap TTypeMap; TTypeMap types; @@ -114,7 +108,7 @@ public: } }; -extern DLL_EXPORT CTypeList typeList; +extern DLL_LINKAGE CTypeList typeList; template struct SavePrimitive @@ -245,7 +239,7 @@ struct VectorisedObjectInfo }; /// Class which is responsible for storing and loading data. -class DLL_EXPORT CSerializer +class DLL_LINKAGE CSerializer { public: typedef std::map TTypeVecMap; @@ -314,7 +308,7 @@ public: void addStdVecItems(CGameState *gs, LibClasses *lib = VLC); }; -class DLL_EXPORT CSaverBase : public virtual CSerializer +class DLL_LINKAGE CSaverBase : public virtual CSerializer { }; @@ -351,7 +345,7 @@ struct VectorisedTypeFor }; /// The class which manages saving objects. -template class DLL_EXPORT COSer : public CSaverBase +template class DLL_LINKAGE COSer : public CSaverBase { public: bool saving; @@ -509,7 +503,7 @@ public: template void saveSerializable(const std::vector &data) { - boost::uint32_t length = data.size(); + ui32 length = data.size(); *this << length; for(ui32 i=0;i &data) { std::set &d = const_cast &>(data); - boost::uint32_t length = d.size(); + ui32 length = d.size(); *this << length; for(typename std::set::iterator i=d.begin();i!=d.end();i++) *this << *i; @@ -527,7 +521,7 @@ public: void saveSerializable(const boost::unordered_set &data) { boost::unordered_set &d = const_cast &>(data); - boost::uint32_t length = d.size(); + ui32 length = d.size(); *this << length; for(typename boost::unordered_set::iterator i=d.begin();i!=d.end();i++) *this << *i; @@ -536,7 +530,7 @@ public: void saveSerializable(const std::list &data) { std::list &d = const_cast &>(data); - boost::uint32_t length = d.size(); + ui32 length = d.size(); *this << length; for(typename std::list::iterator i=d.begin();i!=d.end();i++) *this << *i; @@ -562,7 +556,7 @@ public: -class DLL_EXPORT CLoaderBase : public virtual CSerializer +class DLL_LINKAGE CLoaderBase : public virtual CSerializer {}; class CBasicPointerLoader @@ -590,7 +584,7 @@ public: }; /// The class which manages loading of objects. -template class DLL_EXPORT CISer : public CLoaderBase +template class DLL_LINKAGE CISer : public CLoaderBase { public: bool saving; @@ -682,7 +676,7 @@ public: void loadArray(T &data) { ui32 size = ARRAY_COUNT(data); - for(ui32 i=0; i < size; i++) + for(ui32 i = 0; i < size; i++) *this >> data[i]; } template @@ -758,7 +752,7 @@ public: } #define READ_CHECK_U32(x) \ - boost::uint32_t length; \ + ui32 length; \ *this >> length; \ if(length > 50000) \ { \ @@ -842,7 +836,7 @@ public: }; -class DLL_EXPORT CSaveFile +class DLL_LINKAGE CSaveFile : public COSer { void dummyMagicFunction() @@ -862,7 +856,7 @@ public: void reportState(CLogger &out); }; -class DLL_EXPORT CLoadFile +class DLL_LINKAGE CLoadFile : public CISer { void dummyMagicFunction() @@ -886,7 +880,7 @@ public: typedef boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > TSocket; typedef boost::asio::basic_socket_acceptor > TAcceptor; -class DLL_EXPORT CConnection +class DLL_LINKAGE CConnection :public CISer, public COSer { //CGameState *gs; @@ -925,7 +919,7 @@ public: void sendPack(const CPack &pack); }; -DLL_EXPORT std::ostream &operator<<(std::ostream &str, const CConnection &cpc); +DLL_LINKAGE std::ostream &operator<<(std::ostream &str, const CConnection &cpc); template class CApplier @@ -947,6 +941,3 @@ public: } }; - - -#endif // __CONNECTION_H__ diff --git a/lib/ConstTransitivePtr.h b/lib/ConstTransitivePtr.h index ccaf8b9a4..b1347bf35 100644 --- a/lib/ConstTransitivePtr.h +++ b/lib/ConstTransitivePtr.h @@ -2,6 +2,16 @@ class CGameHandler; +/* + * ConstTransitivePtr.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + template class ConstTransitivePtr { diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index ea1f93ff0..9e5dd36ab 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -1,26 +1,22 @@ -#define VCMI_DLL +#include "StdInc.h" #include "HeroBonus.h" -#include + #include "VCMI_Lib.h" #include "CSpellHandler.h" -#include #include "CCreatureHandler.h" -#include #include "CCreatureSet.h" -#include -#include #include "CHeroHandler.h" #include "CGeneralTextHandler.h" #include "BattleState.h" #include "CArtHandler.h" -#include +#include "GameConstants.h" #define FOREACH_PARENT(pname) TNodes lparents; getParents(lparents); BOOST_FOREACH(CBonusSystemNode *pname, lparents) #define FOREACH_RED_CHILD(pname) TNodes lchildren; getRedChildren(lchildren); BOOST_FOREACH(CBonusSystemNode *pname, lchildren) #define FOREACH_RED_PARENT(pname) TNodes lparents; getRedParents(lparents); BOOST_FOREACH(CBonusSystemNode *pname, lparents) #define BONUS_NAME(x) ( #x, Bonus::x ) - DLL_EXPORT const std::map bonusNameMap = boost::assign::map_list_of BONUS_LIST; + DLL_LINKAGE const std::map bonusNameMap = boost::assign::map_list_of BONUS_LIST; #undef BONUS_NAME #define BONUS_LOG_LINE(x) tlog5 << x << std::endl @@ -85,7 +81,7 @@ int BonusList::totalValue() const } else { - amax(indepMax, b->val); + vstd::amax(indepMax, b->val); } break; @@ -97,7 +93,7 @@ int BonusList::totalValue() const } else { - amin(indepMin, b->val); + vstd::amin(indepMin, b->val); } break; @@ -110,15 +106,15 @@ int BonusList::totalValue() const if(hasIndepMin && hasIndepMax) assert(indepMin < indepMax); if (hasIndepMax) - amax(valFirst, indepMax); + vstd::amax(valFirst, indepMax); if (hasIndepMin) - amin(valFirst, indepMin); + vstd::amin(valFirst, indepMin); return valFirst; } const Bonus * BonusList::getFirst(const CSelector &selector) const { - for (unsigned int i = 0; i < bonuses.size(); i++) + for (ui32 i = 0; i < bonuses.size(); i++) { const Bonus *b = bonuses[i]; if(selector(b)) @@ -129,7 +125,7 @@ const Bonus * BonusList::getFirst(const CSelector &selector) const Bonus * BonusList::getFirst(const CSelector &select) { - for (unsigned int i = 0; i < bonuses.size(); i++) + for (ui32 i = 0; i < bonuses.size(); i++) { Bonus *b = bonuses[i]; if(select(b)) @@ -158,7 +154,7 @@ void BonusList::getBonuses(TBonusListPtr out, const CSelector &selector) const void BonusList::getBonuses(TBonusListPtr out, const CSelector &selector, const CSelector &limit, const bool caching /*= false*/) const { - for (unsigned int i = 0; i < bonuses.size(); i++) + for (ui32 i = 0; i < bonuses.size(); i++) { Bonus *b = bonuses[i]; @@ -329,9 +325,9 @@ int IBonusBearer::MoraleVal() const int ret = valOfBonuses(Bonus::MORALE); if(hasBonusOfType(Bonus::SELF_MORALE)) //eg. minotaur - amax(ret, +1); + vstd::amax(ret, +1); - return abetw(ret, -3, +3); + return vstd::abetween(ret, -3, +3); } int IBonusBearer::LuckVal() const @@ -342,9 +338,9 @@ int IBonusBearer::LuckVal() const int ret = valOfBonuses(Bonus::LUCK); if(hasBonusOfType(Bonus::SELF_LUCK)) //eg. halfling - amax(ret, +1); + vstd::amax(ret, +1); - return abetw(ret, -3, +3); + return vstd::abetween(ret, -3, +3); } si32 IBonusBearer::Attack() const @@ -355,7 +351,7 @@ si32 IBonusBearer::Attack() const { ret += frenzyPower * Defense(false); } - amax(ret, 0); + vstd::amax(ret, 0); return ret; } @@ -368,7 +364,7 @@ si32 IBonusBearer::Defense(bool withFrenzy /*= true*/) const { return 0; } - amax(ret, 0); + vstd::amax(ret, 0); return ret; } @@ -393,7 +389,7 @@ ui32 IBonusBearer::getMaxDamage() const si32 IBonusBearer::manaLimit() const { - return si32(getPrimSkillLevel(3) * (100.0f + valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, 24)) / 10.0f); + return si32(getPrimSkillLevel(3) * (100.0 + valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, 24)) / 10.0); } int IBonusBearer::getPrimSkillLevel(int id) const @@ -406,7 +402,7 @@ int IBonusBearer::getPrimSkillLevel(int id) const else ret = valOfBonuses(Bonus::PRIMARY_SKILL, id); - amax(ret, id/2); //minimal value is 0 for attack and defense and 1 for spell power and knowledge + vstd::amax(ret, id/2); //minimal value is 0 for attack and defense and 1 for spell power and knowledge return ret; } @@ -452,7 +448,7 @@ const Bonus * CBonusSystemNode::getBonus( const CSelector &selector ) const void CBonusSystemNode::getParents(TCNodes &out) const /*retreives list of parent nodes (nodes to inherit bonuses from) */ { - for (unsigned int i = 0; i < parents.size(); i++) + for (ui32 i = 0; i < parents.size(); i++) { const CBonusSystemNode *parent = parents[i]; out.insert(parent); @@ -461,7 +457,7 @@ void CBonusSystemNode::getParents(TCNodes &out) const /*retreives list of parent void CBonusSystemNode::getParents(TNodes &out) { - for (unsigned int i = 0; i < parents.size(); i++) + for (ui32 i = 0; i < parents.size(); i++) { const CBonusSystemNode *parent = parents[i]; out.insert(const_cast(parent)); @@ -618,7 +614,7 @@ void CBonusSystemNode::removeBonus(Bonus *b) unpropagateBonus(b); else bonuses -= b; - delNull(b); + vstd::clear_pointer(b); CBonusSystemNode::treeChanged++; } @@ -777,7 +773,7 @@ void CBonusSystemNode::getRedDescendants(TNodes &out) void CBonusSystemNode::battleTurnPassed() { BonusList bonusesCpy = exportedBonuses; //copy, because removing bonuses invalidates iters - for (unsigned int i = 0; i < bonusesCpy.size(); i++) + for (ui32 i = 0; i < bonusesCpy.size(); i++) { Bonus *b = bonusesCpy[i]; @@ -970,36 +966,36 @@ Bonus * Bonus::addPropagator(boost::shared_ptr Propagator) return this; } -CSelector DLL_EXPORT operator&&(const CSelector &first, const CSelector &second) +CSelector DLL_LINKAGE operator&&(const CSelector &first, const CSelector &second) { return CSelectorsConjunction(first, second); } -CSelector DLL_EXPORT operator||(const CSelector &first, const CSelector &second) +CSelector DLL_LINKAGE operator||(const CSelector &first, const CSelector &second) { return CSelectorsAlternative(first, second); } namespace Selector { - DLL_EXPORT CSelectFieldEqual type(&Bonus::type, 0); - DLL_EXPORT CSelectFieldEqual subtype(&Bonus::subtype, 0); - DLL_EXPORT CSelectFieldEqual info(&Bonus::additionalInfo, 0); - DLL_EXPORT CSelectFieldEqual duration(&Bonus::duration, 0); - DLL_EXPORT CSelectFieldEqual sourceType(&Bonus::source, 0); - DLL_EXPORT CSelectFieldEqual effectRange(&Bonus::effectRange, Bonus::NO_LIMIT); - DLL_EXPORT CWillLastTurns turns; + DLL_LINKAGE CSelectFieldEqual type(&Bonus::type, 0); + DLL_LINKAGE CSelectFieldEqual subtype(&Bonus::subtype, 0); + DLL_LINKAGE CSelectFieldEqual info(&Bonus::additionalInfo, 0); + DLL_LINKAGE CSelectFieldEqual duration(&Bonus::duration, 0); + DLL_LINKAGE CSelectFieldEqual sourceType(&Bonus::source, 0); + DLL_LINKAGE CSelectFieldEqual effectRange(&Bonus::effectRange, Bonus::NO_LIMIT); + DLL_LINKAGE CWillLastTurns turns; - CSelector DLL_EXPORT typeSubtype(TBonusType Type, TBonusSubtype Subtype) + CSelector DLL_LINKAGE typeSubtype(TBonusType Type, TBonusSubtype Subtype) { return type(Type) && subtype(Subtype); } - CSelector DLL_EXPORT typeSubtypeInfo(TBonusType type, TBonusSubtype subtype, si32 info) + CSelector DLL_LINKAGE typeSubtypeInfo(TBonusType type, TBonusSubtype subtype, si32 info) { return CSelectFieldEqual(&Bonus::type, type) && CSelectFieldEqual(&Bonus::subtype, subtype) && CSelectFieldEqual(&Bonus::additionalInfo, info); } - CSelector DLL_EXPORT source(ui8 source, ui32 sourceID) + CSelector DLL_LINKAGE source(ui8 source, ui32 sourceID) { return CSelectFieldEqual(&Bonus::source, source) && CSelectFieldEqual(&Bonus::sid, sourceID); } @@ -1009,19 +1005,19 @@ namespace Selector return CSelectFieldEqual(&Bonus::duration, duration); } - CSelector DLL_EXPORT sourceTypeSel(ui8 source) + CSelector DLL_LINKAGE sourceTypeSel(ui8 source) { return CSelectFieldEqual(&Bonus::source, source); } - bool DLL_EXPORT matchesType(const CSelector &sel, TBonusType type) + bool DLL_LINKAGE matchesType(const CSelector &sel, TBonusType type) { Bonus dummy; dummy.type = type; return sel(&dummy); } - bool DLL_EXPORT matchesTypeSubtype(const CSelector &sel, TBonusType type, TBonusSubtype subtype) + bool DLL_LINKAGE matchesTypeSubtype(const CSelector &sel, TBonusType type, TBonusSubtype subtype) { Bonus dummy; dummy.type = type; @@ -1029,7 +1025,7 @@ namespace Selector return sel(&dummy); } - bool DLL_EXPORT positiveSpellEffects(const Bonus *b) + bool DLL_LINKAGE positiveSpellEffects(const Bonus *b) { if(b->source == Bonus::SPELL_EFFECT) { @@ -1078,9 +1074,9 @@ const CCreature * retrieveCreature(const CBonusSystemNode *node) } } -DLL_EXPORT std::ostream & operator<<(std::ostream &out, const BonusList &bonusList) +DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const BonusList &bonusList) { - for (unsigned int i = 0; i < bonusList.size(); i++) + for (ui32 i = 0; i < bonusList.size(); i++) { Bonus *b = bonusList[i]; out << "Bonus " << i << "\n" << *b << std::endl; @@ -1088,7 +1084,7 @@ DLL_EXPORT std::ostream & operator<<(std::ostream &out, const BonusList &bonusLi return out; } -DLL_EXPORT std::ostream & operator<<(std::ostream &out, const Bonus &bonus) +DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus) { for(std::map::const_iterator i = bonusNameMap.begin(); i != bonusNameMap.end(); i++) if(i->second == bonus.type) @@ -1208,7 +1204,7 @@ CreatureNativeTerrainLimiter::CreatureNativeTerrainLimiter() bool CreatureNativeTerrainLimiter::limit(const Bonus *b, const CBonusSystemNode &node) const { const CCreature *c = retrieveCreature(&node); - return !c || !iswith(c->faction, 0, 9) || VLC->heroh->nativeTerrains[c->faction] != terrainType; //drop bonus for non-creatures or non-native residents + return !c || !vstd::iswithin(c->faction, 0, 9) || VLC->heroh->nativeTerrains[c->faction] != terrainType; //drop bonus for non-creatures or non-native residents //TODO neutral creatues } @@ -1242,11 +1238,11 @@ bool CreatureAlignmentLimiter::limit(const Bonus *b, const CBonusSystemNode &nod return true; switch(alignment) { - case GOOD: + case EAlignment::GOOD: return !c->isGood(); //if not good -> return true (drop bonus) - case NEUTRAL: + case EAlignment::NEUTRAL: return c->isEvil() || c->isGood(); - case EVIL: + case EAlignment::EVIL: return !c->isEvil(); default: tlog1 << "Warning: illegal alignment in limiter!\n"; diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 8d5d9dd39..34126a45e 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -1,11 +1,8 @@ #pragma once -#include "../global.h" -#include -#include -#include -#include + + #include -#include +#include "GameConstants.h" /* * HeroBonus.h, part of VCMI engine @@ -37,6 +34,8 @@ namespace PrimarySkill enum { ATTACK, DEFENSE, SPELL_POWER, KNOWLEDGE}; } +#define BONUS_TREE_DESERIALIZATION_FIX if(!h.saving && h.smartPointerSerialization) deserializationFix(); + #define BONUS_LIST \ BONUS_NAME(NONE) \ BONUS_NAME(MOVEMENT) /*both water/land*/ \ @@ -175,7 +174,7 @@ namespace PrimarySkill BONUS_NAME(REBIRTH) /* val - percent of life restored, subtype = 0 - regular, 1 - at least one unit (sacred Phoenix) */ /// Struct for handling bonuses of several types. Can be transferred to any hero -struct DLL_EXPORT Bonus +struct DLL_LINKAGE Bonus { enum BonusType { @@ -327,10 +326,10 @@ struct DLL_EXPORT Bonus Bonus *addPropagator(boost::shared_ptr Propagator); //returns this for convenient chain-calls }; -DLL_EXPORT std::ostream & operator<<(std::ostream &out, const Bonus &bonus); +DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus); -class DLL_EXPORT BonusList +class DLL_LINKAGE BonusList { private: std::vector bonuses; @@ -380,7 +379,7 @@ public: void remove_if(Predicate pred) { BonusList newList; - for (unsigned int i = 0; i < bonuses.size(); i++) + for (ui32 i = 0; i < bonuses.size(); i++) { Bonus *b = bonuses[i]; if (!pred(b)) @@ -426,9 +425,9 @@ inline std::vector::const_iterator range_end(BonusList const &x) return x.end(); } -DLL_EXPORT std::ostream & operator<<(std::ostream &out, const BonusList &bonusList); +DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const BonusList &bonusList); -class DLL_EXPORT IPropagator +class DLL_LINKAGE IPropagator { public: virtual ~IPropagator(); @@ -439,7 +438,7 @@ public: {} }; -class DLL_EXPORT CPropagatorNodeType : public IPropagator +class DLL_LINKAGE CPropagatorNodeType : public IPropagator { ui8 nodeType; public: @@ -454,7 +453,7 @@ public: } }; -class DLL_EXPORT ILimiter +class DLL_LINKAGE ILimiter { public: virtual ~ILimiter(); @@ -465,7 +464,7 @@ public: {} }; -class DLL_EXPORT IBonusBearer +class DLL_LINKAGE IBonusBearer { public: //new bonusing node interface @@ -504,7 +503,7 @@ public: const TBonusListPtr getSpellBonuses() const; }; -class DLL_EXPORT CBonusSystemNode : public IBonusBearer +class DLL_LINKAGE CBonusSystemNode : public IBonusBearer { private: BonusList bonuses; //wielded bonuses (local or up-propagated here) @@ -600,11 +599,11 @@ public: namespace NBonus { //set of methods that may be safely called with NULL objs - DLL_EXPORT int valOf(const CBonusSystemNode *obj, Bonus::BonusType type, int subtype = -1); //subtype -> subtype of bonus, if -1 then any - DLL_EXPORT bool hasOfType(const CBonusSystemNode *obj, Bonus::BonusType type, int subtype = -1);//determines if hero has a bonus of given type (and optionally subtype) - //DLL_EXPORT const HeroBonus * get(const CBonusSystemNode *obj, int from, int id ); - DLL_EXPORT void getModifiersWDescr(const CBonusSystemNode *obj, TModDescr &out, Bonus::BonusType type, int subtype = -1 ); //out: pairs - DLL_EXPORT int getCount(const CBonusSystemNode *obj, int from, int id); + DLL_LINKAGE int valOf(const CBonusSystemNode *obj, Bonus::BonusType type, int subtype = -1); //subtype -> subtype of bonus, if -1 then any + DLL_LINKAGE bool hasOfType(const CBonusSystemNode *obj, Bonus::BonusType type, int subtype = -1);//determines if hero has a bonus of given type (and optionally subtype) + //DLL_LINKAGE const HeroBonus * get(const CBonusSystemNode *obj, int from, int id ); + DLL_LINKAGE void getModifiersWDescr(const CBonusSystemNode *obj, TModDescr &out, Bonus::BonusType type, int subtype = -1 ); //out: pairs + DLL_LINKAGE int getCount(const CBonusSystemNode *obj, int from, int id); }; /// generates HeroBonus from given data @@ -629,7 +628,7 @@ inline Bonus * makeFeature(Bonus::BonusType type, ui8 duration, si16 subtype, si } -class DLL_EXPORT CSelectorsConjunction +class DLL_LINKAGE CSelectorsConjunction { const CSelector first, second; public: @@ -642,9 +641,9 @@ public: return first(bonus) && second(bonus); } }; -CSelector DLL_EXPORT operator&&(const CSelector &first, const CSelector &second); +CSelector DLL_LINKAGE operator&&(const CSelector &first, const CSelector &second); -class DLL_EXPORT CSelectorsAlternative +class DLL_LINKAGE CSelectorsAlternative { const CSelector first, second; public: @@ -657,7 +656,7 @@ public: return first(bonus) || second(bonus); } }; -CSelector DLL_EXPORT operator||(const CSelector &first, const CSelector &second); +CSelector DLL_LINKAGE operator||(const CSelector &first, const CSelector &second); template class CSelectFieldEqual @@ -680,7 +679,7 @@ public: } }; -class DLL_EXPORT CWillLastTurns +class DLL_LINKAGE CWillLastTurns { public: int turnsRequested; @@ -698,7 +697,7 @@ public: } }; -class DLL_EXPORT CCreatureTypeLimiter : public ILimiter //affect only stacks of given creature (and optionally it's upgrades) +class DLL_LINKAGE CCreatureTypeLimiter : public ILimiter //affect only stacks of given creature (and optionally it's upgrades) { public: const CCreature *creature; @@ -715,7 +714,7 @@ public: } }; -class DLL_EXPORT HasAnotherBonusLimiter : public ILimiter //applies only to nodes that have another bonus working +class DLL_LINKAGE HasAnotherBonusLimiter : public ILimiter //applies only to nodes that have another bonus working { public: TBonusType type; @@ -733,7 +732,7 @@ public: } }; -class DLL_EXPORT CreatureNativeTerrainLimiter : public ILimiter //applies only to creatures that are on their native terrain +class DLL_LINKAGE CreatureNativeTerrainLimiter : public ILimiter //applies only to creatures that are on their native terrain { public: si8 terrainType; @@ -748,7 +747,7 @@ public: } }; -class DLL_EXPORT CreatureFactionLimiter : public ILimiter //applies only to creatures of given faction +class DLL_LINKAGE CreatureFactionLimiter : public ILimiter //applies only to creatures of given faction { public: si8 faction; @@ -763,7 +762,7 @@ public: } }; -class DLL_EXPORT CreatureAlignmentLimiter : public ILimiter //applies only to creatures of given alignment +class DLL_LINKAGE CreatureAlignmentLimiter : public ILimiter //applies only to creatures of given alignment { public: si8 alignment; @@ -778,7 +777,7 @@ public: } }; -class DLL_EXPORT StackOwnerLimiter : public ILimiter //applies only to creatures of given alignment +class DLL_LINKAGE StackOwnerLimiter : public ILimiter //applies only to creatures of given alignment { public: ui8 owner; @@ -793,7 +792,7 @@ public: } }; -class DLL_EXPORT RankRangeLimiter : public ILimiter //applies to creatures with min <= Rank <= max +class DLL_LINKAGE RankRangeLimiter : public ILimiter //applies to creatures with min <= Rank <= max { public: ui8 minRank, maxRank; @@ -812,26 +811,26 @@ const CCreature *retrieveCreature(const CBonusSystemNode *node); namespace Selector { - extern DLL_EXPORT CSelectFieldEqual type; - extern DLL_EXPORT CSelectFieldEqual subtype; - extern DLL_EXPORT CSelectFieldEqual info; - extern DLL_EXPORT CSelectFieldEqual duration; - extern DLL_EXPORT CSelectFieldEqual sourceType; - extern DLL_EXPORT CSelectFieldEqual effectRange; - extern DLL_EXPORT CWillLastTurns turns; + extern DLL_LINKAGE CSelectFieldEqual type; + extern DLL_LINKAGE CSelectFieldEqual subtype; + extern DLL_LINKAGE CSelectFieldEqual info; + extern DLL_LINKAGE CSelectFieldEqual duration; + extern DLL_LINKAGE CSelectFieldEqual sourceType; + extern DLL_LINKAGE CSelectFieldEqual effectRange; + extern DLL_LINKAGE CWillLastTurns turns; - CSelector DLL_EXPORT typeSubtype(TBonusType Type, TBonusSubtype Subtype); - CSelector DLL_EXPORT typeSubtypeInfo(TBonusType type, TBonusSubtype subtype, si32 info); - CSelector DLL_EXPORT source(ui8 source, ui32 sourceID); - CSelector DLL_EXPORT durationType(ui16 duration); - CSelector DLL_EXPORT sourceTypeSel(ui8 source); + CSelector DLL_LINKAGE typeSubtype(TBonusType Type, TBonusSubtype Subtype); + CSelector DLL_LINKAGE typeSubtypeInfo(TBonusType type, TBonusSubtype subtype, si32 info); + CSelector DLL_LINKAGE source(ui8 source, ui32 sourceID); + CSelector DLL_LINKAGE durationType(ui16 duration); + CSelector DLL_LINKAGE sourceTypeSel(ui8 source); - bool DLL_EXPORT matchesType(const CSelector &sel, TBonusType type); - bool DLL_EXPORT matchesTypeSubtype(const CSelector &sel, TBonusType type, TBonusSubtype subtype); - bool DLL_EXPORT positiveSpellEffects(const Bonus *b); + bool DLL_LINKAGE matchesType(const CSelector &sel, TBonusType type); + bool DLL_LINKAGE matchesTypeSubtype(const CSelector &sel, TBonusType type, TBonusSubtype subtype); + bool DLL_LINKAGE positiveSpellEffects(const Bonus *b); } -extern DLL_EXPORT const std::map bonusNameMap; +extern DLL_LINKAGE const std::map bonusNameMap; // BonusList template that requires full interface of CBonusSystemNode template diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index d1e453635..b915e3410 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -1,20 +1,20 @@ -#define VCMI_DLL +#include "StdInc.h" #include "IGameCallback.h" + #include "../lib/CGameState.h" #include "../lib/map.h" #include "CObjectHandler.h" #include "CHeroHandler.h" -#include "../StartInfo.h" +#include "StartInfo.h" #include "CArtHandler.h" #include "CSpellHandler.h" #include "../lib/VCMI_Lib.h" #include #include "CTownHandler.h" #include "BattleState.h" -#include #include "NetPacks.h" -#include #include "CBuildingHandler.h" +#include "GameConstants.h" /* * IGameCallback.cpp, part of VCMI engine @@ -39,35 +39,35 @@ boost::shared_mutex& CCallbackBase::getGsMutex() return *gs->mx; } -si8 CBattleInfoCallback::battleHasDistancePenalty( const CStack * stack, THex destHex ) +si8 CBattleInfoCallback::battleHasDistancePenalty( const CStack * stack, SHexField destHex ) { return gs->curB->hasDistancePenalty(stack, destHex); } -si8 CBattleInfoCallback::battleHasWallPenalty( const CStack * stack, THex destHex ) +si8 CBattleInfoCallback::battleHasWallPenalty( const CStack * stack, SHexField destHex ) { return gs->curB->hasWallPenalty(stack, destHex); } -si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, THex destHex, int telportLevel) +si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, SHexField destHex, int telportLevel) { return gs->curB->canTeleportTo(stack, destHex, telportLevel); } -std::vector CBattleInfoCallback::battleGetDistances(const CStack * stack, THex hex /*= THex::INVALID*/, THex * predecessors /*= NULL*/) +std::vector CBattleInfoCallback::battleGetDistances(const CStack * stack, SHexField hex /*= SHexField::INVALID*/, SHexField * predecessors /*= NULL*/) { if(!hex.isValid()) hex = stack->position; std::vector ret; - bool ac[BFIELD_SIZE] = {0}; - std::set occupyable; + bool ac[GameConstants::BFIELD_SIZE] = {0}; + std::set occupyable; gs->curB->getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack); - THex pr[BFIELD_SIZE]; - int dist[BFIELD_SIZE]; + SHexField pr[GameConstants::BFIELD_SIZE]; + int dist[GameConstants::BFIELD_SIZE]; gs->curB->makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false); - for(int i=0; i CBattleInfoCallback::battleGetDistances(const CStack * stack, T if(predecessors) { - memcpy(predecessors, pr, BFIELD_SIZE * sizeof(THex)); + memcpy(predecessors, pr, GameConstants::BFIELD_SIZE * sizeof(SHexField)); } return ret; } -std::set CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos /*= THex::INVALID*/) +std::set CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, SHexField destinationTile, SHexField attackerPos /*= SHexField::INVALID*/) { if(!gs->curB) { tlog1 << "battleGetAttackedHexes called when there is no battle!\n"; - std::set set; + std::set set; return set; } return gs->curB->getAttackedHexes(attacker, destinationTile, attackerPos); } -SpellCasting::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell( const CSpell * spell ) +ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell( const CSpell * spell ) { if(!gs->curB) { tlog1 << "battleCanCastThisSpell called when there is no battle!\n"; - return SpellCasting::NO_HERO_TO_CAST_SPELL; + return ESpellCastProblem::NO_HERO_TO_CAST_SPELL; } - return gs->curB->battleCanCastThisSpell(player, spell, SpellCasting::HERO_CASTING); + return gs->curB->battleCanCastThisSpell(player, spell, ECastingMode::HERO_CASTING); } -SpellCasting::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell(const CSpell * spell, THex destination) +ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell(const CSpell * spell, SHexField destination) { if(!gs->curB) { tlog1 << "battleCanCastThisSpell called when there is no battle!\n"; - return SpellCasting::NO_HERO_TO_CAST_SPELL; + return ESpellCastProblem::NO_HERO_TO_CAST_SPELL; } - return gs->curB->battleCanCastThisSpellHere(player, spell, SpellCasting::CREATURE_ACTIVE_CASTING, destination); + return gs->curB->battleCanCastThisSpellHere(player, spell, ECastingMode::CREATURE_ACTIVE_CASTING, destination); } TSpell CBattleInfoCallback::battleGetRandomStackSpell(const CStack * stack, ERandomSpell mode) @@ -185,7 +185,7 @@ int CBattleInfoCallback::battleGetBattlefieldType() return gs->curB->battlefieldType; } -int CBattleInfoCallback::battleGetObstaclesAtTile(THex tile) //returns bitfield +int CBattleInfoCallback::battleGetObstaclesAtTile(SHexField tile) //returns bitfield { //TODO - write return -1; @@ -207,26 +207,26 @@ const CStack* CBattleInfoCallback::battleGetStackByID(int ID, bool onlyAlive) return gs->curB->getStack(ID, onlyAlive); } -const CStack* CBattleInfoCallback::battleGetStackByPos(THex pos, bool onlyAlive) +const CStack* CBattleInfoCallback::battleGetStackByPos(SHexField pos, bool onlyAlive) { //boost::shared_lock lock(*gs->mx); return gs->curB->battleGetStack(pos, onlyAlive); } -THex CBattleInfoCallback::battleGetPos(int stack) +SHexField CBattleInfoCallback::battleGetPos(int stack) { //boost::shared_lock lock(*gs->mx); if(!gs->curB) { tlog2<<"battleGetPos called when there is no battle!"<curB->stacks.size(); ++g) { if(gs->curB->stacks[g]->ID == stack) return gs->curB->stacks[g]->position; } - return THex::INVALID; + return SHexField::INVALID; } TStacks CBattleInfoCallback::battleGetStacks(EStackOwnership whose /*= MINE_AND_ENEMY*/, bool onlyAlive /*= true*/) @@ -265,27 +265,27 @@ void CBattleInfoCallback::battleGetStackCountOutsideHexes(bool *ac) if(!gs->curB) { tlog2<<"battleGetAvailableHexes called when there is no battle!"< ignored; + std::set ignored; gs->curB->getAccessibilityMap(ac, false /*ignored*/, false, false, ignored, false /*ignored*/, NULL); } } -std::vector CBattleInfoCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable) +std::vector CBattleInfoCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable) { //boost::shared_lock lock(*gs->mx); if(!gs->curB) { tlog2<<"battleGetAvailableHexes called when there is no battle!"<(); + return std::vector(); } return gs->curB->getAccessibility(stack, addOccupiable, attackable); //return gs->battleGetRange(ID); } -bool CBattleInfoCallback::battleCanShoot(const CStack * stack, THex dest) +bool CBattleInfoCallback::battleCanShoot(const CStack * stack, SHexField dest) { //boost::shared_lock lock(*gs->mx); @@ -299,7 +299,7 @@ bool CBattleInfoCallback::battleCanCastSpell() if(!gs->curB) //there is no battle return false; - return gs->curB->battleCanCastSpell(player, SpellCasting::HERO_CASTING) == SpellCasting::OK; + return gs->curB->battleCanCastSpell(player, ECastingMode::HERO_CASTING) == ESpellCastProblem::OK; } bool CBattleInfoCallback::battleCanFlee() @@ -324,7 +324,7 @@ ui8 CBattleInfoCallback::battleGetWallState(int partOfWall) return gs->curB->si.wallState[partOfWall]; } -int CBattleInfoCallback::battleGetWallUnderHex(THex hex) +int CBattleInfoCallback::battleGetWallUnderHex(SHexField hex) { if(!gs->curB || gs->curB->siege == 0) { @@ -432,7 +432,7 @@ const PlayerSettings * CGameInfoCallback::getPlayerSettings(int color) const void CPrivilagedInfoCallback::getTilesInRange( boost::unordered_set &tiles, int3 pos, int radious, int player/*=-1*/, int mode/*=0*/ ) const { - if(player >= PLAYER_LIMIT) + if(player >= GameConstants::PLAYER_LIMIT) { tlog1 << "Illegal call to getTilesInRange!\n"; return; @@ -462,7 +462,7 @@ void CPrivilagedInfoCallback::getTilesInRange( boost::unordered_set &tiles, int Player/*=-1*/, int level, int surface ) const { - if(Player >= PLAYER_LIMIT) + if(Player >= GameConstants::PLAYER_LIMIT) { tlog1 << "Illegal call to getAllTiles !\n"; return; @@ -568,7 +568,7 @@ void CPrivilagedInfoCallback::getAllowedSpells(std::vector &out, ui16 leve { CSpell *spell; - for (unsigned int i = 0; i < gs->map->allowedSpell.size(); i++) //spellh size appears to be greater (?) + for (ui32 i = 0; i < gs->map->allowedSpell.size(); i++) //spellh size appears to be greater (?) { spell = VLC->spellh->spells[i]; if (isAllowed (0, spell->id) && spell->level == level) @@ -702,10 +702,10 @@ void CGameInfoCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObj { //boost::shared_lock lock(*gs->mx); ERROR_RET_IF(!obj, "No guild object!"); - ERROR_RET_IF(obj->ID == TOWNI_TYPE && !canGetFullInfo(obj), "Cannot get info about town guild object!"); + ERROR_RET_IF(obj->ID == GameConstants::TOWNI_TYPE && !canGetFullInfo(obj), "Cannot get info about town guild object!"); //TODO: advmap object -> check if they're visited by our hero - if(obj->ID == TOWNI_TYPE || obj->ID == 95) //it is a town or adv map tavern + if(obj->ID == GameConstants::TOWNI_TYPE || obj->ID == 95) //it is a town or adv map tavern { gs->obtainPlayersStats(thi, gs->players[obj->tempOwner].towns.size()); } @@ -727,7 +727,7 @@ bool CGameInfoCallback::getTownInfo( const CGObjectInstance *town, InfoAboutTown bool detailed = hasAccess(town->tempOwner); //TODO vision support - if(town->ID == TOWNI_TYPE) + if(town->ID == GameConstants::TOWNI_TYPE) dest.initFromTown(static_cast(town), detailed); else if(town->ID == 33 || town->ID == 219) dest.initFromGarrison(static_cast(town), detailed); @@ -896,18 +896,18 @@ int CGameInfoCallback::canBuildStructure( const CGTownInstance *t, int ID ) { ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", -1); - int ret = Buildings::ALLOWED; - if(t->builded >= MAX_BUILDING_PER_TURN) - ret = Buildings::CANT_BUILD_TODAY; //building limit + int ret = EBuildingState::ALLOWED; + if(t->builded >= GameConstants::MAX_BUILDING_PER_TURN) + ret = EBuildingState::CANT_BUILD_TODAY; //building limit CBuilding * pom = VLC->buildh->buildings[t->subID][ID]; if(!pom) - return Buildings::ERROR; + return EBuildingState::BUILDING_ERROR; //checking resources if(!pom->resources.canBeAfforded(getPlayer(t->tempOwner)->resources)) - ret = Buildings::NO_RESOURCES; //lack of res + ret = EBuildingState::NO_RESOURCES; //lack of res //checking for requirements std::set reqs = getBuildingRequiments(t, ID);//getting all requirements @@ -915,12 +915,12 @@ int CGameInfoCallback::canBuildStructure( const CGTownInstance *t, int ID ) for( std::set::iterator ri = reqs.begin(); ri != reqs.end(); ri++ ) { if(t->builtBuildings.find(*ri)==t->builtBuildings.end()) - ret = Buildings::PREREQUIRES; //lack of requirements - cannot build + ret = EBuildingState::PREREQUIRES; //lack of requirements - cannot build } //can we build it? if(t->forbiddenBuildings.find(ID)!=t->forbiddenBuildings.end()) - ret = Buildings::FORBIDDEN; //forbidden + ret = EBuildingState::FORBIDDEN; //forbidden if(ID == 13) //capitol { @@ -931,7 +931,7 @@ int CGameInfoCallback::canBuildStructure( const CGTownInstance *t, int ID ) { if(vstd::contains(t->builtBuildings, 13)) { - ret = Buildings::HAVE_CAPITAL; //no more than one capitol + ret = EBuildingState::HAVE_CAPITAL; //no more than one capitol break; } } @@ -942,11 +942,11 @@ int CGameInfoCallback::canBuildStructure( const CGTownInstance *t, int ID ) const TerrainTile *tile = getTile(t->bestLocation()); if(!tile || tile->tertype != TerrainTile::water ) - ret = Buildings::NO_WATER; //lack of water + ret = EBuildingState::NO_WATER; //lack of water } if(t->builtBuildings.find(ID)!=t->builtBuildings.end()) //already built - ret = Buildings::ALREADY_PRESENT; + ret = EBuildingState::ALREADY_PRESENT; return ret; } @@ -1027,7 +1027,7 @@ int CGameInfoCallback::getHeroCount( int player, bool includeGarrisoned ) const if(includeGarrisoned) return p->heroes.size(); else - for(unsigned int i = 0; i < p->heroes.size(); i++) + for(ui32 i = 0; i < p->heroes.size(); i++) if(!p->heroes[i]->inTownGarrison) ret++; return ret; @@ -1040,7 +1040,7 @@ bool CGameInfoCallback::isOwnedOrVisited(const CGObjectInstance *obj) const const TerrainTile *t = getTile(obj->visitablePos()); //get entrance tile const CGObjectInstance *visitor = t->visitableObjects.back(); //visitong hero if present or the obejct itself at last - return visitor->ID == HEROI_TYPE && canGetFullInfo(visitor); //owned or allied hero is a visitor + return visitor->ID == GameConstants::HEROI_TYPE && canGetFullInfo(visitor); //owned or allied hero is a visitor } int CGameInfoCallback::getCurrentPlayer() const @@ -1058,7 +1058,7 @@ CGameInfoCallback::CGameInfoCallback(CGameState *GS, int Player) player = Player; } -const std::vector< std::vector< std::vector > > & CPlayerSpecificInfoCallback::getVisibilityMap() const +const std::vector< std::vector< std::vector > > & CPlayerSpecificInfoCallback::getVisibilityMap() const { //boost::shared_lock lock(*gs->mx); return gs->getPlayerTeam(player)->fogOfWarMap; @@ -1119,15 +1119,15 @@ int CPlayerSpecificInfoCallback::getHeroSerial(const CGHeroInstance * hero) cons return -1; } -int3 CPlayerSpecificInfoCallback::getGrailPos( float &outKnownRatio ) +int3 CPlayerSpecificInfoCallback::getGrailPos( double &outKnownRatio ) { if (CGObelisk::obeliskCount == 0) { - outKnownRatio = 0.0f; + outKnownRatio = 0.0; } else { - outKnownRatio = (float)CGObelisk::visited[gs->getPlayerTeam(player)->id] / CGObelisk::obeliskCount; + outKnownRatio = static_cast(CGObelisk::visited[gs->getPlayerTeam(player)->id]) / CGObelisk::obeliskCount; } return gs->map->grailPos; } @@ -1167,7 +1167,7 @@ const CGHeroInstance* CPlayerSpecificInfoCallback::getHeroBySerial(int serialId, if (!includeGarrisoned) { - for(unsigned int i = 0; i < p->heroes.size() && i<=serialId; i++) + for(ui32 i = 0; i < p->heroes.size() && i<=serialId; i++) if(p->heroes[i]->inTownGarrison) serialId++; } diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index c75a58db5..c19ccbe45 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -1,12 +1,12 @@ -#ifndef __IGAMECALLBACK_H__ -#define __IGAMECALLBACK_H__ +#pragma once -#include "../global.h" -#include -#include + +#include "SHexField.h" #include "../client/FunctionList.h" #include "CObstacleInstance.h" #include "ResourceSet.h" +#include "int3.h" +#include "GameConstants.h" /* * IGameCallback.h, part of VCMI engine @@ -63,7 +63,7 @@ typedef std::vector TStacks; namespace boost {class shared_mutex;} -class DLL_EXPORT CCallbackBase +class DLL_LINKAGE CCallbackBase { protected: CGameState *gs; @@ -80,7 +80,7 @@ public: boost::shared_mutex &getGsMutex(); //just return a reference to mutex, does not lock nor anything }; -class DLL_EXPORT CBattleInfoCallback : public virtual CCallbackBase +class DLL_LINKAGE CBattleInfoCallback : public virtual CCallbackBase { public: enum EStackOwnership @@ -94,33 +94,33 @@ public: //battle int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship - int battleGetObstaclesAtTile(THex tile); //returns bitfield + int battleGetObstaclesAtTile(SHexField tile); //returns bitfield std::vector battleGetAllObstacles(); //returns all obstacles on the battlefield const CStack * battleGetStackByID(int ID, bool onlyAlive = true); //returns stack info by given ID - const CStack * battleGetStackByPos(THex pos, bool onlyAlive = true); //returns stack info by given pos - THex battleGetPos(int stack); //returns position (tile ID) of stack + const CStack * battleGetStackByPos(SHexField pos, bool onlyAlive = true); //returns stack info by given pos + SHexField battleGetPos(int stack); //returns position (tile ID) of stack TStacks battleGetStacks(EStackOwnership whose = MINE_AND_ENEMY, bool onlyAlive = true); //returns stacks on battlefield void getStackQueue( std::vector &out, int howMany ); //returns vector of stack in order of their move sequence void battleGetStackCountOutsideHexes(bool *ac); // returns hexes which when in front of a stack cause us to move the amount box back - std::vector battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL); //returns numbers of hexes reachable by creature with id ID - std::vector battleGetDistances(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL); //returns vector of distances to [dest hex number] - std::set battleGetAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos = THex::INVALID); - bool battleCanShoot(const CStack * stack, THex dest); //returns true if unit with id ID can shoot to dest + std::vector battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL); //returns numbers of hexes reachable by creature with id ID + std::vector battleGetDistances(const CStack * stack, SHexField hex = SHexField::INVALID, SHexField * predecessors = NULL); //returns vector of distances to [dest hex number] + std::set battleGetAttackedHexes(const CStack* attacker, SHexField destinationTile, SHexField attackerPos = SHexField::INVALID); + bool battleCanShoot(const CStack * stack, SHexField dest); //returns true if unit with id ID can shoot to dest bool battleCanCastSpell(); //returns true, if caller can cast a spell - SpellCasting::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell); //determines if given spell can be casted (and returns problem description) - SpellCasting::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell, THex destination); //determines if creature can cast a spell here - TSpell battleGetRandomStackSpell(const CStack * stack, ERandomSpell mode); + ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell); //determines if given spell can be casted (and returns problem description) + ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell, SHexField destination); //determines if creature can cast a spell here + ui32 battleGetRandomStackSpell(const CStack * stack, ERandomSpell mode); bool battleCanFlee(); //returns true if caller can flee from the battle int battleGetSurrenderCost(); //returns cost of surrendering battle, -1 if surrendering is not possible const CGTownInstance * battleGetDefendedTown(); //returns defended town if current battle is a siege, NULL instead ui8 battleGetWallState(int partOfWall); //for determining state of a part of the wall; format: parameter [0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; returned value: 1 - intact, 2 - damaged, 3 - destroyed; 0 - no battle - int battleGetWallUnderHex(THex hex); //returns part of destructible wall / gate / keep under given hex or -1 if not found - TDmgRange battleEstimateDamage(const CStack * attacker, const CStack * defender, TDmgRange * retaliationDmg = NULL); //estimates damage dealt by attacker to defender; it may be not precise especially when stack has randomly working bonuses; returns pair + int battleGetWallUnderHex(SHexField hex); //returns part of destructible wall / gate / keep under given hex or -1 if not found + std::pair battleEstimateDamage(const CStack * attacker, const CStack * defender, std::pair * retaliationDmg = NULL); //estimates damage dealt by attacker to defender; it may be not precise especially when stack has randomly working bonuses; returns pair ui8 battleGetSiegeLevel(); //returns 0 when there is no siege, 1 if fort, 2 is citadel, 3 is castle const CGHeroInstance * battleGetFightingHero(ui8 side) const; //returns hero corresponding to given side (0 - attacker, 1 - defender) - si8 battleHasDistancePenalty(const CStack * stack, THex destHex); //checks if given stack has distance penalty - si8 battleHasWallPenalty(const CStack * stack, THex destHex); //checks if given stack has wall penalty - si8 battleCanTeleportTo(const CStack * stack, THex destHex, int telportLevel); //checks if teleportation of given stack to given position can take place + si8 battleHasDistancePenalty(const CStack * stack, SHexField destHex); //checks if given stack has distance penalty + si8 battleHasWallPenalty(const CStack * stack, SHexField destHex); //checks if given stack has wall penalty + si8 battleCanTeleportTo(const CStack * stack, SHexField destHex, int telportLevel); //checks if teleportation of given stack to given position can take place si8 battleGetTacticDist(); //returns tactic distance for calling player or 0 if player is not in tactic phase ui8 battleGetMySide(); //return side of player in battle (attacker/defender) @@ -131,7 +131,7 @@ public: } }; -class DLL_EXPORT CGameInfoCallback : public virtual CCallbackBase +class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase { protected: CGameInfoCallback(); @@ -210,12 +210,12 @@ public: }; -class DLL_EXPORT CPlayerSpecificInfoCallback : public CGameInfoCallback +class DLL_LINKAGE CPlayerSpecificInfoCallback : public CGameInfoCallback { public: int howManyTowns() const; int howManyHeroes(bool includeGarrisoned = true) const; - int3 getGrailPos(float &outKnownRatio); + int3 getGrailPos(double &outKnownRatio); int getMyColor() const; std::vector getTownsInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible @@ -228,11 +228,11 @@ public: int getResourceAmount(int type)const; TResources getResourceAmount() const; - const std::vector< std::vector< std::vector > > & getVisibilityMap()const; //returns visibility map + const std::vector< std::vector< std::vector > > & getVisibilityMap()const; //returns visibility map const PlayerSettings * getPlayerSettings(int color) const; }; -class DLL_EXPORT CPrivilagedInfoCallback : public CGameInfoCallback +class DLL_LINKAGE CPrivilagedInfoCallback : public CGameInfoCallback { public: CGameState *const gameState (); @@ -246,7 +246,7 @@ public: void getAllowedSpells(std::vector &out, ui16 level); }; -class DLL_EXPORT CNonConstInfoCallback : public CPrivilagedInfoCallback +class DLL_LINKAGE CNonConstInfoCallback : public CPrivilagedInfoCallback { public: PlayerState *getPlayer(ui8 color, bool verbose = true); @@ -257,7 +257,7 @@ public: TerrainTile * getTile(int3 pos); }; -class DLL_EXPORT IGameEventRealizer +class DLL_LINKAGE IGameEventRealizer { public: virtual void commitPackage(CPackForClient *pack) = 0; @@ -269,7 +269,7 @@ public: virtual void showInfoDialog(const std::string &msg, int player); }; -class DLL_EXPORT IGameEventCallback : public IGameEventRealizer +class DLL_LINKAGE IGameEventCallback : public IGameEventRealizer { public: virtual void changeSpells(int hid, bool give, const std::set &spells)=0; @@ -320,7 +320,7 @@ public: }; /// Interface class for handling general game logic and actions -class DLL_EXPORT IGameCallback : public CPrivilagedInfoCallback, public IGameEventCallback +class DLL_LINKAGE IGameCallback : public CPrivilagedInfoCallback, public IGameEventCallback { public: virtual ~IGameCallback(){}; @@ -333,4 +333,3 @@ public: friend struct CPackForClient; friend struct CPackForServer; }; -#endif // __IGAMECALLBACK_H__ diff --git a/lib/IGameEventsReceiver.h b/lib/IGameEventsReceiver.h index 7e1acece9..964645fe5 100644 --- a/lib/IGameEventsReceiver.h +++ b/lib/IGameEventsReceiver.h @@ -1,6 +1,8 @@ #pragma once -#include "../global.h" -#include + + +#include "SHexField.h" +#include "int3.h" class CGTownInstance; class CCreature; @@ -33,7 +35,7 @@ struct SetStackEffect; struct BattleTriggerEffect; -class DLL_EXPORT IBattleEventsReceiver +class DLL_LINKAGE IBattleEventsReceiver { public: virtual void actionFinished(const BattleAction *action){};//occurs AFTER every action taken by any stack or by the hero @@ -43,7 +45,7 @@ public: virtual void battleEnd(const BattleResult *br){}; virtual void battleNewRoundFirst(int round){}; //called at the beginning of each turn before changes are applied; virtual void battleNewRound(int round){}; //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance){}; + virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance){}; virtual void battleSpellCast(const BattleSpellCast *sc){}; virtual void battleStacksEffectsSet(const SetStackEffect & sse){};//called when a specific effect is set to stacks virtual void battleTriggerEffect(const BattleTriggerEffect & bte){}; //called for various one-shot effects @@ -55,7 +57,7 @@ public: virtual void battleStacksRemoved(const BattleStacksRemoved & bsr){}; //called when certain stack is completely removed from battlefield }; -class DLL_EXPORT IGameEventsReceiver +class DLL_LINKAGE IGameEventsReceiver { public: virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished diff --git a/lib/Interprocess.h b/lib/Interprocess.h index 6f7363227..4c4ac9c45 100644 --- a/lib/Interprocess.h +++ b/lib/Interprocess.h @@ -1,3 +1,5 @@ +#pragma once + #include #include #include diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index 6ffeeadbf..6aa8f1d3b 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -1,14 +1,6 @@ -#define VCMI_DLL +#include "StdInc.h" #include "JsonNode.h" -#include -#include - -#include -#include -#include -#include - const JsonNode JsonNode::nullNode; JsonNode::JsonNode(JsonType Type): @@ -123,7 +115,7 @@ bool & JsonNode::Bool() return data.Bool; } -float & JsonNode::Float() +double & JsonNode::Float() { setType(DATA_FLOAT); return data.Float; @@ -156,8 +148,8 @@ const bool & JsonNode::Bool() const return data.Bool; } -const float floatDefault = 0; -const float & JsonNode::Float() const +const double floatDefault = 0; +const double & JsonNode::Float() const { if (type == DATA_NULL) return floatDefault; @@ -362,7 +354,7 @@ bool JsonParser::extractWhitespace(bool verbose) { while (true) { - while (pos < input.size() && (unsigned char)input[pos] <= ' ') + while (pos < input.size() && (ui8)input[pos] <= ' ') { if (input[pos] == '\n') { @@ -602,7 +594,7 @@ bool JsonParser::extractFloat(JsonNode &node) { assert(input[pos] == '-' || (input[pos] >= '0' && input[pos] <= '9')); bool negative=false; - float result=0; + double result=0; if (input[pos] == '-') { @@ -624,7 +616,7 @@ bool JsonParser::extractFloat(JsonNode &node) { //extract fractional part pos++; - float fractMult = 0.1; + double fractMult = 0.1; if (input[pos] < '0' || input[pos] > '9') return error("Decimal part expected!"); diff --git a/lib/JsonNode.h b/lib/JsonNode.h index 4bcb4ec9f..c383a8a08 100644 --- a/lib/JsonNode.h +++ b/lib/JsonNode.h @@ -1,18 +1,12 @@ #pragma once -#include "../global.h" -#include -#include -#include -#include -#include class JsonNode; typedef std::map JsonMap; typedef std::vector JsonVector; -class DLL_EXPORT JsonNode +class DLL_LINKAGE JsonNode { public: enum JsonType @@ -29,7 +23,7 @@ private: union JsonData { bool Bool; - float Float; + double Float; std::string* String; JsonVector* Vector; JsonMap* Struct; @@ -61,14 +55,14 @@ public: //non-const accessors, node will change type on type mismatch bool & Bool(); - float & Float(); + double & Float(); std::string & String(); JsonVector & Vector(); JsonMap & Struct(); //const accessors, will cause assertion failure on type mismatch const bool & Bool() const; - const float & Float() const; + const double & Float() const; const std::string & String() const; const JsonVector & Vector() const; const JsonMap & Struct() const; @@ -129,7 +123,7 @@ class JsonParser { std::string errors; // Contains description of all encountered errors constString input; // Input data - unsigned int lineCount; // Currently parsed line, starting from 1 + ui32 lineCount; // Currently parsed line, starting from 1 size_t lineStart; // Position of current line start size_t pos; // Current position of parser diff --git a/lib/Makefile.am b/lib/Makefile.am index 87f8c31b3..531f0a491 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,6 +1,10 @@ +BUILT_SOURCES = StdInc.h.gch +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< + pkglib_LTLIBRARIES = libvcmi.la libvcmi_la_LIBADD = @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ @BOOST_IOSTREAMS_LIB@ -lz -lpthread -ldl -libvcmi_la_CXXFLAGS = @SDL_CFLAGS@ +libvcmi_la_CXXFLAGS = @SDL_CFLAGS@ -DVCMI_DLL libvcmi_la_SOURCES = \ BattleAction.cpp \ BattleAction.h \ @@ -12,6 +16,8 @@ libvcmi_la_SOURCES = \ CBuildingHandler.h \ CCampaignHandler.cpp \ CCampaignHandler.h \ + CConsoleHandler.cpp \ + CConsoleHandler.h \ CCreatureHandler.cpp \ CCreatureHandler.h \ CCreatureSet.cpp \ @@ -30,6 +36,8 @@ libvcmi_la_SOURCES = \ CHeroHandler.h \ CLodHandler.cpp \ CLodHandler.h \ + CLogger.cpp \ + CLogger.h \ CMapInfo.cpp \ CMapInfo.h \ CObjectHandler.cpp \ @@ -40,6 +48,8 @@ libvcmi_la_SOURCES = \ CScriptingModule.h \ CTownHandler.cpp \ CTownHandler.h \ + CThreadHelper.cpp \ + CThreadHelper.h \ CondSh.h \ Connection.cpp \ Connection.h \ @@ -56,8 +66,9 @@ libvcmi_la_SOURCES = \ NetPacksLib.cpp \ ResourceSet.cpp \ ResourceSet.h \ - RegisterTypes.cpp \ RegisterTypes.h \ + SHexField.cpp \ + SHexField.h \ VCMIDirs.h \ VCMI_Lib.cpp \ VCMI_Lib.h \ diff --git a/lib/Makefile.in b/lib/Makefile.in index 68e259848..cfe714b99 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -82,17 +82,19 @@ libvcmi_la_DEPENDENCIES = am_libvcmi_la_OBJECTS = libvcmi_la-BattleAction.lo \ libvcmi_la-BattleState.lo libvcmi_la-CArtHandler.lo \ libvcmi_la-CBuildingHandler.lo libvcmi_la-CCampaignHandler.lo \ - libvcmi_la-CCreatureHandler.lo libvcmi_la-CCreatureSet.lo \ - libvcmi_la-CDefObjInfoHandler.lo libvcmi_la-CFileUtility.lo \ - libvcmi_la-CGameInterface.lo libvcmi_la-CGameState.lo \ - libvcmi_la-CGeneralTextHandler.lo libvcmi_la-CHeroHandler.lo \ - libvcmi_la-CLodHandler.lo libvcmi_la-CMapInfo.lo \ + libvcmi_la-CConsoleHandler.lo libvcmi_la-CCreatureHandler.lo \ + libvcmi_la-CCreatureSet.lo libvcmi_la-CDefObjInfoHandler.lo \ + libvcmi_la-CFileUtility.lo libvcmi_la-CGameInterface.lo \ + libvcmi_la-CGameState.lo libvcmi_la-CGeneralTextHandler.lo \ + libvcmi_la-CHeroHandler.lo libvcmi_la-CLodHandler.lo \ + libvcmi_la-CLogger.lo libvcmi_la-CMapInfo.lo \ libvcmi_la-CObjectHandler.lo libvcmi_la-CSpellHandler.lo \ - libvcmi_la-CTownHandler.lo libvcmi_la-Connection.lo \ - libvcmi_la-HeroBonus.lo libvcmi_la-IGameCallback.lo \ - libvcmi_la-JsonNode.lo libvcmi_la-NetPacksLib.lo \ - libvcmi_la-ResourceSet.lo libvcmi_la-RegisterTypes.lo \ - libvcmi_la-VCMI_Lib.lo libvcmi_la-map.lo + libvcmi_la-CTownHandler.lo libvcmi_la-CThreadHelper.lo \ + libvcmi_la-Connection.lo libvcmi_la-HeroBonus.lo \ + libvcmi_la-IGameCallback.lo libvcmi_la-JsonNode.lo \ + libvcmi_la-NetPacksLib.lo libvcmi_la-ResourceSet.lo \ + libvcmi_la-SHexField.lo libvcmi_la-VCMI_Lib.lo \ + libvcmi_la-map.lo libvcmi_la_OBJECTS = $(am_libvcmi_la_OBJECTS) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) @@ -281,9 +283,10 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ +BUILT_SOURCES = StdInc.h.gch pkglib_LTLIBRARIES = libvcmi.la libvcmi_la_LIBADD = @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ @BOOST_IOSTREAMS_LIB@ -lz -lpthread -ldl -libvcmi_la_CXXFLAGS = @SDL_CFLAGS@ +libvcmi_la_CXXFLAGS = @SDL_CFLAGS@ -DVCMI_DLL libvcmi_la_SOURCES = \ BattleAction.cpp \ BattleAction.h \ @@ -295,6 +298,8 @@ libvcmi_la_SOURCES = \ CBuildingHandler.h \ CCampaignHandler.cpp \ CCampaignHandler.h \ + CConsoleHandler.cpp \ + CConsoleHandler.h \ CCreatureHandler.cpp \ CCreatureHandler.h \ CCreatureSet.cpp \ @@ -313,6 +318,8 @@ libvcmi_la_SOURCES = \ CHeroHandler.h \ CLodHandler.cpp \ CLodHandler.h \ + CLogger.cpp \ + CLogger.h \ CMapInfo.cpp \ CMapInfo.h \ CObjectHandler.cpp \ @@ -323,6 +330,8 @@ libvcmi_la_SOURCES = \ CScriptingModule.h \ CTownHandler.cpp \ CTownHandler.h \ + CThreadHelper.cpp \ + CThreadHelper.h \ CondSh.h \ Connection.cpp \ Connection.h \ @@ -339,15 +348,17 @@ libvcmi_la_SOURCES = \ NetPacksLib.cpp \ ResourceSet.cpp \ ResourceSet.h \ - RegisterTypes.cpp \ RegisterTypes.h \ + SHexField.cpp \ + SHexField.h \ VCMIDirs.h \ VCMI_Lib.cpp \ VCMI_Lib.h \ map.cpp \ map.h -all: all-am +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .cpp .lo .o .obj @@ -426,6 +437,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CArtHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CBuildingHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CCampaignHandler.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CConsoleHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CCreatureHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CCreatureSet.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CDefObjInfoHandler.Plo@am__quote@ @@ -435,17 +447,19 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CGeneralTextHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CHeroHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CLodHandler.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CLogger.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CMapInfo.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CObjectHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CSpellHandler.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CThreadHelper.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-CTownHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-Connection.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-HeroBonus.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-IGameCallback.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-JsonNode.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-NetPacksLib.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-RegisterTypes.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-ResourceSet.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-SHexField.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-VCMI_Lib.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvcmi_la-map.Plo@am__quote@ @@ -513,6 +527,14 @@ libvcmi_la-CCampaignHandler.lo: CCampaignHandler.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -c -o libvcmi_la-CCampaignHandler.lo `test -f 'CCampaignHandler.cpp' || echo '$(srcdir)/'`CCampaignHandler.cpp +libvcmi_la-CConsoleHandler.lo: CConsoleHandler.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -MT libvcmi_la-CConsoleHandler.lo -MD -MP -MF $(DEPDIR)/libvcmi_la-CConsoleHandler.Tpo -c -o libvcmi_la-CConsoleHandler.lo `test -f 'CConsoleHandler.cpp' || echo '$(srcdir)/'`CConsoleHandler.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvcmi_la-CConsoleHandler.Tpo $(DEPDIR)/libvcmi_la-CConsoleHandler.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='CConsoleHandler.cpp' object='libvcmi_la-CConsoleHandler.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -c -o libvcmi_la-CConsoleHandler.lo `test -f 'CConsoleHandler.cpp' || echo '$(srcdir)/'`CConsoleHandler.cpp + libvcmi_la-CCreatureHandler.lo: CCreatureHandler.cpp @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -MT libvcmi_la-CCreatureHandler.lo -MD -MP -MF $(DEPDIR)/libvcmi_la-CCreatureHandler.Tpo -c -o libvcmi_la-CCreatureHandler.lo `test -f 'CCreatureHandler.cpp' || echo '$(srcdir)/'`CCreatureHandler.cpp @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvcmi_la-CCreatureHandler.Tpo $(DEPDIR)/libvcmi_la-CCreatureHandler.Plo @@ -585,6 +607,14 @@ libvcmi_la-CLodHandler.lo: CLodHandler.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -c -o libvcmi_la-CLodHandler.lo `test -f 'CLodHandler.cpp' || echo '$(srcdir)/'`CLodHandler.cpp +libvcmi_la-CLogger.lo: CLogger.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -MT libvcmi_la-CLogger.lo -MD -MP -MF $(DEPDIR)/libvcmi_la-CLogger.Tpo -c -o libvcmi_la-CLogger.lo `test -f 'CLogger.cpp' || echo '$(srcdir)/'`CLogger.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvcmi_la-CLogger.Tpo $(DEPDIR)/libvcmi_la-CLogger.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='CLogger.cpp' object='libvcmi_la-CLogger.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -c -o libvcmi_la-CLogger.lo `test -f 'CLogger.cpp' || echo '$(srcdir)/'`CLogger.cpp + libvcmi_la-CMapInfo.lo: CMapInfo.cpp @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -MT libvcmi_la-CMapInfo.lo -MD -MP -MF $(DEPDIR)/libvcmi_la-CMapInfo.Tpo -c -o libvcmi_la-CMapInfo.lo `test -f 'CMapInfo.cpp' || echo '$(srcdir)/'`CMapInfo.cpp @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvcmi_la-CMapInfo.Tpo $(DEPDIR)/libvcmi_la-CMapInfo.Plo @@ -617,6 +647,14 @@ libvcmi_la-CTownHandler.lo: CTownHandler.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -c -o libvcmi_la-CTownHandler.lo `test -f 'CTownHandler.cpp' || echo '$(srcdir)/'`CTownHandler.cpp +libvcmi_la-CThreadHelper.lo: CThreadHelper.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -MT libvcmi_la-CThreadHelper.lo -MD -MP -MF $(DEPDIR)/libvcmi_la-CThreadHelper.Tpo -c -o libvcmi_la-CThreadHelper.lo `test -f 'CThreadHelper.cpp' || echo '$(srcdir)/'`CThreadHelper.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvcmi_la-CThreadHelper.Tpo $(DEPDIR)/libvcmi_la-CThreadHelper.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='CThreadHelper.cpp' object='libvcmi_la-CThreadHelper.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -c -o libvcmi_la-CThreadHelper.lo `test -f 'CThreadHelper.cpp' || echo '$(srcdir)/'`CThreadHelper.cpp + libvcmi_la-Connection.lo: Connection.cpp @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -MT libvcmi_la-Connection.lo -MD -MP -MF $(DEPDIR)/libvcmi_la-Connection.Tpo -c -o libvcmi_la-Connection.lo `test -f 'Connection.cpp' || echo '$(srcdir)/'`Connection.cpp @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvcmi_la-Connection.Tpo $(DEPDIR)/libvcmi_la-Connection.Plo @@ -665,13 +703,13 @@ libvcmi_la-ResourceSet.lo: ResourceSet.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -c -o libvcmi_la-ResourceSet.lo `test -f 'ResourceSet.cpp' || echo '$(srcdir)/'`ResourceSet.cpp -libvcmi_la-RegisterTypes.lo: RegisterTypes.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -MT libvcmi_la-RegisterTypes.lo -MD -MP -MF $(DEPDIR)/libvcmi_la-RegisterTypes.Tpo -c -o libvcmi_la-RegisterTypes.lo `test -f 'RegisterTypes.cpp' || echo '$(srcdir)/'`RegisterTypes.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvcmi_la-RegisterTypes.Tpo $(DEPDIR)/libvcmi_la-RegisterTypes.Plo +libvcmi_la-SHexField.lo: SHexField.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -MT libvcmi_la-SHexField.lo -MD -MP -MF $(DEPDIR)/libvcmi_la-SHexField.Tpo -c -o libvcmi_la-SHexField.lo `test -f 'SHexField.cpp' || echo '$(srcdir)/'`SHexField.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvcmi_la-SHexField.Tpo $(DEPDIR)/libvcmi_la-SHexField.Plo @am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='RegisterTypes.cpp' object='libvcmi_la-RegisterTypes.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SHexField.cpp' object='libvcmi_la-SHexField.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -c -o libvcmi_la-RegisterTypes.lo `test -f 'RegisterTypes.cpp' || echo '$(srcdir)/'`RegisterTypes.cpp +@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -c -o libvcmi_la-SHexField.lo `test -f 'SHexField.cpp' || echo '$(srcdir)/'`SHexField.cpp libvcmi_la-VCMI_Lib.lo: VCMI_Lib.cpp @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvcmi_la_CXXFLAGS) $(CXXFLAGS) -MT libvcmi_la-VCMI_Lib.lo -MD -MP -MF $(DEPDIR)/libvcmi_la-VCMI_Lib.Tpo -c -o libvcmi_la-VCMI_Lib.lo `test -f 'VCMI_Lib.cpp' || echo '$(srcdir)/'`VCMI_Lib.cpp @@ -778,13 +816,15 @@ distdir: $(DISTFILES) fi; \ done check-am: all-am -check: check-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am all-am: Makefile $(LTLIBRARIES) installdirs: for dir in "$(DESTDIR)$(pkglibdir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-am +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -809,6 +849,7 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am clean-am: clean-generic clean-libtool clean-pkglibLTLIBRARIES \ @@ -880,7 +921,7 @@ ps-am: uninstall-am: uninstall-pkglibLTLIBRARIES -.MAKE: install-am install-strip +.MAKE: all check install install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ clean-libtool clean-pkglibLTLIBRARIES ctags distclean \ @@ -896,6 +937,8 @@ uninstall-am: uninstall-pkglibLTLIBRARIES mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags uninstall uninstall-am uninstall-pkglibLTLIBRARIES +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/lib/NetPacks.h b/lib/NetPacks.h index fbafac2ab..8dc4c2fbe 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -1,15 +1,13 @@ -#ifndef __NETPACKS_H__ -#define __NETPACKS_H__ -#include -#include "../global.h" +#pragma once + + #include "BattleAction.h" #include "HeroBonus.h" -#include #include "CCreatureSet.h" #include "CMapInfo.h" -#include "../StartInfo.h" +#include "StartInfo.h" #include "ConstTransitivePtr.h" -#include "../int3.h" +#include "int3.h" #include "ResourceSet.h" /* @@ -45,7 +43,7 @@ struct CPack { tlog1 << "CPack serialized... this should not happen!\n"; } - DLL_EXPORT void applyGs(CGameState *gs) + DLL_LINKAGE void applyGs(CGameState *gs) {}; }; @@ -141,9 +139,9 @@ public: message.push_back(TREPLACE_PLUSNUMBER); numbers.push_back(txt); } - DLL_EXPORT void addCreReplacement(TCreature id, TQuantity count); //adds sing or plural name; - DLL_EXPORT void addReplacement(const CStackBasicDescriptor &stack); //adds sing or plural name; - DLL_EXPORT std::string buildList () const; + DLL_LINKAGE void addCreReplacement(TCreature id, TQuantity count); //adds sing or plural name; + DLL_LINKAGE void addReplacement(const CStackBasicDescriptor &stack); //adds sing or plural name; + DLL_LINKAGE std::string buildList () const; void clear() { exactStrings.clear(); @@ -151,8 +149,8 @@ public: message.clear(); numbers.clear(); } - DLL_EXPORT void toString(std::string &dst) const; - DLL_EXPORT std::string toString() const; + DLL_LINKAGE void toString(std::string &dst) const; + DLL_LINKAGE std::string toString() const; void getLocalString(const std::pair &txt, std::string &dst) const; MetaString() @@ -213,7 +211,7 @@ struct YourTurn : public CPackForClient //100 { YourTurn(){type = 100;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui8 player; @@ -227,7 +225,7 @@ struct SetResource : public CPackForClient //102 { SetResource(){type = 102;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui8 player, resid; si32 val; @@ -241,7 +239,7 @@ struct SetResource : public CPackForClient //102 { SetResources(){type = 104;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui8 player; TResources res; //res[resid] => res amount @@ -256,7 +254,7 @@ struct SetPrimSkill : public CPackForClient //105 { SetPrimSkill(){type = 105;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui8 abs; //0 - changes by value; 1 - sets to value si32 id; @@ -272,7 +270,7 @@ struct SetSecSkill : public CPackForClient //106 { SetSecSkill(){type = 106;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui8 abs; //0 - changes by value; 1 - sets to value si32 id; @@ -287,7 +285,7 @@ struct HeroVisitCastle : public CPackForClient //108 { HeroVisitCastle(){flags=0;type = 108;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui8 flags; //1 - start ui32 tid, hid; @@ -309,7 +307,7 @@ struct ChangeSpells : public CPackForClient //109 { ChangeSpells(){type = 109;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui8 learn; //1 - gives spell, 0 - takes ui32 hid; @@ -325,7 +323,7 @@ struct SetMana : public CPackForClient //110 { SetMana(){type = 110;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); si32 hid, val; @@ -340,7 +338,7 @@ struct SetMovePoints : public CPackForClient //111 { SetMovePoints(){type = 111;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui32 hid, val; @@ -354,7 +352,7 @@ struct FoWChange : public CPackForClient //112 { FoWChange(){type = 112;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); boost::unordered_set tiles; ui8 player, mode; //mode==0 - hide, mode==1 - reveal @@ -369,18 +367,18 @@ struct SetAvailableHeroes : public CPackForClient //113 SetAvailableHeroes() { type = 113; - for (int i = 0; i < AVAILABLE_HEROES_PER_PLAYER; i++) + for (int i = 0; i < GameConstants::AVAILABLE_HEROES_PER_PLAYER; i++) army[i].clear(); } ~SetAvailableHeroes() { } void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui8 player; - si32 hid[AVAILABLE_HEROES_PER_PLAYER]; //-1 if no hero - CSimpleArmy army[AVAILABLE_HEROES_PER_PLAYER]; + si32 hid[GameConstants::AVAILABLE_HEROES_PER_PLAYER]; //-1 if no hero + CSimpleArmy army[GameConstants::AVAILABLE_HEROES_PER_PLAYER]; template void serialize(Handler &h, const int version) { h & player & hid & army; @@ -396,7 +394,7 @@ struct GiveBonus : public CPackForClient //115 } void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); enum {HERO, PLAYER, TOWN}; ui8 who; //who receives bonus, uses enum above @@ -419,7 +417,7 @@ struct ChangeObjPos : public CPackForClient //116 } void applyFirstCl(CClient *cl); void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui32 objid; int3 nPos; @@ -439,7 +437,7 @@ struct PlayerEndsGame : public CPackForClient //117 } void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui8 player; ui8 victory; @@ -460,7 +458,7 @@ struct RemoveBonus : public CPackForClient //118 } void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); enum {HERO, PLAYER, TOWN}; ui8 who; //who receives bonus, uses enum above @@ -501,7 +499,7 @@ struct RemoveObject : public CPackForClient //500 RemoveObject(si32 ID){id = ID;type = 500;}; void applyFirstCl(CClient *cl); void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); si32 id; @@ -540,7 +538,7 @@ struct TryMoveHero : public CPackForClient //501 // { // SetGarrisons(){type = 502;}; // void applyCl(CClient *cl); -// DLL_EXPORT void applyGs(CGameState *gs); +// DLL_LINKAGE void applyGs(CGameState *gs); // // std::map garrs; // @@ -554,7 +552,7 @@ struct NewStructures : public CPackForClient //504 { NewStructures(){type = 504;}; void applyCl(CClient *cl); - DLL_EXPORT virtual void applyGs(CGameState *gs); + DLL_LINKAGE virtual void applyGs(CGameState *gs); si32 tid; std::set bid; @@ -569,7 +567,7 @@ struct RazeStructures : public CPackForClient //505 { RazeStructures() {type = 505;}; void applyCl (CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); si32 tid; std::set bid; @@ -584,7 +582,7 @@ struct SetAvailableCreatures : public CPackForClient //506 { SetAvailableCreatures(){type = 506;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); si32 tid; std::vector > > creatures; @@ -598,7 +596,7 @@ struct SetHeroesInTown : public CPackForClient //508 { SetHeroesInTown(){type = 508;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); si32 tid, visiting, garrison; //id of town, visiting hero, hero in garrison @@ -612,8 +610,8 @@ struct SetHeroesInTown : public CPackForClient //508 // { // SetHeroArtifacts(){type = 509;}; // void applyCl(CClient *cl); -// DLL_EXPORT void applyGs(CGameState *gs); -// DLL_EXPORT void setArtAtPos(ui16 pos, const CArtifact* art); +// DLL_LINKAGE void applyGs(CGameState *gs); +// DLL_LINKAGE void setArtAtPos(ui16 pos, const CArtifact* art); // // si32 hid; // std::vector artifacts; //hero's artifacts from bag @@ -632,7 +630,7 @@ struct HeroRecruited : public CPackForClient //515 { HeroRecruited(){type = 515;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); si32 hid, tid; //subID of hero int3 tile; @@ -649,7 +647,7 @@ struct GiveHero : public CPackForClient //516 GiveHero(){type = 516;}; void applyFirstCl(CClient *cl); void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui32 id; //object id ui8 player; @@ -684,7 +682,7 @@ struct NewObject : public CPackForClient //518 id = -1; } void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui32 ID, subID; int3 pos; @@ -701,7 +699,7 @@ struct SetAvailableArtifacts : public CPackForClient //519 { SetAvailableArtifacts(){type = 519;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); si32 id; //two variants: id < 0: set artifact pool for Artifact Merchants in towns; id >= 0: set pool for adv. map Black Market (id is the id of Black Market instance then) std::vector arts; @@ -716,7 +714,7 @@ struct NewArtifact : public CPackForClient //520 { NewArtifact(){type = 520;}; //void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ConstTransitivePtr art; @@ -740,7 +738,7 @@ struct StackLocation army = const_cast(Army); //we are allowed here to const cast -> change will go through one of our packages... do not abuse! slot = Slot; } - DLL_EXPORT const CStackInstance *getStack(); + DLL_LINKAGE const CStackInstance *getStack(); template void serialize(Handler &h, const int version) { h & army & slot; @@ -762,7 +760,7 @@ struct ChangeStackCount : CGarrisonOperationPack //521 ui8 absoluteValue; //if not -> count will be added (or subtracted if negative) void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -776,7 +774,7 @@ struct SetStackType : CGarrisonOperationPack //522 CCreature *type; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -789,7 +787,7 @@ struct EraseStack : CGarrisonOperationPack //523 StackLocation sl; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -802,7 +800,7 @@ struct SwapStacks : CGarrisonOperationPack //524 StackLocation sl1, sl2; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -816,7 +814,7 @@ struct InsertNewStack : CGarrisonOperationPack //525 CStackBasicDescriptor stack; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -831,7 +829,7 @@ struct RebalanceStacks : CGarrisonOperationPack //526 TQuantity count; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -855,9 +853,9 @@ struct ArtifactLocation hero = const_cast(Hero); //we are allowed here to const cast -> change will go through one of our packages... do not abuse! slot = Slot; } - DLL_EXPORT const CArtifactInstance *getArt() const; - DLL_EXPORT CArtifactInstance *getArt(); - DLL_EXPORT const ArtSlotInfo *getSlot() const; + DLL_LINKAGE const CArtifactInstance *getArt() const; + DLL_LINKAGE CArtifactInstance *getArt(); + DLL_LINKAGE const ArtSlotInfo *getSlot() const; template void serialize(Handler &h, const int version) { h & hero & slot; @@ -870,7 +868,7 @@ struct PutArtifact : CArtifactOperationPack //526 ConstTransitivePtr art; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -883,7 +881,7 @@ struct EraseArtifact : CArtifactOperationPack //527 ArtifactLocation al; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -896,7 +894,7 @@ struct MoveArtifact : CArtifactOperationPack //528 ArtifactLocation src, dst; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -912,7 +910,7 @@ struct AssembledArtifact : CArtifactOperationPack //529 void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -925,7 +923,7 @@ struct DisassembledArtifact : CArtifactOperationPack //530 ArtifactLocation al; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -940,7 +938,7 @@ struct HeroVisit : CPackForClient //531 bool starting; //false -> ending void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { @@ -953,7 +951,7 @@ struct NewTurn : public CPackForClient //101 enum weekType {NORMAL, DOUBLE_GROWTH, BONUS_GROWTH, DEITYOFFIRE, PLAGUE, NO_ACTION}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); struct Hero { @@ -997,7 +995,7 @@ struct Component : public CPack //2002 helper for object scrips informations { type = 2002; } - DLL_EXPORT explicit Component(const CStackBasicDescriptor &stack); + DLL_LINKAGE explicit Component(const CStackBasicDescriptor &stack); Component(ui16 Type, ui16 Subtype, si32 Val, si16 When) :id(Type),subtype(Subtype),val(Val),when(When) { @@ -1034,7 +1032,7 @@ namespace ObjProperty struct SetObjectProperty : public CPackForClient//1001 { - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); void applyCl(CClient *cl); ui32 id; @@ -1051,7 +1049,7 @@ struct SetObjectProperty : public CPackForClient//1001 struct SetHoverName : public CPackForClient//1002 { - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui32 id; MetaString name; @@ -1066,7 +1064,7 @@ struct SetHoverName : public CPackForClient//1002 struct HeroLevelUp : public Query//2000 { void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); si32 heroid; ui8 primskill, level; @@ -1084,7 +1082,7 @@ struct TradeComponents : public CPackForClient, public CPackForServer { ///used to handle info about components available in shops void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); si32 heroid; ui32 objectid; @@ -1159,7 +1157,7 @@ struct BattleStart : public CPackForClient//3000 { BattleStart(){type = 3000;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); BattleInfo * info; @@ -1174,7 +1172,7 @@ struct BattleNextRound : public CPackForClient//3001 BattleNextRound(){type = 3001;}; void applyFirstCl(CClient *cl); void applyCl(CClient *cl); - DLL_EXPORT void applyGs( CGameState *gs ); + DLL_LINKAGE void applyGs( CGameState *gs ); si32 round; template void serialize(Handler &h, const int version) @@ -1186,7 +1184,7 @@ struct BattleSetActiveStack : public CPackForClient//3002 { BattleSetActiveStack(){type = 3002;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui32 stack; @@ -1216,7 +1214,7 @@ struct BattleResult : public CPackForClient//3003 struct BattleStackMoved : public CPackForClient//3004 { ui32 stack; - std::vector tilesToMove; + std::vector tilesToMove; ui8 distance, teleporting; BattleStackMoved(){type = 3004;}; void applyFirstCl(CClient *cl); @@ -1231,7 +1229,7 @@ struct StacksHealedOrResurrected : public CPackForClient //3013 { StacksHealedOrResurrected(){type = 3013;} - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); void applyCl(CClient *cl); struct HealInfo @@ -1260,7 +1258,7 @@ struct BattleStackAttacked : public CPackForClient//3005 { BattleStackAttacked(){flags = 0; type = 3005;}; void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); ui32 stackAttacked, attackerID; ui32 newAmount, newHP, killedAmount, damageAmount; @@ -1305,7 +1303,7 @@ struct BattleAttack : public CPackForClient//3006 { BattleAttack(){flags = 0; type = 3006;}; void applyFirstCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); void applyCl(CClient *cl); std::vector bsa; @@ -1353,7 +1351,7 @@ struct StartAction : public CPackForClient//3007 StartAction(){type = 3007;}; StartAction(const BattleAction &act){ba = act; type = 3007;}; void applyFirstCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); BattleAction ba; template void serialize(Handler &h, const int version) @@ -1375,7 +1373,7 @@ struct EndAction : public CPackForClient//3008 struct BattleSpellCast : public CPackForClient//3009 { BattleSpellCast(){type = 3009;}; - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); void applyCl(CClient *cl); si32 dmgToDisplay; //this amount will be displayed as amount of damage dealt by spell @@ -1384,7 +1382,7 @@ struct BattleSpellCast : public CPackForClient//3009 ui8 skill; //caster's skill level ui8 spellCost; ui8 manaGained; //mana channeling ability - THex tile; //destination tile (may not be set in some global/mass spells + SHexField tile; //destination tile (may not be set in some global/mass spells std::vector resisted; //ids of creatures that resisted this spell std::set affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure) TCreature attackerType;//id of caster to generate console message; -1 if not set (eg. spell casted by artifact) @@ -1398,7 +1396,7 @@ struct BattleSpellCast : public CPackForClient//3009 struct SetStackEffect : public CPackForClient //3010 { SetStackEffect(){type = 3010;}; - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); void applyCl(CClient *cl); std::vector stacks; //affected stacks (IDs) @@ -1413,7 +1411,7 @@ struct SetStackEffect : public CPackForClient //3010 struct StacksInjured : public CPackForClient //3011 { StacksInjured(){type = 3011;} - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); void applyCl(CClient *cl); std::vector stacks; @@ -1440,7 +1438,7 @@ struct ObstaclesRemoved : public CPackForClient //3014 { ObstaclesRemoved(){type = 3014;} - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); void applyCl(CClient *cl); std::set obstacles; //uniqueIDs of removed obstacles @@ -1455,7 +1453,7 @@ struct CatapultAttack : public CPackForClient //3015 { CatapultAttack(){type = 3015;} - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); void applyCl(CClient *cl); std::set< std::pair< std::pair< ui8, si16 >, ui8> > attackedParts; // < , damageDealt> @@ -1474,7 +1472,7 @@ struct BattleStacksRemoved : public CPackForClient //3016 { BattleStacksRemoved(){type = 3016;} - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); void applyCl(CClient *cl); std::set stackIDs; //IDs of removed stacks @@ -1489,7 +1487,7 @@ struct BattleStackAdded : public CPackForClient //3017 { BattleStackAdded(){type = 3017;}; - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); void applyCl(CClient *cl); int attacker; // if true, stack belongs to attacker @@ -1510,7 +1508,7 @@ struct BattleSetStackProperty : public CPackForClient //3018 enum BattleStackProperty {CASTS, ENCHANTER_COUNTER, UNBIND}; - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); //void applyCl(CClient *cl){}; int stackID; @@ -1528,7 +1526,7 @@ struct BattleTriggerEffect : public CPackForClient //3019 { //activated at the beginning of turn BattleTriggerEffect(){type = 3019;}; - DLL_EXPORT void applyGs(CGameState *gs); //effect + DLL_LINKAGE void applyGs(CGameState *gs); //effect void applyCl(CClient *cl); //play animations & stuff //enum BattleEffect {REGENERATION, MANA_DRAIN, FEAR, MANA_CHANNELING, ENCHANTER, UNBIND, POISON, ENCHANTED, SUMMONER}; @@ -1795,7 +1793,7 @@ struct TradeOnMarketplace : public CPackForServer const CGObjectInstance *market; const CGHeroInstance *hero; //needed when trading artifacts / creatures - ui8 mode;//enum EMarketMode + ui8 mode;//enum EEMarketMode ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res (exception: when sacrificing art r1 is art id [todo: make r2 preferred slot?] ui32 val; //units of sold resource @@ -1953,7 +1951,7 @@ struct PlayerMessage : public CPackForClient, public CPackForServer //513 struct SetSelection : public CPackForClient, public CPackForServer //514 { SetSelection(){CPackForClient::type = 514;}; - DLL_EXPORT void applyGs(CGameState *gs); + DLL_LINKAGE void applyGs(CGameState *gs); bool applyGh(CGameHandler *gh); void applyCl(CClient *cl); @@ -2155,5 +2153,3 @@ public: //h & playerNames; } }; - -#endif //__NETPACKS_H__ diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 3422c5b52..5b045693c 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -1,5 +1,6 @@ -#define VCMI_DLL +#include "StdInc.h" #include "NetPacks.h" + #include "CGeneralTextHandler.h" #include "CDefObjInfoHandler.h" #include "CArtHandler.h" @@ -9,12 +10,6 @@ #include "map.h" #include "CSpellHandler.h" #include "CCreatureHandler.h" -#include -#include -#include -#include -#include -#include #include "CGameState.h" #include "BattleState.h" @@ -38,20 +33,20 @@ #undef max #endif -DLL_EXPORT void SetResource::applyGs( CGameState *gs ) +DLL_LINKAGE void SetResource::applyGs( CGameState *gs ) { - assert(player < PLAYER_LIMIT); - amax(val, 0); //new value must be >= 0 + assert(player < GameConstants::PLAYER_LIMIT); + vstd::amax(val, 0); //new value must be >= 0 gs->getPlayer(player)->resources[resid] = val; } -DLL_EXPORT void SetResources::applyGs( CGameState *gs ) +DLL_LINKAGE void SetResources::applyGs( CGameState *gs ) { - assert(player < PLAYER_LIMIT); + assert(player < GameConstants::PLAYER_LIMIT); gs->getPlayer(player)->resources = res; } -DLL_EXPORT void SetPrimSkill::applyGs( CGameState *gs ) +DLL_LINKAGE void SetPrimSkill::applyGs( CGameState *gs ) { CGHeroInstance *hero = gs->getHero(id); assert(hero); @@ -75,13 +70,13 @@ DLL_EXPORT void SetPrimSkill::applyGs( CGameState *gs ) } } -DLL_EXPORT void SetSecSkill::applyGs( CGameState *gs ) +DLL_LINKAGE void SetSecSkill::applyGs( CGameState *gs ) { CGHeroInstance *hero = gs->getHero(id); hero->setSecSkillLevel(static_cast(which), val, abs); } -DLL_EXPORT void HeroVisitCastle::applyGs( CGameState *gs ) +DLL_LINKAGE void HeroVisitCastle::applyGs( CGameState *gs ) { CGHeroInstance *h = gs->getHero(hid); CGTownInstance *t = gs->getTown(tid); @@ -92,7 +87,7 @@ DLL_EXPORT void HeroVisitCastle::applyGs( CGameState *gs ) t->setVisitingHero(NULL); } -DLL_EXPORT void ChangeSpells::applyGs( CGameState *gs ) +DLL_LINKAGE void ChangeSpells::applyGs( CGameState *gs ) { CGHeroInstance *hero = gs->getHero(hid); @@ -104,20 +99,20 @@ DLL_EXPORT void ChangeSpells::applyGs( CGameState *gs ) hero->spells.erase(sid); } -DLL_EXPORT void SetMana::applyGs( CGameState *gs ) +DLL_LINKAGE void SetMana::applyGs( CGameState *gs ) { CGHeroInstance *hero = gs->getHero(hid); - amax(val, 0); //not less than 0 + vstd::amax(val, 0); //not less than 0 hero->mana = val; } -DLL_EXPORT void SetMovePoints::applyGs( CGameState *gs ) +DLL_LINKAGE void SetMovePoints::applyGs( CGameState *gs ) { CGHeroInstance *hero = gs->getHero(hid); hero->movement = val; } -DLL_EXPORT void FoWChange::applyGs( CGameState *gs ) +DLL_LINKAGE void FoWChange::applyGs( CGameState *gs ) { TeamState * team = gs->getPlayerTeam(player); BOOST_FOREACH(int3 t, tiles) @@ -145,12 +140,12 @@ DLL_EXPORT void FoWChange::applyGs( CGameState *gs ) team->fogOfWarMap[t.x][t.y][t.z] = 1; } } -DLL_EXPORT void SetAvailableHeroes::applyGs( CGameState *gs ) +DLL_LINKAGE void SetAvailableHeroes::applyGs( CGameState *gs ) { PlayerState *p = gs->getPlayer(player); p->availableHeroes.clear(); - for (int i = 0; i < AVAILABLE_HEROES_PER_PLAYER; i++) + for (int i = 0; i < GameConstants::AVAILABLE_HEROES_PER_PLAYER; i++) { CGHeroInstance *h = (hid[i]>=0 ? (CGHeroInstance*)gs->hpool.heroesPool[hid[i]] : NULL); if(h && army[i]) @@ -159,7 +154,7 @@ DLL_EXPORT void SetAvailableHeroes::applyGs( CGameState *gs ) } } -DLL_EXPORT void GiveBonus::applyGs( CGameState *gs ) +DLL_LINKAGE void GiveBonus::applyGs( CGameState *gs ) { CBonusSystemNode *cbsn = NULL; switch(who) @@ -185,7 +180,7 @@ DLL_EXPORT void GiveBonus::applyGs( CGameState *gs ) if(!bdescr.message.size() && bonus.source == Bonus::OBJECT && (bonus.type == Bonus::LUCK || bonus.type == Bonus::MORALE) - && gs->map->objects[bonus.sid]->ID == EVENTI_TYPE) //it's morale/luck bonus from an event without description + && gs->map->objects[bonus.sid]->ID == GameConstants::EVENTI_TYPE) //it's morale/luck bonus from an event without description { descr = VLC->generaltexth->arraytxt[bonus.val > 0 ? 110 : 109]; //+/-%d Temporary until next battle" boost::replace_first(descr,"%d",boost::lexical_cast(std::abs(bonus.val))); @@ -196,7 +191,7 @@ DLL_EXPORT void GiveBonus::applyGs( CGameState *gs ) } } -DLL_EXPORT void ChangeObjPos::applyGs( CGameState *gs ) +DLL_LINKAGE void ChangeObjPos::applyGs( CGameState *gs ) { CGObjectInstance *obj = gs->map->objects[objid]; if(!obj) @@ -209,13 +204,13 @@ DLL_EXPORT void ChangeObjPos::applyGs( CGameState *gs ) gs->map->addBlockVisTiles(obj); } -DLL_EXPORT void PlayerEndsGame::applyGs( CGameState *gs ) +DLL_LINKAGE void PlayerEndsGame::applyGs( CGameState *gs ) { PlayerState *p = gs->getPlayer(player); p->status = victory ? 2 : 1; } -DLL_EXPORT void RemoveBonus::applyGs( CGameState *gs ) +DLL_LINKAGE void RemoveBonus::applyGs( CGameState *gs ) { CBonusSystemNode *node; if (who == HERO) @@ -237,7 +232,7 @@ DLL_EXPORT void RemoveBonus::applyGs( CGameState *gs ) } } -DLL_EXPORT void RemoveObject::applyGs( CGameState *gs ) +DLL_LINKAGE void RemoveObject::applyGs( CGameState *gs ) { CGObjectInstance *obj = gs->map->objects[id]; //unblock tiles @@ -246,7 +241,7 @@ DLL_EXPORT void RemoveObject::applyGs( CGameState *gs ) gs->map->removeBlockVisTiles(obj); } - if(obj->ID==HEROI_TYPE) + if(obj->ID==GameConstants::HEROI_TYPE) { CGHeroInstance *h = static_cast(obj); PlayerState *p = gs->getPlayer(h->tempOwner); @@ -362,7 +357,7 @@ void TryMoveHero::applyGs( CGameState *gs ) gs->getPlayerTeam(h->getOwner())->fogOfWarMap[t.x][t.y][t.z] = 1; } -DLL_EXPORT void NewStructures::applyGs( CGameState *gs ) +DLL_LINKAGE void NewStructures::applyGs( CGameState *gs ) { CGTownInstance *t = gs->getTown(tid); BOOST_FOREACH(si32 id,bid) @@ -372,7 +367,7 @@ DLL_EXPORT void NewStructures::applyGs( CGameState *gs ) t->builded = builded; t->recreateBuildingsBonuses(); } -DLL_EXPORT void RazeStructures::applyGs( CGameState *gs ) +DLL_LINKAGE void RazeStructures::applyGs( CGameState *gs ) { CGTownInstance *t = gs->getTown(tid); BOOST_FOREACH(si32 id,bid) @@ -383,14 +378,14 @@ DLL_EXPORT void RazeStructures::applyGs( CGameState *gs ) t->recreateBuildingsBonuses(); } -DLL_EXPORT void SetAvailableCreatures::applyGs( CGameState *gs ) +DLL_LINKAGE void SetAvailableCreatures::applyGs( CGameState *gs ) { CGDwelling *dw = dynamic_cast(gs->map->objects[tid].get()); assert(dw); dw->creatures = creatures; } -DLL_EXPORT void SetHeroesInTown::applyGs( CGameState *gs ) +DLL_LINKAGE void SetHeroesInTown::applyGs( CGameState *gs ) { CGTownInstance *t = gs->getTown(tid); @@ -419,7 +414,7 @@ DLL_EXPORT void SetHeroesInTown::applyGs( CGameState *gs ) } } -DLL_EXPORT void HeroRecruited::applyGs( CGameState *gs ) +DLL_LINKAGE void HeroRecruited::applyGs( CGameState *gs ) { assert(vstd::contains(gs->hpool.heroesPool, hid)); CGHeroInstance *h = gs->hpool.heroesPool[hid]; @@ -451,7 +446,7 @@ DLL_EXPORT void HeroRecruited::applyGs( CGameState *gs ) } } -DLL_EXPORT void GiveHero::applyGs( CGameState *gs ) +DLL_LINKAGE void GiveHero::applyGs( CGameState *gs ) { CGHeroInstance *h = gs->getHero(id); gs->map->removeBlockVisTiles(h,true); @@ -464,7 +459,7 @@ DLL_EXPORT void GiveHero::applyGs( CGameState *gs ) h->inTownGarrison = false; } -DLL_EXPORT void NewObject::applyGs( CGameState *gs ) +DLL_LINKAGE void NewObject::applyGs( CGameState *gs ) { CGObjectInstance *o = NULL; @@ -515,7 +510,7 @@ DLL_EXPORT void NewObject::applyGs( CGameState *gs ) o->initObj(); assert(o->defInfo); } -DLL_EXPORT void NewArtifact::applyGs( CGameState *gs ) +DLL_LINKAGE void NewArtifact::applyGs( CGameState *gs ) { assert(!vstd::contains(gs->map->artInstances, art)); gs->map->addNewArtifactInstance(art); @@ -526,7 +521,7 @@ DLL_EXPORT void NewArtifact::applyGs( CGameState *gs ) cart->createConstituents(); } -DLL_EXPORT const CStackInstance * StackLocation::getStack() +DLL_LINKAGE const CStackInstance * StackLocation::getStack() { if(!army->hasStackAtSlot(slot)) { @@ -536,7 +531,7 @@ DLL_EXPORT const CStackInstance * StackLocation::getStack() return &army->getStack(slot); } -DLL_EXPORT const CArtifactInstance *ArtifactLocation::getArt() const +DLL_LINKAGE const CArtifactInstance *ArtifactLocation::getArt() const { const ArtSlotInfo *s = getSlot(); if(s && s->artifact) @@ -553,18 +548,18 @@ DLL_EXPORT const CArtifactInstance *ArtifactLocation::getArt() const return NULL; } -DLL_EXPORT CArtifactInstance *ArtifactLocation::getArt() +DLL_LINKAGE CArtifactInstance *ArtifactLocation::getArt() { const ArtifactLocation *t = this; return const_cast(t->getArt()); } -DLL_EXPORT const ArtSlotInfo *ArtifactLocation::getSlot() const +DLL_LINKAGE const ArtSlotInfo *ArtifactLocation::getSlot() const { return hero->getSlot(slot); } -DLL_EXPORT void ChangeStackCount::applyGs( CGameState *gs ) +DLL_LINKAGE void ChangeStackCount::applyGs( CGameState *gs ) { if(absoluteValue) sl.army->setStackCount(sl.slot, count); @@ -572,17 +567,17 @@ DLL_EXPORT void ChangeStackCount::applyGs( CGameState *gs ) sl.army->changeStackCount(sl.slot, count); } -DLL_EXPORT void SetStackType::applyGs( CGameState *gs ) +DLL_LINKAGE void SetStackType::applyGs( CGameState *gs ) { sl.army->setStackType(sl.slot, type); } -DLL_EXPORT void EraseStack::applyGs( CGameState *gs ) +DLL_LINKAGE void EraseStack::applyGs( CGameState *gs ) { sl.army->eraseStack(sl.slot); } -DLL_EXPORT void SwapStacks::applyGs( CGameState *gs ) +DLL_LINKAGE void SwapStacks::applyGs( CGameState *gs ) { CStackInstance *s1 = sl1.army->detachStack(sl1.slot), *s2 = sl2.army->detachStack(sl2.slot); @@ -591,13 +586,13 @@ DLL_EXPORT void SwapStacks::applyGs( CGameState *gs ) sl1.army->putStack(sl1.slot, s2); } -DLL_EXPORT void InsertNewStack::applyGs( CGameState *gs ) +DLL_LINKAGE void InsertNewStack::applyGs( CGameState *gs ) { CStackInstance *s = new CStackInstance(stack.type, stack.count); sl.army->putStack(sl.slot, s); } -DLL_EXPORT void RebalanceStacks::applyGs( CGameState *gs ) +DLL_LINKAGE void RebalanceStacks::applyGs( CGameState *gs ) { const CCreature *srcType = src.army->getCreature(src.slot); TQuantity srcCount = src.army->getStackCount(src.slot); @@ -607,7 +602,7 @@ DLL_EXPORT void RebalanceStacks::applyGs( CGameState *gs ) if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> merge { assert(c == srcType); - if (STACK_EXP) + if (GameConstants::STACK_EXP) { ui64 totalExp = srcCount * src.army->getStackExperience(src.slot) + dst.army->getStackCount(dst.slot) * dst.army->getStackExperience(dst.slot); src.army->eraseStack(src.slot); @@ -631,7 +626,7 @@ DLL_EXPORT void RebalanceStacks::applyGs( CGameState *gs ) if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> rebalance { assert(c == srcType); - if (STACK_EXP) + if (GameConstants::STACK_EXP) { ui64 totalExp = srcCount * src.army->getStackExperience(src.slot) + dst.army->getStackCount(dst.slot) * dst.army->getStackExperience(dst.slot); src.army->changeStackCount(src.slot, -count); @@ -648,35 +643,35 @@ DLL_EXPORT void RebalanceStacks::applyGs( CGameState *gs ) { src.army->changeStackCount(src.slot, -count); dst.army->addToSlot(dst.slot, srcType->idNumber, count, false); - if (STACK_EXP) + if (GameConstants::STACK_EXP) dst.army->setStackExp(dst.slot, src.army->getStackExperience(src.slot)); } } } -DLL_EXPORT void PutArtifact::applyGs( CGameState *gs ) +DLL_LINKAGE void PutArtifact::applyGs( CGameState *gs ) { assert(art->canBePutAt(al)); al.hero->putArtifact(al.slot, art); } -DLL_EXPORT void EraseArtifact::applyGs( CGameState *gs ) +DLL_LINKAGE void EraseArtifact::applyGs( CGameState *gs ) { CArtifactInstance *a = al.getArt(); assert(a); a->removeFrom(al.hero, al.slot); } -DLL_EXPORT void MoveArtifact::applyGs( CGameState *gs ) +DLL_LINKAGE void MoveArtifact::applyGs( CGameState *gs ) { CArtifactInstance *a = src.getArt(); - if(dst.slot < Arts::BACKPACK_START) + if(dst.slot < GameConstants::BACKPACK_START) assert(!dst.getArt()); a->move(src, dst); } -DLL_EXPORT void AssembledArtifact::applyGs( CGameState *gs ) +DLL_LINKAGE void AssembledArtifact::applyGs( CGameState *gs ) { CGHeroInstance *h = al.hero; const CArtifactInstance *transformedArt = al.getArt(); @@ -703,7 +698,7 @@ DLL_EXPORT void AssembledArtifact::applyGs( CGameState *gs ) combinedArt->putAt(h, al.slot); } -DLL_EXPORT void DisassembledArtifact::applyGs( CGameState *gs ) +DLL_LINKAGE void DisassembledArtifact::applyGs( CGameState *gs ) { CGHeroInstance *h = al.hero; CCombinedArtifactInstance *disassembled = dynamic_cast(al.getArt()); @@ -720,7 +715,7 @@ DLL_EXPORT void DisassembledArtifact::applyGs( CGameState *gs ) gs->map->eraseArtifactInstance(disassembled); } -DLL_EXPORT void HeroVisit::applyGs( CGameState *gs ) +DLL_LINKAGE void HeroVisit::applyGs( CGameState *gs ) { if(starting) gs->ongoingVisits[hero] = obj; @@ -728,7 +723,7 @@ DLL_EXPORT void HeroVisit::applyGs( CGameState *gs ) gs->ongoingVisits.erase(hero); } -DLL_EXPORT void SetAvailableArtifacts::applyGs( CGameState *gs ) +DLL_LINKAGE void SetAvailableArtifacts::applyGs( CGameState *gs ) { if(id >= 0) { @@ -747,7 +742,7 @@ DLL_EXPORT void SetAvailableArtifacts::applyGs( CGameState *gs ) } } -DLL_EXPORT void NewTurn::applyGs( CGameState *gs ) +DLL_LINKAGE void NewTurn::applyGs( CGameState *gs ) { gs->day = day; BOOST_FOREACH(NewTurn::Hero h, heroes) //give mana/movement point @@ -759,7 +754,7 @@ DLL_EXPORT void NewTurn::applyGs( CGameState *gs ) for(std::map::iterator i = res.begin(); i != res.end(); i++) { - assert(i->first < PLAYER_LIMIT); + assert(i->first < GameConstants::PLAYER_LIMIT); gs->getPlayer(i->first)->resources = i->second; } @@ -785,7 +780,7 @@ DLL_EXPORT void NewTurn::applyGs( CGameState *gs ) t->builded = 0; } -DLL_EXPORT void SetObjectProperty::applyGs( CGameState *gs ) +DLL_LINKAGE void SetObjectProperty::applyGs( CGameState *gs ) { CGObjectInstance *obj = gs->map->objects[id]; if(!obj) @@ -797,12 +792,12 @@ DLL_EXPORT void SetObjectProperty::applyGs( CGameState *gs ) CArmedInstance *cai = dynamic_cast(obj); if(what == ObjProperty::OWNER && cai) { - if(obj->ID == TOWNI_TYPE) + if(obj->ID == GameConstants::TOWNI_TYPE) { CGTownInstance *t = static_cast(obj); - if(t->tempOwner < PLAYER_LIMIT) + if(t->tempOwner < GameConstants::PLAYER_LIMIT) gs->getPlayer(t->tempOwner)->towns -= t; - if(val < PLAYER_LIMIT) + if(val < GameConstants::PLAYER_LIMIT) gs->getPlayer(val)->towns.push_back(t); } @@ -817,12 +812,12 @@ DLL_EXPORT void SetObjectProperty::applyGs( CGameState *gs ) } } -DLL_EXPORT void SetHoverName::applyGs( CGameState *gs ) +DLL_LINKAGE void SetHoverName::applyGs( CGameState *gs ) { name.toString(gs->map->objects[id]->hoverName); } -DLL_EXPORT void HeroLevelUp::applyGs( CGameState *gs ) +DLL_LINKAGE void HeroLevelUp::applyGs( CGameState *gs ) { CGHeroInstance* h = gs->getHero(heroid); h->level = level; @@ -830,36 +825,36 @@ DLL_EXPORT void HeroLevelUp::applyGs( CGameState *gs ) h->UpdateSpeciality(); } -DLL_EXPORT void BattleStart::applyGs( CGameState *gs ) +DLL_LINKAGE void BattleStart::applyGs( CGameState *gs ) { gs->curB = info; gs->curB->localInit(); } -DLL_EXPORT void BattleNextRound::applyGs( CGameState *gs ) +DLL_LINKAGE void BattleNextRound::applyGs( CGameState *gs ) { gs->curB->castSpells[0] = gs->curB->castSpells[1] = 0; for (int i = 0; i < 2; ++i) { - amax(--gs->curB->enchanterCounter[i], 0); + vstd::amax(--gs->curB->enchanterCounter[i], 0); } gs->curB->round = round; BOOST_FOREACH(CStack *s, gs->curB->stacks) { - s->state -= DEFENDING; - s->state -= WAITING; - s->state -= MOVED; - s->state -= HAD_MORALE; - s->state -= FEAR; + s->state -= EBattleStackState::DEFENDING; + s->state -= EBattleStackState::WAITING; + s->state -= EBattleStackState::MOVED; + s->state -= EBattleStackState::HAD_MORALE; + s->state -= EBattleStackState::FEAR; s->counterAttacks = 1 + s->valOfBonuses(Bonus::ADDITIONAL_RETALIATION); // new turn effects s->battleTurnPassed(); } } -DLL_EXPORT void BattleSetActiveStack::applyGs( CGameState *gs ) +DLL_LINKAGE void BattleSetActiveStack::applyGs( CGameState *gs ) { gs->curB->activeStack = stack; CStack *st = gs->curB->getStack(stack); @@ -867,24 +862,24 @@ DLL_EXPORT void BattleSetActiveStack::applyGs( CGameState *gs ) //remove bonuses that last until when stack gets new turn st->getBonusList().remove_if(Bonus::UntilGetsTurn); - if(vstd::contains(st->state,MOVED)) //if stack is moving second time this turn it must had a high morale bonus - st->state.insert(HAD_MORALE); + if(vstd::contains(st->state,EBattleStackState::MOVED)) //if stack is moving second time this turn it must had a high morale bonus + st->state.insert(EBattleStackState::HAD_MORALE); } -DLL_EXPORT void BattleTriggerEffect::applyGs( CGameState *gs ) +DLL_LINKAGE void BattleTriggerEffect::applyGs( CGameState *gs ) { CStack *st = gs->curB->getStack(stackID); switch (effect) { case Bonus::HP_REGENERATION: st->firstHPleft += val; - amin (st->firstHPleft, (ui32)st->MaxHealth()); + vstd::amin (st->firstHPleft, (ui32)st->MaxHealth()); break; case Bonus::MANA_DRAIN: { CGHeroInstance * h = gs->getHero(additionalInfo); h->mana -= val; - amax(h->mana, 0); + vstd::amax(h->mana, 0); break; } case Bonus::POISON: @@ -897,7 +892,7 @@ DLL_EXPORT void BattleTriggerEffect::applyGs( CGameState *gs ) case Bonus::ENCHANTER: break; case Bonus::FEAR: - st->state.insert(FEAR); + st->state.insert(EBattleStackState::FEAR); break; default: tlog2 << "Unrecognized trigger effect type "<< type <<"\n"; @@ -909,7 +904,7 @@ void BattleResult::applyGs( CGameState *gs ) //stack with SUMMONED flag but coming from garrison -> most likely resurrected, needs to be removed BOOST_FOREACH(CStack *s, gs->curB->stacks) { - if(s->base && s->base->armyObj && vstd::contains(s->state, SUMMONED)) + if(s->base && s->base->armyObj && vstd::contains(s->state, EBattleStackState::SUMMONED)) { assert(&s->base->armyObj->getStack(s->slot) == s->base); const_cast(s->base->armyObj)->eraseStack(s->slot); @@ -928,7 +923,7 @@ void BattleResult::applyGs( CGameState *gs ) if(h) h->getBonusList().remove_if(Bonus::OneBattle); - if (STACK_EXP) + if (GameConstants::STACK_EXP) { if (exp[0]) //checking local array is easier than dereferencing this crap twice gs->curB->belligerents[0]->giveStackExp(exp[0]); @@ -945,7 +940,7 @@ void BattleStackMoved::applyGs( CGameState *gs ) gs->curB->getStack(stack)->position = tilesToMove.back(); } -DLL_EXPORT void BattleStackAttacked::applyGs( CGameState *gs ) +DLL_LINKAGE void BattleStackAttacked::applyGs( CGameState *gs ) { CStack * at = gs->curB->getStack(stackAttacked); at->count = newAmount; @@ -953,7 +948,7 @@ DLL_EXPORT void BattleStackAttacked::applyGs( CGameState *gs ) if(killed()) { - at->state -= ALIVE; + at->state -= EBattleStackState::ALIVE; } //life drain handling for (int g=0; gcasts--; - at->state.insert(ALIVE); //hmm? + at->state.insert(EBattleStackState::ALIVE); //hmm? } } -DLL_EXPORT void BattleAttack::applyGs( CGameState *gs ) +DLL_LINKAGE void BattleAttack::applyGs( CGameState *gs ) { CStack *attacker = gs->curB->getStack(stackAttacking); if(counter()) @@ -1003,7 +998,7 @@ DLL_EXPORT void BattleAttack::applyGs( CGameState *gs ) } } -DLL_EXPORT void StartAction::applyGs( CGameState *gs ) +DLL_LINKAGE void StartAction::applyGs( CGameState *gs ) { CStack *st = gs->curB->getStack(ba.stackNumber); @@ -1025,23 +1020,23 @@ DLL_EXPORT void StartAction::applyGs( CGameState *gs ) switch(ba.actionType) { case BattleAction::DEFEND: - st->state.insert(DEFENDING); + st->state.insert(EBattleStackState::DEFENDING); break; case BattleAction::WAIT: - st->state.insert(WAITING); + st->state.insert(EBattleStackState::WAITING); return; case BattleAction::HERO_SPELL: //no change in current stack state return; default: //any active stack action - attack, catapult, heal, spell... - st->state.insert(MOVED); + st->state.insert(EBattleStackState::MOVED); break; } if(st) - st->state -= WAITING; //if stack was waiting it has made move, so it won't be "waiting" anymore (if the action was WAIT, then we have returned) + st->state -= EBattleStackState::WAITING; //if stack was waiting it has made move, so it won't be "waiting" anymore (if the action was WAIT, then we have returned) } -DLL_EXPORT void BattleSpellCast::applyGs( CGameState *gs ) +DLL_LINKAGE void BattleSpellCast::applyGs( CGameState *gs ) { assert(gs->curB); if (castedByHero) @@ -1050,7 +1045,7 @@ DLL_EXPORT void BattleSpellCast::applyGs( CGameState *gs ) CGHeroInstance * enemy = gs->curB->heroes[1-side]; h->mana -= spellCost; - amax(h->mana, 0); + vstd::amax(h->mana, 0); if (enemy && manaGained) enemy->mana += manaGained; if (side >= 0 && side < 2) @@ -1102,7 +1097,7 @@ void actualizeEffect(CStack * s, const Bonus & ef) } } -DLL_EXPORT void SetStackEffect::applyGs( CGameState *gs ) +DLL_LINKAGE void SetStackEffect::applyGs( CGameState *gs ) { int spellid = effect.begin()->sid; //effects' source ID @@ -1142,22 +1137,22 @@ DLL_EXPORT void SetStackEffect::applyGs( CGameState *gs ) } } -DLL_EXPORT void StacksInjured::applyGs( CGameState *gs ) +DLL_LINKAGE void StacksInjured::applyGs( CGameState *gs ) { BOOST_FOREACH(BattleStackAttacked stackAttacked, stacks) stackAttacked.applyGs(gs); } -DLL_EXPORT void StacksHealedOrResurrected::applyGs( CGameState *gs ) +DLL_LINKAGE void StacksHealedOrResurrected::applyGs( CGameState *gs ) { for(int g=0; gcurB->getStack(healedStacks[g].stackID, false); //checking if we resurrect a stack that is under a living stack - std::vector access = gs->curB->getAccessibility(changedStack, true); - bool acc[BFIELD_SIZE]; - for(int h=0; h access = gs->curB->getAccessibility(changedStack, true); + bool acc[GameConstants::BFIELD_SIZE]; + for(int h=0; halive(); //indicates if stack is resurrected or just healed if(resurrected) { - changedStack->state.insert(ALIVE); + changedStack->state.insert(EBattleStackState::ALIVE); if(healedStacks[g].lowLevelResurrection) - changedStack->state.insert(SUMMONED); //TODO: different counter for rised units + changedStack->state.insert(EBattleStackState::SUMMONED); //TODO: different counter for rised units } //int missingHPfirst = changedStack->MaxHealth() - changedStack->firstHPleft; int res = std::min( healedStacks[g].healedHP / changedStack->MaxHealth() , changedStack->baseAmount - changedStack->count ); @@ -1186,7 +1181,7 @@ DLL_EXPORT void StacksHealedOrResurrected::applyGs( CGameState *gs ) changedStack->count += 1; } } - amin(changedStack->firstHPleft, changedStack->MaxHealth()); + vstd::amin(changedStack->firstHPleft, changedStack->MaxHealth()); //removal of negative effects if(resurrected) { @@ -1215,7 +1210,7 @@ DLL_EXPORT void StacksHealedOrResurrected::applyGs( CGameState *gs ) } } -DLL_EXPORT void ObstaclesRemoved::applyGs( CGameState *gs ) +DLL_LINKAGE void ObstaclesRemoved::applyGs( CGameState *gs ) { if(gs->curB) //if there is a battle { @@ -1233,7 +1228,7 @@ DLL_EXPORT void ObstaclesRemoved::applyGs( CGameState *gs ) } } -DLL_EXPORT void CatapultAttack::applyGs( CGameState *gs ) +DLL_LINKAGE void CatapultAttack::applyGs( CGameState *gs ) { if(gs->curB && gs->curB->siege != 0) //if there is a battle and it's a siege { @@ -1245,7 +1240,7 @@ DLL_EXPORT void CatapultAttack::applyGs( CGameState *gs ) } } -DLL_EXPORT void BattleStacksRemoved::applyGs( CGameState *gs ) +DLL_LINKAGE void BattleStacksRemoved::applyGs( CGameState *gs ) { if(!gs->curB) return; @@ -1263,9 +1258,9 @@ DLL_EXPORT void BattleStacksRemoved::applyGs( CGameState *gs ) } } -DLL_EXPORT void BattleStackAdded::applyGs(CGameState *gs) +DLL_LINKAGE void BattleStackAdded::applyGs(CGameState *gs) { - if (!THex(pos).isValid()) + if (!SHexField(pos).isValid()) { tlog2 << "No place found for new stack!\n"; return; @@ -1274,13 +1269,13 @@ DLL_EXPORT void BattleStackAdded::applyGs(CGameState *gs) csi->setArmyObj(gs->curB->belligerents[attacker ? 0 : 1]); CStack * summonedStack = gs->curB->generateNewStack(*csi, gs->curB->stacks.size(), attacker, 255, pos); //TODO: netpacks? if (summoned) - summonedStack->state.insert(SUMMONED); + summonedStack->state.insert(EBattleStackState::SUMMONED); summonedStack->attachTo(csi); summonedStack->postInit(); gs->curB->stacks.push_back(summonedStack); //the stack is not "SUMMONED", it is permanent } -DLL_EXPORT void BattleSetStackProperty::applyGs(CGameState *gs) +DLL_LINKAGE void BattleSetStackProperty::applyGs(CGameState *gs) { CStack * stack = gs->curB->getStack(stackID); switch (which) @@ -1291,7 +1286,7 @@ DLL_EXPORT void BattleSetStackProperty::applyGs(CGameState *gs) stack->casts = val; else stack->casts += val; - amax(stack->casts, 0); + vstd::amax(stack->casts, 0); break; } case ENCHANTER_COUNTER: @@ -1301,7 +1296,7 @@ DLL_EXPORT void BattleSetStackProperty::applyGs(CGameState *gs) gs->curB->enchanterCounter[side] = val; else gs->curB->enchanterCounter[side] += val; - amax(gs->curB->enchanterCounter[side], 0); + vstd::amax(gs->curB->enchanterCounter[side], 0); break; } case UNBIND: @@ -1312,17 +1307,17 @@ DLL_EXPORT void BattleSetStackProperty::applyGs(CGameState *gs) } } -DLL_EXPORT void YourTurn::applyGs( CGameState *gs ) +DLL_LINKAGE void YourTurn::applyGs( CGameState *gs ) { gs->currentPlayer = player; } -DLL_EXPORT void SetSelection::applyGs( CGameState *gs ) +DLL_LINKAGE void SetSelection::applyGs( CGameState *gs ) { gs->getPlayer(player)->currentSelection = id; } -DLL_EXPORT Component::Component(const CStackBasicDescriptor &stack) +DLL_LINKAGE Component::Component(const CStackBasicDescriptor &stack) :id(CREATURE), subtype(stack.type->idNumber), val(stack.count), when(0) { diff --git a/lib/RegisterTypes.h b/lib/RegisterTypes.h index e282d2319..1d20a88e3 100644 --- a/lib/RegisterTypes.h +++ b/lib/RegisterTypes.h @@ -1,21 +1,13 @@ #pragma once -//templates for registering object types -//first set of types - derivatives of CGObjectInstance -template DLL_EXPORT -void registerTypes1(Serializer &s); - - -//second set of types - derivatives of CPack for client (network VCMI packages) -template DLL_EXPORT -void registerTypes2(Serializer &s); - -template DLL_EXPORT -void registerTypes3(Serializer &s); - -//register all -template DLL_EXPORT -void registerTypes(Serializer &s); +#include "Connection.h" +#include "NetPacks.h" +#include "VCMI_Lib.h" +#include "CArtHandler.h" +#include "CObjectHandler.h" +#include "CGameState.h" +#include "CHeroHandler.h" +#include "CTownHandler.h" /* * RegisterTypes.h, part of VCMI engine @@ -25,4 +17,222 @@ void registerTypes(Serializer &s); * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ \ No newline at end of file + */ + +template +void registerTypes1(Serializer &s) +{ + //map objects + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + //end of objects + s.template registerType(); + s.template registerType(); + + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); +} + +template +void registerTypes2(Serializer &s) +{ + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + //s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + //s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); +} + +template +void registerTypes3(Serializer &s) +{ + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); +} + +template +void registerTypes4(Serializer &s) +{ + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); + s.template registerType(); +} + +template +void registerTypes(Serializer &s) +{ + registerTypes1(s); + registerTypes2(s); + registerTypes3(s); + registerTypes4(s); +} \ No newline at end of file diff --git a/lib/ResourceSet.cpp b/lib/ResourceSet.cpp index b5cb6edc5..ffcb4f229 100644 --- a/lib/ResourceSet.cpp +++ b/lib/ResourceSet.cpp @@ -1,9 +1,10 @@ -#define VCMI_DLL +#include "StdInc.h" #include "ResourceSet.h" +#include "GameConstants.h" Res::ResourceSet::ResourceSet() { - resize(RESOURCE_QUANTITY, 0); + resize(GameConstants::RESOURCE_QUANTITY, 0); } bool Res::ResourceSet::nonZero() const @@ -18,7 +19,7 @@ bool Res::ResourceSet::nonZero() const void Res::ResourceSet::amax(const TResource &val) { for(int i = 0; i < size(); i++) - ::amax(at(i), val); + ::vstd::amax(at(i), val); } bool Res::ResourceSet::canBeAfforded(const ResourceSet &res) const @@ -33,8 +34,8 @@ bool Res::ResourceSet::canAfford(const ResourceSet &price) const bool Res::canAfford(const ResourceSet &res, const ResourceSet &price) { - assert(res.size() == price.size() && price.size() == RESOURCE_QUANTITY); - for(int i = 0; i < RESOURCE_QUANTITY; i++) + assert(res.size() == price.size() && price.size() == GameConstants::RESOURCE_QUANTITY); + for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; i++) if(price[i] > res[i]) return false; @@ -43,7 +44,7 @@ bool Res::canAfford(const ResourceSet &res, const ResourceSet &price) bool Res::ResourceSet::nziterator::valid() { - return cur.resType < RESOURCE_QUANTITY && cur.resVal; + return cur.resType < GameConstants::RESOURCE_QUANTITY && cur.resVal; } Res::ResourceSet::nziterator Res::ResourceSet::nziterator::operator++() @@ -74,9 +75,9 @@ void Res::ResourceSet::nziterator::advance() do { cur.resType++; - } while(cur.resType < RESOURCE_QUANTITY && !(cur.resVal=rs[cur.resType])); + } while(cur.resType < GameConstants::RESOURCE_QUANTITY && !(cur.resVal=rs[cur.resType])); - if(cur.resType >= RESOURCE_QUANTITY) + if(cur.resType >= GameConstants::RESOURCE_QUANTITY) cur.resVal = -1; } diff --git a/lib/ResourceSet.h b/lib/ResourceSet.h index a9cc49ff3..d6ad8d4ab 100644 --- a/lib/ResourceSet.h +++ b/lib/ResourceSet.h @@ -1,6 +1,6 @@ #pragma once -#include "../global.h" + #include typedef si32 TResource; @@ -19,11 +19,11 @@ namespace Res class ResourceSet : public std::vector { public: - DLL_EXPORT ResourceSet(); + DLL_LINKAGE ResourceSet(); #define scalarOperator(OPSIGN) \ - DLL_EXPORT ResourceSet operator OPSIGN(const TResource &rhs) const \ + DLL_LINKAGE ResourceSet operator OPSIGN(const TResource &rhs) const \ { \ ResourceSet ret = *this; \ for(int i = 0; i < size(); i++) \ @@ -35,7 +35,7 @@ namespace Res #define vectorOperator(OPSIGN) \ - DLL_EXPORT ResourceSet operator OPSIGN(const ResourceSet &rhs) const \ + DLL_LINKAGE ResourceSet operator OPSIGN(const ResourceSet &rhs) const \ { \ ResourceSet ret = *this; \ for(int i = 0; i < size(); i++) \ @@ -46,7 +46,7 @@ namespace Res #define opEqOperator(OPSIGN, RHS_TYPE) \ - DLL_EXPORT ResourceSet& operator OPSIGN ## =(const RHS_TYPE &rhs) \ + DLL_LINKAGE ResourceSet& operator OPSIGN ## =(const RHS_TYPE &rhs) \ { \ return *this = *this OPSIGN rhs; \ } @@ -68,12 +68,12 @@ namespace Res #undef opEqOperator //to be used for calculations of type "how many units of sth can I afford?" - DLL_EXPORT int operator/(const ResourceSet &rhs) + DLL_LINKAGE int operator/(const ResourceSet &rhs) { int ret = INT_MAX; for(int i = 0; i < size(); i++) if(rhs[i]) - amin(ret, at(i) / rhs[i]); + vstd::amin(ret, at(i) / rhs[i]); return ret; } @@ -94,13 +94,13 @@ namespace Res h & static_cast&>(*this); } - DLL_EXPORT void amax(const TResource &val); //performs amax on each element - DLL_EXPORT bool nonZero() const; //returns true if at least one value is non-zero; - DLL_EXPORT bool canAfford(const ResourceSet &price) const; - DLL_EXPORT bool canBeAfforded(const ResourceSet &res) const; + DLL_LINKAGE void amax(const TResource &val); //performs vstd::amax on each element + DLL_LINKAGE bool nonZero() const; //returns true if at least one value is non-zero; + DLL_LINKAGE bool canAfford(const ResourceSet &price) const; + DLL_LINKAGE bool canBeAfforded(const ResourceSet &res) const; //special iterator of iterating over non-zero resources in set - class DLL_EXPORT nziterator + class DLL_LINKAGE nziterator { struct ResEntry { diff --git a/lib/VCMIDirs.h b/lib/VCMIDirs.h index ffe45f9ee..e840fbd97 100644 --- a/lib/VCMIDirs.h +++ b/lib/VCMIDirs.h @@ -1,8 +1,9 @@ -#ifndef __VCMIDIRS_H__ -#define __VCMIDIRS_H__ +#pragma once + +#include "GameConstants.h" /* - * UserHome.h, part of VCMI engine + * VCMIDirs.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * @@ -25,7 +26,7 @@ public: VCMIDirs() { #ifdef _WIN32 - UserPath = DATA_DIR; + UserPath = GameConstants::DATA_DIR; #else try { #ifdef ANDROID @@ -52,5 +53,3 @@ public: } }; extern VCMIDirs GVCMIDirs; - -#endif // __VCMIDIRS_H__ diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index c7aa98012..5add0d34f 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -1,6 +1,7 @@ -#define VCMI_DLL -#include "../global.h" +#include "StdInc.h" #include "VCMI_Lib.h" + + #include "CArtHandler.h" #include "CCreatureHandler.h" #include "CDefObjInfoHandler.h" @@ -12,6 +13,7 @@ #include "CSpellHandler.h" #include "CGeneralTextHandler.h" #include "IGameEventsReceiver.h" +#include "StopWatch.h" /* * VCMI_Lib.cpp, part of VCMI engine @@ -25,23 +27,12 @@ class CLodHandler; LibClasses * VLC = NULL; -DLL_EXPORT CLodHandler *bitmaph = NULL, +DLL_LINKAGE CLodHandler *bitmaph = NULL, *spriteh = NULL, *bitmaph_ab = NULL; -DLL_EXPORT CLogger tlog0(0); -DLL_EXPORT CLogger tlog1(1); -DLL_EXPORT CLogger tlog2(2); -DLL_EXPORT CLogger tlog3(3); -DLL_EXPORT CLogger tlog4(4); -DLL_EXPORT CLogger tlog5(5); -DLL_EXPORT CLogger tlog6(-2); - -DLL_EXPORT CConsoleHandler *console = NULL; -DLL_EXPORT std::ostream *logfile = NULL -; -DLL_EXPORT void initDLL(CConsoleHandler *Console, std::ostream *Logfile) +DLL_LINKAGE void initDLL(CConsoleHandler *Console, std::ostream *Logfile) { console = Console; logfile = Logfile; @@ -49,10 +40,11 @@ DLL_EXPORT void initDLL(CConsoleHandler *Console, std::ostream *Logfile) try { VLC->init(); - } HANDLE_EXCEPTION; + } + HANDLE_EXCEPTION; } -DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, int mode) +DLL_LINKAGE void loadToIt(std::string &dest, const std::string &src, int &iter, int mode) { switch(mode) { @@ -160,7 +152,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i } -DLL_EXPORT void loadToIt(si32 &dest, const std::string &src, int &iter, int mode) +DLL_LINKAGE void loadToIt(si32 &dest, const std::string &src, int &iter, int mode) { std::string pom; loadToIt(pom,src,iter,mode); @@ -169,45 +161,45 @@ DLL_EXPORT void loadToIt(si32 &dest, const std::string &src, int &iter, int mode void LibClasses::init() { - timeHandler pomtime; + StopWatch pomtime; generaltexth = new CGeneralTextHandler; generaltexth->load(); - tlog0<<"\tGeneral text handler: "<loadHeroes(); heroh->loadObstacles(); heroh->loadPuzzleInfo(); - tlog0 <<"\tHero handler: "<loadArtifacts(false); - tlog0<<"\tArtifact handler: "<loadCreatures(); - tlog0<<"\tCreature handler: "<loadStructures(); - tlog0<<"\tTown handler: "<loadObjects(); - tlog0<<"\tObject handler: "<load(); - tlog0<<"\tDef information handler: "<loadBuildings(); - tlog0<<"\tBuilding handler: "<loadSpells(); - tlog0<<"\tSpell handler: "<init(DATA_DIR "/Data/H3sprite.lod", DATA_DIR "/Sprites"); + spriteh->init(GameConstants::DATA_DIR + "/Data/H3sprite.lod", GameConstants::DATA_DIR + "/Sprites"); bitmaph = new CLodHandler; - bitmaph->init(DATA_DIR "/Data/H3bitmap.lod", DATA_DIR "/Data"); + bitmaph->init(GameConstants::DATA_DIR + "/Data/H3bitmap.lod", GameConstants::DATA_DIR + "/Data"); bitmaph_ab = new CLodHandler(); - bitmaph_ab->init(DATA_DIR "/Data/H3ab_bmp.lod", DATA_DIR "/Data"); - tlog0<<"Loading .lod files: "<init(GameConstants::DATA_DIR + "/Data/H3ab_bmp.lod", GameConstants::DATA_DIR + "/Data"); + tlog0<<"Loading .lod files: "<false EnableFastChecks MultiThreadedDebugDLL - Level1 + Level3 EditAndContinue 4251;%(DisableSpecificWarnings) false NoListing false + Use + StdInc.h + $(IntDir)StdInc.h.pch + VCMI_DLL;%(PreprocessorDefinitions) zlib.lib;%(AdditionalDependencies) @@ -209,13 +213,12 @@ - - + @@ -225,30 +228,36 @@ + + - - + + + VCMI_DLL;%(PreprocessorDefinitions) + Create + StdInc.h + - + - + @@ -258,6 +267,7 @@ + @@ -266,16 +276,23 @@ + + + + + + + diff --git a/lib/map.cpp b/lib/map.cpp index d9c13ae08..92f65b962 100644 --- a/lib/map.cpp +++ b/lib/map.cpp @@ -1,6 +1,6 @@ -#define VCMI_DLL -#include "../stdafx.h" +#include "StdInc.h" #include "map.h" + #include "CObjectHandler.h" #include "CDefObjInfoHandler.h" #include "VCMI_Lib.h" @@ -9,12 +9,11 @@ #include "CLodHandler.h" #include "CArtHandler.h" #include "CCreatureHandler.h" -#include -#include #include "CSpellHandler.h" -#include #include "../lib/JsonNode.h" #include "vcmi_endian.h" +#include "GameConstants.h" +#include "StopWatch.h" /* * map.cpp, part of VCMI engine @@ -32,7 +31,7 @@ static std::set convertBuildings(const std::set h3m, int castleID, b std::set ret; // Note: this file is parsed many times. - const JsonNode config(DATA_DIR "/config/buildings5.json"); + const JsonNode config(GameConstants::DATA_DIR + "/config/buildings5.json"); BOOST_FOREACH(const JsonNode &entry, config["table"].Vector()) { @@ -46,7 +45,7 @@ static std::set convertBuildings(const std::set h3m, int castleID, b { if(mapa[*i]>=0) ret.insert(mapa[*i]); - else if(mapa[*i] >= (-CREATURES_PER_TOWN)) // horde buildings + else if(mapa[*i] >= (-GameConstants::CREATURES_PER_TOWN)) // horde buildings { int level = (mapa[*i]); ret.insert(level-30);//(-30)..(-36) - horde buildings (for game loading only), don't see other way to handle hordes in random towns @@ -73,16 +72,16 @@ static std::set convertBuildings(const std::set h3m, int castleID, b return ret; } -static unsigned int intPow(unsigned int a, unsigned int b) +static ui32 intPow(ui32 a, ui32 b) { - unsigned int ret=1; - for(unsigned int i=0; i>i) @@ -93,7 +92,7 @@ static unsigned char reverse(unsigned char arg) return ret; } -void readCreatureSet(CCreatureSet *out, const unsigned char * bufor, int &i, int number, bool version) //version==true for >RoE maps +void readCreatureSet(CCreatureSet *out, const ui8 * bufor, int &i, int number, bool version) //version==true for >RoE maps { const int bytesPerCre = version ? 4 : 3, maxID = version ? 0xffff : 0xff; @@ -135,7 +134,7 @@ void readCreatureSet(CCreatureSet *out, const unsigned char * bufor, int &i, int out->validTypes(true); } -CMapHeader::CMapHeader(const unsigned char *map) +CMapHeader::CMapHeader(const ui8 *map) { int i=0; initFromMemory(map,i); @@ -147,7 +146,7 @@ CMapHeader::CMapHeader() height = width = twoLevel = -1; } -void CMapHeader::initFromMemory( const unsigned char *bufor, int &i ) +void CMapHeader::initFromMemory( const ui8 *bufor, int &i ) { version = (Eformat)(read_le_u32(bufor + i)); i+=4; //map version if(version != RoE && version != AB && version != SoD && version != WoG) @@ -178,20 +177,20 @@ void CMapHeader::initFromMemory( const unsigned char *bufor, int &i ) } else//no alliances { - for(int i=0;iRoE) //probably reserved for further heroes @@ -201,7 +200,7 @@ void CMapHeader::initFromMemory( const unsigned char *bufor, int &i ) placeholdedHeroes.push_back(bufor[i++]); } } -void CMapHeader::loadPlayerInfo( int &pom, const unsigned char * bufor, int &i ) +void CMapHeader::loadPlayerInfo( int &pom, const ui8 * bufor, int &i ) { players.resize(8); for (pom=0;pom<8;pom++) @@ -288,22 +287,22 @@ void CMapHeader::loadPlayerInfo( int &pom, const unsigned char * bufor, int &i ) } } -void CMapHeader::loadViCLossConditions( const unsigned char * bufor, int &i) +void CMapHeader::loadViCLossConditions( const ui8 * bufor, int &i) { victoryCondition.obj = NULL; - victoryCondition.condition = (EvictoryConditions)bufor[i++]; - if (victoryCondition.condition != winStandard) //specific victory conditions + victoryCondition.condition = (EVictoryConditionType::EVictoryConditionType)bufor[i++]; + if (victoryCondition.condition != EVictoryConditionType::WINSTANDARD) //specific victory conditions { int nr; switch (victoryCondition.condition) //read victory conditions { - case artifact: + case EVictoryConditionType::ARTIFACT: { victoryCondition.ID = bufor[i+2]; nr=(version==RoE ? 1 : 2); break; } - case gatherTroop: + case EVictoryConditionType::GATHERTROOP: { // int temp1 = bufor[i+2]; // int temp2 = bufor[i+3]; @@ -312,14 +311,14 @@ void CMapHeader::loadViCLossConditions( const unsigned char * bufor, int &i) nr=(version==RoE ? 5 : 6); break; } - case gatherResource: + case EVictoryConditionType::GATHERRESOURCE: { victoryCondition.ID = bufor[i+2]; victoryCondition.count = read_le_u32(bufor + i+3); nr = 5; break; } - case buildCity: + case EVictoryConditionType::BUILDCITY: { victoryCondition.pos.x = bufor[i+2]; victoryCondition.pos.y = bufor[i+3]; @@ -329,7 +328,7 @@ void CMapHeader::loadViCLossConditions( const unsigned char * bufor, int &i) nr = 5; break; } - case buildGrail: + case EVictoryConditionType::BUILDGRAIL: { if (bufor[i+4]>2) victoryCondition.pos = int3(-1,-1,-1); @@ -342,9 +341,9 @@ void CMapHeader::loadViCLossConditions( const unsigned char * bufor, int &i) nr = 3; break; } - case beatHero: - case captureCity: - case beatMonster: + case EVictoryConditionType::BEATHERO: + case EVictoryConditionType::CAPTURECITY: + case EVictoryConditionType::BEATMONSTER: { victoryCondition.pos.x = bufor[i+2]; victoryCondition.pos.y = bufor[i+3]; @@ -352,13 +351,13 @@ void CMapHeader::loadViCLossConditions( const unsigned char * bufor, int &i) nr = 3; break; } - case takeDwellings: - case takeMines: + case EVictoryConditionType::TAKEDWELLINGS: + case EVictoryConditionType::TAKEMINES: { nr = 0; break; } - case transportItem: + case EVictoryConditionType::TRANSPORTITEM: { victoryCondition.ID = bufor[i+2]; victoryCondition.pos.x = bufor[i+3]; @@ -372,18 +371,18 @@ void CMapHeader::loadViCLossConditions( const unsigned char * bufor, int &i) victoryCondition.appliesToAI = bufor[i++]; i+=nr; } - lossCondition.typeOfLossCon = (ElossCon)bufor[i++]; + lossCondition.typeOfLossCon = (ELossConditionType::ELossConditionType)bufor[i++]; switch (lossCondition.typeOfLossCon) //read loss conditions { - case lossCastle: - case lossHero: + case ELossConditionType::LOSSCASTLE: + case ELossConditionType::LOSSHERO: { lossCondition.pos.x=bufor[i++]; lossCondition.pos.y=bufor[i++]; lossCondition.pos.z=bufor[i++]; break; } - case timeExpires: + case ELossConditionType::TIMEEXPIRES: { lossCondition.timeLimit = read_le_u16(bufor + i); i+=2; @@ -397,7 +396,7 @@ CMapHeader::~CMapHeader() } -void Mapa::initFromBytes(const unsigned char * bufor, size_t size) +void Mapa::initFromBytes(const ui8 * bufor, size_t size) { // Compute checksum boost::crc_32_type result; @@ -407,42 +406,42 @@ void Mapa::initFromBytes(const unsigned char * bufor, size_t size) int i=0; initFromMemory(bufor,i); - timeHandler th; - th.getDif(); + StopWatch th; + th.getDiff(); readHeader(bufor, i); - tlog0<<"\tReading header: "<defInfo) continue; addBlockVisTiles(objects[f]); } - tlog0<<"\tCalculating blocked/visitable tiles: "<subID == ID) return heroes[i]; return NULL; } -int Mapa::loadSeerHut( const unsigned char * bufor, int i, CGObjectInstance *& nobj ) +int Mapa::loadSeerHut( const ui8 * bufor, int i, CGObjectInstance *& nobj ) { CGSeerHut *hut = new CGSeerHut(); nobj = hut; @@ -581,7 +580,7 @@ int Mapa::loadSeerHut( const unsigned char * bufor, int i, CGObjectInstance *& n if(hut->missionType) { - unsigned char rewardType = bufor[i]; ++i; + ui8 rewardType = bufor[i]; ++i; hut->rewardType = rewardType; switch(rewardType) @@ -667,7 +666,7 @@ int Mapa::loadSeerHut( const unsigned char * bufor, int i, CGObjectInstance *& n return i; } -void Mapa::loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int &i, int subid) +void Mapa::loadTown( CGObjectInstance * &nobj, const ui8 * bufor, int &i, int subid) { CGTownInstance * nt = new CGTownInstance(); //(*(static_cast(nt))) = *nobj; @@ -717,12 +716,12 @@ void Mapa::loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int { for(; iobligatorySpells.push_back((i-ist)*8+yy); } } @@ -732,12 +731,12 @@ void Mapa::loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int ist = i; for(; ipossibleSpells.push_back((i-ist)*8+yy); } } @@ -805,7 +804,7 @@ void Mapa::loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int nt->garrisonHero = NULL; } -CGObjectInstance * Mapa::loadHero(const unsigned char * bufor, int &i, int idToBeGiven) +CGObjectInstance * Mapa::loadHero(const ui8 * bufor, int &i, int idToBeGiven) { CGHeroInstance * nhi = new CGHeroInstance(); @@ -819,7 +818,7 @@ CGObjectInstance * Mapa::loadHero(const unsigned char * bufor, int &i, int idToB ui8 owner = bufor[i++]; nhi->subID = bufor[i++]; - for(unsigned int j=0; jsubID == nhi->subID) { @@ -833,7 +832,7 @@ CGObjectInstance * Mapa::loadHero(const unsigned char * bufor, int &i, int idToB nhi->portrait = nhi->subID; - for(unsigned int j=0; jsubID) { @@ -904,12 +903,12 @@ CGObjectInstance * Mapa::loadHero(const unsigned char * bufor, int &i, int idToB int ist = i; for(; ispells.insert((i-ist)*8+yy); } } @@ -918,7 +917,7 @@ CGObjectInstance * Mapa::loadHero(const unsigned char * bufor, int &i, int idToB } else if(version==AB) //we can read one spell { - unsigned char buff = bufor[i]; ++i; + ui8 buff = bufor[i]; ++i; if(buff != 254) { nhi->spells.insert(0xffffffff); //placeholder "preset spells" @@ -940,7 +939,7 @@ CGObjectInstance * Mapa::loadHero(const unsigned char * bufor, int &i, int idToB return nhi; } -void Mapa::readRumors( const unsigned char * bufor, int &i) +void Mapa::readRumors( const ui8 * bufor, int &i) { int rumNr = read_le_u32(bufor + i);i+=4; for (int it=0;it=SoD) { @@ -979,8 +978,8 @@ void Mapa::readHeader( const unsigned char * bufor, int &i) i+=31; //omitting NULLS - allowedArtifact.resize(ARTIFACTS_QUANTITY); - for (unsigned int x=0; x=SoD) @@ -1027,10 +1026,10 @@ void Mapa::readHeader( const unsigned char * bufor, int &i) ist=i; //starting i for loop for(; iID = HEROI_TYPE; + cgh->ID = GameConstants::HEROI_TYPE; cgh->subID = z; if(readChar(bufor,i))//true if hore's experience is greater than 0 { cgh->exp = read_le_u32(bufor + i); i+=4; } @@ -1091,12 +1090,12 @@ void Mapa::readPredefinedHeroes( const unsigned char * bufor, int &i) int ist = i; for(; ispells.insert((i-ist)*8+yy); } } @@ -1117,7 +1116,7 @@ void Mapa::readPredefinedHeroes( const unsigned char * bufor, int &i) } } -void Mapa::readTerrain( const unsigned char * bufor, int &i) +void Mapa::readTerrain( const ui8 * bufor, int &i) { terrain = new TerrainTile**[width]; // allocate memory for (int ii=0;iiname.begin(),vinya->name.end(),vinya->name.begin(),(int(*)(int))toupper); - unsigned char bytes[12]; + ui8 bytes[12]; for (int v=0; v<12; v++) // read info { bytes[v] = bufor[i++]; @@ -1200,7 +1199,7 @@ void Mapa::readDefInfo( const unsigned char * bufor, int &i) vinya->visitMap[zi] = reverse(bytes[6+zi]); } i+=16; - if(vinya->id!=HEROI_TYPE && vinya->id!=70) + if(vinya->id!=GameConstants::HEROI_TYPE && vinya->id!=70) { CGDefInfo *h = VLC->dobjinfo->gobjs[vinya->id][vinya->subid]; if(!h) @@ -1221,7 +1220,7 @@ void Mapa::readDefInfo( const unsigned char * bufor, int &i) vinya->visitDir = 0xff; } - if(vinya->id == EVENTI_TYPE) + if(vinya->id == GameConstants::EVENTI_TYPE) std::memset(vinya->blockMap,255,6); //calculating coverageMap @@ -1246,7 +1245,7 @@ public: } }; -void Mapa::readObjects( const unsigned char * bufor, int &i) +void Mapa::readObjects( const ui8 * bufor, int &i) { int howManyObjs = read_le_u32(bufor + i); i+=4; for(int ww=0; wwid) { - case EVENTI_TYPE: //for event objects + case GameConstants::EVENTI_TYPE: //for event objects { CGEvent *evnt = new CGEvent(); nobj = evnt; @@ -1291,17 +1290,17 @@ void Mapa::readObjects( const unsigned char * bufor, int &i) } evnt->gainedExp = read_le_u32(bufor + i); i+=4; evnt->manaDiff = read_le_u32(bufor + i); i+=4; - evnt->moraleDiff = (si8)bufor[i]; ++i; - evnt->luckDiff = (si8)bufor[i]; ++i; + evnt->moraleDiff = (char)bufor[i]; ++i; + evnt->luckDiff = (char)bufor[i]; ++i; - evnt->resources.resize(RESOURCE_QUANTITY); + evnt->resources.resize(GameConstants::RESOURCE_QUANTITY); for(int x=0; x<7; x++) { evnt->resources[x] = read_le_u32(bufor + i); i+=4; } - evnt->primskills.resize(PRIMARY_SKILLS); + evnt->primskills.resize(GameConstants::PRIMARY_SKILLS); for(int x=0; x<4; x++) { evnt->primskills[x] = bufor[i]; @@ -1415,7 +1414,7 @@ void Mapa::readObjects( const unsigned char * bufor, int &i) if(isMesTre) { cre->message = readString(bufor,i); - cre->resources.resize(RESOURCE_QUANTITY); + cre->resources.resize(GameConstants::RESOURCE_QUANTITY); for(int j=0; j<7; j++) { cre->resources[j] = read_le_u32(bufor + i); i+=4; @@ -1473,12 +1472,12 @@ void Mapa::readObjects( const unsigned char * bufor, int &i) int ist=i; //starting i for loop for(; iallowedAbilities.push_back((i-ist)*8+yy); } } @@ -1486,7 +1485,7 @@ void Mapa::readObjects( const unsigned char * bufor, int &i) } else //(RoE map) { - for(int gg=0; ggallowedAbilities.push_back(gg); } @@ -1627,14 +1626,14 @@ void Mapa::readObjects( const unsigned char * bufor, int &i) box->moraleDiff = (si8)bufor[i]; ++i; box->luckDiff = (si8)bufor[i]; ++i; - box->resources.resize(RESOURCE_QUANTITY); + box->resources.resize(GameConstants::RESOURCE_QUANTITY); for(int x=0; x<7; x++) { box->resources[x] = read_le_u32(bufor + i); i+=4; } - box->primskills.resize(PRIMARY_SKILLS); + box->primskills.resize(GameConstants::PRIMARY_SKILLS); for(int x=0; x<4; x++) { box->primskills[x] = bufor[i]; @@ -1897,21 +1896,21 @@ void Mapa::readObjects( const unsigned char * bufor, int &i) nobj->pos = pos; nobj->ID = defInfo->id; nobj->id = idToBeGiven; - if(nobj->ID != HEROI_TYPE && nobj->ID != 214 && nobj->ID != 62) + if(nobj->ID != GameConstants::HEROI_TYPE && nobj->ID != 214 && nobj->ID != 62) nobj->subID = defInfo->subid; nobj->defInfo = defInfo; assert(idToBeGiven == objects.size()); objects.push_back(nobj); - if(nobj->ID==TOWNI_TYPE) + if(nobj->ID==GameConstants::TOWNI_TYPE) towns.push_back(static_cast(nobj)); - if(nobj->ID==HEROI_TYPE) + if(nobj->ID==GameConstants::HEROI_TYPE) heroes.push_back(static_cast(nobj)); } std::sort(heroes.begin(), heroes.end(), _HERO_SORTER()); } -void Mapa::readEvents( const unsigned char * bufor, int &i ) +void Mapa::readEvents( const ui8 * bufor, int &i ) { int numberOfEvents = read_le_u32(bufor + i); i+=4; for(int yyoo=0; yyoomissionType = bufor[i]; ++i; //int len1, len2, len3; @@ -2060,9 +2059,9 @@ const CGObjectInstance *Mapa::getObjectiveObjectFrom(int3 pos, bool lookForHero) { const std::vector &objs = getTile(pos).visitableObjects; assert(objs.size()); - if(objs.size() > 1 && lookForHero && objs.front()->ID != HEROI_TYPE) + if(objs.size() > 1 && lookForHero && objs.front()->ID != GameConstants::HEROI_TYPE) { - assert(objs.back()->ID == HEROI_TYPE); + assert(objs.back()->ID == GameConstants::HEROI_TYPE); return objs.back(); } else @@ -2072,10 +2071,10 @@ const CGObjectInstance *Mapa::getObjectiveObjectFrom(int3 pos, bool lookForHero) void Mapa::checkForObjectives() { if(isInTheMap(victoryCondition.pos)) - victoryCondition.obj = getObjectiveObjectFrom(victoryCondition.pos, victoryCondition.condition == beatHero); + victoryCondition.obj = getObjectiveObjectFrom(victoryCondition.pos, victoryCondition.condition == EVictoryConditionType::BEATHERO); if(isInTheMap(lossCondition.pos)) - lossCondition.obj = getObjectiveObjectFrom(lossCondition.pos, lossCondition.typeOfLossCon == lossHero); + lossCondition.obj = getObjectiveObjectFrom(lossCondition.pos, lossCondition.typeOfLossCon == ELossConditionType::LOSSHERO); } void Mapa::addNewArtifactInstance( CArtifactInstance *art ) @@ -2084,7 +2083,7 @@ void Mapa::addNewArtifactInstance( CArtifactInstance *art ) artInstances.push_back(art); } -bool Mapa::loadArtifactToSlot(CGHeroInstance *h, int slot, const unsigned char * bufor, int &i) +bool Mapa::loadArtifactToSlot(CGHeroInstance *h, int slot, const ui8 * bufor, int &i) { const int artmask = version == RoE ? 0xff : 0xffff; int aid; @@ -2101,16 +2100,16 @@ bool Mapa::loadArtifactToSlot(CGHeroInstance *h, int slot, const unsigned char * bool isArt = aid != artmask; if(isArt) { - if(vstd::contains(VLC->arth->bigArtifacts, aid) && slot >= Arts::BACKPACK_START) + if(vstd::contains(VLC->arth->bigArtifacts, aid) && slot >= GameConstants::BACKPACK_START) { tlog3 << "Warning: A big artifact (war machine) in hero's backpack, ignoring...\n"; return false; } - if(aid == 0 && slot == Arts::MISC5) + if(aid == 0 && slot == ArtifactPosition::MISC5) { //TODO: check how H3 handles it -> art 0 in slot 18 in AB map tlog3 << "Spellbook to MISC5 slot? Putting it spellbook place. AB format peculiarity ? (format " << (int)version << ")\n"; - slot = Arts::SPELLBOOK; + slot = ArtifactPosition::SPELLBOOK; } h->putArtifact(slot, createArt(aid)); @@ -2118,7 +2117,7 @@ bool Mapa::loadArtifactToSlot(CGHeroInstance *h, int slot, const unsigned char * return isArt; } -void Mapa::loadArtifactsOfHero(const unsigned char * bufor, int & i, CGHeroInstance * nhi) +void Mapa::loadArtifactsOfHero(const ui8 * bufor, int & i, CGHeroInstance * nhi) { bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts) if(artSet) @@ -2129,22 +2128,22 @@ void Mapa::loadArtifactsOfHero(const unsigned char * bufor, int & i, CGHeroInsta //misc5 art //17 if(version >= SoD) { - if(!loadArtifactToSlot(nhi, Arts::MACH4, bufor, i)) - nhi->putArtifact(Arts::MACH4, createArt(Arts::ID_CATAPULT)); //catapult by default + if(!loadArtifactToSlot(nhi, ArtifactPosition::MACH4, bufor, i)) + nhi->putArtifact(ArtifactPosition::MACH4, createArt(GameConstants::ID_CATAPULT)); //catapult by default } - loadArtifactToSlot(nhi, Arts::SPELLBOOK, bufor, i); + loadArtifactToSlot(nhi, ArtifactPosition::SPELLBOOK, bufor, i); //19 //???what is that? gap in file or what? - it's probably fifth slot.. if(version > RoE) - loadArtifactToSlot(nhi, Arts::MISC5, bufor, i); + loadArtifactToSlot(nhi, ArtifactPosition::MISC5, bufor, i); else i+=1; //bag artifacts //20 int amount = read_le_u16(bufor + i); i+=2; //number of artifacts in hero's bag for(int ss = 0; ss < amount; ++ss) - loadArtifactToSlot(nhi, Arts::BACKPACK_START + nhi->artifactsInBackpack.size(), bufor, i); + loadArtifactToSlot(nhi, GameConstants::BACKPACK_START + nhi->artifactsInBackpack.size(), bufor, i); } //artifacts } diff --git a/lib/map.h b/lib/map.h index 50f150239..629fb80e6 100644 --- a/lib/map.h +++ b/lib/map.h @@ -1,14 +1,6 @@ -#ifndef __MAP_H__ -#define __MAP_H__ -#ifdef _MSC_VER -#pragma warning (disable : 4482) -#endif -#include -#include -#include -#include -#include -#include "../global.h" +#pragma once + + #ifndef _MSC_VER #include "CObjectHandler.h" #include "CDefObjInfoHandler.h" @@ -16,6 +8,8 @@ #include "ConstTransitivePtr.h" #include "ResourceSet.h" +#include "int3.h" +#include "GameConstants.h" /* * map.h, part of VCMI engine @@ -37,19 +31,19 @@ class CGTownInstance; class IModableArt; /// Struct which describes a single terrain tile -struct DLL_EXPORT TerrainTile +struct DLL_LINKAGE TerrainTile { enum EterrainType {border=-1, dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock}; enum Eriver {noRiver=0, clearRiver, icyRiver, muddyRiver, lavaRiver}; enum Eroad {dirtRoad=1, grazvelRoad, cobblestoneRoad}; EterrainType tertype; // type of terrain - unsigned char terview; // look of terrain + ui8 terview; // look of terrain Eriver nuine; // type of Eriver (0 if there is no river) - unsigned char rivDir; // direction of Eriver + ui8 rivDir; // direction of Eriver Eroad malle; // type of Eroad (0 if there is no river) - unsigned char roadDir; // direction of Eroad - unsigned char siodmyTajemniczyBajt; //first two bits - how to rotate terrain graphic (next two - river graphic, next two - road); 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favourable Winds effect + ui8 roadDir; // direction of Eroad + ui8 siodmyTajemniczyBajt; //first two bits - how to rotate terrain graphic (next two - river graphic, next two - road); 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favourable Winds effect bool visitable; //false = not visitable; true = visitable bool blocked; //false = free; true = blocked; @@ -78,7 +72,7 @@ struct DLL_EXPORT TerrainTile }; /// name of starting hero -struct DLL_EXPORT SheroName +struct DLL_LINKAGE SheroName { int heroID; std::string heroName; @@ -91,7 +85,7 @@ struct DLL_EXPORT SheroName /// Player information regarding map. Which factions are allowed, AI tactic setting, main hero name, /// position of main town,... -struct DLL_EXPORT PlayerInfo +struct DLL_LINKAGE PlayerInfo { si32 p7, p8, p9; ui8 powerPlacehodlers; //q-ty of hero placeholders containing hero type, WARNING: powerPlacehodlers sometimes gives false 0 (eg. even if there is one placeholder), maybe different meaning??? @@ -117,7 +111,7 @@ struct DLL_EXPORT PlayerInfo si8 defaultCastle() const { si8 ret = -2; - for (int j = 0; j < F_NUMBER && ret != -1; j++) //we start with none and find matching faction. if more than one, then set to random + for (int j = 0; j < GameConstants::F_NUMBER && ret != -1; j++) //we start with none and find matching faction. if more than one, then set to random { if((1 << j) & allowedFactions) { @@ -148,9 +142,9 @@ struct DLL_EXPORT PlayerInfo }; /// Small struct which holds information about the loss condition -struct DLL_EXPORT LossCondition +struct DLL_LINKAGE LossCondition { - ElossCon typeOfLossCon; + ELossConditionType::ELossConditionType typeOfLossCon; int3 pos; @@ -167,9 +161,9 @@ struct DLL_EXPORT LossCondition }; /// Small struct which holds information about the victory condition -struct DLL_EXPORT CVictoryCondition +struct DLL_LINKAGE CVictoryCondition { - EvictoryConditions condition; //ID of condition + EVictoryConditionType::EVictoryConditionType condition; //ID of condition ui8 allowNormalVictory, appliesToAI; int3 pos; //pos of city to upgrade (3); pos of town to build grail, {-1,-1,-1} if not relevant (4); hero pos (5); town pos(6); monster pos (7); destination pos(8) @@ -187,7 +181,7 @@ struct DLL_EXPORT CVictoryCondition }; /// Struct which holds a name and the rumor text -struct DLL_EXPORT Rumor +struct DLL_LINKAGE Rumor { std::string name, text; @@ -198,7 +192,7 @@ struct DLL_EXPORT Rumor }; /// Struct which describes who can hire this hero -struct DLL_EXPORT DisposedHero +struct DLL_LINKAGE DisposedHero { ui32 ID; ui16 portrait; //0xFF - default @@ -212,7 +206,7 @@ struct DLL_EXPORT DisposedHero }; /// Class which manages map events. -class DLL_EXPORT CMapEvent +class DLL_LINKAGE CMapEvent { public: std::string name, message; @@ -240,7 +234,7 @@ public: /// Sub-class derived by CMapEvent; This event can build specific buildings or add /// additional creatures in a town. -class DLL_EXPORT CCastleEvent: public CMapEvent +class DLL_LINKAGE CCastleEvent: public CMapEvent { public: std::set buildings;//build specific buildings @@ -255,7 +249,7 @@ public: }; /// Holds information about loss/victory condition, map format, version, players, height, width,... -class DLL_EXPORT CMapHeader +class DLL_LINKAGE CMapHeader { public: enum Eformat {invalid, WoG=0x33, AB=0x15, RoE=0x0e, SoD=0x1c}; @@ -272,10 +266,10 @@ public: ui8 howManyTeams; std::vector allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed std::vector placeholdedHeroes; //ID of types of heroes in placeholders - void initFromMemory(const unsigned char *bufor, int &i); - void loadViCLossConditions( const unsigned char * bufor, int &i); - void loadPlayerInfo( int &pom, const unsigned char * bufor, int &i); - CMapHeader(const unsigned char *map); //an argument is a reference to string described a map (unpacked) + void initFromMemory(const ui8 *bufor, int &i); + void loadViCLossConditions( const ui8 * bufor, int &i); + void loadPlayerInfo( int &pom, const ui8 * bufor, int &i); + CMapHeader(const ui8 *map); //an argument is a reference to string described a map (unpacked) CMapHeader(); virtual ~CMapHeader(); @@ -289,7 +283,7 @@ public: /// Extends the base class and adds further map information like rumors, disposed heroes, /// allowed spells, artifacts, abilities and such things. -struct DLL_EXPORT Mapa : public CMapHeader +struct DLL_LINKAGE Mapa : public CMapHeader { ui32 checksum; TerrainTile*** terrain; @@ -314,21 +308,21 @@ struct DLL_EXPORT Mapa : public CMapHeader bmap questIdentifierToId; - void initFromBytes( const unsigned char * bufor, size_t size); //creates map from decompressed .h3m data + void initFromBytes( const ui8 * bufor, size_t size); //creates map from decompressed .h3m data - void readEvents( const unsigned char * bufor, int &i); - void readObjects( const unsigned char * bufor, int &i); - void loadQuest( CQuest * guard, const unsigned char * bufor, int & i); - void readDefInfo( const unsigned char * bufor, int &i); - void readTerrain( const unsigned char * bufor, int &i); - void readPredefinedHeroes( const unsigned char * bufor, int &i); - void readHeader( const unsigned char * bufor, int &i); - void readRumors( const unsigned char * bufor, int &i); - CGObjectInstance *loadHero(const unsigned char * bufor, int &i, int idToBeGiven); - void loadArtifactsOfHero(const unsigned char * bufor, int & i, CGHeroInstance * nhi); - bool loadArtifactToSlot(CGHeroInstance *h, int slot, const unsigned char * bufor, int &i); - void loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int &i, int subid); - int loadSeerHut( const unsigned char * bufor, int i, CGObjectInstance *& nobj); + void readEvents( const ui8 * bufor, int &i); + void readObjects( const ui8 * bufor, int &i); + void loadQuest( CQuest * guard, const ui8 * bufor, int & i); + void readDefInfo( const ui8 * bufor, int &i); + void readTerrain( const ui8 * bufor, int &i); + void readPredefinedHeroes( const ui8 * bufor, int &i); + void readHeader( const ui8 * bufor, int &i); + void readRumors( const ui8 * bufor, int &i); + CGObjectInstance *loadHero(const ui8 * bufor, int &i, int idToBeGiven); + void loadArtifactsOfHero(const ui8 * bufor, int & i, CGHeroInstance * nhi); + bool loadArtifactToSlot(CGHeroInstance *h, int slot, const ui8 * bufor, int &i); + void loadTown( CGObjectInstance * &nobj, const ui8 * bufor, int &i, int subid); + int loadSeerHut( const ui8 * bufor, int i, CGObjectInstance *& nobj); CArtifactInstance *createArt(int aid, int spellID = -1); void addNewArtifactInstance(CArtifactInstance *art); @@ -387,11 +381,11 @@ struct DLL_EXPORT Mapa : public CMapHeader // // if(h.saving) //create vector with all defs used on map // { -// for(unsigned int i=0; idefInfo->serial = -1; //set serial to serial -1 - indicates that def is not present in defs vector // -// for(unsigned int i=0; idefInfo; @@ -426,7 +420,7 @@ struct DLL_EXPORT Mapa : public CMapHeader h & CGObelisk::obeliskCount & CGObelisk::visited; h & CGTownInstance::merchantArtifacts; -// for(unsigned int i=0; iID == HEROI_TYPE) + if(objects[i]->ID == GameConstants::HEROI_TYPE) heroes.push_back(static_cast(+objects[i])); - else if(objects[i]->ID == TOWNI_TYPE) + else if(objects[i]->ID == GameConstants::TOWNI_TYPE) towns.push_back(static_cast(+objects[i])); addBlockVisTiles(objects[i]); //recreate blockvis map } - for(unsigned int i=0; ipos; vistile.x++; - for(unsigned int j=0; jpos) //hero stands on the town entrance { @@ -480,7 +474,7 @@ struct DLL_EXPORT Mapa : public CMapHeader const TerrainTile &t = getTile(vistile); if(t.tertype != TerrainTile::water) continue; //hero stands on the water - he must be in the boat - for(unsigned int j = 0; j < t.visitableObjects.size(); j++) + for(ui32 j = 0; j < t.visitableObjects.size(); j++) { if(t.visitableObjects[j]->ID == 8) { @@ -495,4 +489,3 @@ struct DLL_EXPORT Mapa : public CMapHeader } //!saving } }; -#endif // __MAP_H__ diff --git a/lib/vcmi_endian.h b/lib/vcmi_endian.h index 3df5ef692..1455b44ff 100644 --- a/lib/vcmi_endian.h +++ b/lib/vcmi_endian.h @@ -1,33 +1,45 @@ -#include - -/* Reading values from memory. - * - * read_le_u16, read_le_u32 : read a little endian value from - * memory. On big endian machines, the value will be byteswapped. - */ - -#if defined(linux) && defined(sparc) -/* SPARC does not support unaligned memory access. Let gcc know when - * to emit the right code. */ -struct unaligned_Uint16 { ui16 val __attribute__(( packed )); }; -struct unaligned_Uint32 { ui32 val __attribute__(( packed )); }; - -static inline ui16 read_unaligned_u16(const void *p) -{ - const struct unaligned_Uint16 *v = reinterpret_cast(p); - return v->val; -} - -static inline ui32 read_unaligned_u32(const void *p) -{ - const struct unaligned_Uint32 *v = reinterpret_cast(p); - return v->val; -} - -#define read_le_u16(p) (SDL_SwapLE16(read_unaligned_u16(p))) -#define read_le_u32(p) (SDL_SwapLE32(read_unaligned_u32(p))) - -#else -#define read_le_u16(p) (SDL_SwapLE16(* reinterpret_cast(p))) -#define read_le_u32(p) (SDL_SwapLE32(* reinterpret_cast(p))) -#endif +#pragma once + +#include + +/* + * vcmi_endian.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/* Reading values from memory. + * + * read_le_u16, read_le_u32 : read a little endian value from + * memory. On big endian machines, the value will be byteswapped. + */ + +#if defined(linux) && defined(sparc) +/* SPARC does not support unaligned memory access. Let gcc know when + * to emit the right code. */ +struct unaligned_Uint16 { ui16 val __attribute__(( packed )); }; +struct unaligned_Uint32 { ui32 val __attribute__(( packed )); }; + +static inline ui16 read_unaligned_u16(const void *p) +{ + const struct unaligned_Uint16 *v = reinterpret_cast(p); + return v->val; +} + +static inline ui32 read_unaligned_u32(const void *p) +{ + const struct unaligned_Uint32 *v = reinterpret_cast(p); + return v->val; +} + +#define read_le_u16(p) (SDL_SwapLE16(read_unaligned_u16(p))) +#define read_le_u32(p) (SDL_SwapLE32(read_unaligned_u32(p))) + +#else +#define read_le_u16(p) (SDL_SwapLE16(* reinterpret_cast(p))) +#define read_le_u32(p) (SDL_SwapLE32(* reinterpret_cast(p))) +#endif diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 945f08a6d..45e69cbbb 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1,7 +1,8 @@ -#include "stdafx.h" -#include "../int3.h" +#include "StdInc.h" + +#include "../lib/int3.h" #include "../lib/CCampaignHandler.h" -#include "../StartInfo.h" +#include "../lib/StartInfo.h" #include "../lib/CArtHandler.h" #include "../lib/CBuildingHandler.h" #include "../lib/CDefObjInfoHandler.h" @@ -24,6 +25,9 @@ #include #include #include "../lib/CCreatureSet.h" +#include "../lib/CThreadHelper.h" +#include "../lib/GameConstants.h" +#include "../lib/RegisterTypes.h" /* * CGameHandler.cpp, part of VCMI engine @@ -35,9 +39,7 @@ * */ -#undef DLL_EXPORT -#define DLL_EXPORT -#include "../lib/RegisterTypes.cpp" + #ifndef _MSC_VER #include #endif @@ -210,7 +212,7 @@ void CGameHandler::levelUpHero(int ID) tlog5 << hero->name <<" got level "<level<::*g = (hero->level>9) ? (&std::pair::second) : (&std::pair::first); - for(;xtype->heroClass->primChance[x].*g; if(r basicAndAdv, expert, none; - for(int i=0;itempOwnertempOwnertempOwner, &PlayerStatus::engagedIntoBattle, false); - if(bEndArmy2 && bEndArmy2->tempOwnertempOwnertempOwner, &PlayerStatus::engagedIntoBattle, false); } @@ -680,7 +682,7 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) tlog1 << "Ended handling connection\n"; } -int CGameHandler::moveStack(int stack, THex dest) +int CGameHandler::moveStack(int stack, SHexField dest) { int ret = 0; @@ -688,7 +690,7 @@ int CGameHandler::moveStack(int stack, THex dest) *stackAtEnd = gs->curB->getStackT(dest); assert(curStack); - assert(dest < BFIELD_SIZE); + assert(dest < GameConstants::BFIELD_SIZE); if (gs->curB->tacticDistance) { @@ -696,9 +698,9 @@ int CGameHandler::moveStack(int stack, THex dest) } //initing necessary tables - bool accessibility[BFIELD_SIZE]; - std::vector accessible = gs->curB->getAccessibility(curStack, false); - for(int b=0; b accessible = gs->curB->getAccessibility(curStack, false); + for(int b=0; battackerOwned) { if(accessibility[dest+1]) - dest += THex::RIGHT; + dest += SHexField::RIGHT; } else { if(accessibility[dest-1]) - dest += THex::LEFT; + dest += SHexField::LEFT; } } if((stackAtEnd && stackAtEnd!=curStack && stackAtEnd->alive()) || !accessibility[dest]) return 0; - bool accessibilityWithOccupyable[BFIELD_SIZE]; - std::vector accOc = gs->curB->getAccessibility(curStack, true); - for(int b=0; b accOc = gs->curB->getAccessibility(curStack, true); + for(int b=0; b curStack->creature->speed && !(stackAtEnd && dists[dest] == curStack->creature->speed+1)) //we can attack a stack if we can go to adjacent hex // return false; - std::pair< std::vector, int > path = gs->curB->getPath(curStack->position, dest, accessibilityWithOccupyable, curStack->hasBonusOfType(Bonus::FLYING), curStack->doubleWide(), curStack->attackerOwned); + std::pair< std::vector, int > path = gs->curB->getPath(curStack->position, dest, accessibilityWithOccupyable, curStack->hasBonusOfType(Bonus::FLYING), curStack->doubleWide(), curStack->attackerOwned); ret = path.second; - int creSpeed = gs->curB->tacticDistance ? BFIELD_SIZE : curStack->Speed(); + int creSpeed = gs->curB->tacticDistance ? GameConstants::BFIELD_SIZE : curStack->Speed(); if(curStack->hasBonusOfType(Bonus::FLYING)) { @@ -752,7 +754,7 @@ int CGameHandler::moveStack(int stack, THex dest) //inform clients about move BattleStackMoved sm; sm.stack = curStack->ID; - std::vector tiles; + std::vector tiles; tiles.push_back(path.first[0]); sm.tilesToMove = tiles; sm.distance = path.second; @@ -763,7 +765,7 @@ int CGameHandler::moveStack(int stack, THex dest) else //for non-flying creatures { // send one package with the creature path information - std::vector tiles; + std::vector tiles; int tilesToMove = std::max((int)(path.first.size() - creSpeed), 0); for(int v=path.first.size()-1; v>=tilesToMove; --v) { @@ -827,12 +829,12 @@ void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=fa return; } - if (forced || town->creatures[CREATURES_PER_TOWN].second.empty())//we need to change creature + if (forced || town->creatures[GameConstants::CREATURES_PER_TOWN].second.empty())//we need to change creature { SetAvailableCreatures ssi; ssi.tid = town->id; ssi.creatures = town->creatures; - ssi.creatures[CREATURES_PER_TOWN].second.clear();//remove old one + ssi.creatures[GameConstants::CREATURES_PER_TOWN].second.clear();//remove old one const std::vector > &dwellings = p->dwellings; if (dwellings.empty())//no dwellings - just remove @@ -846,10 +848,10 @@ void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=fa ui32 creature = dwellings[dwellpos]->creatures[creapos].second[0]; if (clear) - ssi.creatures[CREATURES_PER_TOWN].first = std::max((ui32)1, (VLC->creh->creatures[creature]->growth)/2); + ssi.creatures[GameConstants::CREATURES_PER_TOWN].first = std::max((ui32)1, (VLC->creh->creatures[creature]->growth)/2); else - ssi.creatures[CREATURES_PER_TOWN].first = VLC->creh->creatures[creature]->growth; - ssi.creatures[CREATURES_PER_TOWN].second.push_back(creature); + ssi.creatures[GameConstants::CREATURES_PER_TOWN].first = VLC->creh->creatures[creature]->growth; + ssi.creatures[GameConstants::CREATURES_PER_TOWN].second.push_back(creature); sendAndApply(&ssi); } } @@ -875,7 +877,7 @@ void CGameHandler::newTurn() bool deityOfFireBuilt = false; BOOST_FOREACH(const CGTownInstance *t, gs->map->towns) { - if(t->subID == 3 && vstd::contains(t->builtBuildings, Buildings::GRAIL)) + if(t->subID == 3 && vstd::contains(t->builtBuildings, EBuilding::GRAIL)) { deityOfFireBuilt = true; break; @@ -929,7 +931,7 @@ void CGameHandler::newTurn() { if(i->first == 255) continue; - else if(i->first >= PLAYER_LIMIT) + else if(i->first >= GameConstants::PLAYER_LIMIT) assert(0); //illegal player number! std::pair playerGold(i->first,i->second.resources[Res::GOLD]); @@ -942,7 +944,7 @@ void CGameHandler::newTurn() //pick heroes and their armies CHeroClass *banned = NULL; - for (int j = 0; j < AVAILABLE_HEROES_PER_PLAYER; j++) + for (int j = 0; j < GameConstants::AVAILABLE_HEROES_PER_PLAYER; j++) { if(CGHeroInstance *h = gs->hpool.pickHeroFor(j == 0, i->first, getNativeTown(i->first), pool, banned)) //first hero - native if possible, second hero -> any other class { @@ -979,7 +981,7 @@ void CGameHandler::newTurn() { n.res[i->first][Res::GOLD] += h->valOfBonuses(Selector::typeSubtype(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::ESTATES)); //estates - for (int k = 0; k < RESOURCE_QUANTITY; k++) + for (int k = 0; k < GameConstants::RESOURCE_QUANTITY; k++) { n.res[i->first][k] += h->valOfBonuses(Bonus::GENERATE_RESOURCE, k); } @@ -995,17 +997,17 @@ void CGameHandler::newTurn() handleTownEvents(t, n, newCreas); if(newWeek) //first day of week { - if(t->subID == 5 && vstd::contains(t->builtBuildings, Buildings::SPECIAL_3)) + if(t->subID == 5 && vstd::contains(t->builtBuildings, EBuilding::SPECIAL_3)) setPortalDwelling(t, true, (n.specialWeek == NewTurn::PLAGUE ? true : false)); //set creatures for Portal of Summoning if(!firstTurn) - if (t->subID == 1 && player < PLAYER_LIMIT && vstd::contains(t->builtBuildings, Buildings::SPECIAL_3))//dwarven treasury + if (t->subID == 1 && player < GameConstants::PLAYER_LIMIT && vstd::contains(t->builtBuildings, EBuilding::SPECIAL_3))//dwarven treasury n.res[player][Res::GOLD] += hadGold[player]/10; //give 10% of starting gold SetAvailableCreatures sac; sac.tid = t->id; sac.creatures = t->creatures; - for (int k=0; k < CREATURES_PER_TOWN; k++) //creature growths + for (int k=0; k < GameConstants::CREATURES_PER_TOWN; k++) //creature growths { if(t->creatureDwelling(k))//there is dwelling (k-level) { @@ -1041,9 +1043,9 @@ void CGameHandler::newTurn() n.cres.push_back(sac); } - if(!firstTurn && player < PLAYER_LIMIT)//not the first day and town not neutral + if(!firstTurn && player < GameConstants::PLAYER_LIMIT)//not the first day and town not neutral { - if(vstd::contains(t->builtBuildings, Buildings::RESOURCE_SILO)) //there is resource silo + if(vstd::contains(t->builtBuildings, EBuilding::RESOURCE_SILO)) //there is resource silo { if(t->town->primaryRes == 127) //we'll give wood and ore { @@ -1058,7 +1060,7 @@ void CGameHandler::newTurn() n.res[player][Res::GOLD] += t->dailyIncome(); } - if(vstd::contains(t->builtBuildings, Buildings::GRAIL) && t->subID == 2) + if(vstd::contains(t->builtBuildings, EBuilding::GRAIL) && t->subID == 2) { // Skyship, probably easier to handle same as Veil of darkness //do it every new day after veils apply @@ -1147,7 +1149,7 @@ void CGameHandler::newTurn() { for (std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) { - if(i->second.status || i->second.towns.size() || i->second.color >= PLAYER_LIMIT) + if(i->second.status || i->second.towns.size() || i->second.color >= GameConstants::PLAYER_LIMIT) continue; InfoWindow iw; @@ -1235,7 +1237,7 @@ void CGameHandler::run(bool resume) { if((i->second.towns.size()==0 && i->second.heroes.size()==0) || i->second.color<0 - || i->first>=PLAYER_LIMIT + || i->first>=GameConstants::PLAYER_LIMIT || i->second.status) { continue; @@ -1317,7 +1319,7 @@ void CGameHandler::giveSpells( const CGTownInstance *t, const CGHeroInstance *h cs.learn = true; for(int i=0; imageGuildLevel(),h->getSecSkillLevel(CGHeroInstance::WISDOM)+2);i++) { - if (t->subID == 8 && vstd::contains(t->builtBuildings, Buildings::GRAIL)) //Aurora Borealis + if (t->subID == 8 && vstd::contains(t->builtBuildings, EBuilding::GRAIL)) //Aurora Borealis { std::vector spells; getAllowedSpells(spells, i); @@ -1405,7 +1407,7 @@ bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255* //OR hero is on land and dest is water and (there is not present only one object - boat) if(((t.tertype == TerrainTile::rock || (t.blocked && !t.visitable && !h->hasBonusOfType(Bonus::FLYING_MOVEMENT) )) && complain("Cannot move hero, destination tile is blocked!")) - || ((!h->boat && !h->canWalkOnSea() && t.tertype == TerrainTile::water && (t.visitableObjects.size() < 1 || (t.visitableObjects.back()->ID != 8 && t.visitableObjects.back()->ID != HEROI_TYPE))) //hero is not on boat/water walking and dst water tile doesn't contain boat/hero (objs visitable from land) -> we test back cause boat may be on top of another object (#276) + || ((!h->boat && !h->canWalkOnSea() && t.tertype == TerrainTile::water && (t.visitableObjects.size() < 1 || (t.visitableObjects.back()->ID != 8 && t.visitableObjects.back()->ID != GameConstants::HEROI_TYPE))) //hero is not on boat/water walking and dst water tile doesn't contain boat/hero (objs visitable from land) -> we test back cause boat may be on top of another object (#276) && complain("Cannot move hero, destination tile is on water!")) || ((h->boat && t.tertype != TerrainTile::water && t.blocked) && complain("Cannot disembark hero, tile is blocked!")) @@ -1502,7 +1504,7 @@ bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255* { BOOST_FOREACH(CGObjectInstance* obj, t.blockingObjects) { - if(obj->ID==HEROI_TYPE) + if(obj->ID==GameConstants::HEROI_TYPE) { CGHeroInstance *dh = static_cast(obj); @@ -1533,9 +1535,9 @@ bool CGameHandler::teleportHero(si32 hid, si32 dstid, ui8 source, ui8 asker/* = const CGTownInstance *from = h->visitedTown; if(((h->getOwner() != t->getOwner()) && complain("Cannot teleport hero to another player")) - || ((!from || from->subID!=3 || !vstd::contains(from->builtBuildings, Buildings::SPECIAL_3)) + || ((!from || from->subID!=3 || !vstd::contains(from->builtBuildings, EBuilding::SPECIAL_3)) && complain("Hero must be in town with Castle gate for teleporting")) - || ((t->subID!=3 || !vstd::contains(t->builtBuildings, Buildings::SPECIAL_3)) + || ((t->subID!=3 || !vstd::contains(t->builtBuildings, EBuilding::SPECIAL_3)) && complain("Cannot teleport hero to town without Castle gate in it"))) return false; int3 pos = t->visitablePos(); @@ -1553,7 +1555,7 @@ void CGameHandler::setOwner(int objid, ui8 owner) sendAndApply(&sop); winLoseHandle(1<subID == 5 && vstd::contains(town->builtBuildings, 22)) @@ -1626,7 +1628,7 @@ void CGameHandler::giveCreatures(const CArmedInstance *obj, const CGHeroInstance COMPLAIN_RET_IF(!creatures.stacksCount(), "Strange, giveCreatures called without args!"); COMPLAIN_RET_IF(obj->stacksCount(), "Cannot give creatures from not-cleared object!"); - COMPLAIN_RET_IF(creatures.stacksCount() > ARMY_SIZE, "Too many stacks to give!"); + COMPLAIN_RET_IF(creatures.stacksCount() > GameConstants::ARMY_SIZE, "Too many stacks to give!"); //first we move creatures to give to make them army of object-source for (TSlots::const_iterator stack = creatures.Slots().begin(); stack != creatures.Slots().end(); stack++) @@ -1685,7 +1687,7 @@ void CGameHandler::heroVisitCastle(int obj, int heroID) vistiCastleObjects (getTown(obj), h); giveSpells (getTown(obj), getHero(heroID)); - if(gs->map->victoryCondition.condition == transportItem) + if(gs->map->victoryCondition.condition == EVictoryConditionType::TRANSPORTITEM) checkLossVictory(h->tempOwner); //transported artifact? } @@ -1716,7 +1718,7 @@ void CGameHandler::startBattleI(const CArmedInstance *army1, const CArmedInstanc engageIntoBattle(army1->tempOwner); engageIntoBattle(army2->tempOwner); //block engaged players - if(army2->tempOwner < PLAYER_LIMIT) + if(army2->tempOwner < GameConstants::PLAYER_LIMIT) states.setFlag(army2->tempOwner,&PlayerStatus::engagedIntoBattle,true); static const CArmedInstance *armies[2]; @@ -1732,8 +1734,8 @@ void CGameHandler::startBattleI(const CArmedInstance *army1, const CArmedInstanc void CGameHandler::startBattleI( const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, boost::function cb, bool creatureBank ) { startBattleI(army1, army2, tile, - army1->ID == HEROI_TYPE ? static_cast(army1) : NULL, - army2->ID == HEROI_TYPE ? static_cast(army2) : NULL, + army1->ID == GameConstants::HEROI_TYPE ? static_cast(army1) : NULL, + army2->ID == GameConstants::HEROI_TYPE ? static_cast(army2) : NULL, creatureBank, cb); } @@ -1944,7 +1946,7 @@ void CGameHandler::applyAndSend(CPackForClient * info) void CGameHandler::sendAndApply(CGarrisonOperationPack * info) { sendAndApply((CPackForClient*)info); - if(gs->map->victoryCondition.condition == gatherTroop) + if(gs->map->victoryCondition.condition == EVictoryConditionType::GATHERTROOP) winLoseHandle(); } @@ -1959,21 +1961,21 @@ void CGameHandler::sendAndApply(CGarrisonOperationPack * info) void CGameHandler::sendAndApply( SetResource * info ) { sendAndApply((CPackForClient*)info); - if(gs->map->victoryCondition.condition == gatherResource) + if(gs->map->victoryCondition.condition == EVictoryConditionType::GATHERRESOURCE) checkLossVictory(info->player); } void CGameHandler::sendAndApply( SetResources * info ) { sendAndApply((CPackForClient*)info); - if(gs->map->victoryCondition.condition == gatherResource) + if(gs->map->victoryCondition.condition == EVictoryConditionType::GATHERRESOURCE) checkLossVictory(info->player); } void CGameHandler::sendAndApply( NewStructures * info ) { sendAndApply((CPackForClient*)info); - if(gs->map->victoryCondition.condition == buildCity) + if(gs->map->victoryCondition.condition == EVictoryConditionType::BUILDCITY) checkLossVictory(getTown(info->tid)->tempOwner); } @@ -2280,7 +2282,7 @@ bool CGameHandler::recruitCreatures( si32 objid, ui32 crid, ui32 cram, si32 from //TODO: test for owning - if(dw->ID == TOWNI_TYPE) + if(dw->ID == GameConstants::TOWNI_TYPE) dst = (static_cast(dw))->getUpperArmy(); else if(dw->ID == 17 || dw->ID == 20 || dw->ID == 78) //advmap dwelling dst = getHero(gs->getPlayer(dw->tempOwner)->currentSelection); //TODO: check if current hero is really visiting dwelling @@ -2343,13 +2345,13 @@ bool CGameHandler::recruitCreatures( si32 objid, ui32 crid, ui32 cram, si32 from switch(crid) { case 146: - giveHeroNewArtifact(h, VLC->arth->artifacts[4], Arts::MACH1); + giveHeroNewArtifact(h, VLC->arth->artifacts[4], ArtifactPosition::MACH1); break; case 147: - giveHeroNewArtifact(h, VLC->arth->artifacts[6], Arts::MACH3); + giveHeroNewArtifact(h, VLC->arth->artifacts[6], ArtifactPosition::MACH3); break; case 148: - giveHeroNewArtifact(h, VLC->arth->artifacts[5], Arts::MACH2); + giveHeroNewArtifact(h, VLC->arth->artifacts[5], ArtifactPosition::MACH2); break; default: complain("This war machine cannot be recruited!"); @@ -2371,7 +2373,7 @@ bool CGameHandler::upgradeCreature( ui32 objid, ui8 pos, ui32 upgID ) int player = obj->tempOwner; const PlayerState *p = getPlayer(player); int crQuantity = obj->stacks[pos]->count; - int newIDpos= vstd::findPos(ui.newID, upgID);//get position of new id in UpgradeInfo + int newIDpos= vstd::find_pos(ui.newID, upgID);//get position of new id in UpgradeInfo TResources totalCost = ui.cost[newIDpos] * crQuantity; //check if upgrade is possible @@ -2515,26 +2517,26 @@ bool CGameHandler::moveArtifact(si32 srcHeroID, si32 destHeroID, ui16 srcSlot, u // Check if src/dest slots are appropriate for the artifacts exchanged. // Moving to the backpack is always allowed. - if ((!srcArtifact || destSlot < Arts::BACKPACK_START) + if ((!srcArtifact || destSlot < GameConstants::BACKPACK_START) && srcArtifact && !srcArtifact->canBePutAt(dst, true)) COMPLAIN_RET("Cannot move artifact!"); - if ((srcArtifact && srcArtifact->artType->id == Arts::ID_LOCK) || (destArtifact && destArtifact->artType->id == Arts::ID_LOCK)) + if ((srcArtifact && srcArtifact->artType->id == GameConstants::ID_LOCK) || (destArtifact && destArtifact->artType->id == GameConstants::ID_LOCK)) COMPLAIN_RET("Cannot move artifact locks."); - if (destSlot >= Arts::BACKPACK_START && srcArtifact->artType->isBig()) + if (destSlot >= GameConstants::BACKPACK_START && srcArtifact->artType->isBig()) COMPLAIN_RET("Cannot put big artifacts in backpack!"); - if (srcSlot == Arts::MACH4 || destSlot == Arts::MACH4) + if (srcSlot == ArtifactPosition::MACH4 || destSlot == ArtifactPosition::MACH4) COMPLAIN_RET("Cannot move catapult!"); - if(dst.slot >= Arts::BACKPACK_START) - amin(dst.slot, Arts::BACKPACK_START + dst.hero->artifactsInBackpack.size()); + if(dst.slot >= GameConstants::BACKPACK_START) + vstd::amin(dst.slot, GameConstants::BACKPACK_START + dst.hero->artifactsInBackpack.size()); if (src.slot == dst.slot && src.hero == dst.hero) COMPLAIN_RET("Won't move artifact: Dest same as source!"); //moving art to backpack is always allowed (we've ruled out exceptions) - if(destSlot >= Arts::BACKPACK_START) + if(destSlot >= GameConstants::BACKPACK_START) { moveArtifact(src, dst); } @@ -2542,7 +2544,7 @@ bool CGameHandler::moveArtifact(si32 srcHeroID, si32 destHeroID, ui16 srcSlot, u { if(destArtifact) //old artifact must be removed first { - moveArtifact(dst, ArtifactLocation(destHero, destHero->artifactsInBackpack.size() + Arts::BACKPACK_START)); + moveArtifact(dst, ArtifactLocation(destHero, destHero->artifactsInBackpack.size() + GameConstants::BACKPACK_START)); } moveArtifact(src, dst); } @@ -2599,15 +2601,15 @@ bool CGameHandler::buyArtifact( ui32 hid, si32 aid ) CGTownInstance *town = hero->visitedTown; if(aid==0) //spellbook { - if((!vstd::contains(town->builtBuildings,si32(Buildings::MAGES_GUILD_1)) && complain("Cannot buy a spellbook, no mage guild in the town!")) - || (getResource(hero->getOwner(), Res::GOLD) < SPELLBOOK_GOLD_COST && complain("Cannot buy a spellbook, not enough gold!") ) - || (hero->getArt(Arts::SPELLBOOK) && complain("Cannot buy a spellbook, hero already has a one!")) + if((!vstd::contains(town->builtBuildings,si32(EBuilding::MAGES_GUILD_1)) && complain("Cannot buy a spellbook, no mage guild in the town!")) + || (getResource(hero->getOwner(), Res::GOLD) < GameConstants::SPELLBOOK_GOLD_COST && complain("Cannot buy a spellbook, not enough gold!") ) + || (hero->getArt(ArtifactPosition::SPELLBOOK) && complain("Cannot buy a spellbook, hero already has a one!")) ) return false; - giveResource(hero->getOwner(),Res::GOLD,-SPELLBOOK_GOLD_COST); - giveHeroNewArtifact(hero, VLC->arth->artifacts[0], Arts::SPELLBOOK); - assert(hero->getArt(Arts::SPELLBOOK)); + giveResource(hero->getOwner(),Res::GOLD,-GameConstants::SPELLBOOK_GOLD_COST); + giveHeroNewArtifact(hero, VLC->arth->artifacts[0], ArtifactPosition::SPELLBOOK); + assert(hero->getArt(ArtifactPosition::SPELLBOOK)); giveSpells(town,hero); return true; } @@ -2615,9 +2617,9 @@ bool CGameHandler::buyArtifact( ui32 hid, si32 aid ) { int price = VLC->arth->artifacts[aid]->price; if((hero->getArt(9+aid) && complain("Hero already has this machine!")) - || (!vstd::contains(town->builtBuildings,si32(Buildings::BLACKSMITH)) && complain("No blackismith!")) + || (!vstd::contains(town->builtBuildings,si32(EBuilding::BLACKSMITH)) && complain("No blackismith!")) || (gs->getPlayer(hero->getOwner())->resources[Res::GOLD] < price && complain("Not enough gold!")) //no gold - || ((!(town->subID == 6 && vstd::contains(town->builtBuildings,si32(Buildings::SPECIAL_3) ) ) + || ((!(town->subID == 6 && vstd::contains(town->builtBuildings,si32(EBuilding::SPECIAL_3) ) ) && town->town->warMachine!= aid ) && complain("This machine is unavailable here!"))) { return false; @@ -2632,11 +2634,11 @@ bool CGameHandler::buyArtifact( ui32 hid, si32 aid ) bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, int rid, int aid) { - if(!vstd::contains(m->availableItemsIds(RESOURCE_ARTIFACT), aid)) + if(!vstd::contains(m->availableItemsIds(EMarketMode::RESOURCE_ARTIFACT), aid)) COMPLAIN_RET("That artifact is unavailable!"); int b1, b2; - m->getOffer(rid, aid, b1, b2, RESOURCE_ARTIFACT); + m->getOffer(rid, aid, b1, b2, EMarketMode::RESOURCE_ARTIFACT); if(getResource(h->tempOwner, rid) < b1) COMPLAIN_RET("You can't afford to buy this artifact!"); @@ -2649,7 +2651,7 @@ bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, int ri SetAvailableArtifacts saa; - if(m->o->ID == TOWNI_TYPE) + if(m->o->ID == GameConstants::TOWNI_TYPE) { saa.id = -1; saa.arts = CGTownInstance::merchantArtifacts; @@ -2691,7 +2693,7 @@ bool CGameHandler::sellArtifact(const IMarket *m, const CGHeroInstance *h, int a COMPLAIN_RET("Cannot sell a war machine or spellbook!"); int resVal = 0, dump = 1; - m->getOffer(art->artType->id, rid, dump, resVal, ARTIFACT_RESOURCE); + m->getOffer(art->artType->id, rid, dump, resVal, EMarketMode::ARTIFACT_RESOURCE); removeArtifact(ArtifactLocation(h, h->getArtPos(art))); giveResource(h->tempOwner, rid, resVal); @@ -2706,13 +2708,13 @@ bool CGameHandler::buySecSkill( const IMarket *m, const CGHeroInstance *h, int s if (h->getSecSkillLevel(static_cast(skill))) COMPLAIN_RET("Hero already know this skill"); - if (h->secSkills.size() >= SKILL_PER_HERO)//can't learn more skills + if (h->secSkills.size() >= GameConstants::SKILL_PER_HERO)//can't learn more skills COMPLAIN_RET("Hero can't learn any more skills"); if (h->type->heroClass->proSec[skill]==0)//can't learn this skill (like necromancy for most of non-necros) COMPLAIN_RET("The hero can't learn this skill!"); - if(!vstd::contains(m->availableItemsIds(RESOURCE_SKILL), skill)) + if(!vstd::contains(m->availableItemsIds(EMarketMode::RESOURCE_SKILL), skill)) COMPLAIN_RET("That skill is unavailable!"); if(getResource(h->tempOwner, Res::GOLD) < 2000)//TODO: remove hardcoded resource\summ? @@ -2733,10 +2735,10 @@ bool CGameHandler::tradeResources(const IMarket *market, ui32 val, ui8 player, u int r1 = gs->getPlayer(player)->resources[id1], r2 = gs->getPlayer(player)->resources[id2]; - amin(val, r1); //can't trade more resources than have + vstd::amin(val, r1); //can't trade more resources than have int b1, b2; //base quantities for trade - market->getOffer(id1, id2, b1, b2, RESOURCE_RESOURCE); + market->getOffer(id1, id2, b1, b2, EMarketMode::RESOURCE_RESOURCE); int units = val / b1; //how many base quantities we trade if(val%b1) //all offered units of resource should be used, if not -> somewhere in calculations must be an error @@ -2772,7 +2774,7 @@ bool CGameHandler::sellCreatures(ui32 count, const IMarket *market, const CGHero } int b1, b2; //base quantities for trade - market->getOffer(s.type->idNumber, resourceID, b1, b2, CREATURE_RESOURCE); + market->getOffer(s.type->idNumber, resourceID, b1, b2, EMarketMode::CREATURE_RESOURCE); int units = count / b1; //how many base quantities we trade if(count%b1) //all offered units of resource should be used, if not -> somewhere in calculations must be an error @@ -2861,7 +2863,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, ui8 player) if(t) //tavern in town { - if( (!vstd::contains(t->builtBuildings,Buildings::TAVERN) && complain("No tavern!")) + if( (!vstd::contains(t->builtBuildings,EBuilding::TAVERN) && complain("No tavern!")) || (t->visitingHero && complain("There is visiting hero - no place!"))) return false; } @@ -3166,7 +3168,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) attack.second = 0; int chanceForHit = 0; - int dmgChance[3] = {sbi.noDmg, sbi.oneDmg, sbi.twoDmg}; //dmgChance[i] - chance for doing i dmg when hit is successful + int dmgChance[] = { sbi.noDmg, sbi.oneDmg, sbi.twoDmg }; //dmgChance[i] - chance for doing i dmg when hit is successful switch(attackedPart) { case 0: //keep @@ -3328,21 +3330,21 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) CStack * stack = gs->curB->getStack(ba.stackNumber); int spellID = ba.additionalInfo; - THex destination(ba.destinationTile); + SHexField destination(ba.destinationTile); int spellLvl = 0; Bonus * bonus = stack->getBonus(Selector::typeSubtype(Bonus::SPELLCASTER, spellID)); if (bonus) - amax(spellLvl, bonus->val); + vstd::amax(spellLvl, bonus->val); bonus = stack->getBonus(Selector::type(Bonus::RANDOM_SPELLCASTER)); if (bonus) - amax(spellLvl, bonus->val); - amin (spellLvl, 3); + vstd::amax(spellLvl, bonus->val); + vstd::amin (spellLvl, 3); int casterSide = gs->curB->whatSide(stack->owner); const CGHeroInstance * secHero = gs->curB->getHero(gs->curB->theOtherPlayer(stack->owner)); - handleSpellCasting(spellID, spellLvl, destination, casterSide, stack->owner, NULL, secHero, 0, SpellCasting::CREATURE_ACTIVE_CASTING, stack); + handleSpellCasting(spellID, spellLvl, destination, casterSide, stack->owner, NULL, secHero, 0, ECastingMode::CREATURE_ACTIVE_CASTING, stack); sendAndApply(&end_action); break; @@ -3381,7 +3383,7 @@ void CGameHandler::playerMessage( ui8 player, const std::string &message ) sm.val = 999; if(!h->hasSpellbook()) //hero doesn't have spellbook - giveHeroNewArtifact(h, VLC->arth->artifacts[0], Arts::SPELLBOOK); //give spellbook + giveHeroNewArtifact(h, VLC->arth->artifacts[0], ArtifactPosition::SPELLBOOK); //give spellbook sendAndApply(&cs); sendAndApply(&sm); @@ -3392,7 +3394,7 @@ void CGameHandler::playerMessage( ui8 player, const std::string &message ) const CCreature *archangel = VLC->creh->creatures[13]; if(!hero) return; - for(int i = 0; i < ARMY_SIZE; i++) + for(int i = 0; i < GameConstants::ARMY_SIZE; i++) if(!hero->hasStackAtSlot(i)) insertNewStack(StackLocation(hero, i), archangel, 5); } @@ -3402,7 +3404,7 @@ void CGameHandler::playerMessage( ui8 player, const std::string &message ) const CCreature *blackKnight = VLC->creh->creatures[66]; if(!hero) return; - for(int i = 0; i < ARMY_SIZE; i++) + for(int i = 0; i < GameConstants::ARMY_SIZE; i++) if(!hero->hasStackAtSlot(i)) insertNewStack(StackLocation(hero, i), blackKnight, 10); } @@ -3411,12 +3413,12 @@ void CGameHandler::playerMessage( ui8 player, const std::string &message ) CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); if(!hero) return; - if(!hero->getArt(Arts::MACH1)) - giveHeroNewArtifact(hero, VLC->arth->artifacts[4], Arts::MACH1); - if(!hero->getArt(Arts::MACH2)) - giveHeroNewArtifact(hero, VLC->arth->artifacts[5], Arts::MACH2); - if(!hero->getArt(Arts::MACH3)) - giveHeroNewArtifact(hero, VLC->arth->artifacts[6], Arts::MACH3); + if(!hero->getArt(ArtifactPosition::MACH1)) + giveHeroNewArtifact(hero, VLC->arth->artifacts[4], ArtifactPosition::MACH1); + if(!hero->getArt(ArtifactPosition::MACH2)) + giveHeroNewArtifact(hero, VLC->arth->artifacts[5], ArtifactPosition::MACH2); + if(!hero->getArt(ArtifactPosition::MACH3)) + giveHeroNewArtifact(hero, VLC->arth->artifacts[6], ArtifactPosition::MACH3); } else if(message == "vcminahar") //1000000 movement points { @@ -3484,7 +3486,7 @@ void CGameHandler::playerMessage( ui8 player, const std::string &message ) } } -void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, SpellCasting::ECastingMode mode, const CStack * stack) +void CGameHandler::handleSpellCasting( int spellID, int spellLvl, SHexField destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack) { const CSpell *spell = VLC->spellh->spells[spellID]; @@ -3503,14 +3505,14 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati { sc.spellCost = gs->curB->getSpellCost(VLC->spellh->spells[spellID], caster); - if (secHero && mode == SpellCasting::HERO_CASTING) //handle mana channel + if (secHero && mode == ECastingMode::HERO_CASTING) //handle mana channel { int manaChannel = 0; BOOST_FOREACH(CStack * stack, gs->curB->stacks) //TODO: shouldn't bonus system handle it somehow? { if (stack->owner == secHero->tempOwner) { - amax(manaChannel, stack->valOfBonuses(Bonus::MANA_CHANNELING)); + vstd::amax(manaChannel, stack->valOfBonuses(Bonus::MANA_CHANNELING)); } } sc.manaGained = (manaChannel * sc.spellCost) / 100; @@ -3519,7 +3521,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati //calculating affected creatures for all spells std::set attackedCres; - if (mode != SpellCasting::ENCHANTER_CASTING) + if (mode != ECastingMode::ENCHANTER_CASTING) { attackedCres = gs->curB->getAttackedCreatures(spell, spellLvl, casterColor, destination); for(std::set::const_iterator it = attackedCres.begin(); it != attackedCres.end(); ++it) @@ -3555,7 +3557,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati { sc.dmgToDisplay = usedSpellPower; if (spellID == Spells::DEATH_STARE) - amin(sc.dmgToDisplay, (*attackedCres.begin())->count); //stack is already reduced after attack + vstd::amin(sc.dmgToDisplay, (*attackedCres.begin())->count); //stack is already reduced after attack } StacksInjured si; @@ -3577,7 +3579,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati case Spells::THUNDERBOLT: //(thunderbirds) { int spellDamage = 0; - if (stack && mode != SpellCasting::MAGIC_MIRROR) + if (stack && mode != ECastingMode::MAGIC_MIRROR) { int unitSpellPower = stack->valOfBonuses(Bonus::SPECIFIC_SPELL_POWER, spellID); if (unitSpellPower) @@ -3653,7 +3655,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati case Spells::ACID_BREATH_DEFENSE: { int stackSpellPower = 0; - if (stack && mode != SpellCasting::MAGIC_MIRROR) + if (stack && mode != ECastingMode::MAGIC_MIRROR) { stackSpellPower = stack->valOfBonuses(Bonus::CREATURE_ENCHANT_POWER); } @@ -3735,7 +3737,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati BattleStackMoved bsm; bsm.distance = -1; bsm.stack = gs->curB->activeStack; - std::vector tiles; + std::vector tiles; tiles.push_back(destination); bsm.tilesToMove = tiles; bsm.teleporting = true; @@ -3811,7 +3813,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati bsa.pos = gs->curB->getAvaliableHex(creID, !(bool)casterSide); //TODO: unify it bsa.amount = caster->getPrimSkillLevel(2) * VLC->spellh->spells[spellID]->powers[spellLvl] * - (100 + caster->valOfBonuses(Bonus::SPECIFIC_SPELL_DAMAGE, spellID)) / 100.0f; //new feature - percentage bonus + (100 + caster->valOfBonuses(Bonus::SPECIFIC_SPELL_DAMAGE, spellID)) / 100.0; //new feature - percentage bonus bsa.creID = creID; bsa.attacker = !(bool)casterSide; @@ -3824,7 +3826,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati ObstaclesRemoved obr; for(int g=0; gcurB->obstacles.size(); ++g) { - std::vector blockedHexes = VLC->heroh->obstacles[gs->curB->obstacles[g].ID].getBlocked(gs->curB->obstacles[g].pos); + std::vector blockedHexes = VLC->heroh->obstacles[gs->curB->obstacles[g].ID].getBlocked(gs->curB->obstacles[g].pos); if(vstd::contains(blockedHexes, destination)) //this obstacle covers given hex { @@ -3878,7 +3880,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati if(!si.stacks.empty()) //after spellcast info shows sendAndApply(&si); - if (mode == SpellCasting::CREATURE_ACTIVE_CASTING || mode == SpellCasting::ENCHANTER_CASTING) //reduce number of casts remaining + if (mode == ECastingMode::CREATURE_ACTIVE_CASTING || mode == ECastingMode::ENCHANTER_CASTING) //reduce number of casts remaining { BattleSetStackProperty ssp; ssp.stackID = stack->ID; @@ -3889,7 +3891,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati } //Magic Mirror effect - if (spell->positiveness < 0 && mode != SpellCasting::MAGIC_MIRROR && spell->level && spell->range[0] == "0") //it is actual spell and can be reflected to single target, no recurrence + if (spell->positiveness < 0 && mode != ECastingMode::MAGIC_MIRROR && spell->level && spell->range[0] == "0") //it is actual spell and can be reflected to single target, no recurrence { for(std::set::iterator it = attackedCres.begin(); it != attackedCres.end(); ++it) { @@ -3902,14 +3904,14 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati { if(battleStacks[j]->owner == casterSide) //get enemy stacks which can be affected by this spell { - if (!gs->curB->battleIsImmune(NULL, spell, SpellCasting::MAGIC_MIRROR, battleStacks[j]->position)) + if (!gs->curB->battleIsImmune(NULL, spell, ECastingMode::MAGIC_MIRROR, battleStacks[j]->position)) mirrorTargets.push_back(battleStacks[j]); } } if (mirrorTargets.size()) { int targetHex = mirrorTargets[rand() % mirrorTargets.size()]->position; - handleSpellCasting(spellID, 0, targetHex, 1 - casterSide, (*it)->owner, NULL, (caster ? caster : NULL), usedSpellPower, SpellCasting::MAGIC_MIRROR, (*it)); + handleSpellCasting(spellID, 0, targetHex, 1 - casterSide, (*it)->owner, NULL, (caster ? caster : NULL), usedSpellPower, ECastingMode::MAGIC_MIRROR, (*it)); } } } @@ -3941,8 +3943,8 @@ bool CGameHandler::makeCustomAction( BattleAction &ba ) { ui8 skill = h->getSpellSchoolLevel(s); //skill level - SpellCasting::ESpellCastProblem escp = gs->curB->battleCanCastThisSpell(h->tempOwner, s, SpellCasting::HERO_CASTING); - if(escp != SpellCasting::OK) + ESpellCastProblem::ESpellCastProblem escp = gs->curB->battleCanCastThisSpell(h->tempOwner, s, ECastingMode::HERO_CASTING); + if(escp != ESpellCastProblem::OK) { tlog2 << "Spell cannot be cast!\n"; tlog2 << "Problem : " << escp << std::endl; @@ -3952,7 +3954,7 @@ bool CGameHandler::makeCustomAction( BattleAction &ba ) StartAction start_action(ba); sendAndApply(&start_action); //start spell casting - handleSpellCasting (ba.additionalInfo, skill, ba.destinationTile, ba.side, h->tempOwner, h, secondHero, h->getPrimSkillLevel(2), SpellCasting::HERO_CASTING, NULL); + handleSpellCasting (ba.additionalInfo, skill, ba.destinationTile, ba.side, h->tempOwner, h, secondHero, h->getPrimSkillLevel(2), ECastingMode::HERO_CASTING, NULL); sendAndApply(&end_action); if( !gs->curB->getStack(gs->curB->activeStack, false)->alive() ) @@ -4047,7 +4049,7 @@ void CGameHandler::stackTurnTrigger(const CStack * st) if (enemy) { ui32 manaDrained = st->valOfBonuses(Bonus::MANA_DRAIN); - amin (manaDrained, gs->curB->heroes[0]->mana); + vstd::amin (manaDrained, gs->curB->heroes[0]->mana); if (manaDrained) { bte.effect = Bonus::MANA_DRAIN; @@ -4083,11 +4085,11 @@ void CGameHandler::stackTurnTrigger(const CStack * st) { int index = rand() % bl.size(); int spellID = bl[index]->subtype; //spell ID - if (gs->curB->battleCanCastThisSpell(st->owner, VLC->spellh->spells[spellID], SpellCasting::ENCHANTER_CASTING)); //TODO: select another? + if (gs->curB->battleCanCastThisSpell(st->owner, VLC->spellh->spells[spellID], ECastingMode::ENCHANTER_CASTING)); //TODO: select another? { int spellLeveL = bl[index]->val; //spell level const CGHeroInstance * enemyHero = gs->curB->getHero(gs->curB->theOtherPlayer(st->owner)); - handleSpellCasting(spellID, spellLeveL, -1, side, st->owner, NULL, enemyHero, 0, SpellCasting::ENCHANTER_CASTING, st); + handleSpellCasting(spellID, spellLeveL, -1, side, st->owner, NULL, enemyHero, 0, ECastingMode::ENCHANTER_CASTING, st); BattleSetStackProperty ssp; ssp.which = BattleSetStackProperty::ENCHANTER_COUNTER; @@ -4106,7 +4108,7 @@ void CGameHandler::handleTimeEvents() while(gs->map->events.size() && gs->map->events.front()->firstOccurence+1 == gs->day) { CMapEvent *ev = gs->map->events.front(); - for(int player = 0; player < PLAYER_LIMIT; player++) + for(int player = 0; player < GameConstants::PLAYER_LIMIT; player++) { PlayerState *pinfo = gs->getPlayer(player); @@ -4297,19 +4299,19 @@ bool CGameHandler::isAllowedExchange( int id1, int id2 ) const CGObjectInstance *o1 = getObj(id1), *o2 = getObj(id2); - if(o1->ID == TOWNI_TYPE) + if(o1->ID == GameConstants::TOWNI_TYPE) { const CGTownInstance *t = static_cast(o1); if(t->visitingHero == o2 || t->garrisonHero == o2) return true; } - if(o2->ID == TOWNI_TYPE) + if(o2->ID == GameConstants::TOWNI_TYPE) { const CGTownInstance *t = static_cast(o2); if(t->visitingHero == o1 || t->garrisonHero == o1) return true; } - if(o1->ID == HEROI_TYPE && o2->ID == HEROI_TYPE + if(o1->ID == GameConstants::HEROI_TYPE && o2->ID == GameConstants::HEROI_TYPE && distance(o1->pos, o2->pos) < 2) //hero stands on the same tile or on the neighbouring tiles { //TODO: it's workaround, we should check if first hero visited second and player hasn't closed exchange window @@ -4344,7 +4346,7 @@ bool CGameHandler::buildBoat( ui32 objid ) complain("Cannot build boat in this shipyard!"); return false; } - else if(obj->o->ID == TOWNI_TYPE + else if(obj->o->ID == GameConstants::TOWNI_TYPE && !vstd::contains((static_cast(obj))->builtBuildings,6)) { complain("Cannot build boat in the town - no shipyard!"); @@ -4397,7 +4399,7 @@ void CGameHandler::engageIntoBattle( ui8 player ) void CGameHandler::winLoseHandle(ui8 players ) { - for(size_t i = 0; i < PLAYER_LIMIT; i++) + for(size_t i = 0; i < GameConstants::PLAYER_LIMIT; i++) { if(players & 1<getPlayer(i)) { @@ -4433,7 +4435,7 @@ void CGameHandler::checkLossVictory( ui8 player ) for (bmap::const_iterator i = gs->players.begin(); i!=gs->players.end(); i++) { - if(i->first < PLAYER_LIMIT && i->first != player)//FIXME: skip already eliminated players? + if(i->first < GameConstants::PLAYER_LIMIT && i->first != player)//FIXME: skip already eliminated players? { iw.player = i->first; sendAndApply(&iw); @@ -4453,11 +4455,11 @@ void CGameHandler::checkLossVictory( ui8 player ) for (std::vector >::const_iterator i = gs->map->objects.begin(); i != gs->map->objects.end(); i++) //unflag objs { if(*i && (*i)->tempOwner == player) - setOwner((**i).id,NEUTRAL_PLAYER); + setOwner((**i).id,GameConstants::NEUTRAL_PLAYER); } //eliminating one player may cause victory of another: - winLoseHandle(ALL_PLAYERS & ~(1<map->victoryCondition.condition) { - case artifact: + case EVictoryConditionType::ARTIFACT: out.text.addTxt(MetaString::GENERAL_TXT, 280); //Congratulations! You have found the %s, and can claim victory! out.text.addReplacement(MetaString::ART_NAMES,gs->map->victoryCondition.ID); //artifact name break; - case gatherTroop: + case EVictoryConditionType::GATHERTROOP: out.text.addTxt(MetaString::GENERAL_TXT, 276); //Congratulations! You have over %d %s in your armies. Your enemies have no choice but to bow down before your power! out.text.addReplacement(gs->map->victoryCondition.count); out.text.addReplacement(MetaString::CRE_PL_NAMES, gs->map->victoryCondition.ID); break; - case gatherResource: + case EVictoryConditionType::GATHERRESOURCE: out.text.addTxt(MetaString::GENERAL_TXT, 278); //Congratulations! You have collected over %d %s in your treasury. Victory is yours! out.text.addReplacement(gs->map->victoryCondition.count); out.text.addReplacement(MetaString::RES_NAMES, gs->map->victoryCondition.ID); break; - case buildCity: + case EVictoryConditionType::BUILDCITY: out.text.addTxt(MetaString::GENERAL_TXT, 282); //Congratulations! You have successfully upgraded your town, and can claim victory! break; - case buildGrail: + case EVictoryConditionType::BUILDGRAIL: out.text.addTxt(MetaString::GENERAL_TXT, 284); //Congratulations! You have constructed a permanent home for the Grail, and can claim victory! break; - case beatHero: + case EVictoryConditionType::BEATHERO: { out.text.addTxt(MetaString::GENERAL_TXT, 252); //Congratulations! You have completed your quest to defeat the enemy hero %s. Victory is yours! const CGHeroInstance *h = dynamic_cast(gs->map->victoryCondition.obj); @@ -4525,7 +4527,7 @@ void CGameHandler::getLossVicMessage( ui8 player, ui8 standard, bool victory, In out.text.addReplacement(h->name); } break; - case captureCity: + case EVictoryConditionType::CAPTURECITY: { out.text.addTxt(MetaString::GENERAL_TXT, 249); //Congratulations! You captured %s, and are victorious! const CGTownInstance *t = dynamic_cast(gs->map->victoryCondition.obj); @@ -4533,16 +4535,16 @@ void CGameHandler::getLossVicMessage( ui8 player, ui8 standard, bool victory, In out.text.addReplacement(t->name); } break; - case beatMonster: + case EVictoryConditionType::BEATMONSTER: out.text.addTxt(MetaString::GENERAL_TXT, 286); //Congratulations! You have completed your quest to kill the fearsome beast, and can claim victory! break; - case takeDwellings: + case EVictoryConditionType::TAKEDWELLINGS: out.text.addTxt(MetaString::GENERAL_TXT, 288); //Congratulations! Your flag flies on the dwelling of every creature. Victory is yours! break; - case takeMines: + case EVictoryConditionType::TAKEMINES: out.text.addTxt(MetaString::GENERAL_TXT, 290); //Congratulations! Your flag flies on every mine. Victory is yours! break; - case transportItem: + case EVictoryConditionType::TRANSPORTITEM: out.text.addTxt(MetaString::GENERAL_TXT, 292); //Congratulations! You have reached your destination, precious cargo intact, and can claim victory! break; } @@ -4558,7 +4560,7 @@ void CGameHandler::getLossVicMessage( ui8 player, ui8 standard, bool victory, In { switch(gs->map->lossCondition.typeOfLossCon) { - case lossCastle: + case ELossConditionType::LOSSCASTLE: { out.text.addTxt(MetaString::GENERAL_TXT, 251); //The town of %s has fallen - all is lost! const CGTownInstance *t = dynamic_cast(gs->map->lossCondition.obj); @@ -4566,7 +4568,7 @@ void CGameHandler::getLossVicMessage( ui8 player, ui8 standard, bool victory, In out.text.addReplacement(t->name); } break; - case lossHero: + case ELossConditionType::LOSSHERO: { out.text.addTxt(MetaString::GENERAL_TXT, 253); //The hero, %s, has suffered defeat - your quest is over! const CGHeroInstance *h = dynamic_cast(gs->map->lossCondition.obj); @@ -4574,7 +4576,7 @@ void CGameHandler::getLossVicMessage( ui8 player, ui8 standard, bool victory, In out.text.addReplacement(h->name); } break; - case timeExpires: + case ELossConditionType::TIMEEXPIRES: out.text.addTxt(MetaString::GENERAL_TXT, 254); //Alas, time has run out on your quest. All is lost. break; } @@ -4673,17 +4675,17 @@ void CGameHandler::attackCasting(const BattleAttack & bat, Bonus::BonusType atta TBonusListPtr spellsByType = attacker->getBonuses(Selector::typeSubtype(attackMode, spellID)); BOOST_FOREACH(const Bonus *sf, *spellsByType) { - amax(spellLevel, sf->additionalInfo % 1000); //pick highest level + vstd::amax(spellLevel, sf->additionalInfo % 1000); //pick highest level meleeRanged = sf->additionalInfo / 1000; if (meleeRanged == 0 || (meleeRanged == 1 && bat.shot()) || (meleeRanged == 2 && !bat.shot())) castMe = true; } int chance = attacker->valOfBonuses((Selector::typeSubtype(attackMode, spellID))); - amin (chance, 100); + vstd::amin (chance, 100); int destination = oneOfAttacked->position; const CSpell * spell = VLC->spellh->spells[spellID]; - if(gs->curB->battleCanCastThisSpellHere(attacker->owner, spell, SpellCasting::AFTER_ATTACK_CASTING, oneOfAttacked->position) != SpellCasting::OK) + if(gs->curB->battleCanCastThisSpellHere(attacker->owner, spell, ECastingMode::AFTER_ATTACK_CASTING, oneOfAttacked->position) != ESpellCastProblem::OK) continue; //check if spell should be casted (probability handling) @@ -4692,7 +4694,7 @@ void CGameHandler::attackCasting(const BattleAttack & bat, Bonus::BonusType atta //casting //TODO: check if spell can be blocked or target is immune if (castMe) //stacks use 0 spell power. If needed, default = 3 or custom value is used - handleSpellCasting(spellID, spellLevel, destination, !attacker->attackerOwned, attacker->owner, NULL, NULL, 0, SpellCasting::AFTER_ATTACK_CASTING, attacker); + handleSpellCasting(spellID, spellLevel, destination, !attacker->attackerOwned, attacker->owner, NULL, NULL, 0, ECastingMode::AFTER_ATTACK_CASTING, attacker); } } } @@ -4727,7 +4729,7 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat ) { if (bat.bsa.size() && bat.bsa[0].newAmount > 0) //TODO: death stare was not originally available for multiple-hex attacks, but... handleSpellCasting(79, 0, gs->curB->getStack(bat.bsa[0].stackAttacked)->position, - !attacker->attackerOwned, attacker->owner, NULL, NULL, staredCreatures, SpellCasting::AFTER_ATTACK_CASTING, attacker); + !attacker->attackerOwned, attacker->owner, NULL, NULL, staredCreatures, ECastingMode::AFTER_ATTACK_CASTING, attacker); } } int acidDamage = 0; @@ -4741,7 +4743,7 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat ) { handleSpellCasting(81, 0, gs->curB->getStack(bat.bsa[0].stackAttacked)->position, !attacker->attackerOwned, attacker->owner, NULL, NULL, - acidDamage * attacker->count, SpellCasting::AFTER_ATTACK_CASTING, attacker); + acidDamage * attacker->count, ECastingMode::AFTER_ATTACK_CASTING, attacker); } } @@ -4927,7 +4929,7 @@ bool CGameHandler::castSpell(const CGHeroInstance *h, int spellID, const int3 &p if (!gs->map->isInTheMap(pos)) COMPLAIN_RET("Destination tile not present!") TerrainTile tile = gs->map->getTile(pos); - if (tile.visitableObjects.empty() || tile.visitableObjects.back()->ID != TOWNI_TYPE ) + if (tile.visitableObjects.empty() || tile.visitableObjects.back()->ID != GameConstants::TOWNI_TYPE ) COMPLAIN_RET("Town not found for Town Portal!"); CGTownInstance * town = static_cast(tile.visitableObjects.back()); @@ -5010,7 +5012,7 @@ bool CGameHandler::sacrificeCreatures(const IMarket *market, const CGHeroInstanc changeStackCount(StackLocation(hero, slot), -count); int dump, exp; - market->getOffer(crid, 0, dump, exp, CREATURE_EXP); + market->getOffer(crid, 0, dump, exp, EMarketMode::CREATURE_EXP); exp *= count; changePrimSkill(hero->id, 4, hero->calculateXp(exp)); @@ -5027,7 +5029,7 @@ bool CGameHandler::sacrificeArtifact(const IMarket * m, const CGHeroInstance * h int dmp, expToGive; - m->getOffer(hero->getArtTypeId(slot), 0, dmp, expToGive, ARTIFACT_EXP); + m->getOffer(hero->getArtTypeId(slot), 0, dmp, expToGive, EMarketMode::ARTIFACT_EXP); removeArtifact(al); changePrimSkill(hero->id, 4, expToGive); @@ -5217,7 +5219,7 @@ void CGameHandler::runBattle() TBonusListPtr bl = gs->curB->heroes[i]->getBonuses(Selector::type(Bonus::OPENING_BATTLE_SPELL)); BOOST_FOREACH (Bonus *b, *bl) { - handleSpellCasting(b->subtype, 3, -1, 0, gs->curB->heroes[i]->tempOwner, NULL, gs->curB->heroes[1-i], b->val, SpellCasting::HERO_CASTING, NULL); + handleSpellCasting(b->subtype, 3, -1, 0, gs->curB->heroes[i]->tempOwner, NULL, gs->curB->heroes[1-i], b->val, ECastingMode::HERO_CASTING, NULL); } } } @@ -5374,7 +5376,7 @@ void CGameHandler::runBattle() { stackTurnTrigger(next); //various effects - if (vstd::contains(next->state, FEAR)) + if (vstd::contains(next->state, EBattleStackState::FEAR)) { makeStackDoNothing(next); //end immediately if stack was affected by fear } @@ -5402,10 +5404,10 @@ void CGameHandler::runBattle() //check for good morale nextStackMorale = next->MoraleVal(); - if(!vstd::contains(next->state,HAD_MORALE) //only one extra move per turn possible - && !vstd::contains(next->state,DEFENDING) - && !vstd::contains(next->state,WAITING) - && !vstd::contains(next->state, FEAR) + if(!vstd::contains(next->state,EBattleStackState::HAD_MORALE) //only one extra move per turn possible + && !vstd::contains(next->state,EBattleStackState::DEFENDING) + && !vstd::contains(next->state,EBattleStackState::WAITING) + && !vstd::contains(next->state, EBattleStackState::FEAR) && next->alive() && nextStackMorale > 0 && !(NBonus::hasOfType(gs->curB->heroes[0], Bonus::BLOCK_MORALE) || NBonus::hasOfType(gs->curB->heroes[1], Bonus::BLOCK_MORALE)) //checking if gs->curB->heroes have (or don't have) morale blocking bonuses @@ -5531,11 +5533,11 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance *army, BattleI { int color = army->tempOwner; if(color == 254) - color = NEUTRAL_PLAYER; + color = GameConstants::NEUTRAL_PLAYER; BOOST_FOREACH(CStack *st, bat->stacks) { - if(vstd::contains(st->state, SUMMONED)) //don't take into account summoned stacks + if(vstd::contains(st->state, EBattleStackState::SUMMONED)) //don't take into account summoned stacks continue; if(st->owner==color && !army->slotEmpty(st->slot) && st->count < army->getStackCount(st->slot)) diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 0ed269248..724f910da 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -1,17 +1,12 @@ -#ifndef __CGAMEHANDLER_H__ -#define __CGAMEHANDLER_H__ +#pragma once + -#include "../global.h" -#include -#include #include "../client/FunctionList.h" #include "../lib/CGameState.h" #include "../lib/Connection.h" #include "../lib/IGameCallback.h" #include "../lib/BattleAction.h" #include "../lib/NetPacks.h" -#include -#include /* * CGameHandler.h, part of VCMI engine @@ -106,7 +101,7 @@ public: bool isAllowedExchange(int id1, int id2); bool isAllowedArrangePack(const ArrangeStacks *pack); void giveSpells(const CGTownInstance *t, const CGHeroInstance *h); - int moveStack(int stack, THex dest); //returned value - travelled distance + int moveStack(int stack, SHexField dest); //returned value - travelled distance void startBattle(const CArmedInstance *armies[2], int3 tile, const CGHeroInstance *heroes[2], bool creatureBank, boost::function cb, const CGTownInstance *town = NULL); //use hero=NULL for no hero void runBattle(); void checkLossVictory(ui8 player); @@ -197,7 +192,7 @@ public: void playerMessage( ui8 player, const std::string &message); bool makeBattleAction(BattleAction &ba); - void handleSpellCasting(int spellID, int spellLvl, THex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, SpellCasting::ECastingMode mode, const CStack * stack); + void handleSpellCasting(int spellID, int spellLvl, SHexField destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack); bool makeCustomAction(BattleAction &ba); void stackTurnTrigger(const CStack * stack); bool queryReply( ui32 qid, ui32 answer, ui8 player ); @@ -262,6 +257,4 @@ public: friend class CScriptCallback; }; -#endif // __CGAMEHANDLER_H__ - void makeStackDoNothing(); diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 7c7609593..d6274d4a9 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -1,31 +1,41 @@ -#include "stdafx.h" +#include "StdInc.h" + +#include //no i/o just types +#include +#include +#include +#include +#include + + + #include "../lib/CCampaignHandler.h" -#include "../global.h" +#include "../lib/CThreadHelper.h" #include "../lib/Connection.h" #include "../lib/CArtHandler.h" #include "../lib/CDefObjInfoHandler.h" #include "../lib/CGeneralTextHandler.h" #include "../lib/CHeroHandler.h" #include "../lib/CTownHandler.h" -#include "../lib/CObjectHandler.h" #include "../lib/CBuildingHandler.h" #include "../lib/CSpellHandler.h" #include "../lib/CCreatureHandler.h" #include "zlib.h" -#ifndef __GNUC__ -#include -#endif #include "CVCMIServer.h" -#include "../StartInfo.h" +#include "../lib/StartInfo.h" #include "../lib/map.h" #include "../lib/Interprocess.h" #include "../lib/VCMI_Lib.h" #include "../lib/VCMIDirs.h" #include "CGameHandler.h" #include "../lib/CMapInfo.h" +#include "../lib/CObjectHandler.h" +#include "../lib/GameConstants.h" + +#include std::string NAME_AFFIX = "server"; -std::string NAME = NAME_VER + std::string(" (") + NAME_AFFIX + ')'; //application name +std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')'; //application name using namespace boost; using namespace boost::asio; using namespace boost::asio::ip; @@ -120,7 +130,7 @@ void CPregameServer::handleConnection(CConnection *cpc) tlog0 << "Thread listening for " << *cpc << " ended\n"; listeningThreads--; - delNull(cpc->handler); + vstd::clear_pointer(cpc->handler); } void CPregameServer::run() @@ -261,14 +271,14 @@ void CPregameServer::processPack(CPackForSelectionScreen * pack) } else if(SelectMap *sm = dynamic_cast(pack)) { - delNull(curmap); + vstd::clear_pointer(curmap); curmap = sm->mapInfo; sm->free = false; announcePack(*pack); } else if(UpdateStartOptions *uso = dynamic_cast(pack)) { - delNull(curStartInfo); + vstd::clear_pointer(curStartInfo); curStartInfo = uso->options; uso->free = false; announcePack(*pack); @@ -298,7 +308,7 @@ void CPregameServer::startListeningThread(CConnection * pc) } CVCMIServer::CVCMIServer() -: io(new io_service()), acceptor(new TAcceptor(*io, tcp::endpoint(tcp::v4(), port))), firstConnection(NULL) +: io(new boost::asio::io_service()), acceptor(new TAcceptor(*io, tcp::endpoint(tcp::v4(), port))), firstConnection(NULL) { tlog4 << "CVCMIServer created!" <run(false); - delNull(gh); + vstd::clear_pointer(gh); } void CVCMIServer::newPregame() @@ -518,7 +528,7 @@ int main(int argc, char** argv) } tlog0 << "Port " << port << " will be used." << std::endl; initDLL(console,logfile); - srand ( (unsigned int)time(NULL) ); + srand ( (ui32)time(NULL) ); try { io_service io_service; diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h index 642b00a91..64649fde8 100644 --- a/server/CVCMIServer.h +++ b/server/CVCMIServer.h @@ -1,8 +1,6 @@ -#ifndef __CVCMISERVER_H__ -#define __CVCMISERVER_H__ -#include "../global.h" -#include -#include +#pragma once + + /* * CVCMIServer.h, part of VCMI engine @@ -98,6 +96,3 @@ public: void sendPack(CConnection * pc, const CPackForSelectionScreen & pack); void startListeningThread(CConnection * pc); }; - - -#endif // __CVCMISERVER_H__ diff --git a/server/Makefile.am b/server/Makefile.am index c34c7763a..1ab6d83f8 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -1,17 +1,14 @@ bin_PROGRAMS = vcmiserver +BUILT_SOURCES = StdInc.h.gch +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -c $< -vcmiserver_LDADD = $(top_builddir)/lib/libvcmi.la @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ -lrt +vcmiserver_LDADD = $(top_builddir)/lib/libvcmi.la @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ -lrt -lpthread vcmiserver_CXXFLAGS = @SDL_CFLAGS@ vcmiserver_LDFLAGS = -L$(top_builddir)/lib vcmiserver_SOURCES = \ - ../CConsoleHandler.cpp \ - ../CConsoleHandler.h \ - ../CThreadHelper.cpp \ - ../CThreadHelper.h \ CGameHandler.cpp \ CGameHandler.h \ CVCMIServer.cpp \ CVCMIServer.h \ - NetPacksServer.cpp \ - stdafx.cpp \ - stdafx.h + NetPacksServer.cpp diff --git a/server/Makefile.in b/server/Makefile.in index 950247b4a..df37ed3e2 100644 --- a/server/Makefile.in +++ b/server/Makefile.in @@ -58,12 +58,9 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) -am_vcmiserver_OBJECTS = vcmiserver-CConsoleHandler.$(OBJEXT) \ - vcmiserver-CThreadHelper.$(OBJEXT) \ - vcmiserver-CGameHandler.$(OBJEXT) \ +am_vcmiserver_OBJECTS = vcmiserver-CGameHandler.$(OBJEXT) \ vcmiserver-CVCMIServer.$(OBJEXT) \ - vcmiserver-NetPacksServer.$(OBJEXT) \ - vcmiserver-stdafx.$(OBJEXT) + vcmiserver-NetPacksServer.$(OBJEXT) vcmiserver_OBJECTS = $(am_vcmiserver_OBJECTS) vcmiserver_DEPENDENCIES = $(top_builddir)/lib/libvcmi.la AM_V_lt = $(am__v_lt_$(V)) @@ -253,23 +250,19 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -vcmiserver_LDADD = $(top_builddir)/lib/libvcmi.la @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ -lrt +BUILT_SOURCES = StdInc.h.gch +vcmiserver_LDADD = $(top_builddir)/lib/libvcmi.la @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ -lrt -lpthread vcmiserver_CXXFLAGS = @SDL_CFLAGS@ vcmiserver_LDFLAGS = -L$(top_builddir)/lib vcmiserver_SOURCES = \ - ../CConsoleHandler.cpp \ - ../CConsoleHandler.h \ - ../CThreadHelper.cpp \ - ../CThreadHelper.h \ CGameHandler.cpp \ CGameHandler.h \ CVCMIServer.cpp \ CVCMIServer.h \ - NetPacksServer.cpp \ - stdafx.cpp \ - stdafx.h + NetPacksServer.cpp -all: all-am +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .cpp .lo .o .obj @@ -356,12 +349,9 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiserver-CConsoleHandler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiserver-CGameHandler.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiserver-CThreadHelper.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiserver-CVCMIServer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiserver-NetPacksServer.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiserver-stdafx.Po@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -387,38 +377,6 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< -vcmiserver-CConsoleHandler.o: ../CConsoleHandler.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -MT vcmiserver-CConsoleHandler.o -MD -MP -MF $(DEPDIR)/vcmiserver-CConsoleHandler.Tpo -c -o vcmiserver-CConsoleHandler.o `test -f '../CConsoleHandler.cpp' || echo '$(srcdir)/'`../CConsoleHandler.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiserver-CConsoleHandler.Tpo $(DEPDIR)/vcmiserver-CConsoleHandler.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../CConsoleHandler.cpp' object='vcmiserver-CConsoleHandler.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -c -o vcmiserver-CConsoleHandler.o `test -f '../CConsoleHandler.cpp' || echo '$(srcdir)/'`../CConsoleHandler.cpp - -vcmiserver-CConsoleHandler.obj: ../CConsoleHandler.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -MT vcmiserver-CConsoleHandler.obj -MD -MP -MF $(DEPDIR)/vcmiserver-CConsoleHandler.Tpo -c -o vcmiserver-CConsoleHandler.obj `if test -f '../CConsoleHandler.cpp'; then $(CYGPATH_W) '../CConsoleHandler.cpp'; else $(CYGPATH_W) '$(srcdir)/../CConsoleHandler.cpp'; fi` -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiserver-CConsoleHandler.Tpo $(DEPDIR)/vcmiserver-CConsoleHandler.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../CConsoleHandler.cpp' object='vcmiserver-CConsoleHandler.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -c -o vcmiserver-CConsoleHandler.obj `if test -f '../CConsoleHandler.cpp'; then $(CYGPATH_W) '../CConsoleHandler.cpp'; else $(CYGPATH_W) '$(srcdir)/../CConsoleHandler.cpp'; fi` - -vcmiserver-CThreadHelper.o: ../CThreadHelper.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -MT vcmiserver-CThreadHelper.o -MD -MP -MF $(DEPDIR)/vcmiserver-CThreadHelper.Tpo -c -o vcmiserver-CThreadHelper.o `test -f '../CThreadHelper.cpp' || echo '$(srcdir)/'`../CThreadHelper.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiserver-CThreadHelper.Tpo $(DEPDIR)/vcmiserver-CThreadHelper.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../CThreadHelper.cpp' object='vcmiserver-CThreadHelper.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -c -o vcmiserver-CThreadHelper.o `test -f '../CThreadHelper.cpp' || echo '$(srcdir)/'`../CThreadHelper.cpp - -vcmiserver-CThreadHelper.obj: ../CThreadHelper.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -MT vcmiserver-CThreadHelper.obj -MD -MP -MF $(DEPDIR)/vcmiserver-CThreadHelper.Tpo -c -o vcmiserver-CThreadHelper.obj `if test -f '../CThreadHelper.cpp'; then $(CYGPATH_W) '../CThreadHelper.cpp'; else $(CYGPATH_W) '$(srcdir)/../CThreadHelper.cpp'; fi` -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiserver-CThreadHelper.Tpo $(DEPDIR)/vcmiserver-CThreadHelper.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../CThreadHelper.cpp' object='vcmiserver-CThreadHelper.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -c -o vcmiserver-CThreadHelper.obj `if test -f '../CThreadHelper.cpp'; then $(CYGPATH_W) '../CThreadHelper.cpp'; else $(CYGPATH_W) '$(srcdir)/../CThreadHelper.cpp'; fi` - vcmiserver-CGameHandler.o: CGameHandler.cpp @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -MT vcmiserver-CGameHandler.o -MD -MP -MF $(DEPDIR)/vcmiserver-CGameHandler.Tpo -c -o vcmiserver-CGameHandler.o `test -f 'CGameHandler.cpp' || echo '$(srcdir)/'`CGameHandler.cpp @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiserver-CGameHandler.Tpo $(DEPDIR)/vcmiserver-CGameHandler.Po @@ -467,22 +425,6 @@ vcmiserver-NetPacksServer.obj: NetPacksServer.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -c -o vcmiserver-NetPacksServer.obj `if test -f 'NetPacksServer.cpp'; then $(CYGPATH_W) 'NetPacksServer.cpp'; else $(CYGPATH_W) '$(srcdir)/NetPacksServer.cpp'; fi` -vcmiserver-stdafx.o: stdafx.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -MT vcmiserver-stdafx.o -MD -MP -MF $(DEPDIR)/vcmiserver-stdafx.Tpo -c -o vcmiserver-stdafx.o `test -f 'stdafx.cpp' || echo '$(srcdir)/'`stdafx.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiserver-stdafx.Tpo $(DEPDIR)/vcmiserver-stdafx.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='stdafx.cpp' object='vcmiserver-stdafx.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -c -o vcmiserver-stdafx.o `test -f 'stdafx.cpp' || echo '$(srcdir)/'`stdafx.cpp - -vcmiserver-stdafx.obj: stdafx.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -MT vcmiserver-stdafx.obj -MD -MP -MF $(DEPDIR)/vcmiserver-stdafx.Tpo -c -o vcmiserver-stdafx.obj `if test -f 'stdafx.cpp'; then $(CYGPATH_W) 'stdafx.cpp'; else $(CYGPATH_W) '$(srcdir)/stdafx.cpp'; fi` -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiserver-stdafx.Tpo $(DEPDIR)/vcmiserver-stdafx.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='stdafx.cpp' object='vcmiserver-stdafx.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiserver_CXXFLAGS) $(CXXFLAGS) -c -o vcmiserver-stdafx.obj `if test -f 'stdafx.cpp'; then $(CYGPATH_W) 'stdafx.cpp'; else $(CYGPATH_W) '$(srcdir)/stdafx.cpp'; fi` - mostlyclean-libtool: -rm -f *.lo @@ -572,13 +514,15 @@ distdir: $(DISTFILES) fi; \ done check-am: all-am -check: check-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am all-am: Makefile $(PROGRAMS) installdirs: for dir in "$(DESTDIR)$(bindir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-am +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -603,6 +547,7 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am @@ -673,7 +618,7 @@ ps-am: uninstall-am: uninstall-binPROGRAMS -.MAKE: install-am install-strip +.MAKE: all check install install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ clean-generic clean-libtool ctags distclean distclean-compile \ @@ -689,6 +634,8 @@ uninstall-am: uninstall-binPROGRAMS pdf pdf-am ps ps-am tags uninstall uninstall-am \ uninstall-binPROGRAMS +StdInc.h.gch: StdInc.h + $(CXXCOMPILE) -c $< # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/server/NetPacksServer.cpp b/server/NetPacksServer.cpp index a83863271..b96871828 100644 --- a/server/NetPacksServer.cpp +++ b/server/NetPacksServer.cpp @@ -1,5 +1,6 @@ -#include "stdafx.h" +#include "StdInc.h" #include "../lib/NetPacks.h" + #include "CGameHandler.h" #include "../lib/CObjectHandler.h" #include "../lib/IGameCallback.h" @@ -158,10 +159,10 @@ bool TradeOnMarketplace::applyGh( CGameHandler *gh ) ui8 player = market->tempOwner; - if(player >= PLAYER_LIMIT) + if(player >= GameConstants::PLAYER_LIMIT) player = gh->getTile(market->visitablePos())->visitableObjects.back()->tempOwner; - if(player >= PLAYER_LIMIT) + if(player >= GameConstants::PLAYER_LIMIT) COMPLAIN_AND_RETURN("No player can use this market!"); if(hero && (player != hero->tempOwner || hero->visitablePos() != market->visitablePos())) @@ -171,29 +172,29 @@ bool TradeOnMarketplace::applyGh( CGameHandler *gh ) switch(mode) { - case RESOURCE_RESOURCE: + case EMarketMode::RESOURCE_RESOURCE: return gh->tradeResources(m, val, player, r1, r2); - case RESOURCE_PLAYER: + case EMarketMode::RESOURCE_PLAYER: return gh->sendResources(val, player, r1, r2); - case CREATURE_RESOURCE: + case EMarketMode::CREATURE_RESOURCE: if(!hero) COMPLAIN_AND_RETURN("Only hero can sell creatures!"); return gh->sellCreatures(val, m, hero, r1, r2); - case RESOURCE_ARTIFACT: + case EMarketMode::RESOURCE_ARTIFACT: if(!hero) COMPLAIN_AND_RETURN("Only hero can buy artifacts!"); return gh->buyArtifact(m, hero, r1, r2); - case ARTIFACT_RESOURCE: + case EMarketMode::ARTIFACT_RESOURCE: if(!hero) COMPLAIN_AND_RETURN("Only hero can sell artifacts!"); return gh->sellArtifact(m, hero, r1, r2); - case CREATURE_UNDEAD: + case EMarketMode::CREATURE_UNDEAD: return gh->transformInUndead(m, hero, r1); - case RESOURCE_SKILL: + case EMarketMode::RESOURCE_SKILL: return gh->buySecSkill(m, hero, r2); - case CREATURE_EXP: + case EMarketMode::CREATURE_EXP: return gh->sacrificeCreatures(m, hero, r1, val); - case ARTIFACT_EXP: + case EMarketMode::ARTIFACT_EXP: return gh->sacrificeArtifact(m, hero, r1); default: COMPLAIN_AND_RETURN("Unknown exchange mode!"); @@ -210,7 +211,7 @@ bool HireHero::applyGh( CGameHandler *gh ) { const CGObjectInstance *obj = gh->getObj(tid); - if(obj->ID == TOWNI_TYPE) + if(obj->ID == GameConstants::TOWNI_TYPE) ERROR_IF_NOT_OWNS(tid); //TODO check for visiting hero diff --git a/server/VCMI_server.vcxproj b/server/VCMI_server.vcxproj index 1a75b0046..1a5a4e52a 100644 --- a/server/VCMI_server.vcxproj +++ b/server/VCMI_server.vcxproj @@ -100,11 +100,11 @@ false EnableFastChecks MultiThreadedDebugDLL - Level1 + Level3 EditAndContinue 4251;%(DisableSpecificWarnings) Use - stdafx.h + StdInc.h VCMI_lib.lib;zlib.lib;%(AdditionalDependencies) @@ -198,17 +198,15 @@ - + Create - Create - Create - Create + StdInc.h - + From cce814c41b545ed5afc7905e473d39b29131fe1b Mon Sep 17 00:00:00 2001 From: beegee1 Date: Tue, 13 Dec 2011 21:35:28 +0000 Subject: [PATCH 2/5] * Final commit --- AI/EmptyAI/StdInc.cpp | 2 + AI/EmptyAI/StdInc.h | 325 +++ AI/GeniusAI/StdInc.cpp | 2 + AI/GeniusAI/StdInc.h | 325 +++ AI/StupidAI/StdInc.cpp | 2 + AI/StupidAI/StdInc.h | 325 +++ AI/StupidAI/stdafx.cpp | 1 - AI/StupidAI/stdafx.h | 3 - Scripting/ERM/StdInc.cpp | 2 + Scripting/ERM/StdInc.h | 325 +++ client/BattleInterface/CAttackAnimation.cpp | 51 + client/BattleInterface/CAttackAnimation.h | 35 + client/BattleInterface/CBattleAnimation.cpp | 49 + client/BattleInterface/CBattleAnimation.h | 30 + client/BattleInterface/CBattleConsole.cpp | 84 + client/BattleInterface/CBattleConsole.h | 35 + client/BattleInterface/CBattleHero.cpp | 153 ++ client/BattleInterface/CBattleHero.h | 39 + .../CBattleInterface.cpp | 2177 ++--------------- client/BattleInterface/CBattleInterface.h | 256 ++ .../BattleInterface/CBattleOptionsWindow.cpp | 73 + client/BattleInterface/CBattleOptionsWindow.h | 39 + .../BattleInterface/CBattleResultWindow.cpp | 216 ++ client/BattleInterface/CBattleResultWindow.h | 37 + .../BattleInterface/CBattleStackAnimation.cpp | 57 + .../BattleInterface/CBattleStackAnimation.h | 31 + client/BattleInterface/CDefenceAnimation.cpp | 139 ++ client/BattleInterface/CDefenceAnimation.h | 34 + client/BattleInterface/CDummyAnimation.cpp | 27 + client/BattleInterface/CDummyAnimation.h | 28 + client/BattleInterface/CHexFieldControl.cpp | 147 ++ client/BattleInterface/CHexFieldControl.h | 40 + .../BattleInterface/CMeleeAttackAnimation.cpp | 95 + .../BattleInterface/CMeleeAttackAnimation.h | 28 + client/BattleInterface/CMovementAnimation.cpp | 176 ++ client/BattleInterface/CMovementAnimation.h | 37 + .../BattleInterface/CMovementEndAnimation.cpp | 52 + .../BattleInterface/CMovementEndAnimation.h | 30 + .../CMovementStartAnimation.cpp | 52 + .../BattleInterface/CMovementStartAnimation.h | 27 + client/BattleInterface/CReverseAnimation.cpp | 100 + client/BattleInterface/CReverseAnimation.h | 34 + client/BattleInterface/CShootingAnimation.cpp | 192 ++ client/BattleInterface/CShootingAnimation.h | 49 + .../BattleInterface/CSpellEffectAnimation.cpp | 181 ++ .../BattleInterface/CSpellEffectAnimation.h | 35 + client/BattleInterface/CStackQueue.cpp | 125 + client/BattleInterface/CStackQueue.h | 51 + client/BattleInterface/SStackAttackedInfo.h | 25 + client/CBattleInterface.h | 597 ----- client/StdInc.cpp | 2 + client/StdInc.h | 325 +++ global.h | 734 ------ AI_Base.h => lib/AI_Base.h | 9 +- .../CConsoleHandler.cpp | 7 +- CConsoleHandler.h => lib/CConsoleHandler.h | 18 +- lib/CLogger.cpp | 62 + lib/CLogger.h | 53 + CThreadHelper.cpp => lib/CThreadHelper.cpp | 6 +- CThreadHelper.h => lib/CThreadHelper.h | 13 +- lib/GameConstants.h | 176 ++ lib/RegisterTypes.cpp | 242 -- lib/SHexField.cpp | 85 + lib/SHexField.h | 109 + StartInfo.h => lib/StartInfo.h | 10 +- lib/StdInc.cpp | 2 + lib/StdInc.h | 325 +++ timeHandler.h => lib/StopWatch.h | 31 +- int3.h => lib/int3.h | 7 +- nodrze.h | 914 ------- server/StdInc.cpp | 2 + server/StdInc.h | 325 +++ server/stdafx.cpp | 1 - server/stdafx.h | 30 - stdafx.cpp | 8 - stdafx.h | 24 - 76 files changed, 5877 insertions(+), 4618 deletions(-) create mode 100644 AI/EmptyAI/StdInc.cpp create mode 100644 AI/EmptyAI/StdInc.h create mode 100644 AI/GeniusAI/StdInc.cpp create mode 100644 AI/GeniusAI/StdInc.h create mode 100644 AI/StupidAI/StdInc.cpp create mode 100644 AI/StupidAI/StdInc.h delete mode 100644 AI/StupidAI/stdafx.cpp delete mode 100644 AI/StupidAI/stdafx.h create mode 100644 Scripting/ERM/StdInc.cpp create mode 100644 Scripting/ERM/StdInc.h create mode 100644 client/BattleInterface/CAttackAnimation.cpp create mode 100644 client/BattleInterface/CAttackAnimation.h create mode 100644 client/BattleInterface/CBattleAnimation.cpp create mode 100644 client/BattleInterface/CBattleAnimation.h create mode 100644 client/BattleInterface/CBattleConsole.cpp create mode 100644 client/BattleInterface/CBattleConsole.h create mode 100644 client/BattleInterface/CBattleHero.cpp create mode 100644 client/BattleInterface/CBattleHero.h rename client/{ => BattleInterface}/CBattleInterface.cpp (57%) create mode 100644 client/BattleInterface/CBattleInterface.h create mode 100644 client/BattleInterface/CBattleOptionsWindow.cpp create mode 100644 client/BattleInterface/CBattleOptionsWindow.h create mode 100644 client/BattleInterface/CBattleResultWindow.cpp create mode 100644 client/BattleInterface/CBattleResultWindow.h create mode 100644 client/BattleInterface/CBattleStackAnimation.cpp create mode 100644 client/BattleInterface/CBattleStackAnimation.h create mode 100644 client/BattleInterface/CDefenceAnimation.cpp create mode 100644 client/BattleInterface/CDefenceAnimation.h create mode 100644 client/BattleInterface/CDummyAnimation.cpp create mode 100644 client/BattleInterface/CDummyAnimation.h create mode 100644 client/BattleInterface/CHexFieldControl.cpp create mode 100644 client/BattleInterface/CHexFieldControl.h create mode 100644 client/BattleInterface/CMeleeAttackAnimation.cpp create mode 100644 client/BattleInterface/CMeleeAttackAnimation.h create mode 100644 client/BattleInterface/CMovementAnimation.cpp create mode 100644 client/BattleInterface/CMovementAnimation.h create mode 100644 client/BattleInterface/CMovementEndAnimation.cpp create mode 100644 client/BattleInterface/CMovementEndAnimation.h create mode 100644 client/BattleInterface/CMovementStartAnimation.cpp create mode 100644 client/BattleInterface/CMovementStartAnimation.h create mode 100644 client/BattleInterface/CReverseAnimation.cpp create mode 100644 client/BattleInterface/CReverseAnimation.h create mode 100644 client/BattleInterface/CShootingAnimation.cpp create mode 100644 client/BattleInterface/CShootingAnimation.h create mode 100644 client/BattleInterface/CSpellEffectAnimation.cpp create mode 100644 client/BattleInterface/CSpellEffectAnimation.h create mode 100644 client/BattleInterface/CStackQueue.cpp create mode 100644 client/BattleInterface/CStackQueue.h create mode 100644 client/BattleInterface/SStackAttackedInfo.h delete mode 100644 client/CBattleInterface.h create mode 100644 client/StdInc.cpp create mode 100644 client/StdInc.h delete mode 100644 global.h rename AI_Base.h => lib/AI_Base.h (61%) rename CConsoleHandler.cpp => lib/CConsoleHandler.cpp (94%) rename CConsoleHandler.h => lib/CConsoleHandler.h (70%) create mode 100644 lib/CLogger.cpp create mode 100644 lib/CLogger.h rename CThreadHelper.cpp => lib/CThreadHelper.cpp (91%) rename CThreadHelper.h => lib/CThreadHelper.h (79%) create mode 100644 lib/GameConstants.h delete mode 100644 lib/RegisterTypes.cpp create mode 100644 lib/SHexField.cpp create mode 100644 lib/SHexField.h rename StartInfo.h => lib/StartInfo.h (90%) create mode 100644 lib/StdInc.cpp create mode 100644 lib/StdInc.h rename timeHandler.h => lib/StopWatch.h (62%) rename int3.h => lib/int3.h (93%) delete mode 100644 nodrze.h create mode 100644 server/StdInc.cpp create mode 100644 server/StdInc.h delete mode 100644 server/stdafx.cpp delete mode 100644 server/stdafx.h delete mode 100644 stdafx.cpp delete mode 100644 stdafx.h diff --git a/AI/EmptyAI/StdInc.cpp b/AI/EmptyAI/StdInc.cpp new file mode 100644 index 000000000..c8f4ddf05 --- /dev/null +++ b/AI/EmptyAI/StdInc.cpp @@ -0,0 +1,2 @@ +// Creates the precompiled header +#include "StdInc.h" \ No newline at end of file diff --git a/AI/EmptyAI/StdInc.h b/AI/EmptyAI/StdInc.h new file mode 100644 index 000000000..5c3d9f243 --- /dev/null +++ b/AI/EmptyAI/StdInc.h @@ -0,0 +1,325 @@ +#pragma once + +// Standard include file +// Should be treated as a precompiled header file in the compiler settings +// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio +// This file shouldn't be changed, except if there is a important header file which is missing. + +/* + * StdInc.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#ifdef _WIN32 +#include +#else +#include "../../tchar_amigaos4.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +//filesystem version 3 causes problems (and it's default as of boost 1.46) +#define BOOST_FILESYSTEM_VERSION 2 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef ANDROID +#include +#endif + +// Integral data types +typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) +typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) +typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) +typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) +typedef boost::int64_t si64; //signed int 64 bits (8 bytes) +typedef boost::int32_t si32; //signed int 32 bits (4 bytes) +typedef boost::int16_t si16; //signed int 16 bits (2 bytes) +typedef boost::int8_t si8; //signed int 8 bits (1 byte) + +// Import + Export macro declarations +#ifdef _WIN32 +#define DLL_EXPORT __declspec(dllexport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_EXPORT __attribute__ ((visibility("default"))) +#else +#define DLL_EXPORT +#endif +#endif + +#ifdef _WIN32 +#define DLL_IMPORT __declspec(dllimport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_IMPORT __attribute__ ((visibility("default"))) +#else +#define DLL_IMPORT +#endif +#endif + +#ifdef VCMI_DLL +#define DLL_LINKAGE DLL_EXPORT +#else +#define DLL_LINKAGE DLL_IMPORT +#endif + + +//a normal std::map with a const operator[] for sanity +template +class bmap : public std::map +{ +public: + const ValT & operator[](KeyT key) const + { + return find(key)->second; + } + ValT & operator[](KeyT key) + { + return static_cast &>(*this)[key]; + } + template void serialize(Handler &h, const int version) + { + h & static_cast &>(*this); + } +}; + +namespace vstd +{ + //returns true if container c contains item i + template + bool contains(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i) != c.end(); + } + + //returns true if map c contains item i + template + bool contains(const std::map & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if bmap c contains item i + template + bool contains(const bmap & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if unordered set c contains item i + template + bool contains(const boost::unordered_set & c, const Item &i) + { + return c.find(i)!=c.end(); + } + + //returns position of first element in vector c equal to s, if there is no such element, -1 is returned + template + int find_pos(const std::vector & c, const T2 &s) + { + for(size_t i=0; i < c.size(); ++i) + if(c[i] == s) + return i; + return -1; + } + + //Func(T1,T2) must say if these elements matches + template + int find_pos(const std::vector & c, const T2 &s, const Func &f) + { + for(size_t i=0; i < c.size(); ++i) + if(f(c[i],s)) + return i; + return -1; + } + + //returns iterator to the given element if present in container, end() if not + template + typename Container::iterator find(Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //returns const iterator to the given element if present in container, end() if not + template + typename Container::const_iterator find(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //removes element i from container c, returns false if c does not contain i + template + typename Container::size_type operator-=(Container &c, const Item &i) + { + typename Container::iterator itr = find(c,i); + if(itr == c.end()) + return false; + c.erase(itr); + return true; + } + + //assigns greater of (a, b) to a and returns maximum of (a, b) + template + t1 &amax(t1 &a, const t2 &b) + { + if(a >= b) + return a; + else + { + a = b; + return a; + } + } + + //assigns smaller of (a, b) to a and returns minimum of (a, b) + template + t1 &amin(t1 &a, const t2 &b) + { + if(a <= b) + return a; + else + { + a = b; + return a; + } + } + + //makes a to fit the range + template + t1 &abetween(t1 &a, const t2 &b, const t3 &c) + { + amax(a,b); + amin(a,c); + return a; + } + + //checks if a is between b and c + template + bool isbetween(const t1 &a, const t2 &b, const t3 &c) + { + return a > b && a < c; + } + + //checks if a is within b and c + template + bool iswithin(const t1 &a, const t2 &b, const t3 &c) + { + return a >= b && a <= c; + } + + template + struct assigner + { + public: + t1 &op1; + t2 op2; + assigner(t1 &a1, const t2 & a2) + :op1(a1), op2(a2) + {} + void operator()() + { + op1 = op2; + } + }; + + // Assigns value a2 to a1. The point of time of the real operation can be controlled + // with the () operator. + template + assigner assigno(t1 &a1, const t2 &a2) + { + return assigner(a1,a2); + } + + //deleted pointer and sets it to NULL + template + void clear_pointer(T* &ptr) + { + delete ptr; + ptr = NULL; + } +} +using vstd::operator-=; + +// can be used for counting arrays +template char (&_ArrayCountObj(const T (&)[N]))[N]; +#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) + +//for explicit overrides +#ifdef _MSC_VER +#define OVERRIDE override +#else +#define OVERRIDE //is there any working counterpart? +#endif + +//XXX pls dont - 'debug macros' are usually more trouble than it's worth +#define HANDLE_EXCEPTION \ + catch (const std::exception& e) { \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::exception * e) \ +{ \ + tlog1 << e->what()<< std::endl; \ + throw; \ +} \ + catch (const std::string& e) { \ + tlog1 << e << std::endl; \ + throw; \ +} + +#define HANDLE_EXCEPTIONC(COMMAND) \ + catch (const std::exception& e) { \ + COMMAND; \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::string &e) \ +{ \ + COMMAND; \ + tlog1 << e << std::endl; \ + throw; \ +} + + +#include "../../lib/CLogger.h" diff --git a/AI/GeniusAI/StdInc.cpp b/AI/GeniusAI/StdInc.cpp new file mode 100644 index 000000000..c8f4ddf05 --- /dev/null +++ b/AI/GeniusAI/StdInc.cpp @@ -0,0 +1,2 @@ +// Creates the precompiled header +#include "StdInc.h" \ No newline at end of file diff --git a/AI/GeniusAI/StdInc.h b/AI/GeniusAI/StdInc.h new file mode 100644 index 000000000..5c3d9f243 --- /dev/null +++ b/AI/GeniusAI/StdInc.h @@ -0,0 +1,325 @@ +#pragma once + +// Standard include file +// Should be treated as a precompiled header file in the compiler settings +// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio +// This file shouldn't be changed, except if there is a important header file which is missing. + +/* + * StdInc.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#ifdef _WIN32 +#include +#else +#include "../../tchar_amigaos4.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +//filesystem version 3 causes problems (and it's default as of boost 1.46) +#define BOOST_FILESYSTEM_VERSION 2 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef ANDROID +#include +#endif + +// Integral data types +typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) +typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) +typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) +typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) +typedef boost::int64_t si64; //signed int 64 bits (8 bytes) +typedef boost::int32_t si32; //signed int 32 bits (4 bytes) +typedef boost::int16_t si16; //signed int 16 bits (2 bytes) +typedef boost::int8_t si8; //signed int 8 bits (1 byte) + +// Import + Export macro declarations +#ifdef _WIN32 +#define DLL_EXPORT __declspec(dllexport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_EXPORT __attribute__ ((visibility("default"))) +#else +#define DLL_EXPORT +#endif +#endif + +#ifdef _WIN32 +#define DLL_IMPORT __declspec(dllimport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_IMPORT __attribute__ ((visibility("default"))) +#else +#define DLL_IMPORT +#endif +#endif + +#ifdef VCMI_DLL +#define DLL_LINKAGE DLL_EXPORT +#else +#define DLL_LINKAGE DLL_IMPORT +#endif + + +//a normal std::map with a const operator[] for sanity +template +class bmap : public std::map +{ +public: + const ValT & operator[](KeyT key) const + { + return find(key)->second; + } + ValT & operator[](KeyT key) + { + return static_cast &>(*this)[key]; + } + template void serialize(Handler &h, const int version) + { + h & static_cast &>(*this); + } +}; + +namespace vstd +{ + //returns true if container c contains item i + template + bool contains(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i) != c.end(); + } + + //returns true if map c contains item i + template + bool contains(const std::map & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if bmap c contains item i + template + bool contains(const bmap & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if unordered set c contains item i + template + bool contains(const boost::unordered_set & c, const Item &i) + { + return c.find(i)!=c.end(); + } + + //returns position of first element in vector c equal to s, if there is no such element, -1 is returned + template + int find_pos(const std::vector & c, const T2 &s) + { + for(size_t i=0; i < c.size(); ++i) + if(c[i] == s) + return i; + return -1; + } + + //Func(T1,T2) must say if these elements matches + template + int find_pos(const std::vector & c, const T2 &s, const Func &f) + { + for(size_t i=0; i < c.size(); ++i) + if(f(c[i],s)) + return i; + return -1; + } + + //returns iterator to the given element if present in container, end() if not + template + typename Container::iterator find(Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //returns const iterator to the given element if present in container, end() if not + template + typename Container::const_iterator find(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //removes element i from container c, returns false if c does not contain i + template + typename Container::size_type operator-=(Container &c, const Item &i) + { + typename Container::iterator itr = find(c,i); + if(itr == c.end()) + return false; + c.erase(itr); + return true; + } + + //assigns greater of (a, b) to a and returns maximum of (a, b) + template + t1 &amax(t1 &a, const t2 &b) + { + if(a >= b) + return a; + else + { + a = b; + return a; + } + } + + //assigns smaller of (a, b) to a and returns minimum of (a, b) + template + t1 &amin(t1 &a, const t2 &b) + { + if(a <= b) + return a; + else + { + a = b; + return a; + } + } + + //makes a to fit the range + template + t1 &abetween(t1 &a, const t2 &b, const t3 &c) + { + amax(a,b); + amin(a,c); + return a; + } + + //checks if a is between b and c + template + bool isbetween(const t1 &a, const t2 &b, const t3 &c) + { + return a > b && a < c; + } + + //checks if a is within b and c + template + bool iswithin(const t1 &a, const t2 &b, const t3 &c) + { + return a >= b && a <= c; + } + + template + struct assigner + { + public: + t1 &op1; + t2 op2; + assigner(t1 &a1, const t2 & a2) + :op1(a1), op2(a2) + {} + void operator()() + { + op1 = op2; + } + }; + + // Assigns value a2 to a1. The point of time of the real operation can be controlled + // with the () operator. + template + assigner assigno(t1 &a1, const t2 &a2) + { + return assigner(a1,a2); + } + + //deleted pointer and sets it to NULL + template + void clear_pointer(T* &ptr) + { + delete ptr; + ptr = NULL; + } +} +using vstd::operator-=; + +// can be used for counting arrays +template char (&_ArrayCountObj(const T (&)[N]))[N]; +#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) + +//for explicit overrides +#ifdef _MSC_VER +#define OVERRIDE override +#else +#define OVERRIDE //is there any working counterpart? +#endif + +//XXX pls dont - 'debug macros' are usually more trouble than it's worth +#define HANDLE_EXCEPTION \ + catch (const std::exception& e) { \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::exception * e) \ +{ \ + tlog1 << e->what()<< std::endl; \ + throw; \ +} \ + catch (const std::string& e) { \ + tlog1 << e << std::endl; \ + throw; \ +} + +#define HANDLE_EXCEPTIONC(COMMAND) \ + catch (const std::exception& e) { \ + COMMAND; \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::string &e) \ +{ \ + COMMAND; \ + tlog1 << e << std::endl; \ + throw; \ +} + + +#include "../../lib/CLogger.h" diff --git a/AI/StupidAI/StdInc.cpp b/AI/StupidAI/StdInc.cpp new file mode 100644 index 000000000..c8f4ddf05 --- /dev/null +++ b/AI/StupidAI/StdInc.cpp @@ -0,0 +1,2 @@ +// Creates the precompiled header +#include "StdInc.h" \ No newline at end of file diff --git a/AI/StupidAI/StdInc.h b/AI/StupidAI/StdInc.h new file mode 100644 index 000000000..5c3d9f243 --- /dev/null +++ b/AI/StupidAI/StdInc.h @@ -0,0 +1,325 @@ +#pragma once + +// Standard include file +// Should be treated as a precompiled header file in the compiler settings +// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio +// This file shouldn't be changed, except if there is a important header file which is missing. + +/* + * StdInc.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#ifdef _WIN32 +#include +#else +#include "../../tchar_amigaos4.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +//filesystem version 3 causes problems (and it's default as of boost 1.46) +#define BOOST_FILESYSTEM_VERSION 2 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef ANDROID +#include +#endif + +// Integral data types +typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) +typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) +typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) +typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) +typedef boost::int64_t si64; //signed int 64 bits (8 bytes) +typedef boost::int32_t si32; //signed int 32 bits (4 bytes) +typedef boost::int16_t si16; //signed int 16 bits (2 bytes) +typedef boost::int8_t si8; //signed int 8 bits (1 byte) + +// Import + Export macro declarations +#ifdef _WIN32 +#define DLL_EXPORT __declspec(dllexport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_EXPORT __attribute__ ((visibility("default"))) +#else +#define DLL_EXPORT +#endif +#endif + +#ifdef _WIN32 +#define DLL_IMPORT __declspec(dllimport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_IMPORT __attribute__ ((visibility("default"))) +#else +#define DLL_IMPORT +#endif +#endif + +#ifdef VCMI_DLL +#define DLL_LINKAGE DLL_EXPORT +#else +#define DLL_LINKAGE DLL_IMPORT +#endif + + +//a normal std::map with a const operator[] for sanity +template +class bmap : public std::map +{ +public: + const ValT & operator[](KeyT key) const + { + return find(key)->second; + } + ValT & operator[](KeyT key) + { + return static_cast &>(*this)[key]; + } + template void serialize(Handler &h, const int version) + { + h & static_cast &>(*this); + } +}; + +namespace vstd +{ + //returns true if container c contains item i + template + bool contains(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i) != c.end(); + } + + //returns true if map c contains item i + template + bool contains(const std::map & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if bmap c contains item i + template + bool contains(const bmap & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if unordered set c contains item i + template + bool contains(const boost::unordered_set & c, const Item &i) + { + return c.find(i)!=c.end(); + } + + //returns position of first element in vector c equal to s, if there is no such element, -1 is returned + template + int find_pos(const std::vector & c, const T2 &s) + { + for(size_t i=0; i < c.size(); ++i) + if(c[i] == s) + return i; + return -1; + } + + //Func(T1,T2) must say if these elements matches + template + int find_pos(const std::vector & c, const T2 &s, const Func &f) + { + for(size_t i=0; i < c.size(); ++i) + if(f(c[i],s)) + return i; + return -1; + } + + //returns iterator to the given element if present in container, end() if not + template + typename Container::iterator find(Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //returns const iterator to the given element if present in container, end() if not + template + typename Container::const_iterator find(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //removes element i from container c, returns false if c does not contain i + template + typename Container::size_type operator-=(Container &c, const Item &i) + { + typename Container::iterator itr = find(c,i); + if(itr == c.end()) + return false; + c.erase(itr); + return true; + } + + //assigns greater of (a, b) to a and returns maximum of (a, b) + template + t1 &amax(t1 &a, const t2 &b) + { + if(a >= b) + return a; + else + { + a = b; + return a; + } + } + + //assigns smaller of (a, b) to a and returns minimum of (a, b) + template + t1 &amin(t1 &a, const t2 &b) + { + if(a <= b) + return a; + else + { + a = b; + return a; + } + } + + //makes a to fit the range + template + t1 &abetween(t1 &a, const t2 &b, const t3 &c) + { + amax(a,b); + amin(a,c); + return a; + } + + //checks if a is between b and c + template + bool isbetween(const t1 &a, const t2 &b, const t3 &c) + { + return a > b && a < c; + } + + //checks if a is within b and c + template + bool iswithin(const t1 &a, const t2 &b, const t3 &c) + { + return a >= b && a <= c; + } + + template + struct assigner + { + public: + t1 &op1; + t2 op2; + assigner(t1 &a1, const t2 & a2) + :op1(a1), op2(a2) + {} + void operator()() + { + op1 = op2; + } + }; + + // Assigns value a2 to a1. The point of time of the real operation can be controlled + // with the () operator. + template + assigner assigno(t1 &a1, const t2 &a2) + { + return assigner(a1,a2); + } + + //deleted pointer and sets it to NULL + template + void clear_pointer(T* &ptr) + { + delete ptr; + ptr = NULL; + } +} +using vstd::operator-=; + +// can be used for counting arrays +template char (&_ArrayCountObj(const T (&)[N]))[N]; +#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) + +//for explicit overrides +#ifdef _MSC_VER +#define OVERRIDE override +#else +#define OVERRIDE //is there any working counterpart? +#endif + +//XXX pls dont - 'debug macros' are usually more trouble than it's worth +#define HANDLE_EXCEPTION \ + catch (const std::exception& e) { \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::exception * e) \ +{ \ + tlog1 << e->what()<< std::endl; \ + throw; \ +} \ + catch (const std::string& e) { \ + tlog1 << e << std::endl; \ + throw; \ +} + +#define HANDLE_EXCEPTIONC(COMMAND) \ + catch (const std::exception& e) { \ + COMMAND; \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::string &e) \ +{ \ + COMMAND; \ + tlog1 << e << std::endl; \ + throw; \ +} + + +#include "../../lib/CLogger.h" diff --git a/AI/StupidAI/stdafx.cpp b/AI/StupidAI/stdafx.cpp deleted file mode 100644 index a27b824da..000000000 --- a/AI/StupidAI/stdafx.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "stdafx.h" diff --git a/AI/StupidAI/stdafx.h b/AI/StupidAI/stdafx.h deleted file mode 100644 index 86113ee86..000000000 --- a/AI/StupidAI/stdafx.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#include -#include "../../AI_Base.h" \ No newline at end of file diff --git a/Scripting/ERM/StdInc.cpp b/Scripting/ERM/StdInc.cpp new file mode 100644 index 000000000..c8f4ddf05 --- /dev/null +++ b/Scripting/ERM/StdInc.cpp @@ -0,0 +1,2 @@ +// Creates the precompiled header +#include "StdInc.h" \ No newline at end of file diff --git a/Scripting/ERM/StdInc.h b/Scripting/ERM/StdInc.h new file mode 100644 index 000000000..5c3d9f243 --- /dev/null +++ b/Scripting/ERM/StdInc.h @@ -0,0 +1,325 @@ +#pragma once + +// Standard include file +// Should be treated as a precompiled header file in the compiler settings +// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio +// This file shouldn't be changed, except if there is a important header file which is missing. + +/* + * StdInc.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#ifdef _WIN32 +#include +#else +#include "../../tchar_amigaos4.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +//filesystem version 3 causes problems (and it's default as of boost 1.46) +#define BOOST_FILESYSTEM_VERSION 2 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef ANDROID +#include +#endif + +// Integral data types +typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) +typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) +typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) +typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) +typedef boost::int64_t si64; //signed int 64 bits (8 bytes) +typedef boost::int32_t si32; //signed int 32 bits (4 bytes) +typedef boost::int16_t si16; //signed int 16 bits (2 bytes) +typedef boost::int8_t si8; //signed int 8 bits (1 byte) + +// Import + Export macro declarations +#ifdef _WIN32 +#define DLL_EXPORT __declspec(dllexport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_EXPORT __attribute__ ((visibility("default"))) +#else +#define DLL_EXPORT +#endif +#endif + +#ifdef _WIN32 +#define DLL_IMPORT __declspec(dllimport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_IMPORT __attribute__ ((visibility("default"))) +#else +#define DLL_IMPORT +#endif +#endif + +#ifdef VCMI_DLL +#define DLL_LINKAGE DLL_EXPORT +#else +#define DLL_LINKAGE DLL_IMPORT +#endif + + +//a normal std::map with a const operator[] for sanity +template +class bmap : public std::map +{ +public: + const ValT & operator[](KeyT key) const + { + return find(key)->second; + } + ValT & operator[](KeyT key) + { + return static_cast &>(*this)[key]; + } + template void serialize(Handler &h, const int version) + { + h & static_cast &>(*this); + } +}; + +namespace vstd +{ + //returns true if container c contains item i + template + bool contains(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i) != c.end(); + } + + //returns true if map c contains item i + template + bool contains(const std::map & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if bmap c contains item i + template + bool contains(const bmap & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if unordered set c contains item i + template + bool contains(const boost::unordered_set & c, const Item &i) + { + return c.find(i)!=c.end(); + } + + //returns position of first element in vector c equal to s, if there is no such element, -1 is returned + template + int find_pos(const std::vector & c, const T2 &s) + { + for(size_t i=0; i < c.size(); ++i) + if(c[i] == s) + return i; + return -1; + } + + //Func(T1,T2) must say if these elements matches + template + int find_pos(const std::vector & c, const T2 &s, const Func &f) + { + for(size_t i=0; i < c.size(); ++i) + if(f(c[i],s)) + return i; + return -1; + } + + //returns iterator to the given element if present in container, end() if not + template + typename Container::iterator find(Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //returns const iterator to the given element if present in container, end() if not + template + typename Container::const_iterator find(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //removes element i from container c, returns false if c does not contain i + template + typename Container::size_type operator-=(Container &c, const Item &i) + { + typename Container::iterator itr = find(c,i); + if(itr == c.end()) + return false; + c.erase(itr); + return true; + } + + //assigns greater of (a, b) to a and returns maximum of (a, b) + template + t1 &amax(t1 &a, const t2 &b) + { + if(a >= b) + return a; + else + { + a = b; + return a; + } + } + + //assigns smaller of (a, b) to a and returns minimum of (a, b) + template + t1 &amin(t1 &a, const t2 &b) + { + if(a <= b) + return a; + else + { + a = b; + return a; + } + } + + //makes a to fit the range + template + t1 &abetween(t1 &a, const t2 &b, const t3 &c) + { + amax(a,b); + amin(a,c); + return a; + } + + //checks if a is between b and c + template + bool isbetween(const t1 &a, const t2 &b, const t3 &c) + { + return a > b && a < c; + } + + //checks if a is within b and c + template + bool iswithin(const t1 &a, const t2 &b, const t3 &c) + { + return a >= b && a <= c; + } + + template + struct assigner + { + public: + t1 &op1; + t2 op2; + assigner(t1 &a1, const t2 & a2) + :op1(a1), op2(a2) + {} + void operator()() + { + op1 = op2; + } + }; + + // Assigns value a2 to a1. The point of time of the real operation can be controlled + // with the () operator. + template + assigner assigno(t1 &a1, const t2 &a2) + { + return assigner(a1,a2); + } + + //deleted pointer and sets it to NULL + template + void clear_pointer(T* &ptr) + { + delete ptr; + ptr = NULL; + } +} +using vstd::operator-=; + +// can be used for counting arrays +template char (&_ArrayCountObj(const T (&)[N]))[N]; +#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) + +//for explicit overrides +#ifdef _MSC_VER +#define OVERRIDE override +#else +#define OVERRIDE //is there any working counterpart? +#endif + +//XXX pls dont - 'debug macros' are usually more trouble than it's worth +#define HANDLE_EXCEPTION \ + catch (const std::exception& e) { \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::exception * e) \ +{ \ + tlog1 << e->what()<< std::endl; \ + throw; \ +} \ + catch (const std::string& e) { \ + tlog1 << e << std::endl; \ + throw; \ +} + +#define HANDLE_EXCEPTIONC(COMMAND) \ + catch (const std::exception& e) { \ + COMMAND; \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::string &e) \ +{ \ + COMMAND; \ + tlog1 << e << std::endl; \ + throw; \ +} + + +#include "../../lib/CLogger.h" diff --git a/client/BattleInterface/CAttackAnimation.cpp b/client/BattleInterface/CAttackAnimation.cpp new file mode 100644 index 000000000..517dbff7d --- /dev/null +++ b/client/BattleInterface/CAttackAnimation.cpp @@ -0,0 +1,51 @@ +#include "StdInc.h" +#include "CAttackAnimation.h" + +#include "../CMusicHandler.h" +#include "../CGameInfo.h" +#include "CBattleInterface.h" +#include "../CCreatureAnimation.h" +#include "../../lib/BattleState.h" +#include "../CPlayerInterface.h" +#include "../../CCallback.h" + +void CAttackAnimation::nextFrame() +{ + if(myAnim()->getType() != group) + myAnim()->setType(group); + + if(myAnim()->onFirstFrameInGroup()) + { + if(shooting) + CCS->soundh->playSound(battle_sound(attackingStack->getCreature(), shoot)); + else + CCS->soundh->playSound(battle_sound(attackingStack->getCreature(), attack)); + } + else if(myAnim()->onLastFrameInGroup()) + { + myAnim()->setType(CCreatureAnim::HOLDING); + endAnim(); + return; //execution of endAnim deletes this !!! + } +} + +bool CAttackAnimation::checkInitialConditions() +{ + return isEarliest(false); +} + +CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SHexField _dest, const CStack *defender) +: CBattleStackAnimation(_owner, attacker), dest(_dest), attackedStack(defender), attackingStack(attacker) +{ + + assert(attackingStack && "attackingStack is NULL in CBattleAttack::CBattleAttack !\n"); + if(attackingStack->getCreature()->idNumber != 145) //catapult is allowed to attack not-creature + { + assert(attackedStack && "attackedStack is NULL in CBattleAttack::CBattleAttack !\n"); + } + else //catapult can attack walls only + { + assert(owner->curInt->cb->battleGetWallUnderHex(_dest) >= 0); + } + attackingStackPosBeforeReturn = attackingStack->position; +} \ No newline at end of file diff --git a/client/BattleInterface/CAttackAnimation.h b/client/BattleInterface/CAttackAnimation.h new file mode 100644 index 000000000..7e4426744 --- /dev/null +++ b/client/BattleInterface/CAttackAnimation.h @@ -0,0 +1,35 @@ +#pragma once + +#include "CBattleStackAnimation.h" +#include "../CAnimation.h" +#include "../../lib/SHexField.h" + +class CBattleInterface; +class CStack; + +/* + * CAttackAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// This class is responsible for managing the battle attack animation +class CAttackAnimation : public CBattleStackAnimation +{ +protected: + SHexField dest; //attacked hex + bool shooting; + CCreatureAnim::EAnimType group; //if shooting is true, print this animation group + const CStack *attackedStack; + const CStack *attackingStack; + int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature +public: + void nextFrame(); + bool checkInitialConditions(); + + CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SHexField _dest, const CStack *defender); +}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleAnimation.cpp b/client/BattleInterface/CBattleAnimation.cpp new file mode 100644 index 000000000..8f7fa0e7e --- /dev/null +++ b/client/BattleInterface/CBattleAnimation.cpp @@ -0,0 +1,49 @@ +#include "StdInc.h" +#include "CBattleAnimation.h" +#include "CBattleInterface.h" +#include "../../lib/BattleState.h" +#include "CSpellEffectAnimation.h" +#include "CReverseAnimation.h" + +void CBattleAnimation::endAnim() +{ + for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + if(it->first == this) + { + it->first = NULL; + } + } + +} + +bool CBattleAnimation::isEarliest(bool perStackConcurrency) +{ + int lowestMoveID = owner->animIDhelper + 5; + CBattleStackAnimation * thAnim = dynamic_cast(this); + CSpellEffectAnimation * thSen = dynamic_cast(this); + + for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + CBattleStackAnimation * stAnim = dynamic_cast(it->first); + CSpellEffectAnimation * sen = dynamic_cast(it->first); + if(perStackConcurrency && stAnim && thAnim && stAnim->stack->ID != thAnim->stack->ID) + continue; + + if(sen && thSen && sen != thSen && perStackConcurrency) + continue; + + CReverseAnimation * revAnim = dynamic_cast(stAnim); + + if(revAnim && thAnim && stAnim && stAnim->stack->ID == thAnim->stack->ID && revAnim->priority) + return false; + + if(it->first) + vstd::amin(lowestMoveID, it->first->ID); + } + return (ID == lowestMoveID) || (lowestMoveID == (owner->animIDhelper + 5)); +} + +CBattleAnimation::CBattleAnimation(CBattleInterface * _owner) + : owner(_owner), ID(_owner->animIDhelper++) +{} \ No newline at end of file diff --git a/client/BattleInterface/CBattleAnimation.h b/client/BattleInterface/CBattleAnimation.h new file mode 100644 index 000000000..99902f414 --- /dev/null +++ b/client/BattleInterface/CBattleAnimation.h @@ -0,0 +1,30 @@ +#pragma once + +class CBattleInterface; + +/* + * CBattleAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Base class of battle animations +class CBattleAnimation +{ +protected: + CBattleInterface * owner; +public: + virtual bool init()=0; //to be called - if returned false, call again until returns true + virtual void nextFrame()=0; //call every new frame + virtual void endAnim(); //to be called mostly internally; in this class it removes animation from pendingAnims list + + bool isEarliest(bool perStackConcurrency); //determines if this animation is earliest of all + + ui32 ID; //unique identifier + + CBattleAnimation(CBattleInterface * _owner); +}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleConsole.cpp b/client/BattleInterface/CBattleConsole.cpp new file mode 100644 index 000000000..c147fd4a3 --- /dev/null +++ b/client/BattleInterface/CBattleConsole.cpp @@ -0,0 +1,84 @@ +#include "StdInc.h" +#include "CBattleConsole.h" +#include "../SDL_Extensions.h" + +CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt(""), whoSetAlter(0) +{ +} + +CBattleConsole::~CBattleConsole() +{ + texts.clear(); +} + +void CBattleConsole::show(SDL_Surface * to) +{ + if(ingcAlter.size()) + { + CSDL_Ext::printAtMiddleWB(ingcAlter, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); + } + else if(alterTxt.size()) + { + CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); + } + else if(texts.size()) + { + if(texts.size()==1) + { + CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); + } + else + { + CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); + CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 27, FONT_SMALL, 80, zwykly, to); + } + } +} + +bool CBattleConsole::addText(const std::string & text) +{ + if(text.size()>70) + return false; //text too long! + int firstInToken = 0; + for(size_t i = 0; i < text.size(); ++i) //tokenize + { + if(text[i] == 10) + { + texts.push_back( text.substr(firstInToken, i-firstInToken) ); + firstInToken = i+1; + } + } + + texts.push_back( text.substr(firstInToken, text.size()) ); + lastShown = texts.size()-1; + return true; +} + +void CBattleConsole::eraseText(ui32 pos) +{ + if(pos < texts.size()) + { + texts.erase(texts.begin() + pos); + if(lastShown == texts.size()) + --lastShown; + } +} + +void CBattleConsole::changeTextAt(const std::string & text, ui32 pos) +{ + if(pos >= texts.size()) //no such pos + return; + texts[pos] = text; +} + +void CBattleConsole::scrollUp(ui32 by) +{ + if(lastShown > static_cast(by)) + lastShown -= by; +} + +void CBattleConsole::scrollDown(ui32 by) +{ + if(lastShown + by < texts.size()) + lastShown += by; +} \ No newline at end of file diff --git a/client/BattleInterface/CBattleConsole.h b/client/BattleInterface/CBattleConsole.h new file mode 100644 index 000000000..dc4adad3f --- /dev/null +++ b/client/BattleInterface/CBattleConsole.h @@ -0,0 +1,35 @@ +#pragma once + +#include "../GUIBase.h" + +struct SDL_Surface; + +/* + * CBattleConsole.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Class which shows the console at the bottom of the battle screen and manages the text of the console +class CBattleConsole : public CIntObject +{ +private: + std::vector< std::string > texts; //a place where texts are stored + int lastShown; //last shown line of text +public: + std::string alterTxt; //if it's not empty, this text is displayed + std::string ingcAlter; //alternative text set by in-game console - very important! + int whoSetAlter; //who set alter text; 0 - battle interface or none, 1 - button + CBattleConsole(); //c-tor + ~CBattleConsole(); //d-tor + void show(SDL_Surface *to = 0); + bool addText(const std::string &text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters) + void eraseText(ui32 pos); //erases added text at position pos + void changeTextAt(const std::string &text, ui32 pos); //if we have more than pos texts, pos-th is changed to given one + void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions + void scrollDown(ui32 by = 1); //scrolls console up by 'by' positions +}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleHero.cpp b/client/BattleInterface/CBattleHero.cpp new file mode 100644 index 000000000..a9b1d80b2 --- /dev/null +++ b/client/BattleInterface/CBattleHero.cpp @@ -0,0 +1,153 @@ +#include "StdInc.h" +#include "CBattleHero.h" +#include "CBattleInterface.h" +#include "../CGameInfo.h" +#include "../CDefHandler.h" +#include "../CCursorHandler.h" +#include "../CPlayerInterface.h" +#include "../../CCallback.h" +#include "../SDL_Extensions.h" +#include "../CSpellWindow.h" +#include "../Graphics.h" +#include "../CConfigHandler.h" + +void CBattleHero::show(SDL_Surface *to) +{ + //animation of flag + if(flip) + { + SDL_Rect temp_rect = genRect( + flag->ourImages[flagAnim].bitmap->h, + flag->ourImages[flagAnim].bitmap->w, + pos.x + 61, + pos.y + 39); + CSDL_Ext::blit8bppAlphaTo24bpp( + flag->ourImages[flagAnim].bitmap, + NULL, + screen, + &temp_rect); + } + else + { + SDL_Rect temp_rect = genRect( + flag->ourImages[flagAnim].bitmap->h, + flag->ourImages[flagAnim].bitmap->w, + pos.x + 72, + pos.y + 39); + CSDL_Ext::blit8bppAlphaTo24bpp( + flag->ourImages[flagAnim].bitmap, + NULL, + screen, + &temp_rect); + } + ++flagAnimCount; + if(flagAnimCount%4==0) + { + ++flagAnim; + flagAnim %= flag->ourImages.size(); + } + //animation of hero + int tick=-1; + for(size_t i = 0; i < dh->ourImages.size(); ++i) + { + if(dh->ourImages[i].groupNumber==phase) + ++tick; + if(tick==image) + { + SDL_Rect posb = pos; + CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb); + if(phase != 4 || nextPhase != -1 || image < 4) + { + if(flagAnimCount%2==0) + { + ++image; + } + if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame + { + image = 0; + } + } + if(phase == 4 && nextPhase != -1 && image == 7) + { + phase = nextPhase; + nextPhase = -1; + image = 0; + } + break; + } + } +} + +void CBattleHero::activate() +{ + activateLClick(); +} +void CBattleHero::deactivate() +{ + deactivateLClick(); +} + +void CBattleHero::setPhase(int newPhase) +{ + if(phase != 4) + { + phase = newPhase; + image = 0; + } + else + { + nextPhase = newPhase; + } +} + +void CBattleHero::clickLeft(tribool down, bool previousState) +{ + if(myOwner->spellDestSelectMode) //we are casting a spell + return; + + if(!down && myHero != NULL && myOwner->myTurn && myOwner->curInt->cb->battleCanCastSpell()) //check conditions + { + for(int it=0; itbfield[it].hovered && myOwner->bfield[it].strictHovered) + return; + } + CCS->curh->changeGraphic(0,0); + + CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), myHero, myOwner->curInt); + GH.pushInt(spellWindow); + } +} + +CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, ui8 player, const CGHeroInstance * hero, const CBattleInterface * owner): flip(flipG), myHero(hero), myOwner(owner), phase(phaseG), nextPhase(-1), image(imageG), flagAnim(0), flagAnimCount(0) +{ + dh = CDefHandler::giveDef( defName ); + for(size_t i = 0; i < dh->ourImages.size(); ++i) //transforming images + { + if(flip) + { + SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap); + SDL_FreeSurface(dh->ourImages[i].bitmap); + dh->ourImages[i].bitmap = hlp; + } + CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap); + } + + if(flip) + flag = CDefHandler::giveDef("CMFLAGR.DEF"); + else + flag = CDefHandler::giveDef("CMFLAGL.DEF"); + + //coloring flag and adding transparency + for(size_t i = 0; i < flag->ourImages.size(); ++i) + { + CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap); + graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player); + } +} + +CBattleHero::~CBattleHero() +{ + delete dh; + delete flag; +} \ No newline at end of file diff --git a/client/BattleInterface/CBattleHero.h b/client/BattleInterface/CBattleHero.h new file mode 100644 index 000000000..3a34e4fe5 --- /dev/null +++ b/client/BattleInterface/CBattleHero.h @@ -0,0 +1,39 @@ +#pragma once + +#include "../GUIBase.h" + +class CBattleInterface; +class CDefHandler; +class CGHeroInstance; +struct SDL_Surface; + +/* + * CBattleHero.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Hero battle animation +class CBattleHero : public CIntObject +{ +public: + bool flip; //false if it's attacking hero, true otherwise + CDefHandler *dh, *flag; //animation and flag + const CGHeroInstance *myHero; //this animation's hero instance + const CBattleInterface *myOwner; //battle interface to which this animation is assigned + int phase; //stage of animation + int nextPhase; //stage of animation to be set after current phase is fully displayed + int image; //frame of animation + ui8 flagAnim, flagAnimCount; //for flag animation + void show(SDL_Surface *to); //prints next frame of animation to to + void activate(); + void deactivate(); + void setPhase(int newPhase); //sets phase of hero animation + void clickLeft(tribool down, bool previousState); //call-in + CBattleHero(const std::string &defName, int phaseG, int imageG, bool filpG, ui8 player, const CGHeroInstance *hero, const CBattleInterface *owner); //c-tor + ~CBattleHero(); //d-tor +}; \ No newline at end of file diff --git a/client/CBattleInterface.cpp b/client/BattleInterface/CBattleInterface.cpp similarity index 57% rename from client/CBattleInterface.cpp rename to client/BattleInterface/CBattleInterface.cpp index a45bc72b0..9995fdf89 100644 --- a/client/CBattleInterface.cpp +++ b/client/BattleInterface/CBattleInterface.cpp @@ -1,37 +1,53 @@ +#include "StdInc.h" #include "CBattleInterface.h" -#include "CGameInfo.h" -#include "../lib/CLodHandler.h" -#include "SDL_Extensions.h" -#include "CAdvmapInterface.h" -#include "AdventureMapButton.h" -#include "CAnimation.h" -#include "../lib/CObjectHandler.h" -#include "../lib/CHeroHandler.h" -#include "CDefHandler.h" -#include "../lib/CSpellHandler.h" -#include "CMusicHandler.h" -#include "CMessage.h" -#include "CCursorHandler.h" -#include "../CCallback.h" -#include "../lib/BattleState.h" -#include "../lib/CGeneralTextHandler.h" -#include "CCreatureAnimation.h" -#include "Graphics.h" -#include "CSpellWindow.h" -#include "CConfigHandler.h" -#include -#include -#include "../lib/CondSh.h" -#include "../lib/NetPacks.h" -#include "CPlayerInterface.h" -#include "CCreatureWindow.h" -#include "CVideoHandler.h" -#include "../lib/CTownHandler.h" -#include "../lib/map.h" -#include -#include -#include -#include + +#include "../CGameInfo.h" +#include "../../lib/CLodHandler.h" +#include "../SDL_Extensions.h" +#include "../CAdvmapInterface.h" +#include "../AdventureMapButton.h" +#include "../CAnimation.h" +#include "../../lib/CObjectHandler.h" +#include "../../lib/CHeroHandler.h" +#include "../CDefHandler.h" +#include "../../lib/CSpellHandler.h" +#include "../CMusicHandler.h" +#include "../CMessage.h" +#include "../CCursorHandler.h" +#include "../../CCallback.h" +#include "../../lib/BattleState.h" +#include "../../lib/CGeneralTextHandler.h" +#include "../CCreatureAnimation.h" +#include "../Graphics.h" +#include "../CSpellWindow.h" +#include "../CConfigHandler.h" +#include "../../lib/CondSh.h" +#include "../../lib/NetPacks.h" +#include "../CPlayerInterface.h" +#include "../CCreatureWindow.h" +#include "../CVideoHandler.h" +#include "../../lib/CTownHandler.h" +#include "../../lib/map.h" + + +#include "CBattleHero.h" +#include "CStackQueue.h" +#include "CBattleConsole.h" +#include "CBattleResultWindow.h" +#include "CBattleAnimation.h" +#include "CBattleOptionsWindow.h" +#include "CDummyAnimation.h" +#include "CHexFieldControl.h" +#include "CShootingAnimation.h" +#include "CSpellEffectAnimation.h" +#include "CMeleeAttackAnimation.h" +#include "CReverseAnimation.h" +#include "CMovementStartAnimation.h" +#include "CMovementEndAnimation.h" +#include "CDefenceAnimation.h" +#include "CMovementAnimation.h" + + #ifndef __GNUC__ const double M_PI = 3.14159265358979323846; #else @@ -65,7 +81,7 @@ struct CMP_stack2 } } cmpst2 ; -static void transformPalette(SDL_Surface * surf, float rCor, float gCor, float bCor) +static void transformPalette(SDL_Surface * surf, double rCor, double gCor, double bCor) { SDL_Color * colorsToChange = surf->format->palette->colors; for(int g=0; gformat->palette->ncolors; ++g) @@ -74,1107 +90,13 @@ static void transformPalette(SDL_Surface * surf, float rCor, float gCor, float b (colorsToChange+g)->g != 231 && (colorsToChange+g)->r != 255) //it's not yellow border { - (colorsToChange+g)->r = (float)((colorsToChange+g)->r) * rCor; - (colorsToChange+g)->g = (float)((colorsToChange+g)->g) * gCor; - (colorsToChange+g)->b = (float)((colorsToChange+g)->b) * bCor; + (colorsToChange+g)->r = static_cast((colorsToChange+g)->r) * rCor; + (colorsToChange+g)->g = static_cast((colorsToChange+g)->g) * gCor; + (colorsToChange+g)->b = static_cast((colorsToChange+g)->b) * bCor; } } } -////////////////////////Battle helpers - -//general anim - -void CBattleAnimation::endAnim() -{ - for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - if(it->first == this) - { - it->first = NULL; - } - } - -} - -bool CBattleAnimation::isEarliest(bool perStackConcurrency) -{ - int lowestMoveID = owner->animIDhelper + 5; - CBattleStackAnimation * thAnim = dynamic_cast(this); - CSpellEffectAnim * thSen = dynamic_cast(this); - - for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - CBattleStackAnimation * stAnim = dynamic_cast(it->first); - CSpellEffectAnim * sen = dynamic_cast(it->first); - if(perStackConcurrency && stAnim && thAnim && stAnim->stack->ID != thAnim->stack->ID) - continue; - - if(sen && thSen && sen != thSen && perStackConcurrency) - continue; - - CReverseAnim * revAnim = dynamic_cast(stAnim); - - if(revAnim && thAnim && stAnim && stAnim->stack->ID == thAnim->stack->ID && revAnim->priority) - return false; - - if(it->first) - amin(lowestMoveID, it->first->ID); - } - return ID == lowestMoveID || lowestMoveID == (owner->animIDhelper + 5); -} - -CBattleAnimation::CBattleAnimation(CBattleInterface * _owner) -: owner(_owner), ID(_owner->animIDhelper++) -{} - -//Dummy animation - - -bool CDummyAnim::init() -{ - return true; -} - -void CDummyAnim::nextFrame() -{ - counter++; - if(counter > howMany) - endAnim(); -} - -void CDummyAnim::endAnim() -{ - CBattleAnimation::endAnim(); - - delete this; -} - -CDummyAnim::CDummyAnim(CBattleInterface * _owner, int howManyFrames) : CBattleAnimation(_owner), counter(0), howMany(howManyFrames) -{ -} - - -//effect animation -bool CSpellEffectAnim::init() -{ - if(!isEarliest(true)) - return false; - - if(effect == 12) //armageddon - { - if(effect == -1 || graphics->battleACToDef[effect].size() != 0) - { - CDefHandler * anim; - if(customAnim.size()) - anim = CDefHandler::giveDef(customAnim); - else - anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); - - if (Vflip) - { - for (int v=0; vourImages.size(); ++v) - { - CSDL_Ext::VflipSurf(anim->ourImages[v].bitmap); - } - } - - for(int i=0; i * anim->width < owner->pos.w ; ++i) - { - for(int j=0; j * anim->height < owner->pos.h ; ++j) - { - SBattleEffect be; - be.effectID = ID; - be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); - if (Vflip) - { - for (int v=0; vourImages.size(); ++v) - { - CSDL_Ext::VflipSurf(be.anim->ourImages[v].bitmap); - } - } - be.frame = 0; - be.maxFrame = be.anim->ourImages.size(); - be.x = i * anim->width + owner->pos.x; - be.y = j * anim->height + owner->pos.y; - - owner->battleEffects.push_back(be); - } - } - } - else //there is nothing to play - { - endAnim(); - return false; - } - } - else // Effects targeted at a specific creature/hex. - { - if(effect == -1 || graphics->battleACToDef[effect].size() != 0) - { - const CStack* destStack = owner->curInt->cb->battleGetStackByPos(destTile, false); - Rect &tilePos = owner->bfield[destTile].pos; - SBattleEffect be; - be.effectID = ID; - if(customAnim.size()) - be.anim = CDefHandler::giveDef(customAnim); - else - be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); - - if (Vflip) - { - for (int v=0; vourImages.size(); ++v) - { - CSDL_Ext::VflipSurf(be.anim->ourImages[v].bitmap); - } - } - - be.frame = 0; - be.maxFrame = be.anim->ourImages.size(); - if(effect == 1) - be.maxFrame = 3; - - switch (effect) - { - case -1: - be.x = x; - be.y = y; - break; - case 0: // Prayer and Lightning Bolt. - case 1: - // Position effect with it's bottom center touching the bottom center of affected tile(s). - be.x = tilePos.x + tilePos.w/2 - be.anim->width/2; - be.y = tilePos.y + tilePos.h - be.anim->height; - break; - - default: - // Position effect with it's center touching the top center of affected tile(s). - be.x = tilePos.x + tilePos.w/2 - be.anim->width/2; - be.y = tilePos.y - be.anim->height/2; - break; - } - - // Correction for 2-hex creatures. - if (destStack != NULL && destStack->doubleWide()) - be.x += (destStack->attackerOwned ? -1 : 1)*tilePos.w/2; - - owner->battleEffects.push_back(be); - } - else //there is nothing to play - { - endAnim(); - return false; - } - } - //battleEffects - return true; -} - -void CSpellEffectAnim::nextFrame() -{ - //notice: there may be more than one effect in owner->battleEffects correcponding to this animation (ie. armageddon) - for(std::list::iterator it = owner->battleEffects.begin(); it != owner->battleEffects.end(); ++it) - { - if(it->effectID == ID) - { - ++(it->frame); - - if(it->frame == it->maxFrame) - { - endAnim(); - break; - } - else - { - it->x += dx; - it->y += dy; - } - } - } -} - -void CSpellEffectAnim::endAnim() -{ - CBattleAnimation::endAnim(); - - std::vector::iterator> toDel; - - for(std::list::iterator it = owner->battleEffects.begin(); it != owner->battleEffects.end(); ++it) - { - if(it->effectID == ID) - { - toDel.push_back(it); - } - } - - for(int b=0; banim; - owner->battleEffects.erase(toDel[b]); - } - - delete this; -} - -CSpellEffectAnim::CSpellEffectAnim(CBattleInterface * _owner, ui32 _effect, THex _destTile, int _dx, int _dy, bool _Vflip) -:CBattleAnimation(_owner), effect(_effect), destTile(_destTile), customAnim(""), dx(_dx), dy(_dy), Vflip(_Vflip) -{ -} - -CSpellEffectAnim::CSpellEffectAnim(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx, int _dy, bool _Vflip) -:CBattleAnimation(_owner), effect(-1), destTile(0), customAnim(_customAnim), x(_x), y(_y), dx(_dx), dy(_dy), Vflip(_Vflip) -{ -} - -//stack's aniamtion - -CBattleStackAnimation::CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack) -: CBattleAnimation(_owner), stack(_stack) -{ -} - -bool CBattleStackAnimation::isToReverseHlp(THex hexFrom, THex hexTo, bool curDir) -{ - int fromMod = hexFrom % BFIELD_WIDTH; - int fromDiv = hexFrom / BFIELD_WIDTH; - int toMod = hexTo % BFIELD_WIDTH; - - if(curDir && fromMod < toMod) - return false; - else if(curDir && fromMod > toMod) - return true; - else if(curDir && fromMod == toMod) - { - return fromDiv % 2 == 0; - } - else if(!curDir && fromMod < toMod) - return true; - else if(!curDir && fromMod > toMod) - return false; - else if(!curDir && fromMod == toMod) - { - return fromDiv % 2 == 1; - } - tlog1 << "Catastrope in CBattleStackAnimation::isToReverse!" << std::endl; - return false; //should never happen -} - -bool CBattleStackAnimation::isToReverse(THex hexFrom, THex hexTo, bool curDir, bool toDoubleWide, bool toDir) -{ - if(hexTo < 0) //turret - return false; - - if(toDoubleWide) - { - return isToReverseHlp(hexFrom, hexTo, curDir) && - (toDir ? isToReverseHlp(hexFrom, hexTo-1, curDir) : isToReverseHlp(hexFrom, hexTo+1, curDir) ); - } - else - { - return isToReverseHlp(hexFrom, hexTo, curDir); - } -} - -CCreatureAnimation * CBattleStackAnimation::myAnim() -{ - return owner->creAnims[stack->ID]; -} - -//revering animation - -bool CReverseAnim::init() -{ - if(myAnim() == NULL || myAnim()->getType() == 5) - { - endAnim(); - - return false; //there is no such creature - } - - if(!priority && !isEarliest(false)) - return false; - - if(myAnim()->framesInGroup(CCreatureAnim::TURN_R)) - myAnim()->setType(CCreatureAnim::TURN_R); - else - setupSecondPart(); - - - return true; -} - -void CReverseAnim::nextFrame() -{ - if(partOfAnim == 1) //first part of animation - { - if(myAnim()->onLastFrameInGroup()) - { - partOfAnim = 2; - } - } - else if(partOfAnim == 2) - { - if(!secondPartSetup) - { - setupSecondPart(); - } - if(myAnim()->onLastFrameInGroup()) - { - endAnim(); - } - } -} - -void CReverseAnim::endAnim() -{ - CBattleAnimation::endAnim(); - if( stack->alive() )//don't do that if stack is dead - myAnim()->setType(CCreatureAnim::HOLDING); - - delete this; -} - -CReverseAnim::CReverseAnim(CBattleInterface * _owner, const CStack * stack, THex dest, bool _priority) -: CBattleStackAnimation(_owner, stack), partOfAnim(1), secondPartSetup(false), hex(dest), priority(_priority) -{ -} - -void CReverseAnim::setupSecondPart() -{ - owner->creDir[stack->ID] = !owner->creDir[stack->ID]; - - if(!stack) - { - endAnim(); - return; - } - - Point coords = CBattleHex::getXYUnitAnim(hex, owner->creDir[stack->ID], stack, owner); - myAnim()->pos.x = coords.x; - //creAnims[stackID]->pos.y = coords.second; - - if(stack->doubleWide()) - { - if(stack->attackerOwned) - { - if(!owner->creDir[stack->ID]) - myAnim()->pos.x -= 44; - } - else - { - if(owner->creDir[stack->ID]) - myAnim()->pos.x += 44; - } - } - - secondPartSetup = true; - - if(myAnim()->framesInGroup(CCreatureAnim::TURN_L)) - myAnim()->setType(CCreatureAnim::TURN_L); - else - endAnim(); -} - -//defence anim - -bool CDefenceAnim::init() -{ - //checking initial conditions - - //if(owner->creAnims[stackID]->getType() != 2) - //{ - // return false; - //} - - if(attacker == NULL && owner->battleEffects.size() > 0) - return false; - - int lowestMoveID = owner->animIDhelper + 5; - for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - CDefenceAnim * defAnim = dynamic_cast(it->first); - if(defAnim && defAnim->stack->ID != stack->ID) - continue; - - CBattleAttack * attAnim = dynamic_cast(it->first); - if(attAnim && attAnim->stack->ID != stack->ID) - continue; - - if(attacker != NULL) - { - int attackerAnimType = owner->creAnims[attacker->ID]->getType(); - if( attackerAnimType == 11 && attackerAnimType == 12 && attackerAnimType == 13 && owner->creAnims[attacker->ID]->getFrame() < attacker->getCreature()->attackClimaxFrame ) - return false; - } - - CReverseAnim * animAsRev = dynamic_cast(it->first); - - if(animAsRev && animAsRev->priority) - return false; - - if(it->first) - amin(lowestMoveID, it->first->ID); - } - if(ID > lowestMoveID) - return false; - - - - //reverse unit if necessary - if(attacker && isToReverse(stack->position, attacker->position, owner->creDir[stack->ID], attacker->doubleWide(), owner->creDir[attacker->ID])) - { - owner->addNewAnim(new CReverseAnim(owner, stack, stack->position, true)); - return false; - } - //unit reversed - - if(byShooting) //delay hit animation - { - for(std::list::const_iterator it = owner->projectiles.begin(); it != owner->projectiles.end(); ++it) - { - if(it->creID == attacker->getCreature()->idNumber) - { - return false; - } - } - } - - //initializing - if(killed) - { - CCS->soundh->playSound(battle_sound(stack->getCreature(), killed)); - myAnim()->setType(CCreatureAnim::DEATH); //death - } - else - { - // TODO: this block doesn't seems correct if the unit is defending. - CCS->soundh->playSound(battle_sound(stack->getCreature(), wince)); - myAnim()->setType(CCreatureAnim::HITTED); //getting hit - } - - return true; //initialized successfuly -} - -void CDefenceAnim::nextFrame() -{ - if(!killed && myAnim()->getType() != CCreatureAnim::HITTED) - { - myAnim()->setType(CCreatureAnim::HITTED); - } - - if(!myAnim()->onLastFrameInGroup()) - { - if( myAnim()->getType() == CCreatureAnim::DEATH && (owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0 - && !myAnim()->onLastFrameInGroup() ) - { - myAnim()->incrementFrame(); - } - } - else - { - endAnim(); - } - -} - -void CDefenceAnim::endAnim() -{ - //restoring animType - - if(myAnim()->getType() == CCreatureAnim::HITTED) - myAnim()->setType(CCreatureAnim::HOLDING); - - //printing info to console - - //if(attacker!=NULL) - // owner->printConsoleAttacked(stack, dmg, amountKilled, attacker); - - //const CStack * attacker = owner->curInt->cb->battleGetStackByID(IDby, false); - //const CStack * attacked = owner->curInt->cb->battleGetStackByID(stackID, false); - - CBattleAnimation::endAnim(); - - delete this; -} - -CDefenceAnim::CDefenceAnim(SStackAttackedInfo _attackedInfo, CBattleInterface * _owner) -: CBattleStackAnimation(_owner, _attackedInfo.defender), dmg(_attackedInfo.dmg), - amountKilled(_attackedInfo.amountKilled), attacker(_attackedInfo.attacker), byShooting(_attackedInfo.byShooting), - killed(_attackedInfo.killed) -{ -} - -////move anim - -bool CBattleStackMoved::init() -{ - if( !isEarliest(false) ) - return false; - - //a few useful variables - steps = myAnim()->framesInGroup(CCreatureAnim::MOVING)*owner->getAnimSpeedMultiplier()-1; - if(steps == 0) //this creature seems to have no move animation so we can end it immediately - { - endAnim(); - return false; - } - whichStep = 0; - int hexWbase = 44, hexHbase = 42; - const CStack * movedStack = stack; - if(!movedStack || myAnim()->getType() == 5) - { - endAnim(); - return false; - } - //bool twoTiles = movedStack->doubleWide(); - - Point begPosition = CBattleHex::getXYUnitAnim(curStackPos, movedStack->attackerOwned, movedStack, owner); - Point endPosition = CBattleHex::getXYUnitAnim(nextHex, movedStack->attackerOwned, movedStack, owner); - - int mutPos = THex::mutualPosition(curStackPos, nextHex); - - //reverse unit if necessary - if((begPosition.x > endPosition.x) && owner->creDir[stack->ID] == true) - { - owner->addNewAnim(new CReverseAnim(owner, stack, curStackPos, true)); - return false; - } - else if ((begPosition.x < endPosition.x) && owner->creDir[stack->ID] == false) - { - owner->addNewAnim(new CReverseAnim(owner, stack, curStackPos, true)); - return false; - } - - if(myAnim()->getType() != CCreatureAnim::MOVING) - { - myAnim()->setType(CCreatureAnim::MOVING); - } - //unit reversed - -// if(owner->moveSh <= 0) -// owner->moveSh = CCS->soundh->playSound(battle_sound(movedStack->getCreature(), move), -1); - - //step shift calculation - posX = myAnim()->pos.x, posY = myAnim()->pos.y; // for precise calculations ;] - if(mutPos == -1 && movedStack->hasBonusOfType(Bonus::FLYING)) - { - steps *= distance; - steps /= 2; //to make animation faster - - stepX = (endPosition.x - (float)begPosition.x)/steps; - stepY = (endPosition.y - (float)begPosition.y)/steps; - } - else - { - switch(mutPos) - { - case 0: - stepX = (-1.0)*((float)hexWbase)/(2.0f*steps); - stepY = (-1.0)*((float)hexHbase)/((float)steps); - break; - case 1: - stepX = ((float)hexWbase)/(2.0f*steps); - stepY = (-1.0)*((float)hexHbase)/((float)steps); - break; - case 2: - stepX = ((float)hexWbase)/((float)steps); - stepY = 0.0; - break; - case 3: - stepX = ((float)hexWbase)/(2.0f*steps); - stepY = ((float)hexHbase)/((float)steps); - break; - case 4: - stepX = (-1.0)*((float)hexWbase)/(2.0f*steps); - stepY = ((float)hexHbase)/((float)steps); - break; - case 5: - stepX = (-1.0)*((float)hexWbase)/((float)steps); - stepY = 0.0; - break; - } - } - //step shifts calculated - - return true; -} - -void CBattleStackMoved::nextFrame() -{ - //moving instructions - posX += stepX; - myAnim()->pos.x = posX; - posY += stepY; - myAnim()->pos.y = posY; - - // Increments step count and check if we are finished with current animation - ++whichStep; - if(whichStep == steps) - { - // Sets the position of the creature animation sprites - Point coords = CBattleHex::getXYUnitAnim(nextHex, owner->creDir[stack->ID], stack, owner); - myAnim()->pos = coords; - - // true if creature haven't reached the final destination hex - if ((nextPos + 1) < destTiles.size()) - { - // update the next hex field which has to be reached by the stack - nextPos++; - curStackPos = nextHex; - nextHex = destTiles[nextPos]; - - // update position of double wide creatures - bool twoTiles = stack->doubleWide(); - if(twoTiles && bool(stack->attackerOwned) && (owner->creDir[stack->ID] != bool(stack->attackerOwned) )) //big attacker creature is reversed - myAnim()->pos.x -= 44; - else if(twoTiles && (! bool(stack->attackerOwned) ) && (owner->creDir[stack->ID] != bool(stack->attackerOwned) )) //big defender creature is reversed - myAnim()->pos.x += 44; - - // re-init animation - for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - if (it->first == this) - { - it->second = false; - break; - } - } - } - else - endAnim(); - } -} - -void CBattleStackMoved::endAnim() -{ - const CStack * movedStack = stack; - - CBattleAnimation::endAnim(); - - if(movedStack) - owner->addNewAnim(new CBattleMoveEnd(owner, stack, nextHex)); - - - if(owner->moveSh >= 0) - { - CCS->soundh->stopSound(owner->moveSh); - owner->moveSh = -1; - } - - delete this; -} - -CBattleStackMoved::CBattleStackMoved(CBattleInterface * _owner, const CStack * _stack, std::vector _destTiles, int _distance) -: CBattleStackAnimation(_owner, _stack), destTiles(_destTiles), nextPos(0), distance(_distance), stepX(0.0f), stepY(0.0f) -{ - curStackPos = stack->position; - nextHex = destTiles.front(); -} - -//move started - -bool CBattleMoveStart::init() -{ - if( !isEarliest(false) ) - return false; - - - if(!stack || myAnim()->getType() == 5) - { - CBattleMoveStart::endAnim(); - return false; - } - - CCS->soundh->playSound(battle_sound(stack->getCreature(), startMoving)); - myAnim()->setType(CCreatureAnim::MOVE_START); - - return true; -} - -void CBattleMoveStart::nextFrame() -{ - if(myAnim()->onLastFrameInGroup()) - { - endAnim(); - } - else - { - if((owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0) - myAnim()->incrementFrame(); - } -} - -void CBattleMoveStart::endAnim() -{ - CBattleAnimation::endAnim(); - - delete this; -} - -CBattleMoveStart::CBattleMoveStart(CBattleInterface * _owner, const CStack * _stack) -: CBattleStackAnimation(_owner, _stack) -{ -} - -//move finished - -bool CBattleMoveEnd::init() -{ - if( !isEarliest(true) ) - return false; - - if(!stack || myAnim()->framesInGroup(CCreatureAnim::MOVE_END) == 0 || - myAnim()->getType() == CCreatureAnim::DEATH) - { - endAnim(); - - return false; - } - - CCS->soundh->playSound(battle_sound(stack->getCreature(), endMoving)); - - myAnim()->setType(CCreatureAnim::MOVE_END); - - return true; -} - -void CBattleMoveEnd::nextFrame() -{ - if(myAnim()->onLastFrameInGroup()) - { - endAnim(); - } -} - -void CBattleMoveEnd::endAnim() -{ - CBattleAnimation::endAnim(); - - if(myAnim()->getType() != CCreatureAnim::DEATH) - myAnim()->setType(CCreatureAnim::HOLDING); //resetting to default - - CCS->curh->show(); - delete this; -} - -CBattleMoveEnd::CBattleMoveEnd(CBattleInterface * _owner, const CStack * _stack, THex destTile) -: CBattleStackAnimation(_owner, _stack), destinationTile(destTile) -{ -} - -//general attack anim - -void CBattleAttack::nextFrame() -{ - if(myAnim()->getType() != group) - myAnim()->setType(group); - - if(myAnim()->onFirstFrameInGroup()) - { - if(shooting) - CCS->soundh->playSound(battle_sound(attackingStack->getCreature(), shoot)); - else - CCS->soundh->playSound(battle_sound(attackingStack->getCreature(), attack)); - } - else if(myAnim()->onLastFrameInGroup()) - { - myAnim()->setType(CCreatureAnim::HOLDING); - endAnim(); - return; //execution of endAnim deletes this !!! - } -} - -bool CBattleAttack::checkInitialConditions() -{ - return isEarliest(false); -} - -CBattleAttack::CBattleAttack(CBattleInterface * _owner, const CStack * attacker, THex _dest, const CStack * defender) -: CBattleStackAnimation(_owner, attacker), dest(_dest), attackedStack(defender), attackingStack(attacker) -{ - - assert(attackingStack && "attackingStack is NULL in CBattleAttack::CBattleAttack !\n"); - if(attackingStack->getCreature()->idNumber != 145) //catapult is allowed to attack not-creature - { - assert(attackedStack && "attackedStack is NULL in CBattleAttack::CBattleAttack !\n"); - } - else //catapult can attack walls only - { - assert(owner->curInt->cb->battleGetWallUnderHex(_dest) >= 0); - } - attackingStackPosBeforeReturn = attackingStack->position; -} - -////melee attack - -bool CMeleeAttack::init() -{ - if( !CBattleAttack::checkInitialConditions() ) - return false; - - //if(owner->creAnims[stackID]->getType()!=2) - //{ - // return false; - //} - - if(!attackingStack || myAnim()->getType() == 5) - { - endAnim(); - - return false; - } - - bool toReverse = isToReverse(attackingStackPosBeforeReturn, dest, owner->creDir[stack->ID], attackedStack->doubleWide(), owner->creDir[attackedStack->ID]); - - if(toReverse) - { - - owner->addNewAnim(new CReverseAnim(owner, stack, attackingStackPosBeforeReturn, true)); - return false; - } - //reversed - - shooting = false; - - static const CCreatureAnim::EAnimType mutPosToGroup[] = {CCreatureAnim::ATTACK_UP, CCreatureAnim::ATTACK_UP, - CCreatureAnim::ATTACK_FRONT, CCreatureAnim::ATTACK_DOWN, CCreatureAnim::ATTACK_DOWN, CCreatureAnim::ATTACK_FRONT}; - - int revShiftattacker = (attackingStack->attackerOwned ? -1 : 1); - - int mutPos = THex::mutualPosition(attackingStackPosBeforeReturn, dest); - if(mutPos == -1 && attackingStack->doubleWide()) - { - mutPos = THex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->position); - } - if (mutPos == -1 && attackedStack->doubleWide()) - { - mutPos = THex::mutualPosition(attackingStackPosBeforeReturn, attackedStack->occupiedHex()); - } - if (mutPos == -1 && attackedStack->doubleWide() && attackingStack->doubleWide()) - { - mutPos = THex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->occupiedHex()); - } - - - switch(mutPos) //attack direction - { - case 0: case 1: case 2: case 3: case 4: case 5: - group = mutPosToGroup[mutPos]; - break; - default: - tlog1<<"Critical Error! Wrong dest in stackAttacking! dest: "< >::const_iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - CBattleMoveStart * anim = dynamic_cast(it->first); - CReverseAnim * anim2 = dynamic_cast(it->first); - if( (anim && anim->stackID == stackID) || (anim2 && anim2->stackID == stackID ) ) - return; - }*/ - - CBattleAttack::nextFrame(); -} - -void CMeleeAttack::endAnim() -{ - CBattleAnimation::endAnim(); - - delete this; -} - -CMeleeAttack::CMeleeAttack(CBattleInterface * _owner, const CStack * attacker, THex _dest, const CStack * _attacked) -: CBattleAttack(_owner, attacker, _dest, _attacked) -{ -} - -//shooting anim - -bool CShootingAnim::init() -{ - if( !CBattleAttack::checkInitialConditions() ) - return false; - - const CStack * shooter = attackingStack; - - if(!shooter || myAnim()->getType() == 5) - { - endAnim(); - return false; - } - - // Create the projectile animation - - 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 = shooter->position; - projectileAngle = atan2(float(abs(dest - fromHex) / BFIELD_WIDTH), float(abs(dest - fromHex) % BFIELD_WIDTH)); - if(fromHex < dest) - projectileAngle = -projectileAngle; - - // Get further info about the shooter e.g. relative pos of projectile to unit. - // If the creature id is 149 then it's a arrow tower which has no additional info so get the - // actual arrow tower shooter instead. - const CCreature *shooterInfo = shooter->getCreature(); - if (shooterInfo->idNumber == 149) - { - int creID = CGI->creh->factionToTurretCreature[owner->siegeH->town->town->typeID]; - shooterInfo = CGI->creh->creatures[creID]; - } - - SProjectileInfo spi; - spi.creID = shooter->getCreature()->idNumber; - spi.stackID = shooter->ID; - spi.reverse = !shooter->attackerOwned; - - spi.step = 0; - spi.frameNum = 0; - if(vstd::contains(CGI->creh->idToProjectileSpin, shooterInfo->idNumber)) - spi.spin = CGI->creh->idToProjectileSpin[shooterInfo->idNumber]; - else - { - tlog2 << "Warning - no projectile spin for spi.creID " << shooterInfo->idNumber << std::endl; - spi.spin = false; - } - - Point xycoord = CBattleHex::getXYUnitAnim(shooter->position, true, shooter, owner); - Point destcoord; - - - // The "master" point where all projectile positions relate to. - static const Point projectileOrigin(181, 252); - - if (attackedStack) - { - destcoord = CBattleHex::getXYUnitAnim(dest, false, attackedStack, owner); - destcoord.x += 250; destcoord.y += 210; //TODO: find a better place to shoot - - // Calculate projectile start position. Offsets are read out of the CRANIM.TXT. - if (projectileAngle > straightAngle) - { - //upper shot - spi.x = xycoord.x + projectileOrigin.x + shooterInfo->upperRightMissleOffsetX; - spi.y = xycoord.y + projectileOrigin.y + shooterInfo->upperRightMissleOffsetY; - } - else if (projectileAngle < -straightAngle) - { - //lower shot - spi.x = xycoord.x + projectileOrigin.x + shooterInfo->lowerRightMissleOffsetX; - spi.y = xycoord.y + projectileOrigin.y + shooterInfo->lowerRightMissleOffsetY; - } - else - { - //straight shot - spi.x = xycoord.x + projectileOrigin.x + shooterInfo->rightMissleOffsetX; - spi.y = xycoord.y + projectileOrigin.y + shooterInfo->rightMissleOffsetY; - } - - double animSpeed = 23.0 * owner->getAnimSpeed(); // flight speed of projectile - spi.lastStep = sqrt((float)((destcoord.x - spi.x)*(destcoord.x - spi.x) + (destcoord.y - spi.y) * (destcoord.y - spi.y))) / animSpeed; - if(spi.lastStep == 0) - spi.lastStep = 1; - spi.dx = (destcoord.x - spi.x) / spi.lastStep; - spi.dy = (destcoord.y - spi.y) / spi.lastStep; - spi.catapultInfo = 0; - } - else - { - // Catapult attack - // These are the values for equations of this kind: f(x) = ax^2 + bx + c - static const std::vector trajectoryCurves = boost::assign::list_of(new CatapultProjectileInfo(4.309, -3.198, 569.2, -296, 182)) - (new CatapultProjectileInfo(4.710, -3.11, 558.68, -258, 175))(new CatapultProjectileInfo(5.056, -3.003, 546.9, -236, 174)) - (new CatapultProjectileInfo(4.760, -2.74, 526.47, -216, 215))(new CatapultProjectileInfo(4.288, -2.496, 508.98, -223, 274)) - (new CatapultProjectileInfo(3.683, -3.018, 558.39, -324, 176))(new CatapultProjectileInfo(2.884, -2.607, 528.95, -366, 312)) - (new CatapultProjectileInfo(3.783, -2.364, 501.35, -227, 318)); - - static std::map hexToCurve = boost::assign::map_list_of(29, 0)(62, 1)(95, 2)(130, 3)(182, 4)(12, 5)(50, 6)(183, 7); - - std::map::iterator it = hexToCurve.find(dest.hex); - - if (it == hexToCurve.end()) - { - tlog1 << "For the hex position " << dest.hex << " is no curve defined."; - endAnim(); - return false; - } - else - { - int curveID = it->second; - spi.catapultInfo = trajectoryCurves[curveID]; - double animSpeed = 3.318 * owner->getAnimSpeed(); - spi.lastStep = (spi.catapultInfo->toX - spi.catapultInfo->fromX) / animSpeed; - spi.dx = animSpeed; - spi.dy = 0; - spi.x = xycoord.x + projectileOrigin.x + shooterInfo->rightMissleOffsetX + 17.; - spi.y = xycoord.y + projectileOrigin.y + shooterInfo->rightMissleOffsetY + 10.; - - // Add explosion anim - int xEnd = spi.x + spi.lastStep * spi.dx; - int yEnd = spi.catapultInfo->calculateY(xEnd); - owner->addNewAnim( new CSpellEffectAnim(owner, "SGEXPL.DEF", xEnd - 126, yEnd - 105)); - } - } - - // Set starting frame - if(spi.spin) - { - spi.frameNum = 0; - } - else - { - spi.frameNum = ((M_PI/2.0f - projectileAngle) / (2.0f *M_PI) + 1/((float)(2*(owner->idToProjectile[spi.creID]->ourImages.size()-1)))) * (owner->idToProjectile[spi.creID]->ourImages.size()-1); - } - - // Set projectile animation start delay which is specified in frames - spi.animStartDelay = shooterInfo->attackClimaxFrame; - owner->projectiles.push_back(spi); - - //attack animation - - shooting = true; - - if(projectileAngle > straightAngle) //upper shot - group = CCreatureAnim::SHOOT_UP; - else if(projectileAngle < -straightAngle) //lower shot - group = CCreatureAnim::SHOOT_DOWN; - else //straight shot - group = CCreatureAnim::SHOOT_FRONT; - - return true; -} - -void CShootingAnim::nextFrame() -{ - for(std::list >::const_iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - CBattleMoveStart * anim = dynamic_cast(it->first); - CReverseAnim * anim2 = dynamic_cast(it->first); - if( (anim && anim->stack->ID == stack->ID) || (anim2 && anim2->stack->ID == stack->ID && anim2->priority ) ) - return; - } - - CBattleAttack::nextFrame(); -} - -void CShootingAnim::endAnim() -{ - CBattleAnimation::endAnim(); - delete this; -} - -CShootingAnim::CShootingAnim(CBattleInterface * _owner, const CStack * attacker, THex _dest, const CStack * _attacked, bool _catapult, int _catapultDmg) -: CBattleAttack(_owner, attacker, _dest, _attacked), catapultDamage(_catapultDmg), catapult(_catapult) -{ - -} - -//////////////////////// +////////////////////// void CBattleInterface::addNewAnim(CBattleAnimation * anim) { @@ -1275,19 +197,19 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe //preparing graphics for displaying amounts of creatures amountNormal = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); CSDL_Ext::alphaTransform(amountNormal); - transformPalette(amountNormal, 0.59f, 0.19f, 0.93f); + transformPalette(amountNormal, 0.59, 0.19, 0.93); amountPositive = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); CSDL_Ext::alphaTransform(amountPositive); - transformPalette(amountPositive, 0.18f, 1.00f, 0.18f); + transformPalette(amountPositive, 0.18, 1.00, 0.18); amountNegative = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); CSDL_Ext::alphaTransform(amountNegative); - transformPalette(amountNegative, 1.00f, 0.18f, 0.18f); + transformPalette(amountNegative, 1.00, 0.18, 0.18); amountEffNeutral = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); CSDL_Ext::alphaTransform(amountEffNeutral); - transformPalette(amountEffNeutral, 1.00f, 1.00f, 0.18f); + transformPalette(amountEffNeutral, 1.00, 1.00, 0.18); ////blitting menu background and terrain // blitAt(background, pos.x, pos.y); @@ -1359,12 +281,12 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe CSDL_Ext::alphaTransform(cellBorder); cellShade = BitmapHandler::loadBitmap("CCELLSHD.BMP"); CSDL_Ext::alphaTransform(cellShade); - for(int h=0; hh, cellShade->w, x + pos.x, y + pos.y); bfield[h].accessible = true; bfield[h].myInterface = this; @@ -1394,7 +316,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe projectile->ourImages.push_back(ci); } } - for(int s=0; sourImages.size(); ++s) //alpha transforming + for(size_t s = 0; s < projectile->ourImages.size(); ++s) //alpha transforming { CSDL_Ext::alphaTransform(projectile->ourImages[s].bitmap); } @@ -1410,9 +332,9 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe cellBorders->format->palette->colors[g] = cellBorder->format->palette->colors[g]; } //palette copied - for(int i=0; i obst = curInt->cb->battleGetAllObstacles(); - for(int t=0; theroh->obstacles.find(obst[t].ID)->second.defName); - for(int n=0; nourImages.size(); ++n) + for(size_t n = 0; n < idToObstacle[obst[t].ID]->ourImages.size(); ++n) { SDL_SetColorKey(idToObstacle[obst[t].ID]->ourImages[n].bitmap, SDL_SRCCOLORKEY, SDL_MapRGB(idToObstacle[obst[t].ID]->ourImages[n].bitmap->format,0,255,255)); } @@ -1456,7 +378,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe int channel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds); CCS->soundh->setCallback(channel, boost::bind(&CMusicHandler::playMusicFromSet, CCS->musich, CCS->musich->battleMusics, -1)); - memset(stackCountOutsideHexes, 1, BFIELD_SIZE * sizeof(bool)); //initialize array with trues + memset(stackCountOutsideHexes, 1, GameConstants::BFIELD_SIZE * sizeof(bool)); //initialize array with trues } CBattleInterface::~CBattleInterface() @@ -1549,7 +471,7 @@ void CBattleInterface::activate() bSpell->activate(); bWait->activate(); bDefence->activate(); - for(int b=0; bdeactivate(); bWait->deactivate(); bDefence->deactivate(); - for(int b=0; b shaded = spToCast.rangeInHexes(b, schoolLevel); for(std::set::iterator it = shaded.begin(); it != shaded.end(); ++it) //for spells with range greater then one hex { - if(curInt->sysOpts.printMouseShadow && (*it % BFIELD_WIDTH != 0) && (*it % BFIELD_WIDTH != 16)) + if(curInt->sysOpts.printMouseShadow && (*it % GameConstants::BFIELD_WIDTH != 0) && (*it % GameConstants::BFIELD_WIDTH != 16)) { - int x = 14 + ((*it/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(*it%BFIELD_WIDTH) + pos.x; - int y = 86 + 42 * (*it/BFIELD_WIDTH) + pos.y; + int x = 14 + ((*it/GameConstants::BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(*it%GameConstants::BFIELD_WIDTH) + pos.x; + int y = 86 + 42 * (*it/GameConstants::BFIELD_WIDTH) + pos.y; SDL_Rect temp_rect = genRect(cellShade->h, cellShade->w, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, to, &temp_rect); } @@ -1681,18 +603,18 @@ void CBattleInterface::show(SDL_Surface * to) {//TODO: do not check it every frame if (activeStack) //highlight all attackable hexes { - std::set set = curInt->cb->battleGetAttackedHexes(activeStack, currentlyHoveredHex, attackingHex); - BOOST_FOREACH(THex hex, set) + std::set set = curInt->cb->battleGetAttackedHexes(activeStack, currentlyHoveredHex, attackingHex); + BOOST_FOREACH(SHexField hex, set) { - int x = 14 + ((hex/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(hex%BFIELD_WIDTH) + pos.x; - int y = 86 + 42 * (hex/BFIELD_WIDTH) + pos.y; + int x = 14 + ((hex/GameConstants::BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(hex%GameConstants::BFIELD_WIDTH) + pos.x; + int y = 86 + 42 * (hex/GameConstants::BFIELD_WIDTH) + pos.y; SDL_Rect temp_rect = genRect(cellShade->h, cellShade->w, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, to, &temp_rect); } } //always highlight pointed hex - int x = 14 + ((b/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(b%BFIELD_WIDTH) + pos.x; - int y = 86 + 42 * (b/BFIELD_WIDTH) + pos.y; + int x = 14 + ((b/GameConstants::BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(b%GameConstants::BFIELD_WIDTH) + pos.x; + int y = 86 + 42 * (b/GameConstants::BFIELD_WIDTH) + pos.y; SDL_Rect temp_rect = genRect(cellShade->h, cellShade->w, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, to, &temp_rect); } @@ -1708,17 +630,17 @@ void CBattleInterface::show(SDL_Surface * to) //preparing obstacles to be shown std::vector obstacles = curInt->cb->battleGetAllObstacles(); - std::multimap hexToObstacle; - for(int b=0; b hexToObstacle; + for(size_t b = 0; b < obstacles.size(); ++b) { - THex position = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getMaxBlocked(obstacles[b].pos); + SHexField position = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getMaxBlocked(obstacles[b].pos); hexToObstacle.insert(std::make_pair(position, b)); } ////showing units //a lot of work... - std::vector stackAliveByHex[BFIELD_SIZE]; + std::vector stackAliveByHex[GameConstants::BFIELD_SIZE]; //double loop because dead stacks should be printed first - for (int i = 0; i < stacks.size(); i++) + for (size_t i = 0; i < stacks.size(); i++) { const CStack *s = stacks[i]; if(creAnims.find(s->ID) == creAnims.end()) //e.g. for summoned but not yet handled stacks @@ -1726,8 +648,8 @@ void CBattleInterface::show(SDL_Surface * to) if(creAnims[s->ID]->getType() != 5 && s->position >= 0) //don't show turrets here stackAliveByHex[s->position].push_back(s); } - std::vector stackDeadByHex[BFIELD_SIZE]; - for (int i = 0; i < stacks.size(); i++) + std::vector stackDeadByHex[GameConstants::BFIELD_SIZE]; + for (size_t i = 0; i < stacks.size(); i++) { const CStack *s = stacks[i]; if(creAnims.find(s->ID) == creAnims.end()) //e.g. for summoned but not yet handled stacks @@ -1777,7 +699,7 @@ void CBattleInterface::show(SDL_Surface * to) animsAreDisplayed.setn(false); } - for(int b=0; b flyingStacks; //flying stacks should be displayed later, over other stacks and obstacles if (!siegeH) { - for(int b = 0; b < BFIELD_SIZE; ++b) //showing alive stacks + for(int b = 0; b < GameConstants::BFIELD_SIZE; ++b) //showing alive stacks { showAliveStacks(stackAliveByHex, b, &flyingStacks, to); showObstacles(&hexToObstacle, obstacles, b, to); @@ -1869,7 +791,7 @@ void CBattleInterface::show(SDL_Surface * to) } } - for(int b=0; b *aliveStacks, if(defendingHero) defendingHero->show(to); - for(int v = 0; v < aliveStacks[hex].size(); ++v) + for(size_t v = 0; v < aliveStacks[hex].size(); ++v) { const CStack *s = aliveStacks[hex][v]; @@ -1969,17 +891,17 @@ void CBattleInterface::showAliveStacks(std::vector *aliveStacks, } } -void CBattleInterface::showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to) +void CBattleInterface::showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to) { - std::pair::const_iterator, std::multimap::const_iterator> obstRange = + std::pair::const_iterator, std::multimap::const_iterator> obstRange = hexToObstacle->equal_range(hex); - for(std::multimap::const_iterator it = obstRange.first; it != obstRange.second; ++it) + for(std::multimap::const_iterator it = obstRange.first; it != obstRange.second; ++it) { CObstacleInstance & curOb = obstacles[it->second]; std::pair shift = CGI->heroh->obstacles.find(curOb.ID)->second.posShift; - int x = ((curOb.pos/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(curOb.pos%BFIELD_WIDTH) + pos.x + shift.first; - int y = 86 + 42 * (curOb.pos/BFIELD_WIDTH) + pos.y + shift.second; + int x = ((curOb.pos/GameConstants::BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(curOb.pos%GameConstants::BFIELD_WIDTH) + pos.x + shift.first; + int y = 86 + 42 * (curOb.pos/GameConstants::BFIELD_WIDTH) + pos.y + shift.second; std::vector &images = idToObstacle[curOb.ID]->ourImages; //reference to animation of obstacle blitAt(images[((animCount+1)/(4/curInt->sysOpts.animSpeed))%images.size()].bitmap, x, y, to); } @@ -2009,7 +931,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) bool stackCastsSpell; mouseHoveredStack = -1; int myNumber = -1; //number of hovered tile - for(int g = 0; g < BFIELD_SIZE; ++g) + for(int g = 0; g < GameConstants::BFIELD_SIZE; ++g) { if(bfield[g].hovered && bfield[g].strictHovered) { @@ -2041,7 +963,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) if ((int)creatureSpellToCast > -1) //use randomized spell (Faerie Dragon), or only avaliable spell (Archangel) { const CSpell * spell = CGI->spellh->spells[creatureSpellToCast]; - if (curInt->cb->battleCanCastThisSpell(spell, THex(myNumber)) == SpellCasting::OK) + if (curInt->cb->battleCanCastThisSpell(spell, SHexField(myNumber)) == ESpellCastProblem::OK) { if ((spell->positiveness > -1 && ourStack) || (spell->positiveness < 1 && !ourStack)) { @@ -2204,7 +1126,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) else if(spellDestSelectMode) { int myNumber = -1; //number of hovered tile - for(int g=0; gplayerID == stackUnder->owner; + whichCase = stackUnder != NULL && curInt->playerID == stackUnder->owner; break; case 2: - whichCase = stackUnder && curInt->playerID != stackUnder->owner; + whichCase = stackUnder != NULL && curInt->playerID != stackUnder->owner; break; case 3: - whichCase = stackUnder; + whichCase = stackUnder != NULL; break; } @@ -2288,7 +1210,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) void CBattleInterface::setBattleCursor(const int myNumber) { - const CBattleHex & hoveredHex = bfield[myNumber]; + const CHexFieldControl & hoveredHex = bfield[myNumber]; CCursorHandler *cursor = CCS->curh; const double subdividingAngle = 2.0*M_PI/6.0; // Divide a hex into six sectors. @@ -2296,7 +1218,7 @@ void CBattleInterface::setBattleCursor(const int myNumber) const double hexMidY = hoveredHex.pos.y + hoveredHex.pos.h/2; const double cursorHexAngle = M_PI - atan2(hexMidY - cursor->ypos, cursor->xpos - hexMidX) + subdividingAngle/2; //TODO: refactor this nightmare const double sector = fmod(cursorHexAngle/subdividingAngle, 6.0); - const int zigzagCorrection = !((myNumber/BFIELD_WIDTH)%2); // Off-by-one correction needed to deal with the odd battlefield rows. + const int zigzagCorrection = !((myNumber/GameConstants::BFIELD_WIDTH)%2); // Off-by-one correction needed to deal with the odd battlefield rows. std::vector sectorCursor; // From left to bottom left. sectorCursor.push_back(8); @@ -2311,12 +1233,12 @@ void CBattleInterface::setBattleCursor(const int myNumber) // Exclude directions which cannot be attacked from. // Check to the left. - if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(occupyableHexes, myNumber - 1)) + if (myNumber%GameConstants::BFIELD_WIDTH <= 1 || !vstd::contains(occupyableHexes, myNumber - 1)) { sectorCursor[0] = -1; } // Check top left, top right as well as above for 2-hex creatures. - if (myNumber/BFIELD_WIDTH == 0) + if (myNumber/GameConstants::BFIELD_WIDTH == 0) { sectorCursor[1] = -1; sectorCursor[2] = -1; @@ -2328,13 +1250,13 @@ void CBattleInterface::setBattleCursor(const int myNumber) { bool attackRow[4] = {true, true, true, true}; - if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH - 2 + zigzagCorrection)) + if (myNumber%GameConstants::BFIELD_WIDTH <= 1 || !vstd::contains(occupyableHexes, myNumber - GameConstants::BFIELD_WIDTH - 2 + zigzagCorrection)) attackRow[0] = false; - if (!vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH - 1 + zigzagCorrection)) + if (!vstd::contains(occupyableHexes, myNumber - GameConstants::BFIELD_WIDTH - 1 + zigzagCorrection)) attackRow[1] = false; - if (!vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH + zigzagCorrection)) + if (!vstd::contains(occupyableHexes, myNumber - GameConstants::BFIELD_WIDTH + zigzagCorrection)) attackRow[2] = false; - if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH + 1 + zigzagCorrection)) + if (myNumber%GameConstants::BFIELD_WIDTH >= GameConstants::BFIELD_WIDTH - 2 || !vstd::contains(occupyableHexes, myNumber - GameConstants::BFIELD_WIDTH + 1 + zigzagCorrection)) attackRow[3] = false; if (!(attackRow[0] && attackRow[1])) @@ -2346,19 +1268,19 @@ void CBattleInterface::setBattleCursor(const int myNumber) } else { - if (!vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH - 1 + zigzagCorrection)) + if (!vstd::contains(occupyableHexes, myNumber - GameConstants::BFIELD_WIDTH - 1 + zigzagCorrection)) sectorCursor[1] = -1; - if (!vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH + zigzagCorrection)) + if (!vstd::contains(occupyableHexes, myNumber - GameConstants::BFIELD_WIDTH + zigzagCorrection)) sectorCursor[2] = -1; } } // Check to the right. - if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(occupyableHexes, myNumber + 1)) + if (myNumber%GameConstants::BFIELD_WIDTH >= GameConstants::BFIELD_WIDTH - 2 || !vstd::contains(occupyableHexes, myNumber + 1)) { sectorCursor[3] = -1; } // Check bottom right, bottom left as well as below for 2-hex creatures. - if (myNumber/BFIELD_WIDTH == BFIELD_HEIGHT - 1) + if (myNumber/GameConstants::BFIELD_WIDTH == GameConstants::BFIELD_HEIGHT - 1) { sectorCursor[4] = -1; sectorCursor[5] = -1; @@ -2370,13 +1292,13 @@ void CBattleInterface::setBattleCursor(const int myNumber) { bool attackRow[4] = {true, true, true, true}; - if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH - 2 + zigzagCorrection)) + if (myNumber%GameConstants::BFIELD_WIDTH <= 1 || !vstd::contains(occupyableHexes, myNumber + GameConstants::BFIELD_WIDTH - 2 + zigzagCorrection)) attackRow[0] = false; - if (!vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH - 1 + zigzagCorrection)) + if (!vstd::contains(occupyableHexes, myNumber + GameConstants::BFIELD_WIDTH - 1 + zigzagCorrection)) attackRow[1] = false; - if (!vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH + zigzagCorrection)) + if (!vstd::contains(occupyableHexes, myNumber + GameConstants::BFIELD_WIDTH + zigzagCorrection)) attackRow[2] = false; - if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH + 1 + zigzagCorrection)) + if (myNumber%GameConstants::BFIELD_WIDTH >= GameConstants::BFIELD_WIDTH - 2 || !vstd::contains(occupyableHexes, myNumber + GameConstants::BFIELD_WIDTH + 1 + zigzagCorrection)) attackRow[3] = false; if (!(attackRow[0] && attackRow[1])) @@ -2388,9 +1310,9 @@ void CBattleInterface::setBattleCursor(const int myNumber) } else { - if (!vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH + zigzagCorrection)) + if (!vstd::contains(occupyableHexes, myNumber + GameConstants::BFIELD_WIDTH + zigzagCorrection)) sectorCursor[4] = -1; - if (!vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH - 1 + zigzagCorrection)) + if (!vstd::contains(occupyableHexes, myNumber + GameConstants::BFIELD_WIDTH - 1 + zigzagCorrection)) sectorCursor[5] = -1; } } @@ -2431,22 +1353,22 @@ void CBattleInterface::setBattleCursor(const int myNumber) attackingHex = myNumber - 1; //left break; case 1: - attackingHex = myNumber - BFIELD_WIDTH - 1 + zigzagCorrection; //top left + attackingHex = myNumber - GameConstants::BFIELD_WIDTH - 1 + zigzagCorrection; //top left break; case 2: - attackingHex = myNumber - BFIELD_WIDTH + zigzagCorrection; //top right + attackingHex = myNumber - GameConstants::BFIELD_WIDTH + zigzagCorrection; //top right break; case 3: break; attackingHex = myNumber + 1; //right case 4: break; - attackingHex = myNumber + BFIELD_WIDTH + zigzagCorrection; //bottom right + attackingHex = myNumber + GameConstants::BFIELD_WIDTH + zigzagCorrection; //bottom right case 5: - attackingHex = myNumber + BFIELD_WIDTH - 1 + zigzagCorrection; //bottom left + attackingHex = myNumber + GameConstants::BFIELD_WIDTH - 1 + zigzagCorrection; //bottom left break; } - THex hex(attackingHex); + SHexField hex(attackingHex); if (!hex.isValid()) attackingHex = -1; } @@ -2594,7 +1516,7 @@ void CBattleInterface::bConsoleDownf() void CBattleInterface::newStack(const CStack * stack) { - Point coords = CBattleHex::getXYUnitAnim(stack->position, stack->owner == attackingHeroInstance->tempOwner, stack, this);; + Point coords = CHexFieldControl::getXYUnitAnim(stack->position, stack->owner == attackingHeroInstance->tempOwner, stack, this);; if(stack->position < 0) //turret { @@ -2646,17 +1568,17 @@ void CBattleInterface::stackActivated(const CStack * stack) //TODO: check it all activateStack(); } -void CBattleInterface::stackMoved(const CStack * stack, std::vector destHex, int distance) +void CBattleInterface::stackMoved(const CStack * stack, std::vector destHex, int distance) { - addNewAnim(new CBattleStackMoved(this, stack, destHex, distance)); + addNewAnim(new CMovementAnimation(this, stack, destHex, distance)); waitForAnims(); } void CBattleInterface::stacksAreAttacked(std::vector attackedInfos) { - for(int h = 0; h < attackedInfos.size(); ++h) + for(size_t h = 0; h < attackedInfos.size(); ++h) { - addNewAnim(new CDefenceAnim(attackedInfos[h], this)); + addNewAnim(new CDefenceAnimation(attackedInfos[h], this)); if (attackedInfos[h].rebirth) { displayEffect(50, attackedInfos[h].defender->position); //TODO: play reverse death animation @@ -2665,7 +1587,7 @@ void CBattleInterface::stacksAreAttacked(std::vector attacke } waitForAnims(); int targets = 0, killed = 0, damage = 0; - for(int h = 0; h < attackedInfos.size(); ++h) + for(size_t h = 0; h < attackedInfos.size(); ++h) { ++targets; killed += attackedInfos[h].killed; @@ -2676,22 +1598,22 @@ void CBattleInterface::stacksAreAttacked(std::vector attacke else printConsoleAttacked(attackedInfos.front().defender, damage, killed, attackedInfos.front().attacker, false); - for(int h = 0; h < attackedInfos.size(); ++h) + for(size_t h = 0; h < attackedInfos.size(); ++h) { if (attackedInfos[h].rebirth) creAnims[attackedInfos[h].defender->ID]->setType(CCreatureAnim::HOLDING); } } -void CBattleInterface::stackAttacking( const CStack * attacker, THex dest, const CStack * attacked, bool shooting ) +void CBattleInterface::stackAttacking( const CStack * attacker, SHexField dest, const CStack * attacked, bool shooting ) { if (shooting) { - addNewAnim(new CShootingAnim(this, attacker, dest, attacked)); + addNewAnim(new CShootingAnimation(this, attacker, dest, attacked)); } else { - addNewAnim(new CMeleeAttack(this, attacker, dest, attacked)); + addNewAnim(new CMeleeAttackAnimation(this, attacker, dest, attacked)); } waitForAnims(); } @@ -2717,7 +1639,7 @@ void CBattleInterface::newRound(int number) } -void CBattleInterface::giveCommand(ui8 action, THex tile, ui32 stack, si32 additional) +void CBattleInterface::giveCommand(ui8 action, SHexField tile, ui32 stack, si32 additional) { if(!curInt->cb->battleGetStackByID(stack) && action != 1 && action != 4 && action != 5) { @@ -2738,7 +1660,7 @@ void CBattleInterface::giveCommand(ui8 action, THex tile, ui32 stack, si32 addit case BattleAction::WALK: case BattleAction::SHOOT: case BattleAction::CATAPULT: - assert(tile < BFIELD_SIZE); + assert(tile < GameConstants::BFIELD_SIZE); break; } @@ -2751,35 +1673,35 @@ void CBattleInterface::giveCommand(ui8 action, THex tile, ui32 stack, si32 addit else { curInt->cb->battleMakeTacticAction(ba); - delNull(ba); + vstd::clear_pointer(ba); bTacticNextStack(); } } -bool CBattleInterface::isTileAttackable(const THex & number) const +bool CBattleInterface::isTileAttackable(const SHexField & number) const { for(size_t b=0; b obstacles = curInt->cb->battleGetAllObstacles(); - std::set coveredHexes; - for(int b = 0; b < obstacles.size(); ++b) + std::set coveredHexes; + for(size_t b = 0; b < obstacles.size(); ++b) { - std::vector blocked = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getBlocked(obstacles[b].pos); - for(int w = 0; w < blocked.size(); ++w) + std::vector blocked = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getBlocked(obstacles[b].pos); + for(size_t w = 0; w < blocked.size(); ++w) coveredHexes.insert(blocked[w]); } return vstd::contains(coveredHexes, hex); } -bool CBattleInterface::isCatapultAttackable(THex hex) const +bool CBattleInterface::isCatapultAttackable(SHexField hex) const { if(!siegeH) return false; @@ -2817,7 +1739,7 @@ void CBattleInterface::hexLclicked(int whichOne) return; } - if( ((whichOne%BFIELD_WIDTH)!=0 && (whichOne%BFIELD_WIDTH)!=(BFIELD_WIDTH-1)) //if player is trying to attack enemey unit or move creature stack + if( ((whichOne%GameConstants::BFIELD_WIDTH)!=0 && (whichOne%GameConstants::BFIELD_WIDTH)!=(GameConstants::BFIELD_WIDTH-1)) //if player is trying to attack enemey unit or move creature stack || (actSt->hasBonusOfType(Bonus::CATAPULT) && !spellDestSelectMode || dest ) //enemy's first aid tent can stand there and we want to shoot it ) { @@ -2877,7 +1799,7 @@ void CBattleInterface::hexLclicked(int whichOne) if ((int)creatureSpellToCast > -1) //use randomized spell (Faerie Dragon), or only avaliable spell (Archangel) { const CSpell * spell = CGI->spellh->spells[creatureSpellToCast]; - if (curInt->cb->battleCanCastThisSpell(spell, THex(whichOne)) == SpellCasting::OK) + if (curInt->cb->battleCanCastThisSpell(spell, SHexField(whichOne)) == ESpellCastProblem::OK) { if ((spell->positiveness > -1 && ourStack) || (spell->positiveness < 1 && !ourStack)) { @@ -2921,7 +1843,7 @@ void CBattleInterface::hexLclicked(int whichOne) case 12: //from bottom right { bool doubleWide = actStack->doubleWide(); - int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 ) + + int destHex = whichOne + ( (whichOne/GameConstants::BFIELD_WIDTH)%2 ? GameConstants::BFIELD_WIDTH : GameConstants::BFIELD_WIDTH+1 ) + (actStack->attackerOwned && doubleWide ? 1 : 0); if(vstd::contains(occupyableHexes, destHex)) attackFromHex = destHex; @@ -2939,7 +1861,7 @@ void CBattleInterface::hexLclicked(int whichOne) } case 7: //from bottom left { - int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH-1 : BFIELD_WIDTH ); + int destHex = whichOne + ( (whichOne/GameConstants::BFIELD_WIDTH)%2 ? GameConstants::BFIELD_WIDTH-1 : GameConstants::BFIELD_WIDTH ); if(vstd::contains(occupyableHexes, destHex)) attackFromHex = destHex; else if(actStack->attackerOwned) //if we are attacker @@ -2958,7 +1880,7 @@ void CBattleInterface::hexLclicked(int whichOne) { if(actStack->doubleWide() && !actStack->attackerOwned) { - std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); if(vstd::contains(acc, whichOne)) attackFromHex = whichOne - 1; else @@ -2972,7 +1894,7 @@ void CBattleInterface::hexLclicked(int whichOne) } case 9: //from top left { - int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH+1 : BFIELD_WIDTH ); + int destHex = whichOne - ( (whichOne/GameConstants::BFIELD_WIDTH)%2 ? GameConstants::BFIELD_WIDTH+1 : GameConstants::BFIELD_WIDTH ); if(vstd::contains(occupyableHexes, destHex)) attackFromHex = destHex; else if(actStack->attackerOwned) //if we are attacker @@ -2990,7 +1912,7 @@ void CBattleInterface::hexLclicked(int whichOne) case 10: //from top right { bool doubleWide = actStack->doubleWide(); - int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 ) + + int destHex = whichOne - ( (whichOne/GameConstants::BFIELD_WIDTH)%2 ? GameConstants::BFIELD_WIDTH : GameConstants::BFIELD_WIDTH-1 ) + (actStack->attackerOwned && doubleWide ? 1 : 0); if(vstd::contains(occupyableHexes, destHex)) attackFromHex = destHex; @@ -3010,7 +1932,7 @@ void CBattleInterface::hexLclicked(int whichOne) { if(actStack->doubleWide() && actStack->attackerOwned) { - std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); if(vstd::contains(acc, whichOne)) attackFromHex = whichOne + 1; else @@ -3024,7 +1946,7 @@ void CBattleInterface::hexLclicked(int whichOne) } case 13: //from bottom { - int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 ); + int destHex = whichOne + ( (whichOne/GameConstants::BFIELD_WIDTH)%2 ? GameConstants::BFIELD_WIDTH : GameConstants::BFIELD_WIDTH+1 ); if(vstd::contains(occupyableHexes, destHex)) attackFromHex = destHex; else if(attackingHeroInstance->tempOwner == curInt->cb->getMyColor()) //if we are attacker @@ -3041,7 +1963,7 @@ void CBattleInterface::hexLclicked(int whichOne) } case 14: //from top { - int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 ); + int destHex = whichOne - ( (whichOne/GameConstants::BFIELD_WIDTH)%2 ? GameConstants::BFIELD_WIDTH : GameConstants::BFIELD_WIDTH-1 ); if(vstd::contains(occupyableHexes, destHex)) attackFromHex = destHex; else if(attackingHeroInstance->tempOwner == curInt->cb->getMyColor()) //if we are attacker @@ -3096,7 +2018,7 @@ void CBattleInterface::hexLclicked(int whichOne) CCS->curh->changeGraphic(1, 6); //cursor should be changed if(activeStack->doubleWide()) { - std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); int shiftedDest = whichOne + (activeStack->attackerOwned ? 1 : -1); if(vstd::contains(acc, whichOne)) giveCommand (BattleAction::WALK ,whichOne, activeStack->ID); @@ -3122,7 +2044,7 @@ void CBattleInterface::stackIsCatapulting(const CatapultAttack & ca) for(std::set< std::pair< std::pair< ui8, si16 >, ui8> >::const_iterator it = ca.attackedParts.begin(); it != ca.attackedParts.end(); ++it) { const CStack * stack = curInt->cb->battleGetStackByID(ca.attacker); - addNewAnim(new CShootingAnim(this, stack, it->first.second, NULL, true, it->second)); + addNewAnim(new CShootingAnimation(this, stack, it->first.second, NULL, true, it->second)); SDL_FreeSurface(siegeH->walls[it->first.first + 2]); siegeH->walls[it->first.first + 2] = BitmapHandler::loadBitmap( @@ -3180,11 +2102,11 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc ) //initial variables std::string animToDisplay; Point srccoord = (sc->side ? Point(770, 60) : Point(30, 60)) + pos; - Point destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, curInt->cb->battleGetStackByPos(sc->tile), this); //position attacked by arrow + Point destcoord = CHexFieldControl::getXYUnitAnim(sc->tile, !sc->side, curInt->cb->battleGetStackByPos(sc->tile), this); //position attacked by arrow destcoord.x += 250; destcoord.y += 240; //animation angle - float angle = atan2(float(destcoord.x - srccoord.x), float(destcoord.y - srccoord.y)); + double angle = atan2(static_cast(destcoord.x - srccoord.x), static_cast(destcoord.y - srccoord.y)); bool Vflip = false; if (angle < 0) { @@ -3207,14 +2129,14 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc ) //displaying animation CDefEssential * animDef = CDefHandler::giveDefEss(animToDisplay); - int steps = sqrt((float)((destcoord.x - srccoord.x)*(destcoord.x - srccoord.x) + (destcoord.y - srccoord.y) * (destcoord.y - srccoord.y))) / 40; + int steps = sqrt(static_cast((destcoord.x - srccoord.x)*(destcoord.x - srccoord.x) + (destcoord.y - srccoord.y) * (destcoord.y - srccoord.y))) / 40; if(steps <= 0) steps = 1; int dx = (destcoord.x - srccoord.x - animDef->ourImages[0].bitmap->w)/steps, dy = (destcoord.y - srccoord.y - animDef->ourImages[0].bitmap->h)/steps; delete animDef; - addNewAnim(new CSpellEffectAnim(this, animToDisplay, srccoord.x, srccoord.y, dx, dy, Vflip)); + addNewAnim(new CSpellEffectAnimation(this, animToDisplay, srccoord.x, srccoord.y, dx, dy, Vflip)); break; //for 15 and 16 cases } @@ -3238,12 +2160,12 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc ) case Spells::SUMMON_EARTH_ELEMENTAL: case Spells::SUMMON_WATER_ELEMENTAL: case Spells::SUMMON_AIR_ELEMENTAL: - addNewAnim(new CDummyAnim(this, 2)); + addNewAnim(new CDummyAnimation(this, 2)); break; } //switch(sc->id) //support for resistance - for(int j=0; jresisted.size(); ++j) + for(size_t j = 0; j < sc->resisted.size(); ++j) { int tile = curInt->cb->battleGetStackByID(sc->resisted[j])->position; displayEffect(78, tile); @@ -3400,8 +2322,8 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc ) { Point leftHero = Point(15, 30) + pos; Point rightHero = Point(755, 30) + pos; - addNewAnim(new CSpellEffectAnim(this, sc->side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero.x, leftHero.y, 0, 0, false)); - addNewAnim(new CSpellEffectAnim(this, sc->side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero.x, rightHero.y, 0, 0, false)); + addNewAnim(new CSpellEffectAnimation(this, sc->side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero.x, leftHero.y, 0, 0, false)); + addNewAnim(new CSpellEffectAnimation(this, sc->side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero.x, rightHero.y, 0, 0, false)); } } @@ -3529,7 +2451,7 @@ void CBattleInterface::castThisSpell(int spellID) void CBattleInterface::displayEffect(ui32 effect, int destTile) { - addNewAnim(new CSpellEffectAnim(this, effect, destTile)); + addNewAnim(new CSpellEffectAnimation(this, effect, destTile)); } void CBattleInterface::battleTriggerEffect(const BattleTriggerEffect & bte) @@ -3586,7 +2508,7 @@ void CBattleInterface::activateStack() queue->update(); redrawBackgroundWithHexes(activeStack); - bWait->block(vstd::contains(s->state, WAITING)); //block waiting button if stack has been already waiting + bWait->block(vstd::contains(s->state, EBattleStackState::WAITING)); //block waiting button if stack has been already waiting //block cast spell button if hero doesn't have a spellbook bSpell->block(!curInt->cb->battleCanCastSpell()); @@ -3612,18 +2534,18 @@ void CBattleInterface::activateStack() activate(); } -float CBattleInterface::getAnimSpeedMultiplier() const +double CBattleInterface::getAnimSpeedMultiplier() const { switch(curInt->sysOpts.animSpeed) { case 1: - return 3.5f; + return 3.5; case 2: - return 2.2f; + return 2.2; case 4: - return 1.0f; + return 1.0; default: - return 0.0f; + return 0.0; } } @@ -3710,8 +2632,8 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to) && !stack->hasBonusOfType(Bonus::SIEGE_WEAPON) //and not a war machine... ) { - const THex nextPos = stack->position + (stack->attackerOwned ? 1 : -1); - const bool edge = stack->position % BFIELD_WIDTH == (stack->attackerOwned ? BFIELD_WIDTH - 2 : 1); + const SHexField nextPos = stack->position + (stack->attackerOwned ? 1 : -1); + const bool edge = stack->position % GameConstants::BFIELD_WIDTH == (stack->attackerOwned ? GameConstants::BFIELD_WIDTH - 2 : 1); const bool moveInside = !edge && !stackCountOutsideHexes[nextPos]; int xAdd = (stack->attackerOwned ? 220 : 202) + (stack->doubleWide() ? 44 : 0) * (stack->attackerOwned ? +1 : -1) + @@ -3847,9 +2769,9 @@ void CBattleInterface::redrawBackgroundWithHexes(const CStack * activeStack) if(curInt->sysOpts.printStackRange) { - std::vector hexesToShade = occupyableHexes; + std::vector hexesToShade = occupyableHexes; hexesToShade.insert(hexesToShade.end(), attackableHexes.begin(), attackableHexes.end()); - BOOST_FOREACH(THex hex, hexesToShade) + BOOST_FOREACH(SHexField hex, hexesToShade) { int i = hex.getY(); //row int j = hex.getX()-1; //column @@ -3980,7 +2902,7 @@ void CBattleInterface::endAction(const BattleAction* action) if(action->actionType == BattleAction::WALK && creAnims[action->stackNumber]->getType() != 2) //walk or walk & attack { const CStack * stack = curInt->cb->battleGetStackByID(action->stackNumber); - pendingAnims.push_back(std::make_pair(new CBattleMoveEnd(this, stack, action->destinationTile), false)); + pendingAnims.push_back(std::make_pair(new CMovementEndAnimation(this, stack, action->destinationTile), false)); } if(action->actionType == BattleAction::CATAPULT) //catapult { @@ -3997,7 +2919,7 @@ void CBattleInterface::endAction(const BattleAction* action) { if(s && creDir[s->ID] != bool(s->attackerOwned) && s->alive()) { - addNewAnim(new CReverseAnim(this, s, s->position, false)); + addNewAnim(new CReverseAnimation(this, s, s->position, false)); } } @@ -4076,7 +2998,7 @@ void CBattleInterface::startAction(const BattleAction* action) if(creAnims[action->stackNumber]->framesInGroup(CCreatureAnim::MOVE_START)) { const CStack * stack = curInt->cb->battleGetStackByID(action->stackNumber); - pendingAnims.push_back(std::make_pair(new CBattleMoveStart(this, stack), false)); + pendingAnims.push_back(std::make_pair(new CMovementStartAnimation(this, stack), false)); } } @@ -4161,630 +3083,12 @@ void CBattleInterface::bTacticNextStack() stackActivated(stacksOfMine.front()); } -void CBattleHero::show(SDL_Surface *to) -{ - //animation of flag - if(flip) - { - SDL_Rect temp_rect = genRect( - flag->ourImages[flagAnim].bitmap->h, - flag->ourImages[flagAnim].bitmap->w, - pos.x + 61, - pos.y + 39); - CSDL_Ext::blit8bppAlphaTo24bpp( - flag->ourImages[flagAnim].bitmap, - NULL, - screen, - &temp_rect); - } - else - { - SDL_Rect temp_rect = genRect( - flag->ourImages[flagAnim].bitmap->h, - flag->ourImages[flagAnim].bitmap->w, - pos.x + 72, - pos.y + 39); - CSDL_Ext::blit8bppAlphaTo24bpp( - flag->ourImages[flagAnim].bitmap, - NULL, - screen, - &temp_rect); - } - ++flagAnimCount; - if(flagAnimCount%4==0) - { - ++flagAnim; - flagAnim %= flag->ourImages.size(); - } - //animation of hero - int tick=-1; - for(int i=0; iourImages.size(); ++i) - { - if(dh->ourImages[i].groupNumber==phase) - ++tick; - if(tick==image) - { - SDL_Rect posb = pos; - CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb); - if(phase != 4 || nextPhase != -1 || image < 4) - { - if(flagAnimCount%2==0) - { - ++image; - } - if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame - { - image = 0; - } - } - if(phase == 4 && nextPhase != -1 && image == 7) - { - phase = nextPhase; - nextPhase = -1; - image = 0; - } - break; - } - } -} - -void CBattleHero::activate() -{ - activateLClick(); -} -void CBattleHero::deactivate() -{ - deactivateLClick(); -} - -void CBattleHero::setPhase(int newPhase) -{ - if(phase != 4) - { - phase = newPhase; - image = 0; - } - else - { - nextPhase = newPhase; - } -} - -void CBattleHero::clickLeft(tribool down, bool previousState) -{ - if(myOwner->spellDestSelectMode) //we are casting a spell - return; - - if(!down && myHero && myOwner->myTurn && myOwner->curInt->cb->battleCanCastSpell()) //check conditions - { - for(int it=0; itbfield[it].hovered && myOwner->bfield[it].strictHovered) - return; - } - CCS->curh->changeGraphic(0,0); - - CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), myHero, myOwner->curInt); - GH.pushInt(spellWindow); - } -} - -CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner): flip(flipG), myHero(hero), myOwner(owner), phase(phaseG), nextPhase(-1), image(imageG), flagAnim(0), flagAnimCount(0) -{ - dh = CDefHandler::giveDef( defName ); - for(int i=0; iourImages.size(); ++i) //transforming images - { - if(flip) - { - SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap); - SDL_FreeSurface(dh->ourImages[i].bitmap); - dh->ourImages[i].bitmap = hlp; - } - CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap); - } - - if(flip) - flag = CDefHandler::giveDef("CMFLAGR.DEF"); - else - flag = CDefHandler::giveDef("CMFLAGL.DEF"); - - //coloring flag and adding transparency - for(int i=0; iourImages.size(); ++i) - { - CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap); - graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player); - } -} - -CBattleHero::~CBattleHero() -{ - delete dh; - delete flag; -} - -Point CBattleHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * stack, const CBattleInterface * cbi) -{ - Point ret(-500, -500); //returned value - if(stack && stack->position < 0) //creatures in turrets - { - switch(stack->position) - { - case -2: //keep - ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][17]; - break; - case -3: //lower turret - ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][18]; - break; - case -4: //upper turret - ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][19]; - break; - } - } - else - { - ret.y = -139 + 42 * (hexNum/BFIELD_WIDTH); //counting y - //counting x - if(attacker) - { - ret.x = -160 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH); - } - else - { - ret.x = -219 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH); - } - //shifting position for double - hex creatures - if(stack && stack->doubleWide()) - { - if(attacker) - { - ret.x -= 44; - } - else - { - ret.x += 45; - } - } - } - //returning - return ret +CPlayerInterface::battleInt->pos; -} -void CBattleHex::activate() -{ - activateHover(); - activateMouseMove(); - activateLClick(); - activateRClick(); -} - -void CBattleHex::deactivate() -{ - deactivateHover(); - deactivateMouseMove(); - deactivateLClick(); - deactivateRClick(); -} - -void CBattleHex::hover(bool on) -{ - hovered = on; - //Hoverable::hover(on); - if(!on && setAlterText) - { - myInterface->console->alterTxt = std::string(); - setAlterText = false; - } -} - -CBattleHex::CBattleHex() : setAlterText(false), myNumber(-1), accessible(true), hovered(false), strictHovered(false), myInterface(NULL) -{ -} - -void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent) -{ - if(myInterface->cellShade) - { - if(CSDL_Ext::SDL_GetPixel(myInterface->cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex - { - strictHovered = false; - } - else //hovered pixel is inside hex - { - strictHovered = true; - } - } - - if(hovered && strictHovered) //print attacked creature to console - { - const CStack * attackedStack = myInterface->curInt->cb->battleGetStackByPos(myNumber); - if(myInterface->console->alterTxt.size() == 0 &&attackedStack != NULL && - attackedStack->owner != myInterface->curInt->playerID && - attackedStack->alive()) - { - char tabh[160]; - const std::string & attackedName = attackedStack->count == 1 ? attackedStack->getCreature()->nameSing : attackedStack->getCreature()->namePl; - sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); - myInterface->console->alterTxt = std::string(tabh); - setAlterText = true; - } - } - else if(setAlterText) - { - myInterface->console->alterTxt = std::string(); - setAlterText = false; - } -} - -void CBattleHex::clickLeft(tribool down, bool previousState) -{ - if(!down && hovered && strictHovered) //we've been really clicked! - { - myInterface->hexLclicked(myNumber); - } -} - -void CBattleHex::clickRight(tribool down, bool previousState) -{ - const CStack * myst = myInterface->curInt->cb->battleGetStackByPos(myNumber); //stack info - if(hovered && strictHovered && myst!=NULL) - { - - if(!myst->alive()) return; - if(down) - { - GH.pushInt(createCreWindow(myst)); - } - } -} - -CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt(""), whoSetAlter(0) -{ -} - -CBattleConsole::~CBattleConsole() -{ - texts.clear(); -} - -void CBattleConsole::show(SDL_Surface * to) -{ - if(ingcAlter.size()) - { - CSDL_Ext::printAtMiddleWB(ingcAlter, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); - } - else if(alterTxt.size()) - { - CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); - } - else if(texts.size()) - { - if(texts.size()==1) - { - CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); - } - else - { - CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); - CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 27, FONT_SMALL, 80, zwykly, to); - } - } -} - -bool CBattleConsole::addText(const std::string & text) -{ - if(text.size()>70) - return false; //text too long! - int firstInToken = 0; - for(int i=0; i= texts.size()) //no such pos - return; - texts[pos] = text; -} - -void CBattleConsole::scrollUp(unsigned int by) -{ - if(lastShown > by) - lastShown -= by; -} - -void CBattleConsole::scrollDown(unsigned int by) -{ - if(lastShown + by < texts.size()) - lastShown += by; -} - -CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect & pos, CBattleInterface * _owner) -: owner(_owner) -{ - this->pos = pos; - background = BitmapHandler::loadBitmap("CPRESULT.BMP", true); - graphics->blueToPlayersAdv(background, owner->curInt->playerID); - SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags); - SDL_FreeSurface(background); - background = pom; - exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleResultWindow::bExitf,this), 384 + pos.x, 505 + pos.y, "iok6432.def", SDLK_RETURN); - exit->borderColor = Colors::MetallicGold; - exit->borderEnabled = true; - - if(br.winner==0) //attacker won - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 59, 124, FONT_SMALL, zwykly, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 408, 124, FONT_SMALL, zwykly, background); - } - else //if(br.winner==1) - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 59, 124, FONT_SMALL, zwykly, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 412, 124, FONT_SMALL, zwykly, background); - } - - - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[407], 232, 302, FONT_BIG, tytulowy, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[408], 232, 332, FONT_BIG, zwykly, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[409], 237, 428, FONT_BIG, zwykly, background); - - std::string attackerName, defenderName; - - if(owner->attackingHeroInstance) //a hero attacked - { - SDL_Rect temp_rect = genRect(64, 58, 21, 38); - SDL_BlitSurface(graphics->portraitLarge[owner->attackingHeroInstance->portrait], NULL, background, &temp_rect); - //setting attackerName - attackerName = owner->attackingHeroInstance->name; - } - else //a monster attacked - { - int bestMonsterID = -1; - int bestPower = 0; - for(TSlots::const_iterator it = owner->army1->Slots().begin(); it!=owner->army1->Slots().end(); ++it) - { - if( it->second->type->AIValue > bestPower) - { - bestPower = it->second->type->AIValue; - bestMonsterID = it->second->type->idNumber; - } - } - SDL_Rect temp_rect = genRect(64, 58, 21, 38); - SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &temp_rect); - //setting attackerName - attackerName = CGI->creh->creatures[bestMonsterID]->namePl; - } - if(owner->defendingHeroInstance) //a hero defended - { - SDL_Rect temp_rect = genRect(64, 58, 392, 38); - SDL_BlitSurface(graphics->portraitLarge[owner->defendingHeroInstance->portrait], NULL, background, &temp_rect); - //setting defenderName - defenderName = owner->defendingHeroInstance->name; - } - else //a monster defended - { - int bestMonsterID = -1; - int bestPower = 0; - for(TSlots::const_iterator it = owner->army2->Slots().begin(); it!=owner->army2->Slots().end(); ++it) - { - if( it->second->type->AIValue > bestPower) - { - bestPower = it->second->type->AIValue; - bestMonsterID = it->second->type->idNumber; - } - } - SDL_Rect temp_rect = genRect(64, 58, 392, 38); - SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &temp_rect); - //setting defenderName - defenderName = CGI->creh->creatures[bestMonsterID]->namePl; - } - - //printing attacker and defender's names - CSDL_Ext::printAt(attackerName, 89, 37, FONT_SMALL, zwykly, background); - CSDL_Ext::printTo(defenderName, 381, 53, FONT_SMALL, zwykly, background); - //printing casualities - for(int step = 0; step < 2; ++step) - { - if(br.casualties[step].size()==0) - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[523], 235, 360 + 97*step, FONT_SMALL, zwykly, background); - } - else - { - int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture - int yPos = 344 + step*97; - for(std::map::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it) - { - blitAt(graphics->smallImgs[it->first], xPos, yPos, background); - std::ostringstream amount; - amount<second; - CSDL_Ext::printAtMiddle(amount.str(), xPos+16, yPos + 42, FONT_SMALL, zwykly, background); - xPos += 42; - } - } - } - //printing result description - bool weAreAttacker = (owner->curInt->playerID == owner->attackingHeroInstance->tempOwner); - if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won - { - int text=-1; - switch(br.result) - { - case 0: text = 304; break; - case 1: text = 303; break; - case 2: text = 302; break; - } - - CCS->musich->playMusic(musicBase::winBattle); - CCS->videoh->open(VIDEO_WIN); - std::string str = CGI->generaltexth->allTexts[text]; - - const CGHeroInstance * ourHero = weAreAttacker? owner->attackingHeroInstance : owner->defendingHeroInstance; - if (ourHero) - { - str += CGI->generaltexth->allTexts[305]; - boost::algorithm::replace_first(str,"%s",ourHero->name); - boost::algorithm::replace_first(str,"%d",boost::lexical_cast(br.exp[weAreAttacker?0:1])); - } - CSDL_Ext::printAtMiddleWB(str, 235, 235, FONT_SMALL, 55, zwykly, background); - } - else // we lose - { - switch(br.result) - { - case 0: //normal victory - { - CCS->musich->playMusic(musicBase::loseCombat); - CCS->videoh->open(VIDEO_LOSE_BATTLE_START); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[311], 235, 235, FONT_SMALL, zwykly, background); - break; - } - case 1: //flee - { - CCS->musich->playMusic(musicBase::retreatBattle); - CCS->videoh->open(VIDEO_RETREAT_START); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[310], 235, 235, FONT_SMALL, zwykly, background); - break; - } - case 2: //surrender - { - CCS->musich->playMusic(musicBase::surrenderBattle); - CCS->videoh->open(VIDEO_SURRENDER); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[309], 235, 220, FONT_SMALL, zwykly, background); - break; - } - } - } -} - -CBattleResultWindow::~CBattleResultWindow() -{ - SDL_FreeSurface(background); -} - -void CBattleResultWindow::activate() -{ - owner->curInt->showingDialog->set(true); - exit->activate(); -} - -void CBattleResultWindow::deactivate() -{ - exit->deactivate(); -} - -void CBattleResultWindow::show(SDL_Surface *to) -{ - //evaluating to - if(!to) - to = screen; - - CCS->videoh->update(107, 70, background, false, true); - - SDL_BlitSurface(background, NULL, to, &pos); - exit->showAll(to); -} - -void CBattleResultWindow::bExitf() -{ - if(LOCPLINT->cb->getStartInfo()->mode == StartInfo::DUEL) - { - std::exit(0); - } - - CPlayerInterface * intTmp = owner->curInt; - GH.popInts(2); //first - we; second - battle interface - intTmp->showingDialog->setn(false); - CCS->videoh->close(); -} - -CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - pos = position; - background = new CPicture("comopbck.bmp"); - background->colorize(owner->curInt->playerID); - - viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[427].first)(3,CGI->generaltexth->zelp[427].first), CGI->generaltexth->zelp[427].second, false, "sysopchk.def", NULL, 25, 56, false); - viewGrid->select(owner->curInt->sysOpts.printCellBorders); - movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[428].first)(3,CGI->generaltexth->zelp[428].first), CGI->generaltexth->zelp[428].second, false, "sysopchk.def", NULL, 25, 89, false); - movementShadow->select(owner->curInt->sysOpts.printStackRange); - mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[429].first)(3,CGI->generaltexth->zelp[429].first), CGI->generaltexth->zelp[429].second, false, "sysopchk.def", NULL, 25, 122, false); - mouseShadow->select(owner->curInt->sysOpts.printMouseShadow); - - animSpeeds = new CHighlightableButtonsGroup(0); - animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[422].first),CGI->generaltexth->zelp[422].second, "sysopb9.def", 28, 225, 1); - animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[423].first),CGI->generaltexth->zelp[423].second, "sysob10.def", 92, 225, 2); - animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[424].first),CGI->generaltexth->zelp[424].second, "sysob11.def",156, 225, 4); - animSpeeds->select(owner->getAnimSpeed(), 1); - animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1); - - setToDefault = new AdventureMapButton (CGI->generaltexth->zelp[393], boost::bind(&CBattleOptionsWindow::bDefaultf,this), 246, 359, "codefaul.def"); - setToDefault->swappedImages = true; - setToDefault->update(); - exit = new AdventureMapButton (CGI->generaltexth->zelp[392], boost::bind(&CBattleOptionsWindow::bExitf,this), 357, 359, "soretrn.def",SDLK_RETURN); - exit->swappedImages = true; - exit->update(); - - //creating labels - labels.push_back(new CLabel(242, 32, FONT_BIG, CENTER, tytulowy, CGI->generaltexth->allTexts[392]));//window title - labels.push_back(new CLabel(122, 214, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[393]));//animation speed - labels.push_back(new CLabel(122, 293, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[394]));//music volume - labels.push_back(new CLabel(122, 359, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[395]));//effects' volume - labels.push_back(new CLabel(353, 66, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[396]));//auto - combat options - labels.push_back(new CLabel(353, 265, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[397]));//creature info - - //auto - combat options - labels.push_back(new CLabel(283, 86, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[398]));//creatures - labels.push_back(new CLabel(283, 116, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[399]));//spells - labels.push_back(new CLabel(283, 146, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[400]));//catapult - labels.push_back(new CLabel(283, 176, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[151]));//ballista - labels.push_back(new CLabel(283, 206, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[401]));//first aid tent - - //creature info - labels.push_back(new CLabel(283, 285, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[402]));//all stats - labels.push_back(new CLabel(283, 315, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[403]));//spells only - - //general options - labels.push_back(new CLabel(61, 57, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[404])); - labels.push_back(new CLabel(61, 90, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[405])); - labels.push_back(new CLabel(61, 123, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[406])); - labels.push_back(new CLabel(61, 156, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[407])); -} - -void CBattleOptionsWindow::bDefaultf() -{ -} - -void CBattleOptionsWindow::bExitf() -{ - GH.popIntTotally(this); -} - -std::string CBattleInterface::SiegeHelper::townTypeInfixes[F_NUMBER] = {"CS", "RM", "TW", "IN", "NC", "DN", "ST", "FR", "EL"}; +std::string CBattleInterface::SiegeHelper::townTypeInfixes[GameConstants::F_NUMBER] = {"CS", "RM", "TW", "IN", "NC", "DN", "ST", "FR", "EL"}; CBattleInterface::SiegeHelper::SiegeHelper(const CGTownInstance *siegeTown, const CBattleInterface * _owner) : owner(_owner), town(siegeTown) { - for(int g=0; gcurInt->cb->getStackQueue(stacksSorted, QUEUE_SIZE); - for (int i = 0; i < QUEUE_SIZE ; i++) - { - stackBoxes[i]->setStack(stacksSorted[i]); - } -} - -CStackQueue::CStackQueue(bool Embedded, CBattleInterface * _owner) -:embedded(Embedded), owner(_owner) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - if(embedded) - { - box = NULL; - bg = NULL; - pos.w = QUEUE_SIZE * 37; - pos.h = 32; //height of small creature img - pos.x = screen->w/2 - pos.w/2; - pos.y = (screen->h - 600)/2 + 10; - } - else - { - box = BitmapHandler::loadBitmap("CHRROP.pcx"); - bg = BitmapHandler::loadBitmap("DIBOXPI.pcx"); - pos.w = 600; - pos.h = bg->h; - } - - stackBoxes.resize(QUEUE_SIZE); - for (int i = 0; i < QUEUE_SIZE; i++) - { - stackBoxes[i] = new StackBox(box); - stackBoxes[i]->pos.x += 6 + (embedded ? 37 : 79)*i; - } -} - -CStackQueue::~CStackQueue() -{ - SDL_FreeSurface(box); -} - -void CStackQueue::showAll( SDL_Surface *to ) -{ - blitBg(to); - - CIntObject::showAll(to); -} - -void CStackQueue::blitBg( SDL_Surface * to ) -{ - if(bg) - { - for (int w = 0; w < pos.w; w += bg->w) - { - blitAtLoc(bg, w, 0, to); - } - } -} - -void CStackQueue::StackBox::showAll( SDL_Surface *to ) -{ - assert(my); - if(bg) - { - graphics->blueToPlayersAdv(bg, my->owner); - //SDL_UpdateRect(bg, 0, 0, 0, 0); - SDL_Rect temp_rect = genRect(bg->h, bg->w, pos.x, pos.y); - CSDL_Ext::blit8bppAlphaTo24bpp(bg, NULL, to, &temp_rect); - //blitAt(bg, pos, to); - blitAt(graphics->bigImgs[my->getCreature()->idNumber], pos.x +9, pos.y + 1, to); - printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 12, FONT_MEDIUM, zwykly, to); - } - else - { - blitAt(graphics->smallImgs[-2], pos, to); - blitAt(graphics->smallImgs[my->getCreature()->idNumber], pos, to); - const SDL_Color &ownerColor = (my->owner == 255 ? *graphics->neutralColor : graphics->playerColors[my->owner]); - CSDL_Ext::drawBorder(to, pos, int3(ownerColor.r, ownerColor.g, ownerColor.b)); - printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 8, FONT_TINY, zwykly, to); - } -} - -void CStackQueue::StackBox::setStack( const CStack *nStack ) -{ - my = nStack; -} - -CStackQueue::StackBox::StackBox(SDL_Surface *BG) - :my(NULL), bg(BG) -{ - if(bg) - { - pos.w = bg->w; - pos.h = bg->h; - } - else - { - pos.w = pos.h = 32; - } - - pos.y += 2; -} - -CStackQueue::StackBox::~StackBox() -{ -} - -void CStackQueue::StackBox::hover( bool on ) -{ - -} - -double CatapultProjectileInfo::calculateY(double x) +double SCatapultSProjectileInfo::calculateY(double x) { return (facA * pow(10., -3.)) * pow(x, 2.0) + facB * x + facC; } diff --git a/client/BattleInterface/CBattleInterface.h b/client/BattleInterface/CBattleInterface.h new file mode 100644 index 000000000..ae233e276 --- /dev/null +++ b/client/BattleInterface/CBattleInterface.h @@ -0,0 +1,256 @@ +#pragma once + + +#include "../GUIBase.h" +#include "../../lib/CCreatureSet.h" +#include "../../lib/ConstTransitivePtr.h" //may be reundant +#include "../CAnimation.h" +#include "SStackAttackedInfo.h" +#include "CHexFieldControl.h" +#include "CShootingAnimation.h" +#include "../../lib/SHexField.h" +#include "../../lib/GameConstants.h" + +/* + * CBattleInterface.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +class CLabel; +class CCreatureSet; +class CGHeroInstance; +class CDefHandler; +class CStack; +class CCallback; +class AdventureMapButton; +class CHighlightableButton; +class CHighlightableButtonsGroup; +struct BattleResult; +struct BattleSpellCast; +struct CObstacleInstance; +template struct CondSh; +struct SetStackEffect;; +struct BattleAction; +class CGTownInstance; +struct CatapultAttack; +class CBattleInterface; +struct SCatapultSProjectileInfo; +struct BattleTriggerEffect; +class CBattleAnimation; +class CBattleHero; +class CBattleConsole; +class CBattleResultWindow; +class CStackQueue; + +/// Class which manages the locked hex fields that are blocked e.g. by obstacles +class CBattleObstacle +{ + std::vector lockedHexes; +}; + +/// Struct for battle effect animation e.g. morale, prayer, armageddon, bless,... +struct SBattleEffect +{ + int x, y; //position on the screen + int frame, maxFrame; + CDefHandler * anim; //animation to display + int effectID; //uniqueID equal ot ID of appropriate CSpellEffectAnim +}; + +/// Small struct which is needed for drawing the parabolic trajectory of the catapult cannon +struct SCatapultSProjectileInfo +{ + const double facA, facB, facC; + const int fromX, toX; + + SCatapultSProjectileInfo() : facA(0), facB(0), facC(0), fromX(0), toX(0) { }; + SCatapultSProjectileInfo(double factorA, double factorB, double factorC, int fromXX, int toXX) : facA(factorA), facB(factorB), facC(factorC), + fromX(fromXX), toX(toXX) { }; + + double calculateY(double x); +}; + +/// Big class which handles the overall battle interface actions and it is also responsible for +/// drawing everything correctly. +class CBattleInterface : public CIntObject +{ + enum SpellSelectionType + { + ANY_LOCATION = 0, FRIENDLY_CREATURE, HOSTILE_CREATURE, ANY_CREATURE, OBSTACLE, TELEPORT, NO_LOCATION = -1, STACK_SPELL_CANCELLED = -2 + }; +private: + SDL_Surface * background, * menu, * amountNormal, * amountNegative, * amountPositive, * amountEffNeutral, * cellBorders, * backgroundWithHexes; + AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell, + * bWait, * bDefence, * bConsoleUp, * bConsoleDown, *btactNext, *btactEnd; + CBattleConsole * console; + CBattleHero * attackingHero, * defendingHero; //fighting heroes + CStackQueue *queue; + const CCreatureSet *army1, *army2; //copy of initial armies (for result window) + const 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 creatures (creatureID, defhandler) + std::map< int, CDefHandler * > idToObstacle; //obstacles located on the battlefield + std::map< int, bool > creDir; // + ui8 animCount; + const CStack * activeStack; //number of active stack; NULL - no one + const CStack * stackToActivate; //when animation is playing, we should wait till the end to make the next stack active; NULL of none + void activateStack(); //sets activeStack to stackToActivate etc. + int mouseHoveredStack; //stack hovered by mouse; if -1 -> none + time_t lastMouseHoveredStackAnimationTime; // time when last mouse hovered animation occurred + static const time_t HOVER_ANIM_DELTA; + std::vector occupyableHexes, //hexes available for active stack + attackableHexes; //hexes attackable by active stack + bool stackCountOutsideHexes[GameConstants::BFIELD_SIZE]; // hexes that when in front of a unit cause it's amount box to move back + int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago + int currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon) + int attackingHex; //hex from which the stack would perform attack with current cursor + double getAnimSpeedMultiplier() const; //returns multiplier for number of frames in a group + std::map standingFrame; //number of frame in standing animation by stack ID, helps in showing 'random moves' + + CPlayerInterface *tacticianInterface; //used during tactics mode, points to the interface of player with higher tactics (can be either attacker or defender in hot-seat), valid onloy for human players + bool tacticsMode; + bool stackCanCastSpell; //if true, active stack could possibly cats some target spell + bool spellDestSelectMode; //if true, player is choosing destination for his spell + SpellSelectionType spellSelMode; + BattleAction * spellToCast; //spell for which player is choosing destination + ui32 creatureSpellToCast; + void endCastingSpell(); //ends casting spell (eg. when spell has been cast or canceled) + + void showAliveStack(const CStack *stack, SDL_Surface * to); //helper function for function show + void showAliveStacks(std::vector *aliveStacks, int hex, std::vector *flyingStacks, SDL_Surface *to); // loops through all stacks at a given hex position + void showPieceOfWall(SDL_Surface * to, int hex, const std::vector & stacks); //helper function for show + void showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to); // show all obstacles at a given hex position + void redrawBackgroundWithHexes(const CStack * activeStack); + void printConsoleAttacked(const CStack * defender, int dmg, int killed, const CStack * attacker, bool Multiple); + + std::list projectiles; //projectiles flying on battlefield + void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield + void giveCommand(ui8 action, SHexField tile, ui32 stack, si32 additional=-1); + bool isTileAttackable(const SHexField & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles + bool blockedByObstacle(SHexField hex) const; + bool isCatapultAttackable(SHexField hex) const; //returns true if given tile can be attacked by catapult + + std::list battleEffects; //different animations to display on the screen like spell effects + + /// Class which is responsible for drawing the wall of a siege during battle + class SiegeHelper + { + private: + static std::string townTypeInfixes[GameConstants::F_NUMBER]; //for internal use only - to build filenames + SDL_Surface* walls[18]; + const CBattleInterface * owner; + public: + const CGTownInstance * town; //besieged town + + SiegeHelper(const CGTownInstance * siegeTown, const CBattleInterface * _owner); //c-tor + ~SiegeHelper(); //d-tor + + //filename getters + std::string getSiegeName(ui16 what, ui16 additInfo = 1) const; //what: 0 - background, 1 - background wall, 2 - keep, 3 - bottom tower, 4 - bottom wall, 5 - below gate, 6 - over gate, 7 - upper wall, 8 - uppert tower, 9 - gate, 10 - gate arch, 11 - bottom static wall, 12 - upper static wall, 13 - moat, 14 - mlip, 15 - keep creature cover, 16 - bottom turret creature cover, 17 - upper turret creature cover; additInfo: 1 - intact, 2 - damaged, 3 - destroyed + + void printPartOfWall(SDL_Surface * to, int what);//what: 1 - background wall, 2 - keep, 3 - bottom tower, 4 - bottom wall, 5 - below gate, 6 - over gate, 7 - upper wall, 8 - uppert tower, 9 - gate, 10 - gate arch, 11 - bottom static wall, 12 - upper static wall, 15 - keep creature cover, 16 - bottom turret creature cover, 17 - upper turret creature cover + + friend class CBattleInterface; + } * siegeH; + + CPlayerInterface * attackerInt, * defenderInt; //because LOCPLINT is not enough in hotSeat + const CGHeroInstance * getActiveHero(); //returns hero that can currently cast a spell +public: + CPlayerInterface * curInt; //current player interface + std::list > pendingAnims; //currently displayed animations + void addNewAnim(CBattleAnimation * anim); //adds new anim to pendingAnims + ui32 animIDhelper; //for giving IDs for animations + static CondSh animsAreDisplayed; //for waiting with the end of battle for end of anims + + CBattleInterface(const CCreatureSet * army1, const CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect, CPlayerInterface * att, CPlayerInterface * defen); //c-tor + ~CBattleInterface(); //d-tor + + //std::vector timeinterested; //animation handling + void setPrintCellBorders(bool set); //if true, cell borders will be printed + void setPrintStackRange(bool set); //if true,range of active stack will be printed + void setPrintMouseShadow(bool set); //if true, hex under mouse will be shaded + void setAnimSpeed(int set); //speed of animation; 1 - slowest, 2 - medium, 4 - fastest + int getAnimSpeed() const; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest + + CHexFieldControl bfield[GameConstants::BFIELD_SIZE]; //11 lines, 17 hexes on each + //std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield + SDL_Surface * cellBorder, * cellShade; + CondSh *givenCommand; //data != NULL if we have i.e. moved current unit + bool myTurn; //if true, interface is active (commands can be ordered) + CBattleResultWindow * resWindow; //window of end of battle + + bool moveStarted; //if true, the creature that is already moving is going to make its first step + int moveSh; // sound handler used when moving a unit + + //button handle funcs: + void bOptionsf(); + void bSurrenderf(); + void bFleef(); + void reallyFlee(); //performs fleeing without asking player + void reallySurrender(); //performs surrendering without asking player + void bAutofightf(); + void bSpellf(); + void bWaitf(); + void bDefencef(); + void bConsoleUpf(); + void bConsoleDownf(); + void bTacticNextStack(); + void bEndTacticPhase(); + //end of button handle funcs + //napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem + void activate(); + void deactivate(); + void show(SDL_Surface * to); + void keyPressed(const SDL_KeyboardEvent & key); + void mouseMoved(const SDL_MouseMotionEvent &sEvent); + void clickRight(tribool down, bool previousState); + + //call-ins + void startAction(const BattleAction* action); + void newStack(const CStack * stack); //new stack appeared on battlefield + void stackRemoved(int stackID); //stack disappeared from batlefiled + void stackActivated(const CStack * stack); //active stack has been changed + void stackMoved(const CStack * stack, std::vector destHex, int distance); //stack with id number moved to destHex + void waitForAnims(); + void stacksAreAttacked(std::vector attackedInfos); //called when a certain amount of stacks has been attacked + void stackAttacking(const CStack * attacker, SHexField dest, const CStack * attacked, bool shooting); //called when stack with id ID is attacking something on hex dest + void newRoundFirst( int round ); + void newRound(int number); //caled when round is ended; number is the number of round + void hexLclicked(int whichOne); //hex only call-in + void stackIsCatapulting(const CatapultAttack & ca); //called when a stack is attacking walls + void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed + const BattleResult * bresult; //result of a battle; if non-zero then display when all animations end + void displayBattleFinished(); //displays battle result + void spellCast(const BattleSpellCast * sc); //called when a hero casts a spell + void battleStacksEffectsSet(const SetStackEffect & sse); //called when a specific effect is set to stacks + void castThisSpell(int spellID); //called when player has chosen a spell from spellbook + void displayEffect(ui32 effect, int destTile); //displays effect of a spell on the battlefield; affected: true - attacker. false - defender + void battleTriggerEffect(const BattleTriggerEffect & bte); + void setBattleCursor(const int myNumber); //really complex and messy + void endAction(const BattleAction* action); + void hideQueue(); + void showQueue(); + + + friend class CPlayerInterface; + friend class AdventureMapButton; + friend class CInGameConsole; + + friend class CBattleResultWindow; + friend class CBattleHero; + friend class CSpellEffectAnimation; + friend class CBattleStackAnimation; + friend class CReverseAnimation; + friend class CDefenceAnimation; + friend class CMovementAnimation; + friend class CMovementStartAnimation; + friend class CAttackAnimation; + friend class CMeleeAttackAnimation; + friend class CShootingAnimation; + friend class CHexFieldControl; +}; diff --git a/client/BattleInterface/CBattleOptionsWindow.cpp b/client/BattleInterface/CBattleOptionsWindow.cpp new file mode 100644 index 000000000..fd09bc796 --- /dev/null +++ b/client/BattleInterface/CBattleOptionsWindow.cpp @@ -0,0 +1,73 @@ +#include "StdInc.h" +#include "CBattleOptionsWindow.h" + +#include "CBattleInterface.h" +#include "../GUIBase.h" +#include "../GUIClasses.h" +#include "../AdventureMapButton.h" +#include "../CGameInfo.h" +#include "../CPlayerInterface.h" +#include "../../lib/CGeneralTextHandler.h" + +CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + pos = position; + background = new CPicture("comopbck.bmp"); + background->colorize(owner->curInt->playerID); + + viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[427].first)(3,CGI->generaltexth->zelp[427].first), CGI->generaltexth->zelp[427].second, false, "sysopchk.def", NULL, 25, 56, false); + viewGrid->select(owner->curInt->sysOpts.printCellBorders); + movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[428].first)(3,CGI->generaltexth->zelp[428].first), CGI->generaltexth->zelp[428].second, false, "sysopchk.def", NULL, 25, 89, false); + movementShadow->select(owner->curInt->sysOpts.printStackRange); + mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[429].first)(3,CGI->generaltexth->zelp[429].first), CGI->generaltexth->zelp[429].second, false, "sysopchk.def", NULL, 25, 122, false); + mouseShadow->select(owner->curInt->sysOpts.printMouseShadow); + + animSpeeds = new CHighlightableButtonsGroup(0); + animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[422].first),CGI->generaltexth->zelp[422].second, "sysopb9.def", 28, 225, 1); + animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[423].first),CGI->generaltexth->zelp[423].second, "sysob10.def", 92, 225, 2); + animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[424].first),CGI->generaltexth->zelp[424].second, "sysob11.def",156, 225, 4); + animSpeeds->select(owner->getAnimSpeed(), 1); + animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1); + + setToDefault = new AdventureMapButton (CGI->generaltexth->zelp[393], boost::bind(&CBattleOptionsWindow::bDefaultf,this), 246, 359, "codefaul.def"); + setToDefault->swappedImages = true; + setToDefault->update(); + exit = new AdventureMapButton (CGI->generaltexth->zelp[392], boost::bind(&CBattleOptionsWindow::bExitf,this), 357, 359, "soretrn.def",SDLK_RETURN); + exit->swappedImages = true; + exit->update(); + + //creating labels + labels.push_back(new CLabel(242, 32, FONT_BIG, CENTER, tytulowy, CGI->generaltexth->allTexts[392]));//window title + labels.push_back(new CLabel(122, 214, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[393]));//animation speed + labels.push_back(new CLabel(122, 293, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[394]));//music volume + labels.push_back(new CLabel(122, 359, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[395]));//effects' volume + labels.push_back(new CLabel(353, 66, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[396]));//auto - combat options + labels.push_back(new CLabel(353, 265, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[397]));//creature info + + //auto - combat options + labels.push_back(new CLabel(283, 86, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[398]));//creatures + labels.push_back(new CLabel(283, 116, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[399]));//spells + labels.push_back(new CLabel(283, 146, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[400]));//catapult + labels.push_back(new CLabel(283, 176, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[151]));//ballista + labels.push_back(new CLabel(283, 206, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[401]));//first aid tent + + //creature info + labels.push_back(new CLabel(283, 285, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[402]));//all stats + labels.push_back(new CLabel(283, 315, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[403]));//spells only + + //general options + labels.push_back(new CLabel(61, 57, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[404])); + labels.push_back(new CLabel(61, 90, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[405])); + labels.push_back(new CLabel(61, 123, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[406])); + labels.push_back(new CLabel(61, 156, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[407])); +} + +void CBattleOptionsWindow::bDefaultf() +{ +} + +void CBattleOptionsWindow::bExitf() +{ + GH.popIntTotally(this); +} \ No newline at end of file diff --git a/client/BattleInterface/CBattleOptionsWindow.h b/client/BattleInterface/CBattleOptionsWindow.h new file mode 100644 index 000000000..4aecf6d75 --- /dev/null +++ b/client/BattleInterface/CBattleOptionsWindow.h @@ -0,0 +1,39 @@ +#pragma once + +#include "../GUIBase.h" + +class CBattleInterface; +class CPicture; +class AdventureMapButton; +class CHighlightableButton; +class CHighlightableButtonsGroup; +class CLabel; +struct SDL_Rect; + +/* + * CBattleOptionsWindow.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Class which manages the battle options window +class CBattleOptionsWindow : public CIntObject +{ +private: + CBattleInterface *myInt; + CPicture *background; + AdventureMapButton *setToDefault, *exit; + CHighlightableButton *viewGrid, *movementShadow, *mouseShadow; + CHighlightableButtonsGroup *animSpeeds; + + std::vector labels; +public: + CBattleOptionsWindow(const SDL_Rect &position, CBattleInterface *owner); //c-tor + + void bDefaultf(); //default button callback + void bExitf(); //exit button callback +}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleResultWindow.cpp b/client/BattleInterface/CBattleResultWindow.cpp new file mode 100644 index 000000000..566ce5455 --- /dev/null +++ b/client/BattleInterface/CBattleResultWindow.cpp @@ -0,0 +1,216 @@ +#include "StdInc.h" +#include "CBattleResultWindow.h" + +#include "CBattleInterface.h" +#include "../AdventureMapButton.h" +#include "../CGameInfo.h" +#include "../../lib/CObjectHandler.h" +#include "../../lib/NetPacks.h" +#include "../../lib/CCreatureHandler.h" +#include "../../lib/CGeneralTextHandler.h" +#include "../CMusicHandler.h" +#include "../CPlayerInterface.h" +#include "../Graphics.h" +#include "../../CCallback.h" +#include "../CVideoHandler.h" +#include "../SDL_Extensions.h" +#include "../CBitmapHandler.h" + +CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect & pos, CBattleInterface * _owner) +: owner(_owner) +{ + this->pos = pos; + background = BitmapHandler::loadBitmap("CPRESULT.BMP", true); + graphics->blueToPlayersAdv(background, owner->curInt->playerID); + SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags); + SDL_FreeSurface(background); + background = pom; + exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleResultWindow::bExitf,this), 384 + pos.x, 505 + pos.y, "iok6432.def", SDLK_RETURN); + exit->borderColor = Colors::MetallicGold; + exit->borderEnabled = true; + + if(br.winner==0) //attacker won + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 59, 124, FONT_SMALL, zwykly, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 408, 124, FONT_SMALL, zwykly, background); + } + else //if(br.winner==1) + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 59, 124, FONT_SMALL, zwykly, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 412, 124, FONT_SMALL, zwykly, background); + } + + + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[407], 232, 302, FONT_BIG, tytulowy, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[408], 232, 332, FONT_BIG, zwykly, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[409], 237, 428, FONT_BIG, zwykly, background); + + std::string attackerName, defenderName; + + if(owner->attackingHeroInstance) //a hero attacked + { + SDL_Rect temp_rect = genRect(64, 58, 21, 38); + SDL_BlitSurface(graphics->portraitLarge[owner->attackingHeroInstance->portrait], NULL, background, &temp_rect); + //setting attackerName + attackerName = owner->attackingHeroInstance->name; + } + else //a monster attacked + { + int bestMonsterID = -1; + ui32 bestPower = 0; + for(TSlots::const_iterator it = owner->army1->Slots().begin(); it!=owner->army1->Slots().end(); ++it) + { + if(it->second->type->AIValue > bestPower) + { + bestPower = it->second->type->AIValue; + bestMonsterID = it->second->type->idNumber; + } + } + SDL_Rect temp_rect = genRect(64, 58, 21, 38); + SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &temp_rect); + //setting attackerName + attackerName = CGI->creh->creatures[bestMonsterID]->namePl; + } + if(owner->defendingHeroInstance) //a hero defended + { + SDL_Rect temp_rect = genRect(64, 58, 392, 38); + SDL_BlitSurface(graphics->portraitLarge[owner->defendingHeroInstance->portrait], NULL, background, &temp_rect); + //setting defenderName + defenderName = owner->defendingHeroInstance->name; + } + else //a monster defended + { + int bestMonsterID = -1; + ui32 bestPower = 0; + for(TSlots::const_iterator it = owner->army2->Slots().begin(); it!=owner->army2->Slots().end(); ++it) + { + if( it->second->type->AIValue > bestPower) + { + bestPower = it->second->type->AIValue; + bestMonsterID = it->second->type->idNumber; + } + } + SDL_Rect temp_rect = genRect(64, 58, 392, 38); + SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &temp_rect); + //setting defenderName + defenderName = CGI->creh->creatures[bestMonsterID]->namePl; + } + + //printing attacker and defender's names + CSDL_Ext::printAt(attackerName, 89, 37, FONT_SMALL, zwykly, background); + CSDL_Ext::printTo(defenderName, 381, 53, FONT_SMALL, zwykly, background); + //printing casualities + for(int step = 0; step < 2; ++step) + { + if(br.casualties[step].size()==0) + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[523], 235, 360 + 97*step, FONT_SMALL, zwykly, background); + } + else + { + int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture + int yPos = 344 + step*97; + for(std::map::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it) + { + blitAt(graphics->smallImgs[it->first], xPos, yPos, background); + std::ostringstream amount; + amount<second; + CSDL_Ext::printAtMiddle(amount.str(), xPos+16, yPos + 42, FONT_SMALL, zwykly, background); + xPos += 42; + } + } + } + //printing result description + bool weAreAttacker = (owner->curInt->playerID == owner->attackingHeroInstance->tempOwner); + if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won + { + int text=-1; + switch(br.result) + { + case 0: text = 304; break; + case 1: text = 303; break; + case 2: text = 302; break; + } + + CCS->musich->playMusic(musicBase::winBattle); + CCS->videoh->open(VIDEO_WIN); + std::string str = CGI->generaltexth->allTexts[text]; + + const CGHeroInstance * ourHero = weAreAttacker? owner->attackingHeroInstance : owner->defendingHeroInstance; + if (ourHero) + { + str += CGI->generaltexth->allTexts[305]; + boost::algorithm::replace_first(str,"%s",ourHero->name); + boost::algorithm::replace_first(str,"%d",boost::lexical_cast(br.exp[weAreAttacker?0:1])); + } + CSDL_Ext::printAtMiddleWB(str, 235, 235, FONT_SMALL, 55, zwykly, background); + } + else // we lose + { + switch(br.result) + { + case 0: //normal victory + { + CCS->musich->playMusic(musicBase::loseCombat); + CCS->videoh->open(VIDEO_LOSE_BATTLE_START); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[311], 235, 235, FONT_SMALL, zwykly, background); + break; + } + case 1: //flee + { + CCS->musich->playMusic(musicBase::retreatBattle); + CCS->videoh->open(VIDEO_RETREAT_START); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[310], 235, 235, FONT_SMALL, zwykly, background); + break; + } + case 2: //surrender + { + CCS->musich->playMusic(musicBase::surrenderBattle); + CCS->videoh->open(VIDEO_SURRENDER); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[309], 235, 220, FONT_SMALL, zwykly, background); + break; + } + } + } +} + +CBattleResultWindow::~CBattleResultWindow() +{ + SDL_FreeSurface(background); +} + +void CBattleResultWindow::activate() +{ + owner->curInt->showingDialog->set(true); + exit->activate(); +} + +void CBattleResultWindow::deactivate() +{ + exit->deactivate(); +} + +void CBattleResultWindow::show(SDL_Surface *to) +{ + //evaluating to + if(!to) + to = screen; + + CCS->videoh->update(107, 70, background, false, true); + + SDL_BlitSurface(background, NULL, to, &pos); + exit->showAll(to); +} + +void CBattleResultWindow::bExitf() +{ + if(LOCPLINT->cb->getStartInfo()->mode == StartInfo::DUEL) + { + std::exit(0); + } + + CPlayerInterface * intTmp = owner->curInt; + GH.popInts(2); //first - we; second - battle interface + intTmp->showingDialog->setn(false); + CCS->videoh->close(); +} \ No newline at end of file diff --git a/client/BattleInterface/CBattleResultWindow.h b/client/BattleInterface/CBattleResultWindow.h new file mode 100644 index 000000000..c49ee74d8 --- /dev/null +++ b/client/BattleInterface/CBattleResultWindow.h @@ -0,0 +1,37 @@ +#pragma once + +#include "../GUIBase.h" + +struct SDL_Surface; +class AdventureMapButton; +class CBattleInterface; +struct SDL_Rect; +struct BattleResult; + +/* + * CBattleResultWindow.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Class which is responsible for showing the battle result window +class CBattleResultWindow : public CIntObject +{ +private: + SDL_Surface *background; + AdventureMapButton *exit; + CBattleInterface *owner; +public: + CBattleResultWindow(const BattleResult &br, const SDL_Rect &pos, CBattleInterface *_owner); //c-tor + ~CBattleResultWindow(); //d-tor + + void bExitf(); //exit button callback + + void activate(); + void deactivate(); + void show(SDL_Surface * to = 0); +}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleStackAnimation.cpp b/client/BattleInterface/CBattleStackAnimation.cpp new file mode 100644 index 000000000..7a3eb11dd --- /dev/null +++ b/client/BattleInterface/CBattleStackAnimation.cpp @@ -0,0 +1,57 @@ +#include "StdInc.h" +#include "CBattleStackAnimation.h" + +#include "CBattleInterface.h" +#include "../../lib/BattleState.h" + +CBattleStackAnimation::CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack) +: CBattleAnimation(_owner), stack(_stack) +{ +} + +bool CBattleStackAnimation::isToReverseHlp(SHexField hexFrom, SHexField hexTo, bool curDir) +{ + int fromMod = hexFrom % GameConstants::BFIELD_WIDTH; + int fromDiv = hexFrom / GameConstants::BFIELD_WIDTH; + int toMod = hexTo % GameConstants::BFIELD_WIDTH; + + if(curDir && fromMod < toMod) + return false; + else if(curDir && fromMod > toMod) + return true; + else if(curDir && fromMod == toMod) + { + return fromDiv % 2 == 0; + } + else if(!curDir && fromMod < toMod) + return true; + else if(!curDir && fromMod > toMod) + return false; + else if(!curDir && fromMod == toMod) + { + return fromDiv % 2 == 1; + } + tlog1 << "Catastrope in CBattleStackAnimation::isToReverse!" << std::endl; + return false; //should never happen +} + +bool CBattleStackAnimation::isToReverse(SHexField hexFrom, SHexField hexTo, bool curDir, bool toDoubleWide, bool toDir) +{ + if(hexTo < 0) //turret + return false; + + if(toDoubleWide) + { + return isToReverseHlp(hexFrom, hexTo, curDir) && + (toDir ? isToReverseHlp(hexFrom, hexTo-1, curDir) : isToReverseHlp(hexFrom, hexTo+1, curDir) ); + } + else + { + return isToReverseHlp(hexFrom, hexTo, curDir); + } +} + +CCreatureAnimation* CBattleStackAnimation::myAnim() +{ + return owner->creAnims[stack->ID]; +} \ No newline at end of file diff --git a/client/BattleInterface/CBattleStackAnimation.h b/client/BattleInterface/CBattleStackAnimation.h new file mode 100644 index 000000000..49eaa1a07 --- /dev/null +++ b/client/BattleInterface/CBattleStackAnimation.h @@ -0,0 +1,31 @@ +#pragma once + +#include "CBattleAnimation.h" +#include "../../lib/SHexField.h" + +class CStack; +class CBattleInterface; +class CCreatureAnimation; + +/* + * CBattleStackAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Sub-class which is responsible for managing the battle stack animation. +class CBattleStackAnimation : public CBattleAnimation +{ +public: + const CStack * stack; //id of stack whose animation it is + + CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack); + static bool isToReverseHlp(SHexField hexFrom, SHexField hexTo, bool curDir); //helper for isToReverse + static bool isToReverse(SHexField hexFrom, SHexField hexTo, bool curDir /*if true, creature is in attacker's direction*/, bool toDoubleWide, bool toDir); //determines if creature should be reversed (it stands on hexFrom and should 'see' hexTo) + + CCreatureAnimation *myAnim(); //animation for our stack +}; \ No newline at end of file diff --git a/client/BattleInterface/CDefenceAnimation.cpp b/client/BattleInterface/CDefenceAnimation.cpp new file mode 100644 index 000000000..4a342a2a1 --- /dev/null +++ b/client/BattleInterface/CDefenceAnimation.cpp @@ -0,0 +1,139 @@ +#include "StdInc.h" +#include "CDefenceAnimation.h" + +#include "CBattleInterface.h" +#include "../CGameInfo.h" +#include "../CCreatureAnimation.h" +#include "../CPlayerInterface.h" +#include "../CMusicHandler.h" +#include "../../lib/BattleState.h" +#include "CReverseAnimation.h" +#include "CAttackAnimation.h" +#include "CShootingAnimation.h" + +bool CDefenceAnimation::init() +{ + //checking initial conditions + + //if(owner->creAnims[stackID]->getType() != 2) + //{ + // return false; + //} + + if(attacker == NULL && owner->battleEffects.size() > 0) + return false; + + ui32 lowestMoveID = owner->animIDhelper + 5; + for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + CDefenceAnimation * defAnim = dynamic_cast(it->first); + if(defAnim && defAnim->stack->ID != stack->ID) + continue; + + CAttackAnimation * attAnim = dynamic_cast(it->first); + if(attAnim && attAnim->stack->ID != stack->ID) + continue; + + if(attacker != NULL) + { + int attackerAnimType = owner->creAnims[attacker->ID]->getType(); + if( attackerAnimType == 11 && attackerAnimType == 12 && attackerAnimType == 13 && owner->creAnims[attacker->ID]->getFrame() < attacker->getCreature()->attackClimaxFrame ) + return false; + } + + CReverseAnimation * animAsRev = dynamic_cast(it->first); + + if(animAsRev && animAsRev->priority) + return false; + + if(it->first) + vstd::amin(lowestMoveID, it->first->ID); + } + if(ID > lowestMoveID) + return false; + + + + //reverse unit if necessary + if(attacker && isToReverse(stack->position, attacker->position, owner->creDir[stack->ID], attacker->doubleWide(), owner->creDir[attacker->ID])) + { + owner->addNewAnim(new CReverseAnimation(owner, stack, stack->position, true)); + return false; + } + //unit reversed + + if(byShooting) //delay hit animation + { + for(std::list::const_iterator it = owner->projectiles.begin(); it != owner->projectiles.end(); ++it) + { + if(it->creID == attacker->getCreature()->idNumber) + { + return false; + } + } + } + + //initializing + if(killed) + { + CCS->soundh->playSound(battle_sound(stack->getCreature(), killed)); + myAnim()->setType(CCreatureAnim::DEATH); //death + } + else + { + // TODO: this block doesn't seems correct if the unit is defending. + CCS->soundh->playSound(battle_sound(stack->getCreature(), wince)); + myAnim()->setType(CCreatureAnim::HITTED); //getting hit + } + + return true; //initialized successfuly +} + +void CDefenceAnimation::nextFrame() +{ + if(!killed && myAnim()->getType() != CCreatureAnim::HITTED) + { + myAnim()->setType(CCreatureAnim::HITTED); + } + + if(!myAnim()->onLastFrameInGroup()) + { + if( myAnim()->getType() == CCreatureAnim::DEATH && (owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0 + && !myAnim()->onLastFrameInGroup() ) + { + myAnim()->incrementFrame(); + } + } + else + { + endAnim(); + } + +} + +void CDefenceAnimation::endAnim() +{ + //restoring animType + + if(myAnim()->getType() == CCreatureAnim::HITTED) + myAnim()->setType(CCreatureAnim::HOLDING); + + //printing info to console + + //if(attacker!=NULL) + // owner->printConsoleAttacked(stack, dmg, amountKilled, attacker); + + //const CStack * attacker = owner->curInt->cb->battleGetStackByID(IDby, false); + //const CStack * attacked = owner->curInt->cb->battleGetStackByID(stackID, false); + + CBattleAnimation::endAnim(); + + delete this; +} + +CDefenceAnimation::CDefenceAnimation(SStackAttackedInfo _attackedInfo, CBattleInterface * _owner) +: CBattleStackAnimation(_owner, _attackedInfo.defender), dmg(_attackedInfo.dmg), +amountKilled(_attackedInfo.amountKilled), attacker(_attackedInfo.attacker), byShooting(_attackedInfo.byShooting), +killed(_attackedInfo.killed) +{ +} \ No newline at end of file diff --git a/client/BattleInterface/CDefenceAnimation.h b/client/BattleInterface/CDefenceAnimation.h new file mode 100644 index 000000000..0d35509b4 --- /dev/null +++ b/client/BattleInterface/CDefenceAnimation.h @@ -0,0 +1,34 @@ +#pragma once + +#include "CBattleStackAnimation.h" +#include "SStackAttackedInfo.h" + +class CStack; + +/* + * CDefenceAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Animation of a defending unit +class CDefenceAnimation : public CBattleStackAnimation +{ +private: + //std::vector attackedInfos; + int dmg; //damage dealt + int amountKilled; //how many creatures in stack has been killed + const CStack * attacker; //attacking stack + bool byShooting; //if true, stack has been attacked by shooting + bool killed; //if true, stack has been killed +public: + bool init(); + void nextFrame(); + void endAnim(); + + CDefenceAnimation(SStackAttackedInfo _attackedInfo, CBattleInterface * _owner); +}; \ No newline at end of file diff --git a/client/BattleInterface/CDummyAnimation.cpp b/client/BattleInterface/CDummyAnimation.cpp new file mode 100644 index 000000000..4040af1de --- /dev/null +++ b/client/BattleInterface/CDummyAnimation.cpp @@ -0,0 +1,27 @@ +#include "StdInc.h" +#include "CDummyAnimation.h" + +#include "CBattleInterface.h" + +bool CDummyAnimation::init() +{ + return true; +} + +void CDummyAnimation::nextFrame() +{ + counter++; + if(counter > howMany) + endAnim(); +} + +void CDummyAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + + delete this; +} + +CDummyAnimation::CDummyAnimation(CBattleInterface * _owner, int howManyFrames) : CBattleAnimation(_owner), counter(0), howMany(howManyFrames) +{ +} \ No newline at end of file diff --git a/client/BattleInterface/CDummyAnimation.h b/client/BattleInterface/CDummyAnimation.h new file mode 100644 index 000000000..ec6f37153 --- /dev/null +++ b/client/BattleInterface/CDummyAnimation.h @@ -0,0 +1,28 @@ +#pragma once + +#include "CBattleAnimation.h" + +class CBattleInterface; + +/* + * CDummyAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +class CDummyAnimation : public CBattleAnimation +{ +private: + int counter; + int howMany; +public: + bool init(); + void nextFrame(); + void endAnim(); + + CDummyAnimation(CBattleInterface *_owner, int howManyFrames); +}; \ No newline at end of file diff --git a/client/BattleInterface/CHexFieldControl.cpp b/client/BattleInterface/CHexFieldControl.cpp new file mode 100644 index 000000000..9b58098cc --- /dev/null +++ b/client/BattleInterface/CHexFieldControl.cpp @@ -0,0 +1,147 @@ +#include "StdInc.h" +#include "CHexFieldControl.h" +#include "CBattleInterface.h" +#include "../../lib/BattleState.h" +#include "../CGameInfo.h" +#include "../CPlayerInterface.h" +#include "../../lib/CTownHandler.h" +#include "../Graphics.h" +#include "../../CCallback.h" +#include "../../lib/CGeneralTextHandler.h" +#include "../SDL_Extensions.h" +#include "../GUIClasses.h" +#include "CBattleConsole.h" + +Point CHexFieldControl::getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * stack, const CBattleInterface * cbi) +{ + Point ret(-500, -500); //returned value + if(stack && stack->position < 0) //creatures in turrets + { + switch(stack->position) + { + case -2: //keep + ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][17]; + break; + case -3: //lower turret + ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][18]; + break; + case -4: //upper turret + ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][19]; + break; + } + } + else + { + ret.y = -139 + 42 * (hexNum/GameConstants::BFIELD_WIDTH); //counting y + //counting x + if(attacker) + { + ret.x = -160 + 22 * ( ((hexNum/GameConstants::BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % GameConstants::BFIELD_WIDTH); + } + else + { + ret.x = -219 + 22 * ( ((hexNum/GameConstants::BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % GameConstants::BFIELD_WIDTH); + } + //shifting position for double - hex creatures + if(stack && stack->doubleWide()) + { + if(attacker) + { + ret.x -= 44; + } + else + { + ret.x += 45; + } + } + } + //returning + return ret +CPlayerInterface::battleInt->pos; +} +void CHexFieldControl::activate() +{ + activateHover(); + activateMouseMove(); + activateLClick(); + activateRClick(); +} + +void CHexFieldControl::deactivate() +{ + deactivateHover(); + deactivateMouseMove(); + deactivateLClick(); + deactivateRClick(); +} + +void CHexFieldControl::hover(bool on) +{ + hovered = on; + //Hoverable::hover(on); + if(!on && setAlterText) + { + myInterface->console->alterTxt = std::string(); + setAlterText = false; + } +} + +CHexFieldControl::CHexFieldControl() : setAlterText(false), myNumber(-1), accessible(true), hovered(false), strictHovered(false), myInterface(NULL) +{ +} + +void CHexFieldControl::mouseMoved(const SDL_MouseMotionEvent &sEvent) +{ + if(myInterface->cellShade) + { + if(CSDL_Ext::SDL_GetPixel(myInterface->cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex + { + strictHovered = false; + } + else //hovered pixel is inside hex + { + strictHovered = true; + } + } + + if(hovered && strictHovered) //print attacked creature to console + { + const CStack * attackedStack = myInterface->curInt->cb->battleGetStackByPos(myNumber); + if(myInterface->console->alterTxt.size() == 0 &&attackedStack != NULL && + attackedStack->owner != myInterface->curInt->playerID && + attackedStack->alive()) + { + char tabh[160]; + const std::string & attackedName = attackedStack->count == 1 ? attackedStack->getCreature()->nameSing : attackedStack->getCreature()->namePl; + sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); + myInterface->console->alterTxt = std::string(tabh); + setAlterText = true; + } + } + else if(setAlterText) + { + myInterface->console->alterTxt = std::string(); + setAlterText = false; + } +} + +void CHexFieldControl::clickLeft(tribool down, bool previousState) +{ + if(!down && hovered && strictHovered) //we've been really clicked! + { + myInterface->hexLclicked(myNumber); + } +} + +void CHexFieldControl::clickRight(tribool down, bool previousState) +{ + const CStack * myst = myInterface->curInt->cb->battleGetStackByPos(myNumber); //stack info + if(hovered && strictHovered && myst!=NULL) + { + + if(!myst->alive()) return; + if(down) + { + GH.pushInt(createCreWindow(myst)); + } + } +} \ No newline at end of file diff --git a/client/BattleInterface/CHexFieldControl.h b/client/BattleInterface/CHexFieldControl.h new file mode 100644 index 000000000..9beacd6de --- /dev/null +++ b/client/BattleInterface/CHexFieldControl.h @@ -0,0 +1,40 @@ +#pragma once + +#include "../GUIBase.h" + +class CBattleInterface; +class CStack; +struct SDL_MouseMotionEvent; + +/* + * CHexFieldControl.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Class which stands for a single hex field on a battlefield +class CHexFieldControl : public CIntObject +{ +private: + bool setAlterText; //if true, this hex has set alternative text in console and will clean it +public: + ui32 myNumber; //number of hex in commonly used format + bool accessible; //if true, this hex is accessible for units + //CStack * ourStack; + bool hovered, strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering) + CBattleInterface * myInterface; //interface that owns me + static Point getXYUnitAnim(const int &hexNum, const bool &attacker, const CStack *creature, const CBattleInterface *cbi); //returns (x, y) of left top corner of animation + + //for user interactions + void hover (bool on); + void activate(); + void deactivate(); + void mouseMoved (const SDL_MouseMotionEvent &sEvent); + void clickLeft(tribool down, bool previousState); + void clickRight(tribool down, bool previousState); + CHexFieldControl(); +}; \ No newline at end of file diff --git a/client/BattleInterface/CMeleeAttackAnimation.cpp b/client/BattleInterface/CMeleeAttackAnimation.cpp new file mode 100644 index 000000000..eb0717bf4 --- /dev/null +++ b/client/BattleInterface/CMeleeAttackAnimation.cpp @@ -0,0 +1,95 @@ +#include "StdInc.h" +#include "CMeleeAttackAnimation.h" + +#include "CBattleInterface.h" +#include "../CCreatureAnimation.h" +#include "../../lib/BattleState.h" +#include "CReverseAnimation.h" + +bool CMeleeAttackAnimation::init() +{ + if( !CAttackAnimation::checkInitialConditions() ) + return false; + + //if(owner->creAnims[stackID]->getType()!=2) + //{ + // return false; + //} + + if(!attackingStack || myAnim()->getType() == 5) + { + endAnim(); + + return false; + } + + bool toReverse = isToReverse(attackingStackPosBeforeReturn, dest, owner->creDir[stack->ID], attackedStack->doubleWide(), owner->creDir[attackedStack->ID]); + + if(toReverse) + { + + owner->addNewAnim(new CReverseAnimation(owner, stack, attackingStackPosBeforeReturn, true)); + return false; + } + //reversed + + shooting = false; + + static const CCreatureAnim::EAnimType mutPosToGroup[] = {CCreatureAnim::ATTACK_UP, CCreatureAnim::ATTACK_UP, + CCreatureAnim::ATTACK_FRONT, CCreatureAnim::ATTACK_DOWN, CCreatureAnim::ATTACK_DOWN, CCreatureAnim::ATTACK_FRONT}; + + int revShiftattacker = (attackingStack->attackerOwned ? -1 : 1); + + int mutPos = SHexField::mutualPosition(attackingStackPosBeforeReturn, dest); + if(mutPos == -1 && attackingStack->doubleWide()) + { + mutPos = SHexField::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->position); + } + if (mutPos == -1 && attackedStack->doubleWide()) + { + mutPos = SHexField::mutualPosition(attackingStackPosBeforeReturn, attackedStack->occupiedHex()); + } + if (mutPos == -1 && attackedStack->doubleWide() && attackingStack->doubleWide()) + { + mutPos = SHexField::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->occupiedHex()); + } + + + switch(mutPos) //attack direction + { + case 0: case 1: case 2: case 3: case 4: case 5: + group = mutPosToGroup[mutPos]; + break; + default: + tlog1<<"Critical Error! Wrong dest in stackAttacking! dest: "< >::const_iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + CBattleMoveStart * anim = dynamic_cast(it->first); + CReverseAnim * anim2 = dynamic_cast(it->first); + if( (anim && anim->stackID == stackID) || (anim2 && anim2->stackID == stackID ) ) + return; + }*/ + + CAttackAnimation::nextFrame(); +} + +void CMeleeAttackAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + + delete this; +} + +CMeleeAttackAnimation::CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, SHexField _dest, const CStack * _attacked) + : CAttackAnimation(_owner, attacker, _dest, _attacked) +{ +} \ No newline at end of file diff --git a/client/BattleInterface/CMeleeAttackAnimation.h b/client/BattleInterface/CMeleeAttackAnimation.h new file mode 100644 index 000000000..fe799aaae --- /dev/null +++ b/client/BattleInterface/CMeleeAttackAnimation.h @@ -0,0 +1,28 @@ +#pragma once + +#include "CAttackAnimation.h" + + +class CBattleInterface; +class CStack; + +/* + * CMeleeAttackAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Hand-to-hand attack +class CMeleeAttackAnimation : public CAttackAnimation +{ +public: + bool init(); + void nextFrame(); + void endAnim(); + + CMeleeAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SHexField _dest, const CStack *_attacked); +}; \ No newline at end of file diff --git a/client/BattleInterface/CMovementAnimation.cpp b/client/BattleInterface/CMovementAnimation.cpp new file mode 100644 index 000000000..636c15276 --- /dev/null +++ b/client/BattleInterface/CMovementAnimation.cpp @@ -0,0 +1,176 @@ +#include "StdInc.h" +#include "CMovementAnimation.h" + +#include "CBattleInterface.h" +#include "../CCreatureAnimation.h" +#include "../../lib/BattleState.h" +#include "../CGameInfo.h" +#include "../CMusicHandler.h" +#include "CReverseAnimation.h" +#include "CMovementEndAnimation.h" +#include "CHexFieldControl.h" + +bool CMovementAnimation::init() +{ + if( !isEarliest(false) ) + return false; + + //a few useful variables + steps = static_cast(myAnim()->framesInGroup(CCreatureAnim::MOVING) * owner->getAnimSpeedMultiplier() - 1); + if(steps == 0) //this creature seems to have no move animation so we can end it immediately + { + endAnim(); + return false; + } + whichStep = 0; + int hexWbase = 44, hexHbase = 42; + const CStack * movedStack = stack; + if(!movedStack || myAnim()->getType() == 5) + { + endAnim(); + return false; + } + //bool twoTiles = movedStack->doubleWide(); + + Point begPosition = CHexFieldControl::getXYUnitAnim(curStackPos, movedStack->attackerOwned, movedStack, owner); + Point endPosition = CHexFieldControl::getXYUnitAnim(nextHex, movedStack->attackerOwned, movedStack, owner); + + int mutPos = SHexField::mutualPosition(curStackPos, nextHex); + + //reverse unit if necessary + if((begPosition.x > endPosition.x) && owner->creDir[stack->ID] == true) + { + owner->addNewAnim(new CReverseAnimation(owner, stack, curStackPos, true)); + return false; + } + else if ((begPosition.x < endPosition.x) && owner->creDir[stack->ID] == false) + { + owner->addNewAnim(new CReverseAnimation(owner, stack, curStackPos, true)); + return false; + } + + if(myAnim()->getType() != CCreatureAnim::MOVING) + { + myAnim()->setType(CCreatureAnim::MOVING); + } + //unit reversed + + // if(owner->moveSh <= 0) + // owner->moveSh = CCS->soundh->playSound(battle_sound(movedStack->getCreature(), move), -1); + + //step shift calculation + posX = myAnim()->pos.x, posY = myAnim()->pos.y; // for precise calculations ;] + if(mutPos == -1 && movedStack->hasBonusOfType(Bonus::FLYING)) + { + steps *= distance; + steps /= 2; //to make animation faster + + stepX = (endPosition.x - begPosition.x) / static_cast(steps); + stepY = (endPosition.y - begPosition.y) / static_cast(steps); + } + else + { + switch(mutPos) + { + case 0: + stepX = -1.0 * (hexWbase / (2.0 * steps)); + stepY = -1.0 * (hexHbase / (static_cast(steps))); + break; + case 1: + stepX = hexWbase / (2.0 * steps); + stepY = -1.0 * hexHbase / (static_cast(steps)); + break; + case 2: + stepX = hexWbase / static_cast(steps); + stepY = 0.0; + break; + case 3: + stepX = hexWbase / (2.0 * steps); + stepY = hexHbase / static_cast(steps); + break; + case 4: + stepX = -1.0 * hexWbase / (2.0 * steps); + stepY = hexHbase / static_cast(steps); + break; + case 5: + stepX = -1.0 * hexWbase / static_cast(steps); + stepY = 0.0; + break; + } + } + //step shifts calculated + + return true; +} + +void CMovementAnimation::nextFrame() +{ + //moving instructions + posX += stepX; + myAnim()->pos.x = static_cast(posX); + posY += stepY; + myAnim()->pos.y = static_cast(posY); + + // Increments step count and check if we are finished with current animation + ++whichStep; + if(whichStep == steps) + { + // Sets the position of the creature animation sprites + Point coords = CHexFieldControl::getXYUnitAnim(nextHex, owner->creDir[stack->ID], stack, owner); + myAnim()->pos = coords; + + // true if creature haven't reached the final destination hex + if ((nextPos + 1) < destTiles.size()) + { + // update the next hex field which has to be reached by the stack + nextPos++; + curStackPos = nextHex; + nextHex = destTiles[nextPos]; + + // update position of double wide creatures + bool twoTiles = stack->doubleWide(); + if(twoTiles && bool(stack->attackerOwned) && (owner->creDir[stack->ID] != bool(stack->attackerOwned) )) //big attacker creature is reversed + myAnim()->pos.x -= 44; + else if(twoTiles && (! bool(stack->attackerOwned) ) && (owner->creDir[stack->ID] != bool(stack->attackerOwned) )) //big defender creature is reversed + myAnim()->pos.x += 44; + + // re-init animation + for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + if (it->first == this) + { + it->second = false; + break; + } + } + } + else + endAnim(); + } +} + +void CMovementAnimation::endAnim() +{ + const CStack * movedStack = stack; + + CBattleAnimation::endAnim(); + + if(movedStack) + owner->addNewAnim(new CMovementEndAnimation(owner, stack, nextHex)); + + + if(owner->moveSh >= 0) + { + CCS->soundh->stopSound(owner->moveSh); + owner->moveSh = -1; + } + + delete this; +} + +CMovementAnimation::CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector _destTiles, int _distance) +: CBattleStackAnimation(_owner, _stack), destTiles(_destTiles), nextPos(0), distance(_distance), stepX(0.0), stepY(0.0) +{ + curStackPos = stack->position; + nextHex = destTiles.front(); +} \ No newline at end of file diff --git a/client/BattleInterface/CMovementAnimation.h b/client/BattleInterface/CMovementAnimation.h new file mode 100644 index 000000000..a288ff72f --- /dev/null +++ b/client/BattleInterface/CMovementAnimation.h @@ -0,0 +1,37 @@ +#pragma once + +#include "CBattleStackAnimation.h" + + +class CBattleInterface; +class CStack; + +/* + * CMovementAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Move animation of a creature +class CMovementAnimation : public CBattleStackAnimation +{ +private: + std::vector destTiles; //destination + SHexField nextHex; + ui32 nextPos; + int distance; + double stepX, stepY; //how far stack is moved in one frame + double posX, posY; + int steps, whichStep; + int curStackPos; //position of stack before move +public: + bool init(); + void nextFrame(); + void endAnim(); + + CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector _destTiles, int _distance); +}; \ No newline at end of file diff --git a/client/BattleInterface/CMovementEndAnimation.cpp b/client/BattleInterface/CMovementEndAnimation.cpp new file mode 100644 index 000000000..4135a1dd7 --- /dev/null +++ b/client/BattleInterface/CMovementEndAnimation.cpp @@ -0,0 +1,52 @@ +#include "StdInc.h" +#include "CMovementEndAnimation.h" + +#include "../CCreatureAnimation.h" +#include "../CMusicHandler.h" +#include "../CGameInfo.h" +#include "../../lib/BattleState.h" +#include "../CCursorHandler.h" + +bool CMovementEndAnimation::init() +{ + if( !isEarliest(true) ) + return false; + + if(!stack || myAnim()->framesInGroup(CCreatureAnim::MOVE_END) == 0 || + myAnim()->getType() == CCreatureAnim::DEATH) + { + endAnim(); + + return false; + } + + CCS->soundh->playSound(battle_sound(stack->getCreature(), endMoving)); + + myAnim()->setType(CCreatureAnim::MOVE_END); + + return true; +} + +void CMovementEndAnimation::nextFrame() +{ + if(myAnim()->onLastFrameInGroup()) + { + endAnim(); + } +} + +void CMovementEndAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + + if(myAnim()->getType() != CCreatureAnim::DEATH) + myAnim()->setType(CCreatureAnim::HOLDING); //resetting to default + + CCS->curh->show(); + delete this; +} + +CMovementEndAnimation::CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, SHexField destTile) +: CBattleStackAnimation(_owner, _stack), destinationTile(destTile) +{ +} \ No newline at end of file diff --git a/client/BattleInterface/CMovementEndAnimation.h b/client/BattleInterface/CMovementEndAnimation.h new file mode 100644 index 000000000..0f90e4c6c --- /dev/null +++ b/client/BattleInterface/CMovementEndAnimation.h @@ -0,0 +1,30 @@ +#pragma once + +#include "CBattleStackAnimation.h" + + +class CBattleInterface; +class CStack; + +/* + * CMovementEndAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Move end animation of a creature +class CMovementEndAnimation : public CBattleStackAnimation +{ +private: + SHexField destinationTile; +public: + bool init(); + void nextFrame(); + void endAnim(); + + CMovementEndAnimation(CBattleInterface *_owner, const CStack *_stack, SHexField destTile); +}; \ No newline at end of file diff --git a/client/BattleInterface/CMovementStartAnimation.cpp b/client/BattleInterface/CMovementStartAnimation.cpp new file mode 100644 index 000000000..0785ef826 --- /dev/null +++ b/client/BattleInterface/CMovementStartAnimation.cpp @@ -0,0 +1,52 @@ +#include "StdInc.h" +#include "CMovementStartAnimation.h" + +#include "../CMusicHandler.h" +#include "CBattleInterface.h" +#include "../CGameInfo.h" +#include "../CCreatureAnimation.h" +#include "../../lib/BattleState.h" +#include "../CPlayerInterface.h" + +bool CMovementStartAnimation::init() +{ + if( !isEarliest(false) ) + return false; + + + if(!stack || myAnim()->getType() == 5) + { + CMovementStartAnimation::endAnim(); + return false; + } + + CCS->soundh->playSound(battle_sound(stack->getCreature(), startMoving)); + myAnim()->setType(CCreatureAnim::MOVE_START); + + return true; +} + +void CMovementStartAnimation::nextFrame() +{ + if(myAnim()->onLastFrameInGroup()) + { + endAnim(); + } + else + { + if((owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0) + myAnim()->incrementFrame(); + } +} + +void CMovementStartAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + + delete this; +} + +CMovementStartAnimation::CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack) +: CBattleStackAnimation(_owner, _stack) +{ +} \ No newline at end of file diff --git a/client/BattleInterface/CMovementStartAnimation.h b/client/BattleInterface/CMovementStartAnimation.h new file mode 100644 index 000000000..582bbb4ab --- /dev/null +++ b/client/BattleInterface/CMovementStartAnimation.h @@ -0,0 +1,27 @@ +#pragma once + +#include "CBattleStackAnimation.h" + +class CBattleInterface; +class CStack; + +/* + * CMovementStartAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Move start animation of a creature +class CMovementStartAnimation : public CBattleStackAnimation +{ +public: + bool init(); + void nextFrame(); + void endAnim(); + + CMovementStartAnimation(CBattleInterface *_owner, const CStack *_stack); +}; \ No newline at end of file diff --git a/client/BattleInterface/CReverseAnimation.cpp b/client/BattleInterface/CReverseAnimation.cpp new file mode 100644 index 000000000..4486749af --- /dev/null +++ b/client/BattleInterface/CReverseAnimation.cpp @@ -0,0 +1,100 @@ +#include "StdInc.h" +#include "CReverseAnimation.h" + +#include "../CCreatureAnimation.h" +#include "../../lib/BattleState.h" +#include "CBattleInterface.h" +#include "CHexFieldControl.h" + +bool CReverseAnimation::init() +{ + if(myAnim() == NULL || myAnim()->getType() == 5) + { + endAnim(); + + return false; //there is no such creature + } + + if(!priority && !isEarliest(false)) + return false; + + if(myAnim()->framesInGroup(CCreatureAnim::TURN_R)) + myAnim()->setType(CCreatureAnim::TURN_R); + else + setupSecondPart(); + + + return true; +} + +void CReverseAnimation::nextFrame() +{ + if(partOfAnim == 1) //first part of animation + { + if(myAnim()->onLastFrameInGroup()) + { + partOfAnim = 2; + } + } + else if(partOfAnim == 2) + { + if(!secondPartSetup) + { + setupSecondPart(); + } + if(myAnim()->onLastFrameInGroup()) + { + endAnim(); + } + } +} + +void CReverseAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + if( stack->alive() )//don't do that if stack is dead + myAnim()->setType(CCreatureAnim::HOLDING); + + delete this; +} + +CReverseAnimation::CReverseAnimation(CBattleInterface * _owner, const CStack * stack, SHexField dest, bool _priority) +: CBattleStackAnimation(_owner, stack), partOfAnim(1), secondPartSetup(false), hex(dest), priority(_priority) +{ +} + +void CReverseAnimation::setupSecondPart() +{ + owner->creDir[stack->ID] = !owner->creDir[stack->ID]; + + if(!stack) + { + endAnim(); + return; + } + + Point coords = CHexFieldControl::getXYUnitAnim(hex, owner->creDir[stack->ID], stack, owner); + myAnim()->pos.x = coords.x; + //creAnims[stackID]->pos.y = coords.second; + + if(stack->doubleWide()) + { + if(stack->attackerOwned) + { + if(!owner->creDir[stack->ID]) + myAnim()->pos.x -= 44; + } + else + { + if(owner->creDir[stack->ID]) + myAnim()->pos.x += 44; + } + } + + secondPartSetup = true; + + if(myAnim()->framesInGroup(CCreatureAnim::TURN_L)) + myAnim()->setType(CCreatureAnim::TURN_L); + else + endAnim(); +} \ No newline at end of file diff --git a/client/BattleInterface/CReverseAnimation.h b/client/BattleInterface/CReverseAnimation.h new file mode 100644 index 000000000..b786db0e1 --- /dev/null +++ b/client/BattleInterface/CReverseAnimation.h @@ -0,0 +1,34 @@ +#pragma once + +#include "CBattleStackAnimation.h" + + +class CStack; + +/* + * CReverseAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Class responsible for animation of stack chaning direction (left <-> right) +class CReverseAnimation : public CBattleStackAnimation +{ +private: + int partOfAnim; //1 - first, 2 - second + bool secondPartSetup; + SHexField hex; +public: + bool priority; //true - high, false - low + bool init(); + void nextFrame(); + + void setupSecondPart(); + void endAnim(); + + CReverseAnimation(CBattleInterface *_owner, const CStack *stack, SHexField dest, bool _priority); +}; \ No newline at end of file diff --git a/client/BattleInterface/CShootingAnimation.cpp b/client/BattleInterface/CShootingAnimation.cpp new file mode 100644 index 000000000..b1fd22684 --- /dev/null +++ b/client/BattleInterface/CShootingAnimation.cpp @@ -0,0 +1,192 @@ +#include "StdInc.h" +#include +#include "CShootingAnimation.h" + +#include "../../lib/BattleState.h" +#include "CBattleInterface.h" +#include "../CCreatureAnimation.h" +#include "../CGameInfo.h" +#include "../../lib/CTownHandler.h" +#include "CMovementStartAnimation.h" +#include "CReverseAnimation.h" +#include "CSpellEffectAnimation.h" +#include "CHexFieldControl.h" + +bool CShootingAnimation::init() +{ + if( !CAttackAnimation::checkInitialConditions() ) + return false; + + const CStack * shooter = attackingStack; + + if(!shooter || myAnim()->getType() == 5) + { + endAnim(); + return false; + } + + // Create the projectile animation + + double projectileAngle; //in radians; if positive, projectiles goes up + double straightAngle = 0.2; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value) + int fromHex = shooter->position; + projectileAngle = atan2(static_cast(abs(dest - fromHex) / GameConstants::BFIELD_WIDTH), static_cast(abs(dest - fromHex) % GameConstants::BFIELD_WIDTH)); + if(fromHex < dest) + projectileAngle = -projectileAngle; + + // Get further info about the shooter e.g. relative pos of projectile to unit. + // If the creature id is 149 then it's a arrow tower which has no additional info so get the + // actual arrow tower shooter instead. + const CCreature *shooterInfo = shooter->getCreature(); + if (shooterInfo->idNumber == 149) + { + int creID = CGI->creh->factionToTurretCreature[owner->siegeH->town->town->typeID]; + shooterInfo = CGI->creh->creatures[creID]; + } + + SProjectileInfo spi; + spi.creID = shooter->getCreature()->idNumber; + spi.stackID = shooter->ID; + spi.reverse = !shooter->attackerOwned; + + spi.step = 0; + spi.frameNum = 0; + if(vstd::contains(CGI->creh->idToProjectileSpin, shooterInfo->idNumber)) + spi.spin = CGI->creh->idToProjectileSpin[shooterInfo->idNumber]; + else + { + tlog2 << "Warning - no projectile spin for spi.creID " << shooterInfo->idNumber << std::endl; + spi.spin = false; + } + + Point xycoord = CHexFieldControl::getXYUnitAnim(shooter->position, true, shooter, owner); + Point destcoord; + + + // The "master" point where all projectile positions relate to. + static const Point projectileOrigin(181, 252); + + if (attackedStack) + { + destcoord = CHexFieldControl::getXYUnitAnim(dest, false, attackedStack, owner); + destcoord.x += 250; destcoord.y += 210; //TODO: find a better place to shoot + + // Calculate projectile start position. Offsets are read out of the CRANIM.TXT. + if (projectileAngle > straightAngle) + { + //upper shot + spi.x = xycoord.x + projectileOrigin.x + shooterInfo->upperRightMissleOffsetX; + spi.y = xycoord.y + projectileOrigin.y + shooterInfo->upperRightMissleOffsetY; + } + else if (projectileAngle < -straightAngle) + { + //lower shot + spi.x = xycoord.x + projectileOrigin.x + shooterInfo->lowerRightMissleOffsetX; + spi.y = xycoord.y + projectileOrigin.y + shooterInfo->lowerRightMissleOffsetY; + } + else + { + //straight shot + spi.x = xycoord.x + projectileOrigin.x + shooterInfo->rightMissleOffsetX; + spi.y = xycoord.y + projectileOrigin.y + shooterInfo->rightMissleOffsetY; + } + + double animSpeed = 23.0 * owner->getAnimSpeed(); // flight speed of projectile + spi.lastStep = static_cast(sqrt(static_cast((destcoord.x - spi.x) * (destcoord.x - spi.x) + (destcoord.y - spi.y) * (destcoord.y - spi.y))) / animSpeed); + if(spi.lastStep == 0) + spi.lastStep = 1; + spi.dx = (destcoord.x - spi.x) / spi.lastStep; + spi.dy = (destcoord.y - spi.y) / spi.lastStep; + spi.catapultInfo = 0; + } + else + { + // Catapult attack + // These are the values for equations of this kind: f(x) = ax^2 + bx + c + static const std::vector trajectoryCurves = boost::assign::list_of(new SCatapultSProjectileInfo(4.309, -3.198, 569.2, -296, 182)) + (new SCatapultSProjectileInfo(4.710, -3.11, 558.68, -258, 175))(new SCatapultSProjectileInfo(5.056, -3.003, 546.9, -236, 174)) + (new SCatapultSProjectileInfo(4.760, -2.74, 526.47, -216, 215))(new SCatapultSProjectileInfo(4.288, -2.496, 508.98, -223, 274)) + (new SCatapultSProjectileInfo(3.683, -3.018, 558.39, -324, 176))(new SCatapultSProjectileInfo(2.884, -2.607, 528.95, -366, 312)) + (new SCatapultSProjectileInfo(3.783, -2.364, 501.35, -227, 318)); + + static std::map hexToCurve = boost::assign::map_list_of(29, 0)(62, 1)(95, 2)(130, 3)(182, 4)(12, 5)(50, 6)(183, 7); + + std::map::iterator it = hexToCurve.find(dest.hex); + + if (it == hexToCurve.end()) + { + tlog1 << "For the hex position " << dest.hex << " is no curve defined."; + endAnim(); + return false; + } + else + { + int curveID = it->second; + spi.catapultInfo = trajectoryCurves[curveID]; + double animSpeed = 3.318 * owner->getAnimSpeed(); + spi.lastStep = static_cast((spi.catapultInfo->toX - spi.catapultInfo->fromX) / animSpeed); + spi.dx = animSpeed; + spi.dy = 0; + spi.x = xycoord.x + projectileOrigin.x + shooterInfo->rightMissleOffsetX + 17.; + spi.y = xycoord.y + projectileOrigin.y + shooterInfo->rightMissleOffsetY + 10.; + + // Add explosion anim + int xEnd = static_cast(spi.x + spi.lastStep * spi.dx); + int yEnd = static_cast(spi.catapultInfo->calculateY(xEnd)); + owner->addNewAnim( new CSpellEffectAnimation(owner, "SGEXPL.DEF", xEnd - 126, yEnd - 105)); + } + } + + // Set starting frame + if(spi.spin) + { + spi.frameNum = 0; + } + else + { + double pi = boost::math::constants::pi(); + spi.frameNum = static_cast(((pi / 2.0 - projectileAngle) / (2.0 * pi) + 1/(static_cast(2*(owner->idToProjectile[spi.creID]->ourImages.size()-1)))) * (owner->idToProjectile[spi.creID]->ourImages.size()-1)); + } + + // Set projectile animation start delay which is specified in frames + spi.animStartDelay = shooterInfo->attackClimaxFrame; + owner->projectiles.push_back(spi); + + //attack animation + + shooting = true; + + if(projectileAngle > straightAngle) //upper shot + group = CCreatureAnim::SHOOT_UP; + else if(projectileAngle < -straightAngle) //lower shot + group = CCreatureAnim::SHOOT_DOWN; + else //straight shot + group = CCreatureAnim::SHOOT_FRONT; + + return true; +} + +void CShootingAnimation::nextFrame() +{ + for(std::list >::const_iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + CMovementStartAnimation * anim = dynamic_cast(it->first); + CReverseAnimation * anim2 = dynamic_cast(it->first); + if( (anim && anim->stack->ID == stack->ID) || (anim2 && anim2->stack->ID == stack->ID && anim2->priority ) ) + return; + } + + CAttackAnimation::nextFrame(); +} + +void CShootingAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + delete this; +} + +CShootingAnimation::CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, SHexField _dest, const CStack * _attacked, bool _catapult, int _catapultDmg) + : CAttackAnimation(_owner, attacker, _dest, _attacked), catapultDamage(_catapultDmg), catapult(_catapult) +{ + +} \ No newline at end of file diff --git a/client/BattleInterface/CShootingAnimation.h b/client/BattleInterface/CShootingAnimation.h new file mode 100644 index 000000000..fa67563f3 --- /dev/null +++ b/client/BattleInterface/CShootingAnimation.h @@ -0,0 +1,49 @@ +#pragma once + +#include "CAttackAnimation.h" +#include "../../lib/SHexField.h" + +class CBattleInterface; +class CStack; +struct SCatapultSProjectileInfo; + +/* + * CShootingAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Small struct which contains information about the position and the velocity of a projectile +struct SProjectileInfo +{ + double x, y; //position on the screen + double 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 stackID; //ID of stack + 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) + bool reverse; //if true, projectile will be flipped by vertical asix + SCatapultSProjectileInfo *catapultInfo; // holds info about the parabolic trajectory of the cannon +}; + +/// Shooting attack +class CShootingAnimation : public CAttackAnimation +{ +private: + int catapultDamage; + bool catapult; +public: + bool init(); + void nextFrame(); + void endAnim(); + + //last param only for catapult attacks + CShootingAnimation(CBattleInterface *_owner, const CStack *attacker, + SHexField _dest, const CStack *_attacked, bool _catapult = false, int _catapultDmg = 0); +}; \ No newline at end of file diff --git a/client/BattleInterface/CSpellEffectAnimation.cpp b/client/BattleInterface/CSpellEffectAnimation.cpp new file mode 100644 index 000000000..f24e45d21 --- /dev/null +++ b/client/BattleInterface/CSpellEffectAnimation.cpp @@ -0,0 +1,181 @@ +#include "StdInc.h" +#include "CSpellEffectAnimation.h" + +#include "../Graphics.h" +#include "CBattleInterface.h" +#include "../CDefHandler.h" +#include "../CPlayerInterface.h" +#include "../../CCallback.h" +#include "../../lib/BattleState.h" +#include "../SDL_Extensions.h" + +//effect animation +bool CSpellEffectAnimation::init() +{ + if(!isEarliest(true)) + return false; + + if(effect == 12) //armageddon + { + if(effect == -1 || graphics->battleACToDef[effect].size() != 0) + { + CDefHandler * anim; + if(customAnim.size()) + anim = CDefHandler::giveDef(customAnim); + else + anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); + + if (Vflip) + { + for (size_t v = 0; v < anim->ourImages.size(); ++v) + { + CSDL_Ext::VflipSurf(anim->ourImages[v].bitmap); + } + } + + for(int i=0; i * anim->width < owner->pos.w ; ++i) + { + for(int j=0; j * anim->height < owner->pos.h ; ++j) + { + SBattleEffect be; + be.effectID = ID; + be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); + if (Vflip) + { + for (size_t v = 0; v < be.anim->ourImages.size(); ++v) + { + CSDL_Ext::VflipSurf(be.anim->ourImages[v].bitmap); + } + } + be.frame = 0; + be.maxFrame = be.anim->ourImages.size(); + be.x = i * anim->width + owner->pos.x; + be.y = j * anim->height + owner->pos.y; + + owner->battleEffects.push_back(be); + } + } + } + else //there is nothing to play + { + endAnim(); + return false; + } + } + else // Effects targeted at a specific creature/hex. + { + if(effect == -1 || graphics->battleACToDef[effect].size() != 0) + { + const CStack* destStack = owner->curInt->cb->battleGetStackByPos(destTile, false); + Rect &tilePos = owner->bfield[destTile].pos; + SBattleEffect be; + be.effectID = ID; + if(customAnim.size()) + be.anim = CDefHandler::giveDef(customAnim); + else + be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); + + if (Vflip) + { + for (size_t v = 0; v < be.anim->ourImages.size(); ++v) + { + CSDL_Ext::VflipSurf(be.anim->ourImages[v].bitmap); + } + } + + be.frame = 0; + be.maxFrame = be.anim->ourImages.size(); + if(effect == 1) + be.maxFrame = 3; + + switch (effect) + { + case -1: + be.x = x; + be.y = y; + break; + case 0: // Prayer and Lightning Bolt. + case 1: + // Position effect with it's bottom center touching the bottom center of affected tile(s). + be.x = tilePos.x + tilePos.w/2 - be.anim->width/2; + be.y = tilePos.y + tilePos.h - be.anim->height; + break; + + default: + // Position effect with it's center touching the top center of affected tile(s). + be.x = tilePos.x + tilePos.w/2 - be.anim->width/2; + be.y = tilePos.y - be.anim->height/2; + break; + } + + // Correction for 2-hex creatures. + if (destStack != NULL && destStack->doubleWide()) + be.x += (destStack->attackerOwned ? -1 : 1)*tilePos.w/2; + + owner->battleEffects.push_back(be); + } + else //there is nothing to play + { + endAnim(); + return false; + } + } + //battleEffects + return true; +} + +void CSpellEffectAnimation::nextFrame() +{ + //notice: there may be more than one effect in owner->battleEffects correcponding to this animation (ie. armageddon) + for(std::list::iterator it = owner->battleEffects.begin(); it != owner->battleEffects.end(); ++it) + { + if(it->effectID == ID) + { + ++(it->frame); + + if(it->frame == it->maxFrame) + { + endAnim(); + break; + } + else + { + it->x += dx; + it->y += dy; + } + } + } +} + +void CSpellEffectAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + + std::vector::iterator> toDel; + + for(std::list::iterator it = owner->battleEffects.begin(); it != owner->battleEffects.end(); ++it) + { + if(it->effectID == ID) + { + toDel.push_back(it); + } + } + + for(size_t b = 0; b < toDel.size(); ++b) + { + delete toDel[b]->anim; + owner->battleEffects.erase(toDel[b]); + } + + delete this; +} + +CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, SHexField _destTile, int _dx, int _dy, bool _Vflip) +:CBattleAnimation(_owner), effect(_effect), destTile(_destTile), customAnim(""), dx(_dx), dy(_dy), Vflip(_Vflip) +{ +} + +CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx, int _dy, bool _Vflip) +:CBattleAnimation(_owner), effect(-1), destTile(0), customAnim(_customAnim), x(_x), y(_y), dx(_dx), dy(_dy), Vflip(_Vflip) +{ +} \ No newline at end of file diff --git a/client/BattleInterface/CSpellEffectAnimation.h b/client/BattleInterface/CSpellEffectAnimation.h new file mode 100644 index 000000000..73af1a563 --- /dev/null +++ b/client/BattleInterface/CSpellEffectAnimation.h @@ -0,0 +1,35 @@ +#pragma once + + +#include "CBattleAnimation.h" +#include "../../lib/SHexField.h" + +class CBattleInterface; + +/* + * CSpellEffectAnimation.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// This class manages a spell effect animation +class CSpellEffectAnimation : public CBattleAnimation +{ +private: + ui32 effect; + SHexField destTile; + std::string customAnim; + int x, y, dx, dy; + bool Vflip; +public: + bool init(); + void nextFrame(); + void endAnim(); + + CSpellEffectAnimation(CBattleInterface *_owner, ui32 _effect, SHexField _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false); + CSpellEffectAnimation(CBattleInterface *_owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false); +}; \ No newline at end of file diff --git a/client/BattleInterface/CStackQueue.cpp b/client/BattleInterface/CStackQueue.cpp new file mode 100644 index 000000000..6cda55472 --- /dev/null +++ b/client/BattleInterface/CStackQueue.cpp @@ -0,0 +1,125 @@ +#include "StdInc.h" +#include "CStackQueue.h" + +#include "CBattleInterface.h" +#include "../../lib/BattleState.h" +#include "../Graphics.h" +#include "../SDL_Extensions.h" +#include "../CPlayerInterface.h" +#include "../CBitmapHandler.h" +#include "../../CCallback.h" + +void CStackQueue::update() +{ + stacksSorted.clear(); + owner->curInt->cb->getStackQueue(stacksSorted, QUEUE_SIZE); + for (int i = 0; i < QUEUE_SIZE ; i++) + { + stackBoxes[i]->setStack(stacksSorted[i]); + } +} + +CStackQueue::CStackQueue(bool Embedded, CBattleInterface * _owner) +:embedded(Embedded), owner(_owner) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + if(embedded) + { + box = NULL; + bg = NULL; + pos.w = QUEUE_SIZE * 37; + pos.h = 32; //height of small creature img + pos.x = screen->w/2 - pos.w/2; + pos.y = (screen->h - 600)/2 + 10; + } + else + { + box = BitmapHandler::loadBitmap("CHRROP.pcx"); + bg = BitmapHandler::loadBitmap("DIBOXPI.pcx"); + pos.w = 600; + pos.h = bg->h; + } + + stackBoxes.resize(QUEUE_SIZE); + for (int i = 0; i < QUEUE_SIZE; i++) + { + stackBoxes[i] = new StackBox(box); + stackBoxes[i]->pos.x += 6 + (embedded ? 37 : 79)*i; + } +} + +CStackQueue::~CStackQueue() +{ + SDL_FreeSurface(box); +} + +void CStackQueue::showAll( SDL_Surface *to ) +{ + blitBg(to); + + CIntObject::showAll(to); +} + +void CStackQueue::blitBg( SDL_Surface * to ) +{ + if(bg) + { + for (int w = 0; w < pos.w; w += bg->w) + { + blitAtLoc(bg, w, 0, to); + } + } +} + +void CStackQueue::StackBox::showAll( SDL_Surface *to ) +{ + assert(my); + if(bg) + { + graphics->blueToPlayersAdv(bg, my->owner); + //SDL_UpdateRect(bg, 0, 0, 0, 0); + SDL_Rect temp_rect = genRect(bg->h, bg->w, pos.x, pos.y); + CSDL_Ext::blit8bppAlphaTo24bpp(bg, NULL, to, &temp_rect); + //blitAt(bg, pos, to); + blitAt(graphics->bigImgs[my->getCreature()->idNumber], pos.x +9, pos.y + 1, to); + printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 12, FONT_MEDIUM, zwykly, to); + } + else + { + blitAt(graphics->smallImgs[-2], pos, to); + blitAt(graphics->smallImgs[my->getCreature()->idNumber], pos, to); + const SDL_Color &ownerColor = (my->owner == 255 ? *graphics->neutralColor : graphics->playerColors[my->owner]); + CSDL_Ext::drawBorder(to, pos, int3(ownerColor.r, ownerColor.g, ownerColor.b)); + printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 8, FONT_TINY, zwykly, to); + } +} + +void CStackQueue::StackBox::setStack( const CStack *nStack ) +{ + my = nStack; +} + +CStackQueue::StackBox::StackBox(SDL_Surface *BG) +:my(NULL), bg(BG) +{ + if(bg) + { + pos.w = bg->w; + pos.h = bg->h; + } + else + { + pos.w = pos.h = 32; + } + + pos.y += 2; +} + +CStackQueue::StackBox::~StackBox() +{ +} + +void CStackQueue::StackBox::hover( bool on ) +{ + +} \ No newline at end of file diff --git a/client/BattleInterface/CStackQueue.h b/client/BattleInterface/CStackQueue.h new file mode 100644 index 000000000..24f248a06 --- /dev/null +++ b/client/BattleInterface/CStackQueue.h @@ -0,0 +1,51 @@ +#pragma once + +#include "../GUIBase.h" + +struct SDL_Surface; +class CStack; +class CBattleInterface; + +/* + * CStackQueue.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Shows the stack queue +class CStackQueue : public CIntObject +{ + class StackBox : public CIntObject + { + public: + const CStack *my; + SDL_Surface *bg; + + void hover (bool on); + void showAll(SDL_Surface *to); + void setStack(const CStack *nStack); + StackBox(SDL_Surface *BG); + ~StackBox(); + }; + +public: + static const int QUEUE_SIZE = 10; + const bool embedded; + std::vector stacksSorted; + std::vector stackBoxes; + + SDL_Surface *box; + SDL_Surface *bg; + CBattleInterface * owner; + + void showAll(SDL_Surface *to); + CStackQueue(bool Embedded, CBattleInterface * _owner); + ~CStackQueue(); + void update(); + void blitBg( SDL_Surface * to ); + //void showAll(SDL_Surface *to); +}; \ No newline at end of file diff --git a/client/BattleInterface/SStackAttackedInfo.h b/client/BattleInterface/SStackAttackedInfo.h new file mode 100644 index 000000000..40de274c1 --- /dev/null +++ b/client/BattleInterface/SStackAttackedInfo.h @@ -0,0 +1,25 @@ +#pragma once + +class CStack; + +/* + * SStackAttackedInfo.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Small struct which contains information about the id of the attacked stack, the damage dealt,... +struct SStackAttackedInfo +{ + const CStack * defender; //attacked stack + int dmg; //damage dealt + int amountKilled; //how many creatures in stack has been killed + const CStack * attacker; //attacking stack + bool byShooting; //if true, stack has been attacked by shooting + bool killed; //if true, stack has been killed + bool rebirth; //if true, play rebirth animation after all +}; \ No newline at end of file diff --git a/client/CBattleInterface.h b/client/CBattleInterface.h deleted file mode 100644 index 72dc1069a..000000000 --- a/client/CBattleInterface.h +++ /dev/null @@ -1,597 +0,0 @@ -#ifndef __CBATTLEINTERFACE_H__ -#define __CBATTLEINTERFACE_H__ - -#include "../global.h" -#include -#include "GUIBase.h" -#include "../lib/CCreatureSet.h" -#include "../lib/ConstTransitivePtr.h" //may be reundant -#include "CAnimation.h" - -/* - * CBattleInterface.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -class CLabel; -class CCreatureSet; -class CGHeroInstance; -class CDefHandler; -class CStack; -class CCallback; -class AdventureMapButton; -class CHighlightableButton; -class CHighlightableButtonsGroup; -struct BattleResult; -struct BattleSpellCast; -struct CObstacleInstance; -template struct CondSh; -struct SetStackEffect;; -struct BattleAction; -class CGTownInstance; -struct CatapultAttack; -class CBattleInterface; -struct CatapultProjectileInfo; -struct BattleTriggerEffect; - -/// Small struct which contains information about the id of the attacked stack, the damage dealt,... -struct SStackAttackedInfo -{ - const CStack * defender; //attacked stack - int dmg; //damage dealt - int amountKilled; //how many creatures in stack has been killed - const CStack * attacker; //attacking stack - bool byShooting; //if true, stack has been attacked by shooting - bool killed; //if true, stack has been killed - bool rebirth; //if true, play rebirth animation after all -}; - -/// Small struct which contains information about the position and the velocity of a projectile -struct SProjectileInfo -{ - double x, y; //position on the screen - double 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 stackID; //ID of stack - 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) - bool reverse; //if true, projectile will be flipped by vertical asix - CatapultProjectileInfo *catapultInfo; // holds info about the parabolic trajectory of the cannon -}; - - -/// Base class of battle animations -class CBattleAnimation -{ -protected: - CBattleInterface * owner; -public: - virtual bool init()=0; //to be called - if returned false, call again until returns true - virtual void nextFrame()=0; //call every new frame - virtual void endAnim(); //to be called mostly internally; in this class it removes animation from pendingAnims list - - bool isEarliest(bool perStackConcurrency); //determines if this animation is earliest of all - - unsigned int ID; //unique identifier - - CBattleAnimation(CBattleInterface * _owner); -}; - -class CDummyAnim : public CBattleAnimation -{ -private: - int counter; - int howMany; -public: - bool init(); - void nextFrame(); - void endAnim(); - - CDummyAnim(CBattleInterface * _owner, int howManyFrames); -}; - -/// This class manages a spell effect animation -class CSpellEffectAnim : public CBattleAnimation -{ -private: - ui32 effect; - THex destTile; - std::string customAnim; - int x, y, dx, dy; - bool Vflip; -public: - bool init(); - void nextFrame(); - void endAnim(); - - CSpellEffectAnim(CBattleInterface * _owner, ui32 _effect, THex _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false); - CSpellEffectAnim(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false); -}; - -/// Sub-class which is responsible for managing the battle stack animation. -class CBattleStackAnimation : public CBattleAnimation -{ -public: - const CStack * stack; //id of stack whose animation it is - - CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack); - static bool isToReverseHlp(THex hexFrom, THex hexTo, bool curDir); //helper for isToReverse - static bool isToReverse(THex hexFrom, THex hexTo, bool curDir /*if true, creature is in attacker's direction*/, bool toDoubleWide, bool toDir); //determines if creature should be reversed (it stands on hexFrom and should 'see' hexTo) - - CCreatureAnimation *myAnim(); //animation for our stack -}; - -/// Class responsible for animation of stack chaning direction (left <-> right) -class CReverseAnim : public CBattleStackAnimation -{ -private: - int partOfAnim; //1 - first, 2 - second - bool secondPartSetup; - THex hex; -public: - bool priority; //true - high, false - low - bool init(); - void nextFrame(); - - void setupSecondPart(); - void endAnim(); - - CReverseAnim(CBattleInterface * _owner, const CStack * stack, THex dest, bool _priority); -}; - -/// Animation of a defending unit -class CDefenceAnim : public CBattleStackAnimation -{ -private: - //std::vector attackedInfos; - int dmg; //damage dealt - int amountKilled; //how many creatures in stack has been killed - const CStack * attacker; //attacking stack - bool byShooting; //if true, stack has been attacked by shooting - bool killed; //if true, stack has been killed -public: - bool init(); - void nextFrame(); - void endAnim(); - - CDefenceAnim(SStackAttackedInfo _attackedInfo, CBattleInterface * _owner); -}; - -/// Move animation of a creature -class CBattleStackMoved : public CBattleStackAnimation -{ -private: - std::vector destTiles; //destination - THex nextHex; - int nextPos; - int distance; - float stepX, stepY; //how far stack is moved in one frame - float posX, posY; - int steps, whichStep; - int curStackPos; //position of stack before move -public: - bool init(); - void nextFrame(); - void endAnim(); - - CBattleStackMoved(CBattleInterface * _owner, const CStack * _stack, std::vector _destTiles, int _distance); -}; - -/// Move start animation of a creature -class CBattleMoveStart : public CBattleStackAnimation -{ -public: - bool init(); - void nextFrame(); - void endAnim(); - - CBattleMoveStart(CBattleInterface * _owner, const CStack * _stack); -}; - -/// Move end animation of a creature -class CBattleMoveEnd : public CBattleStackAnimation -{ -private: - THex destinationTile; -public: - bool init(); - void nextFrame(); - void endAnim(); - - CBattleMoveEnd(CBattleInterface * _owner, const CStack * _stack, THex destTile); -}; - -/// This class is responsible for managing the battle attack animation -class CBattleAttack : public CBattleStackAnimation -{ -protected: - THex dest; //atacked hex - bool shooting; - CCreatureAnim::EAnimType group; //if shooting is true, print this animation group - const CStack * attackedStack; - const CStack * attackingStack; - int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature -public: - void nextFrame(); - - bool checkInitialConditions(); - - - CBattleAttack(CBattleInterface * _owner, const CStack * attacker, THex _dest, const CStack * defender); -}; - -/// Hand-to-hand attack -class CMeleeAttack : public CBattleAttack -{ -public: - bool init(); - void nextFrame(); - void endAnim(); - - CMeleeAttack(CBattleInterface * _owner, const CStack * attacker, THex _dest, const CStack * _attacked); -}; - -/// Shooting attack -class CShootingAnim : public CBattleAttack -{ -private: - int catapultDamage; - bool catapult; -public: - bool init(); - void nextFrame(); - void endAnim(); - - CShootingAnim(CBattleInterface * _owner, const CStack * attacker, THex _dest, const CStack * _attacked, bool _catapult = false, int _catapultDmg = 0); //last param only for catapult attacks -}; - -//end of battle animation handlers - -/// Hero battle animation -class CBattleHero : public CIntObject -{ -public: - bool flip; //false if it's attacking hero, true otherwise - CDefHandler * dh, *flag; //animation and flag - const CGHeroInstance * myHero; //this animation's hero instance - const CBattleInterface * myOwner; //battle interface to which this animation is assigned - int phase; //stage of animation - int nextPhase; //stage of animation to be set after current phase is fully displayed - int image; //frame of animation - unsigned char flagAnim, flagAnimCount; //for flag animation - void show(SDL_Surface * to); //prints next frame of animation to to - void activate(); - void deactivate(); - void setPhase(int newPhase); //sets phase of hero animation - void clickLeft(tribool down, bool previousState); //call-in - CBattleHero(const std::string & defName, int phaseG, int imageG, bool filpG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner); //c-tor - ~CBattleHero(); //d-tor -}; - -/// Class which stands for a single hex field on a battlefield -class CBattleHex : public CIntObject -{ -private: - bool setAlterText; //if true, this hex has set alternative text in console and will clean it -public: - unsigned int myNumber; //number of hex in commonly used format - bool accessible; //if true, this hex is accessible for units - //CStack * ourStack; - bool hovered, strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering) - CBattleInterface * myInterface; //interface that owns me - static Point getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * creature, const CBattleInterface * cbi); //returns (x, y) of left top corner of animation - //for user interactions - void hover (bool on); - void activate(); - void deactivate(); - void mouseMoved (const SDL_MouseMotionEvent & sEvent); - void clickLeft(tribool down, bool previousState); - void clickRight(tribool down, bool previousState); - CBattleHex(); -}; - -/// Class which manages the locked hex fields that are blocked e.g. by obstacles -class CBattleObstacle -{ - std::vector lockedHexes; -}; - -/// Class which shows the console at the bottom of the battle screen and manages the text of the console -class CBattleConsole : public CIntObject -{ -private: - std::vector< std::string > texts; //a place where texts are stored - int lastShown; //last shown line of text -public: - std::string alterTxt; //if it's not empty, this text is displayed - std::string ingcAlter; //alternative text set by in-game console - very important! - int whoSetAlter; //who set alter text; 0 - battle interface or none, 1 - button - CBattleConsole(); //c-tor - ~CBattleConsole(); //d-tor - void show(SDL_Surface * to = 0); - bool addText(const std::string & text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters) - void eraseText(unsigned int pos); //erases added text at position pos - void changeTextAt(const std::string & text, unsigned int pos); //if we have more than pos texts, pos-th is changed to given one - void scrollUp(unsigned int by = 1); //scrolls console up by 'by' positions - void scrollDown(unsigned int by = 1); //scrolls console up by 'by' positions -}; - -/// Class which is responsible for showing the battle result window -class CBattleResultWindow : public CIntObject -{ -private: - SDL_Surface * background; - AdventureMapButton * exit; - CBattleInterface * owner; -public: - CBattleResultWindow(const BattleResult & br, const SDL_Rect & pos, CBattleInterface * _owner); //c-tor - ~CBattleResultWindow(); //d-tor - - void bExitf(); //exit button callback - - void activate(); - void deactivate(); - void show(SDL_Surface * to = 0); -}; - -/// Class which manages the battle options window -class CBattleOptionsWindow : public CIntObject -{ -private: - CBattleInterface * myInt; - CPicture * background; - AdventureMapButton * setToDefault, * exit; - CHighlightableButton * viewGrid, * movementShadow, * mouseShadow; - CHighlightableButtonsGroup * animSpeeds; - - std::vector labels; -public: - CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface * owner); //c-tor - - void bDefaultf(); //dafault button callback - void bExitf(); //exit button callback -}; - -/// Struct for battle effect animation e.g. morale, prayer, armageddon, bless,... -struct SBattleEffect -{ - int x, y; //position on the screen - int frame, maxFrame; - CDefHandler * anim; //animation to display - int effectID; //uniqueID equal ot ID of appropriate CSpellEffectAnim -}; - -/// Shows the stack queue -class CStackQueue : public CIntObject -{ - class StackBox : public CIntObject - { - public: - const CStack *my; - SDL_Surface *bg; - - void hover (bool on); - void showAll(SDL_Surface *to); - void setStack(const CStack *nStack); - StackBox(SDL_Surface *BG); - ~StackBox(); - }; - -public: - static const int QUEUE_SIZE = 10; - const bool embedded; - std::vector stacksSorted; - std::vector stackBoxes; - - SDL_Surface *box; - SDL_Surface *bg; - CBattleInterface * owner; - - void showAll(SDL_Surface *to); - CStackQueue(bool Embedded, CBattleInterface * _owner); - ~CStackQueue(); - void update(); - void blitBg( SDL_Surface * to ); - //void showAll(SDL_Surface *to); -}; - -/// Small struct which is needed for drawing the parabolic trajectory of the catapult cannon -struct CatapultProjectileInfo -{ - const double facA, facB, facC; - const int fromX, toX; - - CatapultProjectileInfo() : facA(0), facB(0), facC(0), fromX(0), toX(0) { }; - CatapultProjectileInfo(double factorA, double factorB, double factorC, int fromXX, int toXX) : facA(factorA), facB(factorB), facC(factorC), - fromX(fromXX), toX(toXX) { }; - - double calculateY(double x); -}; - -/// Big class which handles the overall battle interface actions and it is also responsible for -/// drawing everything correctly. -class CBattleInterface : public CIntObject -{ - enum SpellSelectionType - { - ANY_LOCATION = 0, FRIENDLY_CREATURE, HOSTILE_CREATURE, ANY_CREATURE, OBSTACLE, TELEPORT, NO_LOCATION = -1, STACK_SPELL_CANCELLED = -2 - }; -private: - SDL_Surface * background, * menu, * amountNormal, * amountNegative, * amountPositive, * amountEffNeutral, * cellBorders, * backgroundWithHexes; - AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell, - * bWait, * bDefence, * bConsoleUp, * bConsoleDown, *btactNext, *btactEnd; - CBattleConsole * console; - CBattleHero * attackingHero, * defendingHero; //fighting heroes - CStackQueue *queue; - const CCreatureSet *army1, *army2; //copy of initial armies (for result window) - const 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 creatures (creatureID, defhandler) - std::map< int, CDefHandler * > idToObstacle; //obstacles located on the battlefield - std::map< int, bool > creDir; // - unsigned char animCount; - const CStack * activeStack; //number of active stack; NULL - no one - const CStack * stackToActivate; //when animation is playing, we should wait till the end to make the next stack active; NULL of none - void activateStack(); //sets activeStack to stackToActivate etc. - int mouseHoveredStack; //stack hovered by mouse; if -1 -> none - time_t lastMouseHoveredStackAnimationTime; // time when last mouse hovered animation occurred - static const time_t HOVER_ANIM_DELTA; - std::vector occupyableHexes, //hexes available for active stack - attackableHexes; //hexes attackable by active stack - bool stackCountOutsideHexes[BFIELD_SIZE]; // hexes that when in front of a unit cause it's amount box to move back - int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago - int currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon) - int attackingHex; //hex from which the stack would perform attack with current cursor - float getAnimSpeedMultiplier() const; //returns multiplier for number of frames in a group - std::map standingFrame; //number of frame in standing animation by stack ID, helps in showing 'random moves' - - CPlayerInterface *tacticianInterface; //used during tactics mode, points to the interface of player with higher tactics (can be either attacker or defender in hot-seat), valid onloy for human players - bool tacticsMode; - bool stackCanCastSpell; //if true, active stack could possibly cats some target spell - bool spellDestSelectMode; //if true, player is choosing destination for his spell - SpellSelectionType spellSelMode; - BattleAction * spellToCast; //spell for which player is choosing destination - TSpell creatureSpellToCast; - void endCastingSpell(); //ends casting spell (eg. when spell has been cast or canceled) - - void showAliveStack(const CStack *stack, SDL_Surface * to); //helper function for function show - void showAliveStacks(std::vector *aliveStacks, int hex, std::vector *flyingStacks, SDL_Surface *to); // loops through all stacks at a given hex position - void showPieceOfWall(SDL_Surface * to, int hex, const std::vector & stacks); //helper function for show - void showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to); // show all obstacles at a given hex position - void redrawBackgroundWithHexes(const CStack * activeStack); - void printConsoleAttacked(const CStack * defender, int dmg, int killed, const CStack * attacker, bool Multiple); - - std::list projectiles; //projectiles flying on battlefield - void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield - void giveCommand(ui8 action, THex tile, ui32 stack, si32 additional=-1); - bool isTileAttackable(const THex & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles - bool blockedByObstacle(THex hex) const; - bool isCatapultAttackable(THex hex) const; //returns true if given tile can be attacked by catapult - - std::list battleEffects; //different animations to display on the screen like spell effects - - /// Class which is responsible for drawing the wall of a siege during battle - class SiegeHelper - { - private: - static std::string townTypeInfixes[F_NUMBER]; //for internal use only - to build filenames - SDL_Surface * walls[18]; - const CBattleInterface * owner; - public: - const CGTownInstance * town; //besieged town - - SiegeHelper(const CGTownInstance * siegeTown, const CBattleInterface * _owner); //c-tor - ~SiegeHelper(); //d-tor - - //filename getters - std::string getSiegeName(ui16 what, ui16 additInfo = 1) const; //what: 0 - background, 1 - background wall, 2 - keep, 3 - bottom tower, 4 - bottom wall, 5 - below gate, 6 - over gate, 7 - upper wall, 8 - uppert tower, 9 - gate, 10 - gate arch, 11 - bottom static wall, 12 - upper static wall, 13 - moat, 14 - mlip, 15 - keep creature cover, 16 - bottom turret creature cover, 17 - upper turret creature cover; additInfo: 1 - intact, 2 - damaged, 3 - destroyed - - void printPartOfWall(SDL_Surface * to, int what);//what: 1 - background wall, 2 - keep, 3 - bottom tower, 4 - bottom wall, 5 - below gate, 6 - over gate, 7 - upper wall, 8 - uppert tower, 9 - gate, 10 - gate arch, 11 - bottom static wall, 12 - upper static wall, 15 - keep creature cover, 16 - bottom turret creature cover, 17 - upper turret creature cover - - friend class CBattleInterface; - } * siegeH; - - CPlayerInterface * attackerInt, * defenderInt; //because LOCPLINT is not enough in hotSeat - const CGHeroInstance * getActiveHero(); //returns hero that can currently cast a spell -public: - CPlayerInterface * curInt; //current player interface - std::list > pendingAnims; //currently displayed animations - void addNewAnim(CBattleAnimation * anim); //adds new anim to pendingAnims - unsigned int animIDhelper; //for giving IDs for animations - static CondSh animsAreDisplayed; //for waiting with the end of battle for end of anims - - CBattleInterface(const CCreatureSet * army1, const CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect, CPlayerInterface * att, CPlayerInterface * defen); //c-tor - ~CBattleInterface(); //d-tor - - //std::vector timeinterested; //animation handling - void setPrintCellBorders(bool set); //if true, cell borders will be printed - void setPrintStackRange(bool set); //if true,range of active stack will be printed - void setPrintMouseShadow(bool set); //if true, hex under mouse will be shaded - void setAnimSpeed(int set); //speed of animation; 1 - slowest, 2 - medium, 4 - fastest - int getAnimSpeed() const; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest - - CBattleHex bfield[BFIELD_SIZE]; //11 lines, 17 hexes on each - //std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield - SDL_Surface * cellBorder, * cellShade; - CondSh *givenCommand; //data != NULL if we have i.e. moved current unit - bool myTurn; //if true, interface is active (commands can be ordered) - CBattleResultWindow * resWindow; //window of end of battle - - bool moveStarted; //if true, the creature that is already moving is going to make its first step - int moveSh; // sound handler used when moving a unit - - //button handle funcs: - void bOptionsf(); - void bSurrenderf(); - void bFleef(); - void reallyFlee(); //performs fleeing without asking player - void reallySurrender(); //performs surrendering without asking player - void bAutofightf(); - void bSpellf(); - void bWaitf(); - void bDefencef(); - void bConsoleUpf(); - void bConsoleDownf(); - void bTacticNextStack(); - void bEndTacticPhase(); - //end of button handle funcs - //napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem - void activate(); - void deactivate(); - void show(SDL_Surface * to); - void keyPressed(const SDL_KeyboardEvent & key); - void mouseMoved(const SDL_MouseMotionEvent &sEvent); - void clickRight(tribool down, bool previousState); - - //call-ins - void startAction(const BattleAction* action); - void newStack(const CStack * stack); //new stack appeared on battlefield - void stackRemoved(int stackID); //stack disappeared from batlefiled - void stackActivated(const CStack * stack); //active stack has been changed - void stackMoved(const CStack * stack, std::vector destHex, int distance); //stack with id number moved to destHex - void waitForAnims(); - void stacksAreAttacked(std::vector attackedInfos); //called when a certain amount of stacks has been attacked - void stackAttacking(const CStack * attacker, THex dest, const CStack * attacked, bool shooting); //called when stack with id ID is attacking something on hex dest - void newRoundFirst( int round ); - void newRound(int number); //caled when round is ended; number is the number of round - void hexLclicked(int whichOne); //hex only call-in - void stackIsCatapulting(const CatapultAttack & ca); //called when a stack is attacking walls - void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed - const BattleResult * bresult; //result of a battle; if non-zero then display when all animations end - void displayBattleFinished(); //displays battle result - void spellCast(const BattleSpellCast * sc); //called when a hero casts a spell - void battleStacksEffectsSet(const SetStackEffect & sse); //called when a specific effect is set to stacks - void castThisSpell(int spellID); //called when player has chosen a spell from spellbook - void displayEffect(ui32 effect, int destTile); //displays effect of a spell on the battlefield; affected: true - attacker. false - defender - void battleTriggerEffect(const BattleTriggerEffect & bte); - void setBattleCursor(const int myNumber); //really complex and messy - void endAction(const BattleAction* action); - void hideQueue(); - void showQueue(); - friend class CBattleHex; - friend class CBattleResultWindow; - friend class CPlayerInterface; - friend class AdventureMapButton; - friend class CInGameConsole; - friend class CReverseAnim; - friend class CBattleStackAnimation; - friend class CBattleAnimation; - friend class CDefenceAnim; - friend class CBattleStackMoved; - friend class CBattleMoveStart; - friend class CBattleMoveEnd; - friend class CBattleAttack; - friend class CMeleeAttack; - friend class CShootingAnim; - friend class CSpellEffectAnim; - friend class CBattleHero; -}; - -#endif // __CBATTLEINTERFACE_H__ diff --git a/client/StdInc.cpp b/client/StdInc.cpp new file mode 100644 index 000000000..c8f4ddf05 --- /dev/null +++ b/client/StdInc.cpp @@ -0,0 +1,2 @@ +// Creates the precompiled header +#include "StdInc.h" \ No newline at end of file diff --git a/client/StdInc.h b/client/StdInc.h new file mode 100644 index 000000000..18659d5ee --- /dev/null +++ b/client/StdInc.h @@ -0,0 +1,325 @@ +#pragma once + +// Standard include file +// Should be treated as a precompiled header file in the compiler settings +// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio +// This file shouldn't be changed, except if there is a important header file which is missing. + +/* + * StdInc.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#ifdef _WIN32 +#include +#else +#include "../tchar_amigaos4.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +//filesystem version 3 causes problems (and it's default as of boost 1.46) +#define BOOST_FILESYSTEM_VERSION 2 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef ANDROID +#include +#endif + +// Integral data types +typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) +typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) +typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) +typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) +typedef boost::int64_t si64; //signed int 64 bits (8 bytes) +typedef boost::int32_t si32; //signed int 32 bits (4 bytes) +typedef boost::int16_t si16; //signed int 16 bits (2 bytes) +typedef boost::int8_t si8; //signed int 8 bits (1 byte) + +// Import + Export macro declarations +#ifdef _WIN32 +#define DLL_EXPORT __declspec(dllexport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_EXPORT __attribute__ ((visibility("default"))) +#else +#define DLL_EXPORT +#endif +#endif + +#ifdef _WIN32 +#define DLL_IMPORT __declspec(dllimport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_IMPORT __attribute__ ((visibility("default"))) +#else +#define DLL_IMPORT +#endif +#endif + +#ifdef VCMI_DLL +#define DLL_LINKAGE DLL_EXPORT +#else +#define DLL_LINKAGE DLL_IMPORT +#endif + + +//a normal std::map with a const operator[] for sanity +template +class bmap : public std::map +{ +public: + const ValT & operator[](KeyT key) const + { + return find(key)->second; + } + ValT & operator[](KeyT key) + { + return static_cast &>(*this)[key]; + } + template void serialize(Handler &h, const int version) + { + h & static_cast &>(*this); + } +}; + +namespace vstd +{ + //returns true if container c contains item i + template + bool contains(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i) != c.end(); + } + + //returns true if map c contains item i + template + bool contains(const std::map & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if bmap c contains item i + template + bool contains(const bmap & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if unordered set c contains item i + template + bool contains(const boost::unordered_set & c, const Item &i) + { + return c.find(i)!=c.end(); + } + + //returns position of first element in vector c equal to s, if there is no such element, -1 is returned + template + int find_pos(const std::vector & c, const T2 &s) + { + for(size_t i=0; i < c.size(); ++i) + if(c[i] == s) + return i; + return -1; + } + + //Func(T1,T2) must say if these elements matches + template + int find_pos(const std::vector & c, const T2 &s, const Func &f) + { + for(size_t i=0; i < c.size(); ++i) + if(f(c[i],s)) + return i; + return -1; + } + + //returns iterator to the given element if present in container, end() if not + template + typename Container::iterator find(Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //returns const iterator to the given element if present in container, end() if not + template + typename Container::const_iterator find(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //removes element i from container c, returns false if c does not contain i + template + typename Container::size_type operator-=(Container &c, const Item &i) + { + typename Container::iterator itr = find(c,i); + if(itr == c.end()) + return false; + c.erase(itr); + return true; + } + + //assigns greater of (a, b) to a and returns maximum of (a, b) + template + t1 &amax(t1 &a, const t2 &b) + { + if(a >= b) + return a; + else + { + a = b; + return a; + } + } + + //assigns smaller of (a, b) to a and returns minimum of (a, b) + template + t1 &amin(t1 &a, const t2 &b) + { + if(a <= b) + return a; + else + { + a = b; + return a; + } + } + + //makes a to fit the range + template + t1 &abetween(t1 &a, const t2 &b, const t3 &c) + { + amax(a,b); + amin(a,c); + return a; + } + + //checks if a is between b and c + template + bool isbetween(const t1 &a, const t2 &b, const t3 &c) + { + return a > b && a < c; + } + + //checks if a is within b and c + template + bool iswithin(const t1 &a, const t2 &b, const t3 &c) + { + return a >= b && a <= c; + } + + template + struct assigner + { + public: + t1 &op1; + t2 op2; + assigner(t1 &a1, const t2 & a2) + :op1(a1), op2(a2) + {} + void operator()() + { + op1 = op2; + } + }; + + // Assigns value a2 to a1. The point of time of the real operation can be controlled + // with the () operator. + template + assigner assigno(t1 &a1, const t2 &a2) + { + return assigner(a1,a2); + } + + //deleted pointer and sets it to NULL + template + void clear_pointer(T* &ptr) + { + delete ptr; + ptr = NULL; + } +} +using vstd::operator-=; + +// can be used for counting arrays +template char (&_ArrayCountObj(const T (&)[N]))[N]; +#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) + +//for explicit overrides +#ifdef _MSC_VER +#define OVERRIDE override +#else +#define OVERRIDE //is there any working counterpart? +#endif + +//XXX pls dont - 'debug macros' are usually more trouble than it's worth +#define HANDLE_EXCEPTION \ + catch (const std::exception& e) { \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::exception * e) \ +{ \ + tlog1 << e->what()<< std::endl; \ + throw; \ +} \ + catch (const std::string& e) { \ + tlog1 << e << std::endl; \ + throw; \ +} + +#define HANDLE_EXCEPTIONC(COMMAND) \ + catch (const std::exception& e) { \ + COMMAND; \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::string &e) \ +{ \ + COMMAND; \ + tlog1 << e << std::endl; \ + throw; \ +} + + +#include "../lib/CLogger.h" diff --git a/global.h b/global.h deleted file mode 100644 index 6ec970cc9..000000000 --- a/global.h +++ /dev/null @@ -1,734 +0,0 @@ -#pragma once -#ifndef __GLOBAL_H__ -#define __GLOBAL_H__ -#include -#include -#include //std::find -#include //std::find -#include -#include -using boost::logic::tribool; -#include -#include -#ifdef ANDROID -#include -#include -#endif -//filesystem version 3 causes problems (and it's default as of boost 1.46) -#define BOOST_FILESYSTEM_VERSION 2 -typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) -typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) -typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) -typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) -typedef boost::int64_t si64; //signed int 64 bits (8 bytes) -typedef boost::int32_t si32; //signed int 32 bits (4 bytes) -typedef boost::int16_t si16; //signed int 16 bits (2 bytes) -typedef boost::int8_t si8; //signed int 8 bits (1 byte) -typedef si64 expType; -typedef ui32 TSpell; -typedef std::pair TDmgRange; -typedef ui8 TBonusType; -typedef si32 TBonusSubtype; -#include "int3.h" -#include -#include -#define CHECKTIME 1 -#if CHECKTIME -#include "timeHandler.h" -#define THC -#endif - -#define NAME_VER ("VCMI 0.87b") -extern std::string NAME; //full name -extern std::string NAME_AFFIX; //client / server -#define CONSOLE_LOGGING_LEVEL 5 -#define FILE_LOGGING_LEVEL 6 - -/* - * DATA_DIR contains the game data (Data/, MP3/, ...). - * BIN_DIR is where the vcmiclient/vcmiserver binaries reside - * LIB_DIR is where the AI libraries reside (linux only) - */ -#ifdef _WIN32 - #define DATA_DIR "." - #define BIN_DIR "." - #define LIB_DIR "." - #define SERVER_NAME "VCMI_server.exe" - #define LIB_EXT "dll" -#else - #ifndef DATA_DIR - #error DATA_DIR undefined. - #endif - #ifndef BIN_DIR - #error BIN_DIR undefined. - #endif - #ifndef LIB_DIR - #error LIB_DIR undefined. - #endif - #define SERVER_NAME "vcmiserver" - #define LIB_EXT "so" -#endif - -#ifdef _WIN32 -#define PATH_SEPARATOR "\\" -#else -#define PATH_SEPARATOR "/" -#endif - -/* - * global.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors -enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero, - captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255}; -enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255}; -enum ECombatInfo{ALIVE = 180, SUMMONED, CLONED, HAD_MORALE, WAITING, MOVED, DEFENDING, FEAR}; - -class CGameInfo; -extern const CGameInfo* CGI; //game info for general use -class CClientState; -extern CClientState * CCS; - -//a few typedefs for CCreatureSet -typedef si32 TSlot; -typedef si32 TQuantity; -typedef ui32 TCreature; //creature id -const int ARMY_SIZE = 7; - -const int - BOATI_TYPE = 8, - HEROI_TYPE = 34, - TOWNI_TYPE = 98, - SUBTERRANEAN_GATE_TYPE = 103, - CREI_TYPE = 54, - EVENTI_TYPE = 26; - -const int CREATURES_COUNT = 197; -const int CRE_LEVELS = 10; -const int F_NUMBER = 9; //factions (town types) quantity -const int PLAYER_LIMIT = 8; //player limit per map -const int ALL_PLAYERS = 255; //bitfield -const int HEROES_PER_TYPE=8; //amount of heroes of each type -const int SKILL_QUANTITY=28; -const int SKILL_PER_HERO=8; -const int ARTIFACTS_QUANTITY=171; -const int HEROES_QUANTITY=156; -const int SPELLS_QUANTITY=70; -const int RESOURCE_QUANTITY=8; -const int TERRAIN_TYPES=10; -const int PRIMARY_SKILLS=4; -const int NEUTRAL_PLAYER=255; -const int NAMES_PER_TOWN=16; -const int CREATURES_PER_TOWN = 7; //without upgrades -const int MAX_BUILDING_PER_TURN = 1; -const int SPELL_LEVELS = 5; -const int CREEP_SIZE = 4000; // neutral stacks won't grow beyond this number -//const int CREEP_SIZE = 2000000000; -const int WEEKLY_GROWTH = 10; //percent -const int AVAILABLE_HEROES_PER_PLAYER = 2; -const bool DWELLINGS_ACCUMULATE_CREATURES = false; -const bool STACK_EXP = true; -const bool STACK_ARTIFACT = true; - -const int BFIELD_WIDTH = 17; -const int BFIELD_HEIGHT = 11; -const int BFIELD_SIZE = BFIELD_WIDTH * BFIELD_HEIGHT; - -const int SPELLBOOK_GOLD_COST = 500; - -//for battle stacks' positions -struct THex -{ - static const si16 INVALID = -1; - enum EDir{RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, LEFT, TOP_LEFT, TOP_RIGHT}; - - si16 hex; - - THex() : hex(INVALID) {} - THex(si16 _hex) : hex(_hex) - { - //assert(isValid()); - } - operator si16() const - { - return hex; - } - - bool isValid() const - { - return hex >= 0 && hex < BFIELD_SIZE; - } - - template - THex(inttype x, inttype y) - { - setXY(x, y); - } - - template - THex(std::pair xy) - { - setXY(xy); - } - - template - void setX(inttype x) - { - setXY(x, getY()); - } - - template - void setY(inttype y) - { - setXY(getX(), y); - } - - void setXY(si16 x, si16 y) - { - assert(x >= 0 && x < BFIELD_WIDTH && y >= 0 && y < BFIELD_HEIGHT); - hex = x + y * BFIELD_WIDTH; - } - - template - void setXY(std::pair xy) - { - setXY(xy.first, xy.second); - } - - si16 getY() const - { - return hex/BFIELD_WIDTH; - } - - si16 getX() const - { - int pos = hex - getY() * BFIELD_WIDTH; - return pos; - } - - std::pair getXY() const - { - return std::make_pair(getX(), getY()); - } - - //moving to direction - void operator+=(EDir dir) - { - si16 x = getX(), - y = getY(); - - switch(dir) - { - case TOP_LEFT: - setXY(y%2 ? x-1 : x, y-1); - break; - case TOP_RIGHT: - setXY(y%2 ? x : x+1, y-1); - break; - case RIGHT: - setXY(x+1, y); - break; - case BOTTOM_RIGHT: - setXY(y%2 ? x : x+1, y+1); - break; - case BOTTOM_LEFT: - setXY(y%2 ? x-1 : x, y+1); - break; - case LEFT: - setXY(x-1, y); - break; - default: - throw std::string("Disaster: wrong direction in THex::operator+=!\n"); - break; - } - } - - //generates new THex moved by given dir - THex operator+(EDir dir) const - { - THex ret(*this); - ret += dir; - return ret; - } - - std::vector neighbouringTiles() const - { - std::vector ret; - const int WN = BFIELD_WIDTH; - checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), ret); - checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), ret); - checkAndPush(hex - 1, ret); - checkAndPush(hex + 1, ret); - checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), ret); - checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), ret); - - return ret; - } - - //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left) - static signed char mutualPosition(THex hex1, THex hex2) - { - if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left - return 0; - if(hex2 == hex1 - ( (hex1/17)%2 ? 17 : 16 )) //top right - return 1; - if(hex2 == hex1 - 1 && hex1%17 != 0) //left - return 5; - if(hex2 == hex1 + 1 && hex1%17 != 16) //right - return 2; - if(hex2 == hex1 + ( (hex1/17)%2 ? 16 : 17 )) //bottom left - return 4; - if(hex2 == hex1 + ( (hex1/17)%2 ? 17 : 18 )) //bottom right - return 3; - return -1; - } - //returns distance between given hexes - static si8 getDistance(THex hex1, THex hex2) - { - int xDst = std::abs(hex1 % BFIELD_WIDTH - hex2 % BFIELD_WIDTH), - yDst = std::abs(hex1 / BFIELD_WIDTH - hex2 / BFIELD_WIDTH); - return std::max(xDst, yDst) + std::min(xDst, yDst) - (yDst + 1)/2; - } - - template void serialize(Handler &h, const int version) - { - h & hex; - } - static void checkAndPush(int tile, std::vector & ret) - { - if( tile>=0 && tile= 4 - #define DLL_F_EXPORT __attribute__ ((visibility("default"))) - #else - #define DLL_F_EXPORT - #endif -#endif - -#ifdef _WIN32 -#define DLL_F_IMPORT __declspec(dllimport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_F_IMPORT __attribute__ ((visibility("default"))) -#else -#define DLL_F_IMPORT -#endif -#endif - - -#ifdef VCMI_DLL - #define DLL_EXPORT DLL_F_EXPORT -#else - #define DLL_EXPORT DLL_F_IMPORT -#endif - - -template char (&_ArrayCountObj(const T (&)[N]))[N]; -#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) - - - -//a normal std::map with consted operator[] for sanity -template -class bmap : public std::map -{ -public: - const ValT & operator[](KeyT key) const - { - return find(key)->second; - } - ValT & operator[](KeyT key) - { - return static_cast &>(*this)[key]; - } - template void serialize(Handler &h, const int version) - { - h & static_cast &>(*this); - } -}; - -namespace vstd -{ - template - bool contains(const Container & c, const Item &i) //returns true if container c contains item i - { - return std::find(c.begin(),c.end(),i) != c.end(); - } - template - bool contains(const std::map & c, const Item2 &i) //returns true if map c contains item i - { - return c.find(i)!=c.end(); - } - template - bool contains(const bmap & c, const Item2 &i) //returns true if bmap c contains item i - { - return c.find(i)!=c.end(); - } - template - bool contains(const boost::unordered_set & c, const Item &i) //returns true if unordered set c contains item i - { - return c.find(i)!=c.end(); - } - template - bool contains(const Item (&c)[N], const Item &i) //returns true if given array contains item i - { - return std::find(c, c+N, i) != c+N; //TODO: find out why template is not resolved - } - template - typename Container2::iterator findFirstNot(Container1 &c1, Container2 &c2)//returns first element of c2 not present in c1 - { - typename Container2::iterator itr = c2.begin(); - while(itr != c2.end()) - if(!contains(c1,*itr)) - return itr; - else - ++itr; - return c2.end(); - } - template - typename Container2::const_iterator findFirstNot(const Container1 &c1, const Container2 &c2)//returns const first element of c2 not present in c1 - { - typename Container2::const_iterator itr = c2.begin(); - while(itr != c2.end()) - if(!contains(c1,*itr)) - return itr; - else - ++itr; - return c2.end(); - } - template - typename Container::iterator find(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - template - int findPos(const std::vector & c, const T2 &s) //returns position of first element in vector c equal to s, if there is no such element, -1 is returned - { - for(size_t i=0; i < c.size(); ++i) - if(c[i] == s) - return i; - return -1; - } - template - int findPos(const std::vector & c, const T2 &s, const Func &f) //Func(T1,T2) must say if these elements matches - { - for(size_t i=0; i < c.size(); ++i) - if(f(c[i],s)) - return i; - return -1; - } - template - typename Container::iterator find(Container & c, const Item &i) //returns iterator to the given element if present in container, end() if not - { - return std::find(c.begin(),c.end(),i); - } - template - typename Container::const_iterator find(const Container & c, const Item &i)//returns const iterator to the given element if present in container, end() if not - { - return std::find(c.begin(),c.end(),i); - } - template - typename Container::size_type operator-=(Container &c, const Item &i) //removes element i from container c, returns false if c does not contain i - { - typename Container::iterator itr = find(c,i); - if(itr == c.end()) - return false; - c.erase(itr); - return true; - } - template - void delObj(t1 *a1) - { - delete a1; - } - template - void assign(t1 &a1, const t2 &a2) - { - a1 = a2; - } - template - struct assigner - { - public: - t1 &op1; - t2 op2; - assigner(t1 &a1, const t2 & a2) - :op1(a1), op2(a2) - {} - void operator()() - { - op1 = op2; - } - }; - template - assigner assigno(t1 &a1, const t2 &a2) - { - return assigner(a1,a2); - } - template - bool equal(const t1 &a1, const t3 t1::* point, const t2 &a2) - { - return a1.*point == a2; - } - template - bool equal(const t1 &a1, const t2 &a2) - { - return a1 == a2; - } -} -using vstd::operator-=; - -template -t1 & amax(t1 &a, const t2 &b) //assigns greater of (a, b) to a and returns maximum of (a, b) -{ - if(a >= b) - return a; - else - { - a = b; - return a; - } -} - -template -t1 & amin(t1 &a, const t2 &b) //assigns smaller of (a, b) to a and returns minimum of (a, b) -{ - if(a <= b) - return a; - else - { - a = b; - return a; - } -} - -template -t1 & abetw(t1 &a, const t2 &b, const t3 &c) //makes a to fit the range -{ - amax(a,b); - amin(a,c); - return a; -} - -template -bool isbetw(const t1 &a, const t2 &b, const t3 &c) //checks if a is between b and c -{ - return a > b && a < c; -} - -template -bool iswith(const t1 &a, const t2 &b, const t3 &c) //checks if a is within b and c -{ - return a >= b && a <= c; -} - -template -void delNull(T* &ptr) //deleted pointer and sets it to NULL -{ - delete ptr; - ptr = NULL; -} - -#include "CConsoleHandler.h" -extern DLL_EXPORT std::ostream *logfile; -extern DLL_EXPORT CConsoleHandler *console; - -class CLogger //logger, prints log info to console and saves in file -{ - const int lvl; -#ifdef ANDROID - std::ostringstream buf; - int androidloglevel; - void outputAndroid() - { - int pos = buf.str().find("\n"); - while( pos >= 0 ) - { - __android_log_print(androidloglevel, "VCMI", "%s", buf.str().substr(0, pos).c_str() ); - buf.str( buf.str().substr(pos+1) ); - pos = buf.str().find("\n"); - } - } -#endif - -public: - CLogger& operator<<(std::ostream& (*fun)(std::ostream&)) - { -#ifdef ANDROID - buf << fun; - outputAndroid(); -#else - if(lvl < CONSOLE_LOGGING_LEVEL) - std::cout << fun; - if((lvl < FILE_LOGGING_LEVEL) && logfile) - *logfile << fun; -#endif - return *this; - } - - template - CLogger & operator<<(const T & data) - { -#ifdef ANDROID - buf << data; - outputAndroid(); -#else - if(lvl < CONSOLE_LOGGING_LEVEL) - { - if(console) - console->print(data,lvl); - else - std::cout << data << std::flush; - } - if((lvl < FILE_LOGGING_LEVEL) && logfile) - *logfile << data << std::flush; -#endif - return *this; - } - - CLogger(const int Lvl) : lvl(Lvl) - { -#ifdef ANDROID - androidloglevel = ANDROID_LOG_INFO; - switch(lvl) { - case 0: androidloglevel = ANDROID_LOG_INFO; break; - case 1: androidloglevel = ANDROID_LOG_FATAL; break; - case 2: androidloglevel = ANDROID_LOG_ERROR; break; - case 3: androidloglevel = ANDROID_LOG_WARN; break; - case 4: androidloglevel = ANDROID_LOG_INFO; break; - case 5: androidloglevel = ANDROID_LOG_DEBUG; break; - case 6: case -2: androidloglevel = ANDROID_LOG_VERBOSE; break; - } -#endif - } -}; - -extern DLL_EXPORT CLogger tlog0; //green - standard progress info -extern DLL_EXPORT CLogger tlog1; //red - big errors -extern DLL_EXPORT CLogger tlog2; //magenta - major warnings -extern DLL_EXPORT CLogger tlog3; //yellow - minor warnings -extern DLL_EXPORT CLogger tlog4; //white - detailed log info -extern DLL_EXPORT CLogger tlog5; //gray - minor log info -extern DLL_EXPORT CLogger tlog6; //teal - AI info - -//XXX pls dont - 'debug macros' are usually more trouble than it's worth -#define HANDLE_EXCEPTION \ - catch (const std::exception& e) { \ - tlog1 << e.what() << std::endl; \ - throw; \ - } \ - catch (const std::exception * e) \ - { \ - tlog1 << e->what()<< std::endl; \ - throw; \ - } \ - catch (const std::string& e) { \ - tlog1 << e << std::endl; \ - throw; \ - } - -#define HANDLE_EXCEPTIONC(COMMAND) \ - catch (const std::exception& e) { \ - COMMAND; \ - tlog1 << e.what() << std::endl; \ - throw; \ - } \ - catch (const std::string &e) \ - { \ - COMMAND; \ - tlog1 << e << std::endl; \ - throw; \ - } - -//for explicit overrides -#ifdef _MSC_VER - #define OVERRIDE override -#else - #define OVERRIDE //is there any working counterpart? -#endif - -#define BONUS_TREE_DESERIALIZATION_FIX if(!h.saving && h.smartPointerSerialization) deserializationFix(); - -#endif // __GLOBAL_H__ diff --git a/AI_Base.h b/lib/AI_Base.h similarity index 61% rename from AI_Base.h rename to lib/AI_Base.h index c4986ebc0..b7814f0af 100644 --- a/AI_Base.h +++ b/lib/AI_Base.h @@ -1,9 +1,6 @@ -#ifndef __AI_BASE_H__ -#define __AI_BASE_H__ +#pragma once -#include -#include -#include "lib/CGameInterface.h" +#include "CGameInterface.h" /* * AI_Base.h, part of VCMI engine @@ -16,5 +13,3 @@ */ #define AI_INTERFACE_VER 1 - -#endif // __AI_BASE_H__ diff --git a/CConsoleHandler.cpp b/lib/CConsoleHandler.cpp similarity index 94% rename from CConsoleHandler.cpp rename to lib/CConsoleHandler.cpp index 66bd82254..7f5f4406d 100644 --- a/CConsoleHandler.cpp +++ b/lib/CConsoleHandler.cpp @@ -1,9 +1,6 @@ -#define VCMI_DLL -#include "stdafx.h" +#include "StdInc.h" #include "CConsoleHandler.h" -#include -#include -#include + #include "CThreadHelper.h" /* diff --git a/CConsoleHandler.h b/lib/CConsoleHandler.h similarity index 70% rename from CConsoleHandler.h rename to lib/CConsoleHandler.h index 166c9e919..b5e32b020 100644 --- a/CConsoleHandler.h +++ b/lib/CConsoleHandler.h @@ -1,5 +1,4 @@ -#ifndef __CCONSOLEHANDLER_H__ -#define __CCONSOLEHANDLER_H__ +#pragma once /* * CConsoleHandler.h, part of VCMI engine @@ -11,16 +10,10 @@ * */ -namespace boost -{ - template - class function; - class thread; -} /// Class which wraps the native console. It can print text based on /// the chosen color -class DLL_EXPORT CConsoleHandler +class DLL_LINKAGE CConsoleHandler { public: boost::function *cb; //function to be called when message is received @@ -35,13 +28,10 @@ public: void start(); //starts listening thread void end(); //kills listening thread - template void print(const T &data, int level) + template void print(const T &data, int lvl) { - setColor(level); + setColor(lvl); std::cout << data << std::flush; setColor(-1); } }; - - -#endif // __CCONSOLEHANDLER_H__ diff --git a/lib/CLogger.cpp b/lib/CLogger.cpp new file mode 100644 index 000000000..91921637a --- /dev/null +++ b/lib/CLogger.cpp @@ -0,0 +1,62 @@ +#include "StdInc.h" +#include "CLogger.h" + +// Console, file definitions +DLL_LINKAGE CConsoleHandler *console = NULL; +DLL_LINKAGE std::ostream *logfile = NULL; + +// CLogger definitions +DLL_LINKAGE CLogger tlog0(0); +DLL_LINKAGE CLogger tlog1(1); +DLL_LINKAGE CLogger tlog2(2); +DLL_LINKAGE CLogger tlog3(3); +DLL_LINKAGE CLogger tlog4(4); +DLL_LINKAGE CLogger tlog5(5); +DLL_LINKAGE CLogger tlog6(-2); + +// Logging level settings +const int CLogger::CONSOLE_LOGGING_LEVEL = 5; +const int CLogger::FILE_LOGGING_LEVEL = 6; + +CLogger::CLogger(const int Lvl) : lvl(Lvl) +{ +#ifdef ANDROID + androidloglevel = ANDROID_LOG_INFO; + switch(lvl) { +case 0: androidloglevel = ANDROID_LOG_INFO; break; +case 1: androidloglevel = ANDROID_LOG_FATAL; break; +case 2: androidloglevel = ANDROID_LOG_ERROR; break; +case 3: androidloglevel = ANDROID_LOG_WARN; break; +case 4: androidloglevel = ANDROID_LOG_INFO; break; +case 5: androidloglevel = ANDROID_LOG_DEBUG; break; +case 6: case -2: androidloglevel = ANDROID_LOG_VERBOSE; break; + } +#endif +} + +#ifdef ANDROID +void CLogger::outputAndroid() +{ + int pos = buf.str().find("\n"); + while( pos >= 0 ) + { + __android_log_print(androidloglevel, "VCMI", "%s", buf.str().substr(0, pos).c_str() ); + buf.str( buf.str().substr(pos+1) ); + pos = buf.str().find("\n"); + } +} +#endif + +CLogger& CLogger::operator<<(std::ostream& (*fun)(std::ostream&)) +{ +#ifdef ANDROID + buf << fun; + outputAndroid(); +#else + if(lvl < CLogger::CONSOLE_LOGGING_LEVEL) + std::cout << fun; + if((lvl < CLogger::FILE_LOGGING_LEVEL) && logfile) + *logfile << fun; +#endif + return *this; +} \ No newline at end of file diff --git a/lib/CLogger.h b/lib/CLogger.h new file mode 100644 index 000000000..fb1aa02c5 --- /dev/null +++ b/lib/CLogger.h @@ -0,0 +1,53 @@ +#pragma once + +#include "CConsoleHandler.h" + +extern DLL_LINKAGE std::ostream *logfile; +extern DLL_LINKAGE CConsoleHandler *console; + +// CLogger, prints log info to console and saves in file +class DLL_LINKAGE CLogger +{ + const int lvl; +#ifdef ANDROID + std::ostringstream buf; + int androidloglevel; + void outputAndroid(); +#endif + +public: + static const int CONSOLE_LOGGING_LEVEL; + static const int FILE_LOGGING_LEVEL; + + CLogger& operator<<(std::ostream& (*fun)(std::ostream&)); + + template + CLogger & operator<<(const T & data) + { +#ifdef ANDROID + buf << data; + outputAndroid(); +#else + if(lvl < CLogger::CONSOLE_LOGGING_LEVEL) + { + if(console) + console->print(data, lvl); + else + std::cout << data << std::flush; + } + if((lvl < CLogger::FILE_LOGGING_LEVEL) && logfile) + *logfile << data << std::flush; +#endif + return *this; + } + + CLogger(const int Lvl); +}; + +extern DLL_LINKAGE CLogger tlog0; //green - standard progress info +extern DLL_LINKAGE CLogger tlog1; //red - big errors +extern DLL_LINKAGE CLogger tlog2; //magenta - major warnings +extern DLL_LINKAGE CLogger tlog3; //yellow - minor warnings +extern DLL_LINKAGE CLogger tlog4; //white - detailed log info +extern DLL_LINKAGE CLogger tlog5; //gray - minor log info +extern DLL_LINKAGE CLogger tlog6; //teal - AI info diff --git a/CThreadHelper.cpp b/lib/CThreadHelper.cpp similarity index 91% rename from CThreadHelper.cpp rename to lib/CThreadHelper.cpp index 11440b759..324971d76 100644 --- a/CThreadHelper.cpp +++ b/lib/CThreadHelper.cpp @@ -1,8 +1,6 @@ -#define VCMI_DLL - +#include "StdInc.h" #include "CThreadHelper.h" -#include -#include + #ifdef _WIN32 #include #endif diff --git a/CThreadHelper.h b/lib/CThreadHelper.h similarity index 79% rename from CThreadHelper.h rename to lib/CThreadHelper.h index 5f8cbb7a3..72b9a92ce 100644 --- a/CThreadHelper.h +++ b/lib/CThreadHelper.h @@ -1,9 +1,6 @@ -#ifndef __CTHREADHELPER_H__ -#define __CTHREADHELPER_H__ +#pragma once + -#include "global.h" -#include -#include /* @@ -19,7 +16,7 @@ typedef boost::function Task; /// Can assign CPU work to other threads/cores -class DLL_EXPORT CThreadHelper +class DLL_LINKAGE CThreadHelper { boost::mutex rtinm; int currentTask, amount, threads; @@ -37,7 +34,7 @@ template inline void setData(T * data, boost::function func) *data = func(); } -void DLL_EXPORT setThreadName(long threadID, const std::string &name); +void DLL_LINKAGE setThreadName(long threadID, const std::string &name); #define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \ (boost::bind(&setData,&DESTINATION,FUNCTION_TO_GET)) @@ -53,5 +50,3 @@ void DLL_EXPORT setThreadName(long threadID, const std::string &name); (GET_DATA \ (CDefEssential*,DESTINATION,\ boost::function(boost::bind(CDefHandler::giveDefEss,DEF_NAME)))) - -#endif // __CTHREADHELPER_H__ diff --git a/lib/GameConstants.h b/lib/GameConstants.h new file mode 100644 index 000000000..42a12356a --- /dev/null +++ b/lib/GameConstants.h @@ -0,0 +1,176 @@ +#pragma once + +/* + * GameConstants.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +namespace GameConstants +{ + const std::string VCMI_VERSION = "VCMI 0.86e"; + + /* + * DATA_DIR contains the game data (Data/, MP3/, ...). + * BIN_DIR is where the vcmiclient/vcmiserver binaries reside + * LIB_DIR is where the AI libraries reside (linux only) + */ + #ifdef _WIN32 + const std::string DATA_DIR = "."; + const std::string BIN_DIR = "."; + const std::string LIB_DIR = "."; + const std::string SERVER_NAME = "VCMI_server.exe"; + const std::string LIB_EXT = "dll"; + const std::string PATH_SEPARATOR = "\\"; + #else + #ifndef M_DATA_DIR + #error M_DATA_DIR undefined. + #else + const std::string DATA_DIR = M_DATA_DIR; + #endif + #ifndef M_BIN_DIR + #error M_BIN_DIR undefined. + #else + const std::string BIN_DIR = M_BIN_DIR; + #endif + #ifndef M_LIB_DIR + #error M_LIB_DIR undefined. + #else + const std::string LIB_DIR = M_LIB_DIR; + #endif + const std::string SERVER_NAME = "vcmiserver"; + const std::string LIB_EXT = "so"; + const std::string PATH_SEPARATOR = "/"; + #endif + + const int BFIELD_WIDTH = 17; + const int BFIELD_HEIGHT = 11; + const int BFIELD_SIZE = BFIELD_WIDTH * BFIELD_HEIGHT; + + const int ARMY_SIZE = 7; + + const int BOATI_TYPE = 8; + const int HEROI_TYPE = 34; + const int TOWNI_TYPE = 98; + const int SUBTERRANEAN_GATE_TYPE = 103; + const int CREI_TYPE = 54; + const int EVENTI_TYPE = 26; + + const int CREATURES_COUNT = 197; + const int CRE_LEVELS = 10; + const int F_NUMBER = 9; //factions (town types) quantity + const int PLAYER_LIMIT = 8; //player limit per map + const int ALL_PLAYERS = 255; //bitfield + const int HEROES_PER_TYPE=8; //amount of heroes of each type + const int SKILL_QUANTITY=28; + const int SKILL_PER_HERO=8; + const int ARTIFACTS_QUANTITY=171; + const int HEROES_QUANTITY=156; + const int SPELLS_QUANTITY=70; + const int RESOURCE_QUANTITY=8; + const int TERRAIN_TYPES=10; + const int PRIMARY_SKILLS=4; + const int NEUTRAL_PLAYER=255; + const int NAMES_PER_TOWN=16; + const int CREATURES_PER_TOWN = 7; //without upgrades + const int MAX_BUILDING_PER_TURN = 1; + const int SPELL_LEVELS = 5; + const int CREEP_SIZE = 4000; // neutral stacks won't grow beyond this number + const int WEEKLY_GROWTH = 10; //percent + const int AVAILABLE_HEROES_PER_PLAYER = 2; + const bool DWELLINGS_ACCUMULATE_CREATURES = false; + const bool STACK_EXP = true; + const bool STACK_ARTIFACT = true; + const int SPELLBOOK_GOLD_COST = 500; + + const ui16 BACKPACK_START = 19; + const int ID_CATAPULT = 3, ID_LOCK = 145; + const ui16 CREATURE_ART = 0; +} + +// Enum declarations +namespace EVictoryConditionType +{ + enum EVictoryConditionType { ARTIFACT, GATHERTROOP, GATHERRESOURCE, BUILDCITY, BUILDGRAIL, BEATHERO, + CAPTURECITY, BEATMONSTER, TAKEDWELLINGS, TAKEMINES, TRANSPORTITEM, WINSTANDARD = 255 }; +} + +namespace ELossConditionType +{ + enum ELossConditionType { LOSSCASTLE, LOSSHERO, TIMEEXPIRES, LOSSSTANDARD = 255 }; +} + +namespace EAlignment +{ + enum EAlignment { GOOD, EVIL, NEUTRAL }; +} + +namespace EBuilding +{ + //Quite useful as long as most of building mechanics hardcoded + enum EBuilding + { + MAGES_GUILD_1, MAGES_GUILD_2, MAGES_GUILD_3, MAGES_GUILD_4, MAGES_GUILD_5, + TAVERN, SHIPYARD, FORT, CITADEL, CASTLE, + VILLAGE_HALL, TOWN_HALL, CITY_HALL, CAPITOL, MARKETPLACE, + RESOURCE_SILO, BLACKSMITH, SPECIAL_1, HORDE_1, HORDE_1_UPGR, + SHIP, SPECIAL_2, SPECIAL_3, SPECIAL_4, HORDE_2, + HORDE_2_UPGR, GRAIL, EXTRA_CITY_HALL, EXTRA_TOWN_HALL, EXTRA_CAPITOL, + DWELL_FIRST=30, DWELL_LAST=36, DWELL_UP_FIRST=37, DWELL_UP_LAST=43 + }; +} + +namespace EBuildingState +{ + enum EBuildingState + { + HAVE_CAPITAL, NO_WATER, FORBIDDEN, ADD_MAGES_GUILD, ALREADY_PRESENT, CANT_BUILD_TODAY, + NO_RESOURCES, ALLOWED, PREREQUIRES, BUILDING_ERROR + }; +} + +namespace ESpellCastProblem +{ + enum ESpellCastProblem + { + OK, NO_HERO_TO_CAST_SPELL, ALREADY_CASTED_THIS_TURN, NO_SPELLBOOK, ANOTHER_ELEMENTAL_SUMMONED, + HERO_DOESNT_KNOW_SPELL, NOT_ENOUGH_MANA, ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL, + SECOND_HEROS_SPELL_IMMUNITY, SPELL_LEVEL_LIMIT_EXCEEDED, NO_SPELLS_TO_DISPEL, + NO_APPROPRIATE_TARGET, STACK_IMMUNE_TO_SPELL, WRONG_SPELL_TARGET + }; +} + +namespace ECastingMode +{ + enum ECastingMode {HERO_CASTING, AFTER_ATTACK_CASTING, //also includes cast before attack + MAGIC_MIRROR, CREATURE_ACTIVE_CASTING, ENCHANTER_CASTING}; +} + +namespace EMarketMode +{ + enum EMarketMode + { + RESOURCE_RESOURCE, RESOURCE_PLAYER, CREATURE_RESOURCE, RESOURCE_ARTIFACT, + ARTIFACT_RESOURCE, ARTIFACT_EXP, CREATURE_EXP, CREATURE_UNDEAD, RESOURCE_SKILL, + MARTKET_AFTER_LAST_PLACEHOLDER + }; +} + +namespace EBattleStackState +{ + enum EBattleStackState{ALIVE = 180, SUMMONED, CLONED, HAD_MORALE, WAITING, MOVED, DEFENDING, FEAR}; +} + +// Typedef declarations +typedef si64 expType; +typedef ui32 TSpell; +typedef std::pair TDmgRange; +typedef ui8 TBonusType; +typedef si32 TBonusSubtype; +typedef si32 TSlot; +typedef si32 TQuantity; +typedef ui32 TCreature; //creature id diff --git a/lib/RegisterTypes.cpp b/lib/RegisterTypes.cpp deleted file mode 100644 index d10b3be2f..000000000 --- a/lib/RegisterTypes.cpp +++ /dev/null @@ -1,242 +0,0 @@ -#include "Connection.h" -#include "NetPacks.h" -#include "VCMI_Lib.h" -#include "CArtHandler.h" -#include "CObjectHandler.h" -#include "CGameState.h" -#include "CHeroHandler.h" -#include "CTownHandler.h" -/* - * RegisterTypes.cpp, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -#ifndef VCMI_DLL - #undef DLL_EXPORT - #define DLL_EXPORT -#endif - -#include "RegisterTypes.h" - -template DLL_EXPORT -void registerTypes1(Serializer &s) -{ - //map objects - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - //end of objects - s.template registerType(); - s.template registerType(); - - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); -} - -template DLL_EXPORT -void registerTypes2(Serializer &s) -{ - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - //s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - //s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); -} - -template DLL_EXPORT -void registerTypes3(Serializer &s) -{ - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); -} - -template DLL_EXPORT -void registerTypes4(Serializer &s) -{ - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); -} - -template DLL_EXPORT -void registerTypes(Serializer &s) -{ - registerTypes1(s); - registerTypes2(s); - registerTypes3(s); - registerTypes4(s); -} diff --git a/lib/SHexField.cpp b/lib/SHexField.cpp new file mode 100644 index 000000000..6d3b1bd85 --- /dev/null +++ b/lib/SHexField.cpp @@ -0,0 +1,85 @@ +#include "StdInc.h" +#include "SHexField.h" + +void SHexField::operator+=(EDir dir) +{ + si16 x = getX(), + y = getY(); + + switch(dir) + { + case TOP_LEFT: + setXY(y%2 ? x-1 : x, y-1); + break; + case TOP_RIGHT: + setXY(y%2 ? x : x+1, y-1); + break; + case RIGHT: + setXY(x+1, y); + break; + case BOTTOM_RIGHT: + setXY(y%2 ? x : x+1, y+1); + break; + case BOTTOM_LEFT: + setXY(y%2 ? x-1 : x, y+1); + break; + case LEFT: + setXY(x-1, y); + break; + default: + throw std::string("Disaster: wrong direction in SHexField::operator+=!\n"); + break; + } +} + +SHexField SHexField::operator+(EDir dir) const +{ + SHexField ret(*this); + ret += dir; + return ret; +} + +std::vector SHexField::neighbouringTiles() const +{ + std::vector ret; + const int WN = GameConstants::BFIELD_WIDTH; + checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), ret); + checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), ret); + checkAndPush(hex - 1, ret); + checkAndPush(hex + 1, ret); + checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), ret); + checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), ret); + + return ret; +} + +signed char SHexField::mutualPosition(SHexField hex1, SHexField hex2) +{ + if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left + return 0; + if(hex2 == hex1 - ( (hex1/17)%2 ? 17 : 16 )) //top right + return 1; + if(hex2 == hex1 - 1 && hex1%17 != 0) //left + return 5; + if(hex2 == hex1 + 1 && hex1%17 != 16) //right + return 2; + if(hex2 == hex1 + ( (hex1/17)%2 ? 16 : 17 )) //bottom left + return 4; + if(hex2 == hex1 + ( (hex1/17)%2 ? 17 : 18 )) //bottom right + return 3; + return -1; +} + +char SHexField::getDistance(SHexField hex1, SHexField hex2) +{ + int xDst = std::abs(hex1 % GameConstants::BFIELD_WIDTH - hex2 % GameConstants::BFIELD_WIDTH), + yDst = std::abs(hex1 / GameConstants::BFIELD_WIDTH - hex2 / GameConstants::BFIELD_WIDTH); + return std::max(xDst, yDst) + std::min(xDst, yDst) - (yDst + 1)/2; +} + +void SHexField::checkAndPush(int tile, std::vector & ret) +{ + if( tile>=0 && tile= 0 && hex < GameConstants::BFIELD_SIZE; + } + + template + SHexField(inttype x, inttype y) + { + setXY(x, y); + } + + template + SHexField(std::pair xy) + { + setXY(xy); + } + + template + void setX(inttype x) + { + setXY(x, getY()); + } + + template + void setY(inttype y) + { + setXY(getX(), y); + } + + void setXY(si16 x, si16 y) + { + assert(x >= 0 && x < GameConstants::BFIELD_WIDTH && y >= 0 && y < GameConstants::BFIELD_HEIGHT); + hex = x + y * GameConstants::BFIELD_WIDTH; + } + + template + void setXY(std::pair xy) + { + setXY(xy.first, xy.second); + } + + si16 getY() const + { + return hex / GameConstants::BFIELD_WIDTH; + } + + si16 getX() const + { + int pos = hex - getY() * GameConstants::BFIELD_WIDTH; + return pos; + } + + std::pair getXY() const + { + return std::make_pair(getX(), getY()); + } + + //moving to direction + void operator+=(EDir dir); + + //generates new SHexField moved by given dir + SHexField operator+(EDir dir) const; + + std::vector neighbouringTiles() const; + + //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left) + static signed char mutualPosition(SHexField hex1, SHexField hex2); + + //returns distance between given hexes + static char getDistance(SHexField hex1, SHexField hex2); + + template void serialize(Handler &h, const int version) + { + h & hex; + } + static void checkAndPush(int tile, std::vector & ret); + +}; \ No newline at end of file diff --git a/StartInfo.h b/lib/StartInfo.h similarity index 90% rename from StartInfo.h rename to lib/StartInfo.h index c8e6a3083..c8ce6ebc2 100644 --- a/StartInfo.h +++ b/lib/StartInfo.h @@ -1,9 +1,4 @@ -#ifndef __STARTINFO_H__ -#define __STARTINFO_H__ - -#include "global.h" -#include -#include +#pragma once /* * StartInfo.h, part of VCMI engine @@ -96,6 +91,3 @@ struct StartInfo choosenCampaignBonus = -1; } }; - - -#endif // __STARTINFO_H__ diff --git a/lib/StdInc.cpp b/lib/StdInc.cpp new file mode 100644 index 000000000..c8f4ddf05 --- /dev/null +++ b/lib/StdInc.cpp @@ -0,0 +1,2 @@ +// Creates the precompiled header +#include "StdInc.h" \ No newline at end of file diff --git a/lib/StdInc.h b/lib/StdInc.h new file mode 100644 index 000000000..18659d5ee --- /dev/null +++ b/lib/StdInc.h @@ -0,0 +1,325 @@ +#pragma once + +// Standard include file +// Should be treated as a precompiled header file in the compiler settings +// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio +// This file shouldn't be changed, except if there is a important header file which is missing. + +/* + * StdInc.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#ifdef _WIN32 +#include +#else +#include "../tchar_amigaos4.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +//filesystem version 3 causes problems (and it's default as of boost 1.46) +#define BOOST_FILESYSTEM_VERSION 2 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef ANDROID +#include +#endif + +// Integral data types +typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) +typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) +typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) +typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) +typedef boost::int64_t si64; //signed int 64 bits (8 bytes) +typedef boost::int32_t si32; //signed int 32 bits (4 bytes) +typedef boost::int16_t si16; //signed int 16 bits (2 bytes) +typedef boost::int8_t si8; //signed int 8 bits (1 byte) + +// Import + Export macro declarations +#ifdef _WIN32 +#define DLL_EXPORT __declspec(dllexport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_EXPORT __attribute__ ((visibility("default"))) +#else +#define DLL_EXPORT +#endif +#endif + +#ifdef _WIN32 +#define DLL_IMPORT __declspec(dllimport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_IMPORT __attribute__ ((visibility("default"))) +#else +#define DLL_IMPORT +#endif +#endif + +#ifdef VCMI_DLL +#define DLL_LINKAGE DLL_EXPORT +#else +#define DLL_LINKAGE DLL_IMPORT +#endif + + +//a normal std::map with a const operator[] for sanity +template +class bmap : public std::map +{ +public: + const ValT & operator[](KeyT key) const + { + return find(key)->second; + } + ValT & operator[](KeyT key) + { + return static_cast &>(*this)[key]; + } + template void serialize(Handler &h, const int version) + { + h & static_cast &>(*this); + } +}; + +namespace vstd +{ + //returns true if container c contains item i + template + bool contains(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i) != c.end(); + } + + //returns true if map c contains item i + template + bool contains(const std::map & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if bmap c contains item i + template + bool contains(const bmap & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if unordered set c contains item i + template + bool contains(const boost::unordered_set & c, const Item &i) + { + return c.find(i)!=c.end(); + } + + //returns position of first element in vector c equal to s, if there is no such element, -1 is returned + template + int find_pos(const std::vector & c, const T2 &s) + { + for(size_t i=0; i < c.size(); ++i) + if(c[i] == s) + return i; + return -1; + } + + //Func(T1,T2) must say if these elements matches + template + int find_pos(const std::vector & c, const T2 &s, const Func &f) + { + for(size_t i=0; i < c.size(); ++i) + if(f(c[i],s)) + return i; + return -1; + } + + //returns iterator to the given element if present in container, end() if not + template + typename Container::iterator find(Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //returns const iterator to the given element if present in container, end() if not + template + typename Container::const_iterator find(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //removes element i from container c, returns false if c does not contain i + template + typename Container::size_type operator-=(Container &c, const Item &i) + { + typename Container::iterator itr = find(c,i); + if(itr == c.end()) + return false; + c.erase(itr); + return true; + } + + //assigns greater of (a, b) to a and returns maximum of (a, b) + template + t1 &amax(t1 &a, const t2 &b) + { + if(a >= b) + return a; + else + { + a = b; + return a; + } + } + + //assigns smaller of (a, b) to a and returns minimum of (a, b) + template + t1 &amin(t1 &a, const t2 &b) + { + if(a <= b) + return a; + else + { + a = b; + return a; + } + } + + //makes a to fit the range + template + t1 &abetween(t1 &a, const t2 &b, const t3 &c) + { + amax(a,b); + amin(a,c); + return a; + } + + //checks if a is between b and c + template + bool isbetween(const t1 &a, const t2 &b, const t3 &c) + { + return a > b && a < c; + } + + //checks if a is within b and c + template + bool iswithin(const t1 &a, const t2 &b, const t3 &c) + { + return a >= b && a <= c; + } + + template + struct assigner + { + public: + t1 &op1; + t2 op2; + assigner(t1 &a1, const t2 & a2) + :op1(a1), op2(a2) + {} + void operator()() + { + op1 = op2; + } + }; + + // Assigns value a2 to a1. The point of time of the real operation can be controlled + // with the () operator. + template + assigner assigno(t1 &a1, const t2 &a2) + { + return assigner(a1,a2); + } + + //deleted pointer and sets it to NULL + template + void clear_pointer(T* &ptr) + { + delete ptr; + ptr = NULL; + } +} +using vstd::operator-=; + +// can be used for counting arrays +template char (&_ArrayCountObj(const T (&)[N]))[N]; +#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) + +//for explicit overrides +#ifdef _MSC_VER +#define OVERRIDE override +#else +#define OVERRIDE //is there any working counterpart? +#endif + +//XXX pls dont - 'debug macros' are usually more trouble than it's worth +#define HANDLE_EXCEPTION \ + catch (const std::exception& e) { \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::exception * e) \ +{ \ + tlog1 << e->what()<< std::endl; \ + throw; \ +} \ + catch (const std::string& e) { \ + tlog1 << e << std::endl; \ + throw; \ +} + +#define HANDLE_EXCEPTIONC(COMMAND) \ + catch (const std::exception& e) { \ + COMMAND; \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::string &e) \ +{ \ + COMMAND; \ + tlog1 << e << std::endl; \ + throw; \ +} + + +#include "../lib/CLogger.h" diff --git a/timeHandler.h b/lib/StopWatch.h similarity index 62% rename from timeHandler.h rename to lib/StopWatch.h index 613517968..03a3d2300 100644 --- a/timeHandler.h +++ b/lib/StopWatch.h @@ -1,5 +1,4 @@ -#ifndef __TIMEHANDLER_H__ -#define __TIMEHANDLER_H__ +#pragma once #ifdef __FreeBSD__ #include @@ -8,7 +7,7 @@ #define TO_MS_DIVISOR (1000) #else #include - #define TO_MS_DIVISOR (CLOCKS_PER_SEC/1000) + #define TO_MS_DIVISOR (CLOCKS_PER_SEC / 1000) #endif /* @@ -21,22 +20,23 @@ * */ -class timeHandler +class StopWatch { - clock_t start, last, mem; + si64 start, last, mem; + public: - timeHandler() + StopWatch() : start(clock()) { last=clock(); mem=0; } - long getDif() //get diff in milliseconds + si64 getDiff() //get diff in milliseconds { - long ret=clock()-last; - last=clock(); - return ret/TO_MS_DIVISOR; + si64 ret = clock() - last; + last = clock(); + return ret / TO_MS_DIVISOR; } void update() { @@ -46,21 +46,20 @@ public: { mem=clock(); } - long memDif() + si64 memDif() { return clock()-mem; } - long clock() + +private: + si64 clock() { #ifdef __FreeBSD__ struct rusage usage; getrusage(RUSAGE_SELF, &usage); - return static_cast(usage.ru_utime.tv_sec + usage.ru_stime.tv_sec) * 1000000 + usage.ru_utime.tv_usec + usage.ru_stime.tv_usec; + return static_cast(usage.ru_utime.tv_sec + usage.ru_stime.tv_sec) * 1000000 + usage.ru_utime.tv_usec + usage.ru_stime.tv_usec; #else return std::clock(); #endif } }; - - -#endif // __TIMEHANDLER_H__ diff --git a/int3.h b/lib/int3.h similarity index 93% rename from int3.h rename to lib/int3.h index 430da6d84..bd3c5a81e 100644 --- a/int3.h +++ b/lib/int3.h @@ -1,5 +1,4 @@ -#ifndef __INT3_H__ -#define __INT3_H__ +#pragma once /* * int3.h, part of VCMI engine @@ -11,8 +10,6 @@ * */ -#include - /// Class which consists of three integer values. Represents position on adventure map. class int3 { @@ -107,5 +104,3 @@ struct ShashInt3 return ret; } }; - -#endif // __INT3_H__ diff --git a/nodrze.h b/nodrze.h deleted file mode 100644 index 66fe685df..000000000 --- a/nodrze.h +++ /dev/null @@ -1,914 +0,0 @@ -#ifndef _NODRZE_H -#define _NODRZE_H - -//don't look here, it's a horrible, partially working implementation of RB trees - -//ignore comment above, it is simply TowDragon's envy. Everything (without removing) is working fine - -//TODO? remove file - not used anymore - -#include -#include -#include -#include - -#define CLOG(x) - -const bool CZERWONY=true, CZARNY=false; -template class wezel -{ -public: - bool kolor:1; - T * zawart; - wezel * ojciec, *lewy, *prawy; - wezel(bool kol):kolor(kol),ojciec(NULL),lewy(NULL),prawy(NULL){zawart = new T;}; - wezel(wezel * NIL); - ~wezel(){delete zawart;} -}; -template std::ostream & piszAdresy(std::ostream & strum, wezel & w) -{ - strum << "Informacje o wezle: "<<&w; - strum <<"\n\tOjciec: "<<(w.ojciec); - strum<<"\n\tLewy syn: "<<(w.lewy); - strum<<"\n\tPrawy syn: "<<(w.prawy); - strum<<"\n\tKolor: "<<((w.kolor)?(std::string("Czerwony")):(std::string("Czarny")))< std::ostream & operator<<(std::ostream & strum, wezel & w) -{ - strum << "Informacje o wezle: "<<&w<<" - "<<*w.zawart; - strum <<"\n\tOjciec: "<<(w.ojciec)<<" - "<<*w.ojciec->zawart; - strum<<"\n\tLewy syn: "<<(w.lewy)<<" - "<<*w.lewy->zawart; - strum<<"\n\tPrawy syn: "<<(w.prawy)<<" - "<<*w.prawy->zawart; - strum<<"\n\tKolor: "<<((w.kolor)?(std::string("Czerwony")):(std::string("Czarny")))< wezel::wezel(wezel * NIL) -{ - ojciec=NIL; lewy=NIL; prawy=NIL; kolor=CZERWONY; zawart = NULL; -} -template class nodrze -{ -private: - wezel * NIL, *ostatnio; - int ile, ktory; - void zepsuj(); - void dodajBSTC (wezel * nowy); - void dodajBST (T co); - void dodajRBT (wezel * nowy); - wezel * usunRBT (wezel * nowy); - void naprawWstaw (wezel * nowy); - void naprawUsun (wezel * x); - wezel * minimum(wezel * w); - wezel * maksimum(wezel * w); - wezel * nastepnik(wezel * w); - wezel * poprzednik(wezel * w); - wezel * szukajRek(wezel * w, T co); - wezel * szukajIter(wezel * w, T co); - void in(std::ostream & strum, wezel * wsk); - void inIt(std::ostream & strum, wezel * wsk); - void pre(std::ostream & strum, wezel * wsk); - void post(std::ostream & strum, wezel * wsk); - void rotacjaLewa (wezel * x); - void rotacjaPrawa (wezel * y); - bool czyBST (wezel * w); - bool sprawdzW(wezel * w); - void destrukcja(wezel * w); - void wypisuj(wezel * w, std::ostream & strum); - void wypisujPre(wezel * w, std::ostream & strum); -public: - wezel * korzen; //root - nodrze():ile(0) //najzwyczajniejszy w swiecie kosntruktor // c-tor - { - NIL=new wezel(CZARNY); - NIL->zawart=NULL; - korzen=NIL; - ostatnio=NIL; - ktory=0; - }; - T * begin () {return minimumimum();}; //first element (=minimum) - T * end () {return NIL;}; // - void clear(); // czysci az do korzenia wlacznie - // removes all elements, including root - void usun (T co); // usuwa element z drzewa - // remove element (value) - bool sprawdz(); // sprawdza, czy drzewo jest poprawnym drzewem BST - //checks if tree is correct (rather useful only for debugging) - T * nast(T czego); // nastepnik zadanego elementu - // successor of that element - T * maksimumimum (); // najwiekszy element w drzewie - //biggest element (and last) - bool czyJest(T co); // czy cos jest w drzewie - //check if given element is in tree - T * minimumimum (); // najmniejszy element w drzewie - //smallest element (first) - void dodaj (T co); // dodaje element do drzewa - // adds (copies) - void inorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku inorder - //print all elements inorder - void preorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku preorder - //print all elements preorder - void postorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku postorder - //print all elements postorder - void wypiszObficie(std::ostream & strum); //wypisuje dane o kazdym wezle -- wymaga operatora >> dla zawartosci - //prints info about all nodes - >> operator for T needed - std::vector vectorize(); //returns vector with all nodrze elements - T * znajdz (T co, bool iter = true); // wyszukuje zadany element - //search for T - int size(); //ilosc elementow - //returns size of tree - T* operator()(int i) ; //n-ty element przez wskaxnik - //returns pointer to element with index i - nodrze & operator()(std::istream & potoczek) ; //zczytanie n elemntow z listy - //read elements from istream (first must be given amount of elements) - T& operator[](int i) ; //dostep do obiektu, ale przez wartosc - //returns value of object with index i - bool operator+=(T * co); //add - bool operator+=(T co); //add - bool operator-=(T co); //remove - bool operator-=(T * co); //ve - T* operator%(T * co); // search and return pointer - bool operator&(T co); // check if exist - bool operator&(T * co); // check if exist - template friend Y* operator%(nodrze & drzewko, X co); // search and return pointer - void push_back(T co){(*this)+=co;}; // add -}; -template std::vector nodrze::vectorize() -{ - std::vector ret; - for (int i=0; i void nodrze::wypisuj(wezel * w, std::ostream & strum) -{ - if (w==NIL) return; - wypisuj(w->lewy, strum); - - strum << "Informacje o wezle: "<ojciec!=NIL) - strum <<"\n\tOjciec: "<<(w->ojciec)<<" - "<<*(w->ojciec->zawart); - else strum <<"\n\tOjciec: NIL"; - if (w->lewy!=NIL) - strum<<"\n\tLewy syn: "<<(w->lewy)<<" - "<<*(w->lewy->zawart); - else strum <<"\n\tLewy syn: NIL"; - if (w->prawy!=NIL) - strum<<"\n\tPrawy syn: "<<(w->prawy)<<" - "<<*(w->prawy->zawart); - else strum <<"\n\tPrawy syn: NIL"; - strum<<"\n\tZawartosc: "<<*w->zawart; - strum<<"\n\tKolor: "<<((w->kolor)?(std::string("Czerwony")):(std::string("Czarny")))<prawy, strum); -} -template void nodrze::wypisujPre(wezel * w, std::ostream & strum) -{ - if (w==NIL) return; - - strum << "Informacje o wezle: "<ojciec!=NIL) - strum <<"\n\tOjciec: "<<(w->ojciec)<<" - "<<*(w->ojciec->zawart); - else strum <<"\n\tOjciec: NIL"; - if (w->lewy!=NIL) - strum<<"\n\tLewy syn: "<<(w->lewy)<<" - "<<*(w->lewy->zawart); - else strum <<"\n\tLewy syn: NIL"; - if (w->prawy!=NIL) - strum<<"\n\tPrawy syn: "<<(w->prawy)<<" - "<<*(w->prawy->zawart); - else strum <<"\n\tPrawy syn: NIL"; - strum<<"\n\tZawartosc: "<<*w->zawart; - strum<<"\n\tKolor: "<<((w->kolor)?(std::string("Czerwony")):(std::string("Czarny")))<lewy, strum); - wypisujPre(w->prawy, strum); -} -template void nodrze::wypiszObficie(std::ostream & strum) -{ - strum << "Nodrze " < T* operator%(nodrze & drzewko, X co) -{ - CLOG ("Szukam " <gl->loguj); -#endif - wezel * w = drzewko.korzen; - while (w!=drzewko.NIL && (*w->zawart)!=co) - { - if ((*w->zawart) > co) - w=w->lewy; - else w=w->prawy; - } - return w->zawart; -} -template int nodrze::size() -{ - return ile; -} -template void nodrze::clear() -{ - destrukcja(korzen); - korzen=NIL; - ostatnio=NIL; - ktory=0; -} -template void nodrze::destrukcja(wezel * w) -{ - if (w==NIL) return; - destrukcja(w->lewy); - destrukcja(w->prawy); - //delete w->zawart; - delete w; -} -template nodrze & nodrze::operator()(std::istream & potoczek) -{ - int temp; - potoczek >> temp; - for (int i=0;i> (*this); - return (*this); -} -template T* nodrze::operator()(int i) -{ - int j; - wezel * nasz; - if (ostatnio!=NIL) - { - j=i-ktory; - if (j>0) - { - if (j > (ile-i)) - { - ktory = i; - i=ile-i-1; - nasz = maksimum(korzen); - for (j=0;jzawart); - } - else - { - ktory = i; - nasz = ostatnio; - for (i=0;izawart); - } - } - if (j==0) - { - return (ostatnio->zawart); - } - else - { - ktory = i; - if ((-j)>i) - { - nasz = minimum(korzen); - for (j=0;jzawart); - } - else - { - nasz = ostatnio; - for (i=0;i>j;i--) - { - nasz = poprzednik(nasz); - } - ostatnio=nasz; - return (nasz->zawart); - } - } - } - else - { - ktory = i; - nasz = minimum(korzen); - for (j=0;jzawart); - } -} -template T& nodrze::operator[](int i) -{ - int j; - wezel * nasz; - if (ostatnio!=NIL) - { - j=i-ktory; - if (j>0) - { - if (j > (ile-i)) - { - ktory = i; - i=ile-i-1; - nasz = maksimum(korzen); - for (j=0;jzawart); - } - else - { - ktory = i; - nasz = ostatnio; - for (i=0;izawart); - } - } - if (j==0) - { - return *(ostatnio->zawart); - } - else - { - ktory = i; - if ((-j)>i) - { - nasz = minimum(korzen); - for (j=0;jzawart); - } - else - { - nasz = ostatnio; - for (i=0;i>j;i--) - { - nasz = poprzednik(nasz); - } - ostatnio=nasz; - return *(nasz->zawart); - } - } - } - else - { - ktory = i; - nasz = minimum(korzen); - for (j=0;jzawart); - } -} -template bool nodrze::operator+=(T * co) -{ - wezel * w = new wezel(NIL); - w->kolor=CZERWONY; - w->zawart = co; - dodajRBT(w); - return true; -} -template bool nodrze::operator+=(T co) -{ - dodaj(co); - return true; -} -template bool nodrze::operator-=(T co) -{ - usun(co); - return true; -} -template bool nodrze::operator-=(T * co) -{ - usun(*co); - return true; -} -template T* nodrze::operator%(T * co) -{ - wezel * w = szukajIter(korzen,*co); - if (w != NIL) - return w; - else return NULL; -} -template bool nodrze::operator&(T co) -{ - return czyJest(co); -} -template bool nodrze::operator&(T * co) -{ - return czyJest(*co); -} -template class iterator -{ - /*nodrze * dd; - wezel * akt; -public: - T * operator->() - { - return akt->zawart; - } - iterator& operator++() - { - akt = dd->nastepnik(akt); - return this; - } - iterator& operator--() - { - akt = dd->poprzednik(akt); - return this; - } - T * operator=(T*) - { - akt->zawart = T; - return akt->zawart; - }*/ - /*void start() - { - akt = maksimum(korzen); - }*/ -}; -template void nodrze::inIt(std::ostream & strum, wezel * wsk) -{ - if (wsk == NIL) - return; - - // Start from the minimumimum wsk - while (wsk->lewy != NIL) - wsk=wsk->lewy; - do - { - visit(wsk); - // Next in order will be our right child's leftmost child (if NIL, our right child) - if (wsk->prawy != NIL) - { - wsk = wsk->prawy; - while (wsk->lewy != NIL) - wsk = wsk->left; - } - else - { - while (true) - { - if (wsk->ojciec == NIL) - { - wsk = NIL; - break; - } - wsk = wsk->ojciec; - // If wsk is its parents left child, then its parent hasn't been visited yet - if (wsk->ojciec->lewy == wsk) - break; - } - } - } - while (wsk != NIL); - -} -template bool nodrze::sprawdz() -{ - return (sprawdzW(korzen)); -} -template T * nodrze::znajdz (T co, bool iter) -{ - return ((iter)?(szukajIter(korzen,co)->zawart):(szukajRek(korzen,co)->zawart)); -} -template void nodrze::usun (T co) -{ - wezel * w = szukajIter(korzen, co); - usunRBT(w); - delete w; -} -template void nodrze::naprawUsun (wezel * x) -{ - wezel *w; - while ( (x != korzen) && (x->kolor == CZARNY) ) - { - CLOG("6... "<ojciec->lewy) - { - CLOG("7... "<ojciec->prawy; - if (w->kolor == CZERWONY) - { - w->kolor = CZARNY; - x->ojciec->kolor = CZERWONY; - rotacjaLewa(x->ojciec); - w = x->ojciec->prawy; - } - CLOG("8... "<lewy->kolor == CZARNY) && (w->prawy->kolor == CZARNY) ) - { - CLOG("8,1... "<kolor = CZERWONY; - x = x->ojciec; - } - else - { - CLOG("9... "<prawy->kolor == CZARNY) - { - CLOG("9,1... "<lewy->kolor = CZARNY; - w->kolor = CZERWONY; - rotacjaPrawa(w); - w = x->ojciec->prawy; - CLOG("9,2... "<kolor = x->ojciec->kolor; - x->ojciec->kolor = CZARNY; - w->prawy->kolor = CZARNY; - rotacjaLewa(x->ojciec); - x=korzen; - CLOG("9,4... "<ojciec->lewy; - if (w->kolor == CZERWONY) - { - w->kolor = CZARNY; - x->ojciec->kolor = CZERWONY; - rotacjaPrawa(x->ojciec); - w = x->ojciec->lewy; - } - CLOG("11... "<lewy->kolor == CZARNY) && (w->prawy->kolor == CZARNY) ) - { - w->kolor = CZERWONY; - x = x->ojciec; - } - else - { - if (w->lewy->kolor == CZARNY) - { - w->prawy->kolor = CZARNY; - w->kolor = CZERWONY; - rotacjaLewa(w); - w = x->ojciec->lewy; - } - w->kolor = x->ojciec->kolor; - x->ojciec->kolor = CZARNY; - w->lewy->kolor = CZARNY; - rotacjaPrawa(x->ojciec); - x=korzen; - CLOG("12... "<kolor = CZARNY; - CLOG("13... "< wezel * nodrze::usunRBT (wezel * nowy) -{ - CLOG ("Usuwam "<<*nowy->zawart<zawart) < (*ostatnio->zawart)) - { - ktory--; - CLOG("Ostatnio to "<<(*ostatnio->zawart)<<", czyli teraz "<<(ktory)<<" (mniej) element."<zawart< *y, *x; - if ( (nowy->lewy == NIL) || (nowy->prawy == NIL) ) - y=nowy; - else y = nastepnik(nowy); - CLOG("2... "<lewy != NIL) - x = y->lewy; - else x = y->prawy; - x->ojciec = y->ojciec; - CLOG("3... "<ojciec == NIL) - korzen = x; - else if (y == y->ojciec->lewy) - y->ojciec->lewy = x; - else - y->ojciec->prawy = x; - CLOG("4... "<kolor == CZARNY) - naprawUsun(x); - CLOG ("koniec usuwania"< void nodrze::naprawWstaw (wezel * nowy) -{ - //CLOG ("Naprawiam po wstawieniu"<ojciec->kolor==CZERWONY) - { - if (nowy->ojciec == nowy->ojciec->ojciec->lewy) // ojciec nowego lest lewy - { - wezel * y = nowy->ojciec->ojciec->prawy; - if (y->kolor == CZERWONY) // a stryj jest czerwony - { - nowy->ojciec->kolor = CZARNY; - y->kolor = CZARNY; - nowy->ojciec->ojciec->kolor = CZERWONY; - nowy = nowy->ojciec->ojciec; - } - else - { - if (nowy->ojciec->prawy == nowy) // nowy jest prawym synem - { - nowy = nowy->ojciec; - rotacjaLewa(nowy); - } - nowy->ojciec->kolor=CZARNY; - nowy->ojciec->ojciec->kolor=CZERWONY; - rotacjaPrawa(nowy->ojciec->ojciec); - } - } - else - { - wezel * y = nowy->ojciec->ojciec->lewy; - if (y->kolor == CZERWONY) // a stryj jest czerwony - { - nowy->ojciec->kolor = CZARNY; - y->kolor = CZARNY; - nowy->ojciec->ojciec->kolor = CZERWONY; - nowy = nowy->ojciec->ojciec; - } - else - { - if (nowy->ojciec->lewy == nowy) - { - nowy = nowy->ojciec; - rotacjaPrawa(nowy); - } - nowy->ojciec->kolor=CZARNY; - nowy->ojciec->ojciec->kolor=CZERWONY; - rotacjaLewa(nowy->ojciec->ojciec); - } - } - } - korzen->kolor = CZARNY; -} -template void nodrze::dodajRBT (wezel * nowy) -{ - //CLOG("Dodaje do drzewa "<zawart<zawart) < (*ostatnio->zawart)) - { - ktory++; - } - wezel * y =NIL, * x = korzen; - while (x != NIL) - { - y=x; - if ((*nowy->zawart) < (*x->zawart)) - x=x->lewy; - else x = x->prawy; - } - nowy->ojciec = y; - if (y == NIL) - { - korzen=nowy; - ostatnio=korzen; - ktory=0; - } - else if ((*nowy->zawart) < (*y->zawart)) - y->lewy = nowy; - else y->prawy = nowy; - nowy->kolor = CZERWONY; - naprawWstaw(nowy); -} -template void nodrze::dodaj (T co) -{ - wezel * w = new wezel(NIL); - w->lewy=w->prawy=w->ojciec=NIL; - w->zawart = new T(co); - dodajRBT(w); -} -template void nodrze::zepsuj() -{ - int pom; - pom = *korzen->zawart; - *korzen->zawart = *korzen->prawy->zawart; - *korzen->prawy->zawart = pom; -} -template bool nodrze::czyBST (wezel * w) -{ - if (w->prawy != NIL) - { - if ((*w->prawy->zawart) < (*w->zawart)) - return false; - } - if (w->lewy != NIL) - { - if((*w->lewy->zawart) > (*w->zawart)) - return false; - } - return true; -} -template bool nodrze::sprawdzW(wezel * w) -{ - bool ret = czyBST(w); - if (w->prawy != NIL) - ret&=sprawdzW(w->prawy); - if (w->lewy != NIL) - ret&=sprawdzW(w->lewy); - return ret; -} -template void nodrze::rotacjaLewa (wezel * x) -{ - //CLOG("Wykonuje lew¹ rotacjê na "<zawart< * y = x->prawy; - x->prawy = y->lewy; // zamiana lewego poddrzewa y na prawe poddrzewo x - if (y->lewy != NIL) y->lewy->ojciec = x; // i przypisanie ojcostwa temu poddrzewu - y->ojciec = x->ojciec; // ojcem y bedzie ojciec x - if (x->ojciec == NIL) - korzen = y; - else if ((x->ojciec->lewy) == x) - x->ojciec->lewy = y; - else - x->ojciec->prawy = y; - y->lewy = x; // a x bedzie lewym synem y - x->ojciec = y; -} -template void nodrze::rotacjaPrawa (wezel * y) -{ - //CLOG("Wykonuje prawa rotacjê na "<zawart< * x = y->lewy; - y->lewy = x->prawy; // zamiana prawe poddrzewa x na lewe poddrzewo y - if (x->prawy != NIL) x->prawy->ojciec = y; // i przypisanie ojcostwa temu poddrzewu - x->ojciec = y->ojciec; // ojcem x bedzie ojciec y - if (x->ojciec == NIL) - korzen = x; - else if ((y->ojciec->lewy) == y) - y->ojciec->lewy = x; - else - y->ojciec->prawy = x; - x->prawy = y; // a y bedzie prawym synem x - y->ojciec = x; -} -template T * nodrze::nast(T czego) -{ - wezel * w = szukajIter(korzen,czego); - if (w != NIL) - w = nastepnik(w); - else throw std::exception("Nie znaleziono wartosci"); - if (w != NIL) - return (w->zawart); - else throw std::exception("Nie znaleziono nastepnika"); -} -template bool nodrze::czyJest(T co) -{ - if ( szukajIter(korzen,co) != NIL ) - return true; - else return false; -} -template wezel * nodrze::szukajRek(wezel * w, T co) -{ - if (w==NIL || (!(((*w->zawart)zawart))))) - return w; - if (co < (*w->zawart)) - return szukajRek(w->lewy,co); - else return szukajRek(w->prawy,co); -} -template wezel * nodrze::szukajIter(wezel * w, T co) -{ - while ( w!=NIL && (((*w->zawart)zawart))) ) - { - if (co < (*w->zawart)) - w=w->lewy; - else w=w->prawy; - } - return (w)?w:NULL; -} -template wezel * nodrze::minimum(wezel * w) -{ - while (w->lewy != NIL) - w=w->lewy; - return w; -} -template wezel * nodrze::maksimum(wezel * w) -{ - while (w->prawy != NIL) - w=w->prawy; - return w; -} -template wezel * nodrze::nastepnik(wezel * w) -{ - if (w->prawy != NIL) - return minimum(w->prawy); - wezel * y = w->ojciec; - while (y!= NIL && w == y->prawy) - { - w=y; - y=y->ojciec; - } - return y; -} -template wezel * nodrze::poprzednik(wezel * w) -{ - if (w->lewy != NIL) - return maksimum(w->lewy); - wezel * y = w->ojciec; - while (y!= NIL && w == y->lewy) - { - w=y; - y=y->ojciec; - } - return y; -} -template T * nodrze::maksimumimum () -{ - wezel * ret = maksimum(korzen); - if (ret != NIL) - return (ret->zawart); - else throw std::exception("Drzewo jest puste"); -} -template T * nodrze::minimumimum () -{ - wezel * ret = minimum(korzen); - if (ret != NIL) - return (ret->zawart); - else throw std::exception("Drzewo jest puste"); -} -template void nodrze::inorder(std::ostream & strum) -{ - in(strum,korzen); -} -template void nodrze::preorder(std::ostream & strum) -{ - pre(strum,korzen); -} -template void nodrze::postorder(std::ostream & strum) -{ - post(strum,korzen); -} -template void nodrze::in(std::ostream & strum, wezel * wsk) -{ - if (wsk==NIL) - return; - if (wsk->lewy != NIL) - in(strum,wsk->lewy); - strum << *wsk->zawart<<"\t"; - if (wsk->prawy != NIL) - in(strum,wsk->prawy); -} -template void nodrze::post(std::ostream & strum, wezel * wsk) -{ - if (wsk==NIL) - return; - if (wsk->lewy != NIL) - post(strum,wsk->lewy); - if (wsk->prawy != NIL) - post(strum,wsk->prawy); - strum << *wsk->zawart<<"\t"; -} -template void nodrze::pre(std::ostream & strum, wezel * wsk) -{ - if (wsk == NIL) - return; - strum << *wsk->zawart<<"\t"; - if (wsk->lewy != NIL) - pre(strum,wsk->lewy); - if (wsk->prawy != NIL) - pre(strum,wsk->prawy); -} -#endif //_NODRZE_H diff --git a/server/StdInc.cpp b/server/StdInc.cpp new file mode 100644 index 000000000..c8f4ddf05 --- /dev/null +++ b/server/StdInc.cpp @@ -0,0 +1,2 @@ +// Creates the precompiled header +#include "StdInc.h" \ No newline at end of file diff --git a/server/StdInc.h b/server/StdInc.h new file mode 100644 index 000000000..18659d5ee --- /dev/null +++ b/server/StdInc.h @@ -0,0 +1,325 @@ +#pragma once + +// Standard include file +// Should be treated as a precompiled header file in the compiler settings +// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio +// This file shouldn't be changed, except if there is a important header file which is missing. + +/* + * StdInc.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#ifdef _WIN32 +#include +#else +#include "../tchar_amigaos4.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +//filesystem version 3 causes problems (and it's default as of boost 1.46) +#define BOOST_FILESYSTEM_VERSION 2 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef ANDROID +#include +#endif + +// Integral data types +typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) +typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) +typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) +typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) +typedef boost::int64_t si64; //signed int 64 bits (8 bytes) +typedef boost::int32_t si32; //signed int 32 bits (4 bytes) +typedef boost::int16_t si16; //signed int 16 bits (2 bytes) +typedef boost::int8_t si8; //signed int 8 bits (1 byte) + +// Import + Export macro declarations +#ifdef _WIN32 +#define DLL_EXPORT __declspec(dllexport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_EXPORT __attribute__ ((visibility("default"))) +#else +#define DLL_EXPORT +#endif +#endif + +#ifdef _WIN32 +#define DLL_IMPORT __declspec(dllimport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_IMPORT __attribute__ ((visibility("default"))) +#else +#define DLL_IMPORT +#endif +#endif + +#ifdef VCMI_DLL +#define DLL_LINKAGE DLL_EXPORT +#else +#define DLL_LINKAGE DLL_IMPORT +#endif + + +//a normal std::map with a const operator[] for sanity +template +class bmap : public std::map +{ +public: + const ValT & operator[](KeyT key) const + { + return find(key)->second; + } + ValT & operator[](KeyT key) + { + return static_cast &>(*this)[key]; + } + template void serialize(Handler &h, const int version) + { + h & static_cast &>(*this); + } +}; + +namespace vstd +{ + //returns true if container c contains item i + template + bool contains(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i) != c.end(); + } + + //returns true if map c contains item i + template + bool contains(const std::map & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if bmap c contains item i + template + bool contains(const bmap & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if unordered set c contains item i + template + bool contains(const boost::unordered_set & c, const Item &i) + { + return c.find(i)!=c.end(); + } + + //returns position of first element in vector c equal to s, if there is no such element, -1 is returned + template + int find_pos(const std::vector & c, const T2 &s) + { + for(size_t i=0; i < c.size(); ++i) + if(c[i] == s) + return i; + return -1; + } + + //Func(T1,T2) must say if these elements matches + template + int find_pos(const std::vector & c, const T2 &s, const Func &f) + { + for(size_t i=0; i < c.size(); ++i) + if(f(c[i],s)) + return i; + return -1; + } + + //returns iterator to the given element if present in container, end() if not + template + typename Container::iterator find(Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //returns const iterator to the given element if present in container, end() if not + template + typename Container::const_iterator find(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //removes element i from container c, returns false if c does not contain i + template + typename Container::size_type operator-=(Container &c, const Item &i) + { + typename Container::iterator itr = find(c,i); + if(itr == c.end()) + return false; + c.erase(itr); + return true; + } + + //assigns greater of (a, b) to a and returns maximum of (a, b) + template + t1 &amax(t1 &a, const t2 &b) + { + if(a >= b) + return a; + else + { + a = b; + return a; + } + } + + //assigns smaller of (a, b) to a and returns minimum of (a, b) + template + t1 &amin(t1 &a, const t2 &b) + { + if(a <= b) + return a; + else + { + a = b; + return a; + } + } + + //makes a to fit the range + template + t1 &abetween(t1 &a, const t2 &b, const t3 &c) + { + amax(a,b); + amin(a,c); + return a; + } + + //checks if a is between b and c + template + bool isbetween(const t1 &a, const t2 &b, const t3 &c) + { + return a > b && a < c; + } + + //checks if a is within b and c + template + bool iswithin(const t1 &a, const t2 &b, const t3 &c) + { + return a >= b && a <= c; + } + + template + struct assigner + { + public: + t1 &op1; + t2 op2; + assigner(t1 &a1, const t2 & a2) + :op1(a1), op2(a2) + {} + void operator()() + { + op1 = op2; + } + }; + + // Assigns value a2 to a1. The point of time of the real operation can be controlled + // with the () operator. + template + assigner assigno(t1 &a1, const t2 &a2) + { + return assigner(a1,a2); + } + + //deleted pointer and sets it to NULL + template + void clear_pointer(T* &ptr) + { + delete ptr; + ptr = NULL; + } +} +using vstd::operator-=; + +// can be used for counting arrays +template char (&_ArrayCountObj(const T (&)[N]))[N]; +#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) + +//for explicit overrides +#ifdef _MSC_VER +#define OVERRIDE override +#else +#define OVERRIDE //is there any working counterpart? +#endif + +//XXX pls dont - 'debug macros' are usually more trouble than it's worth +#define HANDLE_EXCEPTION \ + catch (const std::exception& e) { \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::exception * e) \ +{ \ + tlog1 << e->what()<< std::endl; \ + throw; \ +} \ + catch (const std::string& e) { \ + tlog1 << e << std::endl; \ + throw; \ +} + +#define HANDLE_EXCEPTIONC(COMMAND) \ + catch (const std::exception& e) { \ + COMMAND; \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::string &e) \ +{ \ + COMMAND; \ + tlog1 << e << std::endl; \ + throw; \ +} + + +#include "../lib/CLogger.h" diff --git a/server/stdafx.cpp b/server/stdafx.cpp deleted file mode 100644 index 1577c4e3b..000000000 --- a/server/stdafx.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "stdafx.h" \ No newline at end of file diff --git a/server/stdafx.h b/server/stdafx.h deleted file mode 100644 index a0011c780..000000000 --- a/server/stdafx.h +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include //no i/o just types -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../global.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include "../CThreadHelper.h" diff --git a/stdafx.cpp b/stdafx.cpp deleted file mode 100644 index 8c0ad7b82..000000000 --- a/stdafx.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// stdafx.cpp : source file that includes just the standard includes -// CMT.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file diff --git a/stdafx.h b/stdafx.h deleted file mode 100644 index 6382555f0..000000000 --- a/stdafx.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __STDAFX_H__ -#define __STDAFX_H__ - -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#ifdef _WIN32 -#include -#else -#include "tchar_amigaos4.h" -#endif -#include -#include -#include -#include -#include -#include "global.h" -// TODO: reference additional headers your program requires here - -#endif // __STDAFX_H__ From 6ea88593db6291c264a539a1b0db929b3ac87864 Mon Sep 17 00:00:00 2001 From: beegee1 Date: Tue, 13 Dec 2011 21:41:11 +0000 Subject: [PATCH 3/5] * Turned GCC build time statistics off --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e71f71b26..7109dafd6 100644 --- a/configure.ac +++ b/configure.ac @@ -32,7 +32,7 @@ fi # For gcc and compatible compilers, enable compilation warnings, but # selectively disable some because too many are generated. if test "x$GXX" = "xyes" ; then - CXXFLAGS="$CXXFLAGS -ftime-report -Wall -Wno-switch -Wno-sign-compare -Wcast-align -Wpointer-arith -Wno-unknown-pragmas" + CXXFLAGS="$CXXFLAGS -Wall -Wno-switch -Wno-sign-compare -Wcast-align -Wpointer-arith -Wno-unknown-pragmas" fi # extra clang parameters From 2f5d6f2684a14fcf9ad941cc0d93e90192fef01f Mon Sep 17 00:00:00 2001 From: beegee1 Date: Sat, 17 Dec 2011 18:59:59 +0000 Subject: [PATCH 4/5] * CHexField renamed to CBattleHex * CHexFieldControl renamed to CClickableHex * CCreatureAnimation.cpp/.h moved to BattleInterface/CCreatureAnimation.cpp/.h * Removed unused project files * Added VCMI_client filters file for VS 2010 * Gathered common parts of StdInc.h in Global.h * Boost.Spirit has been included in PCH for ERM project * StopWatch renamed to CStopWatch * GuiBase.cpp split up in UIFramework/... --- AI/EmptyAI/StdInc.h | 324 +---- AI/GeniusAI/BattleLogic.cpp | 10 +- AI/GeniusAI/CGeniusAI.cpp | 4 +- AI/GeniusAI/CGeniusAI.h | 2 +- AI/GeniusAI/StdInc.h | 324 +---- AI/GeniusAI/bouml/GeniusAI/129161 | 107 -- AI/GeniusAI/bouml/GeniusAI/129161.diagram | 34 - AI/GeniusAI/bouml/GeniusAI/129289 | 106 -- AI/GeniusAI/bouml/GeniusAI/129289.diagram | 25 - AI/GeniusAI/bouml/GeniusAI/129417 | 87 -- AI/GeniusAI/bouml/GeniusAI/129417.diagram | 3 - AI/GeniusAI/bouml/GeniusAI/GeniusAI.prj | 46 - AI/GeniusAI/bouml/GeniusAI/cpp_includes | 13 - .../bouml/GeniusAI/generation_settings | 309 ----- AI/GeniusAI/bouml/GeniusAI/idl_includes | 1 - AI/GeniusAI/bouml/GeniusAI/java_imports | 1 - AI/GeniusAI/bouml/GeniusAI/python_imports | 1 - AI/GeniusAI/bouml/GeniusAI/stereotypes | 58 - AI/GeniusAI/bouml/GeniusAI/tools | 18 - AI/GeniusAI/genius.cbp | 77 -- AI/GeniusAI/genius.vcxproj | 1 + AI/StupidAI/StdInc.h | 324 +---- AI/StupidAI/StupidAI.cpp | 24 +- AI/StupidAI/StupidAI.h | 6 +- AI/StupidAI/StupidAI.vcxproj | 1 + Global.h | 330 +++++ Scripting/ERM/ERM.vcxproj | 1 + Scripting/ERM/ERMParser.cpp | 15 +- Scripting/ERM/ERMParser.h | 4 - Scripting/ERM/StdInc.h | 338 +----- client/AdventureMapButton.cpp | 13 +- client/AdventureMapButton.h | 5 +- client/BattleInterface/CAttackAnimation.cpp | 4 +- client/BattleInterface/CAttackAnimation.h | 6 +- client/BattleInterface/CBattleConsole.h | 2 +- client/BattleInterface/CBattleHero.cpp | 1 + client/BattleInterface/CBattleHero.h | 2 +- client/BattleInterface/CBattleInterface.cpp | 86 +- client/BattleInterface/CBattleInterface.h | 28 +- .../BattleInterface/CBattleOptionsWindow.cpp | 2 +- client/BattleInterface/CBattleOptionsWindow.h | 2 +- .../BattleInterface/CBattleResultWindow.cpp | 1 + client/BattleInterface/CBattleResultWindow.h | 2 +- .../BattleInterface/CBattleStackAnimation.cpp | 4 +- .../BattleInterface/CBattleStackAnimation.h | 6 +- ...CHexFieldControl.cpp => CClickableHex.cpp} | 21 +- .../{CHexFieldControl.h => CClickableHex.h} | 10 +- .../CCreatureAnimation.cpp | 8 +- .../CCreatureAnimation.h | 8 +- client/BattleInterface/CDefenceAnimation.cpp | 2 +- .../BattleInterface/CMeleeAttackAnimation.cpp | 12 +- .../BattleInterface/CMeleeAttackAnimation.h | 2 +- client/BattleInterface/CMovementAnimation.cpp | 14 +- client/BattleInterface/CMovementAnimation.h | 6 +- .../BattleInterface/CMovementEndAnimation.cpp | 4 +- .../BattleInterface/CMovementEndAnimation.h | 4 +- .../CMovementStartAnimation.cpp | 2 +- client/BattleInterface/CReverseAnimation.cpp | 8 +- client/BattleInterface/CReverseAnimation.h | 4 +- client/BattleInterface/CShootingAnimation.cpp | 14 +- client/BattleInterface/CShootingAnimation.h | 4 +- .../BattleInterface/CSpellEffectAnimation.cpp | 5 +- .../BattleInterface/CSpellEffectAnimation.h | 6 +- client/BattleInterface/CStackQueue.cpp | 1 + client/BattleInterface/CStackQueue.h | 2 +- client/CAdvmapInterface.cpp | 43 +- client/CAnimation.cpp | 34 +- client/CAnimation.h | 19 +- client/CCastleInterface.cpp | 71 +- client/CCastleInterface.h | 15 +- client/CCreatureWindow.cpp | 10 +- client/CCreatureWindow.h | 3 +- client/CHeroWindow.cpp | 26 +- client/CKingdomInterface.cpp | 47 +- client/CKingdomInterface.h | 3 +- client/CMT.cpp | 7 +- client/CMessage.cpp | 24 +- client/CPlayerInterface.cpp | 37 +- client/CPlayerInterface.h | 6 +- client/CPreGame.cpp | 53 +- client/CPreGame.h | 4 +- client/CSpellWindow.cpp | 5 +- client/CSpellWindow.h | 4 +- client/Client.cpp | 8 +- client/Client.h | 4 +- client/GUIBase.cpp | 1071 ----------------- client/GUIBase.h | 626 ---------- client/GUIClasses.cpp | 177 +-- client/GUIClasses.h | 73 +- client/Graphics.cpp | 5 +- client/Graphics.h | 5 +- client/Makefile.am | 20 +- client/NetPacksClient.cpp | 2 +- client/SDL_Extensions.cpp | 7 +- client/SDL_Extensions.h | 3 +- client/StdInc.h | 324 +---- client/UIFramework/CGuiHandler.cpp | 461 +++++++ client/UIFramework/CGuiHandler.h | 117 ++ client/UIFramework/CIntObject.cpp | 443 +++++++ client/UIFramework/CIntObject.h | 135 +++ client/UIFramework/CKeyShortcut.cpp | 20 + client/UIFramework/CKeyShortcut.h | 25 + client/UIFramework/CPicture.cpp | 133 ++ client/UIFramework/CPicture.h | 46 + client/UIFramework/CSimpleWindow.h | 23 + client/UIFramework/IActivatable.h | 20 + client/UIFramework/IShowActivatable.h | 24 + client/UIFramework/IShowable.h | 26 + client/UIFramework/IStatusBar.h | 24 + client/UIFramework/IUpdateable.h | 18 + client/UIFramework/SPoint.h | 87 ++ client/UIFramework/SRect.cpp | 19 + client/UIFramework/SRect.h | 187 +++ client/VCMI_client.cbp | 145 --- client/VCMI_client.vcxproj | 28 +- client/VCMI_client.vcxproj.filters | 258 ++++ client/mapHandler.cpp | 3 +- client/vcmi_client/.dep.inc | 5 - client/vcmi_client/Makefile | 92 -- .../vcmi_client/nbproject/Makefile-Debug.mk | 221 ---- .../vcmi_client/nbproject/Makefile-Release.mk | 217 ---- client/vcmi_client/nbproject/Makefile-impl.mk | 123 -- .../vcmi_client/nbproject/Package-Debug.bash | 72 -- .../nbproject/Package-Release.bash | 72 -- .../vcmi_client/nbproject/configurations.xml | 594 --------- .../nbproject/private/configurations.xml | 37 - .../nbproject/private/private.properties | 0 .../vcmi_client/nbproject/private/private.xml | 26 - .../vcmi_client/nbproject/project.properties | 0 client/vcmi_client/nbproject/project.xml | 17 - lib/BattleAction.cpp | 4 +- lib/BattleAction.h | 8 +- lib/BattleState.cpp | 210 ++-- lib/BattleState.h | 64 +- lib/CGameInterface.cpp | 2 +- lib/CGameInterface.h | 4 +- lib/CHeroHandler.cpp | 8 +- lib/CHeroHandler.h | 6 +- lib/{StopWatch.h => CStopWatch.h} | 4 +- lib/IGameCallback.cpp | 40 +- lib/IGameCallback.h | 26 +- lib/IGameEventsReceiver.h | 4 +- lib/Makefile.am | 4 +- lib/NetPacks.h | 4 +- lib/NetPacksLib.cpp | 4 +- lib/{SHexField.cpp => SBattleHex.cpp} | 22 +- lib/{SHexField.h => SBattleHex.h} | 24 +- lib/StdInc.h | 324 +---- lib/VCMI_Lib.cpp | 6 +- lib/VCMI_lib.cbp | 111 -- lib/VCMI_lib.vcxproj | 7 +- lib/map.cpp | 4 +- lib/vcmi_lib/Makefile-nb | 92 -- lib/vcmi_lib/nbproject/Makefile-Debug.mk | 142 --- lib/vcmi_lib/nbproject/Makefile-Release.mk | 142 --- lib/vcmi_lib/nbproject/Makefile-impl.mk | 123 -- lib/vcmi_lib/nbproject/Package-Debug.bash | 72 -- lib/vcmi_lib/nbproject/Package-Release.bash | 72 -- lib/vcmi_lib/nbproject/configurations.xml | 325 ----- lib/vcmi_lib/nbproject/project.properties | 0 lib/vcmi_lib/nbproject/project.xml | 15 - server/CGameHandler.cpp | 24 +- server/CGameHandler.h | 4 +- server/StdInc.h | 324 +---- server/VCMI_server.cbp | 71 -- server/VCMI_server.vcxproj | 1 + server/vcmi_server/Makefile | 92 -- .../vcmi_server/nbproject/Makefile-Debug.mk | 81 -- .../vcmi_server/nbproject/Makefile-Release.mk | 77 -- server/vcmi_server/nbproject/Makefile-impl.mk | 123 -- .../vcmi_server/nbproject/Package-Debug.bash | 72 -- .../nbproject/Package-Release.bash | 72 -- .../vcmi_server/nbproject/configurations.xml | 127 -- .../vcmi_server/nbproject/project.properties | 0 server/vcmi_server/nbproject/project.xml | 17 - vcmi.workspace | 9 - 176 files changed, 3257 insertions(+), 9059 deletions(-) delete mode 100644 AI/GeniusAI/bouml/GeniusAI/129161 delete mode 100644 AI/GeniusAI/bouml/GeniusAI/129161.diagram delete mode 100644 AI/GeniusAI/bouml/GeniusAI/129289 delete mode 100644 AI/GeniusAI/bouml/GeniusAI/129289.diagram delete mode 100644 AI/GeniusAI/bouml/GeniusAI/129417 delete mode 100644 AI/GeniusAI/bouml/GeniusAI/129417.diagram delete mode 100644 AI/GeniusAI/bouml/GeniusAI/GeniusAI.prj delete mode 100644 AI/GeniusAI/bouml/GeniusAI/cpp_includes delete mode 100644 AI/GeniusAI/bouml/GeniusAI/generation_settings delete mode 100644 AI/GeniusAI/bouml/GeniusAI/idl_includes delete mode 100644 AI/GeniusAI/bouml/GeniusAI/java_imports delete mode 100644 AI/GeniusAI/bouml/GeniusAI/python_imports delete mode 100644 AI/GeniusAI/bouml/GeniusAI/stereotypes delete mode 100644 AI/GeniusAI/bouml/GeniusAI/tools delete mode 100644 AI/GeniusAI/genius.cbp create mode 100644 Global.h rename client/BattleInterface/{CHexFieldControl.cpp => CClickableHex.cpp} (78%) rename client/BattleInterface/{CHexFieldControl.h => CClickableHex.h} (74%) rename client/{ => BattleInterface}/CCreatureAnimation.cpp (94%) rename client/{ => BattleInterface}/CCreatureAnimation.h (93%) delete mode 100644 client/GUIBase.cpp delete mode 100644 client/GUIBase.h create mode 100644 client/UIFramework/CGuiHandler.cpp create mode 100644 client/UIFramework/CGuiHandler.h create mode 100644 client/UIFramework/CIntObject.cpp create mode 100644 client/UIFramework/CIntObject.h create mode 100644 client/UIFramework/CKeyShortcut.cpp create mode 100644 client/UIFramework/CKeyShortcut.h create mode 100644 client/UIFramework/CPicture.cpp create mode 100644 client/UIFramework/CPicture.h create mode 100644 client/UIFramework/CSimpleWindow.h create mode 100644 client/UIFramework/IActivatable.h create mode 100644 client/UIFramework/IShowActivatable.h create mode 100644 client/UIFramework/IShowable.h create mode 100644 client/UIFramework/IStatusBar.h create mode 100644 client/UIFramework/IUpdateable.h create mode 100644 client/UIFramework/SPoint.h create mode 100644 client/UIFramework/SRect.cpp create mode 100644 client/UIFramework/SRect.h delete mode 100644 client/VCMI_client.cbp create mode 100644 client/VCMI_client.vcxproj.filters delete mode 100644 client/vcmi_client/.dep.inc delete mode 100644 client/vcmi_client/Makefile delete mode 100644 client/vcmi_client/nbproject/Makefile-Debug.mk delete mode 100644 client/vcmi_client/nbproject/Makefile-Release.mk delete mode 100644 client/vcmi_client/nbproject/Makefile-impl.mk delete mode 100644 client/vcmi_client/nbproject/Package-Debug.bash delete mode 100644 client/vcmi_client/nbproject/Package-Release.bash delete mode 100644 client/vcmi_client/nbproject/configurations.xml delete mode 100644 client/vcmi_client/nbproject/private/configurations.xml delete mode 100644 client/vcmi_client/nbproject/private/private.properties delete mode 100644 client/vcmi_client/nbproject/private/private.xml delete mode 100644 client/vcmi_client/nbproject/project.properties delete mode 100644 client/vcmi_client/nbproject/project.xml rename lib/{StopWatch.h => CStopWatch.h} (91%) rename lib/{SHexField.cpp => SBattleHex.cpp} (71%) rename lib/{SHexField.h => SBattleHex.h} (71%) delete mode 100644 lib/VCMI_lib.cbp delete mode 100644 lib/vcmi_lib/Makefile-nb delete mode 100644 lib/vcmi_lib/nbproject/Makefile-Debug.mk delete mode 100644 lib/vcmi_lib/nbproject/Makefile-Release.mk delete mode 100644 lib/vcmi_lib/nbproject/Makefile-impl.mk delete mode 100644 lib/vcmi_lib/nbproject/Package-Debug.bash delete mode 100644 lib/vcmi_lib/nbproject/Package-Release.bash delete mode 100644 lib/vcmi_lib/nbproject/configurations.xml delete mode 100644 lib/vcmi_lib/nbproject/project.properties delete mode 100644 lib/vcmi_lib/nbproject/project.xml delete mode 100644 server/VCMI_server.cbp delete mode 100644 server/vcmi_server/Makefile delete mode 100644 server/vcmi_server/nbproject/Makefile-Debug.mk delete mode 100644 server/vcmi_server/nbproject/Makefile-Release.mk delete mode 100644 server/vcmi_server/nbproject/Makefile-impl.mk delete mode 100644 server/vcmi_server/nbproject/Package-Debug.bash delete mode 100644 server/vcmi_server/nbproject/Package-Release.bash delete mode 100644 server/vcmi_server/nbproject/configurations.xml delete mode 100644 server/vcmi_server/nbproject/project.properties delete mode 100644 server/vcmi_server/nbproject/project.xml delete mode 100644 vcmi.workspace diff --git a/AI/EmptyAI/StdInc.h b/AI/EmptyAI/StdInc.h index 5c3d9f243..81a6cb308 100644 --- a/AI/EmptyAI/StdInc.h +++ b/AI/EmptyAI/StdInc.h @@ -1,325 +1,7 @@ #pragma once -// Standard include file -// Should be treated as a precompiled header file in the compiler settings -// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio -// This file shouldn't be changed, except if there is a important header file which is missing. +#include "../../Global.h" -/* - * StdInc.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ +// This header should be treated as a pre compiled header file(PCH) in the compiler building settings. -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#include -#ifdef _WIN32 -#include -#else -#include "../../tchar_amigaos4.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -//filesystem version 3 causes problems (and it's default as of boost 1.46) -#define BOOST_FILESYSTEM_VERSION 2 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ANDROID -#include -#endif - -// Integral data types -typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) -typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) -typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) -typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) -typedef boost::int64_t si64; //signed int 64 bits (8 bytes) -typedef boost::int32_t si32; //signed int 32 bits (4 bytes) -typedef boost::int16_t si16; //signed int 16 bits (2 bytes) -typedef boost::int8_t si8; //signed int 8 bits (1 byte) - -// Import + Export macro declarations -#ifdef _WIN32 -#define DLL_EXPORT __declspec(dllexport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_EXPORT __attribute__ ((visibility("default"))) -#else -#define DLL_EXPORT -#endif -#endif - -#ifdef _WIN32 -#define DLL_IMPORT __declspec(dllimport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_IMPORT __attribute__ ((visibility("default"))) -#else -#define DLL_IMPORT -#endif -#endif - -#ifdef VCMI_DLL -#define DLL_LINKAGE DLL_EXPORT -#else -#define DLL_LINKAGE DLL_IMPORT -#endif - - -//a normal std::map with a const operator[] for sanity -template -class bmap : public std::map -{ -public: - const ValT & operator[](KeyT key) const - { - return find(key)->second; - } - ValT & operator[](KeyT key) - { - return static_cast &>(*this)[key]; - } - template void serialize(Handler &h, const int version) - { - h & static_cast &>(*this); - } -}; - -namespace vstd -{ - //returns true if container c contains item i - template - bool contains(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i) != c.end(); - } - - //returns true if map c contains item i - template - bool contains(const std::map & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if bmap c contains item i - template - bool contains(const bmap & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if unordered set c contains item i - template - bool contains(const boost::unordered_set & c, const Item &i) - { - return c.find(i)!=c.end(); - } - - //returns position of first element in vector c equal to s, if there is no such element, -1 is returned - template - int find_pos(const std::vector & c, const T2 &s) - { - for(size_t i=0; i < c.size(); ++i) - if(c[i] == s) - return i; - return -1; - } - - //Func(T1,T2) must say if these elements matches - template - int find_pos(const std::vector & c, const T2 &s, const Func &f) - { - for(size_t i=0; i < c.size(); ++i) - if(f(c[i],s)) - return i; - return -1; - } - - //returns iterator to the given element if present in container, end() if not - template - typename Container::iterator find(Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //returns const iterator to the given element if present in container, end() if not - template - typename Container::const_iterator find(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //removes element i from container c, returns false if c does not contain i - template - typename Container::size_type operator-=(Container &c, const Item &i) - { - typename Container::iterator itr = find(c,i); - if(itr == c.end()) - return false; - c.erase(itr); - return true; - } - - //assigns greater of (a, b) to a and returns maximum of (a, b) - template - t1 &amax(t1 &a, const t2 &b) - { - if(a >= b) - return a; - else - { - a = b; - return a; - } - } - - //assigns smaller of (a, b) to a and returns minimum of (a, b) - template - t1 &amin(t1 &a, const t2 &b) - { - if(a <= b) - return a; - else - { - a = b; - return a; - } - } - - //makes a to fit the range - template - t1 &abetween(t1 &a, const t2 &b, const t3 &c) - { - amax(a,b); - amin(a,c); - return a; - } - - //checks if a is between b and c - template - bool isbetween(const t1 &a, const t2 &b, const t3 &c) - { - return a > b && a < c; - } - - //checks if a is within b and c - template - bool iswithin(const t1 &a, const t2 &b, const t3 &c) - { - return a >= b && a <= c; - } - - template - struct assigner - { - public: - t1 &op1; - t2 op2; - assigner(t1 &a1, const t2 & a2) - :op1(a1), op2(a2) - {} - void operator()() - { - op1 = op2; - } - }; - - // Assigns value a2 to a1. The point of time of the real operation can be controlled - // with the () operator. - template - assigner assigno(t1 &a1, const t2 &a2) - { - return assigner(a1,a2); - } - - //deleted pointer and sets it to NULL - template - void clear_pointer(T* &ptr) - { - delete ptr; - ptr = NULL; - } -} -using vstd::operator-=; - -// can be used for counting arrays -template char (&_ArrayCountObj(const T (&)[N]))[N]; -#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) - -//for explicit overrides -#ifdef _MSC_VER -#define OVERRIDE override -#else -#define OVERRIDE //is there any working counterpart? -#endif - -//XXX pls dont - 'debug macros' are usually more trouble than it's worth -#define HANDLE_EXCEPTION \ - catch (const std::exception& e) { \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::exception * e) \ -{ \ - tlog1 << e->what()<< std::endl; \ - throw; \ -} \ - catch (const std::string& e) { \ - tlog1 << e << std::endl; \ - throw; \ -} - -#define HANDLE_EXCEPTIONC(COMMAND) \ - catch (const std::exception& e) { \ - COMMAND; \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::string &e) \ -{ \ - COMMAND; \ - tlog1 << e << std::endl; \ - throw; \ -} - - -#include "../../lib/CLogger.h" +// Here you can add specific libraries and macros which are specific to this project. \ No newline at end of file diff --git a/AI/GeniusAI/BattleLogic.cpp b/AI/GeniusAI/BattleLogic.cpp index 0579ae29e..3da277936 100644 --- a/AI/GeniusAI/BattleLogic.cpp +++ b/AI/GeniusAI/BattleLogic.cpp @@ -526,7 +526,7 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) } } - std::vector fields = m_cb->battleGetAvailableHexes(m_cb->battleGetStackByID(attackerID), false); + std::vector fields = m_cb->battleGetAvailableHexes(m_cb->battleGetStackByID(attackerID), false); if(fields.size() == 0) { @@ -540,11 +540,11 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) ba.destinationTile = static_cast(dest_tile); //simplified checking for possibility of attack (previous was too simplified) int destStackPos = m_cb->battleGetPos(destinationID); - if(SHexField::mutualPosition(dest_tile, destStackPos) != -1) + if(SBattleHex::mutualPosition(dest_tile, destStackPos) != -1) ba.additionalInfo = destStackPos; - else if(SHexField::mutualPosition(dest_tile, destStackPos+1) != -1) + else if(SBattleHex::mutualPosition(dest_tile, destStackPos+1) != -1) ba.additionalInfo = destStackPos+1; - else if(SHexField::mutualPosition(dest_tile, destStackPos-1) != -1) + else if(SBattleHex::mutualPosition(dest_tile, destStackPos-1) != -1) ba.additionalInfo = destStackPos-1; else return BattleAction::makeDefend(attackerStack); @@ -581,7 +581,7 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) } } - for (std::vector::const_iterator it = fields.begin(); it != fields.end(); ++it) + for (std::vector::const_iterator it = fields.begin(); it != fields.end(); ++it) { if (*it == dest_tile) { diff --git a/AI/GeniusAI/CGeniusAI.cpp b/AI/GeniusAI/CGeniusAI.cpp index de8d3551f..e15836b6f 100644 --- a/AI/GeniusAI/CGeniusAI.cpp +++ b/AI/GeniusAI/CGeniusAI.cpp @@ -1311,7 +1311,7 @@ void CGeniusAI::battleNewRound(int round) /** * */ -void CGeniusAI::battleStackMoved(int ID, std::vector dest, int distance) +void CGeniusAI::battleStackMoved(int ID, std::vector dest, int distance) { std::string message("\t\t\tCGeniusAI::battleStackMoved ID("); message += boost::lexical_cast(ID); @@ -1345,7 +1345,7 @@ void CGeniusAI::battleSpellCast(const BattleSpellCast *sc) * */ // void CGeniusAI::battleStackMoved(int ID, -// SHexField dest, +// SBattleHex dest, // bool startMoving, // bool endMoving) // { diff --git a/AI/GeniusAI/CGeniusAI.h b/AI/GeniusAI/CGeniusAI.h index 747ea024b..a5ebc7f2b 100644 --- a/AI/GeniusAI/CGeniusAI.h +++ b/AI/GeniusAI/CGeniusAI.h @@ -201,7 +201,7 @@ public: virtual void battleStacksAttacked(const std::set & bsa); //called when stack receives damage (after battleAttack()) virtual void battleEnd(const BattleResult *br); virtual void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackMoved(int ID, std::vector dest, int distance); + virtual void battleStackMoved(int ID, std::vector dest, int distance); virtual void battleSpellCast(const BattleSpellCast *sc); virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right //virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles); //called when battlefield is prepared, prior the battle beginning diff --git a/AI/GeniusAI/StdInc.h b/AI/GeniusAI/StdInc.h index 5c3d9f243..81a6cb308 100644 --- a/AI/GeniusAI/StdInc.h +++ b/AI/GeniusAI/StdInc.h @@ -1,325 +1,7 @@ #pragma once -// Standard include file -// Should be treated as a precompiled header file in the compiler settings -// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio -// This file shouldn't be changed, except if there is a important header file which is missing. +#include "../../Global.h" -/* - * StdInc.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ +// This header should be treated as a pre compiled header file(PCH) in the compiler building settings. -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#include -#ifdef _WIN32 -#include -#else -#include "../../tchar_amigaos4.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -//filesystem version 3 causes problems (and it's default as of boost 1.46) -#define BOOST_FILESYSTEM_VERSION 2 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ANDROID -#include -#endif - -// Integral data types -typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) -typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) -typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) -typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) -typedef boost::int64_t si64; //signed int 64 bits (8 bytes) -typedef boost::int32_t si32; //signed int 32 bits (4 bytes) -typedef boost::int16_t si16; //signed int 16 bits (2 bytes) -typedef boost::int8_t si8; //signed int 8 bits (1 byte) - -// Import + Export macro declarations -#ifdef _WIN32 -#define DLL_EXPORT __declspec(dllexport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_EXPORT __attribute__ ((visibility("default"))) -#else -#define DLL_EXPORT -#endif -#endif - -#ifdef _WIN32 -#define DLL_IMPORT __declspec(dllimport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_IMPORT __attribute__ ((visibility("default"))) -#else -#define DLL_IMPORT -#endif -#endif - -#ifdef VCMI_DLL -#define DLL_LINKAGE DLL_EXPORT -#else -#define DLL_LINKAGE DLL_IMPORT -#endif - - -//a normal std::map with a const operator[] for sanity -template -class bmap : public std::map -{ -public: - const ValT & operator[](KeyT key) const - { - return find(key)->second; - } - ValT & operator[](KeyT key) - { - return static_cast &>(*this)[key]; - } - template void serialize(Handler &h, const int version) - { - h & static_cast &>(*this); - } -}; - -namespace vstd -{ - //returns true if container c contains item i - template - bool contains(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i) != c.end(); - } - - //returns true if map c contains item i - template - bool contains(const std::map & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if bmap c contains item i - template - bool contains(const bmap & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if unordered set c contains item i - template - bool contains(const boost::unordered_set & c, const Item &i) - { - return c.find(i)!=c.end(); - } - - //returns position of first element in vector c equal to s, if there is no such element, -1 is returned - template - int find_pos(const std::vector & c, const T2 &s) - { - for(size_t i=0; i < c.size(); ++i) - if(c[i] == s) - return i; - return -1; - } - - //Func(T1,T2) must say if these elements matches - template - int find_pos(const std::vector & c, const T2 &s, const Func &f) - { - for(size_t i=0; i < c.size(); ++i) - if(f(c[i],s)) - return i; - return -1; - } - - //returns iterator to the given element if present in container, end() if not - template - typename Container::iterator find(Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //returns const iterator to the given element if present in container, end() if not - template - typename Container::const_iterator find(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //removes element i from container c, returns false if c does not contain i - template - typename Container::size_type operator-=(Container &c, const Item &i) - { - typename Container::iterator itr = find(c,i); - if(itr == c.end()) - return false; - c.erase(itr); - return true; - } - - //assigns greater of (a, b) to a and returns maximum of (a, b) - template - t1 &amax(t1 &a, const t2 &b) - { - if(a >= b) - return a; - else - { - a = b; - return a; - } - } - - //assigns smaller of (a, b) to a and returns minimum of (a, b) - template - t1 &amin(t1 &a, const t2 &b) - { - if(a <= b) - return a; - else - { - a = b; - return a; - } - } - - //makes a to fit the range - template - t1 &abetween(t1 &a, const t2 &b, const t3 &c) - { - amax(a,b); - amin(a,c); - return a; - } - - //checks if a is between b and c - template - bool isbetween(const t1 &a, const t2 &b, const t3 &c) - { - return a > b && a < c; - } - - //checks if a is within b and c - template - bool iswithin(const t1 &a, const t2 &b, const t3 &c) - { - return a >= b && a <= c; - } - - template - struct assigner - { - public: - t1 &op1; - t2 op2; - assigner(t1 &a1, const t2 & a2) - :op1(a1), op2(a2) - {} - void operator()() - { - op1 = op2; - } - }; - - // Assigns value a2 to a1. The point of time of the real operation can be controlled - // with the () operator. - template - assigner assigno(t1 &a1, const t2 &a2) - { - return assigner(a1,a2); - } - - //deleted pointer and sets it to NULL - template - void clear_pointer(T* &ptr) - { - delete ptr; - ptr = NULL; - } -} -using vstd::operator-=; - -// can be used for counting arrays -template char (&_ArrayCountObj(const T (&)[N]))[N]; -#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) - -//for explicit overrides -#ifdef _MSC_VER -#define OVERRIDE override -#else -#define OVERRIDE //is there any working counterpart? -#endif - -//XXX pls dont - 'debug macros' are usually more trouble than it's worth -#define HANDLE_EXCEPTION \ - catch (const std::exception& e) { \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::exception * e) \ -{ \ - tlog1 << e->what()<< std::endl; \ - throw; \ -} \ - catch (const std::string& e) { \ - tlog1 << e << std::endl; \ - throw; \ -} - -#define HANDLE_EXCEPTIONC(COMMAND) \ - catch (const std::exception& e) { \ - COMMAND; \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::string &e) \ -{ \ - COMMAND; \ - tlog1 << e << std::endl; \ - throw; \ -} - - -#include "../../lib/CLogger.h" +// Here you can add specific libraries and macros which are specific to this project. \ No newline at end of file diff --git a/AI/GeniusAI/bouml/GeniusAI/129161 b/AI/GeniusAI/bouml/GeniusAI/129161 deleted file mode 100644 index 34e04bdf5..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/129161 +++ /dev/null @@ -1,107 +0,0 @@ -format 66 -"Battle AI" // Battle AI - revision 1 - modified_by 9 "rrowniak" - // class settings - //class diagram settings - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - //use case diagram settings - package_name_in_tab default show_context default auto_label_position default draw_all_relations default class_drawing_mode default shadow default show_stereotype_properties default - //sequence diagram settings - show_full_operations_definition default write_horizontally default class_drawing_mode default drawing_language default draw_all_relations default shadow default show_stereotype_properties default - //collaboration diagram settings - show_full_operations_definition default show_hierarchical_rank default write_horizontally default drawing_language default package_name_in_tab default show_context default draw_all_relations default shadow default show_stereotype_properties default - //object diagram settings - write_horizontally default package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default show_stereotype_properties default - //component diagram settings - package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default - draw_component_as_icon default show_component_req_prov default show_component_rea default show_stereotype_properties default - //deployment diagram settings - package_name_in_tab default show_context default write_horizontally default auto_label_position default draw_all_relations default shadow default - draw_component_as_icon default show_component_req_prov default show_component_rea default show_stereotype_properties default - //state diagram settings - package_name_in_tab default show_context default auto_label_position default write_trans_label_horizontally default show_trans_definition default draw_all_relations default shadow default - show_activities default region_horizontally default drawing_language default show_stereotype_properties default - //activity diagram settings - package_name_in_tab default show_context default show_opaque_action_definition default auto_label_position default write_flow_label_horizontally default draw_all_relations default shadow default - show_infonote default drawing_language default show_stereotype_properties default - - classview 129161 "Diagrams" - //class diagram settings - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - //collaboration diagram settings - show_full_operations_definition default show_hierarchical_rank default write_horizontally default drawing_language default package_name_in_tab default show_context default draw_all_relations default shadow default show_stereotype_properties default - //object diagram settings - write_horizontally default package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default show_stereotype_properties default - //sequence diagram settings - show_full_operations_definition default write_horizontally default class_drawing_mode default drawing_language default draw_all_relations default shadow default show_stereotype_properties default - //state diagram settings - package_name_in_tab default show_context default auto_label_position default write_trans_label_horizontally default show_trans_definition default draw_all_relations default shadow default - show_activities default region_horizontally default drawing_language default show_stereotype_properties default - //class settings - //activity diagram settings - package_name_in_tab default show_context default show_opaque_action_definition default auto_label_position default write_flow_label_horizontally default draw_all_relations default shadow default - show_infonote default drawing_language default show_stereotype_properties default - classdiagram 129161 "Structure - class diagram" - draw_all_relations no hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - size A4 - end - end - - classview 129417 "Class view" - //class diagram settings - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - //collaboration diagram settings - show_full_operations_definition default show_hierarchical_rank default write_horizontally default drawing_language default package_name_in_tab default show_context default draw_all_relations default shadow default show_stereotype_properties default - //object diagram settings - write_horizontally default package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default show_stereotype_properties default - //sequence diagram settings - show_full_operations_definition default write_horizontally default class_drawing_mode default drawing_language default draw_all_relations default shadow default show_stereotype_properties default - //state diagram settings - package_name_in_tab default show_context default auto_label_position default write_trans_label_horizontally default show_trans_definition default draw_all_relations default shadow default - show_activities default region_horizontally default drawing_language default show_stereotype_properties default - //class settings - //activity diagram settings - package_name_in_tab default show_context default show_opaque_action_definition default auto_label_position default write_flow_label_horizontally default draw_all_relations default shadow default - show_infonote default drawing_language default show_stereotype_properties default - class 129417 "CBattleLogic" - visibility package - cpp_decl "" - java_decl "" - php_decl "" - python_2_2 python_decl "" - idl_decl "" - explicit_switch_type "" - - classrelation 130057 // - relation 129673 *--- - a role_name "" private - classrelation_ref 130057 // - b role_name "" private - classrelation_ref 130185 // - end - - classrelation 130441 // - relation_ref 129801 // - end - end - - class 129545 "CBattleHelper" - visibility package - cpp_decl "" - java_decl "" - php_decl "" - python_2_2 python_decl "" - idl_decl "" - explicit_switch_type "" - - classrelation 130313 // - relation 129801 *--- - a role_name "" private - classrelation_ref 130313 // - b role_name "" private - classrelation_ref 130441 // - end - end - end -end diff --git a/AI/GeniusAI/bouml/GeniusAI/129161.diagram b/AI/GeniusAI/bouml/GeniusAI/129161.diagram deleted file mode 100644 index 5748fa68d..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/129161.diagram +++ /dev/null @@ -1,34 +0,0 @@ -format 66 - -classcanvas 128009 class_ref 129289 // CGlobalAI - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - xyz 119 38 2000 -end -classcanvas 128137 class_ref 129161 // CGeniusAI - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - xyz 123 153 2000 -end -classcanvas 128905 class_ref 129417 // CBattleLogic - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - xyz 279 152 2000 -end -classcanvas 129033 class_ref 129545 // CBattleHelper - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - xyz 435 153 2000 -end -relationcanvas 128265 relation_ref 129161 // - from ref 128137 z 2001 to ref 128009 - no_role_a no_role_b - no_multiplicity_a no_multiplicity_b -end -relationcanvas 129161 relation_ref 129673 // - from ref 128905 z 2001 to ref 128137 - no_role_a no_role_b - no_multiplicity_a no_multiplicity_b -end -relationcanvas 129289 relation_ref 129801 // - from ref 129033 z 2001 to ref 128905 - no_role_a no_role_b - no_multiplicity_a no_multiplicity_b -end -end diff --git a/AI/GeniusAI/bouml/GeniusAI/129289 b/AI/GeniusAI/bouml/GeniusAI/129289 deleted file mode 100644 index 09f002177..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/129289 +++ /dev/null @@ -1,106 +0,0 @@ -format 66 -"General AI" // General AI - revision 1 - modified_by 9 "rrowniak" - // class settings - //class diagram settings - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - //use case diagram settings - package_name_in_tab default show_context default auto_label_position default draw_all_relations default class_drawing_mode default shadow default show_stereotype_properties default - //sequence diagram settings - show_full_operations_definition default write_horizontally default class_drawing_mode default drawing_language default draw_all_relations default shadow default show_stereotype_properties default - //collaboration diagram settings - show_full_operations_definition default show_hierarchical_rank default write_horizontally default drawing_language default package_name_in_tab default show_context default draw_all_relations default shadow default show_stereotype_properties default - //object diagram settings - write_horizontally default package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default show_stereotype_properties default - //component diagram settings - package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default - draw_component_as_icon default show_component_req_prov default show_component_rea default show_stereotype_properties default - //deployment diagram settings - package_name_in_tab default show_context default write_horizontally default auto_label_position default draw_all_relations default shadow default - draw_component_as_icon default show_component_req_prov default show_component_rea default show_stereotype_properties default - //state diagram settings - package_name_in_tab default show_context default auto_label_position default write_trans_label_horizontally default show_trans_definition default draw_all_relations default shadow default - show_activities default region_horizontally default drawing_language default show_stereotype_properties default - //activity diagram settings - package_name_in_tab default show_context default show_opaque_action_definition default auto_label_position default write_flow_label_horizontally default draw_all_relations default shadow default - show_infonote default drawing_language default show_stereotype_properties default - - classview 129289 "Diagrams" - //class diagram settings - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - //collaboration diagram settings - show_full_operations_definition default show_hierarchical_rank default write_horizontally default drawing_language default package_name_in_tab default show_context default draw_all_relations default shadow default show_stereotype_properties default - //object diagram settings - write_horizontally default package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default show_stereotype_properties default - //sequence diagram settings - show_full_operations_definition default write_horizontally default class_drawing_mode default drawing_language default draw_all_relations default shadow default show_stereotype_properties default - //state diagram settings - package_name_in_tab default show_context default auto_label_position default write_trans_label_horizontally default show_trans_definition default draw_all_relations default shadow default - show_activities default region_horizontally default drawing_language default show_stereotype_properties default - //class settings - //activity diagram settings - package_name_in_tab default show_context default show_opaque_action_definition default auto_label_position default write_flow_label_horizontally default draw_all_relations default shadow default - show_infonote default drawing_language default show_stereotype_properties default - classdiagram 129289 "Structure - clas diagram" - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - size A4 - end - end - - classview 129545 "Class view" - //class diagram settings - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - //collaboration diagram settings - show_full_operations_definition default show_hierarchical_rank default write_horizontally default drawing_language default package_name_in_tab default show_context default draw_all_relations default shadow default show_stereotype_properties default - //object diagram settings - write_horizontally default package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default show_stereotype_properties default - //sequence diagram settings - show_full_operations_definition default write_horizontally default class_drawing_mode default drawing_language default draw_all_relations default shadow default show_stereotype_properties default - //state diagram settings - package_name_in_tab default show_context default auto_label_position default write_trans_label_horizontally default show_trans_definition default draw_all_relations default shadow default - show_activities default region_horizontally default drawing_language default show_stereotype_properties default - //class settings - //activity diagram settings - package_name_in_tab default show_context default show_opaque_action_definition default auto_label_position default write_flow_label_horizontally default draw_all_relations default shadow default - show_infonote default drawing_language default show_stereotype_properties default - class 129673 "CGeneralAI" - visibility package - cpp_decl "" - java_decl "" - php_decl "" - python_2_2 python_decl "" - idl_decl "" - explicit_switch_type "" - - classrelation 129801 // - relation 129545 *--- - a role_name "" private - classrelation_ref 129801 // - b role_name "" private - classrelation_ref 129929 // - end - end - end - - usecaseview 129161 "Use case diagrams" - //use case diagram settings - package_name_in_tab default show_context default auto_label_position default draw_all_relations default class_drawing_mode default shadow default show_stereotype_properties default - //sequence diagram settings - show_full_operations_definition default write_horizontally default class_drawing_mode default drawing_language default draw_all_relations default shadow default show_stereotype_properties default - //collaboration diagram settings - show_full_operations_definition default show_hierarchical_rank default write_horizontally default drawing_language default package_name_in_tab default show_context default draw_all_relations default shadow default show_stereotype_properties default - //object diagram settings - write_horizontally default package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default show_stereotype_properties default - //state diagram settings - package_name_in_tab default show_context default auto_label_position default write_trans_label_horizontally default show_trans_definition default draw_all_relations default shadow default - show_activities default region_horizontally default drawing_language default show_stereotype_properties default - //activity diagram settings - package_name_in_tab default show_context default show_opaque_action_definition default auto_label_position default write_flow_label_horizontally default draw_all_relations default shadow default - show_infonote default drawing_language default show_stereotype_properties default - usecasediagram 129417 "Main requirements" - package_name_in_tab default show_context default auto_label_position default draw_all_relations default class_drawing_mode default shadow default show_stereotype_properties default - size A4 - end - end -end diff --git a/AI/GeniusAI/bouml/GeniusAI/129289.diagram b/AI/GeniusAI/bouml/GeniusAI/129289.diagram deleted file mode 100644 index 5263641d3..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/129289.diagram +++ /dev/null @@ -1,25 +0,0 @@ -format 66 - -classcanvas 128009 class_ref 129161 // CGeniusAI - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - xyz 102 100 2000 -end -classcanvas 128137 class_ref 129289 // CGlobalAI - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - xyz 102 15 2006 -end -classcanvas 128393 class_ref 129673 // CGeneralAI - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - xyz 281 100 2006 -end -relationcanvas 128265 relation_ref 129161 // - from ref 128009 z 2001 to ref 128137 - no_role_a no_role_b - no_multiplicity_a no_multiplicity_b -end -relationcanvas 128521 relation_ref 129545 // - from ref 128393 z 2001 to ref 128009 - no_role_a no_role_b - no_multiplicity_a no_multiplicity_b -end -end diff --git a/AI/GeniusAI/bouml/GeniusAI/129417 b/AI/GeniusAI/bouml/GeniusAI/129417 deleted file mode 100644 index 8293aa7d1..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/129417 +++ /dev/null @@ -1,87 +0,0 @@ -format 66 -"Common" // Common - revision 1 - modified_by 9 "rrowniak" - // class settings - //class diagram settings - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - //use case diagram settings - package_name_in_tab default show_context default auto_label_position default draw_all_relations default class_drawing_mode default shadow default show_stereotype_properties default - //sequence diagram settings - show_full_operations_definition default write_horizontally default class_drawing_mode default drawing_language default draw_all_relations default shadow default show_stereotype_properties default - //collaboration diagram settings - show_full_operations_definition default show_hierarchical_rank default write_horizontally default drawing_language default package_name_in_tab default show_context default draw_all_relations default shadow default show_stereotype_properties default - //object diagram settings - write_horizontally default package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default show_stereotype_properties default - //component diagram settings - package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default - draw_component_as_icon default show_component_req_prov default show_component_rea default show_stereotype_properties default - //deployment diagram settings - package_name_in_tab default show_context default write_horizontally default auto_label_position default draw_all_relations default shadow default - draw_component_as_icon default show_component_req_prov default show_component_rea default show_stereotype_properties default - //state diagram settings - package_name_in_tab default show_context default auto_label_position default write_trans_label_horizontally default show_trans_definition default draw_all_relations default shadow default - show_activities default region_horizontally default drawing_language default show_stereotype_properties default - //activity diagram settings - package_name_in_tab default show_context default show_opaque_action_definition default auto_label_position default write_flow_label_horizontally default draw_all_relations default shadow default - show_infonote default drawing_language default show_stereotype_properties default - - classview 129673 "Class view" - //class diagram settings - draw_all_relations default hide_attributes default hide_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_infonote default shadow default show_stereotype_properties default - //collaboration diagram settings - show_full_operations_definition default show_hierarchical_rank default write_horizontally default drawing_language default package_name_in_tab default show_context default draw_all_relations default shadow default show_stereotype_properties default - //object diagram settings - write_horizontally default package_name_in_tab default show_context default auto_label_position default draw_all_relations default shadow default show_stereotype_properties default - //sequence diagram settings - show_full_operations_definition default write_horizontally default class_drawing_mode default drawing_language default draw_all_relations default shadow default show_stereotype_properties default - //state diagram settings - package_name_in_tab default show_context default auto_label_position default write_trans_label_horizontally default show_trans_definition default draw_all_relations default shadow default - show_activities default region_horizontally default drawing_language default show_stereotype_properties default - //class settings - //activity diagram settings - package_name_in_tab default show_context default show_opaque_action_definition default auto_label_position default write_flow_label_horizontally default draw_all_relations default shadow default - show_infonote default drawing_language default show_stereotype_properties default - class 129161 "CGeniusAI" - visibility package - cpp_decl "" - java_decl "" - php_decl "" - python_2_2 python_decl "" - idl_decl "" - explicit_switch_type "" - - classrelation 129161 // - relation 129161 -_-|> - a public - classrelation_ref 129161 // - b parent class_ref 129289 // CGlobalAI - end - - classrelation 129929 // - relation_ref 129545 // - end - - classrelation 130185 // - relation_ref 129673 // - end - end - - class 129289 "CGlobalAI" - abstract visibility package stereotype "interface" - cpp_decl "" - java_decl "${comment}${@}${visibility}interface ${name}${extends} { -${members}} -" - php_decl "${comment}${visibility}interface ${name} { -${members}} -" - python_2_2 python_decl "" - idl_decl "${comment}${abstract}${local}interface ${name}${inherit} { -${members}}; -" - explicit_switch_type "" - - end - end -end diff --git a/AI/GeniusAI/bouml/GeniusAI/129417.diagram b/AI/GeniusAI/bouml/GeniusAI/129417.diagram deleted file mode 100644 index 789feb175..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/129417.diagram +++ /dev/null @@ -1,3 +0,0 @@ -format 66 - -end diff --git a/AI/GeniusAI/bouml/GeniusAI/GeniusAI.prj b/AI/GeniusAI/bouml/GeniusAI/GeniusAI.prj deleted file mode 100644 index d1053e5be..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/GeniusAI.prj +++ /dev/null @@ -1,46 +0,0 @@ -format 66 -"GeniusAI" - revision 2 - modified_by 9 "rrowniak" - - - - // class settings - default_attribute_visibility private default_relation_visibility private default_operation_visibility public - //class diagram settings - draw_all_relations yes hide_attributes no hide_operations no show_members_full_definition no show_members_visibility no show_members_stereotype no show_members_multiplicity no show_members_initialization no show_attribute_modifiers no member_max_width 127 show_parameter_dir yes show_parameter_name yes package_name_in_tab no class_drawing_mode natural drawing_language uml show_context_mode no auto_label_position yes show_relation_modifiers no show_infonote no shadow yes show_stereotype_properties no - //use case diagram settings - package_name_in_tab no show_context no auto_label_position yes draw_all_relations yes class_drawing_mode actor shadow yes show_stereotype_properties no - //sequence diagram settings - show_full_operations_definition no write_horizontally yes class_drawing_mode natural drawing_language uml draw_all_relations yes shadow yes show_stereotype_properties no - //collaboration diagram settings - show_full_operations_definition no show_hierarchical_rank no write_horizontally yes drawing_language uml package_name_in_tab no show_context no draw_all_relations yes shadow yes show_stereotype_properties no - //object diagram settings - write_horizontally yes package_name_in_tab no show_context no auto_label_position yes draw_all_relations yes shadow yes show_stereotype_properties no - //component diagram settings - package_name_in_tab no show_context no auto_label_position yes draw_all_relations yes shadow yes - draw_component_as_icon no show_component_req_prov no show_component_rea no show_stereotype_properties no - //deployment diagram settings - package_name_in_tab no show_context no write_horizontally yes auto_label_position yes draw_all_relations yes shadow yes - draw_component_as_icon no show_component_req_prov no show_component_rea no show_stereotype_properties no - //state diagram settings - package_name_in_tab no show_context no auto_label_position yes write_trans_label_horizontally yes show_trans_definition no draw_all_relations yes shadow yes - show_activities yes region_horizontally yes drawing_language uml show_stereotype_properties no - //activity diagram settings - package_name_in_tab no show_context no show_opaque_action_definition no auto_label_position yes write_flow_label_horizontally no draw_all_relations yes shadow yes - show_infonote yes drawing_language uml show_stereotype_properties no - - class_color yellow duration_color transparent continuation_color gray note_color blue fragment_color transparent subject_color transparent usecase_color yellow package_color transparent component_color green artifact_color green deploymentnode_color gray state_color yellow stateaction_color transparent activity_color transparent activityregion_color transparent activitypartition_color transparent activityaction_color transparent parameterpin_color white - font_size 8 - diagram_format A4 - - mark_for_import - - ncouples 1 - key "check-in-cmd" value "specify the command containing %file and %dir or %dironly" - package_ref 129161 // Battle AI - - package_ref 129289 // General AI - - package_ref 129417 // Common -end diff --git a/AI/GeniusAI/bouml/GeniusAI/cpp_includes b/AI/GeniusAI/bouml/GeniusAI/cpp_includes deleted file mode 100644 index 531b86f76..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/cpp_includes +++ /dev/null @@ -1,13 +0,0 @@ -// "a type" "needed cpp_includes" -"vector" "#include -using namespace std;" - -"list" "#include -using namespace std;" - -"map" "#include -using namespace std;" - -"string" "#include -using namespace std;" - diff --git a/AI/GeniusAI/bouml/GeniusAI/generation_settings b/AI/GeniusAI/bouml/GeniusAI/generation_settings deleted file mode 100644 index 1f32568c0..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/generation_settings +++ /dev/null @@ -1,309 +0,0 @@ - - - cpp_h_extension "h" cpp_src_extension "cpp" java_extension "java" php_extension "php" python_extension "py" idl_extension "idl" - - type_forms 15 // uml cpp java idl cpp_in cpp_out cpp_inout cpp_return - "void" "void" "void" "void" "${type}" "${type} &" "${type}" "${type}" - "any" "void *" "Object" "any" "const ${type}" "${type}" "${type} &" "${type}" - "bool" "bool" "boolean" "boolean" "${type}" "${type} &" "${type} &" "${type}" - "char" "char" "char" "char" "${type}" "${type} &" "${type} &" "${type}" - "uchar" "unsigned char" "char" "octet" "${type}" "${type} &" "${type} &" "${type}" - "byte" "unsigned char" "byte" "octet" "${type}" "${type} &" "${type} &" "${type}" - "short" "short" "short" "short" "${type}" "${type} &" "${type} &" "${type}" - "ushort" "unsigned short" "short" "unsigned short" "${type}" "${type} &" "${type} &" "${type}" - "int" "int" "int" "long" "${type}" "${type} &" "${type} &" "${type}" - "uint" "unsigned int" "int" "unsigned long" "${type}" "${type} &" "${type} &" "${type}" - "long" "long" "long" "long" "${type}" "${type} &" "${type} &" "${type}" - "ulong" "unsigned long" "long" "unsigned long" "${type}" "${type} &" "${type} &" "${type}" - "float" "float" "float" "float" "${type}" "${type} &" "${type} &" "${type}" - "double" "double" "double" "double" "${type}" "${type} &" "${type} &" "${type}" - "string" "string" "String" "string" "${type}" "${type} &" "${type} &" "${type}" - - relations_stereotypes 5 // uml cpp java pythonidl - "sequence" "vector" "Vector" "list" "sequence" - "vector" "vector" "Vector" "list" "sequence" - "list" "list" "List" "list" "sequence" - "set" "set" "Set" "set" "sequence" - "map" "map" "Map" "dict" "sequence" - - classes_stereotypes 14 // uml cpp java php python idl - "class" "class" "class" "class" "class" "valuetype" - "interface" "class" "interface" "interface" "class" "interface" - "exception" "class" "class" "class" "class" "exception" - "enum" "enum" "enum" "enum" "enum" "enum" - "enum_pattern" "enum" "enum_pattern" "enum" "enum" "enum" - "struct" "struct" "class" "class" "class" "struct" - "union" "union" "class" "class" "class" "union" - "typedef" "typedef" "ignored" "ignored" "ignored" "typedef" - "boundary" "class" "class" "class" "class" "interface" - "control" "class" "class" "class" "class" "valuetype" - "entity" "class" "class" "class" "class" "valuetype" - "actor" "ignored" "ignored" "ignored" "ignored" "ignored" - "@interface" "ignored" "@interface" "ignored" "ignored" "ignored" - "stereotype" "ignored" "ignored" "ignored" "ignored" "ignored" - - cpp_enum_default_type_forms "${type}" "${type} &" "${type} &" "${type}" // in out inout return - other_cpp_types_default_type_forms "const ${type} &" "${type} &" "${type} &" "${type}" // in out inout return - - cpp_default_h_content "#ifndef ${NAMESPACE}_${NAME}_H -#define ${NAMESPACE}_${NAME}_H - -${comment} -${includes} -${declarations} -${namespace_start} -${definition} -${namespace_end} -#endif -" - cpp_default_src_content "${comment} -${includes} -${namespace_start} -${members} -${namespace_end}" - cpp_default_class_decl "${comment}${template}class ${name}${inherit} { -${members}}; -${inlines} -" - cpp_default_external_class_decl "${name} -#include <${name}.h> -" - cpp_default_struct_decl "${comment}${template}struct ${name}${inherit} { -${members}}; -${inlines} -" - cpp_default_union_decl "${comment}${template}union ${name} { -${members}}; -${inlines} -" - cpp_default_enum_decl "${comment}enum ${name} { -${items} -}; -" - cpp_default_typedef_decl "${comment}typedef ${type} ${name}; -" - cpp_default_attribute_declaration " ${comment}${static}${mutable}${volatile}${const}${type} ${name}${value}; -" // multiplicity 1 - " ${comment}${static}${mutable}${volatile}${const}${stereotype}<${type}> ${name}${value}; -" // multiplicity * a..b - " ${comment}${static}${mutable}${volatile}${const}${type} ${name}${multiplicity}${value}; -" // multiplicity [..] - cpp_default_enum_item_declaration " ${name}${value},${comment}" - cpp_association_aggregation_declaration - " ${comment}${static}${mutable}${volatile}${const}${type} * ${name}${value}; -" // multiplicity 1 - " ${comment}${static}${mutable}${volatile}${const}${stereotype}<${type} *> ${name}${value}; -" // multiplicity * a..b - " ${comment}${static}${mutable}${volatile}${const}${type} * ${name}${multiplicity}${value}; -" // multiplicity [..] - cpp_aggregation_by_value_declaration - " ${comment}${static}${mutable}${volatile}${const}${type} ${name}${value}; -" // multiplicity 1 - " ${comment}${static}${mutable}${volatile}${const}${stereotype}<${type}> ${name}${value}; -" // multiplicity * a..b - " ${comment}${static}${mutable}${volatile}${const}${type} ${name}${multiplicity}${value}; -" // multiplicity [..] - cpp_get "get_${name}" inline const value_const public - cpp_set "set_${name}" public - cpp_default_operation_declaration " ${comment}${friend}${static}${inline}${virtual}${type} ${name}${(}${)}${const}${volatile}${throw}${abstract}; -" - cpp_default_operation_definition "${comment}${inline}${type} ${class}::${name}${(}${)}${const}${volatile}${throw}${staticnl}{ - ${body}} -" - java_default_src_content "${comment} -${package} -${imports} -${definition}" - java_default_class_decl "${comment}${@}${visibility}${final}${abstract}class ${name}${extends}${implements} { -${members}} -" - java_default_external_class_decl "${name}" - java_default_interface_decl "${comment}${@}${visibility}interface ${name}${extends} { -${members}} -" - java5_default_enum_decl "${comment}${@}${visibility}${final}${abstract}enum ${name}${implements} { -${items}; -${members}} -" - java_default_enum_decl "${comment}${@}${visibility}final class ${name} { -${members} - private final int value; - - public int value() { - return value; - } - - public static ${name} fromInt(int value) { - switch (value) { -${cases} default: throw new Error(); - } - - } - private ${name}(int v) { value = v; }; -} -" - java_default_attribute_declaration " ${comment}${@}${visibility}${static}${final}${transient}${volatile}${type} ${name}${value}; -" // multiplicity 1 - " ${comment}${@}${visibility}${static}${final}${transient}${volatile}${stereotype}<${type}> ${name}${value}; -" // multiplicity * a..b - " ${comment}${@}${visibility}${static}${final}${transient}${volatile}${type}${multiplicity} ${name}${value}; -" // multiplicity N - java5_default_enum_item_declaration " ${@}${name}${value},${comment}" - java_default_enum_item_declaration " ${comment}${@}public static final int _${name}${value}; -public static final ${class} ${name} = new ${class}(_${name}); -" - java_default_enum_case " case _${name}: return ${name}; -" - java_association_aggregation_declaration - " ${comment}${@}${visibility}${static}${final}${transient}${volatile}${type} ${name}${value}; -" // multiplicity 1 - " ${comment}${@}${visibility}${static}${final}${transient}${volatile}${stereotype}<${type}> ${name}${value}; -" // multiplicity * a..b - " ${comment}${@}${visibility}${static}${final}${transient}${volatile}${type}${multiplicity} ${name}${value}; -" // multiplicity N - java_get "get${Name}" final public - java_set "set${Name}" public - java_default_operation_definition " ${comment}${@}${visibility}${final}${static}${abstract}${synchronized}${type} ${name}${(}${)}${throws}${staticnl}{ - ${body}} -" - php_default_src_content " -" - php_default_class_decl "${comment}${final}${visibility}${abstract}class ${name}${extends}${implements} { -${members}} -" - php_default_enum_decl "${comment}${visibility}final class ${name} { -${items}} -" - php_default_external_class_decl "${name}" - php_default_interface_decl "${comment}${visibility}interface ${name} { -${members}} -" - php_default_attribute_declaration " ${comment}${visibility}${const}${static}${var}${name}${value}; -" - php_default_enum_item_decl " const ${name}${value};${comment} -" - php_default_relation_declaration" ${comment}${visibility}${const}${static}${var}${name}${value}; -" - php_get "get${Name}" final - php_set "set${Name}" - php_default_operation_definition " ${comment}${final}${visibility}${abstract}${static}function ${name}${(}${)} -{ - ${body}} -" - python_2_2 - python_indent_step " " - python_default_src_content "${comment} -${import} -${definition}" - python_default_class_decl "class ${name}${inherit}: -${docstring}${members} -" - python_default_enum_decl "class ${name}: -${docstring}${members} -" - python_default_external_class_decl "${name}" - python_default_attribute_declaration "${comment}${self}${name} = ${value} -" // multiplicity 1 - "${comment}${self}${name} = ${stereotype}() -" // multiplicity != 1 - python_default_enum_item_decl "${comment}${self}${name} = ${value} -" - python_default_relation_declaration"${comment}${self}${name} = ${value} -" // multiplicity 1 - "${comment}${self}${name} = ${stereotype}() -" // multiplicity != 1 - python_default_composition_declaration"${comment}${self}${name} = ${type}() -" // multiplicity 1 - "${comment}${self}${name} = ${stereotype}() -" // multiplicity != 1 - python_default_operation_definition "${@}${static}${abstract}def ${name}${(}${)}: -${docstring}${body} -" - python_default_initoperation_definition "${@}${static}${abstract}def ${name}${(}${p0}${v0}${)}: -${docstring}super(${class}, ${p0}).__init__() -${body} -" - python_get "get${Name}" - python_set "set${Name}" - idl_default_src_content "#ifndef ${MODULE}_${NAME}_H -#define ${MODULE}_${NAME}_H - -${comment} -${includes} -${module_start} -${definition} -${module_end} -#endif -" - idl_default_interface_decl "${comment}${abstract}${local}interface ${name}${inherit} { -${members}}; -" - idl_default_valuetype_decl "${comment}${abstract}${custom}valuetype ${name}${inherit} { -${members}}; -" - idl_default_struct_decl "${comment}struct ${name} { -${members}}; -" - idl_default_typedef_decl "${comment}typedef ${type} ${name}; -" - idl_default_exception_decl "${comment}exception ${name} { -${members}}; -" - idl_default_union_decl "${comment}union ${name} switch(${switch}) { -${members}}; -" - idl_default_enum_decl "${comment}enum ${name} { -${items}}; -" - idl_default_external_class_decl "${name} -#include \"${name}.idl\" -" - idl_default_attribute_declaration " ${comment}${readonly}${attribute}${type} ${name}; -" // multiplicity 1 - " ${comment}${readonly}${attribute}${stereotype}<${type}> ${name}; -" // multiplicity * a..b - " ${comment}${readonly}${attribute}${stereotype}<${type},${multiplicity}> ${name}; -" // multiplicity N - idl_default_valuetype_attribute_declaration " ${comment}${visibility}${type} ${name}; -" // multiplicity 1 - " ${comment}${visibility}${stereotype}<${type}> ${name}; -" // multiplicity * a..b - " ${comment}${visibility}${stereotype}<${type},${multiplicity}> ${name}; -" // multiplicity N - idl_default_const_declaration " ${comment}const ${type} ${name}${value}; -" // multiplicity 1 - " ${comment}const ${stereotype}<${type}> ${name}${value}; -" // multiplicity * a..b - " ${comment}const ${stereotype}<${type},${multiplicity}> ${name}${value}; -" // multiplicity N - idl_default_enum_item_declaration " ${name},${comment}" - idl_default_union_item_declaration " ${comment}case ${case} : ${readonly}${type} ${name};" // multiplicity 1 - " ${comment}case ${case} : ${readonly}${stereotype}<${type}> ${name};" // multiplicity * a..b - " ${comment}case ${case} : ${readonly}${stereotype}<${type},${multiplicity}> ${name};" // multiplicity N - idl_association_aggregation_declaration - " ${comment}${readonly}${attribute}${type} ${name}; -" // multiplicity 1 - " ${comment}${readonly}${attribute}${stereotype}<${type}> ${name}; -" // multiplicity * a..b - " ${comment}${readonly}${attribute}${stereotype}<${type},${multiplicity}> ${name}; -" // multiplicity N - idl_valuetype_association_aggregation_declaration - " ${comment}${visibility}${type} ${name}; -" // multiplicity 1 - " ${comment}${visibility}${stereotype}<${type}> ${name}; -" // multiplicity * a..b - " ${comment}${visibility}${stereotype}<${type},${multiplicity}> ${name}; -" // multiplicity N - idl_union_association_aggregation_declaration - " ${comment}case ${case} : ${readonly}${type} ${name};" // multiplicity 1 - " ${comment}case ${case} : ${readonly}${stereotype}<${type}> ${name};" // multiplicity * a..b - " ${comment}case ${case} : ${readonly}${stereotype}<${type},${multiplicity}> ${name};" // multiplicity N - idl_get "get_${name}" - idl_set "set_${name}" twoways - idl_default_operation_declaration " ${comment}${oneway}${type} ${name}${(}${)}${raisesnl}${raises}; -" - uml_get_name uml uml_set_name uml -end diff --git a/AI/GeniusAI/bouml/GeniusAI/idl_includes b/AI/GeniusAI/bouml/GeniusAI/idl_includes deleted file mode 100644 index fceab64b9..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/idl_includes +++ /dev/null @@ -1 +0,0 @@ -// "a type" "needed idl_includes" diff --git a/AI/GeniusAI/bouml/GeniusAI/java_imports b/AI/GeniusAI/bouml/GeniusAI/java_imports deleted file mode 100644 index bbd370acb..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/java_imports +++ /dev/null @@ -1 +0,0 @@ -// "a type" "needed java_imports" diff --git a/AI/GeniusAI/bouml/GeniusAI/python_imports b/AI/GeniusAI/bouml/GeniusAI/python_imports deleted file mode 100644 index 4a1bd3a85..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/python_imports +++ /dev/null @@ -1 +0,0 @@ -// "a type" "needed python_imports" diff --git a/AI/GeniusAI/bouml/GeniusAI/stereotypes b/AI/GeniusAI/bouml/GeniusAI/stereotypes deleted file mode 100644 index 0ac476cf9..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/stereotypes +++ /dev/null @@ -1,58 +0,0 @@ - - package_stereotypes 6 "facade" "framework" "model library" "stub" "toplevel" "profile" - -_-> 3 "access" "import" "from" - end - - class_stereotypes 19 "actor" "auxiliary" "boundary" "control" "entity" "enum" "enum_pattern" "exception" "focus" "implementationClass" "interface" "@interface" "metaclass" "stereotype" "struct" "type" "typedef" "union" "utility" - ---- 4 "list" "set" "vector" "map" - ---> 4 "list" "set" "vector" "map" - ---|> 4 "{complete,disjoint}" "{incomplete,disjoint}" "{complete,overlapping}" "{incomplete,overlapping}" - o--- 4 "list" "set" "vector" "map" - *--- 4 "list" "set" "vector" "map" - o--> 4 "list" "set" "vector" "map" - *--> 4 "list" "set" "vector" "map" - -_-> 4 "friend" "from" "import" "instantiate" - -_-|> 1 "bind" - end - - use_case_stereotypes 1 "realization" - - ---|> 4 "{complete,disjoint}" "{incomplete,disjoint}" "{complete,overlapping}" "{incomplete,overlapping}" - -_-> 2 "include" "extend" - end - - artifact_stereotypes 7 "document" "file" "script" "source" "text" "library" "executable" - -_-> 4 "deploy" "manifest" "import" "from" - end - - attribute_stereotypes 4 "list" "set" "vector" "map" - operation_stereotypes 0 - state_stereotypes 3 "machine" "submachine" "top" - activity_stereotypes 0 - flow_stereotypes 3 "interrupt" "multicast" "multireceive" - interruptibleactivityregion_stereotypes 0 - pseudostate_stereotypes 0 - stateaction_stereotypes 2 "send-signal" "receive-signal" - parameter_stereotypes 0 - parameterset_stereotypes 0 - activitynode_stereotypes 0 - activityaction_stereotypes 0 - activityobject_stereotypes 2 "datastore" "centralBuffer" - expansionregion_stereotypes 0 - activitypartition_stereotypes 0 - pin_stereotypes 0 - component_stereotypes 6 "buildComponent" "entity" "implement" "process" "service" "subsystem" - deploymentnode_stereotypes 3 "cpu" "device" "executionEnvironment" - classview_stereotypes 0 - usecaseview_stereotypes 0 - componentview_stereotypes 0 - deploymentview_stereotypes 0 - classdiagram_stereotypes 0 - seqdiagram_stereotypes 0 - coldiagram_stereotypes 0 - usecasediagram_stereotypes 0 - statediagram_stereotypes 0 - activitydiagram_stereotypes 0 - componentdiagram_stereotypes 0 - deploymentdiagram_stereotypes 0 -end diff --git a/AI/GeniusAI/bouml/GeniusAI/tools b/AI/GeniusAI/bouml/GeniusAI/tools deleted file mode 100644 index 3579028be..000000000 --- a/AI/GeniusAI/bouml/GeniusAI/tools +++ /dev/null @@ -1,18 +0,0 @@ -// 'tool' "the executable" "displayed string" {target}+ -tool "HTML documentation" "ghtml" Class Operation Attribute Generalisation Realize Dependency Association DirectionalAssociation Aggregation AggregationByValue DirectionalAggregation DirectionalAggregationByValue ExtraMember ClassInstance State Region StateAction Initial EntryPoint Final Terminate ExitPoint DeepHistory ShallowHistory Junction Choice Fork Join Transition Activity InterruptibleActivityRegion ExpansionRegion ActivityObject ActivityAction Parameter ParameterSet Pin ExpansionNode InitialActivityNode FinalActivityNode ExitPointActivityNode DecisionActivityNode MergeActivityNode ForkActivityNode JoinActivityNode Flow Project Package UseCaseView ClassView ComponentView DeploymentView UseCaseDiagram SeqDiagram ColDiagram ClassDiagram ObjectDiagram StateDiagram ActivityDiagram ComponentDiagram DeploymentDiagram UseCase Component Node Artifact Inherit DependOn -tool "HTML doc. (flat)" "ghtml -flat" Class Operation Attribute Generalisation Realize Dependency Association DirectionalAssociation Aggregation AggregationByValue DirectionalAggregation DirectionalAggregationByValue ExtraMember ClassInstance State Region StateAction Initial EntryPoint Final Terminate ExitPoint DeepHistory ShallowHistory Junction Choice Fork Join Transition Activity InterruptibleActivityRegion ExpansionRegion ActivityObject ActivityAction Parameter ParameterSet Pin ExpansionNode InitialActivityNode FinalActivityNode ExitPointActivityNode DecisionActivityNode MergeActivityNode ForkActivityNode JoinActivityNode Flow Project Package UseCaseView ClassView ComponentView DeploymentView UseCaseDiagram SeqDiagram ColDiagram ClassDiagram ObjectDiagram StateDiagram ActivityDiagram ComponentDiagram DeploymentDiagram UseCase Component Node Artifact Inherit DependOn -tool "HTML doc. (svg)" "ghtml -svg" Class Operation Attribute Generalisation Realize Dependency Association DirectionalAssociation Aggregation AggregationByValue DirectionalAggregation DirectionalAggregationByValue ExtraMember ClassInstance State Region StateAction Initial EntryPoint Final Terminate ExitPoint DeepHistory ShallowHistory Junction Choice Fork Join Transition Activity InterruptibleActivityRegion ExpansionRegion ActivityObject ActivityAction Parameter ParameterSet Pin ExpansionNode InitialActivityNode FinalActivityNode ExitPointActivityNode DecisionActivityNode MergeActivityNode ForkActivityNode JoinActivityNode Flow Project Package UseCaseView ClassView ComponentView DeploymentView UseCaseDiagram SeqDiagram ColDiagram ClassDiagram ObjectDiagram StateDiagram ActivityDiagram ComponentDiagram DeploymentDiagram UseCase Component Node Artifact Inherit DependOn -tool "HTML doc. (flat, svg)" "ghtml -flat -svg" Class Operation Attribute Generalisation Realize Dependency Association DirectionalAssociation Aggregation AggregationByValue DirectionalAggregation DirectionalAggregationByValue ExtraMember ClassInstance State Region StateAction Initial EntryPoint Final Terminate ExitPoint DeepHistory ShallowHistory Junction Choice Fork Join Transition Activity InterruptibleActivityRegion ExpansionRegion ActivityObject ActivityAction Parameter ParameterSet Pin ExpansionNode InitialActivityNode FinalActivityNode ExitPointActivityNode DecisionActivityNode MergeActivityNode ForkActivityNode JoinActivityNode Flow Project Package UseCaseView ClassView ComponentView DeploymentView UseCaseDiagram SeqDiagram ColDiagram ClassDiagram ObjectDiagram StateDiagram ActivityDiagram ComponentDiagram DeploymentDiagram UseCase Component Node Artifact Inherit DependOn -tool "Generate .pro" "gpro" Artifact -tool "Import Rose" "irose" Project Package -tool "C++ utilities" "cpp_util" Class -tool "Generate XMI 1.2" "gxmi" Project -tool "Generate XMI 2.1" "gxmi2" Project -tool "Import XMI 2.1" "ixmi2" Project Package -tool "C++ state machine" "stmgen" State -tool "Use case wizard" "usecasewizard" UseCase -tool "Check-in" "file_control ci" Project Package -tool "Check-out" "file_control co" Project Package -tool "Deploy classes" "deplcl" ClassView -tool "Global Change" "global_change" Class Project Package ClassView DeploymentView -tool "Uml projection" "uml_proj" Class Operation Attribute Generalisation Realize Dependency Association DirectionalAssociation Aggregation AggregationByValue DirectionalAggregation DirectionalAggregationByValue Project Package ClassView diff --git a/AI/GeniusAI/genius.cbp b/AI/GeniusAI/genius.cbp deleted file mode 100644 index 792be6722..000000000 --- a/AI/GeniusAI/genius.cbp +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - diff --git a/AI/GeniusAI/genius.vcxproj b/AI/GeniusAI/genius.vcxproj index d05f272d7..b1ef241b5 100644 --- a/AI/GeniusAI/genius.vcxproj +++ b/AI/GeniusAI/genius.vcxproj @@ -231,6 +231,7 @@ + diff --git a/AI/StupidAI/StdInc.h b/AI/StupidAI/StdInc.h index 5c3d9f243..81a6cb308 100644 --- a/AI/StupidAI/StdInc.h +++ b/AI/StupidAI/StdInc.h @@ -1,325 +1,7 @@ #pragma once -// Standard include file -// Should be treated as a precompiled header file in the compiler settings -// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio -// This file shouldn't be changed, except if there is a important header file which is missing. +#include "../../Global.h" -/* - * StdInc.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ +// This header should be treated as a pre compiled header file(PCH) in the compiler building settings. -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#include -#ifdef _WIN32 -#include -#else -#include "../../tchar_amigaos4.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -//filesystem version 3 causes problems (and it's default as of boost 1.46) -#define BOOST_FILESYSTEM_VERSION 2 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ANDROID -#include -#endif - -// Integral data types -typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) -typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) -typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) -typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) -typedef boost::int64_t si64; //signed int 64 bits (8 bytes) -typedef boost::int32_t si32; //signed int 32 bits (4 bytes) -typedef boost::int16_t si16; //signed int 16 bits (2 bytes) -typedef boost::int8_t si8; //signed int 8 bits (1 byte) - -// Import + Export macro declarations -#ifdef _WIN32 -#define DLL_EXPORT __declspec(dllexport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_EXPORT __attribute__ ((visibility("default"))) -#else -#define DLL_EXPORT -#endif -#endif - -#ifdef _WIN32 -#define DLL_IMPORT __declspec(dllimport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_IMPORT __attribute__ ((visibility("default"))) -#else -#define DLL_IMPORT -#endif -#endif - -#ifdef VCMI_DLL -#define DLL_LINKAGE DLL_EXPORT -#else -#define DLL_LINKAGE DLL_IMPORT -#endif - - -//a normal std::map with a const operator[] for sanity -template -class bmap : public std::map -{ -public: - const ValT & operator[](KeyT key) const - { - return find(key)->second; - } - ValT & operator[](KeyT key) - { - return static_cast &>(*this)[key]; - } - template void serialize(Handler &h, const int version) - { - h & static_cast &>(*this); - } -}; - -namespace vstd -{ - //returns true if container c contains item i - template - bool contains(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i) != c.end(); - } - - //returns true if map c contains item i - template - bool contains(const std::map & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if bmap c contains item i - template - bool contains(const bmap & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if unordered set c contains item i - template - bool contains(const boost::unordered_set & c, const Item &i) - { - return c.find(i)!=c.end(); - } - - //returns position of first element in vector c equal to s, if there is no such element, -1 is returned - template - int find_pos(const std::vector & c, const T2 &s) - { - for(size_t i=0; i < c.size(); ++i) - if(c[i] == s) - return i; - return -1; - } - - //Func(T1,T2) must say if these elements matches - template - int find_pos(const std::vector & c, const T2 &s, const Func &f) - { - for(size_t i=0; i < c.size(); ++i) - if(f(c[i],s)) - return i; - return -1; - } - - //returns iterator to the given element if present in container, end() if not - template - typename Container::iterator find(Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //returns const iterator to the given element if present in container, end() if not - template - typename Container::const_iterator find(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //removes element i from container c, returns false if c does not contain i - template - typename Container::size_type operator-=(Container &c, const Item &i) - { - typename Container::iterator itr = find(c,i); - if(itr == c.end()) - return false; - c.erase(itr); - return true; - } - - //assigns greater of (a, b) to a and returns maximum of (a, b) - template - t1 &amax(t1 &a, const t2 &b) - { - if(a >= b) - return a; - else - { - a = b; - return a; - } - } - - //assigns smaller of (a, b) to a and returns minimum of (a, b) - template - t1 &amin(t1 &a, const t2 &b) - { - if(a <= b) - return a; - else - { - a = b; - return a; - } - } - - //makes a to fit the range - template - t1 &abetween(t1 &a, const t2 &b, const t3 &c) - { - amax(a,b); - amin(a,c); - return a; - } - - //checks if a is between b and c - template - bool isbetween(const t1 &a, const t2 &b, const t3 &c) - { - return a > b && a < c; - } - - //checks if a is within b and c - template - bool iswithin(const t1 &a, const t2 &b, const t3 &c) - { - return a >= b && a <= c; - } - - template - struct assigner - { - public: - t1 &op1; - t2 op2; - assigner(t1 &a1, const t2 & a2) - :op1(a1), op2(a2) - {} - void operator()() - { - op1 = op2; - } - }; - - // Assigns value a2 to a1. The point of time of the real operation can be controlled - // with the () operator. - template - assigner assigno(t1 &a1, const t2 &a2) - { - return assigner(a1,a2); - } - - //deleted pointer and sets it to NULL - template - void clear_pointer(T* &ptr) - { - delete ptr; - ptr = NULL; - } -} -using vstd::operator-=; - -// can be used for counting arrays -template char (&_ArrayCountObj(const T (&)[N]))[N]; -#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) - -//for explicit overrides -#ifdef _MSC_VER -#define OVERRIDE override -#else -#define OVERRIDE //is there any working counterpart? -#endif - -//XXX pls dont - 'debug macros' are usually more trouble than it's worth -#define HANDLE_EXCEPTION \ - catch (const std::exception& e) { \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::exception * e) \ -{ \ - tlog1 << e->what()<< std::endl; \ - throw; \ -} \ - catch (const std::string& e) { \ - tlog1 << e << std::endl; \ - throw; \ -} - -#define HANDLE_EXCEPTIONC(COMMAND) \ - catch (const std::exception& e) { \ - COMMAND; \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::string &e) \ -{ \ - COMMAND; \ - tlog1 << e << std::endl; \ - throw; \ -} - - -#include "../../lib/CLogger.h" +// Here you can add specific libraries and macros which are specific to this project. \ No newline at end of file diff --git a/AI/StupidAI/StupidAI.cpp b/AI/StupidAI/StupidAI.cpp index 59a1a0c70..21ba21e4f 100644 --- a/AI/StupidAI/StupidAI.cpp +++ b/AI/StupidAI/StupidAI.cpp @@ -39,7 +39,7 @@ struct EnemyInfo { const CStack * s; int adi, adr; - std::vector attackFrom; //for melee fight + std::vector attackFrom; //for melee fight EnemyInfo(const CStack * _s) : s(_s) {} void calcDmg(const CStack * ourStack) @@ -60,10 +60,10 @@ bool isMoreProfitable(const EnemyInfo &ei1, const EnemyInfo& ei2) return (ei1.adi-ei1.adr) < (ei2.adi - ei2.adr); } -int distToNearestNeighbour(SHexField hex, const std::vector & dists, SHexField *chosenHex = NULL) +int distToNearestNeighbour(SBattleHex hex, const std::vector & dists, SBattleHex *chosenHex = NULL) { int ret = 1000000; - BOOST_FOREACH(SHexField n, hex.neighbouringTiles()) + BOOST_FOREACH(SBattleHex n, hex.neighbouringTiles()) { if(dists[n] >= 0 && dists[n] < ret) { @@ -81,12 +81,12 @@ bool isCloser(const EnemyInfo & ei1, const EnemyInfo & ei2, const std::vectorposition, dists) < distToNearestNeighbour(ei2.s->position, dists); } -static bool willSecondHexBlockMoreEnemyShooters(const SHexField &h1, const SHexField &h2) +static bool willSecondHexBlockMoreEnemyShooters(const SBattleHex &h1, const SBattleHex &h2) { int shooters[2] = {0}; //count of shooters on hexes for(int i = 0; i < 2; i++) - BOOST_FOREACH(SHexField neighbour, (i ? h2 : h1).neighbouringTiles()) + BOOST_FOREACH(SBattleHex neighbour, (i ? h2 : h1).neighbouringTiles()) if(const CStack *s = cbc->battleGetStackByPos(neighbour)) if(s->getCreature()->isShooting()) shooters[i]++; @@ -98,7 +98,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack ) { //boost::this_thread::sleep(boost::posix_time::seconds(2)); print("activeStack called"); - std::vector avHexes = cb->battleGetAvailableHexes(stack, false); + std::vector avHexes = cb->battleGetAvailableHexes(stack, false); std::vector dists = cb->battleGetDistances(stack); std::vector enemiesShootable, enemiesReachable, enemiesUnreachable; @@ -110,7 +110,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack ) } else { - BOOST_FOREACH(SHexField hex, avHexes) + BOOST_FOREACH(SBattleHex hex, avHexes) { if(CStack::isMeleeAttackPossible(stack, s, hex)) { @@ -182,7 +182,7 @@ void CStupidAI::battleNewRound(int round) print("battleNewRound called"); } -void CStupidAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) +void CStupidAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) { print("battleStackMoved called");; } @@ -233,10 +233,10 @@ void CStupidAI::print(const std::string &text) const tlog0 << "CStupidAI [" << this <<"]: " << text << std::endl; } -BattleAction CStupidAI::goTowards(const CStack * stack, SHexField hex) +BattleAction CStupidAI::goTowards(const CStack * stack, SBattleHex hex) { - SHexField realDest = hex; - SHexField predecessors[GameConstants::BFIELD_SIZE]; + SBattleHex realDest = hex; + SBattleHex predecessors[GameConstants::BFIELD_SIZE]; std::vector dists = cb->battleGetDistances(stack, hex); if(distToNearestNeighbour(hex, dists, &realDest) > GameConstants::BFIELD_SIZE) { @@ -245,7 +245,7 @@ BattleAction CStupidAI::goTowards(const CStack * stack, SHexField hex) } dists = cb->battleGetDistances(stack, realDest, predecessors); - std::vector avHexes = cb->battleGetAvailableHexes(stack, false); + std::vector avHexes = cb->battleGetAvailableHexes(stack, false); if(!avHexes.size()) { diff --git a/AI/StupidAI/StupidAI.h b/AI/StupidAI/StupidAI.h index 663c399e9..909135adc 100644 --- a/AI/StupidAI/StupidAI.h +++ b/AI/StupidAI/StupidAI.h @@ -1,6 +1,6 @@ #pragma once -#include "../../lib/SHexField.h" +#include "../../lib/SBattleHex.h" class CStupidAI : public CBattleGameInterface { @@ -23,7 +23,7 @@ public: //void battleResultsApplied() OVERRIDE; //called when all effects of last battle are applied void battleNewRoundFirst(int round) OVERRIDE; //called at the beginning of each turn before changes are applied; void battleNewRound(int round) OVERRIDE; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; + void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; void battleSpellCast(const BattleSpellCast *sc) OVERRIDE; void battleStacksEffectsSet(const SetStackEffect & sse) OVERRIDE;//called when a specific effect is set to stacks //void battleTriggerEffect(const BattleTriggerEffect & bte) OVERRIDE; @@ -34,6 +34,6 @@ public: void battleCatapultAttacked(const CatapultAttack & ca) OVERRIDE; //called when catapult makes an attack void battleStacksRemoved(const BattleStacksRemoved & bsr) OVERRIDE; //called when certain stack is completely removed from battlefield - BattleAction goTowards(const CStack * stack, SHexField hex ); + BattleAction goTowards(const CStack * stack, SBattleHex hex ); }; diff --git a/AI/StupidAI/StupidAI.vcxproj b/AI/StupidAI/StupidAI.vcxproj index 7ff466078..9d5da3b9b 100644 --- a/AI/StupidAI/StupidAI.vcxproj +++ b/AI/StupidAI/StupidAI.vcxproj @@ -166,6 +166,7 @@ + diff --git a/Global.h b/Global.h new file mode 100644 index 000000000..911581a34 --- /dev/null +++ b/Global.h @@ -0,0 +1,330 @@ +#pragma once + +// Standard include file +// Contents: +// Includes C/C++ libraries, STL libraries, IOStream and String libraries +// Includes the most important boost headers +// Defines the import + export, override and exception handling macros +// Defines the vstd library +// Includes the logger + +// This file shouldn't be changed, except if there is a important header file missing which is shared among several projects. + +/* + * Global.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#ifdef _WIN32 +#include +#else +#include "tchar_amigaos4.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +//filesystem version 3 causes problems (and it's default as of boost 1.46) +#define BOOST_FILESYSTEM_VERSION 2 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef ANDROID +#include +#endif + +// Integral data types +typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) +typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) +typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) +typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) +typedef boost::int64_t si64; //signed int 64 bits (8 bytes) +typedef boost::int32_t si32; //signed int 32 bits (4 bytes) +typedef boost::int16_t si16; //signed int 16 bits (2 bytes) +typedef boost::int8_t si8; //signed int 8 bits (1 byte) + +// Import + Export macro declarations +#ifdef _WIN32 +#define DLL_EXPORT __declspec(dllexport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_EXPORT __attribute__ ((visibility("default"))) +#else +#define DLL_EXPORT +#endif +#endif + +#ifdef _WIN32 +#define DLL_IMPORT __declspec(dllimport) +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define DLL_IMPORT __attribute__ ((visibility("default"))) +#else +#define DLL_IMPORT +#endif +#endif + +#ifdef VCMI_DLL +#define DLL_LINKAGE DLL_EXPORT +#else +#define DLL_LINKAGE DLL_IMPORT +#endif + + +//a normal std::map with a const operator[] for sanity +template +class bmap : public std::map +{ +public: + const ValT & operator[](KeyT key) const + { + return find(key)->second; + } + ValT & operator[](KeyT key) + { + return static_cast &>(*this)[key]; + } + template void serialize(Handler &h, const int version) + { + h & static_cast &>(*this); + } +}; + +namespace vstd +{ + //returns true if container c contains item i + template + bool contains(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i) != c.end(); + } + + //returns true if map c contains item i + template + bool contains(const std::map & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if bmap c contains item i + template + bool contains(const bmap & c, const Item2 &i) + { + return c.find(i)!=c.end(); + } + + //returns true if unordered set c contains item i + template + bool contains(const boost::unordered_set & c, const Item &i) + { + return c.find(i)!=c.end(); + } + + //returns position of first element in vector c equal to s, if there is no such element, -1 is returned + template + int find_pos(const std::vector & c, const T2 &s) + { + for(size_t i=0; i < c.size(); ++i) + if(c[i] == s) + return i; + return -1; + } + + //Func(T1,T2) must say if these elements matches + template + int find_pos(const std::vector & c, const T2 &s, const Func &f) + { + for(size_t i=0; i < c.size(); ++i) + if(f(c[i],s)) + return i; + return -1; + } + + //returns iterator to the given element if present in container, end() if not + template + typename Container::iterator find(Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //returns const iterator to the given element if present in container, end() if not + template + typename Container::const_iterator find(const Container & c, const Item &i) + { + return std::find(c.begin(),c.end(),i); + } + + //removes element i from container c, returns false if c does not contain i + template + typename Container::size_type operator-=(Container &c, const Item &i) + { + typename Container::iterator itr = find(c,i); + if(itr == c.end()) + return false; + c.erase(itr); + return true; + } + + //assigns greater of (a, b) to a and returns maximum of (a, b) + template + t1 &amax(t1 &a, const t2 &b) + { + if(a >= b) + return a; + else + { + a = b; + return a; + } + } + + //assigns smaller of (a, b) to a and returns minimum of (a, b) + template + t1 &amin(t1 &a, const t2 &b) + { + if(a <= b) + return a; + else + { + a = b; + return a; + } + } + + //makes a to fit the range + template + t1 &abetween(t1 &a, const t2 &b, const t3 &c) + { + amax(a,b); + amin(a,c); + return a; + } + + //checks if a is between b and c + template + bool isbetween(const t1 &a, const t2 &b, const t3 &c) + { + return a > b && a < c; + } + + //checks if a is within b and c + template + bool iswithin(const t1 &a, const t2 &b, const t3 &c) + { + return a >= b && a <= c; + } + + template + struct assigner + { + public: + t1 &op1; + t2 op2; + assigner(t1 &a1, const t2 & a2) + :op1(a1), op2(a2) + {} + void operator()() + { + op1 = op2; + } + }; + + // Assigns value a2 to a1. The point of time of the real operation can be controlled + // with the () operator. + template + assigner assigno(t1 &a1, const t2 &a2) + { + return assigner(a1,a2); + } + + //deleted pointer and sets it to NULL + template + void clear_pointer(T* &ptr) + { + delete ptr; + ptr = NULL; + } +} +using vstd::operator-=; + +// can be used for counting arrays +template char (&_ArrayCountObj(const T (&)[N]))[N]; +#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) + +//for explicit overrides +#ifdef _MSC_VER +#define OVERRIDE override +#else +#define OVERRIDE //is there any working counterpart? +#endif + +//XXX pls dont - 'debug macros' are usually more trouble than it's worth +#define HANDLE_EXCEPTION \ + catch (const std::exception& e) { \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::exception * e) \ +{ \ + tlog1 << e->what()<< std::endl; \ + throw; \ +} \ + catch (const std::string& e) { \ + tlog1 << e << std::endl; \ + throw; \ +} + +#define HANDLE_EXCEPTIONC(COMMAND) \ + catch (const std::exception& e) { \ + COMMAND; \ + tlog1 << e.what() << std::endl; \ + throw; \ +} \ + catch (const std::string &e) \ +{ \ + COMMAND; \ + tlog1 << e << std::endl; \ + throw; \ +} + + +#include "lib/CLogger.h" diff --git a/Scripting/ERM/ERM.vcxproj b/Scripting/ERM/ERM.vcxproj index b3fa4a53b..b931aabea 100644 --- a/Scripting/ERM/ERM.vcxproj +++ b/Scripting/ERM/ERM.vcxproj @@ -129,6 +129,7 @@ + diff --git a/Scripting/ERM/ERMParser.cpp b/Scripting/ERM/ERMParser.cpp index 1526e3a17..e1d84fc2b 100644 --- a/Scripting/ERM/ERMParser.cpp +++ b/Scripting/ERM/ERMParser.cpp @@ -1,24 +1,11 @@ #include "StdInc.h" #include "ERMParser.h" -#include + //To make compilation with older boost versions possible //Don't know exact version - 1.46 works while 1.42 not #if BOOST_VERSION >= 104600 -#include -#include -#include -#include -#include -#include -#include - -namespace spirit = boost::spirit; -namespace qi = boost::spirit::qi; -namespace ascii = spirit::ascii; -namespace phoenix = boost::phoenix; - /* * ERMParser.cpp, part of VCMI engine * diff --git a/Scripting/ERM/ERMParser.h b/Scripting/ERM/ERMParser.h index cde879b44..6e303da85 100644 --- a/Scripting/ERM/ERMParser.h +++ b/Scripting/ERM/ERMParser.h @@ -1,10 +1,6 @@ #pragma once -#include -#include -#include - /* * ERMParser.h, part of VCMI engine * diff --git a/Scripting/ERM/StdInc.h b/Scripting/ERM/StdInc.h index 5c3d9f243..4990e0910 100644 --- a/Scripting/ERM/StdInc.h +++ b/Scripting/ERM/StdInc.h @@ -1,325 +1,23 @@ #pragma once -// Standard include file -// Should be treated as a precompiled header file in the compiler settings -// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio -// This file shouldn't be changed, except if there is a important header file which is missing. +#include "../../Global.h" -/* - * StdInc.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ +// This header should be treated as a pre compiled header file(PCH) in the compiler building settings. -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#include -#ifdef _WIN32 -#include -#else -#include "../../tchar_amigaos4.h" -#endif +// Here you can add specific libraries and macros which are specific to this project. +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -//filesystem version 3 causes problems (and it's default as of boost 1.46) -#define BOOST_FILESYSTEM_VERSION 2 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ANDROID -#include -#endif - -// Integral data types -typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) -typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) -typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) -typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) -typedef boost::int64_t si64; //signed int 64 bits (8 bytes) -typedef boost::int32_t si32; //signed int 32 bits (4 bytes) -typedef boost::int16_t si16; //signed int 16 bits (2 bytes) -typedef boost::int8_t si8; //signed int 8 bits (1 byte) - -// Import + Export macro declarations -#ifdef _WIN32 -#define DLL_EXPORT __declspec(dllexport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_EXPORT __attribute__ ((visibility("default"))) -#else -#define DLL_EXPORT -#endif -#endif - -#ifdef _WIN32 -#define DLL_IMPORT __declspec(dllimport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_IMPORT __attribute__ ((visibility("default"))) -#else -#define DLL_IMPORT -#endif -#endif - -#ifdef VCMI_DLL -#define DLL_LINKAGE DLL_EXPORT -#else -#define DLL_LINKAGE DLL_IMPORT -#endif - - -//a normal std::map with a const operator[] for sanity -template -class bmap : public std::map -{ -public: - const ValT & operator[](KeyT key) const - { - return find(key)->second; - } - ValT & operator[](KeyT key) - { - return static_cast &>(*this)[key]; - } - template void serialize(Handler &h, const int version) - { - h & static_cast &>(*this); - } -}; - -namespace vstd -{ - //returns true if container c contains item i - template - bool contains(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i) != c.end(); - } - - //returns true if map c contains item i - template - bool contains(const std::map & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if bmap c contains item i - template - bool contains(const bmap & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if unordered set c contains item i - template - bool contains(const boost::unordered_set & c, const Item &i) - { - return c.find(i)!=c.end(); - } - - //returns position of first element in vector c equal to s, if there is no such element, -1 is returned - template - int find_pos(const std::vector & c, const T2 &s) - { - for(size_t i=0; i < c.size(); ++i) - if(c[i] == s) - return i; - return -1; - } - - //Func(T1,T2) must say if these elements matches - template - int find_pos(const std::vector & c, const T2 &s, const Func &f) - { - for(size_t i=0; i < c.size(); ++i) - if(f(c[i],s)) - return i; - return -1; - } - - //returns iterator to the given element if present in container, end() if not - template - typename Container::iterator find(Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //returns const iterator to the given element if present in container, end() if not - template - typename Container::const_iterator find(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //removes element i from container c, returns false if c does not contain i - template - typename Container::size_type operator-=(Container &c, const Item &i) - { - typename Container::iterator itr = find(c,i); - if(itr == c.end()) - return false; - c.erase(itr); - return true; - } - - //assigns greater of (a, b) to a and returns maximum of (a, b) - template - t1 &amax(t1 &a, const t2 &b) - { - if(a >= b) - return a; - else - { - a = b; - return a; - } - } - - //assigns smaller of (a, b) to a and returns minimum of (a, b) - template - t1 &amin(t1 &a, const t2 &b) - { - if(a <= b) - return a; - else - { - a = b; - return a; - } - } - - //makes a to fit the range - template - t1 &abetween(t1 &a, const t2 &b, const t3 &c) - { - amax(a,b); - amin(a,c); - return a; - } - - //checks if a is between b and c - template - bool isbetween(const t1 &a, const t2 &b, const t3 &c) - { - return a > b && a < c; - } - - //checks if a is within b and c - template - bool iswithin(const t1 &a, const t2 &b, const t3 &c) - { - return a >= b && a <= c; - } - - template - struct assigner - { - public: - t1 &op1; - t2 op2; - assigner(t1 &a1, const t2 & a2) - :op1(a1), op2(a2) - {} - void operator()() - { - op1 = op2; - } - }; - - // Assigns value a2 to a1. The point of time of the real operation can be controlled - // with the () operator. - template - assigner assigno(t1 &a1, const t2 &a2) - { - return assigner(a1,a2); - } - - //deleted pointer and sets it to NULL - template - void clear_pointer(T* &ptr) - { - delete ptr; - ptr = NULL; - } -} -using vstd::operator-=; - -// can be used for counting arrays -template char (&_ArrayCountObj(const T (&)[N]))[N]; -#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) - -//for explicit overrides -#ifdef _MSC_VER -#define OVERRIDE override -#else -#define OVERRIDE //is there any working counterpart? -#endif - -//XXX pls dont - 'debug macros' are usually more trouble than it's worth -#define HANDLE_EXCEPTION \ - catch (const std::exception& e) { \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::exception * e) \ -{ \ - tlog1 << e->what()<< std::endl; \ - throw; \ -} \ - catch (const std::string& e) { \ - tlog1 << e << std::endl; \ - throw; \ -} - -#define HANDLE_EXCEPTIONC(COMMAND) \ - catch (const std::exception& e) { \ - COMMAND; \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::string &e) \ -{ \ - COMMAND; \ - tlog1 << e << std::endl; \ - throw; \ -} - - -#include "../../lib/CLogger.h" +namespace spirit = boost::spirit; +namespace qi = boost::spirit::qi; +namespace ascii = spirit::ascii; +namespace phoenix = boost::phoenix; diff --git a/client/AdventureMapButton.cpp b/client/AdventureMapButton.cpp index da7b46ae6..fe4449959 100644 --- a/client/AdventureMapButton.cpp +++ b/client/AdventureMapButton.cpp @@ -12,6 +12,7 @@ #include "CMessage.h" #include "CMusicHandler.h" #include "GUIClasses.h" +#include "UIFramework/CGuiHandler.h" /* * AdventureMapButton.cpp, part of VCMI engine @@ -42,9 +43,9 @@ void CButtonBase::update() if (text) { if (state == PRESSED) - text->moveTo(Point(pos.x+pos.w/2+1, pos.y+pos.h/2+1)); + text->moveTo(SPoint(pos.x+pos.w/2+1, pos.y+pos.h/2+1)); else - text->moveTo(Point(pos.x+pos.w/2, pos.y+pos.h/2)); + text->moveTo(SPoint(pos.x+pos.w/2, pos.y+pos.h/2)); } int newPos = (int)state + bitmapOffset; @@ -500,10 +501,10 @@ void CSlider::moveTo(int to) double part = static_cast(to) / positions; part*=(pos.w-48); int newPos = part + pos.x + 16 - slider->pos.x; - slider->moveBy(Point(newPos, 0)); + slider->moveBy(SPoint(newPos, 0)); } else - slider->moveTo(Point(pos.x+16, pos.y)); + slider->moveTo(SPoint(pos.x+16, pos.y)); } else { @@ -512,10 +513,10 @@ void CSlider::moveTo(int to) double part = static_cast(to) / positions; part*=(pos.h-48); int newPos = part + pos.y + 16 - slider->pos.y; - slider->moveBy(Point(0, newPos)); + slider->moveBy(SPoint(0, newPos)); } else - slider->moveTo(Point(pos.x, pos.y+16)); + slider->moveTo(SPoint(pos.x, pos.y+16)); } if(moved) diff --git a/client/AdventureMapButton.h b/client/AdventureMapButton.h index 00146094e..aa0576d35 100644 --- a/client/AdventureMapButton.h +++ b/client/AdventureMapButton.h @@ -1,7 +1,8 @@ #pragma once #include "FunctionList.h" -#include "GUIBase.h" +#include "UIFramework/CKeyShortcut.h" +#include "UIFramework/SRect.h" /* * AdventureMapButton.h, part of VCMI engine @@ -22,7 +23,7 @@ class CLabel; namespace config{struct ButtonInfo;} /// Base class for buttons. -class CButtonBase : public KeyShortcut +class CButtonBase : public CKeyShortcut { public: enum ButtonState diff --git a/client/BattleInterface/CAttackAnimation.cpp b/client/BattleInterface/CAttackAnimation.cpp index 517dbff7d..f21d9f6ba 100644 --- a/client/BattleInterface/CAttackAnimation.cpp +++ b/client/BattleInterface/CAttackAnimation.cpp @@ -4,7 +4,7 @@ #include "../CMusicHandler.h" #include "../CGameInfo.h" #include "CBattleInterface.h" -#include "../CCreatureAnimation.h" +#include "CCreatureAnimation.h" #include "../../lib/BattleState.h" #include "../CPlayerInterface.h" #include "../../CCallback.h" @@ -34,7 +34,7 @@ bool CAttackAnimation::checkInitialConditions() return isEarliest(false); } -CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SHexField _dest, const CStack *defender) +CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SBattleHex _dest, const CStack *defender) : CBattleStackAnimation(_owner, attacker), dest(_dest), attackedStack(defender), attackingStack(attacker) { diff --git a/client/BattleInterface/CAttackAnimation.h b/client/BattleInterface/CAttackAnimation.h index 7e4426744..9c63f46df 100644 --- a/client/BattleInterface/CAttackAnimation.h +++ b/client/BattleInterface/CAttackAnimation.h @@ -2,7 +2,7 @@ #include "CBattleStackAnimation.h" #include "../CAnimation.h" -#include "../../lib/SHexField.h" +#include "../../lib/SBattleHex.h" class CBattleInterface; class CStack; @@ -21,7 +21,7 @@ class CStack; class CAttackAnimation : public CBattleStackAnimation { protected: - SHexField dest; //attacked hex + SBattleHex dest; //attacked hex bool shooting; CCreatureAnim::EAnimType group; //if shooting is true, print this animation group const CStack *attackedStack; @@ -31,5 +31,5 @@ public: void nextFrame(); bool checkInitialConditions(); - CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SHexField _dest, const CStack *defender); + CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SBattleHex _dest, const CStack *defender); }; \ No newline at end of file diff --git a/client/BattleInterface/CBattleConsole.h b/client/BattleInterface/CBattleConsole.h index dc4adad3f..9971b0ab9 100644 --- a/client/BattleInterface/CBattleConsole.h +++ b/client/BattleInterface/CBattleConsole.h @@ -1,6 +1,6 @@ #pragma once -#include "../GUIBase.h" +#include "../UIFramework/CIntObject.h" struct SDL_Surface; diff --git a/client/BattleInterface/CBattleHero.cpp b/client/BattleInterface/CBattleHero.cpp index a9b1d80b2..2b7093e0b 100644 --- a/client/BattleInterface/CBattleHero.cpp +++ b/client/BattleInterface/CBattleHero.cpp @@ -10,6 +10,7 @@ #include "../CSpellWindow.h" #include "../Graphics.h" #include "../CConfigHandler.h" +#include "../UIFramework/CGuiHandler.h" void CBattleHero::show(SDL_Surface *to) { diff --git a/client/BattleInterface/CBattleHero.h b/client/BattleInterface/CBattleHero.h index 3a34e4fe5..c207a0ce9 100644 --- a/client/BattleInterface/CBattleHero.h +++ b/client/BattleInterface/CBattleHero.h @@ -1,6 +1,6 @@ #pragma once -#include "../GUIBase.h" +#include "../UIFramework/CIntObject.h" class CBattleInterface; class CDefHandler; diff --git a/client/BattleInterface/CBattleInterface.cpp b/client/BattleInterface/CBattleInterface.cpp index 9995fdf89..b14c5a7e6 100644 --- a/client/BattleInterface/CBattleInterface.cpp +++ b/client/BattleInterface/CBattleInterface.cpp @@ -17,7 +17,7 @@ #include "../../CCallback.h" #include "../../lib/BattleState.h" #include "../../lib/CGeneralTextHandler.h" -#include "../CCreatureAnimation.h" +#include "CCreatureAnimation.h" #include "../Graphics.h" #include "../CSpellWindow.h" #include "../CConfigHandler.h" @@ -29,7 +29,6 @@ #include "../../lib/CTownHandler.h" #include "../../lib/map.h" - #include "CBattleHero.h" #include "CStackQueue.h" #include "CBattleConsole.h" @@ -37,7 +36,7 @@ #include "CBattleAnimation.h" #include "CBattleOptionsWindow.h" #include "CDummyAnimation.h" -#include "CHexFieldControl.h" +#include "CClickableHex.h" #include "CShootingAnimation.h" #include "CSpellEffectAnimation.h" #include "CMeleeAttackAnimation.h" @@ -47,6 +46,7 @@ #include "CDefenceAnimation.h" #include "CMovementAnimation.h" +#include "../UIFramework/CGuiHandler.h" #ifndef __GNUC__ const double M_PI = 3.14159265358979323846; @@ -112,7 +112,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe myTurn(false), resWindow(NULL), moveStarted(false), moveSh(-1), bresult(NULL) { - ObjectConstruction h__l__p(this); + OBJ_CONSTRUCTION; if(!curInt) curInt = LOCPLINT; //may happen when we are defending during network MP game @@ -136,7 +136,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe if(curInt->sysOpts.showQueue) pos.y += queue->pos.h / 2; //center whole window - queue->moveTo(Point(pos.x, pos.y - queue->pos.h)); + queue->moveTo(SPoint(pos.x, pos.y - queue->pos.h)); // queue->pos.x = pos.x; // queue->pos.y = pos.y - queue->pos.h; // pos.h += queue->pos.h; @@ -173,7 +173,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe SDL_Surface * moat = BitmapHandler::loadBitmap( siegeH->getSiegeName(13) ), * mlip = BitmapHandler::loadBitmap( siegeH->getSiegeName(14) ); - Point moatPos = graphics->wallPositions[siegeH->town->town->typeID][12], + SPoint moatPos = graphics->wallPositions[siegeH->town->town->typeID][12], mlipPos = graphics->wallPositions[siegeH->town->town->typeID][13]; if(moat) //eg. tower has no moat @@ -603,8 +603,8 @@ void CBattleInterface::show(SDL_Surface * to) {//TODO: do not check it every frame if (activeStack) //highlight all attackable hexes { - std::set set = curInt->cb->battleGetAttackedHexes(activeStack, currentlyHoveredHex, attackingHex); - BOOST_FOREACH(SHexField hex, set) + std::set set = curInt->cb->battleGetAttackedHexes(activeStack, currentlyHoveredHex, attackingHex); + BOOST_FOREACH(SBattleHex hex, set) { int x = 14 + ((hex/GameConstants::BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(hex%GameConstants::BFIELD_WIDTH) + pos.x; int y = 86 + 42 * (hex/GameConstants::BFIELD_WIDTH) + pos.y; @@ -630,10 +630,10 @@ void CBattleInterface::show(SDL_Surface * to) //preparing obstacles to be shown std::vector obstacles = curInt->cb->battleGetAllObstacles(); - std::multimap hexToObstacle; + std::multimap hexToObstacle; for(size_t b = 0; b < obstacles.size(); ++b) { - SHexField position = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getMaxBlocked(obstacles[b].pos); + SBattleHex position = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getMaxBlocked(obstacles[b].pos); hexToObstacle.insert(std::make_pair(position, b)); } @@ -845,7 +845,7 @@ void CBattleInterface::show(SDL_Surface * to) //showing in-game console LOCPLINT->cingconsole->show(to); - Rect posWithQueue = Rect(pos.x, pos.y, 800, 600); + SRect posWithQueue = SRect(pos.x, pos.y, 800, 600); if(curInt->sysOpts.showQueue) { @@ -891,12 +891,12 @@ void CBattleInterface::showAliveStacks(std::vector *aliveStacks, } } -void CBattleInterface::showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to) +void CBattleInterface::showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to) { - std::pair::const_iterator, std::multimap::const_iterator> obstRange = + std::pair::const_iterator, std::multimap::const_iterator> obstRange = hexToObstacle->equal_range(hex); - for(std::multimap::const_iterator it = obstRange.first; it != obstRange.second; ++it) + for(std::multimap::const_iterator it = obstRange.first; it != obstRange.second; ++it) { CObstacleInstance & curOb = obstacles[it->second]; std::pair shift = CGI->heroh->obstacles.find(curOb.ID)->second.posShift; @@ -963,7 +963,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) if ((int)creatureSpellToCast > -1) //use randomized spell (Faerie Dragon), or only avaliable spell (Archangel) { const CSpell * spell = CGI->spellh->spells[creatureSpellToCast]; - if (curInt->cb->battleCanCastThisSpell(spell, SHexField(myNumber)) == ESpellCastProblem::OK) + if (curInt->cb->battleCanCastThisSpell(spell, SBattleHex(myNumber)) == ESpellCastProblem::OK) { if ((spell->positiveness > -1 && ourStack) || (spell->positiveness < 1 && !ourStack)) { @@ -1210,7 +1210,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) void CBattleInterface::setBattleCursor(const int myNumber) { - const CHexFieldControl & hoveredHex = bfield[myNumber]; + const CClickableHex & hoveredHex = bfield[myNumber]; CCursorHandler *cursor = CCS->curh; const double subdividingAngle = 2.0*M_PI/6.0; // Divide a hex into six sectors. @@ -1368,7 +1368,7 @@ void CBattleInterface::setBattleCursor(const int myNumber) attackingHex = myNumber + GameConstants::BFIELD_WIDTH - 1 + zigzagCorrection; //bottom left break; } - SHexField hex(attackingHex); + SBattleHex hex(attackingHex); if (!hex.isValid()) attackingHex = -1; } @@ -1388,7 +1388,7 @@ void CBattleInterface::bOptionsf() CCS->curh->changeGraphic(0,0); - Rect tempRect = genRect(431, 481, 160, 84); + SRect tempRect = genRect(431, 481, 160, 84); tempRect += pos.topLeft(); CBattleOptionsWindow * optionsWin = new CBattleOptionsWindow(tempRect, this); GH.pushInt(optionsWin); @@ -1516,7 +1516,7 @@ void CBattleInterface::bConsoleDownf() void CBattleInterface::newStack(const CStack * stack) { - Point coords = CHexFieldControl::getXYUnitAnim(stack->position, stack->owner == attackingHeroInstance->tempOwner, stack, this);; + SPoint coords = CClickableHex::getXYUnitAnim(stack->position, stack->owner == attackingHeroInstance->tempOwner, stack, this);; if(stack->position < 0) //turret { @@ -1549,7 +1549,7 @@ void CBattleInterface::newStack(const CStack * stack) creAnims[stack->ID] = new CCreatureAnimation(stack->getCreature()->animDefName); } creAnims[stack->ID]->setType(CCreatureAnim::HOLDING); - creAnims[stack->ID]->pos = Rect(coords.x, coords.y, creAnims[stack->ID]->fullWidth, creAnims[stack->ID]->fullHeight); + creAnims[stack->ID]->pos = SRect(coords.x, coords.y, creAnims[stack->ID]->fullWidth, creAnims[stack->ID]->fullHeight); creDir[stack->ID] = stack->attackerOwned; } @@ -1568,7 +1568,7 @@ void CBattleInterface::stackActivated(const CStack * stack) //TODO: check it all activateStack(); } -void CBattleInterface::stackMoved(const CStack * stack, std::vector destHex, int distance) +void CBattleInterface::stackMoved(const CStack * stack, std::vector destHex, int distance) { addNewAnim(new CMovementAnimation(this, stack, destHex, distance)); waitForAnims(); @@ -1605,7 +1605,7 @@ void CBattleInterface::stacksAreAttacked(std::vector attacke } } -void CBattleInterface::stackAttacking( const CStack * attacker, SHexField dest, const CStack * attacked, bool shooting ) +void CBattleInterface::stackAttacking( const CStack * attacker, SBattleHex dest, const CStack * attacked, bool shooting ) { if (shooting) { @@ -1639,7 +1639,7 @@ void CBattleInterface::newRound(int number) } -void CBattleInterface::giveCommand(ui8 action, SHexField tile, ui32 stack, si32 additional) +void CBattleInterface::giveCommand(ui8 action, SBattleHex tile, ui32 stack, si32 additional) { if(!curInt->cb->battleGetStackByID(stack) && action != 1 && action != 4 && action != 5) { @@ -1678,30 +1678,30 @@ void CBattleInterface::giveCommand(ui8 action, SHexField tile, ui32 stack, si32 } } -bool CBattleInterface::isTileAttackable(const SHexField & number) const +bool CBattleInterface::isTileAttackable(const SBattleHex & number) const { for(size_t b=0; b obstacles = curInt->cb->battleGetAllObstacles(); - std::set coveredHexes; + std::set coveredHexes; for(size_t b = 0; b < obstacles.size(); ++b) { - std::vector blocked = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getBlocked(obstacles[b].pos); + std::vector blocked = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getBlocked(obstacles[b].pos); for(size_t w = 0; w < blocked.size(); ++w) coveredHexes.insert(blocked[w]); } return vstd::contains(coveredHexes, hex); } -bool CBattleInterface::isCatapultAttackable(SHexField hex) const +bool CBattleInterface::isCatapultAttackable(SBattleHex hex) const { if(!siegeH) return false; @@ -1799,7 +1799,7 @@ void CBattleInterface::hexLclicked(int whichOne) if ((int)creatureSpellToCast > -1) //use randomized spell (Faerie Dragon), or only avaliable spell (Archangel) { const CSpell * spell = CGI->spellh->spells[creatureSpellToCast]; - if (curInt->cb->battleCanCastThisSpell(spell, SHexField(whichOne)) == ESpellCastProblem::OK) + if (curInt->cb->battleCanCastThisSpell(spell, SBattleHex(whichOne)) == ESpellCastProblem::OK) { if ((spell->positiveness > -1 && ourStack) || (spell->positiveness < 1 && !ourStack)) { @@ -1880,7 +1880,7 @@ void CBattleInterface::hexLclicked(int whichOne) { if(actStack->doubleWide() && !actStack->attackerOwned) { - std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); if(vstd::contains(acc, whichOne)) attackFromHex = whichOne - 1; else @@ -1932,7 +1932,7 @@ void CBattleInterface::hexLclicked(int whichOne) { if(actStack->doubleWide() && actStack->attackerOwned) { - std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); if(vstd::contains(acc, whichOne)) attackFromHex = whichOne + 1; else @@ -2018,7 +2018,7 @@ void CBattleInterface::hexLclicked(int whichOne) CCS->curh->changeGraphic(1, 6); //cursor should be changed if(activeStack->doubleWide()) { - std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); int shiftedDest = whichOne + (activeStack->attackerOwned ? 1 : -1); if(vstd::contains(acc, whichOne)) giveCommand (BattleAction::WALK ,whichOne, activeStack->ID); @@ -2101,8 +2101,8 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc ) { //common ice bolt and magic arrow part //initial variables std::string animToDisplay; - Point srccoord = (sc->side ? Point(770, 60) : Point(30, 60)) + pos; - Point destcoord = CHexFieldControl::getXYUnitAnim(sc->tile, !sc->side, curInt->cb->battleGetStackByPos(sc->tile), this); //position attacked by arrow + SPoint srccoord = (sc->side ? SPoint(770, 60) : SPoint(30, 60)) + pos; + SPoint destcoord = CClickableHex::getXYUnitAnim(sc->tile, !sc->side, curInt->cb->battleGetStackByPos(sc->tile), this); //position attacked by arrow destcoord.x += 250; destcoord.y += 240; //animation angle @@ -2320,8 +2320,8 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc ) //mana absorption if (sc->manaGained) { - Point leftHero = Point(15, 30) + pos; - Point rightHero = Point(755, 30) + pos; + SPoint leftHero = SPoint(15, 30) + pos; + SPoint rightHero = SPoint(755, 30) + pos; addNewAnim(new CSpellEffectAnimation(this, sc->side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero.x, leftHero.y, 0, 0, false)); addNewAnim(new CSpellEffectAnimation(this, sc->side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero.x, rightHero.y, 0, 0, false)); } @@ -2632,7 +2632,7 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to) && !stack->hasBonusOfType(Bonus::SIEGE_WEAPON) //and not a war machine... ) { - const SHexField nextPos = stack->position + (stack->attackerOwned ? 1 : -1); + const SBattleHex nextPos = stack->position + (stack->attackerOwned ? 1 : -1); const bool edge = stack->position % GameConstants::BFIELD_WIDTH == (stack->attackerOwned ? GameConstants::BFIELD_WIDTH - 2 : 1); const bool moveInside = !edge && !stackCountOutsideHexes[nextPos]; int xAdd = (stack->attackerOwned ? 220 : 202) + @@ -2769,9 +2769,9 @@ void CBattleInterface::redrawBackgroundWithHexes(const CStack * activeStack) if(curInt->sysOpts.printStackRange) { - std::vector hexesToShade = occupyableHexes; + std::vector hexesToShade = occupyableHexes; hexesToShade.insert(hexesToShade.end(), attackableHexes.begin(), attackableHexes.end()); - BOOST_FOREACH(SHexField hex, hexesToShade) + BOOST_FOREACH(SBattleHex hex, hexesToShade) { int i = hex.getY(); //row int j = hex.getX()-1; //column @@ -2937,7 +2937,7 @@ void CBattleInterface::hideQueue() if(!queue->embedded) { - moveBy(Point(0, -queue->pos.h / 2)); + moveBy(SPoint(0, -queue->pos.h / 2)); GH.totalRedraw(); } } @@ -2950,7 +2950,7 @@ void CBattleInterface::showQueue() if(!queue->embedded) { - moveBy(Point(0, +queue->pos.h / 2)); + moveBy(SPoint(0, +queue->pos.h / 2)); GH.totalRedraw(); } } @@ -3170,7 +3170,7 @@ std::string CBattleInterface::SiegeHelper::getSiegeName(ui16 what, ui16 additInf /// Positions are loaded from the config file: /config/wall_pos.txt void CBattleInterface::SiegeHelper::printPartOfWall(SDL_Surface * to, int what) { - Point pos = Point(-1, -1); + SPoint pos = SPoint(-1, -1); if (what >= 1 && what <= 17) { diff --git a/client/BattleInterface/CBattleInterface.h b/client/BattleInterface/CBattleInterface.h index ae233e276..2883b4c51 100644 --- a/client/BattleInterface/CBattleInterface.h +++ b/client/BattleInterface/CBattleInterface.h @@ -1,14 +1,13 @@ #pragma once -#include "../GUIBase.h" #include "../../lib/CCreatureSet.h" #include "../../lib/ConstTransitivePtr.h" //may be reundant #include "../CAnimation.h" #include "SStackAttackedInfo.h" -#include "CHexFieldControl.h" +#include "CClickableHex.h" #include "CShootingAnimation.h" -#include "../../lib/SHexField.h" +#include "../../lib/SBattleHex.h" #include "../../lib/GameConstants.h" /* @@ -46,6 +45,7 @@ class CBattleHero; class CBattleConsole; class CBattleResultWindow; class CStackQueue; +class CPlayerInterface; /// Class which manages the locked hex fields that are blocked e.g. by obstacles class CBattleObstacle @@ -103,7 +103,7 @@ private: int mouseHoveredStack; //stack hovered by mouse; if -1 -> none time_t lastMouseHoveredStackAnimationTime; // time when last mouse hovered animation occurred static const time_t HOVER_ANIM_DELTA; - std::vector occupyableHexes, //hexes available for active stack + std::vector occupyableHexes, //hexes available for active stack attackableHexes; //hexes attackable by active stack bool stackCountOutsideHexes[GameConstants::BFIELD_SIZE]; // hexes that when in front of a unit cause it's amount box to move back int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago @@ -112,7 +112,7 @@ private: double getAnimSpeedMultiplier() const; //returns multiplier for number of frames in a group std::map standingFrame; //number of frame in standing animation by stack ID, helps in showing 'random moves' - CPlayerInterface *tacticianInterface; //used during tactics mode, points to the interface of player with higher tactics (can be either attacker or defender in hot-seat), valid onloy for human players + CPlayerInterface * tacticianInterface; //used during tactics mode, points to the interface of player with higher tactics (can be either attacker or defender in hot-seat), valid onloy for human players bool tacticsMode; bool stackCanCastSpell; //if true, active stack could possibly cats some target spell bool spellDestSelectMode; //if true, player is choosing destination for his spell @@ -124,16 +124,16 @@ private: void showAliveStack(const CStack *stack, SDL_Surface * to); //helper function for function show void showAliveStacks(std::vector *aliveStacks, int hex, std::vector *flyingStacks, SDL_Surface *to); // loops through all stacks at a given hex position void showPieceOfWall(SDL_Surface * to, int hex, const std::vector & stacks); //helper function for show - void showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to); // show all obstacles at a given hex position + void showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to); // show all obstacles at a given hex position void redrawBackgroundWithHexes(const CStack * activeStack); void printConsoleAttacked(const CStack * defender, int dmg, int killed, const CStack * attacker, bool Multiple); std::list projectiles; //projectiles flying on battlefield void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield - void giveCommand(ui8 action, SHexField tile, ui32 stack, si32 additional=-1); - bool isTileAttackable(const SHexField & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles - bool blockedByObstacle(SHexField hex) const; - bool isCatapultAttackable(SHexField hex) const; //returns true if given tile can be attacked by catapult + void giveCommand(ui8 action, SBattleHex tile, ui32 stack, si32 additional=-1); + bool isTileAttackable(const SBattleHex & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles + bool blockedByObstacle(SBattleHex hex) const; + bool isCatapultAttackable(SBattleHex hex) const; //returns true if given tile can be attacked by catapult std::list battleEffects; //different animations to display on the screen like spell effects @@ -177,7 +177,7 @@ public: void setAnimSpeed(int set); //speed of animation; 1 - slowest, 2 - medium, 4 - fastest int getAnimSpeed() const; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest - CHexFieldControl bfield[GameConstants::BFIELD_SIZE]; //11 lines, 17 hexes on each + CClickableHex bfield[GameConstants::BFIELD_SIZE]; //11 lines, 17 hexes on each //std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield SDL_Surface * cellBorder, * cellShade; CondSh *givenCommand; //data != NULL if we have i.e. moved current unit @@ -215,10 +215,10 @@ public: void newStack(const CStack * stack); //new stack appeared on battlefield void stackRemoved(int stackID); //stack disappeared from batlefiled void stackActivated(const CStack * stack); //active stack has been changed - void stackMoved(const CStack * stack, std::vector destHex, int distance); //stack with id number moved to destHex + void stackMoved(const CStack * stack, std::vector destHex, int distance); //stack with id number moved to destHex void waitForAnims(); void stacksAreAttacked(std::vector attackedInfos); //called when a certain amount of stacks has been attacked - void stackAttacking(const CStack * attacker, SHexField dest, const CStack * attacked, bool shooting); //called when stack with id ID is attacking something on hex dest + void stackAttacking(const CStack * attacker, SBattleHex dest, const CStack * attacked, bool shooting); //called when stack with id ID is attacking something on hex dest void newRoundFirst( int round ); void newRound(int number); //caled when round is ended; number is the number of round void hexLclicked(int whichOne); //hex only call-in @@ -252,5 +252,5 @@ public: friend class CAttackAnimation; friend class CMeleeAttackAnimation; friend class CShootingAnimation; - friend class CHexFieldControl; + friend class CClickableHex; }; diff --git a/client/BattleInterface/CBattleOptionsWindow.cpp b/client/BattleInterface/CBattleOptionsWindow.cpp index fd09bc796..b0a429df7 100644 --- a/client/BattleInterface/CBattleOptionsWindow.cpp +++ b/client/BattleInterface/CBattleOptionsWindow.cpp @@ -2,12 +2,12 @@ #include "CBattleOptionsWindow.h" #include "CBattleInterface.h" -#include "../GUIBase.h" #include "../GUIClasses.h" #include "../AdventureMapButton.h" #include "../CGameInfo.h" #include "../CPlayerInterface.h" #include "../../lib/CGeneralTextHandler.h" +#include "../UIFramework/CGuiHandler.h" CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner) { diff --git a/client/BattleInterface/CBattleOptionsWindow.h b/client/BattleInterface/CBattleOptionsWindow.h index 4aecf6d75..91c89c624 100644 --- a/client/BattleInterface/CBattleOptionsWindow.h +++ b/client/BattleInterface/CBattleOptionsWindow.h @@ -1,6 +1,6 @@ #pragma once -#include "../GUIBase.h" +#include "../UIFramework/CIntObject.h" class CBattleInterface; class CPicture; diff --git a/client/BattleInterface/CBattleResultWindow.cpp b/client/BattleInterface/CBattleResultWindow.cpp index 566ce5455..44dd9de59 100644 --- a/client/BattleInterface/CBattleResultWindow.cpp +++ b/client/BattleInterface/CBattleResultWindow.cpp @@ -15,6 +15,7 @@ #include "../CVideoHandler.h" #include "../SDL_Extensions.h" #include "../CBitmapHandler.h" +#include "../UIFramework/CGuiHandler.h" CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect & pos, CBattleInterface * _owner) : owner(_owner) diff --git a/client/BattleInterface/CBattleResultWindow.h b/client/BattleInterface/CBattleResultWindow.h index c49ee74d8..ecb97ff0f 100644 --- a/client/BattleInterface/CBattleResultWindow.h +++ b/client/BattleInterface/CBattleResultWindow.h @@ -1,6 +1,6 @@ #pragma once -#include "../GUIBase.h" +#include "../UIFramework/CIntObject.h" struct SDL_Surface; class AdventureMapButton; diff --git a/client/BattleInterface/CBattleStackAnimation.cpp b/client/BattleInterface/CBattleStackAnimation.cpp index 7a3eb11dd..f6dd972db 100644 --- a/client/BattleInterface/CBattleStackAnimation.cpp +++ b/client/BattleInterface/CBattleStackAnimation.cpp @@ -9,7 +9,7 @@ CBattleStackAnimation::CBattleStackAnimation(CBattleInterface * _owner, const CS { } -bool CBattleStackAnimation::isToReverseHlp(SHexField hexFrom, SHexField hexTo, bool curDir) +bool CBattleStackAnimation::isToReverseHlp(SBattleHex hexFrom, SBattleHex hexTo, bool curDir) { int fromMod = hexFrom % GameConstants::BFIELD_WIDTH; int fromDiv = hexFrom / GameConstants::BFIELD_WIDTH; @@ -35,7 +35,7 @@ bool CBattleStackAnimation::isToReverseHlp(SHexField hexFrom, SHexField hexTo, b return false; //should never happen } -bool CBattleStackAnimation::isToReverse(SHexField hexFrom, SHexField hexTo, bool curDir, bool toDoubleWide, bool toDir) +bool CBattleStackAnimation::isToReverse(SBattleHex hexFrom, SBattleHex hexTo, bool curDir, bool toDoubleWide, bool toDir) { if(hexTo < 0) //turret return false; diff --git a/client/BattleInterface/CBattleStackAnimation.h b/client/BattleInterface/CBattleStackAnimation.h index 49eaa1a07..4e9ef9f62 100644 --- a/client/BattleInterface/CBattleStackAnimation.h +++ b/client/BattleInterface/CBattleStackAnimation.h @@ -1,7 +1,7 @@ #pragma once #include "CBattleAnimation.h" -#include "../../lib/SHexField.h" +#include "../../lib/SBattleHex.h" class CStack; class CBattleInterface; @@ -24,8 +24,8 @@ public: const CStack * stack; //id of stack whose animation it is CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack); - static bool isToReverseHlp(SHexField hexFrom, SHexField hexTo, bool curDir); //helper for isToReverse - static bool isToReverse(SHexField hexFrom, SHexField hexTo, bool curDir /*if true, creature is in attacker's direction*/, bool toDoubleWide, bool toDir); //determines if creature should be reversed (it stands on hexFrom and should 'see' hexTo) + static bool isToReverseHlp(SBattleHex hexFrom, SBattleHex hexTo, bool curDir); //helper for isToReverse + static bool isToReverse(SBattleHex hexFrom, SBattleHex hexTo, bool curDir /*if true, creature is in attacker's direction*/, bool toDoubleWide, bool toDir); //determines if creature should be reversed (it stands on hexFrom and should 'see' hexTo) CCreatureAnimation *myAnim(); //animation for our stack }; \ No newline at end of file diff --git a/client/BattleInterface/CHexFieldControl.cpp b/client/BattleInterface/CClickableHex.cpp similarity index 78% rename from client/BattleInterface/CHexFieldControl.cpp rename to client/BattleInterface/CClickableHex.cpp index 9b58098cc..a2f6142cd 100644 --- a/client/BattleInterface/CHexFieldControl.cpp +++ b/client/BattleInterface/CClickableHex.cpp @@ -1,5 +1,5 @@ #include "StdInc.h" -#include "CHexFieldControl.h" +#include "CClickableHex.h" #include "CBattleInterface.h" #include "../../lib/BattleState.h" #include "../CGameInfo.h" @@ -11,10 +11,11 @@ #include "../SDL_Extensions.h" #include "../GUIClasses.h" #include "CBattleConsole.h" +#include "../UIFramework/CGuiHandler.h" -Point CHexFieldControl::getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * stack, const CBattleInterface * cbi) +SPoint CClickableHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * stack, const CBattleInterface * cbi) { - Point ret(-500, -500); //returned value + SPoint ret(-500, -500); //returned value if(stack && stack->position < 0) //creatures in turrets { switch(stack->position) @@ -58,7 +59,7 @@ Point CHexFieldControl::getXYUnitAnim(const int & hexNum, const bool & attacker, //returning return ret +CPlayerInterface::battleInt->pos; } -void CHexFieldControl::activate() +void CClickableHex::activate() { activateHover(); activateMouseMove(); @@ -66,7 +67,7 @@ void CHexFieldControl::activate() activateRClick(); } -void CHexFieldControl::deactivate() +void CClickableHex::deactivate() { deactivateHover(); deactivateMouseMove(); @@ -74,7 +75,7 @@ void CHexFieldControl::deactivate() deactivateRClick(); } -void CHexFieldControl::hover(bool on) +void CClickableHex::hover(bool on) { hovered = on; //Hoverable::hover(on); @@ -85,11 +86,11 @@ void CHexFieldControl::hover(bool on) } } -CHexFieldControl::CHexFieldControl() : setAlterText(false), myNumber(-1), accessible(true), hovered(false), strictHovered(false), myInterface(NULL) +CClickableHex::CClickableHex() : setAlterText(false), myNumber(-1), accessible(true), hovered(false), strictHovered(false), myInterface(NULL) { } -void CHexFieldControl::mouseMoved(const SDL_MouseMotionEvent &sEvent) +void CClickableHex::mouseMoved(const SDL_MouseMotionEvent &sEvent) { if(myInterface->cellShade) { @@ -124,7 +125,7 @@ void CHexFieldControl::mouseMoved(const SDL_MouseMotionEvent &sEvent) } } -void CHexFieldControl::clickLeft(tribool down, bool previousState) +void CClickableHex::clickLeft(tribool down, bool previousState) { if(!down && hovered && strictHovered) //we've been really clicked! { @@ -132,7 +133,7 @@ void CHexFieldControl::clickLeft(tribool down, bool previousState) } } -void CHexFieldControl::clickRight(tribool down, bool previousState) +void CClickableHex::clickRight(tribool down, bool previousState) { const CStack * myst = myInterface->curInt->cb->battleGetStackByPos(myNumber); //stack info if(hovered && strictHovered && myst!=NULL) diff --git a/client/BattleInterface/CHexFieldControl.h b/client/BattleInterface/CClickableHex.h similarity index 74% rename from client/BattleInterface/CHexFieldControl.h rename to client/BattleInterface/CClickableHex.h index 9beacd6de..3ce60d28c 100644 --- a/client/BattleInterface/CHexFieldControl.h +++ b/client/BattleInterface/CClickableHex.h @@ -1,13 +1,13 @@ #pragma once -#include "../GUIBase.h" +#include "../UIFramework/CIntObject.h" class CBattleInterface; class CStack; struct SDL_MouseMotionEvent; /* - * CHexFieldControl.h, part of VCMI engine + * CClickableHex.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * @@ -17,7 +17,7 @@ struct SDL_MouseMotionEvent; */ /// Class which stands for a single hex field on a battlefield -class CHexFieldControl : public CIntObject +class CClickableHex : public CIntObject { private: bool setAlterText; //if true, this hex has set alternative text in console and will clean it @@ -27,7 +27,7 @@ public: //CStack * ourStack; bool hovered, strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering) CBattleInterface * myInterface; //interface that owns me - static Point getXYUnitAnim(const int &hexNum, const bool &attacker, const CStack *creature, const CBattleInterface *cbi); //returns (x, y) of left top corner of animation + static SPoint getXYUnitAnim(const int &hexNum, const bool &attacker, const CStack *creature, const CBattleInterface *cbi); //returns (x, y) of left top corner of animation //for user interactions void hover (bool on); @@ -36,5 +36,5 @@ public: void mouseMoved (const SDL_MouseMotionEvent &sEvent); void clickLeft(tribool down, bool previousState); void clickRight(tribool down, bool previousState); - CHexFieldControl(); + CClickableHex(); }; \ No newline at end of file diff --git a/client/CCreatureAnimation.cpp b/client/BattleInterface/CCreatureAnimation.cpp similarity index 94% rename from client/CCreatureAnimation.cpp rename to client/BattleInterface/CCreatureAnimation.cpp index 5b10a7e90..4658695ca 100644 --- a/client/CCreatureAnimation.cpp +++ b/client/BattleInterface/CCreatureAnimation.cpp @@ -1,10 +1,10 @@ #include "StdInc.h" #include "CCreatureAnimation.h" -#include "../lib/CLodHandler.h" -#include "../lib/VCMI_Lib.h" -#include "../lib/vcmi_endian.h" -#include "SDL_Extensions.h" +#include "../../lib/CLodHandler.h" +#include "../../lib/VCMI_Lib.h" +#include "../../lib/vcmi_endian.h" +#include "../SDL_Extensions.h" /* * CCreatureAnimation.cpp, part of VCMI engine diff --git a/client/CCreatureAnimation.h b/client/BattleInterface/CCreatureAnimation.h similarity index 93% rename from client/CCreatureAnimation.h rename to client/BattleInterface/CCreatureAnimation.h index dd8170afc..87ac66e9d 100644 --- a/client/CCreatureAnimation.h +++ b/client/BattleInterface/CCreatureAnimation.h @@ -1,10 +1,9 @@ #pragma once -#include "CDefHandler.h" -#include "GUIBase.h" -#include "../client/CBitmapHandler.h" -#include "CAnimation.h" +#include "../CDefHandler.h" +#include "../../client/CBitmapHandler.h" +#include "../CAnimation.h" /* * CCreatureAnimation.h, part of VCMI engine @@ -17,6 +16,7 @@ */ struct BMPPalette; +class CIntObject; /// Class which manages animations of creatures/units inside battles class CCreatureAnimation : public CIntObject diff --git a/client/BattleInterface/CDefenceAnimation.cpp b/client/BattleInterface/CDefenceAnimation.cpp index 4a342a2a1..0c32ec23c 100644 --- a/client/BattleInterface/CDefenceAnimation.cpp +++ b/client/BattleInterface/CDefenceAnimation.cpp @@ -3,7 +3,7 @@ #include "CBattleInterface.h" #include "../CGameInfo.h" -#include "../CCreatureAnimation.h" +#include "CCreatureAnimation.h" #include "../CPlayerInterface.h" #include "../CMusicHandler.h" #include "../../lib/BattleState.h" diff --git a/client/BattleInterface/CMeleeAttackAnimation.cpp b/client/BattleInterface/CMeleeAttackAnimation.cpp index eb0717bf4..7116a6a63 100644 --- a/client/BattleInterface/CMeleeAttackAnimation.cpp +++ b/client/BattleInterface/CMeleeAttackAnimation.cpp @@ -2,7 +2,7 @@ #include "CMeleeAttackAnimation.h" #include "CBattleInterface.h" -#include "../CCreatureAnimation.h" +#include "CCreatureAnimation.h" #include "../../lib/BattleState.h" #include "CReverseAnimation.h" @@ -40,18 +40,18 @@ bool CMeleeAttackAnimation::init() int revShiftattacker = (attackingStack->attackerOwned ? -1 : 1); - int mutPos = SHexField::mutualPosition(attackingStackPosBeforeReturn, dest); + int mutPos = SBattleHex::mutualPosition(attackingStackPosBeforeReturn, dest); if(mutPos == -1 && attackingStack->doubleWide()) { - mutPos = SHexField::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->position); + mutPos = SBattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->position); } if (mutPos == -1 && attackedStack->doubleWide()) { - mutPos = SHexField::mutualPosition(attackingStackPosBeforeReturn, attackedStack->occupiedHex()); + mutPos = SBattleHex::mutualPosition(attackingStackPosBeforeReturn, attackedStack->occupiedHex()); } if (mutPos == -1 && attackedStack->doubleWide() && attackingStack->doubleWide()) { - mutPos = SHexField::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->occupiedHex()); + mutPos = SBattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->occupiedHex()); } @@ -89,7 +89,7 @@ void CMeleeAttackAnimation::endAnim() delete this; } -CMeleeAttackAnimation::CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, SHexField _dest, const CStack * _attacked) +CMeleeAttackAnimation::CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, SBattleHex _dest, const CStack * _attacked) : CAttackAnimation(_owner, attacker, _dest, _attacked) { } \ No newline at end of file diff --git a/client/BattleInterface/CMeleeAttackAnimation.h b/client/BattleInterface/CMeleeAttackAnimation.h index fe799aaae..3afd64872 100644 --- a/client/BattleInterface/CMeleeAttackAnimation.h +++ b/client/BattleInterface/CMeleeAttackAnimation.h @@ -24,5 +24,5 @@ public: void nextFrame(); void endAnim(); - CMeleeAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SHexField _dest, const CStack *_attacked); + CMeleeAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SBattleHex _dest, const CStack *_attacked); }; \ No newline at end of file diff --git a/client/BattleInterface/CMovementAnimation.cpp b/client/BattleInterface/CMovementAnimation.cpp index 636c15276..b86f0c503 100644 --- a/client/BattleInterface/CMovementAnimation.cpp +++ b/client/BattleInterface/CMovementAnimation.cpp @@ -2,13 +2,13 @@ #include "CMovementAnimation.h" #include "CBattleInterface.h" -#include "../CCreatureAnimation.h" +#include "CCreatureAnimation.h" #include "../../lib/BattleState.h" #include "../CGameInfo.h" #include "../CMusicHandler.h" #include "CReverseAnimation.h" #include "CMovementEndAnimation.h" -#include "CHexFieldControl.h" +#include "CClickableHex.h" bool CMovementAnimation::init() { @@ -32,10 +32,10 @@ bool CMovementAnimation::init() } //bool twoTiles = movedStack->doubleWide(); - Point begPosition = CHexFieldControl::getXYUnitAnim(curStackPos, movedStack->attackerOwned, movedStack, owner); - Point endPosition = CHexFieldControl::getXYUnitAnim(nextHex, movedStack->attackerOwned, movedStack, owner); + SPoint begPosition = CClickableHex::getXYUnitAnim(curStackPos, movedStack->attackerOwned, movedStack, owner); + SPoint endPosition = CClickableHex::getXYUnitAnim(nextHex, movedStack->attackerOwned, movedStack, owner); - int mutPos = SHexField::mutualPosition(curStackPos, nextHex); + int mutPos = SBattleHex::mutualPosition(curStackPos, nextHex); //reverse unit if necessary if((begPosition.x > endPosition.x) && owner->creDir[stack->ID] == true) @@ -116,7 +116,7 @@ void CMovementAnimation::nextFrame() if(whichStep == steps) { // Sets the position of the creature animation sprites - Point coords = CHexFieldControl::getXYUnitAnim(nextHex, owner->creDir[stack->ID], stack, owner); + SPoint coords = CClickableHex::getXYUnitAnim(nextHex, owner->creDir[stack->ID], stack, owner); myAnim()->pos = coords; // true if creature haven't reached the final destination hex @@ -168,7 +168,7 @@ void CMovementAnimation::endAnim() delete this; } -CMovementAnimation::CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector _destTiles, int _distance) +CMovementAnimation::CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector _destTiles, int _distance) : CBattleStackAnimation(_owner, _stack), destTiles(_destTiles), nextPos(0), distance(_distance), stepX(0.0), stepY(0.0) { curStackPos = stack->position; diff --git a/client/BattleInterface/CMovementAnimation.h b/client/BattleInterface/CMovementAnimation.h index a288ff72f..3d7cba533 100644 --- a/client/BattleInterface/CMovementAnimation.h +++ b/client/BattleInterface/CMovementAnimation.h @@ -20,8 +20,8 @@ class CStack; class CMovementAnimation : public CBattleStackAnimation { private: - std::vector destTiles; //destination - SHexField nextHex; + std::vector destTiles; //destination + SBattleHex nextHex; ui32 nextPos; int distance; double stepX, stepY; //how far stack is moved in one frame @@ -33,5 +33,5 @@ public: void nextFrame(); void endAnim(); - CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector _destTiles, int _distance); + CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector _destTiles, int _distance); }; \ No newline at end of file diff --git a/client/BattleInterface/CMovementEndAnimation.cpp b/client/BattleInterface/CMovementEndAnimation.cpp index 4135a1dd7..fbc80ae2f 100644 --- a/client/BattleInterface/CMovementEndAnimation.cpp +++ b/client/BattleInterface/CMovementEndAnimation.cpp @@ -1,7 +1,7 @@ #include "StdInc.h" #include "CMovementEndAnimation.h" -#include "../CCreatureAnimation.h" +#include "CCreatureAnimation.h" #include "../CMusicHandler.h" #include "../CGameInfo.h" #include "../../lib/BattleState.h" @@ -46,7 +46,7 @@ void CMovementEndAnimation::endAnim() delete this; } -CMovementEndAnimation::CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, SHexField destTile) +CMovementEndAnimation::CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, SBattleHex destTile) : CBattleStackAnimation(_owner, _stack), destinationTile(destTile) { } \ No newline at end of file diff --git a/client/BattleInterface/CMovementEndAnimation.h b/client/BattleInterface/CMovementEndAnimation.h index 0f90e4c6c..0db777d69 100644 --- a/client/BattleInterface/CMovementEndAnimation.h +++ b/client/BattleInterface/CMovementEndAnimation.h @@ -20,11 +20,11 @@ class CStack; class CMovementEndAnimation : public CBattleStackAnimation { private: - SHexField destinationTile; + SBattleHex destinationTile; public: bool init(); void nextFrame(); void endAnim(); - CMovementEndAnimation(CBattleInterface *_owner, const CStack *_stack, SHexField destTile); + CMovementEndAnimation(CBattleInterface *_owner, const CStack *_stack, SBattleHex destTile); }; \ No newline at end of file diff --git a/client/BattleInterface/CMovementStartAnimation.cpp b/client/BattleInterface/CMovementStartAnimation.cpp index 0785ef826..0a00db716 100644 --- a/client/BattleInterface/CMovementStartAnimation.cpp +++ b/client/BattleInterface/CMovementStartAnimation.cpp @@ -4,7 +4,7 @@ #include "../CMusicHandler.h" #include "CBattleInterface.h" #include "../CGameInfo.h" -#include "../CCreatureAnimation.h" +#include "CCreatureAnimation.h" #include "../../lib/BattleState.h" #include "../CPlayerInterface.h" diff --git a/client/BattleInterface/CReverseAnimation.cpp b/client/BattleInterface/CReverseAnimation.cpp index 4486749af..951974e6e 100644 --- a/client/BattleInterface/CReverseAnimation.cpp +++ b/client/BattleInterface/CReverseAnimation.cpp @@ -1,10 +1,10 @@ #include "StdInc.h" #include "CReverseAnimation.h" -#include "../CCreatureAnimation.h" +#include "CCreatureAnimation.h" #include "../../lib/BattleState.h" #include "CBattleInterface.h" -#include "CHexFieldControl.h" +#include "CClickableHex.h" bool CReverseAnimation::init() { @@ -58,7 +58,7 @@ void CReverseAnimation::endAnim() delete this; } -CReverseAnimation::CReverseAnimation(CBattleInterface * _owner, const CStack * stack, SHexField dest, bool _priority) +CReverseAnimation::CReverseAnimation(CBattleInterface * _owner, const CStack * stack, SBattleHex dest, bool _priority) : CBattleStackAnimation(_owner, stack), partOfAnim(1), secondPartSetup(false), hex(dest), priority(_priority) { } @@ -73,7 +73,7 @@ void CReverseAnimation::setupSecondPart() return; } - Point coords = CHexFieldControl::getXYUnitAnim(hex, owner->creDir[stack->ID], stack, owner); + SPoint coords = CClickableHex::getXYUnitAnim(hex, owner->creDir[stack->ID], stack, owner); myAnim()->pos.x = coords.x; //creAnims[stackID]->pos.y = coords.second; diff --git a/client/BattleInterface/CReverseAnimation.h b/client/BattleInterface/CReverseAnimation.h index b786db0e1..dac230e0b 100644 --- a/client/BattleInterface/CReverseAnimation.h +++ b/client/BattleInterface/CReverseAnimation.h @@ -21,7 +21,7 @@ class CReverseAnimation : public CBattleStackAnimation private: int partOfAnim; //1 - first, 2 - second bool secondPartSetup; - SHexField hex; + SBattleHex hex; public: bool priority; //true - high, false - low bool init(); @@ -30,5 +30,5 @@ public: void setupSecondPart(); void endAnim(); - CReverseAnimation(CBattleInterface *_owner, const CStack *stack, SHexField dest, bool _priority); + CReverseAnimation(CBattleInterface *_owner, const CStack *stack, SBattleHex dest, bool _priority); }; \ No newline at end of file diff --git a/client/BattleInterface/CShootingAnimation.cpp b/client/BattleInterface/CShootingAnimation.cpp index b1fd22684..8f2f1c247 100644 --- a/client/BattleInterface/CShootingAnimation.cpp +++ b/client/BattleInterface/CShootingAnimation.cpp @@ -4,13 +4,13 @@ #include "../../lib/BattleState.h" #include "CBattleInterface.h" -#include "../CCreatureAnimation.h" +#include "CCreatureAnimation.h" #include "../CGameInfo.h" #include "../../lib/CTownHandler.h" #include "CMovementStartAnimation.h" #include "CReverseAnimation.h" #include "CSpellEffectAnimation.h" -#include "CHexFieldControl.h" +#include "CClickableHex.h" bool CShootingAnimation::init() { @@ -59,16 +59,16 @@ bool CShootingAnimation::init() spi.spin = false; } - Point xycoord = CHexFieldControl::getXYUnitAnim(shooter->position, true, shooter, owner); - Point destcoord; + SPoint xycoord = CClickableHex::getXYUnitAnim(shooter->position, true, shooter, owner); + SPoint destcoord; // The "master" point where all projectile positions relate to. - static const Point projectileOrigin(181, 252); + static const SPoint projectileOrigin(181, 252); if (attackedStack) { - destcoord = CHexFieldControl::getXYUnitAnim(dest, false, attackedStack, owner); + destcoord = CClickableHex::getXYUnitAnim(dest, false, attackedStack, owner); destcoord.x += 250; destcoord.y += 210; //TODO: find a better place to shoot // Calculate projectile start position. Offsets are read out of the CRANIM.TXT. @@ -185,7 +185,7 @@ void CShootingAnimation::endAnim() delete this; } -CShootingAnimation::CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, SHexField _dest, const CStack * _attacked, bool _catapult, int _catapultDmg) +CShootingAnimation::CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, SBattleHex _dest, const CStack * _attacked, bool _catapult, int _catapultDmg) : CAttackAnimation(_owner, attacker, _dest, _attacked), catapultDamage(_catapultDmg), catapult(_catapult) { diff --git a/client/BattleInterface/CShootingAnimation.h b/client/BattleInterface/CShootingAnimation.h index fa67563f3..a2f1890da 100644 --- a/client/BattleInterface/CShootingAnimation.h +++ b/client/BattleInterface/CShootingAnimation.h @@ -1,7 +1,7 @@ #pragma once #include "CAttackAnimation.h" -#include "../../lib/SHexField.h" +#include "../../lib/SBattleHex.h" class CBattleInterface; class CStack; @@ -45,5 +45,5 @@ public: //last param only for catapult attacks CShootingAnimation(CBattleInterface *_owner, const CStack *attacker, - SHexField _dest, const CStack *_attacked, bool _catapult = false, int _catapultDmg = 0); + SBattleHex _dest, const CStack *_attacked, bool _catapult = false, int _catapultDmg = 0); }; \ No newline at end of file diff --git a/client/BattleInterface/CSpellEffectAnimation.cpp b/client/BattleInterface/CSpellEffectAnimation.cpp index f24e45d21..8e31b936d 100644 --- a/client/BattleInterface/CSpellEffectAnimation.cpp +++ b/client/BattleInterface/CSpellEffectAnimation.cpp @@ -8,6 +8,7 @@ #include "../../CCallback.h" #include "../../lib/BattleState.h" #include "../SDL_Extensions.h" +#include "../UIFramework/SRect.h" //effect animation bool CSpellEffectAnimation::init() @@ -67,7 +68,7 @@ bool CSpellEffectAnimation::init() if(effect == -1 || graphics->battleACToDef[effect].size() != 0) { const CStack* destStack = owner->curInt->cb->battleGetStackByPos(destTile, false); - Rect &tilePos = owner->bfield[destTile].pos; + SRect &tilePos = owner->bfield[destTile].pos; SBattleEffect be; be.effectID = ID; if(customAnim.size()) @@ -170,7 +171,7 @@ void CSpellEffectAnimation::endAnim() delete this; } -CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, SHexField _destTile, int _dx, int _dy, bool _Vflip) +CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, SBattleHex _destTile, int _dx, int _dy, bool _Vflip) :CBattleAnimation(_owner), effect(_effect), destTile(_destTile), customAnim(""), dx(_dx), dy(_dy), Vflip(_Vflip) { } diff --git a/client/BattleInterface/CSpellEffectAnimation.h b/client/BattleInterface/CSpellEffectAnimation.h index 73af1a563..2528e5072 100644 --- a/client/BattleInterface/CSpellEffectAnimation.h +++ b/client/BattleInterface/CSpellEffectAnimation.h @@ -2,7 +2,7 @@ #include "CBattleAnimation.h" -#include "../../lib/SHexField.h" +#include "../../lib/SBattleHex.h" class CBattleInterface; @@ -21,7 +21,7 @@ class CSpellEffectAnimation : public CBattleAnimation { private: ui32 effect; - SHexField destTile; + SBattleHex destTile; std::string customAnim; int x, y, dx, dy; bool Vflip; @@ -30,6 +30,6 @@ public: void nextFrame(); void endAnim(); - CSpellEffectAnimation(CBattleInterface *_owner, ui32 _effect, SHexField _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false); + CSpellEffectAnimation(CBattleInterface *_owner, ui32 _effect, SBattleHex _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false); CSpellEffectAnimation(CBattleInterface *_owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false); }; \ No newline at end of file diff --git a/client/BattleInterface/CStackQueue.cpp b/client/BattleInterface/CStackQueue.cpp index 6cda55472..4a6b07eeb 100644 --- a/client/BattleInterface/CStackQueue.cpp +++ b/client/BattleInterface/CStackQueue.cpp @@ -8,6 +8,7 @@ #include "../CPlayerInterface.h" #include "../CBitmapHandler.h" #include "../../CCallback.h" +#include "../UIFramework/CGuiHandler.h" void CStackQueue::update() { diff --git a/client/BattleInterface/CStackQueue.h b/client/BattleInterface/CStackQueue.h index 24f248a06..b4ff8ccae 100644 --- a/client/BattleInterface/CStackQueue.h +++ b/client/BattleInterface/CStackQueue.h @@ -1,6 +1,6 @@ #pragma once -#include "../GUIBase.h" +#include "../UIFramework/CIntObject.h" struct SDL_Surface; class CStack; diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index 66e44e760..a2e562292 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -29,6 +29,7 @@ #include "CSoundBase.h" #include "../lib/CGameState.h" #include "CMusicHandler.h" +#include "UIFramework/CGuiHandler.h" #ifdef _MSC_VER #pragma warning (disable : 4355) @@ -142,7 +143,7 @@ void CMinimap::draw(SDL_Surface * to) rx = static_cast((tilesw / static_cast(mapSizes.x)) * pos.w), //width ry = static_cast((tilesh / static_cast(mapSizes.y)) * pos.h); //height - CSDL_Ext::drawDashedBorder(temps, Rect(bx, by, rx, ry), int3(255,75,125)); + CSDL_Ext::drawDashedBorder(temps, SRect(bx, by, rx, ry), int3(255,75,125)); //blitAt(radar,bx,by,temps); blitAt(temps,pos.x,pos.y,to); @@ -180,7 +181,7 @@ void CMinimapSurfacesRef::initMap(int level) SDL_FreeSurface(map[g]); } map.clear();*/ - const Rect &minimap_pos = adventureInt->minimap.pos; + const SRect &minimap_pos = adventureInt->minimap.pos; std::map &colors = adventureInt->minimap.colors; std::map &colorsBlocked = adventureInt->minimap.colorsBlocked; int3 mapSizes = LOCPLINT->cb->getMapSize(); @@ -220,7 +221,7 @@ void CMinimapSurfacesRef::initFoW(int level) } FoW.clear();*/ - const Rect &minimap_pos = adventureInt->minimap.pos; + const SRect &minimap_pos = adventureInt->minimap.pos; int3 mapSizes = LOCPLINT->cb->getMapSize(); int mw = map_[0]->w, mh = map_[0]->h;//, //wo = mw/mapSizes.x, ho = mh/mapSizes.y; //TODO use me @@ -252,7 +253,7 @@ void CMinimapSurfacesRef::initFlaggableObjs(int level) } flObjs.clear();*/ - const Rect &minimap_pos = adventureInt->minimap.pos; + const SRect &minimap_pos = adventureInt->minimap.pos; int3 mapSizes = LOCPLINT->cb->getMapSize(); int mw = map_[0]->w, mh = map_[0]->h; for(int d=0; dmh->map->twoLevel+1; ++d) @@ -629,25 +630,25 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to) { if (hvx<0 && hvy<0) { - Rect dstRect = genRect(32, 32, x + moveX, y + moveY); + SRect dstRect = genRect(32, 32, x + moveX, y + moveY); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, to, &dstRect); } else if(hvx<0) { - Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0); - Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY); + SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0); + SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } else if (hvy<0) { - Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); - Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY); + SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); + SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } else { - Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); - Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY); + SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); + SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } } @@ -655,25 +656,25 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to) { if (hvx<0 && hvy<0) { - Rect dstRect = genRect(32, 32, x, y); + SRect dstRect = genRect(32, 32, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, to, &dstRect); } else if(hvx<0) { - Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0); - Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y); + SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0); + SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } else if (hvy<0) { - Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); - Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y); + SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); + SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } else { - Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); - Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y); + SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); + SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } } @@ -1129,7 +1130,7 @@ void CAdvMapInt::fadventureOPtions() void CAdvMapInt::fsystemOptions() { - CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(Rect::createCentered(487, 481), LOCPLINT); + CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(SRect::createCentered(487, 481), LOCPLINT); GH.pushInt(sysopWindow); } @@ -1491,7 +1492,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) int3(-1, -1, 0), int3(0, -1, 0), int3(+1, -1, 0) }; //numpad arrow - if(isArrowKey(SDLKey(k))) + if(CGuiHandler::isArrowKey(SDLKey(k))) { switch(k) { @@ -1509,7 +1510,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) break; } - k = arrowToNum(SDLKey(k)); + k = CGuiHandler::arrowToNum(SDLKey(k)); } if(!isActive() || LOCPLINT->ctrlPressed())//ctrl makes arrow move screen, not hero diff --git a/client/CAnimation.cpp b/client/CAnimation.cpp index c5077c4cd..d36a444e5 100644 --- a/client/CAnimation.cpp +++ b/client/CAnimation.cpp @@ -39,7 +39,7 @@ public: inline void Load(size_t size, ui8 color=0); inline void EndLine(); //init image with these sizes and palette - inline void init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal); + inline void init(SPoint SpriteSize, SPoint Margins, SPoint FullSize, SDL_Color *pal); SDLImageLoader(SDLImage * Img); ~SDLImageLoader(); @@ -63,7 +63,7 @@ public: inline void Load(size_t size, ui8 color=0); inline void EndLine(); //init image with these sizes and palette - inline void init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal); + inline void init(SPoint SpriteSize, SPoint Margins, SPoint FullSize, SDL_Color *pal); CompImageLoader(CompImage * Img); ~CompImageLoader(); @@ -158,9 +158,9 @@ void CDefFile::loadFrame(size_t frame, size_t group, ImageLoader &loader) const ui32 currentOffset = sizeof(SSpriteDef); ui32 BaseOffset = sizeof(SSpriteDef); - loader.init(Point(sprite.width, sprite.height), - Point(sprite.leftMargin, sprite.topMargin), - Point(sprite.fullWidth, sprite.fullHeight), palette); + loader.init(SPoint(sprite.width, sprite.height), + SPoint(sprite.leftMargin, sprite.topMargin), + SPoint(sprite.fullWidth, sprite.fullHeight), palette); switch (sprite.format) { @@ -297,7 +297,7 @@ SDLImageLoader::SDLImageLoader(SDLImage * Img): { } -void SDLImageLoader::init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal) +void SDLImageLoader::init(SPoint SpriteSize, SPoint Margins, SPoint FullSize, SDL_Color *pal) { //Init image image->surf = SDL_CreateRGBSurface(SDL_SWSURFACE, SpriteSize.x, SpriteSize.y, 8, 0, 0, 0, 0); @@ -353,9 +353,9 @@ CompImageLoader::CompImageLoader(CompImage * Img): } -void CompImageLoader::init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal) +void CompImageLoader::init(SPoint SpriteSize, SPoint Margins, SPoint FullSize, SDL_Color *pal) { - image->sprite = Rect(Margins, SpriteSize); + image->sprite = SRect(Margins, SpriteSize); image->fullSize = FullSize; if (SpriteSize.x && SpriteSize.y) { @@ -588,17 +588,17 @@ SDLImage::SDLImage(std::string filename, bool compressed): } } -void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 rotation) const +void SDLImage::draw(SDL_Surface *where, int posX, int posY, SRect *src, ui8 rotation) const { if (!surf) return; - Rect sourceRect(margins.x, margins.y, surf->w, surf->h); + SRect sourceRect(margins.x, margins.y, surf->w, surf->h); //TODO: rotation and scaling if (src) { sourceRect = sourceRect & *src; } - Rect destRect(posX, posY, surf->w, surf->h); + SRect destRect(posX, posY, surf->w, surf->h); destRect += sourceRect.topLeft(); sourceRect -= margins; CSDL_Ext::blitSurface(surf, &sourceRect, where, &destRect); @@ -640,22 +640,22 @@ CompImage::CompImage(SDL_Surface * surf) assert(0); } -void CompImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alpha) const +void CompImage::draw(SDL_Surface *where, int posX, int posY, SRect *src, ui8 alpha) const { int rotation = 0; //TODO //rotation & 2 = horizontal rotation //rotation & 4 = vertical rotation if (!surf) return; - Rect sourceRect(sprite); + SRect sourceRect(sprite); //TODO: rotation and scaling if (src) sourceRect = sourceRect & *src; //Limit source rect to sizes of surface - sourceRect = sourceRect & Rect(0, 0, where->w, where->h); + sourceRect = sourceRect & SRect(0, 0, where->w, where->h); //Starting point on SDL surface - Point dest(posX+sourceRect.x, posY+sourceRect.y); + SPoint dest(posX+sourceRect.x, posY+sourceRect.y); if (rotation & 2) dest.y += sourceRect.h; if (rotation & 4) @@ -1309,7 +1309,7 @@ void CShowableAnim::showAll(SDL_Surface *to) void CShowableAnim::blitImage(size_t frame, size_t group, SDL_Surface *to) { assert(to); - Rect src( xOffset, yOffset, pos.w, pos.h); + SRect src( xOffset, yOffset, pos.w, pos.h); IImage * img = anim.getImage(frame, group); if (img) img->draw(to, pos.x-xOffset, pos.y-yOffset, &src, alpha); @@ -1324,7 +1324,7 @@ void CShowableAnim::rotate(bool on, bool vertical) flags &= ~flag; } -CCreatureAnim::CCreatureAnim(int x, int y, std::string name, Rect picPos, ui8 flags, EAnimType type): +CCreatureAnim::CCreatureAnim(int x, int y, std::string name, SRect picPos, ui8 flags, EAnimType type): CShowableAnim(x,y,name,flags,3,type) { xOffset = picPos.x; diff --git a/client/CAnimation.h b/client/CAnimation.h index e17291137..86002fa65 100644 --- a/client/CAnimation.h +++ b/client/CAnimation.h @@ -1,7 +1,6 @@ #pragma once - -#include "GUIBase.h" +#include "UIFramework/CIntObject.h" /* * CAnimation.h, part of VCMI engine @@ -61,7 +60,7 @@ class IImage public: //draws image on surface "where" at position - virtual void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=NULL, ui8 alpha=255) const=0; + virtual void draw(SDL_Surface *where, int posX=0, int posY=0, SRect *src=NULL, ui8 alpha=255) const=0; //decrease ref count, returns true if image can be deleted (refCount <= 0) bool decreaseRef(); @@ -84,9 +83,9 @@ public: //Surface without empty borders SDL_Surface * surf; //size of left and top borders - Point margins; + SPoint margins; //total size including borders - Point fullSize; + SPoint fullSize; public: //Load image from def file @@ -97,7 +96,7 @@ public: SDLImage(SDL_Surface * from, bool extraRef); ~SDLImage(); - void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=NULL, ui8 alpha=255) const; + void draw(SDL_Surface *where, int posX=0, int posY=0, SRect *src=NULL, ui8 alpha=255) const; void playerColored(int player); int width() const; int height() const; @@ -120,9 +119,9 @@ public: class CompImage : public IImage { //x,y - margins, w,h - sprite size - Rect sprite; + SRect sprite; //total size including borders - Point fullSize; + SPoint fullSize; //RLE-d data ui8 * surf; @@ -143,7 +142,7 @@ public: CompImage(SDL_Surface * surf); ~CompImage(); - void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=NULL, ui8 alpha=255) const; + void draw(SDL_Surface *where, int posX=0, int posY=0, SRect *src=NULL, ui8 alpha=255) const; void playerColored(int player); int width() const; int height() const; @@ -367,7 +366,7 @@ public: //clear queue and set animation to this sequence void clearAndSet(EAnimType type); - CCreatureAnim(int x, int y, std::string name, Rect picPos, + CCreatureAnim(int x, int y, std::string name, SRect picPos, ui8 flags= USE_RLE, EAnimType = HOLDING ); }; diff --git a/client/CCastleInterface.cpp b/client/CCastleInterface.cpp index 8ae467671..cd865bd1e 100644 --- a/client/CCastleInterface.cpp +++ b/client/CCastleInterface.cpp @@ -22,6 +22,7 @@ #include "Graphics.h" #include "SDL_Extensions.h" #include "../lib/GameConstants.h" +#include "UIFramework/CGuiHandler.h" using namespace boost::assign; @@ -255,7 +256,7 @@ CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstanc background->colorize(LOCPLINT->playerID); pos.w = background->pos.w; pos.h = background->pos.h; - moveTo(Point(centerX - pos.w/2, centerY - pos.h/2)); + moveTo(SPoint(centerX - pos.w/2, centerY - pos.h/2)); const CCreature * creature = CGI->creh->creatures[Town->creatures[level].second.back()]; @@ -279,8 +280,8 @@ CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstanc int posX = pos.w/2 - resAmount.size() * 25 + 5; for (size_t i=0; imoveBy(Point(posX, posY)); - resAmount[i]->moveBy(Point(posX+16, posY+43)); + resPicture[i]->moveBy(SPoint(posX, posY)); + resAmount[i]->moveBy(SPoint(posX+16, posY+43)); posX += 50; } } @@ -927,8 +928,8 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, int listPos): pos.h = builds->pos.h + panel->pos.h; center(); - garr = new CGarrisonInt(305, 387, 4, Point(0,96), panel->bg, Point(62,374), town->getUpperArmy(), town->visitingHero); - heroes = new HeroSlots(town, Point(241, 387), Point(241, 483), garr, true); + garr = new CGarrisonInt(305, 387, 4, SPoint(0,96), panel->bg, SPoint(62,374), town->getUpperArmy(), town->visitingHero); + heroes = new HeroSlots(town, SPoint(241, 387), SPoint(241, 483), garr, true); title = new CLabel(85, 387, FONT_MEDIUM, TOPLEFT, zwykly, town->name); income = new CLabel(195, 443, FONT_SMALL, CENTER); icon = new CAnimImage("ITPT", 0, 0, 15, 387); @@ -942,7 +943,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, int listPos): removeChild(split); garr->addSplitBtn(split); - Rect barRect(9, 182, 732, 18); + SRect barRect(9, 182, 732, 18); statusbar = new CGStatusBar(new CPicture(*panel, barRect, 9, 555, false)); resdatabar = new CResDataBar("ZRESBAR", 3, 575, 32, 2, 85, 85); @@ -1044,13 +1045,13 @@ void CCastleInterface::recreateIcons() creainfo.clear(); for (size_t i=0; i<4; i++) - creainfo.push_back(new CCreaInfo(Point(14+55*i, 459), town, i)); + creainfo.push_back(new CCreaInfo(SPoint(14+55*i, 459), town, i)); for (size_t i=0; i<4; i++) - creainfo.push_back(new CCreaInfo(Point(14+55*i, 507), town, i+4)); + creainfo.push_back(new CCreaInfo(SPoint(14+55*i, 507), town, i+4)); } -CCreaInfo::CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool compact, bool ShowAvailable): +CCreaInfo::CCreaInfo(SPoint position, const CGTownInstance *Town, int Level, bool compact, bool ShowAvailable): town(Town), level(Level), showAvailable(ShowAvailable) @@ -1262,7 +1263,7 @@ void CCastleInterface::keyPressed( const SDL_KeyboardEvent & key ) } } -HeroSlots::HeroSlots(const CGTownInstance * Town, Point garrPos, Point visitPos, CGarrisonInt *Garrison, bool ShowEmpty): +HeroSlots::HeroSlots(const CGTownInstance * Town, SPoint garrPos, SPoint visitPos, CGarrisonInt *Garrison, bool ShowEmpty): showEmpty(ShowEmpty), town(Town), garr(Garrison) @@ -1350,7 +1351,7 @@ CHallInterface::CHallInterface(const CGTownInstance *Town): resdatabar = new CMinorResDataBar; resdatabar->pos.x += pos.x; resdatabar->pos.y += pos.y; - Rect barRect(5, 556, 740, 18); + SRect barRect(5, 556, 740, 18); statusBar = new CGStatusBar(new CPicture(*background, barRect, 5, 556, false)); title = new CLabel(399, 12, FONT_MEDIUM, CENTER, zwykly, CGI->buildh->buildings[town->subID][town->hallLevel()+EBuilding::VILLAGE_HALL]->Name()); @@ -1453,13 +1454,13 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin background->colorize(LOCPLINT->playerID); buildingPic = new CAnimImage(graphics->buildingPics[town->subID], building->bid, 0, 125, 50); - Rect barRect(9, 494, 380, 18); + SRect barRect(9, 494, 380, 18); statusBar = new CGStatusBar(new CPicture(*background, barRect, 9, 494, false)); title = new CLabel(197, 30, FONT_MEDIUM, CENTER, zwykly, boost::str(boost::format(CGI->generaltexth->hcommands[7]) % building->Name())); - buildingDescr = new CTextBox(building->Description(), Rect(33, 135, 329, 67), 0, FONT_MEDIUM, CENTER); - buildingState = new CTextBox(getTextForState(state), Rect(33, 216, 329, 67), 0, FONT_SMALL, CENTER); + buildingDescr = new CTextBox(building->Description(), SRect(33, 135, 329, 67), 0, FONT_MEDIUM, CENTER); + buildingState = new CTextBox(getTextForState(state), SRect(33, 216, 329, 67), 0, FONT_SMALL, CENTER); //Create objects for all required resources for(int i = 0; imoveBy(Point(posX, posY)); - resAmount[index]->moveBy(Point(posX+16, posY+48)); + resPicture[index]->moveBy(SPoint(posX, posY)); + resAmount[index]->moveBy(SPoint(posX+16, posY+48)); posX += 80; index++; } @@ -1543,15 +1544,15 @@ CFortScreen::CFortScreen(const CGTownInstance * town) std::string text = boost::str(boost::format(CGI->generaltexth->fcommands[6]) % fortBuilding->Name()); exit = new AdventureMapButton(text, "", boost::bind(&CFortScreen::close,this) ,748, 556, "TPMAGE1", SDLK_RETURN); - std::vector positions; - positions += Point(10, 22), Point(404, 22), - Point(10, 155), Point(404,155), - Point(10, 288), Point(404,288); + std::vector positions; + positions += SPoint(10, 22), SPoint(404, 22), + SPoint(10, 155), SPoint(404,155), + SPoint(10, 288), SPoint(404,288); if (fortSize == GameConstants::CREATURES_PER_TOWN) - positions += Point(206,421); + positions += SPoint(206,421); else - positions += Point(10, 421), Point(404,421); + positions += SPoint(10, 421), SPoint(404,421); for (ui32 i=0; ipos.x += pos.x; resdatabar->pos.y += pos.y; - Rect barRect(4, 554, 740, 18); + SRect barRect(4, 554, 740, 18); statusBar = new CGStatusBar(new CPicture(*background, barRect, 4, 554, false)); } @@ -1582,7 +1583,7 @@ void CFortScreen::creaturesChanged() recAreas[i]->creaturesChanged(); } -LabeledValue::LabeledValue(Rect size, std::string name, std::string descr, int min, int max) +LabeledValue::LabeledValue(SRect size, std::string name, std::string descr, int min, int max) { pos.x+=size.x; pos.y+=size.y; @@ -1591,7 +1592,7 @@ LabeledValue::LabeledValue(Rect size, std::string name, std::string descr, int m init(name, descr, min, max); } -LabeledValue::LabeledValue(Rect size, std::string name, std::string descr, int val) +LabeledValue::LabeledValue(SRect size, std::string name, std::string descr, int val) { pos.x+=size.x; pos.y+=size.y; @@ -1654,7 +1655,7 @@ CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance * hoverText = boost::str(boost::format(CGI->generaltexth->tcommands[21]) % creature->namePl); creatureAnim = new CCreaturePic(159, 4, creature, false); - Rect sizes(287, 4, 96, 18); + SRect sizes(287, 4, 96, 18); values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[190], CGI->generaltexth->fcommands[0], creature->attack)); sizes.y+=20; values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[191], CGI->generaltexth->fcommands[1], creature->defence)); @@ -1718,20 +1719,20 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner) resdatabar = new CMinorResDataBar; resdatabar->pos.x += pos.x; resdatabar->pos.y += pos.y; - Rect barRect(7, 556, 737, 18); + SRect barRect(7, 556, 737, 18); statusBar = new CGStatusBar(new CPicture(*background, barRect, 7, 556, false)); exit = new AdventureMapButton(CGI->generaltexth->allTexts[593],"",boost::bind(&CMageGuildScreen::close,this), 748, 556,"TPMAGE1.DEF",SDLK_RETURN); exit->assignedKeys.insert(SDLK_ESCAPE); - std::vector > positions; + std::vector > positions; positions.resize(5); - positions[0] += Point(222,445), Point(312,445), Point(402,445), Point(520,445), Point(610,445), Point(700,445); - positions[1] += Point(48,53), Point(48,147), Point(48,241), Point(48,335), Point(48,429); - positions[2] += Point(570,82), Point(672,82), Point(570,157), Point(672,157); - positions[3] += Point(183,42), Point(183,148), Point(183,253); - positions[4] += Point(491,325), Point(591,325); + positions[0] += SPoint(222,445), SPoint(312,445), SPoint(402,445), SPoint(520,445), SPoint(610,445), SPoint(700,445); + positions[1] += SPoint(48,53), SPoint(48,147), SPoint(48,241), SPoint(48,335), SPoint(48,429); + positions[2] += SPoint(570,82), SPoint(672,82), SPoint(570,157), SPoint(672,157); + positions[3] += SPoint(183,42), SPoint(183,148), SPoint(183,253); + positions[4] += SPoint(491,325), SPoint(591,325); for(size_t i=0; itown->town->mageLevel; i++) { @@ -1751,7 +1752,7 @@ void CMageGuildScreen::close() GH.popIntTotally(this); } -CMageGuildScreen::Scroll::Scroll(Point position, const CSpell *Spell) +CMageGuildScreen::Scroll::Scroll(SPoint position, const CSpell *Spell) :spell(Spell) { OBJ_CONSTRUCTION_CAPTURING_ALL; @@ -1810,7 +1811,7 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, i animBG->needRefresh = true; const CCreature *creature = CGI->creh->creatures[creMachineID]; - anim = new CCreatureAnim(64, 50, creature->animDefName, Rect()); + anim = new CCreatureAnim(64, 50, creature->animDefName, SRect()); anim->clipRect(113,125,200,150); title = new CLabel(165, 28, FONT_BIG, CENTER, tytulowy, diff --git a/client/CCastleInterface.h b/client/CCastleInterface.h index e5a80045c..f9d71d7d4 100644 --- a/client/CCastleInterface.h +++ b/client/CCastleInterface.h @@ -2,7 +2,7 @@ #include "CAnimation.h" -#include "GUIBase.h" +#include "GUIClasses.h" class AdventureMapButton; class CBuilding; @@ -19,6 +19,9 @@ class CStatusBar; class CTextBox; class CTownList; struct Structure; +class CGHeroInstance; +class CGarrisonInt; +class CCreature; /* * CCastleInterface.h, part of VCMI engine @@ -101,7 +104,7 @@ public: CHeroGSlot * garrisonedHero; CHeroGSlot * visitingHero; - HeroSlots(const CGTownInstance * town, Point garrPos, Point visitPos, CGarrisonInt *Garrison, bool ShowEmpty); + HeroSlots(const CGTownInstance * town, SPoint garrPos, SPoint visitPos, CGarrisonInt *Garrison, bool ShowEmpty); void splitClicked(); //for hero meeting only (splitting stacks is handled by garrison int) void update(); @@ -162,7 +165,7 @@ class CCreaInfo : public CIntObject std::string genGrowthText(); public: - CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool compact=false, bool showAvailable=false); + CCreaInfo(SPoint position, const CGTownInstance *Town, int Level, bool compact=false, bool showAvailable=false); void update(); void hover(bool on); @@ -301,8 +304,8 @@ class LabeledValue : public CIntObject void init(std::string name, std::string descr, int min, int max); public: - LabeledValue(Rect size, std::string name, std::string descr, int min, int max); - LabeledValue(Rect size, std::string name, std::string descr, int val); + LabeledValue(SRect size, std::string name, std::string descr, int min, int max); + LabeledValue(SRect size, std::string name, std::string descr, int val); void hover(bool on); }; @@ -356,7 +359,7 @@ class CMageGuildScreen : public CIntObject CAnimImage *image; public: - Scroll(Point position, const CSpell *Spell); + Scroll(SPoint position, const CSpell *Spell); void clickLeft(tribool down, bool previousState); void clickRight(tribool down, bool previousState); void hover(bool on); diff --git a/client/CCreatureWindow.cpp b/client/CCreatureWindow.cpp index 7a83b02bc..fd4308814 100644 --- a/client/CCreatureWindow.cpp +++ b/client/CCreatureWindow.cpp @@ -20,6 +20,8 @@ #include "../lib/BattleState.h" #include "../lib/CSpellHandler.h" +#include "UIFramework/CGuiHandler.h" + using namespace CSDL_Ext; class CBonusItem; @@ -242,7 +244,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * number = (stack->count * (expmax - expmin)) / expmin; boost::replace_first (expText, "%i", boost::lexical_cast(number)); //Maximum New Recruits to remain at Rank 10 if at Maximum Experience - expArea = new LRClickableAreaWTextComp(Rect(334, 49, 160, 44),SComponent::experience); + expArea = new LRClickableAreaWTextComp(SRect(334, 49, 160, 44),SComponent::experience); expArea->text = expText; expArea->bonusValue = 0; //TDO: some specific value or no number at all } @@ -276,7 +278,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * int duration = battleStack->getBonus(Selector::source(Bonus::SPELL_EFFECT,effect))->turnsRemain; boost::replace_first (spellText, "%d", boost::lexical_cast(duration)); blitAt(graphics->spellEffectsPics->ourImages[effect + 1].bitmap, 20 + 52 * printed, 184, *bitmap); - spellEffects.push_back(new LRClickableAreaWText(Rect(20 + 52 * printed, 184, 50, 38), spellText, spellText)); + spellEffects.push_back(new LRClickableAreaWText(SRect(20 + 52 * printed, 184, 50, 38), spellText, spellText)); if (++printed >= 10) //we can fit only 10 effects break; } @@ -327,7 +329,7 @@ void CCreatureWindow::recreateSkillList(int Pos) int offsetx = 257*j - (bonusRows == 4 ? 1 : 0); int offsety = 60*i + (bonusRows > 1 ? 1 : 0); //lack of precision :/ - bonusItems[n]->moveTo (Point(pos.x + offsetx + 10, pos.y + offsety + 230), true); + bonusItems[n]->moveTo (SPoint(pos.x + offsetx + 10, pos.y + offsety + 230), true); bonusItems[n]->visible = true; if (++j > 1) //next line @@ -426,7 +428,7 @@ CBonusItem::CBonusItem() } -CBonusItem::CBonusItem(const Rect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName) +CBonusItem::CBonusItem(const SRect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName) { OBJ_CONSTRUCTION; visible = false; diff --git a/client/CCreatureWindow.h b/client/CCreatureWindow.h index 9358d79b0..3c752f53c 100644 --- a/client/CCreatureWindow.h +++ b/client/CCreatureWindow.h @@ -1,7 +1,6 @@ #pragma once -#include "GUIBase.h" #include "GUIClasses.h" #include "../lib/HeroBonus.h" @@ -79,7 +78,7 @@ public: bool visible; CBonusItem(); - CBonusItem(const Rect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName); + CBonusItem(const SRect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName); ~CBonusItem(); void setBonus (const Bonus &bonus); diff --git a/client/CHeroWindow.cpp b/client/CHeroWindow.cpp index 778acfefe..4ddda141c 100644 --- a/client/CHeroWindow.cpp +++ b/client/CHeroWindow.cpp @@ -22,6 +22,8 @@ #include "../lib/CLodHandler.h" #include "../lib/CObjectHandler.h" +#include "UIFramework/CGuiHandler.h" + #undef min /* @@ -82,7 +84,7 @@ CHeroWindow * CHeroSwitcher::getOwner() CHeroSwitcher::CHeroSwitcher(int serial) { - pos = Rect(612, 87 + serial * 54, 48, 32) + pos; + pos = SRect(612, 87 + serial * 54, 48, 32) + pos; id = serial; used = LCLICK; } @@ -122,26 +124,26 @@ CHeroWindow::CHeroWindow(const CGHeroInstance *hero) flags = CDefHandler::giveDefEss("CREST58.DEF"); //areas - portraitArea = new LRClickableAreaWText(Rect(18, 18, 58, 64)); + portraitArea = new LRClickableAreaWText(SRect(18, 18, 58, 64)); for(int v=0; vtext = CGI->generaltexth->arraytxt[2+v]; area->type = v; area->hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1]) % CGI->generaltexth->primarySkillNames[v]); primSkillAreas.push_back(area); } - specArea = new LRClickableAreaWText(Rect(18, 180, 136, 42), CGI->generaltexth->heroscrn[27]); - expArea = new LRClickableAreaWText(Rect(18, 228, 136, 42), CGI->generaltexth->heroscrn[9]); - morale = new MoraleLuckBox(true, Rect(175,179,53,45)); - luck = new MoraleLuckBox(false, Rect(233,179,53,45)); - spellPointsArea = new LRClickableAreaWText(Rect(162,228, 136, 42), CGI->generaltexth->heroscrn[22]); + specArea = new LRClickableAreaWText(SRect(18, 180, 136, 42), CGI->generaltexth->heroscrn[27]); + expArea = new LRClickableAreaWText(SRect(18, 228, 136, 42), CGI->generaltexth->heroscrn[9]); + morale = new MoraleLuckBox(true, SRect(175,179,53,45)); + luck = new MoraleLuckBox(false, SRect(233,179,53,45)); + spellPointsArea = new LRClickableAreaWText(SRect(162,228, 136, 42), CGI->generaltexth->heroscrn[22]); for(int i = 0; i < std::min(hero->secSkills.size(), 8u); ++i) { - Rect r = Rect(i%2 == 0 ? 18 : 162, 276 + 48 * (i/2), 136, 42); + SRect r = SRect(i%2 == 0 ? 18 : 162, 276 + 48 * (i/2), 136, 42); secSkillAreas.push_back(new LRClickableAreaWTextComp(r, SComponent::secskill)); } @@ -195,7 +197,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded /*= fals OBJ_CONSTRUCTION_CAPTURING_ALL; if(!garr) { - garr = new CGarrisonInt(15, 485, 8, Point(), background->bg, Point(15,485), curHero); + garr = new CGarrisonInt(15, 485, 8, SPoint(), background->bg, SPoint(15,485), curHero); { BLOCK_CAPTURING; split = new AdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::bind(&CGarrisonInt::splitClick,garr), pos.x + 539, pos.y + 519, "hsbtns9.def", false, NULL, false); //deleted by garrison destructor @@ -205,7 +207,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded /*= fals } if(!artSets.size()) { - CArtifactsOfHero *arts = new CArtifactsOfHero(Point(-65, -8), true); + CArtifactsOfHero *arts = new CArtifactsOfHero(SPoint(-65, -8), true); arts->setHero(curHero); artSets.push_back(arts); } @@ -243,7 +245,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded /*= fals //if we have exchange window with this curHero open bool noDismiss=false; - BOOST_FOREACH(IShowActivable *isa, GH.listInt) + BOOST_FOREACH(IShowActivatable *isa, GH.listInt) { if(CExchangeWindow * cew = dynamic_cast(isa)) for(int g=0; g < ARRAY_COUNT(cew->heroInst); ++g) diff --git a/client/CKingdomInterface.cpp b/client/CKingdomInterface.cpp index d9f21225b..d088d3171 100644 --- a/client/CKingdomInterface.cpp +++ b/client/CKingdomInterface.cpp @@ -13,6 +13,7 @@ #include "CConfigHandler.h" #include "CGameInfo.h" #include "CPlayerInterface.h" //LOCPLINT +#include "UIFramework/CGuiHandler.h" /* * CKingdomInterface.cpp, part of VCMI engine @@ -26,7 +27,7 @@ extern SDL_Surface *screenBuf; -InfoBox::InfoBox(Point position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data): +InfoBox::InfoBox(SPoint position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data): size(Size), infoPos(Pos), data(Data), @@ -469,7 +470,7 @@ CKingdomInterface::CKingdomInterface() pos = background->center(); ui32 footerPos = conf.go()->ac.overviewSize * 116; - tabArea = new CTabbedInt(boost::bind(&CKingdomInterface::createMainTab, this, _1), CTabbedInt::DestroyFunc(), Point(4,4)); + tabArea = new CTabbedInt(boost::bind(&CKingdomInterface::createMainTab, this, _1), CTabbedInt::DestroyFunc(), SPoint(4,4)); std::vector ownedObjects = LOCPLINT->cb->getMyObjects(); generateObjectsList(ownedObjects); @@ -530,7 +531,7 @@ void CKingdomInterface::generateObjectsList(const std::vector(obj.count); - return new InfoBox(Point(), InfoBox::POS_CORNER, InfoBox::SIZE_SMALL, + return new InfoBox(SPoint(), InfoBox::POS_CORNER, InfoBox::SIZE_SMALL, new InfoBoxCustom(value,"", "FLAGPORT", obj.imageID, obj.hoverText)); } return NULL; @@ -593,11 +594,11 @@ void CKingdomInterface::generateMinesList(const std::vector(minesCount[i]); - minesBox[i] = new InfoBox(Point(20+i*80, 31+footerPos), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, + minesBox[i] = new InfoBox(SPoint(20+i*80, 31+footerPos), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, new InfoBoxCustom(value, "", "OVMINES", i, CGI->generaltexth->mines[i].first)); } incomeArea = new HoverableArea; - incomeArea->pos = Rect(pos.x+580, pos.y+31+footerPos, 136, 68); + incomeArea->pos = SRect(pos.x+580, pos.y+31+footerPos, 136, 68); incomeArea->hoverText = CGI->generaltexth->allTexts[255]; incomeAmount = new CLabel(628, footerPos + 70, FONT_SMALL, TOPLEFT, zwykly, boost::lexical_cast(totalIncome)); } @@ -690,7 +691,7 @@ CKingdHeroList::CKingdHeroList(size_t maxSize) ui32 townCount = LOCPLINT->cb->howManyHeroes(false); ui32 size = conf.go()->ac.overviewSize*116 + 19; heroes = new CListBox(boost::bind(&CKingdHeroList::createHeroItem, this, _1), boost::bind(&CKingdHeroList::destroyHeroItem, this, _1), - Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size) ); + SPoint(19,21), SPoint(0,116), maxSize, townCount, 0, 1, SRect(-19, -21, size, size) ); } void CKingdHeroList::updateGarrisons() @@ -743,7 +744,7 @@ CKingdTownList::CKingdTownList(size_t maxSize) ui32 townCount = LOCPLINT->cb->howManyTowns(); ui32 size = conf.go()->ac.overviewSize*116 + 19; towns = new CListBox(boost::bind(&CKingdTownList::createTownItem, this, _1), CListBox::DestroyFunc(), - Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size) ); + SPoint(19,21), SPoint(0,116), maxSize, townCount, 0, 1, SRect(-19, -21, size, size) ); } void CKingdTownList::townChanged(const CGTownInstance *town) @@ -789,8 +790,8 @@ CTownItem::CTownItem(const CGTownInstance* Town): hall = new CTownInfo( 69, 31, town, true); fort = new CTownInfo(111, 31, town, false); - garr = new CGarrisonInt(313, 3, 4, Point(232,0), NULL, Point(313,2), town->getUpperArmy(), town->visitingHero, true, true, true); - heroes = new HeroSlots(town, Point(244,6), Point(475,6), garr, false); + garr = new CGarrisonInt(313, 3, 4, SPoint(232,0), NULL, SPoint(313,2), town->getUpperArmy(), town->visitingHero, true, true, true); + heroes = new HeroSlots(town, SPoint(244,6), SPoint(475,6), garr, false); size_t iconIndex = town->subID*2; if (!town->hasFort()) @@ -801,13 +802,13 @@ CTownItem::CTownItem(const CGTownInstance* Town): picture = new CAnimImage("ITPT", iconIndex, 0, 5, 6); townArea = new LRClickableAreaOpenTown; - townArea->pos = Rect(pos.x+5, pos.y+6, 58, 64); + townArea->pos = SRect(pos.x+5, pos.y+6, 58, 64); townArea->town = town; for (size_t i=0; icreatures.size(); i++) { - growth.push_back(new CCreaInfo(Point(401+37*i, 78), town, i, true, true)); - available.push_back(new CCreaInfo(Point(48+37*i, 78), town, i, true, false)); + growth.push_back(new CCreaInfo(SPoint(401+37*i, 78), town, i, true, true)); + available.push_back(new CCreaInfo(SPoint(48+37*i, 78), town, i, true, false)); } } @@ -846,7 +847,7 @@ public: background = new CAnimImage("OVSLOT", 4); pos = background->pos; for (size_t i=0; i<9; i++) - arts.push_back(new CArtPlace(Point(270+i*48, 65))); + arts.push_back(new CArtPlace(SPoint(270+i*48, 65))); } }; @@ -866,7 +867,7 @@ public: btnLeft = new AdventureMapButton(std::string(), std::string(), CFunctionList(), 269, 66, "HSBTNS3"); btnRight = new AdventureMapButton(std::string(), std::string(), CFunctionList(), 675, 66, "HSBTNS5"); for (size_t i=0; i<8; i++) - arts.push_back(new CArtPlace(Point(295+i*48, 65))); + arts.push_back(new CArtPlace(SPoint(295+i*48, 65))); } }; @@ -916,7 +917,7 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart * artButtons->onChange += boost::bind(&CHeroItem::onArtChange, this, _1); artButtons->select(0,0); - garr = new CGarrisonInt(6, 78, 4, Point(), NULL, Point(), hero, NULL, true, true); + garr = new CGarrisonInt(6, 78, 4, SPoint(), NULL, SPoint(), hero, NULL, true, true); portrait = new CAnimImage("PortraitsLarge", hero->subID, 0, 5, 6); heroArea = new CHeroArea(5, 6, hero); @@ -925,24 +926,24 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart * artsText = new CLabel(320, 55, FONT_SMALL, CENTER, zwykly, CGI->generaltexth->overview[2]); for (size_t i=0; iset(hero); luck->set(hero); diff --git a/client/CKingdomInterface.h b/client/CKingdomInterface.h index 178673d31..5f689d690 100644 --- a/client/CKingdomInterface.h +++ b/client/CKingdomInterface.h @@ -1,7 +1,6 @@ #pragma once -#include "GUIBase.h" #include "GUIClasses.h" class AdventureMapButton; @@ -65,7 +64,7 @@ private: HoverableArea *hover; public: - InfoBox(Point position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data); + InfoBox(SPoint position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data); ~InfoBox(); void clickRight(tribool down, bool previousState); diff --git a/client/CMT.cpp b/client/CMT.cpp index 5f4a9871c..6b4a361ae 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -38,6 +38,7 @@ #include "../lib/CArtHandler.h" #include "../lib/CScriptingModule.h" #include "../lib/GameConstants.h" +#include "UIFramework/CGuiHandler.h" #ifdef _WIN32 #include "SDL_syswm.h" @@ -95,7 +96,7 @@ void startGame(StartInfo * options, CConnection *serv = NULL); void init() { - StopWatch tmh, pomtime; + CStopWatch tmh, pomtime; #if SDL_BYTEORDER == SDL_BIG_ENDIAN int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff; #else @@ -220,7 +221,7 @@ int main(int argc, char** argv) putenv((char*)"SDL_VIDEO_WINDOW_POS"); putenv((char*)"SDL_VIDEO_CENTERED=1"); - StopWatch total, pomtime; + CStopWatch total, pomtime; std::cout.flags(std::ios::unitbuf); logfile = new std::ofstream((GVCMIDirs.UserPath + "/VCMI_Client_log.txt").c_str()); console = new CConsoleHandler; @@ -479,7 +480,7 @@ void processCommand(const std::string &message) } else if(cn == "gui") { - BOOST_FOREACH(const IShowActivable *child, GH.listInt) + BOOST_FOREACH(const IShowActivatable *child, GH.listInt) { if(const CIntObject *obj = dynamic_cast(child)) printInfoAboutIntObject(obj, 0); diff --git a/client/CMessage.cpp b/client/CMessage.cpp index e479fc02c..24e3a9863 100644 --- a/client/CMessage.cpp +++ b/client/CMessage.cpp @@ -106,8 +106,8 @@ SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for { for (int j=0; jh) { - Rect srcR(0,0,background->w, background->h); - Rect dstR(i,j,w,h); + SRect srcR(0,0,background->w, background->h); + SRect dstR(i,j,w,h); CSDL_Ext::blitSurface(background, &srcR, ret, &dstR); } } @@ -446,7 +446,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player) curh = (ret->bitmap->h - ret->text->pos.h)/2; } - ret->text->moveBy(Point(xOffset, curh)); + ret->text->moveBy(SPoint(xOffset, curh)); curh += ret->text->pos.h; @@ -463,7 +463,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player) for(size_t i=0; ibuttons.size(); i++) { - ret->buttons[i]->moveBy(Point(bw, curh)); + ret->buttons[i]->moveBy(SPoint(bw, curh)); bw += ret->buttons[i]->pos.w + 20; } } @@ -493,8 +493,8 @@ void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int cur_w = box[6]->w; // Top border - Rect srcR(0, 0, cur_w, box[6]->h); - Rect dstR(start_x, y, 0, 0); + SRect srcR(0, 0, cur_w, box[6]->h); + SRect dstR(start_x, y, 0, 0); CSDL_Ext::blitSurface(box[6], &srcR, ret, &dstR); // Bottom border @@ -514,8 +514,8 @@ void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int cur_h = box[4]->h; // Left border - Rect srcR(0, 0, box[4]->w, cur_h); - Rect dstR(x, start_y, 0, 0); + SRect srcR(0, 0, box[4]->w, cur_h); + SRect dstR(x, start_y, 0, 0); CSDL_Ext::blitSurface(box[4], &srcR, ret, &dstR); // Right border @@ -526,16 +526,16 @@ void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int } //corners - Rect dstR(x, y, box[0]->w, box[0]->h); + SRect dstR(x, y, box[0]->w, box[0]->h); CSDL_Ext::blitSurface(box[0], NULL, ret, &dstR); - dstR=Rect(x+w-box[1]->w, y, box[1]->w, box[1]->h); + dstR=SRect(x+w-box[1]->w, y, box[1]->w, box[1]->h); CSDL_Ext::blitSurface(box[1], NULL, ret, &dstR); - dstR=Rect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h); + dstR=SRect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h); CSDL_Ext::blitSurface(box[2], NULL, ret, &dstR); - dstR=Rect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h); + dstR=SRect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h); CSDL_Ext::blitSurface(box[3], NULL, ret, &dstR); } diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index b34c91c99..31630cc94 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -15,7 +15,7 @@ #include "SDL_Extensions.h" #include "SDL_framerate.h" #include "CConfigHandler.h" -#include "CCreatureAnimation.h" +#include "BattleInterface/CCreatureAnimation.h" #include "Graphics.h" #include "../lib/CArtHandler.h" #include "../lib/CGeneralTextHandler.h" @@ -32,10 +32,11 @@ #include "../lib/map.h" #include "../lib/VCMIDirs.h" #include "mapHandler.h" -#include "../lib/StopWatch.h" +#include "../lib/CStopWatch.h" #include "../lib/StartInfo.h" #include "../lib/CGameState.h" #include "../lib/GameConstants.h" +#include "UIFramework/CGuiHandler.h" #ifdef min #undef min @@ -482,7 +483,7 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town) c->garr->recreateSlots(); c->heroes->update(); } - BOOST_FOREACH(IShowActivable *isa, GH.listInt) + BOOST_FOREACH(IShowActivatable *isa, GH.listInt) { CKingdomInterface *ki = dynamic_cast(isa); if (ki) @@ -508,9 +509,9 @@ void CPlayerInterface::garrisonChanged( const CGObjectInstance * obj, bool updat if(updateInfobox) updateInfo(obj); - for(std::list::iterator i = GH.listInt.begin(); i != GH.listInt.end(); i++) + for(std::list::iterator i = GH.listInt.begin(); i != GH.listInt.end(); i++) { - if((*i)->type & IShowActivable::WITH_GARRISON) + if((*i)->type & IShowActivatable::WITH_GARRISON) { CGarrisonHolder *cgh = dynamic_cast(*i); cgh->updateGarrisons(); @@ -755,7 +756,7 @@ void CPlayerInterface::battleEnd(const BattleResult *br) battleInt->battleFinished(*br); } -void CPlayerInterface::battleStackMoved(const CStack * stack, std::vector dest, int distance) +void CPlayerInterface::battleStackMoved(const CStack * stack, std::vector dest, int distance) { if(LOCPLINT != this) { //another local interface should do this @@ -873,10 +874,10 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba) else { int shift = 0; - if(ba->counter() && SHexField::mutualPosition(curAction->destinationTile, attacker->position) < 0) + if(ba->counter() && SBattleHex::mutualPosition(curAction->destinationTile, attacker->position) < 0) { - int distp = SHexField::getDistance(curAction->destinationTile + 1, attacker->position); - int distm = SHexField::getDistance(curAction->destinationTile - 1, attacker->position); + int distp = SBattleHex::getDistance(curAction->destinationTile + 1, attacker->position); + int distm = SBattleHex::getDistance(curAction->destinationTile - 1, attacker->position); if( distp < distm ) shift = 1; @@ -1052,7 +1053,7 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town ) if(fs) fs->creaturesChanged(); - BOOST_FOREACH(IShowActivable *isa, GH.listInt) + BOOST_FOREACH(IShowActivatable *isa, GH.listInt) { CKingdomInterface *ki = dynamic_cast(isa); if (ki && townObj) @@ -2339,9 +2340,9 @@ void CPlayerInterface::artifactPut(const ArtifactLocation &al) void CPlayerInterface::artifactRemoved(const ArtifactLocation &al) { boost::unique_lock un(*pim); - BOOST_FOREACH(IShowActivable *isa, GH.listInt) + BOOST_FOREACH(IShowActivatable *isa, GH.listInt) { - if(isa->type & IShowActivable::WITH_ARTIFACTS) + if(isa->type & IShowActivatable::WITH_ARTIFACTS) { (dynamic_cast(isa))->artifactRemoved(al); } @@ -2351,9 +2352,9 @@ void CPlayerInterface::artifactRemoved(const ArtifactLocation &al) void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst) { boost::unique_lock un(*pim); - BOOST_FOREACH(IShowActivable *isa, GH.listInt) + BOOST_FOREACH(IShowActivatable *isa, GH.listInt) { - if(isa->type & IShowActivable::WITH_ARTIFACTS) + if(isa->type & IShowActivatable::WITH_ARTIFACTS) { (dynamic_cast(isa))->artifactMoved(src, dst); } @@ -2363,9 +2364,9 @@ void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const Artifact void CPlayerInterface::artifactAssembled(const ArtifactLocation &al) { boost::unique_lock un(*pim); - BOOST_FOREACH(IShowActivable *isa, GH.listInt) + BOOST_FOREACH(IShowActivatable *isa, GH.listInt) { - if(isa->type & IShowActivable::WITH_ARTIFACTS) + if(isa->type & IShowActivatable::WITH_ARTIFACTS) { (dynamic_cast(isa))->artifactAssembled(al); } @@ -2375,9 +2376,9 @@ void CPlayerInterface::artifactAssembled(const ArtifactLocation &al) void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al) { boost::unique_lock un(*pim); - BOOST_FOREACH(IShowActivable *isa, GH.listInt) + BOOST_FOREACH(IShowActivatable *isa, GH.listInt) { - if(isa->type & IShowActivable::WITH_ARTIFACTS) + if(isa->type & IShowActivatable::WITH_ARTIFACTS) { (dynamic_cast(isa))->artifactDisassembled(al); } diff --git a/client/CPlayerInterface.h b/client/CPlayerInterface.h index 933bbf2a7..34d689ee2 100644 --- a/client/CPlayerInterface.h +++ b/client/CPlayerInterface.h @@ -2,9 +2,9 @@ #include "../lib/CondSh.h" -#include "GUIBase.h" #include "FunctionList.h" #include "../lib/CGameInterface.h" +#include "UIFramework/IUpdateable.h" #ifdef __GNUC__ #define sprintf_s snprintf @@ -55,7 +55,7 @@ class CInGameConsole; union SDL_Event; class IStatusBar; class CInfoWindow; -class IShowActivable; +class IShowActivatable; class ClickableL; class ClickableR; class Hoverable; @@ -218,7 +218,7 @@ public: void battleEnd(const BattleResult *br) OVERRIDE; //end of battle void battleNewRoundFirst(int round) OVERRIDE; //called at the beginning of each turn before changes are applied; used for HP regen handling void battleNewRound(int round) OVERRIDE; //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; + void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; void battleSpellCast(const BattleSpellCast *sc) OVERRIDE; void battleStacksEffectsSet(const SetStackEffect & sse) OVERRIDE; //called when a specific effect is set to stacks void battleTriggerEffect(const BattleTriggerEffect & bte) OVERRIDE; //various one-shot effect diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index f6c9e0d4c..b02af4996 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -2,7 +2,7 @@ #include "CPreGame.h" #include -#include "../lib/StopWatch.h" +#include "../lib/CStopWatch.h" #include "SDL_Extensions.h" #include "CGameInfo.h" #include "CCursorHandler.h" @@ -39,6 +39,7 @@ #include "CConfigHandler.h" #include "../lib/CFileUtility.h" #include "../lib/GameConstants.h" +#include "UIFramework/CGuiHandler.h" /* * CPreGame.cpp, part of VCMI engine @@ -360,7 +361,7 @@ CreditsScreen::CreditsScreen() std::string text = bitmaph->getTextFile("CREDITS"); size_t firstQuote = text.find('\"')+1; text = text.substr(firstQuote, text.find('\"', firstQuote) - firstQuote ); - credits = new CTextBox(text, Rect(450, 600, 350, 32000), 0, FONT_CREDITS, CENTER, zwykly); + credits = new CTextBox(text, SRect(450, 600, 350, 32000), 0, FONT_CREDITS, CENTER, zwykly); credits->pos.h = credits->maxH; } @@ -493,7 +494,7 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti sh->startServer(); } - IShowActivable::type = BLOCK_ADV_HOTKEYS; + IShowActivatable::type = BLOCK_ADV_HOTKEYS; pos.w = 762; pos.h = 584; if(Type == CMenuScreen::saveGame) @@ -1088,7 +1089,7 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::functionbutton.x, GH.current->button.y); + SPoint clickPos(GH.current->button.x, GH.current->button.y); clickPos = clickPos - pos.topLeft(); if (clickPos.y > 115 && clickPos.y < 564 && clickPos.x > 22 && clickPos.x < 371) @@ -1474,7 +1475,7 @@ void SelectionTab::selectFName( const std::string &fname ) -CChatBox::CChatBox(const Rect &rect) +CChatBox::CChatBox(const SRect &rect) { OBJ_CONSTRUCTION; pos += rect; @@ -1482,9 +1483,9 @@ CChatBox::CChatBox(const Rect &rect) captureAllKeys = true; const int height = graphics->fonts[FONT_SMALL]->height; - inputBox = new CTextInput(Rect(0, rect.h - height, rect.w, height)); + inputBox = new CTextInput(SRect(0, rect.h - height, rect.w, height)); inputBox->used &= ~KEYBOARD; - chatHistory = new CTextBox("", Rect(0, 0, rect.w, rect.h - height), 1); + chatHistory = new CTextBox("", SRect(0, 0, rect.w, rect.h - height), 1); SDL_Color green = {0,252,0}; chatHistory->color = green; @@ -1517,18 +1518,18 @@ InfoCard::InfoCard( bool Network ) used = RCLICK; mapDescription = NULL; - Rect descriptionRect(26, 149, 320, 115); + SRect descriptionRect(26, 149, 320, 115); mapDescription = new CTextBox("", descriptionRect, 1); if(SEL->screenType == CMenuScreen::campaignList) { CSelectionScreen *ss = static_cast(parent); - moveChild(new CPicture(*ss->bg, descriptionRect + Point(-393, 0)), this, mapDescription, true); //move subpicture bg to our description control (by default it's our (Infocard) child) + CGuiHandler::moveChild(new CPicture(*ss->bg, descriptionRect + SPoint(-393, 0)), this, mapDescription, true); //move subpicture bg to our description control (by default it's our (Infocard) child) } else { bg = new CPicture(BitmapHandler::loadBitmap("GSELPOP1.bmp"), 0, 0, true); - moveChild(bg, this, parent); + CGuiHandler::moveChild(bg, this, parent); parent->children.insert(parent->children.begin()+1, bg); parent->children.pop_back(); pos.w = bg->pos.w; @@ -1549,13 +1550,13 @@ InfoCard::InfoCard( bool Network ) difficulty->block(true); //description needs bg - moveChild(new CPicture(*bg, descriptionRect), this, mapDescription, true); //move subpicture bg to our description control (by default it's our (Infocard) child) + CGuiHandler::moveChild(new CPicture(*bg, descriptionRect), this, mapDescription, true); //move subpicture bg to our description control (by default it's our (Infocard) child) if(network) { playerListBg = new CPicture("CHATPLUG.bmp", 16, 276); chat = new CChatBox(descriptionRect); - moveChild(new CPicture(*bg, chat->chatHistory->pos - pos), this, chat->chatHistory, true); //move subpicture bg to our description control (by default it's our (Infocard) child) + CGuiHandler::moveChild(new CPicture(*bg, chat->chatHistory->pos - pos), this, chat->chatHistory, true); //move subpicture bg to our description control (by default it's our (Infocard) child) chatOn = true; mapDescription->disable(); @@ -1752,7 +1753,7 @@ void InfoCard::changeSelection( const CMapInfo *to ) void InfoCard::clickRight( tribool down, bool previousState ) { - static const Rect flagArea(19, 397, 335, 23); + static const SRect flagArea(19, 397, 335, 23); if(down && SEL->current && isItInLoc(flagArea, GH.current->motion.x, GH.current->motion.y)) showTeamsPopup(); } @@ -2128,7 +2129,7 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSet serial++; } - pos = parent->pos + Point(54, 122 + serial*50); + pos = parent->pos + SPoint(54, 122 + serial*50); static const char *flags[] = {"AOFLGBR.DEF", "AOFLGBB.DEF", "AOFLGBY.DEF", "AOFLGBG.DEF", "AOFLGBO.DEF", "AOFLGBP.DEF", "AOFLGBT.DEF", "AOFLGBS.DEF"}; @@ -2173,11 +2174,11 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSet defActions &= ~SHARE_POS; town = new SelectedBox(TOWN, s.color); - town->pos += pos + Point(119, 2); + town->pos += pos + SPoint(119, 2); hero = new SelectedBox(HERO, s.color); - hero->pos += pos + Point(195, 2); + hero->pos += pos + SPoint(195, 2); bonus = new SelectedBox(BONUS, s.color); - bonus->pos += pos + Point(271, 2); + bonus->pos += pos + SPoint(271, 2); } void OptionsTab::PlayerOptionsEntry::showAll( SDL_Surface * to ) @@ -2615,8 +2616,8 @@ CMultiMode::CMultiMode() blitAt(CPicture("MUMAP.bmp"), 16, 77, *bg); //blit img pos = bg->center(); //center, window has size of bg graphic - bar = new CGStatusBar(new CPicture(Rect(7, 465, 440, 18), 0));//226, 472 - txt = new CTextInput(Rect(19, 436, 334, 16), *bg); + bar = new CGStatusBar(new CPicture(SRect(7, 465, 440, 18), 0));//226, 472 + txt = new CTextInput(SRect(19, 436, 334, 16), *bg); txt->setText(GDefaultOptions.playerName); //Player btns[0] = new AdventureMapButton(CGI->generaltexth->zelp[266], bind(&CMultiMode::openHotseat, this), 373, 78, "MUBHOT.DEF"); @@ -2652,18 +2653,18 @@ CHotSeatPlayers::CHotSeatPlayers(const std::string &firstPlayer) std::string text = CGI->generaltexth->allTexts[446]; boost::replace_all(text, "\t","\n"); - Rect boxRect(25, 20, 315, 50); + SRect boxRect(25, 20, 315, 50); title = new CTextBox(text, boxRect, 0, FONT_BIG, CENTER, zwykly);//HOTSEAT Please enter names for(int i = 0; i < ARRAY_COUNT(txt); i++) { - txt[i] = new CTextInput(Rect(60, 85 + i*30, 280, 16), *bg); + txt[i] = new CTextInput(SRect(60, 85 + i*30, 280, 16), *bg); txt[i]->cb += boost::bind(&CHotSeatPlayers::onChange, this, _1); } ok = new AdventureMapButton(CGI->generaltexth->zelp[560], bind(&CHotSeatPlayers::enterSelectionScreen, this), 95, 338, "MUBCHCK.DEF", SDLK_RETURN); cancel = new AdventureMapButton(CGI->generaltexth->zelp[561], bind(&CGuiHandler::popIntTotally, ref(GH), this), 205, 338, "MUBCANC.DEF", SDLK_ESCAPE); - bar = new CGStatusBar(new CPicture(Rect(7, 381, 348, 18), 0));//226, 472 + bar = new CGStatusBar(new CPicture(SRect(7, 381, 348, 18), 0));//226, 472 txt[0]->setText(firstPlayer, true); txt[0]->giveFocus(); @@ -2727,11 +2728,11 @@ CBonusSelection::CBonusSelection( CCampaignState * _ourCampaign ) //campaign description printAtLoc(CGI->generaltexth->allTexts[38], 481, 63, FONT_SMALL, tytulowy, background); - cmpgDesc = new CTextBox(ourCampaign->camp->header.description, Rect(480, 86, 286, 117), 1); + cmpgDesc = new CTextBox(ourCampaign->camp->header.description, SRect(480, 86, 286, 117), 1); cmpgDesc->showAll(background); //map description - mapDesc = new CTextBox("", Rect(480, 280, 286, 117), 1); + mapDesc = new CTextBox("", SRect(480, 280, 286, 117), 1); //bonus choosing printAtLoc(CGI->generaltexth->allTexts[71], 511, 432, FONT_MEDIUM, zwykly, background); //Choose a bonus: @@ -3495,7 +3496,7 @@ CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode &config ) image = new CPicture(config["image"].String()); hoverLabel = new CLabel(pos.w / 2, pos.h + 20, FONT_MEDIUM, CENTER, tytulowy, ""); - moveChild(hoverLabel, this, parent); + CGuiHandler::moveChild(hoverLabel, this, parent); } if (status == CCampaignScreen::COMPLETED) diff --git a/client/CPreGame.h b/client/CPreGame.h index fa5a8676b..a2281b76e 100644 --- a/client/CPreGame.h +++ b/client/CPreGame.h @@ -3,10 +3,10 @@ #include #include "../lib/StartInfo.h" -#include "GUIBase.h" #include "GUIClasses.h" #include "FunctionList.h" #include "../lib/CMapInfo.h" +#include "UIFramework/IUpdateable.h" /* * CPreGame.h, part of VCMI engine @@ -103,7 +103,7 @@ public: CTextBox *chatHistory; CTextInput *inputBox; - CChatBox(const Rect &rect); + CChatBox(const SRect &rect); void keyPressed(const SDL_KeyboardEvent & key); diff --git a/client/CSpellWindow.cpp b/client/CSpellWindow.cpp index cb8453351..b292d88d3 100644 --- a/client/CSpellWindow.cpp +++ b/client/CSpellWindow.cpp @@ -18,6 +18,7 @@ #include "../lib/CHeroHandler.h" #include "../lib/BattleState.h" #include "../lib/GameConstants.h" +#include "UIFramework/CGuiHandler.h" /* * CSpellWindow.cpp, part of VCMI engine @@ -550,12 +551,12 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key) if(LOCPLINT->altPressed()) { SDLKey hlpKey = key.keysym.sym; - if(isNumKey(hlpKey, false)) + if(CGuiHandler::isNumKey(hlpKey, false)) { if(hlpKey == SDLK_KP_PLUS) hlpKey = SDLK_EQUALS; else - hlpKey = numToDigit(hlpKey); + hlpKey = CGuiHandler::numToDigit(hlpKey); } static const SDLKey spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS}; diff --git a/client/CSpellWindow.h b/client/CSpellWindow.h index d5325b192..93d9d23f0 100644 --- a/client/CSpellWindow.h +++ b/client/CSpellWindow.h @@ -1,7 +1,6 @@ #pragma once - -#include "GUIBase.h" +#include "UIFramework/CIntObject.h" /* * CSpellWindow.h, part of VCMI engine @@ -18,6 +17,7 @@ class CDefHandler; struct SDL_Rect; class CGHeroInstance; class CStatusBar; +class CPlayerInterface; /// Spellbook button is used by the spell window class class SpellbookInteractiveArea : public CIntObject diff --git a/client/Client.cpp b/client/Client.cpp index c6b66a0af..ce0fa55b8 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -27,13 +27,13 @@ #include "mapHandler.h" #include "CConfigHandler.h" #include "Client.h" -#include "GUIBase.h" #include "CPreGame.h" #include "BattleInterface/CBattleInterface.h" #include "../lib/CThreadHelper.h" #include "../lib/CScriptingModule.h" #include "../lib/CFileUtility.h" #include "../lib/RegisterTypes.h" +#include "UIFramework/CGuiHandler.h" extern std::string NAME; namespace intpr = boost::interprocess; @@ -222,7 +222,7 @@ void CClient::loadGame( const std::string & fname ) CServerHandler sh; sh.startServer(); - StopWatch tmh; + CStopWatch tmh; { char sig[8]; CMapHeader dum; @@ -306,7 +306,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) - StopWatch tmh; + CStopWatch tmh; const_cast(CGI)->state = new CGameState(); tlog0 <<"\tGamestate: "<scenarioOps->mode == StartInfo::DUEL) - new CBattleInterface(info->belligerents[0], info->belligerents[1], info->heroes[0], info->heroes[1], Rect((conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2, 800, 600), att, def); + new CBattleInterface(info->belligerents[0], info->belligerents[1], info->heroes[0], info->heroes[1], SRect((conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2, 800, 600), att, def); if(vstd::contains(battleints,info->sides[0])) battleints[info->sides[0]]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 0); diff --git a/client/Client.h b/client/Client.h index a26593800..279e6a3b9 100644 --- a/client/Client.h +++ b/client/Client.h @@ -3,7 +3,7 @@ #include "../lib/IGameCallback.h" #include "../lib/CondSh.h" -#include "../lib/StopWatch.h" +#include "../lib/CStopWatch.h" /* * Client.h, part of VCMI engine @@ -38,7 +38,7 @@ class CServerHandler private: void callServer(); //calls server via system(), should be called as thread public: - StopWatch th; + CStopWatch th; boost::thread *serverThread; //thread that called system to run server SharedMem *shared; //interprocess memory (for waiting for server) bool verbose; //whether to print log msgs diff --git a/client/GUIBase.cpp b/client/GUIBase.cpp deleted file mode 100644 index cffb9e8ca..000000000 --- a/client/GUIBase.cpp +++ /dev/null @@ -1,1071 +0,0 @@ -#include "StdInc.h" -#include "SDL_Extensions.h" -#include "GUIBase.h" - -#include "CGameInfo.h" -#include "CCursorHandler.h" -#include "CBitmapHandler.h" -#include "Graphics.h" -#include "../lib/CThreadHelper.h" -#include "CConfigHandler.h" - -/* - * GUIBase.cpp, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -extern std::queue events; -extern boost::mutex eventsM; - - -SDL_Color Colors::MetallicGold = createColor(173, 142, 66); -SDL_Color Colors::Yellow = createColor(242, 226, 110); - -SDL_Color Colors::createColor(int r, int g, int b) -{ - SDL_Color temp = {r, g, b, 0}; - return temp; -} - -void KeyShortcut::keyPressed(const SDL_KeyboardEvent & key) -{ - if(vstd::contains(assignedKeys,key.keysym.sym)) - { - bool prev = pressedL; - if(key.state == SDL_PRESSED) - { - pressedL = true; - clickLeft(true, prev); - } - else - { - pressedL = false; - clickLeft(false, prev); - } - } -} - - -void CGuiHandler::popInt( IShowActivable *top ) -{ - assert(listInt.front() == top); - top->deactivate(); - listInt.pop_front(); - objsToBlit -= top; - if(listInt.size()) - listInt.front()->activate(); - totalRedraw(); -} - -void CGuiHandler::popIntTotally( IShowActivable *top ) -{ - assert(listInt.front() == top); - popInt(top); - delete top; - fakeMouseMove(); -} - -void CGuiHandler::pushInt( IShowActivable *newInt ) -{ - //a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway) - screenBuf = screen2; - - if(listInt.size()) - listInt.front()->deactivate(); - listInt.push_front(newInt); - newInt->activate(); - objsToBlit.push_back(newInt); - totalRedraw(); -} - -void CGuiHandler::popInts( int howMany ) -{ - if(!howMany) return; //senseless but who knows... - - assert(listInt.size() >= howMany); - listInt.front()->deactivate(); - for(int i=0; i < howMany; i++) - { - objsToBlit -= listInt.front(); - delete listInt.front(); - listInt.pop_front(); - } - - if(listInt.size()) - { - listInt.front()->activate(); - totalRedraw(); - } - fakeMouseMove(); -} - -IShowActivable * CGuiHandler::topInt() -{ - if(!listInt.size()) - return NULL; - else - return listInt.front(); -} - -void CGuiHandler::totalRedraw() -{ - for(int i=0;ishowAll(screen2); - - blitAt(screen2,0,0,screen); -} - -void CGuiHandler::updateTime() -{ - int tv = th.getDiff(); - std::list hlp = timeinterested; - for (std::list::iterator i=hlp.begin(); i != hlp.end();i++) - { - if(!vstd::contains(timeinterested,*i)) continue; - if ((*i)->toNextTick>=0) - (*i)->toNextTick-=tv; - if ((*i)->toNextTick<0) - (*i)->tick(); - } -} - -void CGuiHandler::handleEvents() -{ - while(true) - { - SDL_Event *ev = NULL; - boost::unique_lock lock(eventsM); - if(!events.size()) - { - return; - } - else - { - ev = events.front(); - events.pop(); - } - handleEvent(ev); - delete ev; - } -} - -void CGuiHandler::handleEvent(SDL_Event *sEvent) -{ - current = sEvent; - bool prev; - - if (sEvent->type==SDL_KEYDOWN || sEvent->type==SDL_KEYUP) - { - SDL_KeyboardEvent key = sEvent->key; - - //translate numpad keys - if(key.keysym.sym == SDLK_KP_ENTER) - { - key.keysym.sym = (SDLKey)SDLK_RETURN; - } - - bool keysCaptured = false; - for(std::list::iterator i=keyinterested.begin(); i != keyinterested.end() && current; i++) - { - if((*i)->captureAllKeys) - { - keysCaptured = true; - break; - } - } - - std::list miCopy = keyinterested; - for(std::list::iterator i=miCopy.begin(); i != miCopy.end() && current; i++) - if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureAllKeys)) - (**i).keyPressed(key); - } - else if(sEvent->type==SDL_MOUSEMOTION) - { - CCS->curh->cursorMove(sEvent->motion.x, sEvent->motion.y); - handleMouseMotion(sEvent); - } - else if (sEvent->type==SDL_MOUSEBUTTONDOWN) - { - if(sEvent->button.button == SDL_BUTTON_LEFT) - { - - if(lastClick == sEvent->motion && (SDL_GetTicks() - lastClickTime) < 300) - { - std::list hlp = doubleClickInterested; - for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) - { - if(!vstd::contains(doubleClickInterested,*i)) continue; - if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) - { - (*i)->onDoubleClick(); - } - } - - } - - lastClick = sEvent->motion; - lastClickTime = SDL_GetTicks(); - - std::list hlp = lclickable; - for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) - { - if(!vstd::contains(lclickable,*i)) continue; - if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) - { - prev = (*i)->pressedL; - (*i)->pressedL = true; - (*i)->clickLeft(true, prev); - } - } - } - else if (sEvent->button.button == SDL_BUTTON_RIGHT) - { - std::list hlp = rclickable; - for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) - { - if(!vstd::contains(rclickable,*i)) continue; - if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) - { - prev = (*i)->pressedR; - (*i)->pressedR = true; - (*i)->clickRight(true, prev); - } - } - } - else if(sEvent->button.button == SDL_BUTTON_WHEELDOWN || sEvent->button.button == SDL_BUTTON_WHEELUP) - { - std::list hlp = wheelInterested; - for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) - { - if(!vstd::contains(wheelInterested,*i)) continue; - (*i)->wheelScrolled(sEvent->button.button == SDL_BUTTON_WHEELDOWN, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)); - } - } - } - else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT)) - { - std::list hlp = lclickable; - for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) - { - if(!vstd::contains(lclickable,*i)) continue; - prev = (*i)->pressedL; - (*i)->pressedL = false; - if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) - { - (*i)->clickLeft(false, prev); - } - else - (*i)->clickLeft(boost::logic::indeterminate, prev); - } - } - else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT)) - { - std::list hlp = rclickable; - for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) - { - if(!vstd::contains(rclickable,*i)) continue; - prev = (*i)->pressedR; - (*i)->pressedR = false; - if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) - { - (*i)->clickRight(false, prev); - } - else - (*i)->clickRight(boost::logic::indeterminate, prev); - } - } - current = NULL; - -} //event end - -void CGuiHandler::handleMouseMotion(SDL_Event *sEvent) -{ - //sending active, hovered hoverable objects hover() call - std::vector hlp; - for(std::list::iterator i=hoverable.begin(); i != hoverable.end();i++) - { - if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) - { - if (!(*i)->hovered) - hlp.push_back((*i)); - } - else if ((*i)->hovered) - { - (*i)->hover(false); - (*i)->hovered = false; - } - } - for(int i=0; ihover(true); - hlp[i]->hovered = true; - } - - handleMoveInterested(sEvent->motion); -} - -void CGuiHandler::simpleRedraw() -{ - //update only top interface and draw background - if(objsToBlit.size() > 1) - blitAt(screen2,0,0,screen); //blit background - objsToBlit.back()->show(screen); //blit active interface/window -} - -void CGuiHandler::handleMoveInterested( const SDL_MouseMotionEvent & motion ) -{ - //sending active, MotionInterested objects mouseMoved() call - std::list miCopy = motioninterested; - for(std::list::iterator i=miCopy.begin(); i != miCopy.end();i++) - { - if ((*i)->strongInterest || isItIn(&(*i)->pos, motion.x, motion.y)) - { - (*i)->mouseMoved(motion); - } - } -} - -void CGuiHandler::fakeMouseMove() -{ - SDL_Event evnt; - - SDL_MouseMotionEvent sme = {SDL_MOUSEMOTION, 0, 0, 0, 0, 0, 0}; - int x, y; - sme.state = SDL_GetMouseState(&x, &y); - sme.x = x; - sme.y = y; - - evnt.motion = sme; - current = &evnt; - handleMouseMotion(&evnt); -} - -void CGuiHandler::run() -{ - setThreadName(-1, "CGuiHandler::run"); - try - { - if (conf.cc.fullscreen) - CCS->curh->centerCursor(); - - mainFPSmng->init(); // resets internal clock, needed for FPS manager - while(!terminate) - { - if(curInt) - curInt->update(); // calls a update and drawing process of the loaded game interface object at the moment - - mainFPSmng->framerateDelay(); // holds a constant FPS - } - } HANDLE_EXCEPTION -} - -CGuiHandler::CGuiHandler() -:lastClick(-500, -500) -{ - curInt = NULL; - current = NULL; - terminate = false; - statusbar = NULL; - - // Creates the FPS manager and sets the framerate to 48 which is doubled the value of the original Heroes 3 FPS rate - mainFPSmng = new FPSManager(48); - mainFPSmng->init(); // resets internal clock, needed for FPS manager -} - -CGuiHandler::~CGuiHandler() -{ - delete mainFPSmng; -} - -void CGuiHandler::breakEventHandling() -{ - current = NULL; -} - -void CGuiHandler::drawFPSCounter() -{ - const static SDL_Color yellow = {255, 255, 0, 0}; - static SDL_Rect overlay = { 0, 0, 64, 32}; - Uint32 black = SDL_MapRGB(screen->format, 10, 10, 10); - SDL_FillRect(screen, &overlay, black); - std::string fps = boost::lexical_cast(mainFPSmng->fps); - CSDL_Ext::printAt(fps, 10, 10, FONT_BIG, yellow, screen); -} - - -void CIntObject::activateLClick() -{ - GH.lclickable.push_front(this); - active |= LCLICK; -} - -void CIntObject::deactivateLClick() -{ - std::list::iterator hlp = std::find(GH.lclickable.begin(),GH.lclickable.end(),this); - assert(hlp != GH.lclickable.end()); - GH.lclickable.erase(hlp); - active &= ~LCLICK; -} - -void CIntObject::clickLeft(tribool down, bool previousState) -{ -} - -void CIntObject::activateRClick() -{ - GH.rclickable.push_front(this); - active |= RCLICK; -} - -void CIntObject::deactivateRClick() -{ - std::list::iterator hlp = std::find(GH.rclickable.begin(),GH.rclickable.end(),this); - assert(hlp != GH.rclickable.end()); - GH.rclickable.erase(hlp); - active &= ~RCLICK; -} - -void CIntObject::clickRight(tribool down, bool previousState) -{ -} - -void CIntObject::activateHover() -{ - GH.hoverable.push_front(this); - active |= HOVER; -} - -void CIntObject::deactivateHover() -{ - std::list::iterator hlp = std::find(GH.hoverable.begin(),GH.hoverable.end(),this); - assert(hlp != GH.hoverable.end()); - GH.hoverable.erase(hlp); - active &= ~HOVER; -} - -void CIntObject::hover( bool on ) -{ -} - -void CIntObject::activateKeys() -{ - GH.keyinterested.push_front(this); - active |= KEYBOARD; -} - -void CIntObject::deactivateKeys() -{ - std::list::iterator hlp = std::find(GH.keyinterested.begin(),GH.keyinterested.end(),this); - assert(hlp != GH.keyinterested.end()); - GH.keyinterested.erase(hlp); - active &= ~KEYBOARD; -} - -void CIntObject::keyPressed( const SDL_KeyboardEvent & key ) -{ -} - -void CIntObject::activateMouseMove() -{ - GH.motioninterested.push_front(this); - active |= MOVE; -} - -void CIntObject::deactivateMouseMove() -{ - std::list::iterator hlp = std::find(GH.motioninterested.begin(),GH.motioninterested.end(),this); - assert(hlp != GH.motioninterested.end()); - GH.motioninterested.erase(hlp); - active &= ~MOVE; -} - -void CIntObject::mouseMoved( const SDL_MouseMotionEvent & sEvent ) -{ -} - -void CIntObject::activateTimer() -{ - GH.timeinterested.push_back(this); - active |= TIME; -} - -void CIntObject::deactivateTimer() -{ - std::list::iterator hlp = std::find(GH.timeinterested.begin(),GH.timeinterested.end(),this); - assert(hlp != GH.timeinterested.end()); - GH.timeinterested.erase(hlp); - active &= ~TIME; -} - -void CIntObject::tick() -{ -} - -CIntObject::CIntObject() -{ - pressedL = pressedR = hovered = captureAllKeys = strongInterest = false; - toNextTick = active = used = 0; - - recActions = defActions = GH.defActionsDef; - - pos.x = 0; - pos.y = 0; - pos.w = 0; - pos.h = 0; - - if(GH.captureChildren) - { - assert(GH.createdObj.size()); - parent = GH.createdObj.front(); - parent->children.push_back(this); - - if(parent->defActions & SHARE_POS) - { - pos.x = parent->pos.x; - pos.y = parent->pos.y; - } - } - else - parent = NULL; -} - -void CIntObject::show( SDL_Surface * to ) -{ - if(defActions & UPDATE) - for(size_t i = 0; i < children.size(); i++) - if(children[i]->recActions & UPDATE) - children[i]->show(to); -} - -void CIntObject::showAll( SDL_Surface * to ) -{ - if(defActions & SHOWALL) - { - for(size_t i = 0; i < children.size(); i++) - if(children[i]->recActions & SHOWALL) - children[i]->showAll(to); - - } - else - show(to); -} - -void CIntObject::activate() -{ - assert(!active); - active |= GENERAL; - activate(used); - - if(defActions & ACTIVATE) - for(size_t i = 0; i < children.size(); i++) - if(children[i]->recActions & ACTIVATE) - children[i]->activate(); -} - -void CIntObject::activate(ui16 what) -{ - if(what & LCLICK) - activateLClick(); - if(what & RCLICK) - activateRClick(); - if(what & HOVER) - activateHover(); - if(what & MOVE) - activateMouseMove(); - if(what & KEYBOARD) - activateKeys(); - if(what & TIME) - activateTimer(); - if(what & WHEEL) - activateWheel(); - if(what & DOUBLECLICK) - activateDClick(); -} - -void CIntObject::deactivate() -{ - assert(active); - active &= ~ GENERAL; - deactivate(used); - - assert(!active); - - if(defActions & DEACTIVATE) - for(size_t i = 0; i < children.size(); i++) - if(children[i]->recActions & DEACTIVATE) - children[i]->deactivate(); -} - -void CIntObject::deactivate(ui16 what) -{ - if(what & LCLICK) - deactivateLClick(); - if(what & RCLICK) - deactivateRClick(); - if(what & HOVER) - deactivateHover(); - if(what & MOVE) - deactivateMouseMove(); - if(what & KEYBOARD) - deactivateKeys(); - if(what & TIME) // TIME is special - deactivateTimer(); - if(what & WHEEL) - deactivateWheel(); - if(what & DOUBLECLICK) - deactivateDClick(); -} - -CIntObject::~CIntObject() -{ - assert(!active); //do not delete active obj - - if(defActions & DISPOSE) - for(size_t i = 0; i < children.size(); i++) - if(children[i]->recActions & DISPOSE) - delete children[i]; - - if(parent && GH.createdObj.size()) //temporary object destroyed - parent->children -= this; -} - -void CIntObject::printAtLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ ) -{ - CSDL_Ext::printAt(text, pos.x + x, pos.y + y, font, kolor, dst); -} - -void CIntObject::printAtMiddleLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ ) -{ - CSDL_Ext::printAtMiddle(text, pos.x + x, pos.y + y, font, kolor, dst); -} - -void CIntObject::printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, SDL_Color kolor, SDL_Surface * dst) -{ - printAtMiddleLoc(text, p.x, p.y, font, kolor, dst); -} - -void CIntObject::blitAtLoc( SDL_Surface * src, int x, int y, SDL_Surface * dst ) -{ - blitAt(src, pos.x + x, pos.y + y, dst); -} - -void CIntObject::blitAtLoc(SDL_Surface * src, const Point &p, SDL_Surface * dst) -{ - blitAtLoc(src, p.x, p.y, dst); -} - -void CIntObject::printAtMiddleWBLoc( const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor, SDL_Surface * dst) -{ - CSDL_Ext::printAtMiddleWB(text, pos.x + x, pos.y + y, font, charpr, kolor, dst); -} - -void CIntObject::printToLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst ) -{ - CSDL_Ext::printTo(text, pos.x + x, pos.y + y, font, kolor, dst); -} - -void CIntObject::disable() -{ - if(active) - deactivate(); - - recActions = DISPOSE; -} - -void CIntObject::enable(bool activation) -{ - if(!active && activation) - activate(); - - recActions = 255; -} - -bool CIntObject::isItInLoc( const SDL_Rect &rect, int x, int y ) -{ - return isItIn(&rect, x - pos.x, y - pos.y); -} - -bool CIntObject::isItInLoc( const SDL_Rect &rect, const Point &p ) -{ - return isItIn(&rect, p.x - pos.x, p.y - pos.y); -} - -void CIntObject::activateWheel() -{ - GH.wheelInterested.push_front(this); - active |= WHEEL; -} - -void CIntObject::deactivateWheel() -{ - std::list::iterator hlp = std::find(GH.wheelInterested.begin(),GH.wheelInterested.end(),this); - assert(hlp != GH.wheelInterested.end()); - GH.wheelInterested.erase(hlp); - active &= ~WHEEL; -} - -void CIntObject::wheelScrolled(bool down, bool in) -{ -} - -void CIntObject::activateDClick() -{ - GH.doubleClickInterested.push_front(this); - active |= DOUBLECLICK; -} - -void CIntObject::deactivateDClick() -{ - std::list::iterator hlp = std::find(GH.doubleClickInterested.begin(),GH.doubleClickInterested.end(),this); - assert(hlp != GH.doubleClickInterested.end()); - GH.doubleClickInterested.erase(hlp); - active &= ~DOUBLECLICK; -} - -void CIntObject::onDoubleClick() -{ -} - -const Rect & CIntObject::center( const Rect &r, bool propagate ) -{ - pos.w = r.w; - pos.h = r.h; - return center(Point(screen->w/2, screen->h/2), propagate); -} - -const Rect & CIntObject::center( bool propagate ) -{ - return center(pos, propagate); -} - -const Rect & CIntObject::center(const Point &p, bool propagate /*= true*/) -{ - moveBy(Point(p.x - pos.w/2 - pos.x, - p.y - pos.h/2 - pos.y), - propagate); - return pos; -} - -void CIntObject::fitToScreen(int borderWidth, bool propagate) -{ - Point newPos = pos.topLeft(); - vstd::amax(newPos.x, borderWidth); - vstd::amax(newPos.y, borderWidth); - vstd::amin(newPos.x, screen->w - borderWidth - pos.w); - vstd::amin(newPos.y, screen->h - borderWidth - pos.h); - if (newPos != pos.topLeft()) - moveTo(newPos, propagate); -} - -void CIntObject::moveBy( const Point &p, bool propagate /*= true*/ ) -{ - pos.x += p.x; - pos.y += p.y; - if(propagate) - for(size_t i = 0; i < children.size(); i++) - children[i]->moveBy(p, propagate); -} - -void CIntObject::moveTo( const Point &p, bool propagate /*= true*/ ) -{ - moveBy(Point(p.x - pos.x, p.y - pos.y), propagate); -} - -void CIntObject::delChild(CIntObject *child) -{ - children -= child; - delete child; -} - -void CIntObject::addChild(CIntObject *child, bool adjustPosition /*= false*/) -{ - assert(!vstd::contains(children, child)); - assert(child->parent == NULL); - children.push_back(child); - child->parent = this; - if(adjustPosition) - child->pos += pos; -} - -void CIntObject::removeChild(CIntObject *child, bool adjustPosition /*= false*/) -{ - assert(vstd::contains(children, child)); - assert(child->parent == this); - children -= child; - child->parent = NULL; - if(adjustPosition) - child->pos -= pos; -} - -void CIntObject::changeUsedEvents(ui16 what, bool enable, bool adjust /*= true*/) -{ - if(enable) - { - used |= what; - if(adjust && active) - activate(what); - } - else - { - used &= ~what; - if(adjust && active) - deactivate(what); - } -} - -void CIntObject::drawBorderLoc(SDL_Surface * sur, const Rect &r, const int3 &color) -{ - CSDL_Ext::drawBorder(sur, r + pos, color); -} - -CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free ) -{ - init(); - bg = BG; - freeSurf = Free; - pos.x += x; - pos.y += y; - pos.w = BG->w; - pos.h = BG->h; -} - -CPicture::CPicture( const std::string &bmpname, int x, int y ) -{ - init(); - bg = BitmapHandler::loadBitmap(bmpname); - freeSurf = true;; - pos.x += x; - pos.y += y; - if(bg) - { - pos.w = bg->w; - pos.h = bg->h; - } - else - { - pos.w = pos.h = 0; - } -} - -CPicture::CPicture(const Rect &r, const SDL_Color &color, bool screenFormat /*= false*/) -{ - init(); - createSimpleRect(r, screenFormat, SDL_MapRGB(bg->format, color.r, color.g,color.b)); -} - -CPicture::CPicture(const Rect &r, ui32 color, bool screenFormat /*= false*/) -{ - init(); - createSimpleRect(r, screenFormat, color); -} - -CPicture::CPicture(SDL_Surface *BG, const Rect &SrcRect, int x /*= 0*/, int y /*= 0*/, bool free /*= false*/) -{ - needRefresh = false; - srcRect = new Rect(SrcRect); - pos.x += x; - pos.y += y; - pos.w = srcRect->w; - pos.h = srcRect->h; - bg = BG; - freeSurf = free; -} - -CPicture::~CPicture() -{ - if(freeSurf) - SDL_FreeSurface(bg); - delete srcRect; -} - -void CPicture::init() -{ - needRefresh = false; - srcRect = NULL; -} - -void CPicture::show( SDL_Surface * to ) -{ - if (needRefresh) - showAll(to); -} - -void CPicture::showAll( SDL_Surface * to ) -{ - if(bg) - { - if(srcRect) - { - SDL_Rect srcRectCpy = *srcRect; - SDL_Rect dstRect = srcRectCpy; - dstRect.x = pos.x; - dstRect.y = pos.y; - - CSDL_Ext::blitSurface(bg, &srcRectCpy, to, &dstRect); - } - else - blitAt(bg, pos, to); - } -} - -void CPicture::convertToScreenBPP() -{ - SDL_Surface *hlp = bg; - bg = SDL_ConvertSurface(hlp,screen->format,0); - SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); - SDL_FreeSurface(hlp); -} - -void CPicture::createSimpleRect(const Rect &r, bool screenFormat, ui32 color) -{ - pos += r; - pos.w = r.w; - pos.h = r.h; - if(screenFormat) - bg = CSDL_Ext::newSurface(r.w, r.h); - else - bg = SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 8, 0, 0, 0, 0); - - SDL_FillRect(bg, NULL, color); - freeSurf = true; -} - -void CPicture::colorizeAndConvert(int player) -{ - assert(bg); - colorize(player); - convertToScreenBPP(); -} - -void CPicture::colorize(int player) -{ - assert(bg); - assert(bg->format->BitsPerPixel == 8); - graphics->blueToPlayersAdv(bg, player); -} - -ObjectConstruction::ObjectConstruction( CIntObject *obj ) - :myObj(obj) -{ - GH.createdObj.push_front(obj); - GH.captureChildren = true; -} - -ObjectConstruction::~ObjectConstruction() -{ - assert(GH.createdObj.size()); - assert(GH.createdObj.front() == myObj); - GH.createdObj.pop_front(); - GH.captureChildren = GH.createdObj.size(); -} - -SetCaptureState::SetCaptureState(bool allow, ui8 actions) -{ - previousCapture = GH.captureChildren; - GH.captureChildren = false; - prevActions = GH.defActionsDef; - GH.defActionsDef = actions; -} - -SetCaptureState::~SetCaptureState() -{ - GH.captureChildren = previousCapture; - GH.defActionsDef = prevActions; -} - -void CIntObject::redraw() -{ - if (parent && (type & REDRAW_PARENT)) - { - parent->redraw(); - } - else - { - showAll(screenBuf); - if(screenBuf != screen) - showAll(screen); - } -} - -SDLKey arrowToNum( SDLKey key ) -{ - switch(key) - { - case SDLK_DOWN: - return SDLK_KP2; - case SDLK_UP: - return SDLK_KP8; - case SDLK_LEFT: - return SDLK_KP4; - case SDLK_RIGHT: - return SDLK_KP6; - default: - assert(0); - } - throw std::string("Wrong key!"); -} - -SDLKey numToDigit( SDLKey key ) -{ - if(key >= SDLK_KP0 && key <= SDLK_KP9) - return SDLKey(key - SDLK_KP0 + SDLK_0); - -#define REMOVE_KP(keyName) case SDLK_KP_ ## keyName : return SDLK_ ## keyName; - switch(key) - { - REMOVE_KP(PERIOD) - REMOVE_KP(MINUS) - REMOVE_KP(PLUS) - REMOVE_KP(EQUALS) - - case SDLK_KP_MULTIPLY: - return SDLK_ASTERISK; - case SDLK_KP_DIVIDE: - return SDLK_SLASH; - case SDLK_KP_ENTER: - return SDLK_RETURN; - default: - tlog3 << "Illegal numkey conversion!" << std::endl; - return SDLK_UNKNOWN; - } -#undef REMOVE_KP -} - -bool isNumKey( SDLKey key, bool number ) -{ - if(number) - return key >= SDLK_KP0 && key <= SDLK_KP9; - else - return key >= SDLK_KP0 && key <= SDLK_KP_EQUALS; -} - -bool isArrowKey( SDLKey key ) -{ - return key >= SDLK_UP && key <= SDLK_LEFT; -} - -CIntObject * moveChild(CIntObject *obj, CIntObject *from, CIntObject *to, bool adjustPos) -{ - from->removeChild(obj, adjustPos); - to->addChild(obj, adjustPos); - return obj; -} -Rect Rect::createCentered( int w, int h ) -{ - return Rect(screen->w/2 - w/2, screen->h/2 - h/2, w, h); -} - -Rect Rect::around(const Rect &r, int width /*= 1*/) /*creates rect around another */ -{ - return Rect(r.x - width, r.y - width, r.w + width * 2, r.h + width * 2); -} - -Rect Rect::centerIn(const Rect &r) -{ - return Rect(r.x + (r.w - w) / 2, r.y + (r.h - h) / 2, w, h); -} diff --git a/client/GUIBase.h b/client/GUIBase.h deleted file mode 100644 index 764c51ca1..000000000 --- a/client/GUIBase.h +++ /dev/null @@ -1,626 +0,0 @@ -#pragma once - - -#include "../lib/int3.h" -#include "SDL.h" -#include "../lib/StopWatch.h" -#include "FontBase.h" -#include "SDL_framerate.h" - -#ifdef max -#undef max -#endif -#ifdef min -#undef min -#endif - -/* - * GUIBase.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -class CDefEssential; -class AdventureMapButton; -class CHighlightableButtonsGroup; -class CDefHandler; -struct HeroMoveDetails; -class CDefEssential; -class CGHeroInstance; -class CAdvMapInt; -class CCastleInterface; -class CBattleInterface; -class CStack; -class SComponent; -class CCreature; -struct SDL_Surface; -struct CPath; -class CCreatureAnimation; -class CSelectableComponent; -class CCreatureSet; -class CGObjectInstance; -class CSlider; -struct UpgradeInfo; -template struct CondSh; -class CInGameConsole; -class CGarrisonInt; -class CInGameConsole; -struct Component; -class CArmedInstance; -class CGTownInstance; -class StackState; -class CPlayerInterface; - -using boost::logic::tribool; - -/// A point with x/y coordinate, used mostly for graphic rendering -struct Point -{ - int x, y; - - //constructors - Point() - { - x = y = 0; - }; - Point(int X, int Y) - :x(X),y(Y) - {}; - Point(const int3 &a) - :x(a.x),y(a.y) - {} - Point(const SDL_MouseMotionEvent &a) - :x(a.x),y(a.y) - {} - - template - Point operator+(const T &b) const - { - return Point(x+b.x,y+b.y); - } - - template - Point operator*(const T &mul) const - { - return Point(x*mul, y*mul); - } - - template - Point& operator+=(const T &b) - { - x += b.x; - y += b.y; - return *this; - } - - template - Point operator-(const T &b) const - { - return Point(x - b.x, y - b.y); - } - - template - Point& operator-=(const T &b) - { - x -= b.x; - y -= b.y; - return *this; - } - bool operator<(const Point &b) const //product order - { - return x < b.x && y < b.y; - } - template Point& operator=(const T &t) - { - x = t.x; - y = t.y; - return *this; - } - template bool operator==(const T &t) const - { - return x == t.x && y == t.y; - } - template bool operator!=(const T &t) const - { - return !(*this == t); - } -}; - -/// Rectangle class, which have a position and a size -struct Rect : public SDL_Rect -{ - Rect()//default c-tor - { - x = y = w = h = -1; - } - Rect(int X, int Y, int W, int H) //c-tor - { - x = X; - y = Y; - w = W; - h = H; - } - Rect(const Point &position, const Point &size) //c-tor - { - x = position.x; - y = position.y; - w = size.x; - h = size.y; - } - Rect(const SDL_Rect & r) //c-tor - { - x = r.x; - y = r.y; - w = r.w; - h = r.h; - } - explicit Rect(const SDL_Surface * const &surf) - { - x = y = 0; - w = surf->w; - h = surf->h; - } - - Rect centerIn(const Rect &r); - static Rect createCentered(int w, int h); - static Rect around(const Rect &r, int width = 1); //creates rect around another - - bool isIn(int qx, int qy) const //determines if given point lies inside rect - { - if (qx > x && qxy && qy Rect operator-(const T &t) - { - return Rect(x - t.x, y - t.y, w, h); - } - Rect operator&(const Rect &p) const //rect intersection - { - bool intersect = true; - - if(p.topLeft().y < y && p.bottomLeft().y < y) //rect p is above *this - { - intersect = false; - } - else if(p.topLeft().y > y+h && p.bottomLeft().y > y+h) //rect p is below *this - { - intersect = false; - } - else if(p.topLeft().x > x+w && p.topRight().x > x+w) //rect p is on the right hand side of this - { - intersect = false; - } - else if(p.topLeft().x < x && p.topRight().x < x) //rect p is on the left hand side of this - { - intersect = false; - } - - if(intersect) - { - Rect ret; - ret.x = std::max(this->x, p.x); - ret.y = std::max(this->y, p.y); - Point bR; //bottomRight point of returned rect - bR.x = std::min(this->w+this->x, p.w+p.x); - bR.y = std::min(this->h+this->y, p.h+p.y); - ret.w = bR.x - ret.x; - ret.h = bR.y - ret.y; - return ret; - } - else - { - return Rect(); - } - } - Rect operator|(const Rect &p) const //union of two rects - { - Rect ret; - ret.x = std::min(p.x, this->x); - ret.y = std::min(p.y, this->y); - int x2 = std::max(p.x+p.w, this->x+this->w); - int y2 = std::max(p.y+p.h, this->y+this->h); - ret.w = x2 -ret.x; - ret.h = y2 -ret.y; - return ret; - } -}; - -/// Defines a show method -class IShowable -{ -public: - virtual void redraw()=0; - virtual void show(SDL_Surface * to)=0; - virtual void showAll(SDL_Surface * to) - { - show(to); - } - virtual ~IShowable(){}; //d-tor -}; - -/// Status bar interface -class IStatusBar -{ -public: - virtual ~IStatusBar(){}; //d-tor - virtual void print(const std::string & text)=0; //prints text and refreshes statusbar - virtual void clear()=0;//clears statusbar and refreshes - virtual void show(SDL_Surface * to)=0; //shows statusbar (with current text) - virtual std::string getCurrent()=0; //returns currently displayed text -}; - -/// Defines a activate/deactive method -class IActivable -{ -public: - virtual void activate()=0; - virtual void deactivate()=0; - virtual ~IActivable(){}; //d-tor -}; - - -class IShowActivable : public IShowable, public IActivable -{ -public: - //redraw parent flag - this int may be semi-transparent and require redraw of parent window - enum {WITH_GARRISON = 1, BLOCK_ADV_HOTKEYS = 2, WITH_ARTIFACTS = 4, REDRAW_PARENT=8}; - int type; //bin flags using etype - IShowActivable(); - virtual ~IShowActivable(){}; //d-tor -}; - - -class IUpdateable -{ -public: - virtual void update()=0; - virtual ~IUpdateable(){}; //d-tor -}; - -/// Base UI element -class CIntObject : public IShowActivable //interface object -{ -public: - CIntObject *parent; //parent object - std::vector children; - - Rect pos, //position of object on the screen - posRelative; //position of object in the parent (not used if no parent) - - CIntObject(); - virtual ~CIntObject(); //d-tor - - //l-clicks handling - bool pressedL; //for determining if object is L-pressed - void activateLClick(); - void deactivateLClick(); - virtual void clickLeft(tribool down, bool previousState); - - //r-clicks handling - bool pressedR; //for determining if object is R-pressed - void activateRClick(); - void deactivateRClick(); - virtual void clickRight(tribool down, bool previousState); - - //hover handling - bool hovered; //for determining if object is hovered - void activateHover(); - void deactivateHover(); - virtual void hover (bool on); - - //keyboard handling - bool captureAllKeys; //if true, only this object should get info about pressed keys - void activateKeys(); - void deactivateKeys(); - virtual void keyPressed(const SDL_KeyboardEvent & key); - - //mouse movement handling - bool strongInterest; //if true - report all mouse movements, if not - only when hovered - void activateMouseMove(); - void deactivateMouseMove(); - virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent); - - //time handling - int toNextTick; - void activateTimer(); - void deactivateTimer(); - virtual void tick(); - - //mouse wheel - void activateWheel(); - void deactivateWheel(); - virtual void wheelScrolled(bool down, bool in); - - //double click - void activateDClick(); - void deactivateDClick(); - virtual void onDoubleClick(); - - enum {LCLICK=1, RCLICK=2, HOVER=4, MOVE=8, KEYBOARD=16, TIME=32, GENERAL=64, WHEEL=128, DOUBLECLICK=256, ALL=0xffff}; - ui16 active; - ui16 used; - - enum {ACTIVATE=1, DEACTIVATE=2, UPDATE=4, SHOWALL=8, DISPOSE=16, SHARE_POS=32}; - ui8 defActions; //which calls will be tried to be redirected to children - ui8 recActions; //which calls we allow te receive from parent - - enum EAlignment {TOPLEFT, CENTER, BOTTOMRIGHT}; - - void disable(); //deactivates if needed, blocks all automatic activity, allows only disposal - void enable(bool activation = true); //activates if needed, all activity enabled (Warning: may not be symetric with disable if recActions was limited!) - void defActivate(); - void defDeactivate(); - void activate(); - void deactivate(); - void activate(ui16 what); - void deactivate(ui16 what); - void show(SDL_Surface * to); - void showAll(SDL_Surface * to); - void redraw(); - - void drawBorderLoc(SDL_Surface * sur, const Rect &r, const int3 &color); - void printAtLoc(const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst); - void printToLoc(const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst); - void printAtMiddleLoc(const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst); - void printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, SDL_Color kolor, SDL_Surface * dst); - void printAtMiddleWBLoc(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor, SDL_Surface * dst); - void blitAtLoc(SDL_Surface * src, int x, int y, SDL_Surface * dst); - void blitAtLoc(SDL_Surface * src, const Point &p, SDL_Surface * dst); - bool isItInLoc(const SDL_Rect &rect, int x, int y); - bool isItInLoc(const SDL_Rect &rect, const Point &p); - const Rect & center(const Rect &r, bool propagate = true); //sets pos so that r will be in the center of screen, assigns sizes of r to pos, returns new position - const Rect & center(const Point &p, bool propagate = true); //moves object so that point p will be in its center - const Rect & center(bool propagate = true); //centers when pos.w and pos.h are set, returns new position - void fitToScreen(int borderWidth, bool propagate = true); //moves window to fit into screen - void moveBy(const Point &p, bool propagate = true); - void moveTo(const Point &p, bool propagate = true); - void changeUsedEvents(ui16 what, bool enable, bool adjust = true); - - void addChild(CIntObject *child, bool adjustPosition = false); - void removeChild(CIntObject *child, bool adjustPosition = false); - void delChild(CIntObject *child); //removes from children list, deletes - template void delChildNUll(T *&child, bool deactivateIfNeeded = false) //removes from children list, deletes and sets pointer to NULL - { - if(!child) - return; - - if(deactivateIfNeeded && child->active) - child->deactivate(); - - delChild(child); - child = NULL; - } -}; - -/// Class for binding keys to left mouse button clicks -/// Classes wanting use it should have it as one of their base classes -class KeyShortcut : public virtual CIntObject -{ -public: - std::set assignedKeys; - KeyShortcut(){}; //c-tor - KeyShortcut(int key){assignedKeys.insert(key);}; //c-tor - KeyShortcut(std::set Keys):assignedKeys(Keys){}; //c-tor - virtual void keyPressed(const SDL_KeyboardEvent & key); //call-in -}; - -/// to unify updating garrisons via PlayerInterface -class CGarrisonHolder : public virtual CIntObject -{ -public: - CGarrisonHolder(); - virtual void updateGarrisons(){}; -}; - -class CWindowWithGarrison : public CGarrisonHolder -{ -public: - CGarrisonInt *garr; - virtual void updateGarrisons(); -}; -/// Window GUI class -class CSimpleWindow : public CIntObject -{ -public: - SDL_Surface * bitmap; //background - virtual void show(SDL_Surface * to); - CSimpleWindow():bitmap(NULL){}; //c-tor - virtual ~CSimpleWindow(); //d-tor -}; -/// Image class -class CPicture : public CIntObject -{ -public: - SDL_Surface *bg; - Rect *srcRect; //if NULL then whole surface will be used - bool freeSurf; //whether surface will be freed upon CPicture destruction - bool needRefresh;//Surface needs to be displayed each frame - - operator SDL_Surface*() - { - return bg; - } - - CPicture(const Rect &r, const SDL_Color &color, bool screenFormat = false); //rect filled with given color - CPicture(const Rect &r, ui32 color, bool screenFormat = false); //rect filled with given color - CPicture(SDL_Surface *BG, int x=0, int y=0, bool Free = true); //wrap existing SDL_Surface - CPicture(const std::string &bmpname, int x=0, int y=0); - CPicture(SDL_Surface *BG, const Rect &SrcRext, int x = 0, int y = 0, bool free = false); //wrap subrect of given surface - void init(); - - void createSimpleRect(const Rect &r, bool screenFormat, ui32 color); - ~CPicture(); - void show(SDL_Surface * to); - void showAll(SDL_Surface * to); - void convertToScreenBPP(); - void colorizeAndConvert(int player); - void colorize(int player); -}; - -/// Handles GUI logic and drawing -class CGuiHandler -{ -public: - FPSManager *mainFPSmng; //to keep const framerate - StopWatch th; - std::list listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on) - IStatusBar * statusbar; - - //active GUI elements (listening for events - std::list lclickable; - std::list rclickable; - std::list hoverable; - std::list keyinterested; - std::list motioninterested; - std::list timeinterested; - std::list wheelInterested; - std::list doubleClickInterested; - - //objs to blit - std::vector objsToBlit; - - SDL_Event * current; //current event - can be set to NULL to stop handling event - IUpdateable *curInt; - - Point lastClick; - unsigned lastClickTime; - bool terminate; - - CGuiHandler(); - ~CGuiHandler(); - void run(); // holds the main loop for the whole program after initialization and manages the update/rendering system - - void totalRedraw(); //forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering - void simpleRedraw(); //update only top interface and draw background from buffer, sets a flag, method gets called at the end of the rendering - - void popInt(IShowActivable *top); //removes given interface from the top and activates next - void popIntTotally(IShowActivable *top); //deactivates, deletes, removes given interface from the top and activates next - void pushInt(IShowActivable *newInt); //deactivate old top interface, activates this one and pushes to the top - void popInts(int howMany); //pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front - IShowActivable *topInt(); //returns top interface - - void updateTime(); //handles timeInterested - void handleEvents(); //takes events from queue and calls interested objects - void handleEvent(SDL_Event *sEvent); - void handleMouseMotion(SDL_Event *sEvent); - void handleMoveInterested( const SDL_MouseMotionEvent & motion ); - void fakeMouseMove(); - void breakEventHandling(); //current event won't be propagated anymore - void drawFPSCounter(); // draws the FPS to the upper left corner of the screen - ui8 defActionsDef; //default auto actions - ui8 captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list - std::list createdObj; //stack of objs being created -}; - -extern CGuiHandler GH; //global gui handler - -SDLKey arrowToNum(SDLKey key); //converts arrow key to according numpad key -SDLKey numToDigit(SDLKey key);//converts numpad digit key to normal digit key -bool isNumKey(SDLKey key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits) -bool isArrowKey(SDLKey key); -CIntObject * moveChild(CIntObject *obj, CIntObject *from, CIntObject *to, bool adjustPos = false); - -template void pushIntT() -{ - GH.pushInt(new T()); -} - -struct ObjectConstruction -{ - CIntObject *myObj; - ObjectConstruction(CIntObject *obj); - ~ObjectConstruction(); -}; - -struct SetCaptureState -{ - bool previousCapture; - ui8 prevActions; - SetCaptureState(bool allow, ui8 actions); - ~SetCaptureState(); -}; - -class Colors -{ -public: - static SDL_Color MetallicGold; - static SDL_Color Yellow; - - static SDL_Color createColor(int r, int g, int b); -}; - -#define OBJ_CONSTRUCTION ObjectConstruction obj__i(this) -#define OBJ_CONSTRUCTION_CAPTURING_ALL defActions = 255; SetCaptureState obj__i1(true, 255); ObjectConstruction obj__i(this) -#define BLOCK_CAPTURING SetCaptureState obj__i(false, 0) -#define BLOCK_CAPTURING_DONT_TOUCH_REC_ACTIONS SetCaptureState obj__i(false, GH.defActionsDef) diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 7e082772c..37f7726b8 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -15,7 +15,7 @@ #include "CConfigHandler.h" #include "SDL_framerate.h" #include "CConfigHandler.h" -#include "CCreatureAnimation.h" +#include "BattleInterface/CCreatureAnimation.h" #include "CPlayerInterface.h" #include "Graphics.h" #include "CAnimation.h" @@ -30,7 +30,7 @@ #include "../lib/CondSh.h" #include "../lib/map.h" #include "mapHandler.h" -#include "../lib/StopWatch.h" +#include "../lib/CStopWatch.h" #include "../lib/NetPacks.h" #include "CSpellWindow.h" #include "CHeroWindow.h" @@ -43,6 +43,7 @@ #include "../lib/BattleState.h" #include "../lib/CGameState.h" #include "../lib/GameConstants.h" +#include "UIFramework/CGuiHandler.h" /* * GUIClasses.cpp, part of VCMI engine @@ -437,8 +438,8 @@ void CGarrisonInt::splitStacks(int am2) LOCPLINT->cb->splitStack(armedObjs[highlighted->upg], armedObjs[pb], highlighted->ID, p2, am2); } -CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset, - SDL_Surface *pomsur, const Point& SurOffset, +CGarrisonInt::CGarrisonInt(int x, int y, int inx, const SPoint &garsOffset, + SDL_Surface *pomsur, const SPoint& SurOffset, const CArmedInstance *s1, const CArmedInstance *s2, bool _removableUnits, bool smallImgs, bool _twoRows ) : interx(inx), garOffset(garsOffset), highlighted(NULL), splitting(false), @@ -481,7 +482,7 @@ CInfoWindow::CInfoWindow(std::string Text, int player, const TCompsInfo &comps, buttons.push_back(button); } - text = new CTextBox(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, zwykly); + text = new CTextBox(Text, SRect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, zwykly); if(!text->slider) { text->pos.w = text->maxW; @@ -602,13 +603,13 @@ void CRClickPopup::createAndPush(const std::string &txt, const CInfoWindow::TCom int player = LOCPLINT ? LOCPLINT->playerID : 1; //if no player, then use blue CSimpleWindow * temp = new CInfoWindow(txt, player, comps); - temp->center(Point(GH.current->motion)); //center on mouse + temp->center(SPoint(GH.current->motion)); //center on mouse temp->fitToScreen(10); CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true); GH.pushInt(rcpi); } -void CRClickPopup::createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment /*= BOTTOMRIGHT*/) +void CRClickPopup::createAndPush(const CGObjectInstance *obj, const SPoint &p, EAlignment alignment /*= BOTTOMRIGHT*/) { SDL_Surface *iWin = LOCPLINT->infoWin(obj); //try get custom infowindow for this obj if(iWin) @@ -632,7 +633,7 @@ CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free) } -CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free/*=false*/) +CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, const SPoint &p, EAlignment alignment, bool Free/*=false*/) : free(Free),bitmap(Bitmap) { switch(alignment) @@ -934,7 +935,7 @@ void CSelectableComponent::show(SDL_Surface * to) blitAt(getImg(),pos.x,pos.y,to); if(selected) { - CSDL_Ext::drawBorder(to, Rect::around(Rect(pos.x, pos.y, getImg()->w, getImg()->h)), int3(239,215,123)); + CSDL_Ext::drawBorder(to, SRect::around(SRect(pos.x, pos.y, getImg()->w, getImg()->h)), int3(239,215,123)); } printAtMiddleWB(subtitle,pos.x+pos.w/2,pos.y+pos.h+25,FONT_SMALL,12,zwykly,to); @@ -976,7 +977,7 @@ CIntObject* CObjectList::createItem(size_t index) if(item->parent != this) { if (item->parent) - moveChild(item, item->parent, this); + CGuiHandler::moveChild(item, item->parent, this); else addChild(item); } @@ -986,7 +987,7 @@ CIntObject* CObjectList::createItem(size_t index) return item; } -CTabbedInt::CTabbedInt(CreateFunc create, DestroyFunc destroy, Point position, size_t ActiveID): +CTabbedInt::CTabbedInt(CreateFunc create, DestroyFunc destroy, SPoint position, size_t ActiveID): CObjectList(create, destroy), activeTab(NULL), activeID(ActiveID) @@ -1019,8 +1020,8 @@ CIntObject * CTabbedInt::getItem() return activeTab; } -CListBox::CListBox(CreateFunc create, DestroyFunc destroy, Point Pos, Point ItemOffset, size_t VisibleSize, - size_t TotalSize, size_t InitialPos, int Slider, Rect SliderPos): +CListBox::CListBox(CreateFunc create, DestroyFunc destroy, SPoint Pos, SPoint ItemOffset, size_t VisibleSize, + size_t TotalSize, size_t InitialPos, int Slider, SRect SliderPos): CObjectList(create, destroy), first(InitialPos), totalSize(TotalSize), @@ -1041,7 +1042,7 @@ CListBox::CListBox(CreateFunc create, DestroyFunc destroy, Point Pos, Point Item // Used to move active items after changing list position void CListBox::updatePositions() { - Point itemPos = pos.topLeft(); + SPoint itemPos = pos.topLeft(); for (std::list::iterator it = items.begin(); it!=items.end(); it++) { (*it)->moveTo(itemPos); @@ -1157,7 +1158,7 @@ CSelWindow::CSelWindow(const std::string &Text, int player, int charperline, con buttons[i]->callback += boost::bind(&CInfoWindow::close,this); //each button will close the window apart from call-defined actions } - text = new CTextBox(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, zwykly); + text = new CTextBox(Text, SRect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, zwykly); text->redrawParentOnScrolling = true; buttons.front()->assignedKeys.insert(SDLK_RETURN); //first button - reacts on enter @@ -1322,8 +1323,8 @@ void CHeroList::init() { int w = pos.w+1, h = pos.h+4; bg = CSDL_Ext::newSurface(w,h,screen); - Rect srcRect = genRect(w, h, pos.x, pos.y); - Rect dstRect = genRect(w, h, 0, 0); + SRect srcRect = genRect(w, h, pos.x, pos.y); + SRect dstRect = genRect(w, h, 0, 0); CSDL_Ext::blitSurface(adventureInt->bg, &srcRect, bg, &dstRect); } @@ -1845,7 +1846,7 @@ CCreaturePic::CCreaturePic(int x, int y, const CCreature *cre, bool Big, bool An else bg = new CPicture(graphics->backgroundsm[cre->faction],0,0,false); bg->needRefresh = true; - anim = new CCreatureAnim(0, 0, cre->animDefName, Rect()); + anim = new CCreatureAnim(0, 0, cre->animDefName, SRect()); anim->clipRect(cre->doubleWide?170:150, 155, bg->pos.w, bg->pos.h); anim->startPreview(); } @@ -1905,7 +1906,7 @@ void CRecruitmentWindow::clickLeft(tribool down, bool previousState) { for(int i=0;imotion.x, GH.current->motion.y)) { which = i; @@ -1930,7 +1931,7 @@ void CRecruitmentWindow::clickRight(tribool down, bool previousState) for(int i=0;imotion.x, GH.current->motion.y)) { CIntObject *popup = createCreWindow(creatures[i].ID, 0, 0); @@ -1985,7 +1986,7 @@ CRecruitmentWindow::CRecruitmentWindow(const CGDwelling *Dwelling, int Level, co bitmap = new CPicture("TPRCRT.bmp"); bitmap->colorizeAndConvert(LOCPLINT->playerID); bitmap->center(); - pos = (bitmap->pos += Point(0, y_offset)); + pos = (bitmap->pos += SPoint(0, y_offset)); bar = new CGStatusBar(8, 370, "APHLFTRT.bmp", 471); max = new AdventureMapButton(CGI->generaltexth->zelp[553],boost::bind(&CRecruitmentWindow::Max,this),134,313,"IRCBTNS.DEF",SDLK_m); @@ -2158,8 +2159,8 @@ void CSplitWindow::show(SDL_Surface * to) void CSplitWindow::keyPressed (const SDL_KeyboardEvent & key) { SDLKey k = key.keysym.sym; - if (isNumKey(k)) //convert numpad number to normal digit - k = numToDigit(k); + if (CGuiHandler::isNumKey(k)) //convert numpad number to normal digit + k = CGuiHandler::numToDigit(k); if(key.state != SDL_PRESSED) return; @@ -2205,11 +2206,11 @@ void CSplitWindow::clickLeft(tribool down, bool previousState) { if(down) { - Point click(GH.current->motion.x,GH.current->motion.y); + SPoint click(GH.current->motion.x,GH.current->motion.y); click = click - pos.topLeft(); - if(Rect(19,216,105,40).isIn(click)) //left picture + if(SRect(19,216,105,40).isIn(click)) //left picture which = 0; - else if(Rect(175,216,105,40).isIn(click)) //right picture + else if(SRect(175,216,105,40).isIn(click)) //right picture which = 1; } } @@ -2680,32 +2681,32 @@ CTradeWindow::CTradeableItem::CTradeableItem( EType Type, int ID, bool Left, int void CTradeWindow::CTradeableItem::showAll(SDL_Surface * to) { - Point posToBitmap; - Point posToSubCenter; + SPoint posToBitmap; + SPoint posToSubCenter; switch(type) { case RESOURCE: - posToBitmap = Point(19,9); - posToSubCenter = Point(36, 59); + posToBitmap = SPoint(19,9); + posToSubCenter = SPoint(36, 59); break; case CREATURE_PLACEHOLDER: case CREATURE: - posToSubCenter = Point(29, 76); + posToSubCenter = SPoint(29, 76); if(downSelection) posToSubCenter.y += 5; break; case PLAYER: - posToSubCenter = Point(31, 76); + posToSubCenter = SPoint(31, 76); break; case ARTIFACT_PLACEHOLDER: case ARTIFACT_INSTANCE: - posToSubCenter = Point(19, 55); + posToSubCenter = SPoint(19, 55); if(downSelection) posToSubCenter.y += 8; break; case ARTIFACT_TYPE: - posToSubCenter = Point(19, 58); + posToSubCenter = SPoint(19, 58); break; } @@ -2785,9 +2786,9 @@ SDL_Surface * CTradeWindow::CTradeableItem::getSurface() } } -void CTradeWindow::CTradeableItem::showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to) +void CTradeWindow::CTradeableItem::showAllAt(const SPoint &dstPos, const std::string &customSub, SDL_Surface * to) { - Rect oldPos = pos; + SRect oldPos = pos; std::string oldSub = subtitle; downSelection = true; @@ -2940,7 +2941,7 @@ void CTradeWindow::initItems(bool Left) CTradeableItem *hlp = new CTradeableItem(itemsType[Left], -1, 1, 0); hlp->recActions &= ~(UPDATE | SHOWALL); - hlp->pos += Rect(137, 469, 42, 42); + hlp->pos += SRect(137, 469, 42, 42); items[Left].push_back(hlp); } else //ARTIFACT_EXP @@ -2950,7 +2951,7 @@ void CTradeWindow::initItems(bool Left) } BLOCK_CAPTURING; - arts = new CArtifactsOfHero(Point(pos.x+xOffset, pos.y+yOffset)); + arts = new CArtifactsOfHero(SPoint(pos.x+xOffset, pos.y+yOffset)); arts->commonInfo = new CArtifactsOfHero::SCommonPart; arts->commonInfo->participants.insert(arts); arts->recActions = 255; @@ -2965,7 +2966,7 @@ void CTradeWindow::initItems(bool Left) } std::vector *ids = getItemsIds(Left); - std::vector pos; + std::vector pos; int amount = -1; getPositionsFor(pos, Left, itemsType[Left]); @@ -3035,7 +3036,7 @@ std::vector *CTradeWindow::getItemsIds(bool Left) return ids; } -void CTradeWindow::getPositionsFor(std::vector &poss, bool Left, EType type) const +void CTradeWindow::getPositionsFor(std::vector &poss, bool Left, EType type) const { if(mode == EMarketMode::ARTIFACT_EXP && !Left) { @@ -3048,10 +3049,10 @@ void CTradeWindow::getPositionsFor(std::vector &poss, bool Left, EType typ dy = 70; for (int i = 0; i < 4 ; i++) for (int j = 0; j < 5 ; j++) - poss += Rect(x + dx*j, y + dy*i, w, h); + poss += SRect(x + dx*j, y + dy*i, w, h); - poss += Rect(x + dx*1.5, y + dy*4, w, h); - poss += Rect(x + dx*2.5, y + dy*4, w, h); + poss += SRect(x + dx*1.5, y + dy*4, w, h); + poss += SRect(x + dx*2.5, y + dy*4, w, h); } else { @@ -3069,7 +3070,7 @@ void CTradeWindow::getPositionsFor(std::vector &poss, bool Left, EType typ if(!Left) { - BOOST_FOREACH(Rect &r, poss) + BOOST_FOREACH(SRect &r, poss) r.x += leftToRightOffset; } } @@ -3283,10 +3284,10 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan { slider = NULL; max = NULL; - deal->moveBy(Point(-30, 0)); + deal->moveBy(SPoint(-30, 0)); } - Rect traderTextRect; + SRect traderTextRect; //left side switch(Mode) @@ -3312,11 +3313,11 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan case EMarketMode::RESOURCE_ARTIFACT: case EMarketMode::ARTIFACT_RESOURCE: printAtMiddle(CGI->generaltexth->allTexts[168],445,148,FONT_SMALL,zwykly,*bg); //available for trade - traderTextRect = Rect(316, 48, 260, 75); + traderTextRect = SRect(316, 48, 260, 75); break; case EMarketMode::RESOURCE_PLAYER: printAtMiddle(CGI->generaltexth->allTexts[169],445,55,FONT_SMALL,zwykly,*bg); //players - traderTextRect = Rect(28, 48, 260, 75); + traderTextRect = SRect(28, 48, 260, 75); break; } @@ -3524,18 +3525,18 @@ std::string CMarketplaceWindow::selectionSubtitle(bool Left) const return "???"; } -Point CMarketplaceWindow::selectionOffset(bool Left) const +SPoint CMarketplaceWindow::selectionOffset(bool Left) const { if(Left) { switch(itemsType[1]) { case RESOURCE: - return Point(122, 446); + return SPoint(122, 446); case CREATURE: - return Point(128, 450); + return SPoint(128, 450); case ARTIFACT_INSTANCE: - return Point(134, 466); + return SPoint(134, 466); } } else @@ -3544,18 +3545,18 @@ Point CMarketplaceWindow::selectionOffset(bool Left) const { case RESOURCE: if(mode == EMarketMode::ARTIFACT_RESOURCE) - return Point(410, 469); + return SPoint(410, 469); else - return Point(410, 446); + return SPoint(410, 446); case ARTIFACT_TYPE: - return Point(425, 447); + return SPoint(425, 447); case PLAYER: - return Point(417, 451); + return SPoint(417, 451); } } assert(0); - return Point(0,0); + return SPoint(0,0); } void CMarketplaceWindow::resourceChanged(int type, int val) @@ -3854,7 +3855,7 @@ void CAltarWindow::selectionChanged(bool side) void CAltarWindow::mimicCres() { - std::vector positions; + std::vector positions; getPositionsFor(positions, false, CREATURE); BOOST_FOREACH(CTradeableItem *t, items[1]) @@ -3865,12 +3866,12 @@ void CAltarWindow::mimicCres() } } -Point CAltarWindow::selectionOffset(bool Left) const +SPoint CAltarWindow::selectionOffset(bool Left) const { if(Left) - return Point(150, 421); + return SPoint(150, 421); else - return Point(396, 421); + return SPoint(396, 421); } std::string CAltarWindow::selectionSubtitle(bool Left) const @@ -4369,7 +4370,7 @@ void CInGameConsole::show(SDL_Surface * to) for(std::list< std::pair< std::string, int > >::iterator it = texts.begin(); it != texts.end(); ++it, ++number) { SDL_Color green = {0,0xff,0,0}; - Point leftBottomCorner(0, screen->h); + SPoint leftBottomCorner(0, screen->h); if(LOCPLINT->battleInt) { leftBottomCorner = LOCPLINT->battleInt->pos.bottomLeft(); @@ -4578,7 +4579,7 @@ CGarrisonWindow::CGarrisonWindow( const CArmedInstance *up, const CGHeroInstance bg->colorizeAndConvert(LOCPLINT->playerID); pos = bg->center(); - garr = new CGarrisonInt(92, 127, 4, Point(0,96), bg->bg, Point(93,127), up, down, removableUnits); + garr = new CGarrisonInt(92, 127, 4, SPoint(0,96), bg->bg, SPoint(93,127), up, down, removableUnits); { AdventureMapButton *split = new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),88,314,"IDV6432.DEF"); removeChild(split); @@ -4609,7 +4610,7 @@ void CGarrisonWindow::showAll(SDL_Surface * to) blitAtLoc(graphics->portraitLarge[static_cast(garr->armedObjs[1])->portrait],29,222,to); } -IShowActivable::IShowActivable() +IShowActivatable::IShowActivatable() { type = 0; } @@ -4629,7 +4630,7 @@ void CRClickPopupInt::show(SDL_Surface * to) inner->show(to); } -CRClickPopupInt::CRClickPopupInt( IShowActivable *our, bool deleteInt ) +CRClickPopupInt::CRClickPopupInt( IShowActivatable *our, bool deleteInt ) { CCS->curh->hide(); inner = our; @@ -4659,7 +4660,7 @@ CArtPlace::CArtPlace(const CArtifactInstance* Art) { } -CArtPlace::CArtPlace(Point position, const CArtifactInstance * Art): +CArtPlace::CArtPlace(SPoint position, const CArtifactInstance * Art): picked(false), marked(false), locked(false), ourArt(Art) { pos += position; @@ -5024,7 +5025,7 @@ LRClickableAreaWText::LRClickableAreaWText() init(); } -LRClickableAreaWText::LRClickableAreaWText(const Rect &Pos, const std::string &HoverText /*= ""*/, const std::string &ClickText /*= ""*/) +LRClickableAreaWText::LRClickableAreaWText(const SRect &Pos, const std::string &HoverText /*= ""*/, const std::string &ClickText /*= ""*/) { init(); pos = Pos + pos; @@ -5050,7 +5051,7 @@ void LRClickableAreaWTextComp::clickLeft(tribool down, bool previousState) } } -LRClickableAreaWTextComp::LRClickableAreaWTextComp(const Rect &Pos, int BaseType) +LRClickableAreaWTextComp::LRClickableAreaWTextComp(const SRect &Pos, int BaseType) : LRClickableAreaWText(Pos), baseType(BaseType), bonusValue(-1) { } @@ -5129,7 +5130,7 @@ void LRClickableAreaOpenTown::clickRight(tribool down, bool previousState) } LRClickableAreaOpenTown::LRClickableAreaOpenTown() - : LRClickableAreaWTextComp(Rect(0,0,0,0), -1) + : LRClickableAreaWTextComp(SRect(0,0,0,0), -1) { } @@ -5388,7 +5389,7 @@ CArtifactsOfHero::CArtifactsOfHero(std::vector ArtWorn, std::vector rightArtRoll->callback += boost::bind(&CArtifactsOfHero::scrollBackpack,this,+1); } -CArtifactsOfHero::CArtifactsOfHero(const Point& position, bool createCommonPart /*= false*/) +CArtifactsOfHero::CArtifactsOfHero(const SPoint& position, bool createCommonPart /*= false*/) : curHero(NULL), backpackPos(0), commonInfo(NULL), updateState(false), allowedAssembling(true), highlightModeCallback(0) { if(createCommonPart) @@ -5401,7 +5402,7 @@ CArtifactsOfHero::CArtifactsOfHero(const Point& position, bool createCommonPart pos += position; artWorn.resize(19); - std::vector slotPos; + std::vector slotPos; slotPos += genRect(44,44,509,30), genRect(44,44,567,240), genRect(44,44,509,80), genRect(44,44,383,68), genRect(44,44,564,183), genRect(44,44,509,130), genRect(44,44,431,68), genRect(44,44,610,183), genRect(44,44,515,295), @@ -5741,11 +5742,11 @@ CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) : bg(NULL) pos.h = screen->h; - artifs[0] = new CArtifactsOfHero(Point(pos.x + -334, pos.y + 150)); + artifs[0] = new CArtifactsOfHero(SPoint(pos.x + -334, pos.y + 150)); artifs[0]->commonInfo = new CArtifactsOfHero::SCommonPart; artifs[0]->commonInfo->participants.insert(artifs[0]); artifs[0]->setHero(heroInst[0]); - artifs[1] = new CArtifactsOfHero(Point(pos.x + 96, pos.y + 150)); + artifs[1] = new CArtifactsOfHero(SPoint(pos.x + 96, pos.y + 150)); artifs[1]->commonInfo = artifs[0]->commonInfo; artifs[1]->commonInfo->participants.insert(artifs[1]); artifs[1]->setHero(heroInst[1]); @@ -5826,7 +5827,7 @@ CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) : bg(NULL) ourBar = new CGStatusBar(pos.x + 3, pos.y + 577, "KSTATBAR"); //garrison interface - garr = new CGarrisonInt(pos.x + 69, pos.y + 131, 4, Point(418,0), bg, Point(69,131), heroInst[0],heroInst[1], true, true); + garr = new CGarrisonInt(pos.x + 69, pos.y + 131, 4, SPoint(418,0), bg, SPoint(69,131), heroInst[0],heroInst[1], true, true); { BLOCK_CAPTURING; @@ -5855,7 +5856,7 @@ CShipyardWindow::CShipyardWindow(const std::vector &cost, int state, int b std::string boatFilenames[3] = {"AB01_", "AB02_", "AB03_"}; - Point waterCenter = Point(bgWater->pos.x+bgWater->pos.w/2, bgWater->pos.y+bgWater->pos.h/2); + SPoint waterCenter = SPoint(bgWater->pos.x+bgWater->pos.w/2, bgWater->pos.y+bgWater->pos.h/2); bgShip = new CAnimImage(boatFilenames[boatType], 0, 7, 120, 96, CShowableAnim::USE_RLE); bgShip->center(waterCenter); @@ -5909,7 +5910,7 @@ CPuzzleWindow::CPuzzleWindow(const int3 &grailPos, double discoveredRatio) //printing necessary things to background int3 moveInt = int3(8, 9, 0); - Rect mapRect = genRect(544, 591, 8, 8); + SRect mapRect = genRect(544, 591, 8, 8); CGI->mh->terrainRect (grailPos - moveInt, adventureInt->anim, &LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim, @@ -6292,7 +6293,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectIn quit = new AdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 294, 275, "IOKAY.DEF", SDLK_RETURN); bar = new CGStatusBar(327, 332); - garr = new CGarrisonInt(108, 60, 18, Point(),bg->bg,Point(108,60),hero,NULL); + garr = new CGarrisonInt(108, 60, 18, SPoint(),bg->bg,SPoint(108,60),hero,NULL); updateGarrisons(); } @@ -6485,7 +6486,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner) SThievesGuildInfo tgi; //info to be displayed LOCPLINT->cb->getThievesGuildInfo(tgi, owner); - pos = center(Rect(0,0,800,600));// Rect( (conf.cc.resx - 800) / 2, (conf.cc.resy - 600) / 2, 800, 600 ); + pos = center(SRect(0,0,800,600));// SRect( (conf.cc.resx - 800) / 2, (conf.cc.resy - 600) / 2, 800, 600 ); //loading backround and converting to more bpp form SDL_Surface * bg = background = BitmapHandler::loadBitmap("TpRank.bmp", false); @@ -6685,10 +6686,10 @@ void MoraleLuckBox::showAll(SDL_Surface * to) def = morale ? graphics->morale42 : graphics->luck42; SDL_Surface *img = def->ourImages[bonusValue + 3].bitmap; - blitAt(img, Rect(img).centerIn(pos), to); //put img in the center of our pos + blitAt(img, SRect(img).centerIn(pos), to); //put img in the center of our pos } -MoraleLuckBox::MoraleLuckBox(bool Morale, const Rect &r, bool Small) +MoraleLuckBox::MoraleLuckBox(bool Morale, const SRect &r, bool Small) :morale(Morale), small(Small) { @@ -6742,7 +6743,7 @@ void CLabel::setTxt(const std::string &Txt) } } -CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= zwykly*/) +CTextBox::CTextBox(std::string Text, const SRect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= zwykly*/) :CLabel(rect.x, rect.y, Font, Align, Color, Text), sliderStyle(SliderStyle), slider(NULL) { redrawParentOnScrolling = false; @@ -6862,7 +6863,7 @@ CGStatusBar::CGStatusBar(CPicture *BG, EFonts Font /*= FONT_SMALL*/, EAlignment { init(); bg = BG; - moveChild(bg, bg->parent, this); + CGuiHandler::moveChild(bg, bg->parent, this); pos = bg->pos; calcOffset(); } @@ -6877,7 +6878,7 @@ CGStatusBar::CGStatusBar(int x, int y, std::string name/*="ADROLLVR.bmp"*/, int if(maxw < pos.w) { vstd::amin(pos.w, maxw); - bg->srcRect = new Rect(0, 0, maxw, pos.h); + bg->srcRect = new SRect(0, 0, maxw, pos.h); } calcOffset(); } @@ -6903,15 +6904,15 @@ void CGStatusBar::calcOffset() switch(alignment) { case CENTER: - textOffset = Point(pos.w/2, pos.h/2); + textOffset = SPoint(pos.w/2, pos.h/2); break; case BOTTOMRIGHT: - textOffset = Point(pos.w, pos.h); + textOffset = SPoint(pos.w, pos.h); break; } } -CTextInput::CTextInput( const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList &CB ) +CTextInput::CTextInput( const SRect &Pos, const SPoint &bgOffset, const std::string &bgName, const CFunctionList &CB ) :cb(CB) { focus = false; @@ -6923,14 +6924,14 @@ CTextInput::CTextInput( const Rect &Pos, const Point &bgOffset, const std::strin giveFocus(); } -CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf) +CTextInput::CTextInput(const SRect &Pos, SDL_Surface *srf) { focus = false; pos += Pos; captureAllKeys = true; OBJ_CONSTRUCTION; bg = new CPicture(Pos, 0, true); - Rect hlp = Pos; + SRect hlp = Pos; if(srf) CSDL_Ext::blitSurface(srf, &hlp, *bg, NULL); else diff --git a/client/GUIClasses.h b/client/GUIClasses.h index ff1d8989e..d7c435adf 100644 --- a/client/GUIClasses.h +++ b/client/GUIClasses.h @@ -1,10 +1,13 @@ #pragma once -#include "GUIBase.h" #include "FunctionList.h" #include "../lib/ResourceSet.h" #include "../lib/GameConstants.h" +#include "UIFramework/CSimpleWindow.h" +#include "UIFramework/IStatusBar.h" +#include "UIFramework/CPicture.h" +#include "UIFramework/CKeyShortcut.h" #ifdef max #undef max @@ -127,19 +130,19 @@ public: virtual ~CRClickPopup(); //d-tor static void createAndPush(const std::string &txt, const CInfoWindow::TCompsInfo &comps = CInfoWindow::TCompsInfo()); - static void createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment = BOTTOMRIGHT); + static void createAndPush(const CGObjectInstance *obj, const SPoint &p, EAlignment alignment = BOTTOMRIGHT); }; /// popup displayed on R-click class CRClickPopupInt : public CRClickPopup { public: - IShowActivable *inner; + IShowActivatable *inner; bool delInner; void show(SDL_Surface * to); void showAll(SDL_Surface * to); - CRClickPopupInt(IShowActivable *our, bool deleteInt); //c-tor + CRClickPopupInt(IShowActivatable *our, bool deleteInt); //c-tor virtual ~CRClickPopupInt(); //d-tor }; @@ -151,7 +154,7 @@ public: void close(); void show(SDL_Surface * to); CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor - CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false); //c-tor + CInfoPopup(SDL_Surface * Bitmap, const SPoint &p, EAlignment alignment, bool Free=false); //c-tor CInfoPopup(SDL_Surface *Bitmap = NULL, bool Free = false); //default c-tor void init(int x, int y); @@ -190,7 +193,7 @@ public: virtual void deactivate(); }; -class CSelectableComponent : public SComponent, public KeyShortcut +class CSelectableComponent : public SComponent, public CKeyShortcut { public: bool selected; //if true, this component is selected @@ -239,7 +242,7 @@ public: //CreateFunc, DestroyFunc - see CObjectList //Pos - position of object, all tabs will be moved to this position //ActiveID - ID of initially active tab - CTabbedInt(CreateFunc create, DestroyFunc destroy = DestroyFunc(), Point position=Point(), size_t ActiveID=0); + CTabbedInt(CreateFunc create, DestroyFunc destroy = DestroyFunc(), SPoint position=SPoint(), size_t ActiveID=0); void setActive(size_t which); //recreate active tab @@ -257,7 +260,7 @@ private: size_t first; size_t totalSize; - Point itemOffset; + SPoint itemOffset; CSlider * slider; void updatePositions(); @@ -269,8 +272,8 @@ public: //TotalSize //Slider - slider style, bit field: 1 = present(disabled), 2=horisontal(vertical), 4=blue(brown) //SliderPos - position of slider, if present - CListBox(CreateFunc create, DestroyFunc destroy, Point Pos, Point ItemOffset, size_t VisibleSize, - size_t TotalSize, size_t InitialPos=0, int Slider=0, Rect SliderPos=Rect() ); + CListBox(CreateFunc create, DestroyFunc destroy, SPoint Pos, SPoint ItemOffset, size_t VisibleSize, + size_t TotalSize, size_t InitialPos=0, int Slider=0, SRect SliderPos=SRect() ); //recreate all visible items void reset(); @@ -318,7 +321,7 @@ class CGarrisonInt :public CIntObject { public: int interx; //space between slots - Point garOffset; //offset between garrisons (not used if only one hero) + SPoint garOffset; //offset between garrisons (not used if only one hero) CGarrisonSlot *highlighted; //chosen slot std::vector splitButtons; //may be empty if no buttons @@ -355,7 +358,7 @@ public: //removableUnits - you can take units from top; //smallImgs - units images size 64x58 or 32x32; //twoRows - display slots in 2 row (1st row = 4, 2nd = 3) - CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *pomsur, const Point &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=NULL, bool _removableUnits = true, bool smallImgs = false, bool _twoRows=false); //c-tor + CGarrisonInt(int x, int y, int inx, const SPoint &garsOffset, SDL_Surface *pomsur, const SPoint &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=NULL, bool _removableUnits = true, bool smallImgs = false, bool _twoRows=false); //c-tor ~CGarrisonInt(); //d-tor }; @@ -387,7 +390,7 @@ public: std::string text; CPicture *bg; bool autoRedraw; //whether control will redraw itself on setTxt - Point textOffset; //text will be blitted at pos + textOffset with appropriate alignment + SPoint textOffset; //text will be blitted at pos + textOffset with appropriate alignment bool ignoreLeadingWhitespace; virtual void setTxt(const std::string &Txt); @@ -410,8 +413,8 @@ public: std::vector effects; CSlider *slider; - //CTextBox( std::string Text, const Point &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly); - CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly); + //CTextBox( std::string Text, const SPoint &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly); + CTextBox(std::string Text, const SRect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly); void showAll(SDL_Surface * to); //shows statusbar (with current text) void setTxt(const std::string &Txt); void setBounds(int limitW, int limitH); @@ -467,8 +470,8 @@ public: void setText(const std::string &nText, bool callCb = false); - CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList &CB); - CTextInput(const Rect &Pos, SDL_Surface *srf = NULL); + CTextInput(const SRect &Pos, const SPoint &bgOffset, const std::string &bgName, const CFunctionList &CB); + CTextInput(const SRect &Pos, SDL_Surface *srf = NULL); ~CTextInput(); void showAll(SDL_Surface * to); void clickLeft(tribool down, bool previousState); @@ -671,7 +674,7 @@ public: CPicture *titleImage;//title image (castle gate\town portal picture) AdventureMapButton *ok, *exit; - std::vector areas;//areas for each visible item + std::vector areas;//areas for each visible item std::vector items;//id of all items present in list int selected;//currently selected item int length;//size of list (=9) @@ -737,7 +740,7 @@ public: CFunctionList callback; bool downSelection; - void showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to); + void showAllAt(const SPoint &dstPos, const std::string &customSub, SDL_Surface * to); void clickRight(tribool down, bool previousState); void hover (bool on); @@ -771,7 +774,7 @@ public: void initTypes(); void initItems(bool Left); std::vector *getItemsIds(bool Left); //NULL if default - void getPositionsFor(std::vector &poss, bool Left, EType type) const; + void getPositionsFor(std::vector &poss, bool Left, EType type) const; void removeItems(const std::set &toRemove); void removeItem(CTradeableItem * t); void getEmptySlots(std::set &toRemove); @@ -781,7 +784,7 @@ public: virtual void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const = 0; virtual void selectionChanged(bool side) = 0; //true == left - virtual Point selectionOffset(bool Left) const = 0; + virtual SPoint selectionOffset(bool Left) const = 0; virtual std::string selectionSubtitle(bool Left) const = 0; virtual void garrisonChanged() = 0; virtual void artifactsChanged(bool left) = 0; @@ -802,7 +805,7 @@ public: CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = NULL, EMarketMode::EMarketMode Mode = EMarketMode::RESOURCE_RESOURCE); //c-tor ~CMarketplaceWindow(); //d-tor - Point selectionOffset(bool Left) const; + SPoint selectionOffset(bool Left) const; std::string selectionSubtitle(bool Left) const; @@ -843,7 +846,7 @@ public: void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const; void mimicCres(); - Point selectionOffset(bool Left) const; + SPoint selectionOffset(bool Left) const; std::string selectionSubtitle(bool Left) const; void garrisonChanged(); void artifactsChanged(bool left); @@ -961,7 +964,7 @@ public: std::string text; LRClickableAreaWText(); - LRClickableAreaWText(const Rect &Pos, const std::string &HoverText = "", const std::string &ClickText = ""); + LRClickableAreaWText(const SRect &Pos, const std::string &HoverText = "", const std::string &ClickText = ""); virtual ~LRClickableAreaWText(); void init(); @@ -978,7 +981,7 @@ public: virtual void clickLeft(tribool down, bool previousState); virtual void clickRight(tribool down, bool previousState); - LRClickableAreaWTextComp(const Rect &Pos = Rect(0,0,0,0), int BaseType = -1); + LRClickableAreaWTextComp(const SRect &Pos = SRect(0,0,0,0), int BaseType = -1); SComponent * createComponent() const; }; @@ -991,7 +994,7 @@ public: void set(const IBonusBearer *node); void showAll(SDL_Surface * to); - MoraleLuckBox(bool Morale, const Rect &r, bool Small=false); + MoraleLuckBox(bool Morale, const SRect &r, bool Small=false); ~MoraleLuckBox(); }; @@ -1063,7 +1066,7 @@ public: const CArtifactInstance * ourArt; CArtPlace(const CArtifactInstance * Art); //c-tor - CArtPlace(Point position, const CArtifactInstance * Art = NULL); //c-tor + CArtPlace(SPoint position, const CArtifactInstance * Art = NULL); //c-tor void clickLeft(tribool down, bool previousState); void clickRight(tribool down, bool previousState); void select (); @@ -1138,7 +1141,7 @@ public: void updateSlot(int i); void eraseSlotData (CArtPlace* artPlace, int slotID); - CArtifactsOfHero(const Point& position, bool createCommonPart = false); + CArtifactsOfHero(const SPoint& position, bool createCommonPart = false); //Alternative constructor, used if custom artifacts positioning required (Kingdom interface) CArtifactsOfHero(std::vector ArtWorn, std::vector Backpack, AdventureMapButton *leftScroll, AdventureMapButton *rightScroll, bool createCommonPart = false); @@ -1147,6 +1150,20 @@ public: friend class CArtPlace; }; +class CGarrisonHolder : public virtual CIntObject +{ +public: + CGarrisonHolder(); + virtual void updateGarrisons(){}; +}; + +class CWindowWithGarrison : public CGarrisonHolder +{ +public: + CGarrisonInt *garr; + virtual void updateGarrisons(); +}; + /// Garrison window where you can take creatures out of the hero to place it on the garrison class CGarrisonWindow : public CWindowWithGarrison { diff --git a/client/Graphics.cpp b/client/Graphics.cpp index e58d979e7..b3ff49ddb 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -20,6 +20,7 @@ #include "../lib/JsonNode.h" #include "../lib/vcmi_endian.h" #include "../lib/GameConstants.h" +#include "../lib/CStopWatch.h" using namespace boost::assign; using namespace CSDL_Ext; @@ -364,7 +365,7 @@ void Graphics::loadWallPositions() int townID = town["id"].Float(); BOOST_FOREACH(const JsonNode &coords, town["pos"].Vector()) { - Point pt(coords["x"].Float(), coords["y"].Float()); + SPoint pt(coords["x"].Float(), coords["y"].Float()); wallPositions[townID].push_back(pt); } @@ -484,7 +485,7 @@ void Graphics::loadHeroFlags(std::pair Graphics::*, void Graphics::loadHeroFlags() { using namespace boost::assign; - StopWatch th; + CStopWatch th; std::pair Graphics::*, std::vector > pr[4]; pr[0].first = &Graphics::flags1; pr[0].second+=("ABF01L.DEF"),("ABF01G.DEF"),("ABF01R.DEF"),("ABF01D.DEF"),("ABF01B.DEF"), diff --git a/client/Graphics.h b/client/Graphics.h index 1f3561b2c..286d3bb6a 100644 --- a/client/Graphics.h +++ b/client/Graphics.h @@ -2,8 +2,9 @@ #include "FontBase.h" -#include "GUIBase.h" #include "../lib/GameConstants.h" +#include "UIFramework/SPoint.h" +#include "UIFramework/SRect.h" /* * Graphics.h, part of VCMI engine @@ -86,7 +87,7 @@ public: std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle std::map< int, std::vector < std::string > > battleACToDef; //maps AC format to vector of appropriate def names CDefEssential * spellEffectsPics; //bitmaps representing spells affecting a stack in battle - std::vector< Point > wallPositions[GameConstants::F_NUMBER]; //positions of different pieces of wall + std::vector< SPoint > wallPositions[GameConstants::F_NUMBER]; //positions of different pieces of wall //abilities CDefEssential * abils32, * abils44, * abils82; //spells diff --git a/client/Makefile.am b/client/Makefile.am index 84158f3b9..262c553ec 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -25,12 +25,14 @@ vcmiclient_SOURCES = \ ./BattleInterface/CBattleResultWindow.h \ ./BattleInterface/CBattleStackAnimation.cpp \ ./BattleInterface/CBattleStackAnimation.h \ + ./BattleInterface/CCreatureAnimation.h \ + ./BattleInterface/CCreatureAnimation.cpp \ ./BattleInterface/CDefenceAnimation.cpp \ ./BattleInterface/CDefenceAnimation.h \ ./BattleInterface/CDummyAnimation.cpp \ ./BattleInterface/CDummyAnimation.h \ - ./BattleInterface/CHexFieldControl.cpp \ - ./BattleInterface/CHexFieldControl.h \ + ./BattleInterface/CClickableHex.cpp \ + ./BattleInterface/CClickableHex.h \ ./BattleInterface/CMeleeAttackAnimation.cpp \ ./BattleInterface/CMeleeAttackAnimation.h \ ./BattleInterface/CMovementAnimation.cpp \ @@ -48,6 +50,16 @@ vcmiclient_SOURCES = \ ./BattleInterface/CStackQueue.cpp \ ./BattleInterface/CStackQueue.h \ ./BattleInterface/SStackAttackedInfo.h \ + ./UIFramework/CGuiHandler.cpp \ + ./UIFramework/CGuiHandler.h \ + ./UIFramework/CIntObject.cpp \ + ./UIFramework/CIntObject.h \ + ./UIFramework/CKeyShortcut.cpp \ + ./UIFramework/CKeyShortcut.h \ + ./UIFramework/CPicture.cpp \ + ./UIFramework/CPicture.h \ + ./UIFramework/SRect.cpp \ + ./UIFramework/SRect.h \ AdventureMapButton.cpp \ AdventureMapButton.h \ CAdvmapInterface.cpp \ @@ -60,8 +72,6 @@ vcmiclient_SOURCES = \ CCastleInterface.h \ CConfigHandler.cpp \ CConfigHandler.h \ - CCreatureAnimation.cpp \ - CCreatureAnimation.h \ CCreatureWindow.cpp \ CCreatureWindow.h \ CCursorHandler.cpp \ @@ -97,8 +107,6 @@ vcmiclient_SOURCES = \ FunctionList.h \ Graphics.cpp \ Graphics.h \ - GUIBase.cpp \ - GUIBase.h \ GUIClasses.cpp \ GUIClasses.h \ mapHandler.cpp \ diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index e8f271f8b..33b735010 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -24,7 +24,7 @@ #include "../lib/CGameState.h" #include "../lib/BattleState.h" #include "../lib/GameConstants.h" - +#include "UIFramework/CGuiHandler.h" //macros to avoid code duplication - calls given method with given arguments if interface for specific player is present //awaiting variadic templates... diff --git a/client/SDL_Extensions.cpp b/client/SDL_Extensions.cpp index b44885291..92d8e87b6 100644 --- a/client/SDL_Extensions.cpp +++ b/client/SDL_Extensions.cpp @@ -6,7 +6,6 @@ #include "CMessage.h" #include "CDefHandler.h" #include "Graphics.h" -#include "GUIBase.h" /* * SDL_Extensions.cpp, part of VCMI engine @@ -1020,7 +1019,7 @@ void CSDL_Ext::drawBorder( SDL_Surface * sur, const SDL_Rect &r, const int3 &col drawBorder(sur, r.x, r.y, r.w, r.h, color); } -void CSDL_Ext::drawDashedBorder(SDL_Surface * sur, const Rect &r, const int3 &color) +void CSDL_Ext::drawDashedBorder(SDL_Surface * sur, const SRect &r, const int3 &color) { const int y1 = r.y, y2 = r.y + r.h-1; for (int i=0; iw, dst->h); + betterDst = SRect(0, 0, dst->w, dst->h); } SDL_BlitSurface(src, srcRect, dst, &betterDst); @@ -1286,7 +1285,7 @@ void CSDL_Ext::fillRect( SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color ) } else { - newRect = Rect(0, 0, dst->w, dst->h); + newRect = SRect(0, 0, dst->w, dst->h); } SDL_FillRect(dst, &newRect, color); } diff --git a/client/SDL_Extensions.h b/client/SDL_Extensions.h index 466e0492f..c42be8008 100644 --- a/client/SDL_Extensions.h +++ b/client/SDL_Extensions.h @@ -5,6 +5,7 @@ #include "SDL_video.h" #include "SDL_ttf.h" #include "FontBase.h" +#include "UIFramework/SRect.h" /* * SDL_Extensions.h, part of VCMI engine @@ -170,7 +171,7 @@ namespace CSDL_Ext void update(SDL_Surface * what = screen); //updates whole surface (default - main screen) void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color); void drawBorder(SDL_Surface * sur, const SDL_Rect &r, const int3 &color); - void drawDashedBorder(SDL_Surface * sur, const Rect &r, const int3 &color); + void drawDashedBorder(SDL_Surface * sur, const SRect &r, const int3 &color); void setPlayerColor(SDL_Surface * sur, ui8 player); //sets correct color of flags; -1 for neutral std::string processStr(std::string str, std::vector & tor); //replaces %s in string SDL_Surface * newSurface(int w, int h, SDL_Surface * mod=screen); //creates new surface, with flags/format same as in surface given diff --git a/client/StdInc.h b/client/StdInc.h index 18659d5ee..76e828312 100644 --- a/client/StdInc.h +++ b/client/StdInc.h @@ -1,325 +1,7 @@ #pragma once -// Standard include file -// Should be treated as a precompiled header file in the compiler settings -// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio -// This file shouldn't be changed, except if there is a important header file which is missing. +#include "../Global.h" -/* - * StdInc.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ +// This header should be treated as a pre compiled header file(PCH) in the compiler building settings. -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#include -#ifdef _WIN32 -#include -#else -#include "../tchar_amigaos4.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -//filesystem version 3 causes problems (and it's default as of boost 1.46) -#define BOOST_FILESYSTEM_VERSION 2 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ANDROID -#include -#endif - -// Integral data types -typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) -typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) -typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) -typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) -typedef boost::int64_t si64; //signed int 64 bits (8 bytes) -typedef boost::int32_t si32; //signed int 32 bits (4 bytes) -typedef boost::int16_t si16; //signed int 16 bits (2 bytes) -typedef boost::int8_t si8; //signed int 8 bits (1 byte) - -// Import + Export macro declarations -#ifdef _WIN32 -#define DLL_EXPORT __declspec(dllexport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_EXPORT __attribute__ ((visibility("default"))) -#else -#define DLL_EXPORT -#endif -#endif - -#ifdef _WIN32 -#define DLL_IMPORT __declspec(dllimport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_IMPORT __attribute__ ((visibility("default"))) -#else -#define DLL_IMPORT -#endif -#endif - -#ifdef VCMI_DLL -#define DLL_LINKAGE DLL_EXPORT -#else -#define DLL_LINKAGE DLL_IMPORT -#endif - - -//a normal std::map with a const operator[] for sanity -template -class bmap : public std::map -{ -public: - const ValT & operator[](KeyT key) const - { - return find(key)->second; - } - ValT & operator[](KeyT key) - { - return static_cast &>(*this)[key]; - } - template void serialize(Handler &h, const int version) - { - h & static_cast &>(*this); - } -}; - -namespace vstd -{ - //returns true if container c contains item i - template - bool contains(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i) != c.end(); - } - - //returns true if map c contains item i - template - bool contains(const std::map & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if bmap c contains item i - template - bool contains(const bmap & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if unordered set c contains item i - template - bool contains(const boost::unordered_set & c, const Item &i) - { - return c.find(i)!=c.end(); - } - - //returns position of first element in vector c equal to s, if there is no such element, -1 is returned - template - int find_pos(const std::vector & c, const T2 &s) - { - for(size_t i=0; i < c.size(); ++i) - if(c[i] == s) - return i; - return -1; - } - - //Func(T1,T2) must say if these elements matches - template - int find_pos(const std::vector & c, const T2 &s, const Func &f) - { - for(size_t i=0; i < c.size(); ++i) - if(f(c[i],s)) - return i; - return -1; - } - - //returns iterator to the given element if present in container, end() if not - template - typename Container::iterator find(Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //returns const iterator to the given element if present in container, end() if not - template - typename Container::const_iterator find(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //removes element i from container c, returns false if c does not contain i - template - typename Container::size_type operator-=(Container &c, const Item &i) - { - typename Container::iterator itr = find(c,i); - if(itr == c.end()) - return false; - c.erase(itr); - return true; - } - - //assigns greater of (a, b) to a and returns maximum of (a, b) - template - t1 &amax(t1 &a, const t2 &b) - { - if(a >= b) - return a; - else - { - a = b; - return a; - } - } - - //assigns smaller of (a, b) to a and returns minimum of (a, b) - template - t1 &amin(t1 &a, const t2 &b) - { - if(a <= b) - return a; - else - { - a = b; - return a; - } - } - - //makes a to fit the range - template - t1 &abetween(t1 &a, const t2 &b, const t3 &c) - { - amax(a,b); - amin(a,c); - return a; - } - - //checks if a is between b and c - template - bool isbetween(const t1 &a, const t2 &b, const t3 &c) - { - return a > b && a < c; - } - - //checks if a is within b and c - template - bool iswithin(const t1 &a, const t2 &b, const t3 &c) - { - return a >= b && a <= c; - } - - template - struct assigner - { - public: - t1 &op1; - t2 op2; - assigner(t1 &a1, const t2 & a2) - :op1(a1), op2(a2) - {} - void operator()() - { - op1 = op2; - } - }; - - // Assigns value a2 to a1. The point of time of the real operation can be controlled - // with the () operator. - template - assigner assigno(t1 &a1, const t2 &a2) - { - return assigner(a1,a2); - } - - //deleted pointer and sets it to NULL - template - void clear_pointer(T* &ptr) - { - delete ptr; - ptr = NULL; - } -} -using vstd::operator-=; - -// can be used for counting arrays -template char (&_ArrayCountObj(const T (&)[N]))[N]; -#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) - -//for explicit overrides -#ifdef _MSC_VER -#define OVERRIDE override -#else -#define OVERRIDE //is there any working counterpart? -#endif - -//XXX pls dont - 'debug macros' are usually more trouble than it's worth -#define HANDLE_EXCEPTION \ - catch (const std::exception& e) { \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::exception * e) \ -{ \ - tlog1 << e->what()<< std::endl; \ - throw; \ -} \ - catch (const std::string& e) { \ - tlog1 << e << std::endl; \ - throw; \ -} - -#define HANDLE_EXCEPTIONC(COMMAND) \ - catch (const std::exception& e) { \ - COMMAND; \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::string &e) \ -{ \ - COMMAND; \ - tlog1 << e << std::endl; \ - throw; \ -} - - -#include "../lib/CLogger.h" +// Here you can add specific libraries and macros which are specific to this project. \ No newline at end of file diff --git a/client/UIFramework/CGuiHandler.cpp b/client/UIFramework/CGuiHandler.cpp new file mode 100644 index 000000000..60414ab55 --- /dev/null +++ b/client/UIFramework/CGuiHandler.cpp @@ -0,0 +1,461 @@ +#include "StdInc.h" +#include "CGuiHandler.h" + +#include "IShowActivatable.h" +#include "../SDL_Extensions.h" +#include "CIntObject.h" +#include "../CGameInfo.h" +#include "../CCursorHandler.h" +#include "../../lib/CThreadHelper.h" +#include "../CConfigHandler.h" +#include "../SDL_framerate.h" +#include "IUpdateable.h" + +extern SDL_Surface * screenBuf, * screen2, * screen; +extern std::queue events; +extern boost::mutex eventsM; + +SDL_Color Colors::createColor(int r, int g, int b) +{ + SDL_Color temp = {r, g, b, 0}; + return temp; +} + +SObjectConstruction::SObjectConstruction( CIntObject *obj ) +:myObj(obj) +{ + GH.createdObj.push_front(obj); + GH.captureChildren = true; +} + +SObjectConstruction::~SObjectConstruction() +{ + assert(GH.createdObj.size()); + assert(GH.createdObj.front() == myObj); + GH.createdObj.pop_front(); + GH.captureChildren = GH.createdObj.size(); +} + +SSetCaptureState::SSetCaptureState(bool allow, ui8 actions) +{ + previousCapture = GH.captureChildren; + GH.captureChildren = false; + prevActions = GH.defActionsDef; + GH.defActionsDef = actions; +} + +SSetCaptureState::~SSetCaptureState() +{ + GH.captureChildren = previousCapture; + GH.defActionsDef = prevActions; +} + +void CGuiHandler::popInt( IShowActivatable *top ) +{ + assert(listInt.front() == top); + top->deactivate(); + listInt.pop_front(); + objsToBlit -= top; + if(listInt.size()) + listInt.front()->activate(); + totalRedraw(); +} + +void CGuiHandler::popIntTotally( IShowActivatable *top ) +{ + assert(listInt.front() == top); + popInt(top); + delete top; + fakeMouseMove(); +} + +void CGuiHandler::pushInt( IShowActivatable *newInt ) +{ + //a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway) + screenBuf = screen2; + + if(listInt.size()) + listInt.front()->deactivate(); + listInt.push_front(newInt); + newInt->activate(); + objsToBlit.push_back(newInt); + totalRedraw(); +} + +void CGuiHandler::popInts( int howMany ) +{ + if(!howMany) return; //senseless but who knows... + + assert(listInt.size() >= howMany); + listInt.front()->deactivate(); + for(int i=0; i < howMany; i++) + { + objsToBlit -= listInt.front(); + delete listInt.front(); + listInt.pop_front(); + } + + if(listInt.size()) + { + listInt.front()->activate(); + totalRedraw(); + } + fakeMouseMove(); +} + +IShowActivatable * CGuiHandler::topInt() +{ + if(!listInt.size()) + return NULL; + else + return listInt.front(); +} + +void CGuiHandler::totalRedraw() +{ + for(int i=0;ishowAll(screen2); + + blitAt(screen2,0,0,screen); +} + +void CGuiHandler::updateTime() +{ + int tv = th.getDiff(); + std::list hlp = timeinterested; + for (std::list::iterator i=hlp.begin(); i != hlp.end();i++) + { + if(!vstd::contains(timeinterested,*i)) continue; + if ((*i)->toNextTick>=0) + (*i)->toNextTick-=tv; + if ((*i)->toNextTick<0) + (*i)->tick(); + } +} + +void CGuiHandler::handleEvents() +{ + while(true) + { + SDL_Event *ev = NULL; + boost::unique_lock lock(eventsM); + if(!events.size()) + { + return; + } + else + { + ev = events.front(); + events.pop(); + } + handleEvent(ev); + delete ev; + } +} + +void CGuiHandler::handleEvent(SDL_Event *sEvent) +{ + current = sEvent; + bool prev; + + if (sEvent->type==SDL_KEYDOWN || sEvent->type==SDL_KEYUP) + { + SDL_KeyboardEvent key = sEvent->key; + + //translate numpad keys + if(key.keysym.sym == SDLK_KP_ENTER) + { + key.keysym.sym = (SDLKey)SDLK_RETURN; + } + + bool keysCaptured = false; + for(std::list::iterator i=keyinterested.begin(); i != keyinterested.end() && current; i++) + { + if((*i)->captureAllKeys) + { + keysCaptured = true; + break; + } + } + + std::list miCopy = keyinterested; + for(std::list::iterator i=miCopy.begin(); i != miCopy.end() && current; i++) + if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureAllKeys)) + (**i).keyPressed(key); + } + else if(sEvent->type==SDL_MOUSEMOTION) + { + CCS->curh->cursorMove(sEvent->motion.x, sEvent->motion.y); + handleMouseMotion(sEvent); + } + else if (sEvent->type==SDL_MOUSEBUTTONDOWN) + { + if(sEvent->button.button == SDL_BUTTON_LEFT) + { + + if(lastClick == sEvent->motion && (SDL_GetTicks() - lastClickTime) < 300) + { + std::list hlp = doubleClickInterested; + for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) + { + if(!vstd::contains(doubleClickInterested,*i)) continue; + if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) + { + (*i)->onDoubleClick(); + } + } + + } + + lastClick = sEvent->motion; + lastClickTime = SDL_GetTicks(); + + std::list hlp = lclickable; + for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) + { + if(!vstd::contains(lclickable,*i)) continue; + if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) + { + prev = (*i)->pressedL; + (*i)->pressedL = true; + (*i)->clickLeft(true, prev); + } + } + } + else if (sEvent->button.button == SDL_BUTTON_RIGHT) + { + std::list hlp = rclickable; + for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) + { + if(!vstd::contains(rclickable,*i)) continue; + if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) + { + prev = (*i)->pressedR; + (*i)->pressedR = true; + (*i)->clickRight(true, prev); + } + } + } + else if(sEvent->button.button == SDL_BUTTON_WHEELDOWN || sEvent->button.button == SDL_BUTTON_WHEELUP) + { + std::list hlp = wheelInterested; + for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) + { + if(!vstd::contains(wheelInterested,*i)) continue; + (*i)->wheelScrolled(sEvent->button.button == SDL_BUTTON_WHEELDOWN, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)); + } + } + } + else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT)) + { + std::list hlp = lclickable; + for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) + { + if(!vstd::contains(lclickable,*i)) continue; + prev = (*i)->pressedL; + (*i)->pressedL = false; + if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) + { + (*i)->clickLeft(false, prev); + } + else + (*i)->clickLeft(boost::logic::indeterminate, prev); + } + } + else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT)) + { + std::list hlp = rclickable; + for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) + { + if(!vstd::contains(rclickable,*i)) continue; + prev = (*i)->pressedR; + (*i)->pressedR = false; + if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) + { + (*i)->clickRight(false, prev); + } + else + (*i)->clickRight(boost::logic::indeterminate, prev); + } + } + current = NULL; + +} //event end + +void CGuiHandler::handleMouseMotion(SDL_Event *sEvent) +{ + //sending active, hovered hoverable objects hover() call + std::vector hlp; + for(std::list::iterator i=hoverable.begin(); i != hoverable.end();i++) + { + if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) + { + if (!(*i)->hovered) + hlp.push_back((*i)); + } + else if ((*i)->hovered) + { + (*i)->hover(false); + (*i)->hovered = false; + } + } + for(int i=0; ihover(true); + hlp[i]->hovered = true; + } + + handleMoveInterested(sEvent->motion); +} + +void CGuiHandler::simpleRedraw() +{ + //update only top interface and draw background + if(objsToBlit.size() > 1) + blitAt(screen2,0,0,screen); //blit background + objsToBlit.back()->show(screen); //blit active interface/window +} + +void CGuiHandler::handleMoveInterested( const SDL_MouseMotionEvent & motion ) +{ + //sending active, MotionInterested objects mouseMoved() call + std::list miCopy = motioninterested; + for(std::list::iterator i=miCopy.begin(); i != miCopy.end();i++) + { + if ((*i)->strongInterest || isItIn(&(*i)->pos, motion.x, motion.y)) + { + (*i)->mouseMoved(motion); + } + } +} + +void CGuiHandler::fakeMouseMove() +{ + SDL_Event evnt; + + SDL_MouseMotionEvent sme = {SDL_MOUSEMOTION, 0, 0, 0, 0, 0, 0}; + int x, y; + sme.state = SDL_GetMouseState(&x, &y); + sme.x = x; + sme.y = y; + + evnt.motion = sme; + current = &evnt; + handleMouseMotion(&evnt); +} + +void CGuiHandler::run() +{ + setThreadName(-1, "CGuiHandler::run"); + try + { + if (conf.cc.fullscreen) + CCS->curh->centerCursor(); + + mainFPSmng->init(); // resets internal clock, needed for FPS manager + while(!terminate) + { + if(curInt) + curInt->update(); // calls a update and drawing process of the loaded game interface object at the moment + + mainFPSmng->framerateDelay(); // holds a constant FPS + } + } HANDLE_EXCEPTION +} + +CGuiHandler::CGuiHandler() +:lastClick(-500, -500) +{ + curInt = NULL; + current = NULL; + terminate = false; + statusbar = NULL; + + // Creates the FPS manager and sets the framerate to 48 which is doubled the value of the original Heroes 3 FPS rate + mainFPSmng = new FPSManager(48); + mainFPSmng->init(); // resets internal clock, needed for FPS manager +} + +CGuiHandler::~CGuiHandler() +{ + delete mainFPSmng; +} + +void CGuiHandler::breakEventHandling() +{ + current = NULL; +} + +CIntObject * CGuiHandler::moveChild(CIntObject *obj, CIntObject *from, CIntObject *to, bool adjustPos) +{ + from->removeChild(obj, adjustPos); + to->addChild(obj, adjustPos); + return obj; +} + +void CGuiHandler::drawFPSCounter() +{ + const static SDL_Color yellow = {255, 255, 0, 0}; + static SDL_Rect overlay = { 0, 0, 64, 32}; + Uint32 black = SDL_MapRGB(screen->format, 10, 10, 10); + SDL_FillRect(screen, &overlay, black); + std::string fps = boost::lexical_cast(mainFPSmng->fps); + CSDL_Ext::printAt(fps, 10, 10, FONT_BIG, yellow, screen); +} + +SDLKey CGuiHandler::arrowToNum( SDLKey key ) +{ + switch(key) + { + case SDLK_DOWN: + return SDLK_KP2; + case SDLK_UP: + return SDLK_KP8; + case SDLK_LEFT: + return SDLK_KP4; + case SDLK_RIGHT: + return SDLK_KP6; + default: + assert(0); + } + throw std::string("Wrong key!"); +} + +SDLKey CGuiHandler::numToDigit( SDLKey key ) +{ + if(key >= SDLK_KP0 && key <= SDLK_KP9) + return SDLKey(key - SDLK_KP0 + SDLK_0); + +#define REMOVE_KP(keyName) case SDLK_KP_ ## keyName : return SDLK_ ## keyName; + switch(key) + { + REMOVE_KP(PERIOD) + REMOVE_KP(MINUS) + REMOVE_KP(PLUS) + REMOVE_KP(EQUALS) + + case SDLK_KP_MULTIPLY: + return SDLK_ASTERISK; + case SDLK_KP_DIVIDE: + return SDLK_SLASH; + case SDLK_KP_ENTER: + return SDLK_RETURN; + default: + tlog3 << "Illegal numkey conversion!" << std::endl; + return SDLK_UNKNOWN; + } +#undef REMOVE_KP +} + +bool CGuiHandler::isNumKey( SDLKey key, bool number ) +{ + if(number) + return key >= SDLK_KP0 && key <= SDLK_KP9; + else + return key >= SDLK_KP0 && key <= SDLK_KP_EQUALS; +} + +bool CGuiHandler::isArrowKey( SDLKey key ) +{ + return key >= SDLK_UP && key <= SDLK_LEFT; +} \ No newline at end of file diff --git a/client/UIFramework/CGuiHandler.h b/client/UIFramework/CGuiHandler.h new file mode 100644 index 000000000..448f82e3e --- /dev/null +++ b/client/UIFramework/CGuiHandler.h @@ -0,0 +1,117 @@ +#pragma once + +#include "../../lib/CStopWatch.h" +#include "SPoint.h" + +class FPSManager; +class IStatusBar; +class CIntObject; +class IUpdateable; +class IShowActivatable; +class IShowable; + +/* + * CGuiHandler.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +// Handles GUI logic and drawing +class CGuiHandler +{ +public: + FPSManager * mainFPSmng; //to keep const framerate + CStopWatch th; + std::list listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on) + IStatusBar * statusbar; + + //active GUI elements (listening for events + std::list lclickable; + std::list rclickable; + std::list hoverable; + std::list keyinterested; + std::list motioninterested; + std::list timeinterested; + std::list wheelInterested; + std::list doubleClickInterested; + + //objs to blit + std::vector objsToBlit; + + SDL_Event * current; //current event - can be set to NULL to stop handling event + IUpdateable *curInt; + + SPoint lastClick; + unsigned lastClickTime; + bool terminate; + + CGuiHandler(); + ~CGuiHandler(); + void run(); // holds the main loop for the whole program after initialization and manages the update/rendering system + + void totalRedraw(); //forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering + void simpleRedraw(); //update only top interface and draw background from buffer, sets a flag, method gets called at the end of the rendering + + void popInt(IShowActivatable *top); //removes given interface from the top and activates next + void popIntTotally(IShowActivatable *top); //deactivates, deletes, removes given interface from the top and activates next + void pushInt(IShowActivatable *newInt); //deactivate old top interface, activates this one and pushes to the top + void popInts(int howMany); //pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front + IShowActivatable *topInt(); //returns top interface + + void updateTime(); //handles timeInterested + void handleEvents(); //takes events from queue and calls interested objects + void handleEvent(SDL_Event *sEvent); + void handleMouseMotion(SDL_Event *sEvent); + void handleMoveInterested( const SDL_MouseMotionEvent & motion ); + void fakeMouseMove(); + void breakEventHandling(); //current event won't be propagated anymore + void drawFPSCounter(); // draws the FPS to the upper left corner of the screen + ui8 defActionsDef; //default auto actions + ui8 captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list + std::list createdObj; //stack of objs being created + + static CIntObject * moveChild(CIntObject *obj, CIntObject *from, CIntObject *to, bool adjustPos = false); + static SDLKey arrowToNum(SDLKey key); //converts arrow key to according numpad key + static SDLKey numToDigit(SDLKey key);//converts numpad digit key to normal digit key + static bool isNumKey(SDLKey key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits) + static bool isArrowKey(SDLKey key); +}; + +extern CGuiHandler GH; //global gui handler + +template void pushIntT() +{ + GH.pushInt(new T()); +} + +struct SObjectConstruction +{ + CIntObject *myObj; + SObjectConstruction(CIntObject *obj); + ~SObjectConstruction(); +}; + +struct SSetCaptureState +{ + bool previousCapture; + ui8 prevActions; + SSetCaptureState(bool allow, ui8 actions); + ~SSetCaptureState(); +}; + +namespace Colors +{ + SDL_Color createColor(int r, int g, int b); + + const SDL_Color MetallicGold = createColor(173, 142, 66); + const SDL_Color Yellow = createColor(242, 226, 110); +}; + +#define OBJ_CONSTRUCTION SObjectConstruction obj__i(this) +#define OBJ_CONSTRUCTION_CAPTURING_ALL defActions = 255; SSetCaptureState obj__i1(true, 255); SObjectConstruction obj__i(this) +#define BLOCK_CAPTURING SSetCaptureState obj__i(false, 0) +#define BLOCK_CAPTURING_DONT_TOUCH_REC_ACTIONS SSetCaptureState obj__i(false, GH.defActionsDef) diff --git a/client/UIFramework/CIntObject.cpp b/client/UIFramework/CIntObject.cpp new file mode 100644 index 000000000..3f30244d4 --- /dev/null +++ b/client/UIFramework/CIntObject.cpp @@ -0,0 +1,443 @@ +#include "StdInc.h" +#include "CIntObject.h" +#include "CGuiHandler.h" +#include "../SDL_Extensions.h" + +void CIntObject::activateLClick() +{ + GH.lclickable.push_front(this); + active |= LCLICK; +} + +void CIntObject::deactivateLClick() +{ + std::list::iterator hlp = std::find(GH.lclickable.begin(),GH.lclickable.end(),this); + assert(hlp != GH.lclickable.end()); + GH.lclickable.erase(hlp); + active &= ~LCLICK; +} + +void CIntObject::clickLeft(tribool down, bool previousState) +{ +} + +void CIntObject::activateRClick() +{ + GH.rclickable.push_front(this); + active |= RCLICK; +} + +void CIntObject::deactivateRClick() +{ + std::list::iterator hlp = std::find(GH.rclickable.begin(),GH.rclickable.end(),this); + assert(hlp != GH.rclickable.end()); + GH.rclickable.erase(hlp); + active &= ~RCLICK; +} + +void CIntObject::clickRight(tribool down, bool previousState) +{ +} + +void CIntObject::activateHover() +{ + GH.hoverable.push_front(this); + active |= HOVER; +} + +void CIntObject::deactivateHover() +{ + std::list::iterator hlp = std::find(GH.hoverable.begin(),GH.hoverable.end(),this); + assert(hlp != GH.hoverable.end()); + GH.hoverable.erase(hlp); + active &= ~HOVER; +} + +void CIntObject::hover( bool on ) +{ +} + +void CIntObject::activateKeys() +{ + GH.keyinterested.push_front(this); + active |= KEYBOARD; +} + +void CIntObject::deactivateKeys() +{ + std::list::iterator hlp = std::find(GH.keyinterested.begin(),GH.keyinterested.end(),this); + assert(hlp != GH.keyinterested.end()); + GH.keyinterested.erase(hlp); + active &= ~KEYBOARD; +} + +void CIntObject::keyPressed( const SDL_KeyboardEvent & key ) +{ +} + +void CIntObject::activateMouseMove() +{ + GH.motioninterested.push_front(this); + active |= MOVE; +} + +void CIntObject::deactivateMouseMove() +{ + std::list::iterator hlp = std::find(GH.motioninterested.begin(),GH.motioninterested.end(),this); + assert(hlp != GH.motioninterested.end()); + GH.motioninterested.erase(hlp); + active &= ~MOVE; +} + +void CIntObject::mouseMoved( const SDL_MouseMotionEvent & sEvent ) +{ +} + +void CIntObject::activateTimer() +{ + GH.timeinterested.push_back(this); + active |= TIME; +} + +void CIntObject::deactivateTimer() +{ + std::list::iterator hlp = std::find(GH.timeinterested.begin(),GH.timeinterested.end(),this); + assert(hlp != GH.timeinterested.end()); + GH.timeinterested.erase(hlp); + active &= ~TIME; +} + +void CIntObject::tick() +{ +} + +CIntObject::CIntObject() +{ + pressedL = pressedR = hovered = captureAllKeys = strongInterest = false; + toNextTick = active = used = 0; + + recActions = defActions = GH.defActionsDef; + + pos.x = 0; + pos.y = 0; + pos.w = 0; + pos.h = 0; + + if(GH.captureChildren) + { + assert(GH.createdObj.size()); + parent = GH.createdObj.front(); + parent->children.push_back(this); + + if(parent->defActions & SHARE_POS) + { + pos.x = parent->pos.x; + pos.y = parent->pos.y; + } + } + else + parent = NULL; +} + +void CIntObject::show( SDL_Surface * to ) +{ + if(defActions & UPDATE) + for(size_t i = 0; i < children.size(); i++) + if(children[i]->recActions & UPDATE) + children[i]->show(to); +} + +void CIntObject::showAll( SDL_Surface * to ) +{ + if(defActions & SHOWALL) + { + for(size_t i = 0; i < children.size(); i++) + if(children[i]->recActions & SHOWALL) + children[i]->showAll(to); + + } + else + show(to); +} + +void CIntObject::activate() +{ + assert(!active); + active |= GENERAL; + activate(used); + + if(defActions & ACTIVATE) + for(size_t i = 0; i < children.size(); i++) + if(children[i]->recActions & ACTIVATE) + children[i]->activate(); +} + +void CIntObject::activate(ui16 what) +{ + if(what & LCLICK) + activateLClick(); + if(what & RCLICK) + activateRClick(); + if(what & HOVER) + activateHover(); + if(what & MOVE) + activateMouseMove(); + if(what & KEYBOARD) + activateKeys(); + if(what & TIME) + activateTimer(); + if(what & WHEEL) + activateWheel(); + if(what & DOUBLECLICK) + activateDClick(); +} + +void CIntObject::deactivate() +{ + assert(active); + active &= ~ GENERAL; + deactivate(used); + + assert(!active); + + if(defActions & DEACTIVATE) + for(size_t i = 0; i < children.size(); i++) + if(children[i]->recActions & DEACTIVATE) + children[i]->deactivate(); +} + +void CIntObject::deactivate(ui16 what) +{ + if(what & LCLICK) + deactivateLClick(); + if(what & RCLICK) + deactivateRClick(); + if(what & HOVER) + deactivateHover(); + if(what & MOVE) + deactivateMouseMove(); + if(what & KEYBOARD) + deactivateKeys(); + if(what & TIME) // TIME is special + deactivateTimer(); + if(what & WHEEL) + deactivateWheel(); + if(what & DOUBLECLICK) + deactivateDClick(); +} + +CIntObject::~CIntObject() +{ + assert(!active); //do not delete active obj + + if(defActions & DISPOSE) + for(size_t i = 0; i < children.size(); i++) + if(children[i]->recActions & DISPOSE) + delete children[i]; + + if(parent && GH.createdObj.size()) //temporary object destroyed + parent->children -= this; +} + +void CIntObject::printAtLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ ) +{ + CSDL_Ext::printAt(text, pos.x + x, pos.y + y, font, kolor, dst); +} + +void CIntObject::printAtMiddleLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ ) +{ + CSDL_Ext::printAtMiddle(text, pos.x + x, pos.y + y, font, kolor, dst); +} + +void CIntObject::printAtMiddleLoc(const std::string & text, const SPoint &p, EFonts font, SDL_Color kolor, SDL_Surface * dst) +{ + printAtMiddleLoc(text, p.x, p.y, font, kolor, dst); +} + +void CIntObject::blitAtLoc( SDL_Surface * src, int x, int y, SDL_Surface * dst ) +{ + blitAt(src, pos.x + x, pos.y + y, dst); +} + +void CIntObject::blitAtLoc(SDL_Surface * src, const SPoint &p, SDL_Surface * dst) +{ + blitAtLoc(src, p.x, p.y, dst); +} + +void CIntObject::printAtMiddleWBLoc( const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor, SDL_Surface * dst) +{ + CSDL_Ext::printAtMiddleWB(text, pos.x + x, pos.y + y, font, charpr, kolor, dst); +} + +void CIntObject::printToLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst ) +{ + CSDL_Ext::printTo(text, pos.x + x, pos.y + y, font, kolor, dst); +} + +void CIntObject::disable() +{ + if(active) + deactivate(); + + recActions = DISPOSE; +} + +void CIntObject::enable(bool activation) +{ + if(!active && activation) + activate(); + + recActions = 255; +} + +bool CIntObject::isItInLoc( const SDL_Rect &rect, int x, int y ) +{ + return isItIn(&rect, x - pos.x, y - pos.y); +} + +bool CIntObject::isItInLoc( const SDL_Rect &rect, const SPoint &p ) +{ + return isItIn(&rect, p.x - pos.x, p.y - pos.y); +} + +void CIntObject::activateWheel() +{ + GH.wheelInterested.push_front(this); + active |= WHEEL; +} + +void CIntObject::deactivateWheel() +{ + std::list::iterator hlp = std::find(GH.wheelInterested.begin(),GH.wheelInterested.end(),this); + assert(hlp != GH.wheelInterested.end()); + GH.wheelInterested.erase(hlp); + active &= ~WHEEL; +} + +void CIntObject::wheelScrolled(bool down, bool in) +{ +} + +void CIntObject::activateDClick() +{ + GH.doubleClickInterested.push_front(this); + active |= DOUBLECLICK; +} + +void CIntObject::deactivateDClick() +{ + std::list::iterator hlp = std::find(GH.doubleClickInterested.begin(),GH.doubleClickInterested.end(),this); + assert(hlp != GH.doubleClickInterested.end()); + GH.doubleClickInterested.erase(hlp); + active &= ~DOUBLECLICK; +} + +void CIntObject::onDoubleClick() +{ +} + +void CIntObject::fitToScreen(int borderWidth, bool propagate) +{ + SPoint newPos = pos.topLeft(); + vstd::amax(newPos.x, borderWidth); + vstd::amax(newPos.y, borderWidth); + vstd::amin(newPos.x, screen->w - borderWidth - pos.w); + vstd::amin(newPos.y, screen->h - borderWidth - pos.h); + if (newPos != pos.topLeft()) + moveTo(newPos, propagate); +} + +void CIntObject::moveBy( const SPoint &p, bool propagate /*= true*/ ) +{ + pos.x += p.x; + pos.y += p.y; + if(propagate) + for(size_t i = 0; i < children.size(); i++) + children[i]->moveBy(p, propagate); +} + +void CIntObject::moveTo( const SPoint &p, bool propagate /*= true*/ ) +{ + moveBy(SPoint(p.x - pos.x, p.y - pos.y), propagate); +} + +void CIntObject::delChild(CIntObject *child) +{ + children -= child; + delete child; +} + +void CIntObject::addChild(CIntObject *child, bool adjustPosition /*= false*/) +{ + assert(!vstd::contains(children, child)); + assert(child->parent == NULL); + children.push_back(child); + child->parent = this; + if(adjustPosition) + child->pos += pos; +} + +void CIntObject::removeChild(CIntObject *child, bool adjustPosition /*= false*/) +{ + assert(vstd::contains(children, child)); + assert(child->parent == this); + children -= child; + child->parent = NULL; + if(adjustPosition) + child->pos -= pos; +} + +void CIntObject::changeUsedEvents(ui16 what, bool enable, bool adjust /*= true*/) +{ + if(enable) + { + used |= what; + if(adjust && active) + activate(what); + } + else + { + used &= ~what; + if(adjust && active) + deactivate(what); + } +} + +void CIntObject::drawBorderLoc(SDL_Surface * sur, const SRect &r, const int3 &color) +{ + CSDL_Ext::drawBorder(sur, r + pos, color); +} + +void CIntObject::redraw() +{ + if (parent && (type & REDRAW_PARENT)) + { + parent->redraw(); + } + else + { + showAll(screenBuf); + if(screenBuf != screen) + showAll(screen); + } +} + +const SRect & CIntObject::center( const SRect &r, bool propagate ) +{ + pos.w = r.w; + pos.h = r.h; + return center(SPoint(screen->w/2, screen->h/2), propagate); +} + +const SRect & CIntObject::center( bool propagate ) +{ + return center(pos, propagate); +} + +const SRect & CIntObject::center(const SPoint &p, bool propagate /*= true*/) +{ + moveBy(SPoint(p.x - pos.w/2 - pos.x, + p.y - pos.h/2 - pos.y), + propagate); + return pos; +} \ No newline at end of file diff --git a/client/UIFramework/CIntObject.h b/client/UIFramework/CIntObject.h new file mode 100644 index 000000000..e28c28d50 --- /dev/null +++ b/client/UIFramework/CIntObject.h @@ -0,0 +1,135 @@ +#pragma once + +#include +#include "IShowActivatable.h" +#include "SRect.h" +#include "../FontBase.h" + +struct SDL_Surface; + +/* + * CIntObject.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +using boost::logic::tribool; + +// Base UI element +class CIntObject : public IShowActivatable //interface object +{ +public: + CIntObject *parent; //parent object + std::vector children; + + SRect pos, //position of object on the screen + posRelative; //position of object in the parent (not used if no parent) + + CIntObject(); + virtual ~CIntObject(); //d-tor + + //l-clicks handling + bool pressedL; //for determining if object is L-pressed + void activateLClick(); + void deactivateLClick(); + virtual void clickLeft(tribool down, bool previousState); + + //r-clicks handling + bool pressedR; //for determining if object is R-pressed + void activateRClick(); + void deactivateRClick(); + virtual void clickRight(tribool down, bool previousState); + + //hover handling + bool hovered; //for determining if object is hovered + void activateHover(); + void deactivateHover(); + virtual void hover (bool on); + + //keyboard handling + bool captureAllKeys; //if true, only this object should get info about pressed keys + void activateKeys(); + void deactivateKeys(); + virtual void keyPressed(const SDL_KeyboardEvent & key); + + //mouse movement handling + bool strongInterest; //if true - report all mouse movements, if not - only when hovered + void activateMouseMove(); + void deactivateMouseMove(); + virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent); + + //time handling + int toNextTick; + void activateTimer(); + void deactivateTimer(); + virtual void tick(); + + //mouse wheel + void activateWheel(); + void deactivateWheel(); + virtual void wheelScrolled(bool down, bool in); + + //double click + void activateDClick(); + void deactivateDClick(); + virtual void onDoubleClick(); + + enum {LCLICK=1, RCLICK=2, HOVER=4, MOVE=8, KEYBOARD=16, TIME=32, GENERAL=64, WHEEL=128, DOUBLECLICK=256, ALL=0xffff}; + ui16 active; + ui16 used; + + enum {ACTIVATE=1, DEACTIVATE=2, UPDATE=4, SHOWALL=8, DISPOSE=16, SHARE_POS=32}; + ui8 defActions; //which calls will be tried to be redirected to children + ui8 recActions; //which calls we allow te receive from parent + + enum EAlignment {TOPLEFT, CENTER, BOTTOMRIGHT}; + + void disable(); //deactivates if needed, blocks all automatic activity, allows only disposal + void enable(bool activation = true); //activates if needed, all activity enabled (Warning: may not be symetric with disable if recActions was limited!) + void defActivate(); + void defDeactivate(); + void activate(); + void deactivate(); + void activate(ui16 what); + void deactivate(ui16 what); + void show(SDL_Surface * to); + void showAll(SDL_Surface * to); + void redraw(); + + void drawBorderLoc(SDL_Surface * sur, const SRect &r, const int3 &color); + void printAtLoc(const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst); + void printToLoc(const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst); + void printAtMiddleLoc(const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst); + void printAtMiddleLoc(const std::string & text, const SPoint &p, EFonts font, SDL_Color kolor, SDL_Surface * dst); + void printAtMiddleWBLoc(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor, SDL_Surface * dst); + void blitAtLoc(SDL_Surface * src, int x, int y, SDL_Surface * dst); + void blitAtLoc(SDL_Surface * src, const SPoint &p, SDL_Surface * dst); + bool isItInLoc(const SDL_Rect &rect, int x, int y); + bool isItInLoc(const SDL_Rect &rect, const SPoint &p); + const SRect & center(const SRect &r, bool propagate = true); //sets pos so that r will be in the center of screen, assigns sizes of r to pos, returns new position + const SRect & center(const SPoint &p, bool propagate = true); //moves object so that point p will be in its center + const SRect & center(bool propagate = true); //centers when pos.w and pos.h are set, returns new position + void fitToScreen(int borderWidth, bool propagate = true); //moves window to fit into screen + void moveBy(const SPoint &p, bool propagate = true); + void moveTo(const SPoint &p, bool propagate = true); + void changeUsedEvents(ui16 what, bool enable, bool adjust = true); + + void addChild(CIntObject *child, bool adjustPosition = false); + void removeChild(CIntObject *child, bool adjustPosition = false); + void delChild(CIntObject *child); //removes from children list, deletes + template void delChildNUll(T *&child, bool deactivateIfNeeded = false) //removes from children list, deletes and sets pointer to NULL + { + if(!child) + return; + + if(deactivateIfNeeded && child->active) + child->deactivate(); + + delChild(child); + child = NULL; + } +}; \ No newline at end of file diff --git a/client/UIFramework/CKeyShortcut.cpp b/client/UIFramework/CKeyShortcut.cpp new file mode 100644 index 000000000..e807fedce --- /dev/null +++ b/client/UIFramework/CKeyShortcut.cpp @@ -0,0 +1,20 @@ +#include "StdInc.h" +#include "CKeyShortcut.h" + +void CKeyShortcut::keyPressed(const SDL_KeyboardEvent & key) +{ + if(vstd::contains(assignedKeys,key.keysym.sym)) + { + bool prev = pressedL; + if(key.state == SDL_PRESSED) + { + pressedL = true; + clickLeft(true, prev); + } + else + { + pressedL = false; + clickLeft(false, prev); + } + } +} \ No newline at end of file diff --git a/client/UIFramework/CKeyShortcut.h b/client/UIFramework/CKeyShortcut.h new file mode 100644 index 000000000..ce1d685c7 --- /dev/null +++ b/client/UIFramework/CKeyShortcut.h @@ -0,0 +1,25 @@ +#pragma once + +#include "CIntObject.h" + +/* + * CKeyShortcut.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Class for binding keys to left mouse button clicks +/// Classes wanting use it should have it as one of their base classes +class CKeyShortcut : public virtual CIntObject +{ +public: + std::set assignedKeys; + CKeyShortcut(){}; //c-tor + CKeyShortcut(int key){assignedKeys.insert(key);}; //c-tor + CKeyShortcut(std::set Keys):assignedKeys(Keys){}; //c-tor + virtual void keyPressed(const SDL_KeyboardEvent & key); //call-in +}; \ No newline at end of file diff --git a/client/UIFramework/CPicture.cpp b/client/UIFramework/CPicture.cpp new file mode 100644 index 000000000..e9bb738c4 --- /dev/null +++ b/client/UIFramework/CPicture.cpp @@ -0,0 +1,133 @@ +#include "StdInc.h" +#include "CPicture.h" + +#include "../CBitmapHandler.h" +#include "../SDL_Extensions.h" +#include "../Graphics.h" + + +CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free ) +{ + init(); + bg = BG; + freeSurf = Free; + pos.x += x; + pos.y += y; + pos.w = BG->w; + pos.h = BG->h; +} + +CPicture::CPicture( const std::string &bmpname, int x, int y ) +{ + init(); + bg = BitmapHandler::loadBitmap(bmpname); + freeSurf = true;; + pos.x += x; + pos.y += y; + if(bg) + { + pos.w = bg->w; + pos.h = bg->h; + } + else + { + pos.w = pos.h = 0; + } +} + +CPicture::CPicture(const SRect &r, const SDL_Color &color, bool screenFormat /*= false*/) +{ + init(); + createSimpleRect(r, screenFormat, SDL_MapRGB(bg->format, color.r, color.g,color.b)); +} + +CPicture::CPicture(const SRect &r, ui32 color, bool screenFormat /*= false*/) +{ + init(); + createSimpleRect(r, screenFormat, color); +} + +CPicture::CPicture(SDL_Surface *BG, const SRect &SrcRect, int x /*= 0*/, int y /*= 0*/, bool free /*= false*/) +{ + needRefresh = false; + srcRect = new SRect(SrcRect); + pos.x += x; + pos.y += y; + pos.w = srcRect->w; + pos.h = srcRect->h; + bg = BG; + freeSurf = free; +} + +CPicture::~CPicture() +{ + if(freeSurf) + SDL_FreeSurface(bg); + delete srcRect; +} + +void CPicture::init() +{ + needRefresh = false; + srcRect = NULL; +} + +void CPicture::show( SDL_Surface * to ) +{ + if (needRefresh) + showAll(to); +} + +void CPicture::showAll( SDL_Surface * to ) +{ + if(bg) + { + if(srcRect) + { + SDL_Rect srcRectCpy = *srcRect; + SDL_Rect dstRect = srcRectCpy; + dstRect.x = pos.x; + dstRect.y = pos.y; + + CSDL_Ext::blitSurface(bg, &srcRectCpy, to, &dstRect); + } + else + blitAt(bg, pos, to); + } +} + +void CPicture::convertToScreenBPP() +{ + SDL_Surface *hlp = bg; + bg = SDL_ConvertSurface(hlp,screen->format,0); + SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); + SDL_FreeSurface(hlp); +} + +void CPicture::createSimpleRect(const SRect &r, bool screenFormat, ui32 color) +{ + pos += r; + pos.w = r.w; + pos.h = r.h; + if(screenFormat) + bg = CSDL_Ext::newSurface(r.w, r.h); + else + bg = SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 8, 0, 0, 0, 0); + + SDL_FillRect(bg, NULL, color); + freeSurf = true; +} + +void CPicture::colorizeAndConvert(int player) +{ + assert(bg); + colorize(player); + convertToScreenBPP(); +} + +void CPicture::colorize(int player) +{ + assert(bg); + assert(bg->format->BitsPerPixel == 8); + graphics->blueToPlayersAdv(bg, player); +} \ No newline at end of file diff --git a/client/UIFramework/CPicture.h b/client/UIFramework/CPicture.h new file mode 100644 index 000000000..581100187 --- /dev/null +++ b/client/UIFramework/CPicture.h @@ -0,0 +1,46 @@ +#pragma once + +#include "CIntObject.h" + +struct SDL_Surface; +struct SRect; + +/* + * CPicture.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +// Image class +class CPicture : public CIntObject +{ +public: + SDL_Surface * bg; + SRect * srcRect; //if NULL then whole surface will be used + bool freeSurf; //whether surface will be freed upon CPicture destruction + bool needRefresh;//Surface needs to be displayed each frame + + operator SDL_Surface*() + { + return bg; + } + + CPicture(const SRect & r, const SDL_Color & color, bool screenFormat = false); //rect filled with given color + CPicture(const SRect & r, ui32 color, bool screenFormat = false); //rect filled with given color + CPicture(SDL_Surface * BG, int x = 0, int y=0, bool Free = true); //wrap existing SDL_Surface + CPicture(const std::string &bmpname, int x=0, int y=0); + CPicture(SDL_Surface *BG, const SRect &SrcRext, int x = 0, int y = 0, bool free = false); //wrap subrect of given surface + ~CPicture(); + void init(); + + void createSimpleRect(const SRect &r, bool screenFormat, ui32 color); + void show(SDL_Surface * to); + void showAll(SDL_Surface * to); + void convertToScreenBPP(); + void colorizeAndConvert(int player); + void colorize(int player); +}; \ No newline at end of file diff --git a/client/UIFramework/CSimpleWindow.h b/client/UIFramework/CSimpleWindow.h new file mode 100644 index 000000000..d2649a602 --- /dev/null +++ b/client/UIFramework/CSimpleWindow.h @@ -0,0 +1,23 @@ +#pragma once + +#include "UIFramework/CIntObject.h" + +/* + * CSimpleWindow.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +// Window GUI class +class CSimpleWindow : public CIntObject +{ +public: + SDL_Surface * bitmap; //background + virtual void show(SDL_Surface * to); + CSimpleWindow():bitmap(NULL){}; //c-tor + virtual ~CSimpleWindow(); //d-tor +}; \ No newline at end of file diff --git a/client/UIFramework/IActivatable.h b/client/UIFramework/IActivatable.h new file mode 100644 index 000000000..8608290ec --- /dev/null +++ b/client/UIFramework/IActivatable.h @@ -0,0 +1,20 @@ +#pragma once + +/* + * IActivatable.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +// Defines a activate/deactive method +class IActivatable +{ +public: + virtual void activate()=0; + virtual void deactivate()=0; + virtual ~IActivatable(){}; //d-tor +}; \ No newline at end of file diff --git a/client/UIFramework/IShowActivatable.h b/client/UIFramework/IShowActivatable.h new file mode 100644 index 000000000..a448b9aeb --- /dev/null +++ b/client/UIFramework/IShowActivatable.h @@ -0,0 +1,24 @@ +#pragma once + +#include "IShowable.h" +#include "IActivatable.h" + +/* + * IShowActivatable.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +class IShowActivatable : public IShowable, public IActivatable +{ +public: + //redraw parent flag - this int may be semi-transparent and require redraw of parent window + enum {WITH_GARRISON = 1, BLOCK_ADV_HOTKEYS = 2, WITH_ARTIFACTS = 4, REDRAW_PARENT=8}; + int type; //bin flags using etype + IShowActivatable(); + virtual ~IShowActivatable(){}; //d-tor +}; \ No newline at end of file diff --git a/client/UIFramework/IShowable.h b/client/UIFramework/IShowable.h new file mode 100644 index 000000000..cb503fa3d --- /dev/null +++ b/client/UIFramework/IShowable.h @@ -0,0 +1,26 @@ +#pragma once + +struct SDL_Surface; + +/* + * IShowable.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +// Defines a show method +class IShowable +{ +public: + virtual void redraw()=0; + virtual void show(SDL_Surface * to)=0; + virtual void showAll(SDL_Surface * to) + { + show(to); + } + virtual ~IShowable(){}; //d-tor +}; \ No newline at end of file diff --git a/client/UIFramework/IStatusBar.h b/client/UIFramework/IStatusBar.h new file mode 100644 index 000000000..97973820d --- /dev/null +++ b/client/UIFramework/IStatusBar.h @@ -0,0 +1,24 @@ +#pragma once + +struct SDL_Surface; + +/* + * IStatusBar.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +// Status bar interface +class IStatusBar +{ +public: + virtual ~IStatusBar(){}; //d-tor + virtual void print(const std::string & text)=0; //prints text and refreshes statusbar + virtual void clear()=0;//clears statusbar and refreshes + virtual void show(SDL_Surface * to)=0; //shows statusbar (with current text) + virtual std::string getCurrent()=0; //returns currently displayed text +}; \ No newline at end of file diff --git a/client/UIFramework/IUpdateable.h b/client/UIFramework/IUpdateable.h new file mode 100644 index 000000000..abec612fa --- /dev/null +++ b/client/UIFramework/IUpdateable.h @@ -0,0 +1,18 @@ +#pragma once + +/* + * IUpdateable.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +class IUpdateable +{ +public: + virtual void update()=0; + virtual ~IUpdateable(){}; //d-tor +}; \ No newline at end of file diff --git a/client/UIFramework/SPoint.h b/client/UIFramework/SPoint.h new file mode 100644 index 000000000..f722780d5 --- /dev/null +++ b/client/UIFramework/SPoint.h @@ -0,0 +1,87 @@ +#pragma once + +#include "../../lib/int3.h" +#include + +/* + * SPoint.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +// A point with x/y coordinate, used mostly for graphic rendering +struct SPoint +{ + int x, y; + + //constructors + SPoint() + { + x = y = 0; + }; + SPoint(int X, int Y) + :x(X),y(Y) + {}; + SPoint(const int3 &a) + :x(a.x),y(a.y) + {} + SPoint(const SDL_MouseMotionEvent &a) + :x(a.x),y(a.y) + {} + + template + SPoint operator+(const T &b) const + { + return SPoint(x+b.x,y+b.y); + } + + template + SPoint operator*(const T &mul) const + { + return SPoint(x*mul, y*mul); + } + + template + SPoint& operator+=(const T &b) + { + x += b.x; + y += b.y; + return *this; + } + + template + SPoint operator-(const T &b) const + { + return SPoint(x - b.x, y - b.y); + } + + template + SPoint& operator-=(const T &b) + { + x -= b.x; + y -= b.y; + return *this; + } + bool operator<(const SPoint &b) const //product order + { + return x < b.x && y < b.y; + } + template SPoint& operator=(const T &t) + { + x = t.x; + y = t.y; + return *this; + } + template bool operator==(const T &t) const + { + return x == t.x && y == t.y; + } + template bool operator!=(const T &t) const + { + return !(*this == t); + } +}; \ No newline at end of file diff --git a/client/UIFramework/SRect.cpp b/client/UIFramework/SRect.cpp new file mode 100644 index 000000000..b4f016dd1 --- /dev/null +++ b/client/UIFramework/SRect.cpp @@ -0,0 +1,19 @@ +#include "StdInc.h" +#include "SRect.h" + +extern SDL_Surface * screen; + +SRect SRect::createCentered( int w, int h ) +{ + return SRect(screen->w/2 - w/2, screen->h/2 - h/2, w, h); +} + +SRect SRect::around(const SRect &r, int width /*= 1*/) /*creates rect around another */ +{ + return SRect(r.x - width, r.y - width, r.w + width * 2, r.h + width * 2); +} + +SRect SRect::centerIn(const SRect &r) +{ + return SRect(r.x + (r.w - w) / 2, r.y + (r.h - h) / 2, w, h); +} \ No newline at end of file diff --git a/client/UIFramework/SRect.h b/client/UIFramework/SRect.h new file mode 100644 index 000000000..bcb005460 --- /dev/null +++ b/client/UIFramework/SRect.h @@ -0,0 +1,187 @@ +#pragma once + +#include +#include "SPoint.h" + +/* + * SRect.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#ifdef max +#undef max +#endif +#ifdef min +#undef min +#endif + +/// Rectangle class, which have a position and a size +struct SRect : public SDL_Rect +{ + SRect()//default c-tor + { + x = y = w = h = -1; + } + SRect(int X, int Y, int W, int H) //c-tor + { + x = X; + y = Y; + w = W; + h = H; + } + SRect(const SPoint & position, const SPoint & size) //c-tor + { + x = position.x; + y = position.y; + w = size.x; + h = size.y; + } + SRect(const SDL_Rect & r) //c-tor + { + x = r.x; + y = r.y; + w = r.w; + h = r.h; + } + explicit SRect(const SDL_Surface * const &surf) + { + x = y = 0; + w = surf->w; + h = surf->h; + } + + SRect centerIn(const SRect &r); + static SRect createCentered(int w, int h); + static SRect around(const SRect &r, int width = 1); //creates rect around another + + bool isIn(int qx, int qy) const //determines if given point lies inside rect + { + if (qx > x && qxy && qy SRect operator-(const T &t) + { + return SRect(x - t.x, y - t.y, w, h); + } + SRect operator&(const SRect &p) const //rect intersection + { + bool intersect = true; + + if(p.topLeft().y < y && p.bottomLeft().y < y) //rect p is above *this + { + intersect = false; + } + else if(p.topLeft().y > y+h && p.bottomLeft().y > y+h) //rect p is below *this + { + intersect = false; + } + else if(p.topLeft().x > x+w && p.topRight().x > x+w) //rect p is on the right hand side of this + { + intersect = false; + } + else if(p.topLeft().x < x && p.topRight().x < x) //rect p is on the left hand side of this + { + intersect = false; + } + + if(intersect) + { + SRect ret; + ret.x = std::max(this->x, p.x); + ret.y = std::max(this->y, p.y); + SPoint bR; //bottomRight point of returned rect + bR.x = std::min(this->w+this->x, p.w+p.x); + bR.y = std::min(this->h+this->y, p.h+p.y); + ret.w = bR.x - ret.x; + ret.h = bR.y - ret.y; + return ret; + } + else + { + return SRect(); + } + } + SRect operator|(const SRect &p) const //union of two rects + { + SRect ret; + ret.x = std::min(p.x, this->x); + ret.y = std::min(p.y, this->y); + int x2 = std::max(p.x+p.w, this->x+this->w); + int y2 = std::max(p.y+p.h, this->y+this->h); + ret.w = x2 -ret.x; + ret.h = y2 -ret.y; + return ret; + } +}; \ No newline at end of file diff --git a/client/VCMI_client.cbp b/client/VCMI_client.cbp deleted file mode 100644 index 97d7f9bc1..000000000 --- a/client/VCMI_client.cbp +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - diff --git a/client/VCMI_client.vcxproj b/client/VCMI_client.vcxproj index 8c6dc0515..4dc7d49cf 100644 --- a/client/VCMI_client.vcxproj +++ b/client/VCMI_client.vcxproj @@ -231,9 +231,10 @@ + + - @@ -248,7 +249,6 @@ - @@ -265,7 +265,6 @@ - @@ -275,8 +274,14 @@ Create StdInc.h + + + + + + @@ -286,9 +291,10 @@ + + - @@ -304,7 +310,6 @@ - @@ -324,13 +329,24 @@ - + + + + + + + + + + + + diff --git a/client/VCMI_client.vcxproj.filters b/client/VCMI_client.vcxproj.filters new file mode 100644 index 000000000..fe0c4514f --- /dev/null +++ b/client/VCMI_client.vcxproj.filters @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + BattleInterface + + + BattleInterface + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + BattleInterface + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + UIFramework + + + + BattleInterface + + + BattleInterface + + + + + + + + + + + + {3b4624b5-80f2-4bd8-b4c0-af29d3be4b58} + + + {918a73d4-7386-4d29-9515-a3579051d4ac} + + + \ No newline at end of file diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index 3b96ddad6..3ad0ac222 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -15,6 +15,7 @@ #include "CConfigHandler.h" #include "../lib/CGeneralTextHandler.h" #include "../lib/GameConstants.h" +#include "../lib/CStopWatch.h" /* * mapHandler.cpp, part of VCMI engine @@ -335,7 +336,7 @@ void CMapHandler::initHeroDef(const CGHeroInstance * h) } void CMapHandler::init() { - StopWatch th; + CStopWatch th; th.getDiff(); graphics->advmapobjGraphics[8][0]["AB01_.DEF"] = graphics->boatAnims[0]; diff --git a/client/vcmi_client/.dep.inc b/client/vcmi_client/.dep.inc deleted file mode 100644 index 4560e55af..000000000 --- a/client/vcmi_client/.dep.inc +++ /dev/null @@ -1,5 +0,0 @@ -# This code depends on make tool being used -DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES})) -ifneq (${DEPFILES},) -include ${DEPFILES} -endif diff --git a/client/vcmi_client/Makefile b/client/vcmi_client/Makefile deleted file mode 100644 index 30bc67837..000000000 --- a/client/vcmi_client/Makefile +++ /dev/null @@ -1,92 +0,0 @@ -# -# There exist several targets which are by default empty and which can be -# used for execution of your targets. These targets are usually executed -# before and after some main targets. They are: -# -# .build-pre: called before 'build' target -# .build-post: called after 'build' target -# .clean-pre: called before 'clean' target -# .clean-post: called after 'clean' target -# .clobber-pre: called before 'clobber' target -# .clobber-post: called after 'clobber' target -# .all-pre: called before 'all' target -# .all-post: called after 'all' target -# .help-pre: called before 'help' target -# .help-post: called after 'help' target -# -# Targets beginning with '.' are not intended to be called on their own. -# -# Main targets can be executed directly, and they are: -# -# build build a specific configuration -# clean remove built files from a configuration -# clobber remove all built files -# all build all configurations -# help print help mesage -# -# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and -# .help-impl are implemented in nbproject/makefile-impl.mk. -# -# NOCDDL - - -# Environment -MKDIR=mkdir -CP=cp -CCADMIN=CCadmin -RANLIB=ranlib - - -# build -build: .build-post - -.build-pre: -# Add your pre 'build' code here... - -.build-post: .build-impl -# Add your post 'build' code here... - - -# clean -clean: .clean-post - -.clean-pre: -# Add your pre 'clean' code here... - -.clean-post: .clean-impl -# Add your post 'clean' code here... - - -# clobber -clobber: .clobber-post - -.clobber-pre: -# Add your pre 'clobber' code here... - -.clobber-post: .clobber-impl -# Add your post 'clobber' code here... - - -# all -all: .all-post - -.all-pre: -# Add your pre 'all' code here... - -.all-post: .all-impl -# Add your post 'all' code here... - - -# help -help: .help-post - -.help-pre: -# Add your pre 'help' code here... - -.help-post: .help-impl -# Add your post 'help' code here... - - - -# include project implementation makefile -include nbproject/Makefile-impl.mk diff --git a/client/vcmi_client/nbproject/Makefile-Debug.mk b/client/vcmi_client/nbproject/Makefile-Debug.mk deleted file mode 100644 index fe68952be..000000000 --- a/client/vcmi_client/nbproject/Makefile-Debug.mk +++ /dev/null @@ -1,221 +0,0 @@ -# -# Generated Makefile - do not edit! -# -# Edit the Makefile in the project folder instead (../Makefile). Each target -# has a -pre and a -post target defined where you can add customized code. -# -# This makefile implements configuration specific macros and targets. - - -# Environment -MKDIR=mkdir -CP=cp -CCADMIN=CCadmin -RANLIB=ranlib -CC=gcc -CCC=g++ -CXX=g++ -FC=gfortran - -# Macros -PLATFORM=GNU-Linux-x86 - -# Include project Makefile -include Makefile - -# Object Directory -OBJECTDIR=build/Debug/${PLATFORM} - -# Object Files -OBJECTFILES= \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o - -# C Compiler Flags -CFLAGS= - -# CC Compiler Flags -CCFLAGS=-D_GNU_SOURCE=1 -D_REENTRANT -CXXFLAGS=-D_GNU_SOURCE=1 -D_REENTRANT - -# Fortran Compiler Flags -FFLAGS= - -# Link Libraries and Options -LDLIBSOPTIONS=-L../../../../boost/lib -Wl,-rpath ../../lib/vcmi_lib/dist/Debug/GNU-Linux-x86 -L../../lib/vcmi_lib/dist/Debug/GNU-Linux-x86 -lvcmi_lib - -# Build Targets -.build-conf: ${BUILD_SUBPROJECTS} - ${MAKE} -f nbproject/Makefile-Debug.mk dist/Debug/${PLATFORM}/vcmi_client - -dist/Debug/${PLATFORM}/vcmi_client: ../../lib/vcmi_lib/dist/Debug/GNU-Linux-x86/libvcmi_lib.so - -dist/Debug/${PLATFORM}/vcmi_client: ${OBJECTFILES} - ${MKDIR} -p dist/Debug/${PLATFORM} - ${LINK.cc} -lboost_system-mt -lboost_thread-mt -lboost_filesystem-mt -lSDL -lSDL_ttf -lSDL_image -lSDL_mixer -o dist/Debug/${PLATFORM}/vcmi_client ${OBJECTFILES} ${LDLIBSOPTIONS} - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o: ../../hch/CSpellHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o ../../hch/CSpellHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o: ../../CLuaHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o ../../CLuaHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o: ../CSpellWindow.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o ../CSpellWindow.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o: ../../CCastleInterface.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o ../../CCastleInterface.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o: ../../CCursorHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o ../../CCursorHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o: ../../hch/CObjectHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o ../../hch/CObjectHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o: ../CCreatureAnimation.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o ../CCreatureAnimation.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o: ../Client.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o ../Client.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o: ../../CGameInfo.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o ../../CGameInfo.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o: ../../CHeroWindow.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o ../../CHeroWindow.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o: ../../CMessage.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o ../../CMessage.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o: ../../CPlayerInterface.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o ../../CPlayerInterface.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o: ../../hch/CAbilityHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o ../../hch/CAbilityHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o: ../../hch/CSndHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o ../../hch/CSndHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o: ../../CBattleInterface.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o ../../CBattleInterface.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o: ../../mapHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o ../../mapHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o: ../../CPathfinder.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o ../../CPathfinder.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o: ../../CGameInterface.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o ../../CGameInterface.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o: ../../CPreGame.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o ../../CPreGame.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o: ../CBitmapHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o ../CBitmapHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o: ../Graphics.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o ../Graphics.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o: ../../hch/CDefHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o ../../hch/CDefHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o: ../../AdventureMapButton.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o ../../AdventureMapButton.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o: ../../SDL_Extensions.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o ../../SDL_Extensions.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o: ../CConfigHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o ../CConfigHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o: ../../CAdvmapInterface.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o ../../CAdvmapInterface.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o: ../../CThreadHelper.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o ../../CThreadHelper.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o: ../../hch/CMusicHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o ../../hch/CMusicHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o: ../../SDL_framerate.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o ../../SDL_framerate.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o: ../../CCallback.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o ../../CCallback.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o: ../../CMT.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -g -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o ../../CMT.cpp - -# Subprojects -.build-subprojects: - cd ../../lib/vcmi_lib && ${MAKE} -f Makefile-nb CONF=Debug - -# Clean Targets -.clean-conf: ${CLEAN_SUBPROJECTS} - ${RM} -r build/Debug - ${RM} dist/Debug/${PLATFORM}/vcmi_client - -# Subprojects -.clean-subprojects: - cd ../../lib/vcmi_lib && ${MAKE} -f Makefile-nb CONF=Debug clean diff --git a/client/vcmi_client/nbproject/Makefile-Release.mk b/client/vcmi_client/nbproject/Makefile-Release.mk deleted file mode 100644 index 521abcda1..000000000 --- a/client/vcmi_client/nbproject/Makefile-Release.mk +++ /dev/null @@ -1,217 +0,0 @@ -# -# Generated Makefile - do not edit! -# -# Edit the Makefile in the project folder instead (../Makefile). Each target -# has a -pre and a -post target defined where you can add customized code. -# -# This makefile implements configuration specific macros and targets. - - -# Environment -MKDIR=mkdir -CP=cp -CCADMIN=CCadmin -RANLIB=ranlib -CC=gcc -CCC=g++ -CXX=g++ -FC=gfortran - -# Macros -PLATFORM=GNU-Linux-x86 - -# Include project Makefile -include Makefile - -# Object Directory -OBJECTDIR=build/Release/${PLATFORM} - -# Object Files -OBJECTFILES= \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o - -# C Compiler Flags -CFLAGS= - -# CC Compiler Flags -CCFLAGS= -CXXFLAGS= - -# Fortran Compiler Flags -FFLAGS= - -# Link Libraries and Options -LDLIBSOPTIONS= - -# Build Targets -.build-conf: ${BUILD_SUBPROJECTS} - ${MAKE} -f nbproject/Makefile-Release.mk dist/Release/${PLATFORM}/vcmi_client - -dist/Release/${PLATFORM}/vcmi_client: ${OBJECTFILES} - ${MKDIR} -p dist/Release/${PLATFORM} - ${LINK.cc} -o dist/Release/${PLATFORM}/vcmi_client ${OBJECTFILES} ${LDLIBSOPTIONS} - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o: ../../hch/CSpellHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o ../../hch/CSpellHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o: ../../CLuaHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o ../../CLuaHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o: ../CSpellWindow.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o ../CSpellWindow.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o: ../../CCastleInterface.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o ../../CCastleInterface.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o: ../../CCursorHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o ../../CCursorHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o: ../../hch/CObjectHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o ../../hch/CObjectHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o: ../CCreatureAnimation.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o ../CCreatureAnimation.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o: ../Client.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o ../Client.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o: ../../CGameInfo.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o ../../CGameInfo.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o: ../../CHeroWindow.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o ../../CHeroWindow.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o: ../../CMessage.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o ../../CMessage.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o: ../../CPlayerInterface.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o ../../CPlayerInterface.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o: ../../hch/CAbilityHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o ../../hch/CAbilityHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o: ../../hch/CSndHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o ../../hch/CSndHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o: ../../CBattleInterface.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o ../../CBattleInterface.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o: ../../mapHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o ../../mapHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o: ../../CPathfinder.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o ../../CPathfinder.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o: ../../CGameInterface.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o ../../CGameInterface.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o: ../../CPreGame.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o ../../CPreGame.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o: ../CBitmapHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o ../CBitmapHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o: ../Graphics.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o ../Graphics.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o: ../../hch/CDefHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o ../../hch/CDefHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o: ../../AdventureMapButton.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o ../../AdventureMapButton.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o: ../../SDL_Extensions.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o ../../SDL_Extensions.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o: ../CConfigHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o ../CConfigHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o: ../../CAdvmapInterface.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o ../../CAdvmapInterface.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o: ../../CThreadHelper.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o ../../CThreadHelper.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o: ../../hch/CMusicHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o ../../hch/CMusicHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o: ../../SDL_framerate.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o ../../SDL_framerate.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o: ../../CCallback.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o ../../CCallback.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o: ../../CMT.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o ../../CMT.cpp - -# Subprojects -.build-subprojects: - -# Clean Targets -.clean-conf: - ${RM} -r build/Release - ${RM} dist/Release/${PLATFORM}/vcmi_client - -# Subprojects -.clean-subprojects: diff --git a/client/vcmi_client/nbproject/Makefile-impl.mk b/client/vcmi_client/nbproject/Makefile-impl.mk deleted file mode 100644 index 7f2bda8a1..000000000 --- a/client/vcmi_client/nbproject/Makefile-impl.mk +++ /dev/null @@ -1,123 +0,0 @@ -# -# Generated Makefile - do not edit! -# -# Edit the Makefile in the project folder instead (../Makefile). Each target -# has a pre- and a post- target defined where you can add customization code. -# -# This makefile implements macros and targets common to all configurations. -# -# NOCDDL - - -# Building and Cleaning subprojects are done by default, but can be controlled with the SUB -# macro. If SUB=no, subprojects will not be built or cleaned. The following macro -# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf -# and .clean-reqprojects-conf unless SUB has the value 'no' -SUB_no=NO -SUBPROJECTS=${SUB_${SUB}} -BUILD_SUBPROJECTS_=.build-subprojects -BUILD_SUBPROJECTS_NO= -BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}} -CLEAN_SUBPROJECTS_=.clean-subprojects -CLEAN_SUBPROJECTS_NO= -CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}} - - -# Project Name -PROJECTNAME=vcmi_client - -# Active Configuration -DEFAULTCONF=Debug -CONF=${DEFAULTCONF} - -# All Configurations -ALLCONFS=Debug Release - - -# build -.build-impl: .build-pre .validate-impl .depcheck-impl - @#echo "=> Running $@... Configuration=$(CONF)" - ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf - - -# clean -.clean-impl: .clean-pre .validate-impl .depcheck-impl - @#echo "=> Running $@... Configuration=$(CONF)" - ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf - - -# clobber -.clobber-impl: .clobber-pre .depcheck-impl - @#echo "=> Running $@..." - for CONF in ${ALLCONFS}; \ - do \ - ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf; \ - done - -# all -.all-impl: .all-pre .depcheck-impl - @#echo "=> Running $@..." - for CONF in ${ALLCONFS}; \ - do \ - ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf; \ - done - -# dependency checking support -.depcheck-impl: - @echo "# This code depends on make tool being used" >.dep.inc - @if [ -n "${MAKE_VERSION}" ]; then \ - echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \ - echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ - echo "include \$${DEPFILES}" >>.dep.inc; \ - echo "endif" >>.dep.inc; \ - else \ - echo ".KEEP_STATE:" >>.dep.inc; \ - echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ - fi - -# configuration validation -.validate-impl: - @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ - then \ - echo ""; \ - echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \ - echo "See 'make help' for details."; \ - echo "Current directory: " `pwd`; \ - echo ""; \ - fi - @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ - then \ - exit 1; \ - fi - - -# help -.help-impl: .help-pre - @echo "This makefile supports the following configurations:" - @echo " ${ALLCONFS}" - @echo "" - @echo "and the following targets:" - @echo " build (default target)" - @echo " clean" - @echo " clobber" - @echo " all" - @echo " help" - @echo "" - @echo "Makefile Usage:" - @echo " make [CONF=] [SUB=no] build" - @echo " make [CONF=] [SUB=no] clean" - @echo " make [SUB=no] clobber" - @echo " make [SUB=no] all" - @echo " make help" - @echo "" - @echo "Target 'build' will build a specific configuration and, unless 'SUB=no'," - @echo " also build subprojects." - @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no'," - @echo " also clean subprojects." - @echo "Target 'clobber' will remove all built files from all configurations and," - @echo " unless 'SUB=no', also from subprojects." - @echo "Target 'all' will will build all configurations and, unless 'SUB=no'," - @echo " also build subprojects." - @echo "Target 'help' prints this message." - @echo "" - diff --git a/client/vcmi_client/nbproject/Package-Debug.bash b/client/vcmi_client/nbproject/Package-Debug.bash deleted file mode 100644 index dc9e4c6f1..000000000 --- a/client/vcmi_client/nbproject/Package-Debug.bash +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash -x - -# -# Generated - do not edit! -# - -# Macros -TOP=`pwd` -PLATFORM=GNU-Linux-x86 -TMPDIR=build/Debug/${PLATFORM}/tmp-packaging -TMPDIRNAME=tmp-packaging -OUTPUT_PATH=dist/Debug/${PLATFORM}/vcmi_client -OUTPUT_BASENAME=vcmi_client -PACKAGE_TOP_DIR=vcmiclient/ - -# Functions -function checkReturnCode -{ - rc=$? - if [ $rc != 0 ] - then - exit $rc - fi -} -function makeDirectory -# $1 directory path -# $2 permission (optional) -{ - mkdir -p "$1" - checkReturnCode - if [ "$2" != "" ] - then - chmod $2 "$1" - checkReturnCode - fi -} -function copyFileToTmpDir -# $1 from-file path -# $2 to-file path -# $3 permission -{ - cp "$1" "$2" - checkReturnCode - if [ "$3" != "" ] - then - chmod $3 "$2" - checkReturnCode - fi -} - -# Setup -cd "${TOP}" -mkdir -p dist/Debug/${PLATFORM}/package -rm -rf ${TMPDIR} -mkdir -p ${TMPDIR} - -# Copy files and create directories and links -cd "${TOP}" -makeDirectory ${TMPDIR}/vcmiclient/bin -copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 - - -# Generate tar file -cd "${TOP}" -rm -f dist/Debug/${PLATFORM}/package/vcmiclient.tar -cd ${TMPDIR} -tar -vcf ../../../../dist/Debug/${PLATFORM}/package/vcmiclient.tar * -checkReturnCode - -# Cleanup -cd "${TOP}" -rm -rf ${TMPDIR} diff --git a/client/vcmi_client/nbproject/Package-Release.bash b/client/vcmi_client/nbproject/Package-Release.bash deleted file mode 100644 index 8e0f3b406..000000000 --- a/client/vcmi_client/nbproject/Package-Release.bash +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash -x - -# -# Generated - do not edit! -# - -# Macros -TOP=`pwd` -PLATFORM=GNU-Linux-x86 -TMPDIR=build/Release/${PLATFORM}/tmp-packaging -TMPDIRNAME=tmp-packaging -OUTPUT_PATH=dist/Release/${PLATFORM}/vcmi_client -OUTPUT_BASENAME=vcmi_client -PACKAGE_TOP_DIR=vcmiclient/ - -# Functions -function checkReturnCode -{ - rc=$? - if [ $rc != 0 ] - then - exit $rc - fi -} -function makeDirectory -# $1 directory path -# $2 permission (optional) -{ - mkdir -p "$1" - checkReturnCode - if [ "$2" != "" ] - then - chmod $2 "$1" - checkReturnCode - fi -} -function copyFileToTmpDir -# $1 from-file path -# $2 to-file path -# $3 permission -{ - cp "$1" "$2" - checkReturnCode - if [ "$3" != "" ] - then - chmod $3 "$2" - checkReturnCode - fi -} - -# Setup -cd "${TOP}" -mkdir -p dist/Release/${PLATFORM}/package -rm -rf ${TMPDIR} -mkdir -p ${TMPDIR} - -# Copy files and create directories and links -cd "${TOP}" -makeDirectory ${TMPDIR}/vcmiclient/bin -copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 - - -# Generate tar file -cd "${TOP}" -rm -f dist/Release/${PLATFORM}/package/vcmiclient.tar -cd ${TMPDIR} -tar -vcf ../../../../dist/Release/${PLATFORM}/package/vcmiclient.tar * -checkReturnCode - -# Cleanup -cd "${TOP}" -rm -rf ${TMPDIR} diff --git a/client/vcmi_client/nbproject/configurations.xml b/client/vcmi_client/nbproject/configurations.xml deleted file mode 100644 index 478288b70..000000000 --- a/client/vcmi_client/nbproject/configurations.xml +++ /dev/null @@ -1,594 +0,0 @@ - - - - - ../../AdventureMapButton.h - ../../AI_Base.h - ../../hch/CAbilityHandler.h - ../../CAdvmapInterface.h - ../../hch/CAmbarCendamo.h - ../../hch/CArtHandler.h - ../../CBattleInterface.h - ../CBitmapHandler.h - ../../hch/CBuildingHandler.h - ../../CCallback.h - ../../CCastleInterface.h - ../CConfigHandler.h - ../CCreatureAnimation.h - ../../CCursorHandler.h - ../../hch/CDefHandler.h - ../../CGameInfo.h - ../../CGameInterface.h - ../../hch/CHeroHandler.h - ../../CHeroWindow.h - ../Client.h - ../../CLuaHandler.h - ../../CMessage.h - ../../hch/CMusicHandler.h - ../../hch/CObjectHandler.h - ../../CPathfinder.h - ../../CPlayerInterface.h - ../../CPreGame.h - ../../hch/CSndHandler.h - ../CSpellWindow.h - ../../CThreadHelper.h - ../FunctionList.h - ../../global.h - ../Graphics.h - ../../int3.h - ../../map.h - ../../mapHandler.h - ../../nodrze.h - ../../SDL_framerate.h - ../../StartInfo.h - ../../stdafx.h - ../../timeHandler.h - - - - - ../../AdventureMapButton.cpp - ../../hch/CAbilityHandler.cpp - ../../CAdvmapInterface.cpp - ../../CBattleInterface.cpp - ../CBitmapHandler.cpp - ../../CCallback.cpp - ../../CCastleInterface.cpp - ../CConfigHandler.cpp - ../CCreatureAnimation.cpp - ../../CCursorHandler.cpp - ../../hch/CDefHandler.cpp - ../../CGameInfo.cpp - ../../CGameInterface.cpp - ../../CHeroWindow.cpp - ../Client.cpp - ../../CLuaHandler.cpp - ../../CMessage.cpp - ../../CMT.cpp - ../../hch/CMusicHandler.cpp - ../../hch/CObjectHandler.cpp - ../../CPathfinder.cpp - ../../CPlayerInterface.cpp - ../../CPreGame.cpp - ../../hch/CSndHandler.cpp - ../../hch/CSpellHandler.cpp - ../CSpellWindow.cpp - ../../CThreadHelper.cpp - ../Graphics.cpp - ../../mapHandler.cpp - ../../SDL_Extensions.cpp - ../../SDL_framerate.cpp - - - Makefile - - - - .. - - Makefile - - - - localhost - GNU|GNU - 2 - - - - - /usr/include/SDL - ../../../../boost/include/boost-1_37 - .. - ../../hch - /usr/include/lua5.1 - - -D_GNU_SOURCE=1 -D_REENTRANT - - - dist/Debug/${PLATFORM}/vcmi_client - - ../../../../boost/lib - - - - - - - - -lboost_system-mt -lboost_thread-mt -lboost_filesystem-mt -lSDL -lSDL_ttf -lSDL_image -lSDL_mixer - - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 1 - - - 3 - - - 3 - - - 3 - - - 1 - - - 3 - - - 3 - - - 3 - - - 3 - - - 1 - - - 3 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 3 - - - 1 - - - 3 - - - 3 - - - 3 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 3 - - - 1 - - - 3 - - - - - localhost - GNU|GNU - 2 - - - - 5 - - - 5 - - - 5 - - - - - - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 1 - - - 3 - - - 3 - - - 3 - - - 1 - - - 3 - - - 3 - - - 3 - - - 3 - - - 1 - - - 3 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 3 - - - 1 - - - 3 - - - 3 - - - 3 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 3 - - - 1 - - - 3 - - - - diff --git a/client/vcmi_client/nbproject/private/configurations.xml b/client/vcmi_client/nbproject/private/configurations.xml deleted file mode 100644 index 554a2aa96..000000000 --- a/client/vcmi_client/nbproject/private/configurations.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - Makefile - 0 - - - - gdb - 10 - - - - - true - 0 - 0 - - - - - - - gdb - 10 - - - - - true - 0 - 0 - - - - - - diff --git a/client/vcmi_client/nbproject/private/private.properties b/client/vcmi_client/nbproject/private/private.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/vcmi_client/nbproject/private/private.xml b/client/vcmi_client/nbproject/private/private.xml deleted file mode 100644 index a764863ba..000000000 --- a/client/vcmi_client/nbproject/private/private.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - file:/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.cpp - 67 - - - file:/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.cpp - 638 - - - file:/home/t0/vcmi/trunk/CPreGame.h - 272 - - - file:/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.cpp - 1754 - 2257 - - - file:/home/t0/vcmi/trunk/CMessage.cpp - 103 - - - diff --git a/client/vcmi_client/nbproject/project.properties b/client/vcmi_client/nbproject/project.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/vcmi_client/nbproject/project.xml b/client/vcmi_client/nbproject/project.xml deleted file mode 100644 index ae8f80dbe..000000000 --- a/client/vcmi_client/nbproject/project.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - org.netbeans.modules.cnd.makeproject - - - vcmi_client - 0 - - cpp - h - UTF-8 - - ../../lib/vcmi_lib - - - - diff --git a/lib/BattleAction.cpp b/lib/BattleAction.cpp index cf7d54c33..00f6b23e7 100644 --- a/lib/BattleAction.cpp +++ b/lib/BattleAction.cpp @@ -32,7 +32,7 @@ BattleAction BattleAction::makeDefend(const CStack *stack) } -BattleAction BattleAction::makeMeleeAttack(const CStack *stack, const CStack * attacked, SHexField attackFrom /*= SHexField::INVALID*/) +BattleAction BattleAction::makeMeleeAttack(const CStack *stack, const CStack * attacked, SBattleHex attackFrom /*= SBattleHex::INVALID*/) { BattleAction ba; ba.side = !stack->attackerOwned; @@ -62,7 +62,7 @@ BattleAction BattleAction::makeShotAttack(const CStack *shooter, const CStack *t return ba; } -BattleAction BattleAction::makeMove(const CStack *stack, SHexField dest) +BattleAction BattleAction::makeMove(const CStack *stack, SBattleHex dest) { BattleAction ba; ba.side = !stack->attackerOwned; diff --git a/lib/BattleAction.h b/lib/BattleAction.h index 896bda764..84b508838 100644 --- a/lib/BattleAction.h +++ b/lib/BattleAction.h @@ -1,7 +1,7 @@ #pragma once -#include "SHexField.h" +#include "SBattleHex.h" /* * BattleAction.h, part of VCMI engine @@ -26,7 +26,7 @@ struct DLL_LINKAGE BattleAction STACK_HEAL, DAEMON_SUMMONING }; si8 actionType; //use ActionType enum for values - SHexField destinationTile; + SBattleHex destinationTile; si32 additionalInfo; // e.g. spell number if type is 1 || 10; tile to attack if type is 6 template void serialize(Handler &h, const int version) { @@ -37,8 +37,8 @@ struct DLL_LINKAGE BattleAction static BattleAction makeDefend(const CStack *stack); static BattleAction makeWait(const CStack *stack); - static BattleAction makeMeleeAttack(const CStack *stack, const CStack * attacked, SHexField attackFrom = SHexField::INVALID); + static BattleAction makeMeleeAttack(const CStack *stack, const CStack * attacked, SBattleHex attackFrom = SBattleHex::INVALID); static BattleAction makeShotAttack(const CStack *shooter, const CStack *target); - static BattleAction makeMove(const CStack *stack, SHexField dest); + static BattleAction makeMove(const CStack *stack, SBattleHex dest); static BattleAction makeEndOFTacticPhase(ui8 side); }; diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index e25c6c44b..8343cf40f 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -103,7 +103,7 @@ const CStack * BattleInfo::getStack(int stackID, bool onlyAlive) const return const_cast(this)->getStack(stackID, onlyAlive); } -CStack * BattleInfo::getStackT(SHexField tileID, bool onlyAlive) +CStack * BattleInfo::getStackT(SBattleHex tileID, bool onlyAlive) { for(ui32 g=0; g(this)->getStackT(tileID, onlyAlive); } -void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack * stackToOmmit) const +void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack * stackToOmmit) const { memset(accessibility, 1, GameConstants::BFIELD_SIZE); //initialize array with trues @@ -153,7 +153,7 @@ void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool atta //obstacles for(ui32 b=0; b blocked = VLC->heroh->obstacles[obstacles[b].ID].getBlocked(obstacles[b].pos); + std::vector blocked = VLC->heroh->obstacles[obstacles[b].ID].getBlocked(obstacles[b].pos); for(ui32 c=0; c=0 && blocked[c] < GameConstants::BFIELD_SIZE) @@ -170,9 +170,9 @@ void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool atta accessibility[permanentlyLocked[b]] = false; } - static const std::pair lockedIfNotDestroyed[] = //(which part of wall, which hex is blocked if this part of wall is not destroyed - {std::make_pair(2, SHexField(182)), std::make_pair(3, SHexField(130)), - std::make_pair(4, SHexField(62)), std::make_pair(5, SHexField(29))}; + static const std::pair lockedIfNotDestroyed[] = //(which part of wall, which hex is blocked if this part of wall is not destroyed + {std::make_pair(2, SBattleHex(182)), std::make_pair(3, SBattleHex(130)), + std::make_pair(4, SBattleHex(62)), std::make_pair(5, SBattleHex(29))}; for(int b=0; b rem; //tiles to unlock + std::set rem; //tiles to unlock for(int h=0; h > hexq; //bfs queue (second filed used only if fillPredecessors is true) + std::queue< std::pair > hexq; //bfs queue (second filed used only if fillPredecessors is true) hexq.push(std::make_pair(start, true)); dists[hexq.front().first] = 0; int curNext = -1; //for bfs loop only (helper var) while(!hexq.empty()) //bfs loop { - std::pair curHex = hexq.front(); - std::vector neighbours = curHex.first.neighbouringTiles(); + std::pair curHex = hexq.front(); + std::vector neighbours = curHex.first.neighbouringTiles(); hexq.pop(); for(ui32 nr=0; nr BattleInfo::getAccessibility( const CStack * stack, bool addOccupiable, std::vector * attackable ) const +std::vector BattleInfo::getAccessibility( const CStack * stack, bool addOccupiable, std::vector * attackable ) const { - std::vector ret; + std::vector ret; bool ac[GameConstants::BFIELD_SIZE]; if(stack->position < 0) //turrets - return std::vector(); + return std::vector(); - std::set occupyable; + std::set occupyable; getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, addOccupiable, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack); - SHexField pr[GameConstants::BFIELD_SIZE]; + SBattleHex pr[GameConstants::BFIELD_SIZE]; int dist[GameConstants::BFIELD_SIZE]; makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false); @@ -285,7 +285,7 @@ std::vector BattleInfo::getAccessibility( const CStack * stack, bool { if(!addOccupiable) { - std::vector rem; + std::vector rem; for(int b=0; b BattleInfo::getAccessibility( const CStack * stack, bool { struct HLP { - static bool meleeAttackable(SHexField hex, const std::vector & baseRng) + static bool meleeAttackable(SBattleHex hex, const std::vector & baseRng) { - BOOST_FOREACH(SHexField h, baseRng) + BOOST_FOREACH(SBattleHex h, baseRng) { - if(SHexField::mutualPosition(h, hex) > 0) + if(SBattleHex::mutualPosition(h, hex) > 0) return true; } @@ -347,7 +347,7 @@ std::vector BattleInfo::getAccessibility( const CStack * stack, bool if(otherSt->owner == stack->owner) continue; - std::vector occupiedBySecond; + std::vector occupiedBySecond; occupiedBySecond.push_back(otherSt->position); if(otherSt->doubleWide()) occupiedBySecond.push_back(otherSt->occupiedHex()); @@ -360,7 +360,7 @@ std::vector BattleInfo::getAccessibility( const CStack * stack, bool } - BOOST_FOREACH(SHexField he, occupiedBySecond) + BOOST_FOREACH(SBattleHex he, occupiedBySecond) { if(HLP::meleeAttackable(he, ret)) attackable->push_back(he); @@ -386,7 +386,7 @@ int BattleInfo::getAvaliableHex(TCreature creID, bool attackerOwned, int initial } bool ac[GameConstants::BFIELD_SIZE]; - std::set occupyable; + std::set occupyable; bool twoHex = VLC->creh->creatures[creID]->isDoubleWide(); bool flying = VLC->creh->creatures[creID]->isFlying();// vstd::contains(VLC->creh->creatures[creID]->bonuses, Bonus::FLYING); getAccessibilityMap(ac, twoHex, attackerOwned, true, occupyable, flying); @@ -419,21 +419,21 @@ bool BattleInfo::isStackBlocked(const CStack * stack) const return false; } -std::pair< std::vector, int > BattleInfo::getPath(SHexField start, SHexField dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned) +std::pair< std::vector, int > BattleInfo::getPath(SBattleHex start, SBattleHex dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned) { - SHexField predecessor[GameConstants::BFIELD_SIZE]; //for getting the Path + SBattleHex predecessor[GameConstants::BFIELD_SIZE]; //for getting the Path int dist[GameConstants::BFIELD_SIZE]; //calculated distances makeBFS(start, accessibility, predecessor, dist, twoHex, attackerOwned, flyingCreature, false); if(predecessor[dest] == -1) //cannot reach destination { - return std::make_pair(std::vector(), 0); + return std::make_pair(std::vector(), 0); } //making the Path - std::vector path; - SHexField curElem = dest; + std::vector path; + SBattleHex curElem = dest; while(curElem != start) { path.push_back(curElem); @@ -721,7 +721,7 @@ void BattleInfo::calculateCasualties( std::map *casualties ) const } } -std::set BattleInfo::getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, SHexField destinationTile ) +std::set BattleInfo::getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, SBattleHex destinationTile ) { std::set attackedHexes = s->rangeInHexes(destinationTile, skillLevel); std::set attackedCres; /*std::set to exclude multiple occurrences of two hex creatures*/ @@ -801,24 +801,24 @@ std::set BattleInfo::getAttackedCreatures(const CSpell * s, int skillLe } return attackedCres; } -void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, SHexField destinationTile, SHexField attackerPos) +void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos) { const int WN = GameConstants::BFIELD_WIDTH; - ui16 hex = (attackerPos != SHexField::INVALID) ? attackerPos.hex : attacker->position.hex; //real or hypothetical (cursor) position + ui16 hex = (attackerPos != SBattleHex::INVALID) ? attackerPos.hex : attacker->position.hex; //real or hypothetical (cursor) position if (attacker->hasBonusOfType(Bonus::ATTACKS_ALL_ADJACENT)) { - std::vector hexes = attacker->getSurroundingHexes(attackerPos); - BOOST_FOREACH (SHexField tile, hexes) + std::vector hexes = attacker->getSurroundingHexes(attackerPos); + BOOST_FOREACH (SBattleHex tile, hexes) { at.hostileCreaturePositions.insert(tile); } } if (attacker->hasBonusOfType(Bonus::THREE_HEADED_ATTACK)) { - std::vector hexes = attacker->getSurroundingHexes(attackerPos); - BOOST_FOREACH (SHexField tile, hexes) + std::vector hexes = attacker->getSurroundingHexes(attackerPos); + BOOST_FOREACH (SBattleHex tile, hexes) { - if ((SHexField::mutualPosition(tile, destinationTile) > -1 && SHexField::mutualPosition(tile, hex) > -1) //adjacent both to attacker's head and attacked tile + if ((SBattleHex::mutualPosition(tile, destinationTile) > -1 && SBattleHex::mutualPosition(tile, hex) > -1) //adjacent both to attacker's head and attacked tile || tile == destinationTile) //or simply attacked directly { CStack * st = getStackT(tile, true); @@ -831,26 +831,26 @@ void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack } if (attacker->hasBonusOfType(Bonus::TWO_HEX_ATTACK_BREATH)) { - std::vector hexes; //only one, in fact + std::vector hexes; //only one, in fact int pseudoVector = destinationTile.hex - hex; switch (pseudoVector) { case 1: case -1: - SHexField::checkAndPush(destinationTile.hex + pseudoVector, hexes); + SBattleHex::checkAndPush(destinationTile.hex + pseudoVector, hexes); break; case WN: //17 case WN + 1: //18 case -WN: //-17 case -WN + 1: //-16 - SHexField::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : -1 ), hexes); + SBattleHex::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : -1 ), hexes); break; case WN-1: //16 case -WN-1: //-18 - SHexField::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : 0), hexes); + SBattleHex::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : 0), hexes); break; } - BOOST_FOREACH (SHexField tile, hexes) + BOOST_FOREACH (SBattleHex tile, hexes) { CStack * st = getStackT(tile, true); if(st) //friendly stacks can also be damaged by Dragon Breath @@ -860,12 +860,12 @@ void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack } } } -std::set BattleInfo::getAttackedCreatures(const CStack* attacker, SHexField destinationTile, SHexField attackerPos) +std::set BattleInfo::getAttackedCreatures(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos) { //TODO: caching? AttackableTiles at; getPotentiallyAttackableHexes(at, attacker, destinationTile, attackerPos); std::set attackedCres; - BOOST_FOREACH (SHexField tile, at.hostileCreaturePositions) //all around & three-headed attack + BOOST_FOREACH (SBattleHex tile, at.hostileCreaturePositions) //all around & three-headed attack { CStack * st = getStackT(tile, true); if(st && st->owner != attacker->owner) //only hostile stacks - does it work well with Berserk? @@ -873,7 +873,7 @@ std::set BattleInfo::getAttackedCreatures(const CStack* attacker, SHexF attackedCres.insert(st); } } - BOOST_FOREACH (SHexField tile, at.friendlyCreaturePositions) + BOOST_FOREACH (SBattleHex tile, at.friendlyCreaturePositions) { CStack * st = getStackT(tile, true); if(st) //friendly stacks can also be damaged by Dragon Breath @@ -884,12 +884,12 @@ std::set BattleInfo::getAttackedCreatures(const CStack* attacker, SHexF return attackedCres; } -std::set BattleInfo::getAttackedHexes(const CStack* attacker, SHexField destinationTile, SHexField attackerPos) +std::set BattleInfo::getAttackedHexes(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos) { AttackableTiles at; getPotentiallyAttackableHexes(at, attacker, destinationTile, attackerPos); - std::set attackedHexes; - BOOST_FOREACH (SHexField tile, at.hostileCreaturePositions) + std::set attackedHexes; + BOOST_FOREACH (SBattleHex tile, at.hostileCreaturePositions) { CStack * st = getStackT(tile, true); if(st && st->owner != attacker->owner) //only hostile stacks - does it work well with Berserk? @@ -897,7 +897,7 @@ std::set BattleInfo::getAttackedHexes(const CStack* attacker, SHexFie attackedHexes.insert(tile); } } - BOOST_FOREACH (SHexField tile, at.friendlyCreaturePositions) + BOOST_FOREACH (SBattleHex tile, at.friendlyCreaturePositions) { CStack * st = getStackT(tile, true); if(st) //friendly stacks can also be damaged by Dragon Breath @@ -913,7 +913,7 @@ std::set BattleInfo::getAdjacentCreatures (const CStack * stack) const std::set stacks; CStack * localStack; - BOOST_FOREACH (SHexField hex, stack->getSurroundingHexes()) + BOOST_FOREACH (SBattleHex hex, stack->getSurroundingHexes()) { localStack = const_cast(getStackT(hex, true)); //only alive? if (localStack) @@ -940,7 +940,7 @@ int BattleInfo::calculateSpellDuration( const CSpell * spell, const CGHeroInstan } } -CStack * BattleInfo::generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, SHexField position) const +CStack * BattleInfo::generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, SBattleHex position) const { int owner = attackerOwned ? sides[0] : sides[1]; assert((owner >= GameConstants::PLAYER_LIMIT) || @@ -950,7 +950,7 @@ CStack * BattleInfo::generateNewStack(const CStackInstance &base, int stackID, b ret->position = position; return ret; } -CStack * BattleInfo::generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, SHexField position) const +CStack * BattleInfo::generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, SBattleHex position) const { int owner = attackerOwned ? sides[0] : sides[1]; CStack * ret = new CStack(&base, owner, stackID, attackerOwned, slot); @@ -981,7 +981,7 @@ ui32 BattleInfo::getSpellCost(const CSpell * sp, const CGHeroInstance * caster) return ret - manaReduction + manaIncrease; } -int BattleInfo::hexToWallPart(SHexField hex) const +int BattleInfo::hexToWallPart(SBattleHex hex) const { if(siege == 0) //there is no battle! return -1; @@ -1007,14 +1007,14 @@ int BattleInfo::lineToWallHex( int line ) const return lineToHex[line]; } -std::pair BattleInfo::getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const +std::pair BattleInfo::getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const { bool ac[GameConstants::BFIELD_SIZE]; - std::set occupyable; + std::set occupyable; getAccessibilityMap(ac, closest->doubleWide(), closest->attackerOwned, false, occupyable, closest->hasBonusOfType(Bonus::FLYING), closest); - SHexField predecessor[GameConstants::BFIELD_SIZE]; + SBattleHex predecessor[GameConstants::BFIELD_SIZE]; int dist[GameConstants::BFIELD_SIZE]; makeBFS(closest->position, ac, predecessor, dist, closest->doubleWide(), closest->attackerOwned, closest->hasBonusOfType(Bonus::FLYING), true); @@ -1055,7 +1055,7 @@ std::pair BattleInfo::getNearestStack(const CStack * return std::make_pair(minPair.second, predecessor[minPair.first.second]); } - return std::make_pair(NULL, SHexField::INVALID); + return std::make_pair(NULL, SBattleHex::INVALID); } ui32 BattleInfo::calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature) const { @@ -1251,13 +1251,13 @@ void BattleInfo::getStackQueue( std::vector &out, int howMany, i } } -si8 BattleInfo::hasDistancePenalty( const CStack * stack, SHexField destHex ) const +si8 BattleInfo::hasDistancePenalty( const CStack * stack, SBattleHex destHex ) const { struct HLP { - static bool lowerAnalyze(const CStack * stack, SHexField hex) + static bool lowerAnalyze(const CStack * stack, SBattleHex hex) { - int distance = SHexField::getDistance(hex, stack->position); + int distance = SBattleHex::getDistance(hex, stack->position); //I hope it's approximately correct return distance > 10 && !stack->hasBonusOfType(Bonus::NO_DISTANCE_PENALTY); @@ -1283,7 +1283,7 @@ si8 BattleInfo::sameSideOfWall(int pos1, int pos2) const return stackLeft != destLeft; } -si8 BattleInfo::hasWallPenalty( const CStack* stack, SHexField destHex ) const +si8 BattleInfo::hasWallPenalty( const CStack* stack, SBattleHex destHex ) const { if (!siege || stack->hasBonusOfType(Bonus::NO_WALL_PENALTY)) { @@ -1308,11 +1308,11 @@ si8 BattleInfo::hasWallPenalty( const CStack* stack, SHexField destHex ) const return false; } -si8 BattleInfo::canTeleportTo(const CStack * stack, SHexField destHex, int telportLevel) const +si8 BattleInfo::canTeleportTo(const CStack * stack, SBattleHex destHex, int telportLevel) const { bool ac[GameConstants::BFIELD_SIZE]; - std::set occupyable; + std::set occupyable; getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack); @@ -1327,7 +1327,7 @@ si8 BattleInfo::canTeleportTo(const CStack * stack, SHexField destHex, int telpo } -bool BattleInfo::battleCanShoot(const CStack * stack, SHexField dest) const +bool BattleInfo::battleCanShoot(const CStack * stack, SBattleHex dest) const { const CStack *dst = getStackT(dest); @@ -1375,7 +1375,7 @@ bool BattleInfo::battleCanFlee(int player) const return true; } -const CStack * BattleInfo::battleGetStack(SHexField pos, bool onlyAlive) +const CStack * BattleInfo::battleGetStack(SBattleHex pos, bool onlyAlive) { CStack * stack = NULL; for(ui32 g=0; gdoubleWide() && stacks[g]->attackerOwned) { - stacks[g]->position += SHexField::RIGHT; + stacks[g]->position += SBattleHex::RIGHT; } else if(stacks[g]->doubleWide() && !stacks[g]->attackerOwned) { if (stacks[g]->position.getX() > 1) - stacks[g]->position += SHexField::LEFT; + stacks[g]->position += SBattleHex::LEFT; } } @@ -1663,7 +1663,7 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const coi.uniqueID = curB->obstacles.size(); coi.ID = possibleObstacles[rand()%possibleObstacles.size()]; coi.pos = rand()%GameConstants::BFIELD_SIZE; - std::vector block = VLC->heroh->obstacles[coi.ID].getBlocked(coi.pos); + std::vector block = VLC->heroh->obstacles[coi.ID].getBlocked(coi.pos); bool badObstacle = false; for(int b=0; b 0 && dest.getX() <= tacticDistance) @@ -1931,7 +1931,7 @@ ESpellCastProblem::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int pla return ESpellCastProblem::OK; } -ESpellCastProblem::ESpellCastProblem BattleInfo::battleCanCastThisSpellHere( int player, const CSpell * spell, ECastingMode::ECastingMode mode, SHexField dest ) const +ESpellCastProblem::ESpellCastProblem BattleInfo::battleCanCastThisSpellHere( int player, const CSpell * spell, ECastingMode::ECastingMode mode, SBattleHex dest ) const { ESpellCastProblem::ESpellCastProblem moreGeneralProblem = battleCanCastThisSpell(player, spell, mode); if(moreGeneralProblem != ESpellCastProblem::OK) @@ -2093,7 +2093,7 @@ bool BattleInfo::battleTestElementalImmunity(const CStack * subject, const CSpel return false; } -ESpellCastProblem::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, ECastingMode::ECastingMode mode, SHexField dest) const +ESpellCastProblem::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, ECastingMode::ECastingMode mode, SBattleHex dest) const { const CStack * subject = getStackT(dest, false); if(subject) @@ -2320,7 +2320,7 @@ void CStack::init() owner = 255; slot = 255; attackerOwned = false; - position = SHexField(); + position = SBattleHex(); counterAttacks = -1; } @@ -2605,7 +2605,7 @@ bool CStack::doubleWide() const return getCreature()->doubleWide; } -SHexField CStack::occupiedHex() const +SBattleHex CStack::occupiedHex() const { if (doubleWide()) { @@ -2616,54 +2616,54 @@ SHexField CStack::occupiedHex() const } else { - return SHexField::INVALID; + return SBattleHex::INVALID; } } -std::vector CStack::getHexes() const +std::vector CStack::getHexes() const { - std::vector hexes; - hexes.push_back(SHexField(position)); - SHexField occupied = occupiedHex(); + std::vector hexes; + hexes.push_back(SBattleHex(position)); + SBattleHex occupied = occupiedHex(); if(occupied.isValid()) hexes.push_back(occupied); return hexes; } -bool CStack::coversPos(SHexField pos) const +bool CStack::coversPos(SBattleHex pos) const { return vstd::contains(getHexes(), pos); } -std::vector CStack::getSurroundingHexes(SHexField attackerPos) const +std::vector CStack::getSurroundingHexes(SBattleHex attackerPos) const { - SHexField hex = (attackerPos != SHexField::INVALID) ? attackerPos : position; //use hypothetical position - std::vector hexes; + SBattleHex hex = (attackerPos != SBattleHex::INVALID) ? attackerPos : position; //use hypothetical position + std::vector hexes; if (doubleWide()) { const int WN = GameConstants::BFIELD_WIDTH; if(attackerOwned) { //position is equal to front hex - SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN+2 : WN+1 ), hexes); - SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); - SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); - SHexField::checkAndPush(hex - 2, hexes); - SHexField::checkAndPush(hex + 1, hexes); - SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN-2 : WN-1 ), hexes); - SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); - SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); + SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+2 : WN+1 ), hexes); + SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); + SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); + SBattleHex::checkAndPush(hex - 2, hexes); + SBattleHex::checkAndPush(hex + 1, hexes); + SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-2 : WN-1 ), hexes); + SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); + SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); } else { - SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); - SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); - SHexField::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN-2 ), hexes); - SHexField::checkAndPush(hex + 2, hexes); - SHexField::checkAndPush(hex - 1, hexes); - SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); - SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); - SHexField::checkAndPush(hex + ( (hex/WN)%2 ? WN+1 : WN+2 ), hexes); + SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); + SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); + SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN-2 ), hexes); + SBattleHex::checkAndPush(hex + 2, hexes); + SBattleHex::checkAndPush(hex - 1, hexes); + SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); + SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); + SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN+1 : WN+2 ), hexes); } return hexes; } @@ -2764,7 +2764,7 @@ void CStack::prepareAttacked(BattleStackAttacked &bsa) const } } -bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defender, SHexField attackerPos /*= SHexField::INVALID*/, SHexField defenderPos /*= SHexField::INVALID*/) +bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defender, SBattleHex attackerPos /*= SBattleHex::INVALID*/, SBattleHex defenderPos /*= SBattleHex::INVALID*/) { if (!attackerPos.isValid()) { @@ -2776,13 +2776,13 @@ bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defen } return - (SHexField::mutualPosition(attackerPos, defenderPos) >= 0) //front <=> front + (SBattleHex::mutualPosition(attackerPos, defenderPos) >= 0) //front <=> front || (attacker->doubleWide() //back <=> front - && SHexField::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos) >= 0) + && SBattleHex::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos) >= 0) || (defender->doubleWide() //front <=> back - && SHexField::mutualPosition(attackerPos, defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0) + && SBattleHex::mutualPosition(attackerPos, defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0) || (defender->doubleWide() && attacker->doubleWide()//back <=> back - && SHexField::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0); + && SBattleHex::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0); } diff --git a/lib/BattleState.h b/lib/BattleState.h index f4f6f29d0..2b15989b3 100644 --- a/lib/BattleState.h +++ b/lib/BattleState.h @@ -1,7 +1,7 @@ #pragma once -#include "SHexField.h" +#include "SBattleHex.h" #include "HeroBonus.h" #include "CCreatureSet.h" #include "CObjectHandler.h" @@ -41,8 +41,8 @@ struct DLL_LINKAGE SiegeInfo struct DLL_LINKAGE AttackableTiles { - std::set hostileCreaturePositions; - std::set friendlyCreaturePositions; //for Dragon Breath + std::set hostileCreaturePositions; + std::set friendlyCreaturePositions; //for Dragon Breath template void serialize(Handler &h, const int version) { h & hostileCreaturePositions & friendlyCreaturePositions; @@ -87,14 +87,14 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode void getStackQueue(std::vector &out, int howMany, int turn = 0, int lastMoved = -1) const; //returns stack in order of their movement action CStack * getStack(int stackID, bool onlyAlive = true); const CStack * getStack(int stackID, bool onlyAlive = true) const; - CStack * getStackT(SHexField tileID, bool onlyAlive = true); - const CStack * getStackT(SHexField tileID, bool onlyAlive = true) const; - void getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack* stackToOmmit = NULL) const; //send pointer to at least 187 allocated bytes - static bool isAccessible(SHexField hex, bool * accessibility, bool twoHex, bool attackerOwned, bool flying, bool lastPos); //helper for makeBFS + CStack * getStackT(SBattleHex tileID, bool onlyAlive = true); + const CStack * getStackT(SBattleHex tileID, bool onlyAlive = true) const; + void getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack* stackToOmmit = NULL) const; //send pointer to at least 187 allocated bytes + static bool isAccessible(SBattleHex hex, bool * accessibility, bool twoHex, bool attackerOwned, bool flying, bool lastPos); //helper for makeBFS int getAvaliableHex(TCreature creID, bool attackerOwned, int initialPos = -1) const; //find place for summon / clone effects - void makeBFS(SHexField start, bool*accessibility, SHexField *predecessor, int *dists, bool twoHex, bool attackerOwned, bool flying, bool fillPredecessors) const; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result - std::pair< std::vector, int > getPath(SHexField start, SHexField dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned); //returned value: pair; length may be different than number of elements in path since flying vreatures jump between distant hexes - std::vector getAccessibility(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL) const; //returns vector of accessible tiles (taking into account the creature range) + void makeBFS(SBattleHex start, bool*accessibility, SBattleHex *predecessor, int *dists, bool twoHex, bool attackerOwned, bool flying, bool fillPredecessors) const; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result + std::pair< std::vector, int > getPath(SBattleHex start, SBattleHex dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned); //returned value: pair; length may be different than number of elements in path since flying vreatures jump between distant hexes + std::vector getAccessibility(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL) const; //returns vector of accessible tiles (taking into account the creature range) bool isStackBlocked(const CStack * stack) const; //returns true if there is neighboring enemy stack @@ -102,35 +102,35 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode TDmgRange calculateDmgRange(const CStack* attacker, const CStack* defender, TQuantity attackerCount, TQuantity defenderCount, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky, bool deathBlow, bool ballistaDoubleDmg) const; //charge - number of hexes travelled before attack (for champion's jousting); returns pair TDmgRange calculateDmgRange(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky, bool deathBlow, bool ballistaDoubleDmg) const; //charge - number of hexes travelled before attack (for champion's jousting); returns pair void calculateCasualties(std::map *casualties) const; //casualties are array of maps size 2 (attacker, defeneder), maps are (crid => amount) - std::set getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, SHexField destinationTile); //calculates stack affected by given spell - void getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, SHexField destinationTile, SHexField attackerPos); //hexes around target that could be attacked in melee - std::set getAttackedCreatures(const CStack* attacker, SHexField destinationTile, SHexField attackerPos = SHexField::INVALID); //calculates range of multi-hex attacks - std::set getAttackedHexes(const CStack* attacker, SHexField destinationTile, SHexField attackerPos = SHexField::INVALID); //calculates range of multi-hex attacks + std::set getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, SBattleHex destinationTile); //calculates stack affected by given spell + void getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos); //hexes around target that could be attacked in melee + std::set getAttackedCreatures(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos = SBattleHex::INVALID); //calculates range of multi-hex attacks + std::set getAttackedHexes(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos = SBattleHex::INVALID); //calculates range of multi-hex attacks std::set getAdjacentCreatures (const CStack * stack) const; static int calculateSpellDuration(const CSpell * spell, const CGHeroInstance * caster, int usedSpellPower); - CStack * generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, SHexField position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield - CStack * generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, SHexField position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield + CStack * generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, SBattleHex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield + CStack * generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, SBattleHex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield ui32 getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //returns cost of given spell - int hexToWallPart(SHexField hex) const; //returns part of destructible wall / gate / keep under given hex or -1 if not found + int hexToWallPart(SBattleHex hex) const; //returns part of destructible wall / gate / keep under given hex or -1 if not found int lineToWallHex(int line) const; //returns hex with wall in given line - std::pair getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const; //if attackerOwned is indetermnate, returened stack is of any owner; hex is the number of hex we should be looking from; returns (nerarest creature, predecessorHex) + std::pair getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const; //if attackerOwned is indetermnate, returened stack is of any owner; hex is the number of hex we should be looking from; returns (nerarest creature, predecessorHex) ui32 calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature) const; ui32 calculateSpellDmg(const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature, int spellSchoolLevel, int usedSpellPower) const; //calculates damage inflicted by spell ui32 calculateHealedHP(const CGHeroInstance * caster, const CSpell * spell, const CStack * stack) const; ui32 calculateHealedHP(int healedHealth, const CSpell * spell, const CStack * stack) const; //for Archangel ui32 calculateHealedHP(const CSpell * spell, int usedSpellPower, int spellSchoolLevel, const CStack * stack) const; //unused bool resurrects(TSpell spellid) const; //TODO: move it to spellHandler? - si8 hasDistancePenalty(const CStack * stackID, SHexField destHex) const; //determines if given stack has distance penalty shooting given pos + si8 hasDistancePenalty(const CStack * stackID, SBattleHex destHex) const; //determines if given stack has distance penalty shooting given pos si8 sameSideOfWall(int pos1, int pos2) const; //determines if given positions are on the same side of wall - si8 hasWallPenalty(const CStack * stack, SHexField destHex) const; //determines if given stack has wall penalty shooting given pos - si8 canTeleportTo(const CStack * stack, SHexField destHex, int telportLevel) const; //determines if given stack can teleport to given place - bool battleCanShoot(const CStack * stack, SHexField dest) const; //determines if stack with given ID shoot at the selected destination + si8 hasWallPenalty(const CStack * stack, SBattleHex destHex) const; //determines if given stack has wall penalty shooting given pos + si8 canTeleportTo(const CStack * stack, SBattleHex destHex, int telportLevel) const; //determines if given stack can teleport to given place + bool battleCanShoot(const CStack * stack, SBattleHex dest) const; //determines if stack with given ID shoot at the selected destination const CGHeroInstance * getHero(int player) const; //returns fighting hero that belongs to given player ESpellCastProblem::ESpellCastProblem battleCanCastSpell(int player, ECastingMode::ECastingMode mode) const; //returns true if there are no general issues preventing from casting a spell ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(int player, const CSpell * spell, ECastingMode::ECastingMode mode) const; //checks if given player can cast given spell - ESpellCastProblem::ESpellCastProblem battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, ECastingMode::ECastingMode mode, SHexField dest) const; //checks for creature immunity / anything that prevent casting *at given hex* - doesn't take into acount general problems such as not having spellbook or mana points etc. - ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(int player, const CSpell * spell, ECastingMode::ECastingMode mode, SHexField dest) const; //checks if given player can cast given spell at given tile in given mode + ESpellCastProblem::ESpellCastProblem battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, ECastingMode::ECastingMode mode, SBattleHex dest) const; //checks for creature immunity / anything that prevent casting *at given hex* - doesn't take into acount general problems such as not having spellbook or mana points etc. + ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(int player, const CSpell * spell, ECastingMode::ECastingMode mode, SBattleHex dest) const; //checks if given player can cast given spell at given tile in given mode bool battleTestElementalImmunity(const CStack * subject, const CSpell * spell, Bonus::BonusType element, bool damageSpell) const; TSpell getRandomBeneficialSpell(const CStack * subject) const; TSpell getRandomCastedSpell(const CStack * caster) const; //called at the beginning of turn for Faerie Dragon @@ -139,12 +139,12 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode bool battleCanFlee(int player) const; //returns true if player can flee from the battle - const CStack * battleGetStack(SHexField pos, bool onlyAlive); //returns stack at given tile + const CStack * battleGetStack(SBattleHex pos, bool onlyAlive); //returns stack at given tile const CGHeroInstance * battleGetOwner(const CStack * stack) const; //returns hero that owns given stack; NULL if none si8 battleMinSpellLevel() const; //calculates minimum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned void localInit(); static BattleInfo * setupBattle( int3 tile, int terrain, int terType, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town ); - bool isInTacticRange( SHexField dest ) const; + bool isInTacticRange( SBattleHex dest ) const; int getSurrenderingCost(int player) const; int theOtherPlayer(int player) const; @@ -161,7 +161,7 @@ public: ui32 firstHPleft; //HP of first creature in stack ui8 owner, slot; //owner - player colour (255 for neutrals), slot - position in garrison (may be 255 for neutrals/called creatures) ui8 attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle) - SHexField position; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower + SBattleHex position; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower ui8 counterAttacks; //how many counter attacks can be performed more in this turn (by default set at the beginning of the round to 1) si16 shots; //how many shots left ui8 casts; //how many casts left @@ -207,13 +207,13 @@ public: return ret; } - static bool isMeleeAttackPossible(const CStack * attacker, const CStack * defender, SHexField attackerPos = SHexField::INVALID, SHexField defenderPos = SHexField::INVALID); + static bool isMeleeAttackPossible(const CStack * attacker, const CStack * defender, SBattleHex attackerPos = SBattleHex::INVALID, SBattleHex defenderPos = SBattleHex::INVALID); bool doubleWide() const; - SHexField occupiedHex() const; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1 - std::vector getHexes() const; //up to two occupied hexes, starting from front - bool coversPos(SHexField position) const; //checks also if unit is double-wide - std::vector getSurroundingHexes(SHexField attackerPos = SHexField::INVALID) const; // get six or 8 surrounding hexes depending on creature size + SBattleHex occupiedHex() const; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1 + std::vector getHexes() const; //up to two occupied hexes, starting from front + bool coversPos(SBattleHex position) const; //checks also if unit is double-wide + std::vector getSurroundingHexes(SBattleHex attackerPos = SBattleHex::INVALID) const; // get six or 8 surrounding hexes depending on creature size void prepareAttacked(BattleStackAttacked &bsa) const; //requires bsa.damageAmout filled diff --git a/lib/CGameInterface.cpp b/lib/CGameInterface.cpp index a7e09e895..c40b02553 100644 --- a/lib/CGameInterface.cpp +++ b/lib/CGameInterface.cpp @@ -170,7 +170,7 @@ void CAdventureAI::battleNewStackAppeared(const CStack * stack) battleAI->battleNewStackAppeared(stack); } -void CAdventureAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) +void CAdventureAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) { battleAI->battleStackMoved(stack, dest, distance); } diff --git a/lib/CGameInterface.h b/lib/CGameInterface.h index 118ba2d71..97729ebe5 100644 --- a/lib/CGameInterface.h +++ b/lib/CGameInterface.h @@ -95,7 +95,7 @@ public: virtual void yourTurn() OVERRIDE{}; virtual void heroKilled(const CGHeroInstance*){}; virtual void heroCreated(const CGHeroInstance*) OVERRIDE{}; - virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE{}; + virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE{}; virtual void battleStackAttacking(int ID, int dest) {}; virtual void battleStacksAttacked(const std::vector & bsa) OVERRIDE{}; virtual BattleAction activeStack(const CStack * stack) OVERRIDE; @@ -127,7 +127,7 @@ public: virtual void battleStacksRemoved(const BattleStacksRemoved & bsr); virtual void battleObstaclesRemoved(const std::set & removedObstacles); virtual void battleNewStackAppeared(const CStack * stack); - virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance); + virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance); virtual void battleAttack(const BattleAttack *ba); virtual void battleSpellCast(const BattleSpellCast *sc); virtual void battleEnd(const BattleResult *br); diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 6203eb019..5f750f8ff 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -92,9 +92,9 @@ int CObstacleInfo::getHeight() const return ret; } -std::vector CObstacleInfo::getBlocked(SHexField hex) const +std::vector CObstacleInfo::getBlocked(SBattleHex hex) const { - std::vector ret; + std::vector ret; int cur = hex; //currently browsed hex int curBeg = hex; //beginning of current line for(int h=0; h CObstacleInfo::getBlocked(SHexField hex) const return ret; } -SHexField CObstacleInfo::getMaxBlocked(SHexField hex) const +SBattleHex CObstacleInfo::getMaxBlocked(SBattleHex hex) const { - std::vector blocked = getBlocked(hex); + std::vector blocked = getBlocked(hex); return *std::max_element(blocked.begin(), blocked.end()); } diff --git a/lib/CHeroHandler.h b/lib/CHeroHandler.h index 5cd4a069b..16e99455a 100644 --- a/lib/CHeroHandler.h +++ b/lib/CHeroHandler.h @@ -1,7 +1,7 @@ #pragma once -#include "SHexField.h" +#include "SBattleHex.h" #include "../lib/ConstTransitivePtr.h" #include "GameConstants.h" @@ -96,8 +96,8 @@ struct DLL_LINKAGE CObstacleInfo std::pair posShift; //shift of obstacle's position in the battlefield , eg. if it's <-1, 2> obstacle will be printed one pixel to the left and two to the bottom int getWidth() const; //returns width of obstacle in hexes int getHeight() const; //returns height of obstacle in hexes - std::vector getBlocked(SHexField hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex' - SHexField getMaxBlocked(SHexField hex) const; //returns maximal hex (max number) covered by this obstacle + std::vector getBlocked(SBattleHex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex' + SBattleHex getMaxBlocked(SBattleHex hex) const; //returns maximal hex (max number) covered by this obstacle template void serialize(Handler &h, const int version) { h & ID & defName & blockmap & allowedTerrains & posShift; diff --git a/lib/StopWatch.h b/lib/CStopWatch.h similarity index 91% rename from lib/StopWatch.h rename to lib/CStopWatch.h index 03a3d2300..009d354fb 100644 --- a/lib/StopWatch.h +++ b/lib/CStopWatch.h @@ -20,12 +20,12 @@ * */ -class StopWatch +class CStopWatch { si64 start, last, mem; public: - StopWatch() + CStopWatch() : start(clock()) { last=clock(); diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index b915e3410..e197953ce 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -39,31 +39,31 @@ boost::shared_mutex& CCallbackBase::getGsMutex() return *gs->mx; } -si8 CBattleInfoCallback::battleHasDistancePenalty( const CStack * stack, SHexField destHex ) +si8 CBattleInfoCallback::battleHasDistancePenalty( const CStack * stack, SBattleHex destHex ) { return gs->curB->hasDistancePenalty(stack, destHex); } -si8 CBattleInfoCallback::battleHasWallPenalty( const CStack * stack, SHexField destHex ) +si8 CBattleInfoCallback::battleHasWallPenalty( const CStack * stack, SBattleHex destHex ) { return gs->curB->hasWallPenalty(stack, destHex); } -si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, SHexField destHex, int telportLevel) +si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, SBattleHex destHex, int telportLevel) { return gs->curB->canTeleportTo(stack, destHex, telportLevel); } -std::vector CBattleInfoCallback::battleGetDistances(const CStack * stack, SHexField hex /*= SHexField::INVALID*/, SHexField * predecessors /*= NULL*/) +std::vector CBattleInfoCallback::battleGetDistances(const CStack * stack, SBattleHex hex /*= SBattleHex::INVALID*/, SBattleHex * predecessors /*= NULL*/) { if(!hex.isValid()) hex = stack->position; std::vector ret; bool ac[GameConstants::BFIELD_SIZE] = {0}; - std::set occupyable; + std::set occupyable; gs->curB->getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack); - SHexField pr[GameConstants::BFIELD_SIZE]; + SBattleHex pr[GameConstants::BFIELD_SIZE]; int dist[GameConstants::BFIELD_SIZE]; gs->curB->makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false); @@ -77,18 +77,18 @@ std::vector CBattleInfoCallback::battleGetDistances(const CStack * stack, S if(predecessors) { - memcpy(predecessors, pr, GameConstants::BFIELD_SIZE * sizeof(SHexField)); + memcpy(predecessors, pr, GameConstants::BFIELD_SIZE * sizeof(SBattleHex)); } return ret; } -std::set CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, SHexField destinationTile, SHexField attackerPos /*= SHexField::INVALID*/) +std::set CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos /*= SBattleHex::INVALID*/) { if(!gs->curB) { tlog1 << "battleGetAttackedHexes called when there is no battle!\n"; - std::set set; + std::set set; return set; } @@ -107,7 +107,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell return gs->curB->battleCanCastThisSpell(player, spell, ECastingMode::HERO_CASTING); } -ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell(const CSpell * spell, SHexField destination) +ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell(const CSpell * spell, SBattleHex destination) { if(!gs->curB) { @@ -185,7 +185,7 @@ int CBattleInfoCallback::battleGetBattlefieldType() return gs->curB->battlefieldType; } -int CBattleInfoCallback::battleGetObstaclesAtTile(SHexField tile) //returns bitfield +int CBattleInfoCallback::battleGetObstaclesAtTile(SBattleHex tile) //returns bitfield { //TODO - write return -1; @@ -207,26 +207,26 @@ const CStack* CBattleInfoCallback::battleGetStackByID(int ID, bool onlyAlive) return gs->curB->getStack(ID, onlyAlive); } -const CStack* CBattleInfoCallback::battleGetStackByPos(SHexField pos, bool onlyAlive) +const CStack* CBattleInfoCallback::battleGetStackByPos(SBattleHex pos, bool onlyAlive) { //boost::shared_lock lock(*gs->mx); return gs->curB->battleGetStack(pos, onlyAlive); } -SHexField CBattleInfoCallback::battleGetPos(int stack) +SBattleHex CBattleInfoCallback::battleGetPos(int stack) { //boost::shared_lock lock(*gs->mx); if(!gs->curB) { tlog2<<"battleGetPos called when there is no battle!"<curB->stacks.size(); ++g) { if(gs->curB->stacks[g]->ID == stack) return gs->curB->stacks[g]->position; } - return SHexField::INVALID; + return SBattleHex::INVALID; } TStacks CBattleInfoCallback::battleGetStacks(EStackOwnership whose /*= MINE_AND_ENEMY*/, bool onlyAlive /*= true*/) @@ -268,24 +268,24 @@ void CBattleInfoCallback::battleGetStackCountOutsideHexes(bool *ac) for (int i = 0; i < GameConstants::BFIELD_SIZE; ++i) ac[i] = false; } else { - std::set ignored; + std::set ignored; gs->curB->getAccessibilityMap(ac, false /*ignored*/, false, false, ignored, false /*ignored*/, NULL); } } -std::vector CBattleInfoCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable) +std::vector CBattleInfoCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable) { //boost::shared_lock lock(*gs->mx); if(!gs->curB) { tlog2<<"battleGetAvailableHexes called when there is no battle!"<(); + return std::vector(); } return gs->curB->getAccessibility(stack, addOccupiable, attackable); //return gs->battleGetRange(ID); } -bool CBattleInfoCallback::battleCanShoot(const CStack * stack, SHexField dest) +bool CBattleInfoCallback::battleCanShoot(const CStack * stack, SBattleHex dest) { //boost::shared_lock lock(*gs->mx); @@ -324,7 +324,7 @@ ui8 CBattleInfoCallback::battleGetWallState(int partOfWall) return gs->curB->si.wallState[partOfWall]; } -int CBattleInfoCallback::battleGetWallUnderHex(SHexField hex) +int CBattleInfoCallback::battleGetWallUnderHex(SBattleHex hex) { if(!gs->curB || gs->curB->siege == 0) { diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index c19ccbe45..bde5a4ec3 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -1,7 +1,7 @@ #pragma once -#include "SHexField.h" +#include "SBattleHex.h" #include "../client/FunctionList.h" #include "CObstacleInstance.h" #include "ResourceSet.h" @@ -94,33 +94,33 @@ public: //battle int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship - int battleGetObstaclesAtTile(SHexField tile); //returns bitfield + int battleGetObstaclesAtTile(SBattleHex tile); //returns bitfield std::vector battleGetAllObstacles(); //returns all obstacles on the battlefield const CStack * battleGetStackByID(int ID, bool onlyAlive = true); //returns stack info by given ID - const CStack * battleGetStackByPos(SHexField pos, bool onlyAlive = true); //returns stack info by given pos - SHexField battleGetPos(int stack); //returns position (tile ID) of stack + const CStack * battleGetStackByPos(SBattleHex pos, bool onlyAlive = true); //returns stack info by given pos + SBattleHex battleGetPos(int stack); //returns position (tile ID) of stack TStacks battleGetStacks(EStackOwnership whose = MINE_AND_ENEMY, bool onlyAlive = true); //returns stacks on battlefield void getStackQueue( std::vector &out, int howMany ); //returns vector of stack in order of their move sequence void battleGetStackCountOutsideHexes(bool *ac); // returns hexes which when in front of a stack cause us to move the amount box back - std::vector battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL); //returns numbers of hexes reachable by creature with id ID - std::vector battleGetDistances(const CStack * stack, SHexField hex = SHexField::INVALID, SHexField * predecessors = NULL); //returns vector of distances to [dest hex number] - std::set battleGetAttackedHexes(const CStack* attacker, SHexField destinationTile, SHexField attackerPos = SHexField::INVALID); - bool battleCanShoot(const CStack * stack, SHexField dest); //returns true if unit with id ID can shoot to dest + std::vector battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL); //returns numbers of hexes reachable by creature with id ID + std::vector battleGetDistances(const CStack * stack, SBattleHex hex = SBattleHex::INVALID, SBattleHex * predecessors = NULL); //returns vector of distances to [dest hex number] + std::set battleGetAttackedHexes(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos = SBattleHex::INVALID); + bool battleCanShoot(const CStack * stack, SBattleHex dest); //returns true if unit with id ID can shoot to dest bool battleCanCastSpell(); //returns true, if caller can cast a spell ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell); //determines if given spell can be casted (and returns problem description) - ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell, SHexField destination); //determines if creature can cast a spell here + ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell, SBattleHex destination); //determines if creature can cast a spell here ui32 battleGetRandomStackSpell(const CStack * stack, ERandomSpell mode); bool battleCanFlee(); //returns true if caller can flee from the battle int battleGetSurrenderCost(); //returns cost of surrendering battle, -1 if surrendering is not possible const CGTownInstance * battleGetDefendedTown(); //returns defended town if current battle is a siege, NULL instead ui8 battleGetWallState(int partOfWall); //for determining state of a part of the wall; format: parameter [0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; returned value: 1 - intact, 2 - damaged, 3 - destroyed; 0 - no battle - int battleGetWallUnderHex(SHexField hex); //returns part of destructible wall / gate / keep under given hex or -1 if not found + int battleGetWallUnderHex(SBattleHex hex); //returns part of destructible wall / gate / keep under given hex or -1 if not found std::pair battleEstimateDamage(const CStack * attacker, const CStack * defender, std::pair * retaliationDmg = NULL); //estimates damage dealt by attacker to defender; it may be not precise especially when stack has randomly working bonuses; returns pair ui8 battleGetSiegeLevel(); //returns 0 when there is no siege, 1 if fort, 2 is citadel, 3 is castle const CGHeroInstance * battleGetFightingHero(ui8 side) const; //returns hero corresponding to given side (0 - attacker, 1 - defender) - si8 battleHasDistancePenalty(const CStack * stack, SHexField destHex); //checks if given stack has distance penalty - si8 battleHasWallPenalty(const CStack * stack, SHexField destHex); //checks if given stack has wall penalty - si8 battleCanTeleportTo(const CStack * stack, SHexField destHex, int telportLevel); //checks if teleportation of given stack to given position can take place + si8 battleHasDistancePenalty(const CStack * stack, SBattleHex destHex); //checks if given stack has distance penalty + si8 battleHasWallPenalty(const CStack * stack, SBattleHex destHex); //checks if given stack has wall penalty + si8 battleCanTeleportTo(const CStack * stack, SBattleHex destHex, int telportLevel); //checks if teleportation of given stack to given position can take place si8 battleGetTacticDist(); //returns tactic distance for calling player or 0 if player is not in tactic phase ui8 battleGetMySide(); //return side of player in battle (attacker/defender) diff --git a/lib/IGameEventsReceiver.h b/lib/IGameEventsReceiver.h index 964645fe5..8db5226cf 100644 --- a/lib/IGameEventsReceiver.h +++ b/lib/IGameEventsReceiver.h @@ -1,7 +1,7 @@ #pragma once -#include "SHexField.h" +#include "SBattleHex.h" #include "int3.h" class CGTownInstance; @@ -45,7 +45,7 @@ public: virtual void battleEnd(const BattleResult *br){}; virtual void battleNewRoundFirst(int round){}; //called at the beginning of each turn before changes are applied; virtual void battleNewRound(int round){}; //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance){}; + virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance){}; virtual void battleSpellCast(const BattleSpellCast *sc){}; virtual void battleStacksEffectsSet(const SetStackEffect & sse){};//called when a specific effect is set to stacks virtual void battleTriggerEffect(const BattleTriggerEffect & bte){}; //called for various one-shot effects diff --git a/lib/Makefile.am b/lib/Makefile.am index 531f0a491..1c6fdf49e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -67,8 +67,8 @@ libvcmi_la_SOURCES = \ ResourceSet.cpp \ ResourceSet.h \ RegisterTypes.h \ - SHexField.cpp \ - SHexField.h \ + SBattleHex.cpp \ + SBattleHex.h \ VCMIDirs.h \ VCMI_Lib.cpp \ VCMI_Lib.h \ diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 8dc4c2fbe..2c18f2b02 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -1214,7 +1214,7 @@ struct BattleResult : public CPackForClient//3003 struct BattleStackMoved : public CPackForClient//3004 { ui32 stack; - std::vector tilesToMove; + std::vector tilesToMove; ui8 distance, teleporting; BattleStackMoved(){type = 3004;}; void applyFirstCl(CClient *cl); @@ -1382,7 +1382,7 @@ struct BattleSpellCast : public CPackForClient//3009 ui8 skill; //caster's skill level ui8 spellCost; ui8 manaGained; //mana channeling ability - SHexField tile; //destination tile (may not be set in some global/mass spells + SBattleHex tile; //destination tile (may not be set in some global/mass spells std::vector resisted; //ids of creatures that resisted this spell std::set affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure) TCreature attackerType;//id of caster to generate console message; -1 if not set (eg. spell casted by artifact) diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 5b045693c..4d628e6cb 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -1150,7 +1150,7 @@ DLL_LINKAGE void StacksHealedOrResurrected::applyGs( CGameState *gs ) CStack * changedStack = gs->curB->getStack(healedStacks[g].stackID, false); //checking if we resurrect a stack that is under a living stack - std::vector access = gs->curB->getAccessibility(changedStack, true); + std::vector access = gs->curB->getAccessibility(changedStack, true); bool acc[GameConstants::BFIELD_SIZE]; for(int h=0; h SHexField::neighbouringTiles() const +std::vector SBattleHex::neighbouringTiles() const { - std::vector ret; + std::vector ret; const int WN = GameConstants::BFIELD_WIDTH; checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), ret); checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), ret); @@ -53,7 +53,7 @@ std::vector SHexField::neighbouringTiles() const return ret; } -signed char SHexField::mutualPosition(SHexField hex1, SHexField hex2) +signed char SBattleHex::mutualPosition(SBattleHex hex1, SBattleHex hex2) { if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left return 0; @@ -70,16 +70,16 @@ signed char SHexField::mutualPosition(SHexField hex1, SHexField hex2) return -1; } -char SHexField::getDistance(SHexField hex1, SHexField hex2) +char SBattleHex::getDistance(SBattleHex hex1, SBattleHex hex2) { int xDst = std::abs(hex1 % GameConstants::BFIELD_WIDTH - hex2 % GameConstants::BFIELD_WIDTH), yDst = std::abs(hex1 / GameConstants::BFIELD_WIDTH - hex2 / GameConstants::BFIELD_WIDTH); return std::max(xDst, yDst) + std::min(xDst, yDst) - (yDst + 1)/2; } -void SHexField::checkAndPush(int tile, std::vector & ret) +void SBattleHex::checkAndPush(int tile, std::vector & ret) { if( tile>=0 && tile - SHexField(inttype x, inttype y) + SBattleHex(inttype x, inttype y) { setXY(x, y); } template - SHexField(std::pair xy) + SBattleHex(std::pair xy) { setXY(xy); } @@ -89,21 +89,21 @@ struct DLL_LINKAGE SHexField //moving to direction void operator+=(EDir dir); - //generates new SHexField moved by given dir - SHexField operator+(EDir dir) const; + //generates new SBattleHex moved by given dir + SBattleHex operator+(EDir dir) const; - std::vector neighbouringTiles() const; + std::vector neighbouringTiles() const; //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left) - static signed char mutualPosition(SHexField hex1, SHexField hex2); + static signed char mutualPosition(SBattleHex hex1, SBattleHex hex2); //returns distance between given hexes - static char getDistance(SHexField hex1, SHexField hex2); + static char getDistance(SBattleHex hex1, SBattleHex hex2); template void serialize(Handler &h, const int version) { h & hex; } - static void checkAndPush(int tile, std::vector & ret); + static void checkAndPush(int tile, std::vector & ret); }; \ No newline at end of file diff --git a/lib/StdInc.h b/lib/StdInc.h index 18659d5ee..76e828312 100644 --- a/lib/StdInc.h +++ b/lib/StdInc.h @@ -1,325 +1,7 @@ #pragma once -// Standard include file -// Should be treated as a precompiled header file in the compiler settings -// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio -// This file shouldn't be changed, except if there is a important header file which is missing. +#include "../Global.h" -/* - * StdInc.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ +// This header should be treated as a pre compiled header file(PCH) in the compiler building settings. -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#include -#ifdef _WIN32 -#include -#else -#include "../tchar_amigaos4.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -//filesystem version 3 causes problems (and it's default as of boost 1.46) -#define BOOST_FILESYSTEM_VERSION 2 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ANDROID -#include -#endif - -// Integral data types -typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) -typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) -typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) -typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) -typedef boost::int64_t si64; //signed int 64 bits (8 bytes) -typedef boost::int32_t si32; //signed int 32 bits (4 bytes) -typedef boost::int16_t si16; //signed int 16 bits (2 bytes) -typedef boost::int8_t si8; //signed int 8 bits (1 byte) - -// Import + Export macro declarations -#ifdef _WIN32 -#define DLL_EXPORT __declspec(dllexport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_EXPORT __attribute__ ((visibility("default"))) -#else -#define DLL_EXPORT -#endif -#endif - -#ifdef _WIN32 -#define DLL_IMPORT __declspec(dllimport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_IMPORT __attribute__ ((visibility("default"))) -#else -#define DLL_IMPORT -#endif -#endif - -#ifdef VCMI_DLL -#define DLL_LINKAGE DLL_EXPORT -#else -#define DLL_LINKAGE DLL_IMPORT -#endif - - -//a normal std::map with a const operator[] for sanity -template -class bmap : public std::map -{ -public: - const ValT & operator[](KeyT key) const - { - return find(key)->second; - } - ValT & operator[](KeyT key) - { - return static_cast &>(*this)[key]; - } - template void serialize(Handler &h, const int version) - { - h & static_cast &>(*this); - } -}; - -namespace vstd -{ - //returns true if container c contains item i - template - bool contains(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i) != c.end(); - } - - //returns true if map c contains item i - template - bool contains(const std::map & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if bmap c contains item i - template - bool contains(const bmap & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if unordered set c contains item i - template - bool contains(const boost::unordered_set & c, const Item &i) - { - return c.find(i)!=c.end(); - } - - //returns position of first element in vector c equal to s, if there is no such element, -1 is returned - template - int find_pos(const std::vector & c, const T2 &s) - { - for(size_t i=0; i < c.size(); ++i) - if(c[i] == s) - return i; - return -1; - } - - //Func(T1,T2) must say if these elements matches - template - int find_pos(const std::vector & c, const T2 &s, const Func &f) - { - for(size_t i=0; i < c.size(); ++i) - if(f(c[i],s)) - return i; - return -1; - } - - //returns iterator to the given element if present in container, end() if not - template - typename Container::iterator find(Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //returns const iterator to the given element if present in container, end() if not - template - typename Container::const_iterator find(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //removes element i from container c, returns false if c does not contain i - template - typename Container::size_type operator-=(Container &c, const Item &i) - { - typename Container::iterator itr = find(c,i); - if(itr == c.end()) - return false; - c.erase(itr); - return true; - } - - //assigns greater of (a, b) to a and returns maximum of (a, b) - template - t1 &amax(t1 &a, const t2 &b) - { - if(a >= b) - return a; - else - { - a = b; - return a; - } - } - - //assigns smaller of (a, b) to a and returns minimum of (a, b) - template - t1 &amin(t1 &a, const t2 &b) - { - if(a <= b) - return a; - else - { - a = b; - return a; - } - } - - //makes a to fit the range - template - t1 &abetween(t1 &a, const t2 &b, const t3 &c) - { - amax(a,b); - amin(a,c); - return a; - } - - //checks if a is between b and c - template - bool isbetween(const t1 &a, const t2 &b, const t3 &c) - { - return a > b && a < c; - } - - //checks if a is within b and c - template - bool iswithin(const t1 &a, const t2 &b, const t3 &c) - { - return a >= b && a <= c; - } - - template - struct assigner - { - public: - t1 &op1; - t2 op2; - assigner(t1 &a1, const t2 & a2) - :op1(a1), op2(a2) - {} - void operator()() - { - op1 = op2; - } - }; - - // Assigns value a2 to a1. The point of time of the real operation can be controlled - // with the () operator. - template - assigner assigno(t1 &a1, const t2 &a2) - { - return assigner(a1,a2); - } - - //deleted pointer and sets it to NULL - template - void clear_pointer(T* &ptr) - { - delete ptr; - ptr = NULL; - } -} -using vstd::operator-=; - -// can be used for counting arrays -template char (&_ArrayCountObj(const T (&)[N]))[N]; -#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) - -//for explicit overrides -#ifdef _MSC_VER -#define OVERRIDE override -#else -#define OVERRIDE //is there any working counterpart? -#endif - -//XXX pls dont - 'debug macros' are usually more trouble than it's worth -#define HANDLE_EXCEPTION \ - catch (const std::exception& e) { \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::exception * e) \ -{ \ - tlog1 << e->what()<< std::endl; \ - throw; \ -} \ - catch (const std::string& e) { \ - tlog1 << e << std::endl; \ - throw; \ -} - -#define HANDLE_EXCEPTIONC(COMMAND) \ - catch (const std::exception& e) { \ - COMMAND; \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::string &e) \ -{ \ - COMMAND; \ - tlog1 << e << std::endl; \ - throw; \ -} - - -#include "../lib/CLogger.h" +// Here you can add specific libraries and macros which are specific to this project. \ No newline at end of file diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index 5add0d34f..f83924410 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -13,7 +13,7 @@ #include "CSpellHandler.h" #include "CGeneralTextHandler.h" #include "IGameEventsReceiver.h" -#include "StopWatch.h" +#include "CStopWatch.h" /* * VCMI_Lib.cpp, part of VCMI engine @@ -161,7 +161,7 @@ DLL_LINKAGE void loadToIt(si32 &dest, const std::string &src, int &iter, int mod void LibClasses::init() { - StopWatch pomtime; + CStopWatch pomtime; generaltexth = new CGeneralTextHandler; generaltexth->load(); @@ -234,7 +234,7 @@ void LibClasses::makeNull() LibClasses::LibClasses() { //load .lod archives - StopWatch pomtime; + CStopWatch pomtime; spriteh = new CLodHandler(); spriteh->init(GameConstants::DATA_DIR + "/Data/H3sprite.lod", GameConstants::DATA_DIR + "/Sprites"); bitmaph = new CLodHandler; diff --git a/lib/VCMI_lib.cbp b/lib/VCMI_lib.cbp deleted file mode 100644 index f59a312f5..000000000 --- a/lib/VCMI_lib.cbp +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - diff --git a/lib/VCMI_lib.vcxproj b/lib/VCMI_lib.vcxproj index e7c3cd122..c820c0580 100644 --- a/lib/VCMI_lib.vcxproj +++ b/lib/VCMI_lib.vcxproj @@ -241,7 +241,7 @@ - + VCMI_DLL;%(PreprocessorDefinitions) Create @@ -250,6 +250,7 @@ + @@ -276,6 +277,7 @@ + @@ -289,10 +291,9 @@ - + - diff --git a/lib/map.cpp b/lib/map.cpp index 92f65b962..bfc0fd6e0 100644 --- a/lib/map.cpp +++ b/lib/map.cpp @@ -13,7 +13,7 @@ #include "../lib/JsonNode.h" #include "vcmi_endian.h" #include "GameConstants.h" -#include "StopWatch.h" +#include "CStopWatch.h" /* * map.cpp, part of VCMI engine @@ -406,7 +406,7 @@ void Mapa::initFromBytes(const ui8 * bufor, size_t size) int i=0; initFromMemory(bufor,i); - StopWatch th; + CStopWatch th; th.getDiff(); readHeader(bufor, i); tlog0<<"\tReading header: "< Running $@... Configuration=$(CONF)" - ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf - - -# clean -.clean-impl: .clean-pre .validate-impl .depcheck-impl - @#echo "=> Running $@... Configuration=$(CONF)" - ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf - - -# clobber -.clobber-impl: .clobber-pre .depcheck-impl - @#echo "=> Running $@..." - for CONF in ${ALLCONFS}; \ - do \ - ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf; \ - done - -# all -.all-impl: .all-pre .depcheck-impl - @#echo "=> Running $@..." - for CONF in ${ALLCONFS}; \ - do \ - ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf; \ - done - -# dependency checking support -.depcheck-impl: - @echo "# This code depends on make tool being used" >.dep.inc - @if [ -n "${MAKE_VERSION}" ]; then \ - echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \ - echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ - echo "include \$${DEPFILES}" >>.dep.inc; \ - echo "endif" >>.dep.inc; \ - else \ - echo ".KEEP_STATE:" >>.dep.inc; \ - echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ - fi - -# configuration validation -.validate-impl: - @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ - then \ - echo ""; \ - echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \ - echo "See 'make help' for details."; \ - echo "Current directory: " `pwd`; \ - echo ""; \ - fi - @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ - then \ - exit 1; \ - fi - - -# help -.help-impl: .help-pre - @echo "This makefile supports the following configurations:" - @echo " ${ALLCONFS}" - @echo "" - @echo "and the following targets:" - @echo " build (default target)" - @echo " clean" - @echo " clobber" - @echo " all" - @echo " help" - @echo "" - @echo "Makefile Usage:" - @echo " make [CONF=] [SUB=no] build" - @echo " make [CONF=] [SUB=no] clean" - @echo " make [SUB=no] clobber" - @echo " make [SUB=no] all" - @echo " make help" - @echo "" - @echo "Target 'build' will build a specific configuration and, unless 'SUB=no'," - @echo " also build subprojects." - @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no'," - @echo " also clean subprojects." - @echo "Target 'clobber' will remove all built files from all configurations and," - @echo " unless 'SUB=no', also from subprojects." - @echo "Target 'all' will will build all configurations and, unless 'SUB=no'," - @echo " also build subprojects." - @echo "Target 'help' prints this message." - @echo "" - diff --git a/lib/vcmi_lib/nbproject/Package-Debug.bash b/lib/vcmi_lib/nbproject/Package-Debug.bash deleted file mode 100644 index 4e56f25ce..000000000 --- a/lib/vcmi_lib/nbproject/Package-Debug.bash +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash -x - -# -# Generated - do not edit! -# - -# Macros -TOP=`pwd` -PLATFORM=GNU-Linux-x86 -TMPDIR=build/Debug/${PLATFORM}/tmp-packaging -TMPDIRNAME=tmp-packaging -OUTPUT_PATH=dist/Debug/${PLATFORM}/libvcmi_lib.so -OUTPUT_BASENAME=libvcmi_lib.so -PACKAGE_TOP_DIR=libvcmilib.so/ - -# Functions -function checkReturnCode -{ - rc=$? - if [ $rc != 0 ] - then - exit $rc - fi -} -function makeDirectory -# $1 directory path -# $2 permission (optional) -{ - mkdir -p "$1" - checkReturnCode - if [ "$2" != "" ] - then - chmod $2 "$1" - checkReturnCode - fi -} -function copyFileToTmpDir -# $1 from-file path -# $2 to-file path -# $3 permission -{ - cp "$1" "$2" - checkReturnCode - if [ "$3" != "" ] - then - chmod $3 "$2" - checkReturnCode - fi -} - -# Setup -cd "${TOP}" -mkdir -p dist/Debug/${PLATFORM}/package -rm -rf ${TMPDIR} -mkdir -p ${TMPDIR} - -# Copy files and create directories and links -cd "${TOP}" -makeDirectory ${TMPDIR}/libvcmilib.so/lib -copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644 - - -# Generate tar file -cd "${TOP}" -rm -f dist/Debug/${PLATFORM}/package/libvcmilib.so.tar -cd ${TMPDIR} -tar -vcf ../../../../dist/Debug/${PLATFORM}/package/libvcmilib.so.tar * -checkReturnCode - -# Cleanup -cd "${TOP}" -rm -rf ${TMPDIR} diff --git a/lib/vcmi_lib/nbproject/Package-Release.bash b/lib/vcmi_lib/nbproject/Package-Release.bash deleted file mode 100644 index ca8da21d4..000000000 --- a/lib/vcmi_lib/nbproject/Package-Release.bash +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash -x - -# -# Generated - do not edit! -# - -# Macros -TOP=`pwd` -PLATFORM=GNU-Linux-x86 -TMPDIR=build/Release/${PLATFORM}/tmp-packaging -TMPDIRNAME=tmp-packaging -OUTPUT_PATH=dist/Release/${PLATFORM}/libvcmi_lib.so -OUTPUT_BASENAME=libvcmi_lib.so -PACKAGE_TOP_DIR=libvcmilib.so/ - -# Functions -function checkReturnCode -{ - rc=$? - if [ $rc != 0 ] - then - exit $rc - fi -} -function makeDirectory -# $1 directory path -# $2 permission (optional) -{ - mkdir -p "$1" - checkReturnCode - if [ "$2" != "" ] - then - chmod $2 "$1" - checkReturnCode - fi -} -function copyFileToTmpDir -# $1 from-file path -# $2 to-file path -# $3 permission -{ - cp "$1" "$2" - checkReturnCode - if [ "$3" != "" ] - then - chmod $3 "$2" - checkReturnCode - fi -} - -# Setup -cd "${TOP}" -mkdir -p dist/Release/${PLATFORM}/package -rm -rf ${TMPDIR} -mkdir -p ${TMPDIR} - -# Copy files and create directories and links -cd "${TOP}" -makeDirectory ${TMPDIR}/libvcmilib.so/lib -copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644 - - -# Generate tar file -cd "${TOP}" -rm -f dist/Release/${PLATFORM}/package/libvcmilib.so.tar -cd ${TMPDIR} -tar -vcf ../../../../dist/Release/${PLATFORM}/package/libvcmilib.so.tar * -checkReturnCode - -# Cleanup -cd "${TOP}" -rm -rf ${TMPDIR} diff --git a/lib/vcmi_lib/nbproject/configurations.xml b/lib/vcmi_lib/nbproject/configurations.xml deleted file mode 100644 index ab02cda1a..000000000 --- a/lib/vcmi_lib/nbproject/configurations.xml +++ /dev/null @@ -1,325 +0,0 @@ - - - - - ../BattleAction.h - ../../hch/CArtHandler.h - ../../hch/CBuildingHandler.h - ../../CConsoleHandler.h - ../../hch/CCreatureHandler.h - ../../hch/CDefObjInfoHandler.h - ../../CGameInfo.h - ../../CGameState.h - ../../hch/CGeneralTextHandler.h - ../../hch/CHeroHandler.h - ../../hch/CLodHandler.h - ../../hch/CObjectHandler.h - ../CondSh.h - ../Connection.h - ../../hch/CSpellHandler.h - ../../hch/CTownHandler.h - ../Interprocess.h - ../../map.h - ../NetPacks.h - ../VCMI_Lib.h - - - - - ../../hch/CArtHandler.cpp - ../../hch/CBuildingHandler.cpp - ../../CConsoleHandler.cpp - ../../hch/CCreatureHandler.cpp - ../../hch/CDefObjInfoHandler.cpp - ../../CGameInfo.cpp - ../../CGameState.cpp - ../../hch/CGeneralTextHandler.cpp - ../../hch/CHeroHandler.cpp - ../../hch/CLodHandler.cpp - ../../hch/CObjectHandler.cpp - ../Connection.cpp - ../../hch/CSpellHandler.cpp - ../../hch/CTownHandler.cpp - ../../map.cpp - ../VCMI_Lib.cpp - - - Makefile-nb - - - Makefile-nb - - - - localhost - GNU|GNU - 2 - - - - - ../../hch - ../.. - ../../../../boost/include/boost-1_37 - /usr/include/SDL - ../../../../boost/include/boost-1_37/boost - - - - dist/Debug/${PLATFORM}/libvcmi_lib.so - - ../../../../boost/lib - - - - - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 3 - - - 3 - - - 1 - - - 3 - - - 3 - - - 3 - - - 1 - - - 3 - - - - - localhost - GNU|GNU - 2 - - - - 5 - - - 5 - - - 5 - - - - - - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - 3 - - - 3 - - - 1 - - - 3 - - - 3 - - - 3 - - - 1 - - - 3 - - - - diff --git a/lib/vcmi_lib/nbproject/project.properties b/lib/vcmi_lib/nbproject/project.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/vcmi_lib/nbproject/project.xml b/lib/vcmi_lib/nbproject/project.xml deleted file mode 100644 index 2b0f72060..000000000 --- a/lib/vcmi_lib/nbproject/project.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - org.netbeans.modules.cnd.makeproject - - - vcmi_lib - 0 - - cpp - h - UTF-8 - - - - diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 45e69cbbb..1b0c53434 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -682,7 +682,7 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) tlog1 << "Ended handling connection\n"; } -int CGameHandler::moveStack(int stack, SHexField dest) +int CGameHandler::moveStack(int stack, SBattleHex dest) { int ret = 0; @@ -699,7 +699,7 @@ int CGameHandler::moveStack(int stack, SHexField dest) //initing necessary tables bool accessibility[GameConstants::BFIELD_SIZE]; - std::vector accessible = gs->curB->getAccessibility(curStack, false); + std::vector accessible = gs->curB->getAccessibility(curStack, false); for(int b=0; battackerOwned) { if(accessibility[dest+1]) - dest += SHexField::RIGHT; + dest += SBattleHex::RIGHT; } else { if(accessibility[dest-1]) - dest += SHexField::LEFT; + dest += SBattleHex::LEFT; } } @@ -728,7 +728,7 @@ int CGameHandler::moveStack(int stack, SHexField dest) return 0; bool accessibilityWithOccupyable[GameConstants::BFIELD_SIZE]; - std::vector accOc = gs->curB->getAccessibility(curStack, true); + std::vector accOc = gs->curB->getAccessibility(curStack, true); for(int b=0; b curStack->creature->speed && !(stackAtEnd && dists[dest] == curStack->creature->speed+1)) //we can attack a stack if we can go to adjacent hex // return false; - std::pair< std::vector, int > path = gs->curB->getPath(curStack->position, dest, accessibilityWithOccupyable, curStack->hasBonusOfType(Bonus::FLYING), curStack->doubleWide(), curStack->attackerOwned); + std::pair< std::vector, int > path = gs->curB->getPath(curStack->position, dest, accessibilityWithOccupyable, curStack->hasBonusOfType(Bonus::FLYING), curStack->doubleWide(), curStack->attackerOwned); ret = path.second; @@ -754,7 +754,7 @@ int CGameHandler::moveStack(int stack, SHexField dest) //inform clients about move BattleStackMoved sm; sm.stack = curStack->ID; - std::vector tiles; + std::vector tiles; tiles.push_back(path.first[0]); sm.tilesToMove = tiles; sm.distance = path.second; @@ -765,7 +765,7 @@ int CGameHandler::moveStack(int stack, SHexField dest) else //for non-flying creatures { // send one package with the creature path information - std::vector tiles; + std::vector tiles; int tilesToMove = std::max((int)(path.first.size() - creSpeed), 0); for(int v=path.first.size()-1; v>=tilesToMove; --v) { @@ -3330,7 +3330,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) CStack * stack = gs->curB->getStack(ba.stackNumber); int spellID = ba.additionalInfo; - SHexField destination(ba.destinationTile); + SBattleHex destination(ba.destinationTile); int spellLvl = 0; Bonus * bonus = stack->getBonus(Selector::typeSubtype(Bonus::SPELLCASTER, spellID)); @@ -3486,7 +3486,7 @@ void CGameHandler::playerMessage( ui8 player, const std::string &message ) } } -void CGameHandler::handleSpellCasting( int spellID, int spellLvl, SHexField destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack) +void CGameHandler::handleSpellCasting( int spellID, int spellLvl, SBattleHex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack) { const CSpell *spell = VLC->spellh->spells[spellID]; @@ -3737,7 +3737,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, SHexField dest BattleStackMoved bsm; bsm.distance = -1; bsm.stack = gs->curB->activeStack; - std::vector tiles; + std::vector tiles; tiles.push_back(destination); bsm.tilesToMove = tiles; bsm.teleporting = true; @@ -3826,7 +3826,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, SHexField dest ObstaclesRemoved obr; for(int g=0; gcurB->obstacles.size(); ++g) { - std::vector blockedHexes = VLC->heroh->obstacles[gs->curB->obstacles[g].ID].getBlocked(gs->curB->obstacles[g].pos); + std::vector blockedHexes = VLC->heroh->obstacles[gs->curB->obstacles[g].ID].getBlocked(gs->curB->obstacles[g].pos); if(vstd::contains(blockedHexes, destination)) //this obstacle covers given hex { diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 724f910da..1a635dd5e 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -101,7 +101,7 @@ public: bool isAllowedExchange(int id1, int id2); bool isAllowedArrangePack(const ArrangeStacks *pack); void giveSpells(const CGTownInstance *t, const CGHeroInstance *h); - int moveStack(int stack, SHexField dest); //returned value - travelled distance + int moveStack(int stack, SBattleHex dest); //returned value - travelled distance void startBattle(const CArmedInstance *armies[2], int3 tile, const CGHeroInstance *heroes[2], bool creatureBank, boost::function cb, const CGTownInstance *town = NULL); //use hero=NULL for no hero void runBattle(); void checkLossVictory(ui8 player); @@ -192,7 +192,7 @@ public: void playerMessage( ui8 player, const std::string &message); bool makeBattleAction(BattleAction &ba); - void handleSpellCasting(int spellID, int spellLvl, SHexField destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack); + void handleSpellCasting(int spellID, int spellLvl, SBattleHex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack); bool makeCustomAction(BattleAction &ba); void stackTurnTrigger(const CStack * stack); bool queryReply( ui32 qid, ui32 answer, ui8 player ); diff --git a/server/StdInc.h b/server/StdInc.h index 18659d5ee..76e828312 100644 --- a/server/StdInc.h +++ b/server/StdInc.h @@ -1,325 +1,7 @@ #pragma once -// Standard include file -// Should be treated as a precompiled header file in the compiler settings -// We generate a .PCH file for every project due to simplicity and some annoying bugs in VisualStudio -// This file shouldn't be changed, except if there is a important header file which is missing. +#include "../Global.h" -/* - * StdInc.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ +// This header should be treated as a pre compiled header file(PCH) in the compiler building settings. -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#include -#ifdef _WIN32 -#include -#else -#include "../tchar_amigaos4.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -//filesystem version 3 causes problems (and it's default as of boost 1.46) -#define BOOST_FILESYSTEM_VERSION 2 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ANDROID -#include -#endif - -// Integral data types -typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) -typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) -typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) -typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) -typedef boost::int64_t si64; //signed int 64 bits (8 bytes) -typedef boost::int32_t si32; //signed int 32 bits (4 bytes) -typedef boost::int16_t si16; //signed int 16 bits (2 bytes) -typedef boost::int8_t si8; //signed int 8 bits (1 byte) - -// Import + Export macro declarations -#ifdef _WIN32 -#define DLL_EXPORT __declspec(dllexport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_EXPORT __attribute__ ((visibility("default"))) -#else -#define DLL_EXPORT -#endif -#endif - -#ifdef _WIN32 -#define DLL_IMPORT __declspec(dllimport) -#else -#if defined(__GNUC__) && __GNUC__ >= 4 -#define DLL_IMPORT __attribute__ ((visibility("default"))) -#else -#define DLL_IMPORT -#endif -#endif - -#ifdef VCMI_DLL -#define DLL_LINKAGE DLL_EXPORT -#else -#define DLL_LINKAGE DLL_IMPORT -#endif - - -//a normal std::map with a const operator[] for sanity -template -class bmap : public std::map -{ -public: - const ValT & operator[](KeyT key) const - { - return find(key)->second; - } - ValT & operator[](KeyT key) - { - return static_cast &>(*this)[key]; - } - template void serialize(Handler &h, const int version) - { - h & static_cast &>(*this); - } -}; - -namespace vstd -{ - //returns true if container c contains item i - template - bool contains(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i) != c.end(); - } - - //returns true if map c contains item i - template - bool contains(const std::map & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if bmap c contains item i - template - bool contains(const bmap & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - - //returns true if unordered set c contains item i - template - bool contains(const boost::unordered_set & c, const Item &i) - { - return c.find(i)!=c.end(); - } - - //returns position of first element in vector c equal to s, if there is no such element, -1 is returned - template - int find_pos(const std::vector & c, const T2 &s) - { - for(size_t i=0; i < c.size(); ++i) - if(c[i] == s) - return i; - return -1; - } - - //Func(T1,T2) must say if these elements matches - template - int find_pos(const std::vector & c, const T2 &s, const Func &f) - { - for(size_t i=0; i < c.size(); ++i) - if(f(c[i],s)) - return i; - return -1; - } - - //returns iterator to the given element if present in container, end() if not - template - typename Container::iterator find(Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //returns const iterator to the given element if present in container, end() if not - template - typename Container::const_iterator find(const Container & c, const Item &i) - { - return std::find(c.begin(),c.end(),i); - } - - //removes element i from container c, returns false if c does not contain i - template - typename Container::size_type operator-=(Container &c, const Item &i) - { - typename Container::iterator itr = find(c,i); - if(itr == c.end()) - return false; - c.erase(itr); - return true; - } - - //assigns greater of (a, b) to a and returns maximum of (a, b) - template - t1 &amax(t1 &a, const t2 &b) - { - if(a >= b) - return a; - else - { - a = b; - return a; - } - } - - //assigns smaller of (a, b) to a and returns minimum of (a, b) - template - t1 &amin(t1 &a, const t2 &b) - { - if(a <= b) - return a; - else - { - a = b; - return a; - } - } - - //makes a to fit the range - template - t1 &abetween(t1 &a, const t2 &b, const t3 &c) - { - amax(a,b); - amin(a,c); - return a; - } - - //checks if a is between b and c - template - bool isbetween(const t1 &a, const t2 &b, const t3 &c) - { - return a > b && a < c; - } - - //checks if a is within b and c - template - bool iswithin(const t1 &a, const t2 &b, const t3 &c) - { - return a >= b && a <= c; - } - - template - struct assigner - { - public: - t1 &op1; - t2 op2; - assigner(t1 &a1, const t2 & a2) - :op1(a1), op2(a2) - {} - void operator()() - { - op1 = op2; - } - }; - - // Assigns value a2 to a1. The point of time of the real operation can be controlled - // with the () operator. - template - assigner assigno(t1 &a1, const t2 &a2) - { - return assigner(a1,a2); - } - - //deleted pointer and sets it to NULL - template - void clear_pointer(T* &ptr) - { - delete ptr; - ptr = NULL; - } -} -using vstd::operator-=; - -// can be used for counting arrays -template char (&_ArrayCountObj(const T (&)[N]))[N]; -#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) - -//for explicit overrides -#ifdef _MSC_VER -#define OVERRIDE override -#else -#define OVERRIDE //is there any working counterpart? -#endif - -//XXX pls dont - 'debug macros' are usually more trouble than it's worth -#define HANDLE_EXCEPTION \ - catch (const std::exception& e) { \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::exception * e) \ -{ \ - tlog1 << e->what()<< std::endl; \ - throw; \ -} \ - catch (const std::string& e) { \ - tlog1 << e << std::endl; \ - throw; \ -} - -#define HANDLE_EXCEPTIONC(COMMAND) \ - catch (const std::exception& e) { \ - COMMAND; \ - tlog1 << e.what() << std::endl; \ - throw; \ -} \ - catch (const std::string &e) \ -{ \ - COMMAND; \ - tlog1 << e << std::endl; \ - throw; \ -} - - -#include "../lib/CLogger.h" +// Here you can add specific libraries and macros which are specific to this project. \ No newline at end of file diff --git a/server/VCMI_server.cbp b/server/VCMI_server.cbp deleted file mode 100644 index 402648ec9..000000000 --- a/server/VCMI_server.cbp +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - diff --git a/server/VCMI_server.vcxproj b/server/VCMI_server.vcxproj index 1a5a4e52a..e2a1b84ce 100644 --- a/server/VCMI_server.vcxproj +++ b/server/VCMI_server.vcxproj @@ -204,6 +204,7 @@ + diff --git a/server/vcmi_server/Makefile b/server/vcmi_server/Makefile deleted file mode 100644 index 30bc67837..000000000 --- a/server/vcmi_server/Makefile +++ /dev/null @@ -1,92 +0,0 @@ -# -# There exist several targets which are by default empty and which can be -# used for execution of your targets. These targets are usually executed -# before and after some main targets. They are: -# -# .build-pre: called before 'build' target -# .build-post: called after 'build' target -# .clean-pre: called before 'clean' target -# .clean-post: called after 'clean' target -# .clobber-pre: called before 'clobber' target -# .clobber-post: called after 'clobber' target -# .all-pre: called before 'all' target -# .all-post: called after 'all' target -# .help-pre: called before 'help' target -# .help-post: called after 'help' target -# -# Targets beginning with '.' are not intended to be called on their own. -# -# Main targets can be executed directly, and they are: -# -# build build a specific configuration -# clean remove built files from a configuration -# clobber remove all built files -# all build all configurations -# help print help mesage -# -# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and -# .help-impl are implemented in nbproject/makefile-impl.mk. -# -# NOCDDL - - -# Environment -MKDIR=mkdir -CP=cp -CCADMIN=CCadmin -RANLIB=ranlib - - -# build -build: .build-post - -.build-pre: -# Add your pre 'build' code here... - -.build-post: .build-impl -# Add your post 'build' code here... - - -# clean -clean: .clean-post - -.clean-pre: -# Add your pre 'clean' code here... - -.clean-post: .clean-impl -# Add your post 'clean' code here... - - -# clobber -clobber: .clobber-post - -.clobber-pre: -# Add your pre 'clobber' code here... - -.clobber-post: .clobber-impl -# Add your post 'clobber' code here... - - -# all -all: .all-post - -.all-pre: -# Add your pre 'all' code here... - -.all-post: .all-impl -# Add your post 'all' code here... - - -# help -help: .help-post - -.help-pre: -# Add your pre 'help' code here... - -.help-post: .help-impl -# Add your post 'help' code here... - - - -# include project implementation makefile -include nbproject/Makefile-impl.mk diff --git a/server/vcmi_server/nbproject/Makefile-Debug.mk b/server/vcmi_server/nbproject/Makefile-Debug.mk deleted file mode 100644 index b386e2aae..000000000 --- a/server/vcmi_server/nbproject/Makefile-Debug.mk +++ /dev/null @@ -1,81 +0,0 @@ -# -# Generated Makefile - do not edit! -# -# Edit the Makefile in the project folder instead (../Makefile). Each target -# has a -pre and a -post target defined where you can add customized code. -# -# This makefile implements configuration specific macros and targets. - - -# Environment -MKDIR=mkdir -CP=cp -CCADMIN=CCadmin -RANLIB=ranlib -CC=gcc -CCC=g++ -CXX=g++ -FC=gfortran - -# Macros -PLATFORM=GNU-Linux-x86 - -# Include project Makefile -include Makefile - -# Object Directory -OBJECTDIR=build/Debug/${PLATFORM} - -# Object Files -OBJECTFILES= \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CVCMIServer.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../../hch/CLodHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CGameHandler.o - -# C Compiler Flags -CFLAGS= - -# CC Compiler Flags -CCFLAGS= -CXXFLAGS= - -# Fortran Compiler Flags -FFLAGS= - -# Link Libraries and Options -LDLIBSOPTIONS=-L../../../../boost/lib -Wl,-rpath ../../lib/vcmi_lib/dist/Debug/GNU-Linux-x86 -L../../lib/vcmi_lib/dist/Debug/GNU-Linux-x86 -lvcmi_lib - -# Build Targets -.build-conf: ${BUILD_SUBPROJECTS} - ${MAKE} -f nbproject/Makefile-Debug.mk dist/Debug/${PLATFORM}/vcmi_server - -dist/Debug/${PLATFORM}/vcmi_server: ../../lib/vcmi_lib/dist/Debug/GNU-Linux-x86/libvcmi_lib.so - -dist/Debug/${PLATFORM}/vcmi_server: ${OBJECTFILES} - ${MKDIR} -p dist/Debug/${PLATFORM} - ${LINK.cc} -lboost_system-mt -lboost_thread-mt -lboost_filesystem-mt -lz -o dist/Debug/${PLATFORM}/vcmi_server ${OBJECTFILES} ${LDLIBSOPTIONS} - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CVCMIServer.o: ../CVCMIServer.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/.. - $(COMPILE.cc) -g -I../../../../boost/include/boost-1_37 -I../.. -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CVCMIServer.o ../CVCMIServer.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../../hch/CLodHandler.o: ../../hch/CLodHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../../hch - $(COMPILE.cc) -g -I../../../../boost/include/boost-1_37 -I../.. -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../../hch/CLodHandler.o ../../hch/CLodHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CGameHandler.o: ../CGameHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/.. - $(COMPILE.cc) -g -I../../../../boost/include/boost-1_37 -I../.. -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CGameHandler.o ../CGameHandler.cpp - -# Subprojects -.build-subprojects: - cd ../../lib/vcmi_lib && ${MAKE} -f Makefile-nb CONF=Debug - -# Clean Targets -.clean-conf: ${CLEAN_SUBPROJECTS} - ${RM} -r build/Debug - ${RM} dist/Debug/${PLATFORM}/vcmi_server - -# Subprojects -.clean-subprojects: - cd ../../lib/vcmi_lib && ${MAKE} -f Makefile-nb CONF=Debug clean diff --git a/server/vcmi_server/nbproject/Makefile-Release.mk b/server/vcmi_server/nbproject/Makefile-Release.mk deleted file mode 100644 index 36953cf2e..000000000 --- a/server/vcmi_server/nbproject/Makefile-Release.mk +++ /dev/null @@ -1,77 +0,0 @@ -# -# Generated Makefile - do not edit! -# -# Edit the Makefile in the project folder instead (../Makefile). Each target -# has a -pre and a -post target defined where you can add customized code. -# -# This makefile implements configuration specific macros and targets. - - -# Environment -MKDIR=mkdir -CP=cp -CCADMIN=CCadmin -RANLIB=ranlib -CC=gcc -CCC=g++ -CXX=g++ -FC=gfortran - -# Macros -PLATFORM=GNU-Linux-x86 - -# Include project Makefile -include Makefile - -# Object Directory -OBJECTDIR=build/Release/${PLATFORM} - -# Object Files -OBJECTFILES= \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CVCMIServer.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../../hch/CLodHandler.o \ - ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CGameHandler.o - -# C Compiler Flags -CFLAGS= - -# CC Compiler Flags -CCFLAGS= -CXXFLAGS= - -# Fortran Compiler Flags -FFLAGS= - -# Link Libraries and Options -LDLIBSOPTIONS= - -# Build Targets -.build-conf: ${BUILD_SUBPROJECTS} - ${MAKE} -f nbproject/Makefile-Release.mk dist/Release/${PLATFORM}/vcmi_server - -dist/Release/${PLATFORM}/vcmi_server: ${OBJECTFILES} - ${MKDIR} -p dist/Release/${PLATFORM} - ${LINK.cc} -o dist/Release/${PLATFORM}/vcmi_server ${OBJECTFILES} ${LDLIBSOPTIONS} - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CVCMIServer.o: ../CVCMIServer.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CVCMIServer.o ../CVCMIServer.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../../hch/CLodHandler.o: ../../hch/CLodHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../../hch - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../../hch/CLodHandler.o ../../hch/CLodHandler.cpp - -${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CGameHandler.o: ../CGameHandler.cpp - ${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/.. - $(COMPILE.cc) -O2 -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/server/vcmi_server/../CGameHandler.o ../CGameHandler.cpp - -# Subprojects -.build-subprojects: - -# Clean Targets -.clean-conf: - ${RM} -r build/Release - ${RM} dist/Release/${PLATFORM}/vcmi_server - -# Subprojects -.clean-subprojects: diff --git a/server/vcmi_server/nbproject/Makefile-impl.mk b/server/vcmi_server/nbproject/Makefile-impl.mk deleted file mode 100644 index debd44e0d..000000000 --- a/server/vcmi_server/nbproject/Makefile-impl.mk +++ /dev/null @@ -1,123 +0,0 @@ -# -# Generated Makefile - do not edit! -# -# Edit the Makefile in the project folder instead (../Makefile). Each target -# has a pre- and a post- target defined where you can add customization code. -# -# This makefile implements macros and targets common to all configurations. -# -# NOCDDL - - -# Building and Cleaning subprojects are done by default, but can be controlled with the SUB -# macro. If SUB=no, subprojects will not be built or cleaned. The following macro -# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf -# and .clean-reqprojects-conf unless SUB has the value 'no' -SUB_no=NO -SUBPROJECTS=${SUB_${SUB}} -BUILD_SUBPROJECTS_=.build-subprojects -BUILD_SUBPROJECTS_NO= -BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}} -CLEAN_SUBPROJECTS_=.clean-subprojects -CLEAN_SUBPROJECTS_NO= -CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}} - - -# Project Name -PROJECTNAME=vcmi_server - -# Active Configuration -DEFAULTCONF=Debug -CONF=${DEFAULTCONF} - -# All Configurations -ALLCONFS=Debug Release - - -# build -.build-impl: .build-pre .validate-impl .depcheck-impl - @#echo "=> Running $@... Configuration=$(CONF)" - ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf - - -# clean -.clean-impl: .clean-pre .validate-impl .depcheck-impl - @#echo "=> Running $@... Configuration=$(CONF)" - ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf - - -# clobber -.clobber-impl: .clobber-pre .depcheck-impl - @#echo "=> Running $@..." - for CONF in ${ALLCONFS}; \ - do \ - ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf; \ - done - -# all -.all-impl: .all-pre .depcheck-impl - @#echo "=> Running $@..." - for CONF in ${ALLCONFS}; \ - do \ - ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf; \ - done - -# dependency checking support -.depcheck-impl: - @echo "# This code depends on make tool being used" >.dep.inc - @if [ -n "${MAKE_VERSION}" ]; then \ - echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \ - echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ - echo "include \$${DEPFILES}" >>.dep.inc; \ - echo "endif" >>.dep.inc; \ - else \ - echo ".KEEP_STATE:" >>.dep.inc; \ - echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ - fi - -# configuration validation -.validate-impl: - @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ - then \ - echo ""; \ - echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \ - echo "See 'make help' for details."; \ - echo "Current directory: " `pwd`; \ - echo ""; \ - fi - @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ - then \ - exit 1; \ - fi - - -# help -.help-impl: .help-pre - @echo "This makefile supports the following configurations:" - @echo " ${ALLCONFS}" - @echo "" - @echo "and the following targets:" - @echo " build (default target)" - @echo " clean" - @echo " clobber" - @echo " all" - @echo " help" - @echo "" - @echo "Makefile Usage:" - @echo " make [CONF=] [SUB=no] build" - @echo " make [CONF=] [SUB=no] clean" - @echo " make [SUB=no] clobber" - @echo " make [SUB=no] all" - @echo " make help" - @echo "" - @echo "Target 'build' will build a specific configuration and, unless 'SUB=no'," - @echo " also build subprojects." - @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no'," - @echo " also clean subprojects." - @echo "Target 'clobber' will remove all built files from all configurations and," - @echo " unless 'SUB=no', also from subprojects." - @echo "Target 'all' will will build all configurations and, unless 'SUB=no'," - @echo " also build subprojects." - @echo "Target 'help' prints this message." - @echo "" - diff --git a/server/vcmi_server/nbproject/Package-Debug.bash b/server/vcmi_server/nbproject/Package-Debug.bash deleted file mode 100644 index e66fba47e..000000000 --- a/server/vcmi_server/nbproject/Package-Debug.bash +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash -x - -# -# Generated - do not edit! -# - -# Macros -TOP=`pwd` -PLATFORM=GNU-Linux-x86 -TMPDIR=build/Debug/${PLATFORM}/tmp-packaging -TMPDIRNAME=tmp-packaging -OUTPUT_PATH=dist/Debug/${PLATFORM}/vcmi_server -OUTPUT_BASENAME=vcmi_server -PACKAGE_TOP_DIR=vcmiserver/ - -# Functions -function checkReturnCode -{ - rc=$? - if [ $rc != 0 ] - then - exit $rc - fi -} -function makeDirectory -# $1 directory path -# $2 permission (optional) -{ - mkdir -p "$1" - checkReturnCode - if [ "$2" != "" ] - then - chmod $2 "$1" - checkReturnCode - fi -} -function copyFileToTmpDir -# $1 from-file path -# $2 to-file path -# $3 permission -{ - cp "$1" "$2" - checkReturnCode - if [ "$3" != "" ] - then - chmod $3 "$2" - checkReturnCode - fi -} - -# Setup -cd "${TOP}" -mkdir -p dist/Debug/${PLATFORM}/package -rm -rf ${TMPDIR} -mkdir -p ${TMPDIR} - -# Copy files and create directories and links -cd "${TOP}" -makeDirectory ${TMPDIR}/vcmiserver/bin -copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 - - -# Generate tar file -cd "${TOP}" -rm -f dist/Debug/${PLATFORM}/package/vcmiserver.tar -cd ${TMPDIR} -tar -vcf ../../../../dist/Debug/${PLATFORM}/package/vcmiserver.tar * -checkReturnCode - -# Cleanup -cd "${TOP}" -rm -rf ${TMPDIR} diff --git a/server/vcmi_server/nbproject/Package-Release.bash b/server/vcmi_server/nbproject/Package-Release.bash deleted file mode 100644 index 38729c9e3..000000000 --- a/server/vcmi_server/nbproject/Package-Release.bash +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash -x - -# -# Generated - do not edit! -# - -# Macros -TOP=`pwd` -PLATFORM=GNU-Linux-x86 -TMPDIR=build/Release/${PLATFORM}/tmp-packaging -TMPDIRNAME=tmp-packaging -OUTPUT_PATH=dist/Release/${PLATFORM}/vcmi_server -OUTPUT_BASENAME=vcmi_server -PACKAGE_TOP_DIR=vcmiserver/ - -# Functions -function checkReturnCode -{ - rc=$? - if [ $rc != 0 ] - then - exit $rc - fi -} -function makeDirectory -# $1 directory path -# $2 permission (optional) -{ - mkdir -p "$1" - checkReturnCode - if [ "$2" != "" ] - then - chmod $2 "$1" - checkReturnCode - fi -} -function copyFileToTmpDir -# $1 from-file path -# $2 to-file path -# $3 permission -{ - cp "$1" "$2" - checkReturnCode - if [ "$3" != "" ] - then - chmod $3 "$2" - checkReturnCode - fi -} - -# Setup -cd "${TOP}" -mkdir -p dist/Release/${PLATFORM}/package -rm -rf ${TMPDIR} -mkdir -p ${TMPDIR} - -# Copy files and create directories and links -cd "${TOP}" -makeDirectory ${TMPDIR}/vcmiserver/bin -copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 - - -# Generate tar file -cd "${TOP}" -rm -f dist/Release/${PLATFORM}/package/vcmiserver.tar -cd ${TMPDIR} -tar -vcf ../../../../dist/Release/${PLATFORM}/package/vcmiserver.tar * -checkReturnCode - -# Cleanup -cd "${TOP}" -rm -rf ${TMPDIR} diff --git a/server/vcmi_server/nbproject/configurations.xml b/server/vcmi_server/nbproject/configurations.xml deleted file mode 100644 index 459da84a6..000000000 --- a/server/vcmi_server/nbproject/configurations.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - - - ../CGameHandler.h - ../../hch/CLodHandler.h - ../CVCMIServer.h - - - - - ../CGameHandler.cpp - ../../hch/CLodHandler.cpp - ../CVCMIServer.cpp - - - Makefile - - - - .. - - Makefile - - - - localhost - GNU|GNU - 2 - - - - - ../../../../boost/include/boost-1_37 - ../.. - - - - - ../../../../boost/lib - - - - - - - - -lboost_system-mt -lboost_thread-mt -lboost_filesystem-mt -lz - - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - - - localhost - GNU|GNU - 2 - - - - 5 - - - 5 - - - 5 - - - - - - - - 1 - - - 3 - - - 1 - - - 3 - - - 1 - - - 3 - - - - diff --git a/server/vcmi_server/nbproject/project.properties b/server/vcmi_server/nbproject/project.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/server/vcmi_server/nbproject/project.xml b/server/vcmi_server/nbproject/project.xml deleted file mode 100644 index c78e89cf9..000000000 --- a/server/vcmi_server/nbproject/project.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - org.netbeans.modules.cnd.makeproject - - - vcmi_server - 0 - - cpp - h - UTF-8 - - ../../lib/vcmi_lib - - - - diff --git a/vcmi.workspace b/vcmi.workspace deleted file mode 100644 index 7f1ec3eca..000000000 --- a/vcmi.workspace +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - From 156aa6e4d9da74fede072502988af0193a1be1b4 Mon Sep 17 00:00:00 2001 From: beegee1 Date: Thu, 22 Dec 2011 13:05:19 +0000 Subject: [PATCH 5/5] * Updated class - file - handling * Renamed color constants * Renamed class AdventureMapButton to CAdventureMapButton * Moved basic controls like CTextBox from GuiClasses to CIntObjectClasses * Moved new creature window from GuiClasses to CCreatureWindow --- AI/GeniusAI/BattleLogic.cpp | 10 +- AI/GeniusAI/CGeniusAI.cpp | 4 +- AI/GeniusAI/CGeniusAI.h | 2 +- AI/StupidAI/StupidAI.cpp | 24 +- AI/StupidAI/StupidAI.h | 6 +- Scripting/ERM/ERM.vcxproj | 1 + client/AdventureMapButton.cpp | 697 -------- client/AdventureMapButton.h | 165 -- client/BattleInterface/CAttackAnimation.cpp | 51 - client/BattleInterface/CAttackAnimation.h | 35 - client/BattleInterface/CBattleAnimation.cpp | 49 - client/BattleInterface/CBattleAnimation.h | 30 - client/BattleInterface/CBattleAnimations.cpp | 1075 ++++++++++++ client/BattleInterface/CBattleAnimations.h | 221 +++ client/BattleInterface/CBattleConsole.cpp | 84 - client/BattleInterface/CBattleConsole.h | 35 - client/BattleInterface/CBattleHero.cpp | 154 -- client/BattleInterface/CBattleHero.h | 39 - client/BattleInterface/CBattleInterface.cpp | 151 +- client/BattleInterface/CBattleInterface.h | 61 +- .../CBattleInterfaceClasses.cpp | 754 ++++++++ .../BattleInterface/CBattleInterfaceClasses.h | 159 ++ .../BattleInterface/CBattleOptionsWindow.cpp | 73 - client/BattleInterface/CBattleOptionsWindow.h | 39 - .../BattleInterface/CBattleResultWindow.cpp | 217 --- client/BattleInterface/CBattleResultWindow.h | 37 - .../BattleInterface/CBattleStackAnimation.cpp | 57 - .../BattleInterface/CBattleStackAnimation.h | 31 - client/BattleInterface/CClickableHex.cpp | 148 -- client/BattleInterface/CClickableHex.h | 40 - client/BattleInterface/CCreatureAnimation.cpp | 2 +- client/BattleInterface/CDefenceAnimation.cpp | 139 -- client/BattleInterface/CDefenceAnimation.h | 34 - client/BattleInterface/CDummyAnimation.cpp | 27 - client/BattleInterface/CDummyAnimation.h | 28 - .../BattleInterface/CMeleeAttackAnimation.cpp | 95 - .../BattleInterface/CMeleeAttackAnimation.h | 28 - client/BattleInterface/CMovementAnimation.cpp | 176 -- client/BattleInterface/CMovementAnimation.h | 37 - .../BattleInterface/CMovementEndAnimation.cpp | 52 - .../BattleInterface/CMovementEndAnimation.h | 30 - .../CMovementStartAnimation.cpp | 52 - .../BattleInterface/CMovementStartAnimation.h | 27 - client/BattleInterface/CReverseAnimation.cpp | 100 -- client/BattleInterface/CReverseAnimation.h | 34 - client/BattleInterface/CShootingAnimation.cpp | 192 --- client/BattleInterface/CShootingAnimation.h | 49 - .../BattleInterface/CSpellEffectAnimation.cpp | 182 -- .../BattleInterface/CSpellEffectAnimation.h | 35 - client/BattleInterface/CStackQueue.cpp | 126 -- client/BattleInterface/CStackQueue.h | 51 - client/BattleInterface/SStackAttackedInfo.h | 25 - client/CAdvmapInterface.cpp | 84 +- client/CAdvmapInterface.h | 10 +- client/CAnimation.cpp | 42 +- client/CAnimation.h | 22 +- client/CCastleInterface.cpp | 166 +- client/CCastleInterface.h | 38 +- client/CCreatureWindow.cpp | 234 ++- client/CCreatureWindow.h | 63 +- client/CHeroWindow.cpp | 82 +- client/CHeroWindow.h | 6 +- client/CKingdomInterface.cpp | 126 +- client/CKingdomInterface.h | 26 +- client/CMT.cpp | 5 +- client/CMessage.cpp | 47 +- client/CMessage.h | 8 +- client/CPlayerInterface.cpp | 47 +- client/CPlayerInterface.h | 14 +- client/CPreGame.cpp | 254 +-- client/CPreGame.h | 31 +- client/CSpellWindow.cpp | 17 +- client/CSpellWindow.h | 2 +- client/CVideoHandler.cpp | 3 +- client/Client.cpp | 2 +- client/GUIClasses.cpp | 1536 ++++------------- client/GUIClasses.h | 387 +---- client/Graphics.cpp | 22 +- client/Graphics.h | 5 +- client/Makefile.am | 65 +- client/NetPacksClient.cpp | 4 +- client/{ => UIFramework}/CCursorHandler.cpp | 6 +- client/{ => UIFramework}/CCursorHandler.h | 0 client/UIFramework/CGuiHandler.cpp | 43 +- client/UIFramework/CGuiHandler.h | 30 +- client/UIFramework/CIntObject.cpp | 54 +- client/UIFramework/CIntObject.h | 85 +- client/UIFramework/CIntObjectClasses.cpp | 1490 ++++++++++++++++ client/UIFramework/CIntObjectClasses.h | 450 +++++ client/UIFramework/CKeyShortcut.cpp | 20 - client/UIFramework/CKeyShortcut.h | 25 - client/UIFramework/CPicture.cpp | 133 -- client/UIFramework/CPicture.h | 46 - client/UIFramework/CSimpleWindow.h | 23 - client/UIFramework/Geometries.cpp | 19 + client/UIFramework/Geometries.h | 262 +++ client/UIFramework/IActivatable.h | 20 - client/UIFramework/IShowActivatable.h | 24 - client/UIFramework/IShowable.h | 26 - client/UIFramework/IStatusBar.h | 24 - client/UIFramework/IUpdateable.h | 18 - client/{ => UIFramework}/SDL_Extensions.cpp | 30 +- client/{ => UIFramework}/SDL_Extensions.h | 34 +- client/UIFramework/SPoint.h | 87 - client/UIFramework/SRect.cpp | 19 - client/UIFramework/SRect.h | 187 -- client/VCMI_client.vcxproj | 73 +- client/VCMI_client.vcxproj.filters | 168 +- client/mapHandler.cpp | 2 +- lib/BattleAction.cpp | 4 +- lib/BattleAction.h | 8 +- lib/{SBattleHex.cpp => BattleHex.cpp} | 22 +- lib/{SBattleHex.h => BattleHex.h} | 24 +- lib/BattleState.cpp | 210 +-- lib/BattleState.h | 64 +- lib/CGameInterface.cpp | 2 +- lib/CGameInterface.h | 4 +- lib/CHeroHandler.cpp | 8 +- lib/CHeroHandler.h | 6 +- lib/IGameCallback.cpp | 40 +- lib/IGameCallback.h | 26 +- lib/IGameEventsReceiver.h | 4 +- lib/Makefile.am | 4 +- lib/NetPacks.h | 4 +- lib/NetPacksLib.cpp | 4 +- lib/VCMI_lib.vcxproj | 4 +- server/CGameHandler.cpp | 24 +- server/CGameHandler.h | 4 +- 128 files changed, 6224 insertions(+), 6958 deletions(-) delete mode 100644 client/AdventureMapButton.cpp delete mode 100644 client/AdventureMapButton.h delete mode 100644 client/BattleInterface/CAttackAnimation.cpp delete mode 100644 client/BattleInterface/CAttackAnimation.h delete mode 100644 client/BattleInterface/CBattleAnimation.cpp delete mode 100644 client/BattleInterface/CBattleAnimation.h create mode 100644 client/BattleInterface/CBattleAnimations.cpp create mode 100644 client/BattleInterface/CBattleAnimations.h delete mode 100644 client/BattleInterface/CBattleConsole.cpp delete mode 100644 client/BattleInterface/CBattleConsole.h delete mode 100644 client/BattleInterface/CBattleHero.cpp delete mode 100644 client/BattleInterface/CBattleHero.h create mode 100644 client/BattleInterface/CBattleInterfaceClasses.cpp create mode 100644 client/BattleInterface/CBattleInterfaceClasses.h delete mode 100644 client/BattleInterface/CBattleOptionsWindow.cpp delete mode 100644 client/BattleInterface/CBattleOptionsWindow.h delete mode 100644 client/BattleInterface/CBattleResultWindow.cpp delete mode 100644 client/BattleInterface/CBattleResultWindow.h delete mode 100644 client/BattleInterface/CBattleStackAnimation.cpp delete mode 100644 client/BattleInterface/CBattleStackAnimation.h delete mode 100644 client/BattleInterface/CClickableHex.cpp delete mode 100644 client/BattleInterface/CClickableHex.h delete mode 100644 client/BattleInterface/CDefenceAnimation.cpp delete mode 100644 client/BattleInterface/CDefenceAnimation.h delete mode 100644 client/BattleInterface/CDummyAnimation.cpp delete mode 100644 client/BattleInterface/CDummyAnimation.h delete mode 100644 client/BattleInterface/CMeleeAttackAnimation.cpp delete mode 100644 client/BattleInterface/CMeleeAttackAnimation.h delete mode 100644 client/BattleInterface/CMovementAnimation.cpp delete mode 100644 client/BattleInterface/CMovementAnimation.h delete mode 100644 client/BattleInterface/CMovementEndAnimation.cpp delete mode 100644 client/BattleInterface/CMovementEndAnimation.h delete mode 100644 client/BattleInterface/CMovementStartAnimation.cpp delete mode 100644 client/BattleInterface/CMovementStartAnimation.h delete mode 100644 client/BattleInterface/CReverseAnimation.cpp delete mode 100644 client/BattleInterface/CReverseAnimation.h delete mode 100644 client/BattleInterface/CShootingAnimation.cpp delete mode 100644 client/BattleInterface/CShootingAnimation.h delete mode 100644 client/BattleInterface/CSpellEffectAnimation.cpp delete mode 100644 client/BattleInterface/CSpellEffectAnimation.h delete mode 100644 client/BattleInterface/CStackQueue.cpp delete mode 100644 client/BattleInterface/CStackQueue.h delete mode 100644 client/BattleInterface/SStackAttackedInfo.h rename client/{ => UIFramework}/CCursorHandler.cpp (93%) rename client/{ => UIFramework}/CCursorHandler.h (100%) create mode 100644 client/UIFramework/CIntObjectClasses.cpp create mode 100644 client/UIFramework/CIntObjectClasses.h delete mode 100644 client/UIFramework/CKeyShortcut.cpp delete mode 100644 client/UIFramework/CKeyShortcut.h delete mode 100644 client/UIFramework/CPicture.cpp delete mode 100644 client/UIFramework/CPicture.h delete mode 100644 client/UIFramework/CSimpleWindow.h create mode 100644 client/UIFramework/Geometries.cpp create mode 100644 client/UIFramework/Geometries.h delete mode 100644 client/UIFramework/IActivatable.h delete mode 100644 client/UIFramework/IShowActivatable.h delete mode 100644 client/UIFramework/IShowable.h delete mode 100644 client/UIFramework/IStatusBar.h delete mode 100644 client/UIFramework/IUpdateable.h rename client/{ => UIFramework}/SDL_Extensions.cpp (94%) rename client/{ => UIFramework}/SDL_Extensions.h (88%) delete mode 100644 client/UIFramework/SPoint.h delete mode 100644 client/UIFramework/SRect.cpp delete mode 100644 client/UIFramework/SRect.h rename lib/{SBattleHex.cpp => BattleHex.cpp} (71%) rename lib/{SBattleHex.h => BattleHex.h} (71%) diff --git a/AI/GeniusAI/BattleLogic.cpp b/AI/GeniusAI/BattleLogic.cpp index 3da277936..d2fc9f2d5 100644 --- a/AI/GeniusAI/BattleLogic.cpp +++ b/AI/GeniusAI/BattleLogic.cpp @@ -526,7 +526,7 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) } } - std::vector fields = m_cb->battleGetAvailableHexes(m_cb->battleGetStackByID(attackerID), false); + std::vector fields = m_cb->battleGetAvailableHexes(m_cb->battleGetStackByID(attackerID), false); if(fields.size() == 0) { @@ -540,11 +540,11 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) ba.destinationTile = static_cast(dest_tile); //simplified checking for possibility of attack (previous was too simplified) int destStackPos = m_cb->battleGetPos(destinationID); - if(SBattleHex::mutualPosition(dest_tile, destStackPos) != -1) + if(BattleHex::mutualPosition(dest_tile, destStackPos) != -1) ba.additionalInfo = destStackPos; - else if(SBattleHex::mutualPosition(dest_tile, destStackPos+1) != -1) + else if(BattleHex::mutualPosition(dest_tile, destStackPos+1) != -1) ba.additionalInfo = destStackPos+1; - else if(SBattleHex::mutualPosition(dest_tile, destStackPos-1) != -1) + else if(BattleHex::mutualPosition(dest_tile, destStackPos-1) != -1) ba.additionalInfo = destStackPos-1; else return BattleAction::makeDefend(attackerStack); @@ -581,7 +581,7 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) } } - for (std::vector::const_iterator it = fields.begin(); it != fields.end(); ++it) + for (std::vector::const_iterator it = fields.begin(); it != fields.end(); ++it) { if (*it == dest_tile) { diff --git a/AI/GeniusAI/CGeniusAI.cpp b/AI/GeniusAI/CGeniusAI.cpp index e15836b6f..231c2fa16 100644 --- a/AI/GeniusAI/CGeniusAI.cpp +++ b/AI/GeniusAI/CGeniusAI.cpp @@ -1311,7 +1311,7 @@ void CGeniusAI::battleNewRound(int round) /** * */ -void CGeniusAI::battleStackMoved(int ID, std::vector dest, int distance) +void CGeniusAI::battleStackMoved(int ID, std::vector dest, int distance) { std::string message("\t\t\tCGeniusAI::battleStackMoved ID("); message += boost::lexical_cast(ID); @@ -1345,7 +1345,7 @@ void CGeniusAI::battleSpellCast(const BattleSpellCast *sc) * */ // void CGeniusAI::battleStackMoved(int ID, -// SBattleHex dest, +// BattleHex dest, // bool startMoving, // bool endMoving) // { diff --git a/AI/GeniusAI/CGeniusAI.h b/AI/GeniusAI/CGeniusAI.h index a5ebc7f2b..f22242895 100644 --- a/AI/GeniusAI/CGeniusAI.h +++ b/AI/GeniusAI/CGeniusAI.h @@ -201,7 +201,7 @@ public: virtual void battleStacksAttacked(const std::set & bsa); //called when stack receives damage (after battleAttack()) virtual void battleEnd(const BattleResult *br); virtual void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackMoved(int ID, std::vector dest, int distance); + virtual void battleStackMoved(int ID, std::vector dest, int distance); virtual void battleSpellCast(const BattleSpellCast *sc); virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right //virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles); //called when battlefield is prepared, prior the battle beginning diff --git a/AI/StupidAI/StupidAI.cpp b/AI/StupidAI/StupidAI.cpp index 21ba21e4f..f67a76da9 100644 --- a/AI/StupidAI/StupidAI.cpp +++ b/AI/StupidAI/StupidAI.cpp @@ -39,7 +39,7 @@ struct EnemyInfo { const CStack * s; int adi, adr; - std::vector attackFrom; //for melee fight + std::vector attackFrom; //for melee fight EnemyInfo(const CStack * _s) : s(_s) {} void calcDmg(const CStack * ourStack) @@ -60,10 +60,10 @@ bool isMoreProfitable(const EnemyInfo &ei1, const EnemyInfo& ei2) return (ei1.adi-ei1.adr) < (ei2.adi - ei2.adr); } -int distToNearestNeighbour(SBattleHex hex, const std::vector & dists, SBattleHex *chosenHex = NULL) +int distToNearestNeighbour(BattleHex hex, const std::vector & dists, BattleHex *chosenHex = NULL) { int ret = 1000000; - BOOST_FOREACH(SBattleHex n, hex.neighbouringTiles()) + BOOST_FOREACH(BattleHex n, hex.neighbouringTiles()) { if(dists[n] >= 0 && dists[n] < ret) { @@ -81,12 +81,12 @@ bool isCloser(const EnemyInfo & ei1, const EnemyInfo & ei2, const std::vectorposition, dists) < distToNearestNeighbour(ei2.s->position, dists); } -static bool willSecondHexBlockMoreEnemyShooters(const SBattleHex &h1, const SBattleHex &h2) +static bool willSecondHexBlockMoreEnemyShooters(const BattleHex &h1, const BattleHex &h2) { int shooters[2] = {0}; //count of shooters on hexes for(int i = 0; i < 2; i++) - BOOST_FOREACH(SBattleHex neighbour, (i ? h2 : h1).neighbouringTiles()) + BOOST_FOREACH(BattleHex neighbour, (i ? h2 : h1).neighbouringTiles()) if(const CStack *s = cbc->battleGetStackByPos(neighbour)) if(s->getCreature()->isShooting()) shooters[i]++; @@ -98,7 +98,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack ) { //boost::this_thread::sleep(boost::posix_time::seconds(2)); print("activeStack called"); - std::vector avHexes = cb->battleGetAvailableHexes(stack, false); + std::vector avHexes = cb->battleGetAvailableHexes(stack, false); std::vector dists = cb->battleGetDistances(stack); std::vector enemiesShootable, enemiesReachable, enemiesUnreachable; @@ -110,7 +110,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack ) } else { - BOOST_FOREACH(SBattleHex hex, avHexes) + BOOST_FOREACH(BattleHex hex, avHexes) { if(CStack::isMeleeAttackPossible(stack, s, hex)) { @@ -182,7 +182,7 @@ void CStupidAI::battleNewRound(int round) print("battleNewRound called"); } -void CStupidAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) +void CStupidAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) { print("battleStackMoved called");; } @@ -233,10 +233,10 @@ void CStupidAI::print(const std::string &text) const tlog0 << "CStupidAI [" << this <<"]: " << text << std::endl; } -BattleAction CStupidAI::goTowards(const CStack * stack, SBattleHex hex) +BattleAction CStupidAI::goTowards(const CStack * stack, BattleHex hex) { - SBattleHex realDest = hex; - SBattleHex predecessors[GameConstants::BFIELD_SIZE]; + BattleHex realDest = hex; + BattleHex predecessors[GameConstants::BFIELD_SIZE]; std::vector dists = cb->battleGetDistances(stack, hex); if(distToNearestNeighbour(hex, dists, &realDest) > GameConstants::BFIELD_SIZE) { @@ -245,7 +245,7 @@ BattleAction CStupidAI::goTowards(const CStack * stack, SBattleHex hex) } dists = cb->battleGetDistances(stack, realDest, predecessors); - std::vector avHexes = cb->battleGetAvailableHexes(stack, false); + std::vector avHexes = cb->battleGetAvailableHexes(stack, false); if(!avHexes.size()) { diff --git a/AI/StupidAI/StupidAI.h b/AI/StupidAI/StupidAI.h index 909135adc..cfef50a86 100644 --- a/AI/StupidAI/StupidAI.h +++ b/AI/StupidAI/StupidAI.h @@ -1,6 +1,6 @@ #pragma once -#include "../../lib/SBattleHex.h" +#include "../../lib/BattleHex.h" class CStupidAI : public CBattleGameInterface { @@ -23,7 +23,7 @@ public: //void battleResultsApplied() OVERRIDE; //called when all effects of last battle are applied void battleNewRoundFirst(int round) OVERRIDE; //called at the beginning of each turn before changes are applied; void battleNewRound(int round) OVERRIDE; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; + void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; void battleSpellCast(const BattleSpellCast *sc) OVERRIDE; void battleStacksEffectsSet(const SetStackEffect & sse) OVERRIDE;//called when a specific effect is set to stacks //void battleTriggerEffect(const BattleTriggerEffect & bte) OVERRIDE; @@ -34,6 +34,6 @@ public: void battleCatapultAttacked(const CatapultAttack & ca) OVERRIDE; //called when catapult makes an attack void battleStacksRemoved(const BattleStacksRemoved & bsr) OVERRIDE; //called when certain stack is completely removed from battlefield - BattleAction goTowards(const CStack * stack, SBattleHex hex ); + BattleAction goTowards(const CStack * stack, BattleHex hex ); }; diff --git a/Scripting/ERM/ERM.vcxproj b/Scripting/ERM/ERM.vcxproj index b931aabea..0d7184acc 100644 --- a/Scripting/ERM/ERM.vcxproj +++ b/Scripting/ERM/ERM.vcxproj @@ -92,6 +92,7 @@ %(AdditionalIncludeDirectories) Use StdInc.h + /Zm207 %(AdditionalOptions) true diff --git a/client/AdventureMapButton.cpp b/client/AdventureMapButton.cpp deleted file mode 100644 index fe4449959..000000000 --- a/client/AdventureMapButton.cpp +++ /dev/null @@ -1,697 +0,0 @@ -#include "StdInc.h" -#include "AdventureMapButton.h" - -#include "CAnimation.h" -#include "SDL_Extensions.h" -#include "CGameInfo.h" -#include "../CCallback.h" -#include "CConfigHandler.h" -#include "BattleInterface/CBattleInterface.h" -#include "BattleInterface/CBattleConsole.h" -#include "CPlayerInterface.h" -#include "CMessage.h" -#include "CMusicHandler.h" -#include "GUIClasses.h" -#include "UIFramework/CGuiHandler.h" - -/* - * AdventureMapButton.cpp, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -CButtonBase::CButtonBase() -{ - swappedImages = keepFrame = false; - bitmapOffset = 0; - state=NORMAL; - image = NULL; - text = NULL; -} - -CButtonBase::~CButtonBase() -{ - -} - -void CButtonBase::update() -{ - if (text) - { - if (state == PRESSED) - text->moveTo(SPoint(pos.x+pos.w/2+1, pos.y+pos.h/2+1)); - else - text->moveTo(SPoint(pos.x+pos.w/2, pos.y+pos.h/2)); - } - - int newPos = (int)state + bitmapOffset; - if (newPos < 0) - newPos = 0; - - if (state == HIGHLIGHTED && image->size() < 4) - newPos = image->size()-1; - - if (swappedImages) - { - if (newPos == 0) newPos = 1; - else if (newPos == 1) newPos = 0; - } - - if (!keepFrame) - image->setFrame(newPos); - - if (active) - redraw(); -} - -void CButtonBase::addTextOverlay( const std::string &Text, EFonts font, SDL_Color color) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - delChild(text); - text = new CLabel(pos.w/2, pos.h/2, font, CENTER, color, Text); - update(); -} - -void CButtonBase::setOffset(int newOffset) -{ - if (bitmapOffset == newOffset) - return; - bitmapOffset = newOffset; - update(); -} - -void CButtonBase::setState(ButtonState newState) -{ - if (state == newState) - return; - state = newState; - update(); -} - -CButtonBase::ButtonState CButtonBase::getState() -{ - return state; -} - -bool CButtonBase::isBlocked() -{ - return state == BLOCKED; -} - -bool CButtonBase::isHighlighted() -{ - return state == HIGHLIGHTED; -} - -void CButtonBase::block(bool on) -{ - setState(on?BLOCKED:NORMAL); -} - -AdventureMapButton::AdventureMapButton () -{ - hoverable = actOnDown = borderEnabled = soundDisabled = false; - borderColor.unused = 1; // represents a transparent color, used for HighlightableButton - used = LCLICK | RCLICK | HOVER | KEYBOARD; -} - -AdventureMapButton::AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, int x, int y, const std::string &defName,int key, std::vector * add, bool playerColoredButton ) -{ - std::map pom; - pom[0] = Name; - init(Callback, pom, HelpBox, playerColoredButton, defName, add, x, y, key); -} - -AdventureMapButton::AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, config::ButtonInfo *info, int key/*=0*/ ) -{ - std::map pom; - pom[0] = Name; - init(Callback, pom, HelpBox, info->playerColoured, info->defName, &info->additionalDefs, info->x, info->y, key); -} - -AdventureMapButton::AdventureMapButton( const std::pair &help, const CFunctionList &Callback, int x, int y, const std::string &defName, int key/*=0*/, std::vector * add /*= NULL*/, bool playerColoredButton /*= false */ ) -{ - std::map pom; - pom[0] = help.first; - init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key); -} -void AdventureMapButton::clickLeft(tribool down, bool previousState) -{ - if(isBlocked()) - return; - - if (down) - { - if (!soundDisabled) - CCS->soundh->playSound(soundBase::button); - setState(PRESSED); - } - else if(hoverable && hovered) - setState(HIGHLIGHTED); - else - setState(NORMAL); - - if (actOnDown && down) - { - callback(); - } - else if (!actOnDown && previousState && (down==false)) - { - callback(); - } -} - -void AdventureMapButton::clickRight(tribool down, bool previousState) -{ - if(down && helpBox.size()) //there is no point to show window with nothing inside... - CRClickPopup::createAndPush(helpBox); -} - -void AdventureMapButton::hover (bool on) -{ - if(hoverable) - { - if(on) - setState(HIGHLIGHTED); - else - setState(NORMAL); - } - - if(pressedL && on) - setState(PRESSED); - - std::string *name = (vstd::contains(hoverTexts,getState())) - ? (&hoverTexts[getState()]) - : (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL); - if(name && name->size() && !isBlocked()) //if there is no name, there is nohing to display also - { - if (LOCPLINT && LOCPLINT->battleInt) //for battle buttons - { - if(on && LOCPLINT->battleInt->console->alterTxt == "") - { - LOCPLINT->battleInt->console->alterTxt = *name; - LOCPLINT->battleInt->console->whoSetAlter = 1; - } - else if (LOCPLINT->battleInt->console->alterTxt == *name) - { - LOCPLINT->battleInt->console->alterTxt = ""; - LOCPLINT->battleInt->console->whoSetAlter = 0; - } - } - else if(GH.statusbar) //for other buttons - { - if (on) - GH.statusbar->print(*name); - else if ( GH.statusbar->getCurrent()==(*name) ) - GH.statusbar->clear(); - } - } -} - -void AdventureMapButton::init(const CFunctionList &Callback, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key) -{ - currentImage = -1; - used = LCLICK | RCLICK | HOVER | KEYBOARD; - callback = Callback; - hoverable = actOnDown = borderEnabled = soundDisabled = false; - borderColor.unused = 1; // represents a transparent color, used for HighlightableButton - assignedKeys.insert(key); - hoverTexts = Name; - helpBox=HelpBox; - - pos.x += x; - pos.y += y; - - if (!defName.empty()) - imageNames.push_back(defName); - if (add) - for (size_t i=0; isize();i++ ) - imageNames.push_back(add->at(i)); - setIndex(0, playerColoredButton); -} - -void AdventureMapButton::setIndex(size_t index, bool playerColoredButton) -{ - if (index == currentImage || index>=imageNames.size()) - return; - currentImage = index; - setImage(new CAnimation(imageNames[index]), playerColoredButton); -} - -void AdventureMapButton::setImage(CAnimation* anim, bool playerColoredButton) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - - if (image && active) - image->deactivate(); - delChild(image); - image = new CAnimImage(anim, getState()); - if (active) - image->activate(); - if (playerColoredButton) - image->playerColored(LOCPLINT->playerID); - - pos.w = image->pos.w; - pos.h = image->pos.h; -} - -void AdventureMapButton::setPlayerColor(int player) -{ - if (image) - image->playerColored(player); -} - -void AdventureMapButton::showAll(SDL_Surface *to) -{ - CIntObject::showAll(to); - - if (borderEnabled && borderColor.unused == 0) - CSDL_Ext::drawBorder(to, pos.x - 1, pos.y - 1, pos.w + 2, pos.h + 2, int3(borderColor.r, borderColor.g, borderColor.b)); -} - -void CHighlightableButton::select(bool on) -{ - selected = on; - if (on) - { - setState(HIGHLIGHTED); - callback(); - borderEnabled = true; - } - else - { - setState(NORMAL); - callback2(); - borderEnabled = false; - } - - if(hoverTexts.size()>1) - { - hover(false); - hover(true); - } -} - -void CHighlightableButton::clickLeft(tribool down, bool previousState) -{ - if(isBlocked()) - return; - - if (down && !(onlyOn && isHighlighted())) - { - CCS->soundh->playSound(soundBase::button); - setState(PRESSED); - } - - if(previousState && down == false && getState() == PRESSED) - { - //if(!onlyOn || !isHighlighted()) - select(!selected); - } -} - -CHighlightableButton::CHighlightableButton( const CFunctionList &onSelect, const CFunctionList &onDeselect, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key) -: onlyOn(false), selected(false), callback2(onDeselect) -{ - init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,key); -} - -CHighlightableButton::CHighlightableButton( const std::pair &help, const CFunctionList &onSelect, int x, int y, const std::string &defName, int myid, int key/*=0*/, std::vector * add /*= NULL*/, bool playerColoredButton /*= false */ ) -: onlyOn(false), selected(false) // TODO: callback2(???) -{ - ID = myid; - std::map pom; - pom[0] = help.first; - init(onSelect, pom, help.second, playerColoredButton, defName, add, x, y, key); -} - -CHighlightableButton::CHighlightableButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &onSelect, int x, int y, const std::string &defName, int myid, int key/*=0*/, std::vector * add /*= NULL*/, bool playerColoredButton /*= false */ ) -: onlyOn(false), selected(false) // TODO: callback2(???) -{ - ID = myid; - std::map pom; - pom[0] = Name; - init(onSelect, pom,HelpBox, playerColoredButton, defName, add, x, y, key); -} - -void CHighlightableButtonsGroup::addButton(CHighlightableButton* bt) -{ - if (bt->parent) - bt->parent->removeChild(bt); - addChild(bt); - bt->recActions = defActions;//FIXME: not needed? - - bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID); - bt->onlyOn = true; - buttons.push_back(bt); -} - -void CHighlightableButtonsGroup::addButton(const std::map &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList &OnSelect, int key) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - CHighlightableButton *bt = new CHighlightableButton(OnSelect, 0, tooltip, HelpBox, false, defName, 0, x, y, key); - if(musicLike) - { - if (buttons.size() > 3) - bt->setOffset(buttons.size()-3); - } - bt->ID = uid; - bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID); - bt->onlyOn = true; - buttons.push_back(bt); -} - -CHighlightableButtonsGroup::CHighlightableButtonsGroup(const CFunctionList2 &OnChange, bool musicLikeButtons) -: onChange(OnChange), musicLike(musicLikeButtons) -{} - -CHighlightableButtonsGroup::~CHighlightableButtonsGroup() -{ - -} - -void CHighlightableButtonsGroup::select(int id, bool mode) -{ - CHighlightableButton *bt = NULL; - if(mode) - { - for(size_t i=0;iID == id) - bt = buttons[i]; - } - else - { - bt = buttons[id]; - } - bt->select(true); - selectionChanged(bt->ID); -} - -void CHighlightableButtonsGroup::selectionChanged(int to) -{ - for(size_t i=0;iID!=to && buttons[i]->isHighlighted()) - buttons[i]->select(false); - onChange(to); - if (parent) - parent->redraw(); -} - -void CHighlightableButtonsGroup::show(SDL_Surface * to ) -{ - if (musicLike) - { - for(size_t i=0;iisHighlighted()) - buttons[i]->show(to); - } - else - CIntObject::show(to); -} - -void CHighlightableButtonsGroup::showAll( SDL_Surface * to ) -{ - if (musicLike) - { - for(size_t i=0;iisHighlighted()) - buttons[i]->showAll(to); - } - else - CIntObject::showAll(to); -} - -void CHighlightableButtonsGroup::block( ui8 on ) -{ - for(size_t i=0;iblock(on); - } -} - -void CSlider::sliderClicked() -{ - if(!(active & MOVE)) - { - activateMouseMove(); - used |= MOVE; - } -} - -void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent) -{ - double v = 0; - if(horizontal) - { - if( std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2+40 || std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2 ) - return; - v = sEvent.x - pos.x - 24; - v *= positions; - v /= (pos.w - 48); - } - else - { - if(std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2+40 || std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2 ) - return; - v = sEvent.y - pos.y - 24; - v *= positions; - v /= (pos.h - 48); - } - v += 0.5; - if(v!=value) - { - moveTo(v); - redrawSlider(); - } -} - -void CSlider::redrawSlider() -{ - //slider->show(screenBuf); -} - -void CSlider::moveLeft() -{ - moveTo(value-1); -} - -void CSlider::moveRight() -{ - moveTo(value+1); -} - -void CSlider::moveTo(int to) -{ - vstd::amax(to, 0); - vstd::amin(to, positions); - - //same, old position? - if(value == to) - return; - - value = to; - if(horizontal) - { - if(positions) - { - double part = static_cast(to) / positions; - part*=(pos.w-48); - int newPos = part + pos.x + 16 - slider->pos.x; - slider->moveBy(SPoint(newPos, 0)); - } - else - slider->moveTo(SPoint(pos.x+16, pos.y)); - } - else - { - if(positions) - { - double part = static_cast(to) / positions; - part*=(pos.h-48); - int newPos = part + pos.y + 16 - slider->pos.y; - slider->moveBy(SPoint(0, newPos)); - } - else - slider->moveTo(SPoint(pos.x, pos.y+16)); - } - - if(moved) - moved(to); -} - -void CSlider::clickLeft(tribool down, bool previousState) -{ - if(down && !slider->isBlocked()) - { - double pw = 0; - double rw = 0; - if(horizontal) - { - pw = GH.current->motion.x-pos.x-25; - rw = pw / static_cast(pos.w - 48); - } - else - { - pw = GH.current->motion.y-pos.y-24; - rw = pw / (pos.h-48); - } - if(pw < -8 || pw > (horizontal ? pos.w : pos.h) - 40) - return; -// if (rw>1) return; -// if (rw<0) return; - slider->clickLeft(true, slider->pressedL); - moveTo(rw * positions + 0.5); - return; - } - if(active & MOVE) - { - deactivateMouseMove(); - used &= ~MOVE; - } -} - -CSlider::~CSlider() -{ - -} - -CSlider::CSlider(int x, int y, int totalw, boost::function Moved, int Capacity, int Amount, int Value, bool Horizontal, int style) -:capacity(Capacity),amount(Amount),horizontal(Horizontal), moved(Moved) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - setAmount(amount); - - used = LCLICK; - strongInterest = true; - - - left = new AdventureMapButton(); - right = new AdventureMapButton(); - slider = new AdventureMapButton(); - - pos.x += x; - pos.y += y; - - if(horizontal) - { - left->pos.y = slider->pos.y = right->pos.y = pos.y; - left->pos.x = pos.x; - right->pos.x = pos.x + totalw - 16; - } - else - { - left->pos.x = slider->pos.x = right->pos.x = pos.x; - left->pos.y = pos.y; - right->pos.y = pos.y + totalw - 16; - } - - left->callback = boost::bind(&CSlider::moveLeft,this); - right->callback = boost::bind(&CSlider::moveRight,this); - slider->callback = boost::bind(&CSlider::sliderClicked,this); - left->pos.w = left->pos.h = right->pos.w = right->pos.h = slider->pos.w = slider->pos.h = 16; - if(horizontal) - { - pos.h = 16; - pos.w = totalw; - } - else - { - pos.w = 16; - pos.h = totalw; - } - - if(style == 0) - { - std::string name = horizontal?"IGPCRDIV.DEF":"OVBUTN2.DEF"; - CAnimation *animLeft = new CAnimation(name); - left->setImage(animLeft); - left->setOffset(0); - - CAnimation *animRight = new CAnimation(name); - right->setImage(animRight); - right->setOffset(2); - - CAnimation *animSlider = new CAnimation(name); - slider->setImage(animSlider); - slider->setOffset(4); - } - else - { - left->setImage(new CAnimation(horizontal ? "SCNRBLF.DEF" : "SCNRBUP.DEF")); - right->setImage(new CAnimation(horizontal ? "SCNRBRT.DEF" : "SCNRBDN.DEF")); - slider->setImage(new CAnimation("SCNRBSL.DEF")); - } - slider->actOnDown = true; - slider->soundDisabled = true; - left->soundDisabled = true; - right->soundDisabled = true; - - value = -1; - moveTo(Value); -} - -void CSlider::block( bool on ) -{ - left->block(on); - right->block(on); - slider->block(on); -} - -void CSlider::setAmount( int to ) -{ - amount = to; - positions = to - capacity; - vstd::amax(positions, 0); -} - -void CSlider::showAll(SDL_Surface * to) -{ - CSDL_Ext::fillRect(to, &pos, 0); - CIntObject::showAll(to); -} - -void CSlider::wheelScrolled(bool down, bool in) -{ - moveTo(value + 3 * (down ? +1 : -1)); -} - -void CSlider::keyPressed(const SDL_KeyboardEvent & key) -{ - if(key.state != SDL_PRESSED) return; - - int moveDest = 0; - switch(key.keysym.sym) - { - case SDLK_UP: - moveDest = value - 1; - break; - case SDLK_DOWN: - moveDest = value + 1; - break; - case SDLK_PAGEUP: - moveDest = value - capacity + 1; - break; - case SDLK_PAGEDOWN: - moveDest = value + capacity - 1; - break; - case SDLK_HOME: - moveDest = 0; - break; - case SDLK_END: - moveDest = amount - capacity; - break; - default: - return; - } - - moveTo(moveDest); -} - -void CSlider::moveToMax() -{ - moveTo(amount); -} diff --git a/client/AdventureMapButton.h b/client/AdventureMapButton.h deleted file mode 100644 index aa0576d35..000000000 --- a/client/AdventureMapButton.h +++ /dev/null @@ -1,165 +0,0 @@ -#pragma once - -#include "FunctionList.h" -#include "UIFramework/CKeyShortcut.h" -#include "UIFramework/SRect.h" - -/* - * AdventureMapButton.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -extern SDL_Color tytulowy, tlo, zwykly ; - -class CAnimation; -class CAnimImage; -class CLabel; - -namespace config{struct ButtonInfo;} - -/// Base class for buttons. -class CButtonBase : public CKeyShortcut -{ -public: - enum ButtonState - { - NORMAL=0, - PRESSED=1, - BLOCKED=2, - HIGHLIGHTED=3 - }; -private: - int bitmapOffset; // base offset of visible bitmap from animation - ButtonState state;//current state of button from enum - -public: - bool swappedImages,//fix for some buttons: normal and pressed image are swapped - keepFrame; // don't change visual representation - - void addTextOverlay(const std::string &Text, EFonts font, SDL_Color color = zwykly); - void update();//to refresh button after image or text change - - void setOffset(int newOffset); - void setState(ButtonState newState); - ButtonState getState(); - - //just to make code clearer - void block(bool on); - bool isBlocked(); - bool isHighlighted(); - - CAnimImage * image; //image for this button - CLabel * text;//text overlay - - CButtonBase(); //c-tor - virtual ~CButtonBase(); //d-tor -}; - -/// Typical Heroes 3 button which can be inactive or active and can -/// hold further information if you right-click it -class AdventureMapButton : public CButtonBase -{ - std::vector imageNames;//store list of images that can be used by this button - size_t currentImage; -public: - std::map hoverTexts; //text for statusbar - std::string helpBox; //for right-click help - CFunctionList callback; - bool actOnDown,//runs when mouse is pressed down over it, not when up - hoverable,//if true, button will be highlighted when hovered - borderEnabled, - soundDisabled; - SDL_Color borderColor; - - void clickRight(tribool down, bool previousState); - virtual void clickLeft(tribool down, bool previousState); - void hover (bool on); - - AdventureMapButton(); //c-tor - AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, int x, int y, const std::string &defName, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor - AdventureMapButton( const std::pair &help, const CFunctionList &Callback, int x, int y, const std::string &defName, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor - AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, config::ButtonInfo *info, int key=0);//c-tor - - void init(const CFunctionList &Callback, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key ); - - void setIndex(size_t index, bool playerColoredButton=false); - void setImage(CAnimation* anim, bool playerColoredButton=false); - void setPlayerColor(int player); - void showAll(SDL_Surface *to); -}; - -/// A button which can be selected/deselected -class CHighlightableButton - : public AdventureMapButton -{ -public: - CHighlightableButton(const CFunctionList &onSelect, const CFunctionList &onDeselect, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key=0); - CHighlightableButton(const std::pair &help, const CFunctionList &onSelect, int x, int y, const std::string &defName, int myid, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor - CHighlightableButton(const std::string &Name, const std::string &HelpBox, const CFunctionList &onSelect, int x, int y, const std::string &defName, int myid, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor - bool onlyOn;//button can not be de-selected - bool selected;//state of highlightable button - int ID; //for identification - CFunctionList callback2; //when de-selecting - void select(bool on); - void clickLeft(tribool down, bool previousState); -}; - -/// A group of buttons where one button can be selected -class CHighlightableButtonsGroup : public CIntObject -{ -public: - CFunctionList2 onChange; //called when changing selected button with new button's id - std::vector buttons; - bool musicLike; //determines the behaviour of this group - - //void addButton(const std::map &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid); - void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor - void addButton(const std::map &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList &OnSelect=0, int key=0); //creates new button - CHighlightableButtonsGroup(const CFunctionList2 &OnChange, bool musicLikeButtons = false); - ~CHighlightableButtonsGroup(); - void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id - void selectionChanged(int to); - void show(SDL_Surface * to); - void showAll(SDL_Surface * to); - void block(ui8 on); -}; - -/// A typical slider which can be orientated horizontally/vertically. -class CSlider : public CIntObject -{ -public: - AdventureMapButton *left, *right, *slider; //if vertical then left=up - int capacity,//how many elements can be active at same time - amount, //how many elements - positions, //number of highest position (0 if there is only one) - value; //first active element - bool horizontal; - bool wheelScrolling; - bool keyScrolling; - - boost::function moved; - - void redrawSlider(); - void sliderClicked(); - void moveLeft(); - void moveRight(); - void moveTo(int to); - void block(bool on); - void setAmount(int to); - - void keyPressed(const SDL_KeyboardEvent & key); - void wheelScrolled(bool down, bool in); - void clickLeft(tribool down, bool previousState); - void mouseMoved (const SDL_MouseMotionEvent & sEvent); - void showAll(SDL_Surface * to); - - CSlider(int x, int y, int totalw, boost::function Moved, int Capacity, int Amount, - int Value=0, bool Horizontal=true, int style = 0); //style 0 - brown, 1 - blue - ~CSlider(); - void moveToMax(); -}; diff --git a/client/BattleInterface/CAttackAnimation.cpp b/client/BattleInterface/CAttackAnimation.cpp deleted file mode 100644 index f21d9f6ba..000000000 --- a/client/BattleInterface/CAttackAnimation.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "StdInc.h" -#include "CAttackAnimation.h" - -#include "../CMusicHandler.h" -#include "../CGameInfo.h" -#include "CBattleInterface.h" -#include "CCreatureAnimation.h" -#include "../../lib/BattleState.h" -#include "../CPlayerInterface.h" -#include "../../CCallback.h" - -void CAttackAnimation::nextFrame() -{ - if(myAnim()->getType() != group) - myAnim()->setType(group); - - if(myAnim()->onFirstFrameInGroup()) - { - if(shooting) - CCS->soundh->playSound(battle_sound(attackingStack->getCreature(), shoot)); - else - CCS->soundh->playSound(battle_sound(attackingStack->getCreature(), attack)); - } - else if(myAnim()->onLastFrameInGroup()) - { - myAnim()->setType(CCreatureAnim::HOLDING); - endAnim(); - return; //execution of endAnim deletes this !!! - } -} - -bool CAttackAnimation::checkInitialConditions() -{ - return isEarliest(false); -} - -CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SBattleHex _dest, const CStack *defender) -: CBattleStackAnimation(_owner, attacker), dest(_dest), attackedStack(defender), attackingStack(attacker) -{ - - assert(attackingStack && "attackingStack is NULL in CBattleAttack::CBattleAttack !\n"); - if(attackingStack->getCreature()->idNumber != 145) //catapult is allowed to attack not-creature - { - assert(attackedStack && "attackedStack is NULL in CBattleAttack::CBattleAttack !\n"); - } - else //catapult can attack walls only - { - assert(owner->curInt->cb->battleGetWallUnderHex(_dest) >= 0); - } - attackingStackPosBeforeReturn = attackingStack->position; -} \ No newline at end of file diff --git a/client/BattleInterface/CAttackAnimation.h b/client/BattleInterface/CAttackAnimation.h deleted file mode 100644 index 9c63f46df..000000000 --- a/client/BattleInterface/CAttackAnimation.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "CBattleStackAnimation.h" -#include "../CAnimation.h" -#include "../../lib/SBattleHex.h" - -class CBattleInterface; -class CStack; - -/* - * CAttackAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// This class is responsible for managing the battle attack animation -class CAttackAnimation : public CBattleStackAnimation -{ -protected: - SBattleHex dest; //attacked hex - bool shooting; - CCreatureAnim::EAnimType group; //if shooting is true, print this animation group - const CStack *attackedStack; - const CStack *attackingStack; - int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature -public: - void nextFrame(); - bool checkInitialConditions(); - - CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SBattleHex _dest, const CStack *defender); -}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleAnimation.cpp b/client/BattleInterface/CBattleAnimation.cpp deleted file mode 100644 index 8f7fa0e7e..000000000 --- a/client/BattleInterface/CBattleAnimation.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "StdInc.h" -#include "CBattleAnimation.h" -#include "CBattleInterface.h" -#include "../../lib/BattleState.h" -#include "CSpellEffectAnimation.h" -#include "CReverseAnimation.h" - -void CBattleAnimation::endAnim() -{ - for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - if(it->first == this) - { - it->first = NULL; - } - } - -} - -bool CBattleAnimation::isEarliest(bool perStackConcurrency) -{ - int lowestMoveID = owner->animIDhelper + 5; - CBattleStackAnimation * thAnim = dynamic_cast(this); - CSpellEffectAnimation * thSen = dynamic_cast(this); - - for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - CBattleStackAnimation * stAnim = dynamic_cast(it->first); - CSpellEffectAnimation * sen = dynamic_cast(it->first); - if(perStackConcurrency && stAnim && thAnim && stAnim->stack->ID != thAnim->stack->ID) - continue; - - if(sen && thSen && sen != thSen && perStackConcurrency) - continue; - - CReverseAnimation * revAnim = dynamic_cast(stAnim); - - if(revAnim && thAnim && stAnim && stAnim->stack->ID == thAnim->stack->ID && revAnim->priority) - return false; - - if(it->first) - vstd::amin(lowestMoveID, it->first->ID); - } - return (ID == lowestMoveID) || (lowestMoveID == (owner->animIDhelper + 5)); -} - -CBattleAnimation::CBattleAnimation(CBattleInterface * _owner) - : owner(_owner), ID(_owner->animIDhelper++) -{} \ No newline at end of file diff --git a/client/BattleInterface/CBattleAnimation.h b/client/BattleInterface/CBattleAnimation.h deleted file mode 100644 index 99902f414..000000000 --- a/client/BattleInterface/CBattleAnimation.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -class CBattleInterface; - -/* - * CBattleAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Base class of battle animations -class CBattleAnimation -{ -protected: - CBattleInterface * owner; -public: - virtual bool init()=0; //to be called - if returned false, call again until returns true - virtual void nextFrame()=0; //call every new frame - virtual void endAnim(); //to be called mostly internally; in this class it removes animation from pendingAnims list - - bool isEarliest(bool perStackConcurrency); //determines if this animation is earliest of all - - ui32 ID; //unique identifier - - CBattleAnimation(CBattleInterface * _owner); -}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleAnimations.cpp b/client/BattleInterface/CBattleAnimations.cpp new file mode 100644 index 000000000..965ed7e5b --- /dev/null +++ b/client/BattleInterface/CBattleAnimations.cpp @@ -0,0 +1,1075 @@ +#include "StdInc.h" +#include "CBattleAnimations.h" + +#include +#include "../CMusicHandler.h" +#include "../CGameInfo.h" +#include "CBattleInterface.h" +#include "CBattleInterfaceClasses.h" +#include "CCreatureAnimation.h" +#include "../../lib/BattleState.h" +#include "../CPlayerInterface.h" +#include "../../CCallback.h" +#include "../UIFramework/SDL_Extensions.h" +#include "../Graphics.h" +#include "../UIFramework/CCursorHandler.h" +#include "../../lib/CTownHandler.h" + + +CBattleAnimation::CBattleAnimation(CBattleInterface * _owner) +: owner(_owner), ID(_owner->animIDhelper++) +{} + +void CBattleAnimation::endAnim() +{ + for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + if(it->first == this) + { + it->first = NULL; + } + } + +} + +bool CBattleAnimation::isEarliest(bool perStackConcurrency) +{ + int lowestMoveID = owner->animIDhelper + 5; + CBattleStackAnimation * thAnim = dynamic_cast(this); + CSpellEffectAnimation * thSen = dynamic_cast(this); + + for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + CBattleStackAnimation * stAnim = dynamic_cast(it->first); + CSpellEffectAnimation * sen = dynamic_cast(it->first); + if(perStackConcurrency && stAnim && thAnim && stAnim->stack->ID != thAnim->stack->ID) + continue; + + if(sen && thSen && sen != thSen && perStackConcurrency) + continue; + + CReverseAnimation * revAnim = dynamic_cast(stAnim); + + if(revAnim && thAnim && stAnim && stAnim->stack->ID == thAnim->stack->ID && revAnim->priority) + return false; + + if(it->first) + vstd::amin(lowestMoveID, it->first->ID); + } + return (ID == lowestMoveID) || (lowestMoveID == (owner->animIDhelper + 5)); +} + +CBattleStackAnimation::CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack) +: CBattleAnimation(_owner), stack(_stack) +{} + +bool CBattleStackAnimation::isToReverseHlp(BattleHex hexFrom, BattleHex hexTo, bool curDir) +{ + int fromMod = hexFrom % GameConstants::BFIELD_WIDTH; + int fromDiv = hexFrom / GameConstants::BFIELD_WIDTH; + int toMod = hexTo % GameConstants::BFIELD_WIDTH; + + if(curDir && fromMod < toMod) + return false; + else if(curDir && fromMod > toMod) + return true; + else if(curDir && fromMod == toMod) + { + return fromDiv % 2 == 0; + } + else if(!curDir && fromMod < toMod) + return true; + else if(!curDir && fromMod > toMod) + return false; + else if(!curDir && fromMod == toMod) + { + return fromDiv % 2 == 1; + } + tlog1 << "Catastrope in CBattleStackAnimation::isToReverse!" << std::endl; + return false; //should never happen +} + +bool CBattleStackAnimation::isToReverse(BattleHex hexFrom, BattleHex hexTo, bool curDir, bool toDoubleWide, bool toDir) +{ + if(hexTo < 0) //turret + return false; + + if(toDoubleWide) + { + return isToReverseHlp(hexFrom, hexTo, curDir) && + (toDir ? isToReverseHlp(hexFrom, hexTo-1, curDir) : isToReverseHlp(hexFrom, hexTo+1, curDir) ); + } + else + { + return isToReverseHlp(hexFrom, hexTo, curDir); + } +} + +CCreatureAnimation* CBattleStackAnimation::myAnim() +{ + return owner->creAnims[stack->ID]; +} + +void CAttackAnimation::nextFrame() +{ + if(myAnim()->getType() != group) + myAnim()->setType(group); + + if(myAnim()->onFirstFrameInGroup()) + { + if(shooting) + CCS->soundh->playSound(battle_sound(attackingStack->getCreature(), shoot)); + else + CCS->soundh->playSound(battle_sound(attackingStack->getCreature(), attack)); + } + else if(myAnim()->onLastFrameInGroup()) + { + myAnim()->setType(CCreatureAnim::HOLDING); + endAnim(); + return; //execution of endAnim deletes this !!! + } +} + +bool CAttackAnimation::checkInitialConditions() +{ + return isEarliest(false); +} + +CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender) +: CBattleStackAnimation(_owner, attacker), dest(_dest), attackedStack(defender), attackingStack(attacker) +{ + + assert(attackingStack && "attackingStack is NULL in CBattleAttack::CBattleAttack !\n"); + if(attackingStack->getCreature()->idNumber != 145) //catapult is allowed to attack not-creature + { + assert(attackedStack && "attackedStack is NULL in CBattleAttack::CBattleAttack !\n"); + } + else //catapult can attack walls only + { + assert(owner->curInt->cb->battleGetWallUnderHex(_dest) >= 0); + } + attackingStackPosBeforeReturn = attackingStack->position; +} + +CDefenceAnimation::CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner) +: CBattleStackAnimation(_owner, _attackedInfo.defender), dmg(_attackedInfo.dmg), +amountKilled(_attackedInfo.amountKilled), attacker(_attackedInfo.attacker), byShooting(_attackedInfo.byShooting), +killed(_attackedInfo.killed) +{} + +bool CDefenceAnimation::init() +{ + //checking initial conditions + + //if(owner->creAnims[stackID]->getType() != 2) + //{ + // return false; + //} + + if(attacker == NULL && owner->battleEffects.size() > 0) + return false; + + ui32 lowestMoveID = owner->animIDhelper + 5; + for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + CDefenceAnimation * defAnim = dynamic_cast(it->first); + if(defAnim && defAnim->stack->ID != stack->ID) + continue; + + CAttackAnimation * attAnim = dynamic_cast(it->first); + if(attAnim && attAnim->stack->ID != stack->ID) + continue; + + if(attacker != NULL) + { + int attackerAnimType = owner->creAnims[attacker->ID]->getType(); + if( attackerAnimType == 11 && attackerAnimType == 12 && attackerAnimType == 13 && owner->creAnims[attacker->ID]->getFrame() < attacker->getCreature()->attackClimaxFrame ) + return false; + } + + CReverseAnimation * animAsRev = dynamic_cast(it->first); + + if(animAsRev && animAsRev->priority) + return false; + + if(it->first) + vstd::amin(lowestMoveID, it->first->ID); + } + if(ID > lowestMoveID) + return false; + + + + //reverse unit if necessary + if(attacker && isToReverse(stack->position, attacker->position, owner->creDir[stack->ID], attacker->doubleWide(), owner->creDir[attacker->ID])) + { + owner->addNewAnim(new CReverseAnimation(owner, stack, stack->position, true)); + return false; + } + //unit reversed + + if(byShooting) //delay hit animation + { + for(std::list::const_iterator it = owner->projectiles.begin(); it != owner->projectiles.end(); ++it) + { + if(it->creID == attacker->getCreature()->idNumber) + { + return false; + } + } + } + + //initializing + if(killed) + { + CCS->soundh->playSound(battle_sound(stack->getCreature(), killed)); + myAnim()->setType(CCreatureAnim::DEATH); //death + } + else + { + // TODO: this block doesn't seems correct if the unit is defending. + CCS->soundh->playSound(battle_sound(stack->getCreature(), wince)); + myAnim()->setType(CCreatureAnim::HITTED); //getting hit + } + + return true; //initialized successfuly +} + +void CDefenceAnimation::nextFrame() +{ + if(!killed && myAnim()->getType() != CCreatureAnim::HITTED) + { + myAnim()->setType(CCreatureAnim::HITTED); + } + + if(!myAnim()->onLastFrameInGroup()) + { + if( myAnim()->getType() == CCreatureAnim::DEATH && (owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0 + && !myAnim()->onLastFrameInGroup() ) + { + myAnim()->incrementFrame(); + } + } + else + { + endAnim(); + } + +} + +void CDefenceAnimation::endAnim() +{ + //restoring animType + + if(myAnim()->getType() == CCreatureAnim::HITTED) + myAnim()->setType(CCreatureAnim::HOLDING); + + //printing info to console + + //if(attacker!=NULL) + // owner->printConsoleAttacked(stack, dmg, amountKilled, attacker); + + //const CStack * attacker = owner->curInt->cb->battleGetStackByID(IDby, false); + //const CStack * attacked = owner->curInt->cb->battleGetStackByID(stackID, false); + + CBattleAnimation::endAnim(); + + delete this; +} + +CDummyAnimation::CDummyAnimation(CBattleInterface * _owner, int howManyFrames) +: CBattleAnimation(_owner), counter(0), howMany(howManyFrames) +{} + +bool CDummyAnimation::init() +{ + return true; +} + +void CDummyAnimation::nextFrame() +{ + counter++; + if(counter > howMany) + endAnim(); +} + +void CDummyAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + + delete this; +} + +bool CMeleeAttackAnimation::init() +{ + if( !CAttackAnimation::checkInitialConditions() ) + return false; + + //if(owner->creAnims[stackID]->getType()!=2) + //{ + // return false; + //} + + if(!attackingStack || myAnim()->getType() == 5) + { + endAnim(); + + return false; + } + + bool toReverse = isToReverse(attackingStackPosBeforeReturn, dest, owner->creDir[stack->ID], attackedStack->doubleWide(), owner->creDir[attackedStack->ID]); + + if(toReverse) + { + + owner->addNewAnim(new CReverseAnimation(owner, stack, attackingStackPosBeforeReturn, true)); + return false; + } + //reversed + + shooting = false; + + static const CCreatureAnim::EAnimType mutPosToGroup[] = {CCreatureAnim::ATTACK_UP, CCreatureAnim::ATTACK_UP, + CCreatureAnim::ATTACK_FRONT, CCreatureAnim::ATTACK_DOWN, CCreatureAnim::ATTACK_DOWN, CCreatureAnim::ATTACK_FRONT}; + + int revShiftattacker = (attackingStack->attackerOwned ? -1 : 1); + + int mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn, dest); + if(mutPos == -1 && attackingStack->doubleWide()) + { + mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->position); + } + if (mutPos == -1 && attackedStack->doubleWide()) + { + mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn, attackedStack->occupiedHex()); + } + if (mutPos == -1 && attackedStack->doubleWide() && attackingStack->doubleWide()) + { + mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->occupiedHex()); + } + + + switch(mutPos) //attack direction + { + case 0: case 1: case 2: case 3: case 4: case 5: + group = mutPosToGroup[mutPos]; + break; + default: + tlog1<<"Critical Error! Wrong dest in stackAttacking! dest: "< >::const_iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + CBattleMoveStart * anim = dynamic_cast(it->first); + CReverseAnim * anim2 = dynamic_cast(it->first); + if( (anim && anim->stackID == stackID) || (anim2 && anim2->stackID == stackID ) ) + return; + }*/ + + CAttackAnimation::nextFrame(); +} + +void CMeleeAttackAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + + delete this; +} + +bool CMovementAnimation::init() +{ + if( !isEarliest(false) ) + return false; + + //a few useful variables + steps = static_cast(myAnim()->framesInGroup(CCreatureAnim::MOVING) * owner->getAnimSpeedMultiplier() - 1); + if(steps == 0) //this creature seems to have no move animation so we can end it immediately + { + endAnim(); + return false; + } + whichStep = 0; + int hexWbase = 44, hexHbase = 42; + const CStack * movedStack = stack; + if(!movedStack || myAnim()->getType() == 5) + { + endAnim(); + return false; + } + //bool twoTiles = movedStack->doubleWide(); + + Point begPosition = CClickableHex::getXYUnitAnim(curStackPos, movedStack->attackerOwned, movedStack, owner); + Point endPosition = CClickableHex::getXYUnitAnim(nextHex, movedStack->attackerOwned, movedStack, owner); + + int mutPos = BattleHex::mutualPosition(curStackPos, nextHex); + + //reverse unit if necessary + if((begPosition.x > endPosition.x) && owner->creDir[stack->ID] == true) + { + owner->addNewAnim(new CReverseAnimation(owner, stack, curStackPos, true)); + return false; + } + else if ((begPosition.x < endPosition.x) && owner->creDir[stack->ID] == false) + { + owner->addNewAnim(new CReverseAnimation(owner, stack, curStackPos, true)); + return false; + } + + if(myAnim()->getType() != CCreatureAnim::MOVING) + { + myAnim()->setType(CCreatureAnim::MOVING); + } + //unit reversed + + // if(owner->moveSh <= 0) + // owner->moveSh = CCS->soundh->playSound(battle_sound(movedStack->getCreature(), move), -1); + + //step shift calculation + posX = myAnim()->pos.x, posY = myAnim()->pos.y; // for precise calculations ;] + if(mutPos == -1 && movedStack->hasBonusOfType(Bonus::FLYING)) + { + steps *= distance; + steps /= 2; //to make animation faster + + stepX = (endPosition.x - begPosition.x) / static_cast(steps); + stepY = (endPosition.y - begPosition.y) / static_cast(steps); + } + else + { + switch(mutPos) + { + case 0: + stepX = -1.0 * (hexWbase / (2.0 * steps)); + stepY = -1.0 * (hexHbase / (static_cast(steps))); + break; + case 1: + stepX = hexWbase / (2.0 * steps); + stepY = -1.0 * hexHbase / (static_cast(steps)); + break; + case 2: + stepX = hexWbase / static_cast(steps); + stepY = 0.0; + break; + case 3: + stepX = hexWbase / (2.0 * steps); + stepY = hexHbase / static_cast(steps); + break; + case 4: + stepX = -1.0 * hexWbase / (2.0 * steps); + stepY = hexHbase / static_cast(steps); + break; + case 5: + stepX = -1.0 * hexWbase / static_cast(steps); + stepY = 0.0; + break; + } + } + //step shifts calculated + + return true; +} + +void CMovementAnimation::nextFrame() +{ + //moving instructions + posX += stepX; + myAnim()->pos.x = static_cast(posX); + posY += stepY; + myAnim()->pos.y = static_cast(posY); + + // Increments step count and check if we are finished with current animation + ++whichStep; + if(whichStep == steps) + { + // Sets the position of the creature animation sprites + Point coords = CClickableHex::getXYUnitAnim(nextHex, owner->creDir[stack->ID], stack, owner); + myAnim()->pos = coords; + + // true if creature haven't reached the final destination hex + if ((nextPos + 1) < destTiles.size()) + { + // update the next hex field which has to be reached by the stack + nextPos++; + curStackPos = nextHex; + nextHex = destTiles[nextPos]; + + // update position of double wide creatures + bool twoTiles = stack->doubleWide(); + if(twoTiles && bool(stack->attackerOwned) && (owner->creDir[stack->ID] != bool(stack->attackerOwned) )) //big attacker creature is reversed + myAnim()->pos.x -= 44; + else if(twoTiles && (! bool(stack->attackerOwned) ) && (owner->creDir[stack->ID] != bool(stack->attackerOwned) )) //big defender creature is reversed + myAnim()->pos.x += 44; + + // re-init animation + for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + if (it->first == this) + { + it->second = false; + break; + } + } + } + else + endAnim(); + } +} + +void CMovementAnimation::endAnim() +{ + const CStack * movedStack = stack; + + CBattleAnimation::endAnim(); + + if(movedStack) + owner->addNewAnim(new CMovementEndAnimation(owner, stack, nextHex)); + + + if(owner->moveSh >= 0) + { + CCS->soundh->stopSound(owner->moveSh); + owner->moveSh = -1; + } + + delete this; +} + +CMovementAnimation::CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector _destTiles, int _distance) +: CBattleStackAnimation(_owner, _stack), destTiles(_destTiles), nextPos(0), distance(_distance), stepX(0.0), stepY(0.0) +{ + curStackPos = stack->position; + nextHex = destTiles.front(); +} + +CMovementEndAnimation::CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile) +: CBattleStackAnimation(_owner, _stack), destinationTile(destTile) +{} + +bool CMovementEndAnimation::init() +{ + if( !isEarliest(true) ) + return false; + + if(!stack || myAnim()->framesInGroup(CCreatureAnim::MOVE_END) == 0 || + myAnim()->getType() == CCreatureAnim::DEATH) + { + endAnim(); + + return false; + } + + CCS->soundh->playSound(battle_sound(stack->getCreature(), endMoving)); + + myAnim()->setType(CCreatureAnim::MOVE_END); + + return true; +} + +void CMovementEndAnimation::nextFrame() +{ + if(myAnim()->onLastFrameInGroup()) + { + endAnim(); + } +} + +void CMovementEndAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + + if(myAnim()->getType() != CCreatureAnim::DEATH) + myAnim()->setType(CCreatureAnim::HOLDING); //resetting to default + + CCS->curh->show(); + delete this; +} + +CMovementStartAnimation::CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack) +: CBattleStackAnimation(_owner, _stack) +{} + +bool CMovementStartAnimation::init() +{ + if( !isEarliest(false) ) + return false; + + + if(!stack || myAnim()->getType() == 5) + { + CMovementStartAnimation::endAnim(); + return false; + } + + CCS->soundh->playSound(battle_sound(stack->getCreature(), startMoving)); + myAnim()->setType(CCreatureAnim::MOVE_START); + + return true; +} + +void CMovementStartAnimation::nextFrame() +{ + if(myAnim()->onLastFrameInGroup()) + { + endAnim(); + } + else + { + if((owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0) + myAnim()->incrementFrame(); + } +} + +void CMovementStartAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + + delete this; +} + +CReverseAnimation::CReverseAnimation(CBattleInterface * _owner, const CStack * stack, BattleHex dest, bool _priority) +: CBattleStackAnimation(_owner, stack), partOfAnim(1), secondPartSetup(false), hex(dest), priority(_priority) +{} + +bool CReverseAnimation::init() +{ + if(myAnim() == NULL || myAnim()->getType() == 5) + { + endAnim(); + + return false; //there is no such creature + } + + if(!priority && !isEarliest(false)) + return false; + + if(myAnim()->framesInGroup(CCreatureAnim::TURN_R)) + myAnim()->setType(CCreatureAnim::TURN_R); + else + setupSecondPart(); + + + return true; +} + +void CReverseAnimation::nextFrame() +{ + if(partOfAnim == 1) //first part of animation + { + if(myAnim()->onLastFrameInGroup()) + { + partOfAnim = 2; + } + } + else if(partOfAnim == 2) + { + if(!secondPartSetup) + { + setupSecondPart(); + } + if(myAnim()->onLastFrameInGroup()) + { + endAnim(); + } + } +} + +void CReverseAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + if( stack->alive() )//don't do that if stack is dead + myAnim()->setType(CCreatureAnim::HOLDING); + + delete this; +} + +void CReverseAnimation::setupSecondPart() +{ + owner->creDir[stack->ID] = !owner->creDir[stack->ID]; + + if(!stack) + { + endAnim(); + return; + } + + Point coords = CClickableHex::getXYUnitAnim(hex, owner->creDir[stack->ID], stack, owner); + myAnim()->pos.x = coords.x; + //creAnims[stackID]->pos.y = coords.second; + + if(stack->doubleWide()) + { + if(stack->attackerOwned) + { + if(!owner->creDir[stack->ID]) + myAnim()->pos.x -= 44; + } + else + { + if(owner->creDir[stack->ID]) + myAnim()->pos.x += 44; + } + } + + secondPartSetup = true; + + if(myAnim()->framesInGroup(CCreatureAnim::TURN_L)) + myAnim()->setType(CCreatureAnim::TURN_L); + else + endAnim(); +} + +CShootingAnimation::CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked, bool _catapult, int _catapultDmg) +: CAttackAnimation(_owner, attacker, _dest, _attacked), catapultDamage(_catapultDmg), catapult(_catapult) +{} + +bool CShootingAnimation::init() +{ + if( !CAttackAnimation::checkInitialConditions() ) + return false; + + const CStack * shooter = attackingStack; + + if(!shooter || myAnim()->getType() == 5) + { + endAnim(); + return false; + } + + // Create the projectile animation + + double projectileAngle; //in radians; if positive, projectiles goes up + double straightAngle = 0.2; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value) + int fromHex = shooter->position; + projectileAngle = atan2(static_cast(abs(dest - fromHex) / GameConstants::BFIELD_WIDTH), static_cast(abs(dest - fromHex) % GameConstants::BFIELD_WIDTH)); + if(fromHex < dest) + projectileAngle = -projectileAngle; + + // Get further info about the shooter e.g. relative pos of projectile to unit. + // If the creature id is 149 then it's a arrow tower which has no additional info so get the + // actual arrow tower shooter instead. + const CCreature *shooterInfo = shooter->getCreature(); + if (shooterInfo->idNumber == 149) + { + int creID = CGI->creh->factionToTurretCreature[owner->siegeH->town->town->typeID]; + shooterInfo = CGI->creh->creatures[creID]; + } + + ProjectileInfo spi; + spi.creID = shooter->getCreature()->idNumber; + spi.stackID = shooter->ID; + spi.reverse = !shooter->attackerOwned; + + spi.step = 0; + spi.frameNum = 0; + if(vstd::contains(CGI->creh->idToProjectileSpin, shooterInfo->idNumber)) + spi.spin = CGI->creh->idToProjectileSpin[shooterInfo->idNumber]; + else + { + tlog2 << "Warning - no projectile spin for spi.creID " << shooterInfo->idNumber << std::endl; + spi.spin = false; + } + + Point xycoord = CClickableHex::getXYUnitAnim(shooter->position, true, shooter, owner); + Point destcoord; + + + // The "master" point where all projectile positions relate to. + static const Point projectileOrigin(181, 252); + + if (attackedStack) + { + destcoord = CClickableHex::getXYUnitAnim(dest, false, attackedStack, owner); + destcoord.x += 250; destcoord.y += 210; //TODO: find a better place to shoot + + // Calculate projectile start position. Offsets are read out of the CRANIM.TXT. + if (projectileAngle > straightAngle) + { + //upper shot + spi.x = xycoord.x + projectileOrigin.x + shooterInfo->upperRightMissleOffsetX; + spi.y = xycoord.y + projectileOrigin.y + shooterInfo->upperRightMissleOffsetY; + } + else if (projectileAngle < -straightAngle) + { + //lower shot + spi.x = xycoord.x + projectileOrigin.x + shooterInfo->lowerRightMissleOffsetX; + spi.y = xycoord.y + projectileOrigin.y + shooterInfo->lowerRightMissleOffsetY; + } + else + { + //straight shot + spi.x = xycoord.x + projectileOrigin.x + shooterInfo->rightMissleOffsetX; + spi.y = xycoord.y + projectileOrigin.y + shooterInfo->rightMissleOffsetY; + } + + double animSpeed = 23.0 * owner->getAnimSpeed(); // flight speed of projectile + spi.lastStep = static_cast(sqrt(static_cast((destcoord.x - spi.x) * (destcoord.x - spi.x) + (destcoord.y - spi.y) * (destcoord.y - spi.y))) / animSpeed); + if(spi.lastStep == 0) + spi.lastStep = 1; + spi.dx = (destcoord.x - spi.x) / spi.lastStep; + spi.dy = (destcoord.y - spi.y) / spi.lastStep; + spi.catapultInfo = 0; + } + else + { + // Catapult attack + // These are the values for equations of this kind: f(x) = ax^2 + bx + c + static const std::vector trajectoryCurves = boost::assign::list_of(new CatapultProjectileInfo(4.309, -3.198, 569.2, -296, 182)) + (new CatapultProjectileInfo(4.710, -3.11, 558.68, -258, 175))(new CatapultProjectileInfo(5.056, -3.003, 546.9, -236, 174)) + (new CatapultProjectileInfo(4.760, -2.74, 526.47, -216, 215))(new CatapultProjectileInfo(4.288, -2.496, 508.98, -223, 274)) + (new CatapultProjectileInfo(3.683, -3.018, 558.39, -324, 176))(new CatapultProjectileInfo(2.884, -2.607, 528.95, -366, 312)) + (new CatapultProjectileInfo(3.783, -2.364, 501.35, -227, 318)); + + static std::map hexToCurve = boost::assign::map_list_of(29, 0)(62, 1)(95, 2)(130, 3)(182, 4)(12, 5)(50, 6)(183, 7); + + std::map::iterator it = hexToCurve.find(dest.hex); + + if (it == hexToCurve.end()) + { + tlog1 << "For the hex position " << dest.hex << " is no curve defined."; + endAnim(); + return false; + } + else + { + int curveID = it->second; + spi.catapultInfo = trajectoryCurves[curveID]; + double animSpeed = 3.318 * owner->getAnimSpeed(); + spi.lastStep = static_cast((spi.catapultInfo->toX - spi.catapultInfo->fromX) / animSpeed); + spi.dx = animSpeed; + spi.dy = 0; + spi.x = xycoord.x + projectileOrigin.x + shooterInfo->rightMissleOffsetX + 17.; + spi.y = xycoord.y + projectileOrigin.y + shooterInfo->rightMissleOffsetY + 10.; + + // Add explosion anim + int xEnd = static_cast(spi.x + spi.lastStep * spi.dx); + int yEnd = static_cast(spi.catapultInfo->calculateY(xEnd)); + owner->addNewAnim( new CSpellEffectAnimation(owner, "SGEXPL.DEF", xEnd - 126, yEnd - 105)); + } + } + + // Set starting frame + if(spi.spin) + { + spi.frameNum = 0; + } + else + { + double pi = boost::math::constants::pi(); + spi.frameNum = static_cast(((pi / 2.0 - projectileAngle) / (2.0 * pi) + 1/(static_cast(2*(owner->idToProjectile[spi.creID]->ourImages.size()-1)))) * (owner->idToProjectile[spi.creID]->ourImages.size()-1)); + } + + // Set projectile animation start delay which is specified in frames + spi.animStartDelay = shooterInfo->attackClimaxFrame; + owner->projectiles.push_back(spi); + + //attack animation + + shooting = true; + + if(projectileAngle > straightAngle) //upper shot + group = CCreatureAnim::SHOOT_UP; + else if(projectileAngle < -straightAngle) //lower shot + group = CCreatureAnim::SHOOT_DOWN; + else //straight shot + group = CCreatureAnim::SHOOT_FRONT; + + return true; +} + +void CShootingAnimation::nextFrame() +{ + for(std::list >::const_iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) + { + CMovementStartAnimation * anim = dynamic_cast(it->first); + CReverseAnimation * anim2 = dynamic_cast(it->first); + if( (anim && anim->stack->ID == stack->ID) || (anim2 && anim2->stack->ID == stack->ID && anim2->priority ) ) + return; + } + + CAttackAnimation::nextFrame(); +} + +void CShootingAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + delete this; +} + +CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, BattleHex _destTile, int _dx, int _dy, bool _Vflip) +:CBattleAnimation(_owner), effect(_effect), destTile(_destTile), customAnim(""), dx(_dx), dy(_dy), Vflip(_Vflip) +{} + +CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx, int _dy, bool _Vflip) +:CBattleAnimation(_owner), effect(-1), destTile(0), customAnim(_customAnim), x(_x), y(_y), dx(_dx), dy(_dy), Vflip(_Vflip) +{} + +bool CSpellEffectAnimation::init() +{ + if(!isEarliest(true)) + return false; + + if(effect == 12) //armageddon + { + if(effect == -1 || graphics->battleACToDef[effect].size() != 0) + { + CDefHandler * anim; + if(customAnim.size()) + anim = CDefHandler::giveDef(customAnim); + else + anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); + + if (Vflip) + { + for (size_t v = 0; v < anim->ourImages.size(); ++v) + { + CSDL_Ext::VflipSurf(anim->ourImages[v].bitmap); + } + } + + for(int i=0; i * anim->width < owner->pos.w ; ++i) + { + for(int j=0; j * anim->height < owner->pos.h ; ++j) + { + BattleEffect be; + be.effectID = ID; + be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); + if (Vflip) + { + for (size_t v = 0; v < be.anim->ourImages.size(); ++v) + { + CSDL_Ext::VflipSurf(be.anim->ourImages[v].bitmap); + } + } + be.frame = 0; + be.maxFrame = be.anim->ourImages.size(); + be.x = i * anim->width + owner->pos.x; + be.y = j * anim->height + owner->pos.y; + + owner->battleEffects.push_back(be); + } + } + } + else //there is nothing to play + { + endAnim(); + return false; + } + } + else // Effects targeted at a specific creature/hex. + { + if(effect == -1 || graphics->battleACToDef[effect].size() != 0) + { + const CStack* destStack = owner->curInt->cb->battleGetStackByPos(destTile, false); + Rect &tilePos = owner->bfield[destTile].pos; + BattleEffect be; + be.effectID = ID; + if(customAnim.size()) + be.anim = CDefHandler::giveDef(customAnim); + else + be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); + + if (Vflip) + { + for (size_t v = 0; v < be.anim->ourImages.size(); ++v) + { + CSDL_Ext::VflipSurf(be.anim->ourImages[v].bitmap); + } + } + + be.frame = 0; + be.maxFrame = be.anim->ourImages.size(); + if(effect == 1) + be.maxFrame = 3; + + switch (effect) + { + case -1: + be.x = x; + be.y = y; + break; + case 0: // Prayer and Lightning Bolt. + case 1: + // Position effect with it's bottom center touching the bottom center of affected tile(s). + be.x = tilePos.x + tilePos.w/2 - be.anim->width/2; + be.y = tilePos.y + tilePos.h - be.anim->height; + break; + + default: + // Position effect with it's center touching the top center of affected tile(s). + be.x = tilePos.x + tilePos.w/2 - be.anim->width/2; + be.y = tilePos.y - be.anim->height/2; + break; + } + + // Correction for 2-hex creatures. + if (destStack != NULL && destStack->doubleWide()) + be.x += (destStack->attackerOwned ? -1 : 1)*tilePos.w/2; + + owner->battleEffects.push_back(be); + } + else //there is nothing to play + { + endAnim(); + return false; + } + } + //battleEffects + return true; +} + +void CSpellEffectAnimation::nextFrame() +{ + //notice: there may be more than one effect in owner->battleEffects correcponding to this animation (ie. armageddon) + for(std::list::iterator it = owner->battleEffects.begin(); it != owner->battleEffects.end(); ++it) + { + if(it->effectID == ID) + { + ++(it->frame); + + if(it->frame == it->maxFrame) + { + endAnim(); + break; + } + else + { + it->x += dx; + it->y += dy; + } + } + } +} + +void CSpellEffectAnimation::endAnim() +{ + CBattleAnimation::endAnim(); + + std::vector::iterator> toDel; + + for(std::list::iterator it = owner->battleEffects.begin(); it != owner->battleEffects.end(); ++it) + { + if(it->effectID == ID) + { + toDel.push_back(it); + } + } + + for(size_t b = 0; b < toDel.size(); ++b) + { + delete toDel[b]->anim; + owner->battleEffects.erase(toDel[b]); + } + + delete this; +} \ No newline at end of file diff --git a/client/BattleInterface/CBattleAnimations.h b/client/BattleInterface/CBattleAnimations.h new file mode 100644 index 000000000..3254ca626 --- /dev/null +++ b/client/BattleInterface/CBattleAnimations.h @@ -0,0 +1,221 @@ +#pragma once + +#include "../CAnimation.h" +#include "../../lib/BattleHex.h" + +class CBattleInterface; +class CStack; +class CCreatureAnimation; +struct CatapultProjectileInfo; +struct StackAttackedInfo; + +/* + * CBattleAnimations.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Base class of battle animations +class CBattleAnimation +{ +protected: + CBattleInterface * owner; +public: + virtual bool init()=0; //to be called - if returned false, call again until returns true + virtual void nextFrame()=0; //call every new frame + virtual void endAnim(); //to be called mostly internally; in this class it removes animation from pendingAnims list + + bool isEarliest(bool perStackConcurrency); //determines if this animation is earliest of all + + ui32 ID; //unique identifier + + CBattleAnimation(CBattleInterface * _owner); +}; + +/// Sub-class which is responsible for managing the battle stack animation. +class CBattleStackAnimation : public CBattleAnimation +{ +public: + const CStack * stack; //id of stack whose animation it is + + CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack); + + static bool isToReverseHlp(BattleHex hexFrom, BattleHex hexTo, bool curDir); //helper for isToReverse + static bool isToReverse(BattleHex hexFrom, BattleHex hexTo, bool curDir /*if true, creature is in attacker's direction*/, bool toDoubleWide, bool toDir); //determines if creature should be reversed (it stands on hexFrom and should 'see' hexTo) + + CCreatureAnimation * myAnim(); //animation for our stack +}; + +/// This class is responsible for managing the battle attack animation +class CAttackAnimation : public CBattleStackAnimation +{ +protected: + BattleHex dest; //attacked hex + bool shooting; + CCreatureAnim::EAnimType group; //if shooting is true, print this animation group + const CStack *attackedStack; + const CStack *attackingStack; + int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature +public: + void nextFrame(); + bool checkInitialConditions(); + + CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender); +}; + +/// Animation of a defending unit +class CDefenceAnimation : public CBattleStackAnimation +{ +private: + //std::vector attackedInfos; + int dmg; //damage dealt + int amountKilled; //how many creatures in stack has been killed + const CStack * attacker; //attacking stack + bool byShooting; //if true, stack has been attacked by shooting + bool killed; //if true, stack has been killed +public: + bool init(); + void nextFrame(); + void endAnim(); + + CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner); +}; + +class CDummyAnimation : public CBattleAnimation +{ +private: + int counter; + int howMany; +public: + bool init(); + void nextFrame(); + void endAnim(); + + CDummyAnimation(CBattleInterface * _owner, int howManyFrames); +}; + +/// Hand-to-hand attack +class CMeleeAttackAnimation : public CAttackAnimation +{ +public: + bool init(); + void nextFrame(); + void endAnim(); + + CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked); +}; + +/// Move animation of a creature +class CMovementAnimation : public CBattleStackAnimation +{ +private: + std::vector destTiles; //destination + BattleHex nextHex; + ui32 nextPos; + int distance; + double stepX, stepY; //how far stack is moved in one frame + double posX, posY; + int steps, whichStep; + int curStackPos; //position of stack before move +public: + bool init(); + void nextFrame(); + void endAnim(); + + CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector _destTiles, int _distance); +}; + +/// Move end animation of a creature +class CMovementEndAnimation : public CBattleStackAnimation +{ +private: + BattleHex destinationTile; +public: + bool init(); + void nextFrame(); + void endAnim(); + + CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile); +}; + +/// Move start animation of a creature +class CMovementStartAnimation : public CBattleStackAnimation +{ +public: + bool init(); + void nextFrame(); + void endAnim(); + + CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack); +}; + +/// Class responsible for animation of stack chaning direction (left <-> right) +class CReverseAnimation : public CBattleStackAnimation +{ +private: + int partOfAnim; //1 - first, 2 - second + bool secondPartSetup; + BattleHex hex; +public: + bool priority; //true - high, false - low + bool init(); + void nextFrame(); + + void setupSecondPart(); + void endAnim(); + + CReverseAnimation(CBattleInterface * _owner, const CStack * stack, BattleHex dest, bool _priority); +}; + +/// Small struct which contains information about the position and the velocity of a projectile +struct ProjectileInfo +{ + double x, y; //position on the screen + double 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 stackID; //ID of stack + 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) + bool reverse; //if true, projectile will be flipped by vertical asix + CatapultProjectileInfo * catapultInfo; // holds info about the parabolic trajectory of the cannon +}; + +/// Shooting attack +class CShootingAnimation : public CAttackAnimation +{ +private: + int catapultDamage; + bool catapult; +public: + bool init(); + void nextFrame(); + void endAnim(); + + //last two params only for catapult attacks + CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, + const CStack * _attacked, bool _catapult = false, int _catapultDmg = 0); +}; + +/// This class manages a spell effect animation +class CSpellEffectAnimation : public CBattleAnimation +{ +private: + ui32 effect; + BattleHex destTile; + std::string customAnim; + int x, y, dx, dy; + bool Vflip; +public: + bool init(); + void nextFrame(); + void endAnim(); + + CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, BattleHex _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false); + CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false); +}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleConsole.cpp b/client/BattleInterface/CBattleConsole.cpp deleted file mode 100644 index c147fd4a3..000000000 --- a/client/BattleInterface/CBattleConsole.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "StdInc.h" -#include "CBattleConsole.h" -#include "../SDL_Extensions.h" - -CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt(""), whoSetAlter(0) -{ -} - -CBattleConsole::~CBattleConsole() -{ - texts.clear(); -} - -void CBattleConsole::show(SDL_Surface * to) -{ - if(ingcAlter.size()) - { - CSDL_Ext::printAtMiddleWB(ingcAlter, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); - } - else if(alterTxt.size()) - { - CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); - } - else if(texts.size()) - { - if(texts.size()==1) - { - CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); - } - else - { - CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to); - CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 27, FONT_SMALL, 80, zwykly, to); - } - } -} - -bool CBattleConsole::addText(const std::string & text) -{ - if(text.size()>70) - return false; //text too long! - int firstInToken = 0; - for(size_t i = 0; i < text.size(); ++i) //tokenize - { - if(text[i] == 10) - { - texts.push_back( text.substr(firstInToken, i-firstInToken) ); - firstInToken = i+1; - } - } - - texts.push_back( text.substr(firstInToken, text.size()) ); - lastShown = texts.size()-1; - return true; -} - -void CBattleConsole::eraseText(ui32 pos) -{ - if(pos < texts.size()) - { - texts.erase(texts.begin() + pos); - if(lastShown == texts.size()) - --lastShown; - } -} - -void CBattleConsole::changeTextAt(const std::string & text, ui32 pos) -{ - if(pos >= texts.size()) //no such pos - return; - texts[pos] = text; -} - -void CBattleConsole::scrollUp(ui32 by) -{ - if(lastShown > static_cast(by)) - lastShown -= by; -} - -void CBattleConsole::scrollDown(ui32 by) -{ - if(lastShown + by < texts.size()) - lastShown += by; -} \ No newline at end of file diff --git a/client/BattleInterface/CBattleConsole.h b/client/BattleInterface/CBattleConsole.h deleted file mode 100644 index 9971b0ab9..000000000 --- a/client/BattleInterface/CBattleConsole.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "../UIFramework/CIntObject.h" - -struct SDL_Surface; - -/* - * CBattleConsole.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Class which shows the console at the bottom of the battle screen and manages the text of the console -class CBattleConsole : public CIntObject -{ -private: - std::vector< std::string > texts; //a place where texts are stored - int lastShown; //last shown line of text -public: - std::string alterTxt; //if it's not empty, this text is displayed - std::string ingcAlter; //alternative text set by in-game console - very important! - int whoSetAlter; //who set alter text; 0 - battle interface or none, 1 - button - CBattleConsole(); //c-tor - ~CBattleConsole(); //d-tor - void show(SDL_Surface *to = 0); - bool addText(const std::string &text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters) - void eraseText(ui32 pos); //erases added text at position pos - void changeTextAt(const std::string &text, ui32 pos); //if we have more than pos texts, pos-th is changed to given one - void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions - void scrollDown(ui32 by = 1); //scrolls console up by 'by' positions -}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleHero.cpp b/client/BattleInterface/CBattleHero.cpp deleted file mode 100644 index 2b7093e0b..000000000 --- a/client/BattleInterface/CBattleHero.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include "StdInc.h" -#include "CBattleHero.h" -#include "CBattleInterface.h" -#include "../CGameInfo.h" -#include "../CDefHandler.h" -#include "../CCursorHandler.h" -#include "../CPlayerInterface.h" -#include "../../CCallback.h" -#include "../SDL_Extensions.h" -#include "../CSpellWindow.h" -#include "../Graphics.h" -#include "../CConfigHandler.h" -#include "../UIFramework/CGuiHandler.h" - -void CBattleHero::show(SDL_Surface *to) -{ - //animation of flag - if(flip) - { - SDL_Rect temp_rect = genRect( - flag->ourImages[flagAnim].bitmap->h, - flag->ourImages[flagAnim].bitmap->w, - pos.x + 61, - pos.y + 39); - CSDL_Ext::blit8bppAlphaTo24bpp( - flag->ourImages[flagAnim].bitmap, - NULL, - screen, - &temp_rect); - } - else - { - SDL_Rect temp_rect = genRect( - flag->ourImages[flagAnim].bitmap->h, - flag->ourImages[flagAnim].bitmap->w, - pos.x + 72, - pos.y + 39); - CSDL_Ext::blit8bppAlphaTo24bpp( - flag->ourImages[flagAnim].bitmap, - NULL, - screen, - &temp_rect); - } - ++flagAnimCount; - if(flagAnimCount%4==0) - { - ++flagAnim; - flagAnim %= flag->ourImages.size(); - } - //animation of hero - int tick=-1; - for(size_t i = 0; i < dh->ourImages.size(); ++i) - { - if(dh->ourImages[i].groupNumber==phase) - ++tick; - if(tick==image) - { - SDL_Rect posb = pos; - CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb); - if(phase != 4 || nextPhase != -1 || image < 4) - { - if(flagAnimCount%2==0) - { - ++image; - } - if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame - { - image = 0; - } - } - if(phase == 4 && nextPhase != -1 && image == 7) - { - phase = nextPhase; - nextPhase = -1; - image = 0; - } - break; - } - } -} - -void CBattleHero::activate() -{ - activateLClick(); -} -void CBattleHero::deactivate() -{ - deactivateLClick(); -} - -void CBattleHero::setPhase(int newPhase) -{ - if(phase != 4) - { - phase = newPhase; - image = 0; - } - else - { - nextPhase = newPhase; - } -} - -void CBattleHero::clickLeft(tribool down, bool previousState) -{ - if(myOwner->spellDestSelectMode) //we are casting a spell - return; - - if(!down && myHero != NULL && myOwner->myTurn && myOwner->curInt->cb->battleCanCastSpell()) //check conditions - { - for(int it=0; itbfield[it].hovered && myOwner->bfield[it].strictHovered) - return; - } - CCS->curh->changeGraphic(0,0); - - CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), myHero, myOwner->curInt); - GH.pushInt(spellWindow); - } -} - -CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, ui8 player, const CGHeroInstance * hero, const CBattleInterface * owner): flip(flipG), myHero(hero), myOwner(owner), phase(phaseG), nextPhase(-1), image(imageG), flagAnim(0), flagAnimCount(0) -{ - dh = CDefHandler::giveDef( defName ); - for(size_t i = 0; i < dh->ourImages.size(); ++i) //transforming images - { - if(flip) - { - SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap); - SDL_FreeSurface(dh->ourImages[i].bitmap); - dh->ourImages[i].bitmap = hlp; - } - CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap); - } - - if(flip) - flag = CDefHandler::giveDef("CMFLAGR.DEF"); - else - flag = CDefHandler::giveDef("CMFLAGL.DEF"); - - //coloring flag and adding transparency - for(size_t i = 0; i < flag->ourImages.size(); ++i) - { - CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap); - graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player); - } -} - -CBattleHero::~CBattleHero() -{ - delete dh; - delete flag; -} \ No newline at end of file diff --git a/client/BattleInterface/CBattleHero.h b/client/BattleInterface/CBattleHero.h deleted file mode 100644 index c207a0ce9..000000000 --- a/client/BattleInterface/CBattleHero.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "../UIFramework/CIntObject.h" - -class CBattleInterface; -class CDefHandler; -class CGHeroInstance; -struct SDL_Surface; - -/* - * CBattleHero.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Hero battle animation -class CBattleHero : public CIntObject -{ -public: - bool flip; //false if it's attacking hero, true otherwise - CDefHandler *dh, *flag; //animation and flag - const CGHeroInstance *myHero; //this animation's hero instance - const CBattleInterface *myOwner; //battle interface to which this animation is assigned - int phase; //stage of animation - int nextPhase; //stage of animation to be set after current phase is fully displayed - int image; //frame of animation - ui8 flagAnim, flagAnimCount; //for flag animation - void show(SDL_Surface *to); //prints next frame of animation to to - void activate(); - void deactivate(); - void setPhase(int newPhase); //sets phase of hero animation - void clickLeft(tribool down, bool previousState); //call-in - CBattleHero(const std::string &defName, int phaseG, int imageG, bool filpG, ui8 player, const CGHeroInstance *hero, const CBattleInterface *owner); //c-tor - ~CBattleHero(); //d-tor -}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleInterface.cpp b/client/BattleInterface/CBattleInterface.cpp index b14c5a7e6..85e41cded 100644 --- a/client/BattleInterface/CBattleInterface.cpp +++ b/client/BattleInterface/CBattleInterface.cpp @@ -3,9 +3,8 @@ #include "../CGameInfo.h" #include "../../lib/CLodHandler.h" -#include "../SDL_Extensions.h" +#include "../UIFramework/SDL_Extensions.h" #include "../CAdvmapInterface.h" -#include "../AdventureMapButton.h" #include "../CAnimation.h" #include "../../lib/CObjectHandler.h" #include "../../lib/CHeroHandler.h" @@ -13,7 +12,6 @@ #include "../../lib/CSpellHandler.h" #include "../CMusicHandler.h" #include "../CMessage.h" -#include "../CCursorHandler.h" #include "../../CCallback.h" #include "../../lib/BattleState.h" #include "../../lib/CGeneralTextHandler.h" @@ -29,23 +27,10 @@ #include "../../lib/CTownHandler.h" #include "../../lib/map.h" -#include "CBattleHero.h" -#include "CStackQueue.h" -#include "CBattleConsole.h" -#include "CBattleResultWindow.h" -#include "CBattleAnimation.h" -#include "CBattleOptionsWindow.h" -#include "CDummyAnimation.h" -#include "CClickableHex.h" -#include "CShootingAnimation.h" -#include "CSpellEffectAnimation.h" -#include "CMeleeAttackAnimation.h" -#include "CReverseAnimation.h" -#include "CMovementStartAnimation.h" -#include "CMovementEndAnimation.h" -#include "CDefenceAnimation.h" -#include "CMovementAnimation.h" +#include "CBattleAnimations.h" +#include "CBattleInterfaceClasses.h" +#include "../UIFramework/CCursorHandler.h" #include "../UIFramework/CGuiHandler.h" #ifndef __GNUC__ @@ -69,7 +54,6 @@ const time_t CBattleInterface::HOVER_ANIM_DELTA = 1; */ extern SDL_Surface * screen; -extern SDL_Color zwykly; CondSh CBattleInterface::animsAreDisplayed; @@ -109,7 +93,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe activeStack(NULL), stackToActivate(NULL), mouseHoveredStack(-1), lastMouseHoveredStackAnimationTime(-1), previouslyHoveredHex(-1), currentlyHoveredHex(-1), attackingHex(-1), tacticianInterface(NULL), stackCanCastSpell(false), spellDestSelectMode(false), spellSelMode(NO_LOCATION), spellToCast(NULL), siegeH(NULL), attackerInt(att), defenderInt(defen), curInt(att), animIDhelper(0), givenCommand(NULL), - myTurn(false), resWindow(NULL), moveStarted(false), moveSh(-1), bresult(NULL) + myTurn(false), resWindow(NULL), moveStarted(false), moveSh(-1), bresult(NULL), bfield(GameConstants::BFIELD_SIZE) { OBJ_CONSTRUCTION; @@ -136,7 +120,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe if(curInt->sysOpts.showQueue) pos.y += queue->pos.h / 2; //center whole window - queue->moveTo(SPoint(pos.x, pos.y - queue->pos.h)); + queue->moveTo(Point(pos.x, pos.y - queue->pos.h)); // queue->pos.x = pos.x; // queue->pos.y = pos.y - queue->pos.h; // pos.h += queue->pos.h; @@ -173,7 +157,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe SDL_Surface * moat = BitmapHandler::loadBitmap( siegeH->getSiegeName(13) ), * mlip = BitmapHandler::loadBitmap( siegeH->getSiegeName(14) ); - SPoint moatPos = graphics->wallPositions[siegeH->town->town->typeID][12], + Point moatPos = graphics->wallPositions[siegeH->town->town->typeID][12], mlipPos = graphics->wallPositions[siegeH->town->town->typeID][13]; if(moat) //eg. tower has no moat @@ -216,19 +200,19 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe // blitAt(menu, pos.x, 556 + pos.y); //preparing buttons and console - bOptions = new AdventureMapButton (CGI->generaltexth->zelp[381].first, CGI->generaltexth->zelp[381].second, boost::bind(&CBattleInterface::bOptionsf,this), 3 + pos.x, 561 + pos.y, "icm003.def", SDLK_o); - bSurrender = new AdventureMapButton (CGI->generaltexth->zelp[379].first, CGI->generaltexth->zelp[379].second, boost::bind(&CBattleInterface::bSurrenderf,this), 54 + pos.x, 561 + pos.y, "icm001.def", SDLK_s); - bFlee = new AdventureMapButton (CGI->generaltexth->zelp[380].first, CGI->generaltexth->zelp[380].second, boost::bind(&CBattleInterface::bFleef,this), 105 + pos.x, 561 + pos.y, "icm002.def", SDLK_r); + bOptions = new CAdventureMapButton (CGI->generaltexth->zelp[381].first, CGI->generaltexth->zelp[381].second, boost::bind(&CBattleInterface::bOptionsf,this), 3 + pos.x, 561 + pos.y, "icm003.def", SDLK_o); + bSurrender = new CAdventureMapButton (CGI->generaltexth->zelp[379].first, CGI->generaltexth->zelp[379].second, boost::bind(&CBattleInterface::bSurrenderf,this), 54 + pos.x, 561 + pos.y, "icm001.def", SDLK_s); + bFlee = new CAdventureMapButton (CGI->generaltexth->zelp[380].first, CGI->generaltexth->zelp[380].second, boost::bind(&CBattleInterface::bFleef,this), 105 + pos.x, 561 + pos.y, "icm002.def", SDLK_r); bFlee->block(!curInt->cb->battleCanFlee()); bSurrender->block(curInt->cb->battleGetSurrenderCost() < 0); - bAutofight = new AdventureMapButton (CGI->generaltexth->zelp[382].first, CGI->generaltexth->zelp[382].second, boost::bind(&CBattleInterface::bAutofightf,this), 157 + pos.x, 561 + pos.y, "icm004.def", SDLK_a); - bSpell = new AdventureMapButton (CGI->generaltexth->zelp[385].first, CGI->generaltexth->zelp[385].second, boost::bind(&CBattleInterface::bSpellf,this), 645 + pos.x, 561 + pos.y, "icm005.def", SDLK_c); + bAutofight = new CAdventureMapButton (CGI->generaltexth->zelp[382].first, CGI->generaltexth->zelp[382].second, boost::bind(&CBattleInterface::bAutofightf,this), 157 + pos.x, 561 + pos.y, "icm004.def", SDLK_a); + bSpell = new CAdventureMapButton (CGI->generaltexth->zelp[385].first, CGI->generaltexth->zelp[385].second, boost::bind(&CBattleInterface::bSpellf,this), 645 + pos.x, 561 + pos.y, "icm005.def", SDLK_c); bSpell->block(true); - bWait = new AdventureMapButton (CGI->generaltexth->zelp[386].first, CGI->generaltexth->zelp[386].second, boost::bind(&CBattleInterface::bWaitf,this), 696 + pos.x, 561 + pos.y, "icm006.def", SDLK_w); - bDefence = new AdventureMapButton (CGI->generaltexth->zelp[387].first, CGI->generaltexth->zelp[387].second, boost::bind(&CBattleInterface::bDefencef,this), 747 + pos.x, 561 + pos.y, "icm007.def", SDLK_d); + bWait = new CAdventureMapButton (CGI->generaltexth->zelp[386].first, CGI->generaltexth->zelp[386].second, boost::bind(&CBattleInterface::bWaitf,this), 696 + pos.x, 561 + pos.y, "icm006.def", SDLK_w); + bDefence = new CAdventureMapButton (CGI->generaltexth->zelp[387].first, CGI->generaltexth->zelp[387].second, boost::bind(&CBattleInterface::bDefencef,this), 747 + pos.x, 561 + pos.y, "icm007.def", SDLK_d); bDefence->assignedKeys.insert(SDLK_SPACE); - bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624 + pos.x, 561 + pos.y, "ComSlide.def", SDLK_UP); - bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624 + pos.x, 580 + pos.y, "ComSlide.def", SDLK_DOWN); + bConsoleUp = new CAdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624 + pos.x, 561 + pos.y, "ComSlide.def", SDLK_UP); + bConsoleDown = new CAdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624 + pos.x, 580 + pos.y, "ComSlide.def", SDLK_DOWN); bConsoleDown->setOffset(2); console = new CBattleConsole(); console->pos.x = 211 + pos.x; @@ -237,8 +221,8 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe console->pos.h = 38; if(tacticsMode) { - btactNext = new AdventureMapButton(std::string(), std::string(), boost::bind(&CBattleInterface::bTacticNextStack,this), 213 + pos.x, 560 + pos.y, "icm011.def", SDLK_SPACE); - btactEnd = new AdventureMapButton(std::string(), std::string(), boost::bind(&CBattleInterface::bEndTacticPhase,this), 419 + pos.x, 560 + pos.y, "icm012.def", SDLK_RETURN); + btactNext = new CAdventureMapButton(std::string(), std::string(), boost::bind(&CBattleInterface::bTacticNextStack,this), 213 + pos.x, 560 + pos.y, "icm011.def", SDLK_SPACE); + btactEnd = new CAdventureMapButton(std::string(), std::string(), boost::bind(&CBattleInterface::bEndTacticPhase,this), 419 + pos.x, 560 + pos.y, "icm012.def", SDLK_RETURN); bDefence->block(true); bWait->block(true); menu = BitmapHandler::loadBitmap("COPLACBR.BMP"); @@ -281,7 +265,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe CSDL_Ext::alphaTransform(cellBorder); cellShade = BitmapHandler::loadBitmap("CCELLSHD.BMP"); CSDL_Ext::alphaTransform(cellShade); - for(int h = 0; h < ARRAY_COUNT(bfield); ++h) + for(int h = 0; h < bfield.size(); ++h) { bfield[h].myNumber = h; @@ -362,7 +346,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe } } - for (int i = 0; i < ARRAY_COUNT(bfield); i++) + for (int i = 0; i < bfield.size(); i++) { children.push_back(&bfield[i]); } @@ -603,8 +587,8 @@ void CBattleInterface::show(SDL_Surface * to) {//TODO: do not check it every frame if (activeStack) //highlight all attackable hexes { - std::set set = curInt->cb->battleGetAttackedHexes(activeStack, currentlyHoveredHex, attackingHex); - BOOST_FOREACH(SBattleHex hex, set) + std::set set = curInt->cb->battleGetAttackedHexes(activeStack, currentlyHoveredHex, attackingHex); + BOOST_FOREACH(BattleHex hex, set) { int x = 14 + ((hex/GameConstants::BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(hex%GameConstants::BFIELD_WIDTH) + pos.x; int y = 86 + 42 * (hex/GameConstants::BFIELD_WIDTH) + pos.y; @@ -630,10 +614,10 @@ void CBattleInterface::show(SDL_Surface * to) //preparing obstacles to be shown std::vector obstacles = curInt->cb->battleGetAllObstacles(); - std::multimap hexToObstacle; + std::multimap hexToObstacle; for(size_t b = 0; b < obstacles.size(); ++b) { - SBattleHex position = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getMaxBlocked(obstacles[b].pos); + BattleHex position = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getMaxBlocked(obstacles[b].pos); hexToObstacle.insert(std::make_pair(position, b)); } @@ -713,7 +697,6 @@ void CBattleInterface::show(SDL_Surface * to) { showAliveStacks(stackAliveByHex, b, &flyingStacks, to); showObstacles(&hexToObstacle, obstacles, b, to); - showPieceOfWall(to, b, stacks); } } // Siege drawing @@ -802,7 +785,7 @@ void CBattleInterface::show(SDL_Surface * to) //showing spell effects if(battleEffects.size()) { - for(std::list::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it) + for(std::list::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it) { SDL_Surface * bitmapToBlit = it->anim->ourImages[(it->frame)%it->anim->ourImages.size()].bitmap; SDL_Rect temp_rect = genRect(bitmapToBlit->h, bitmapToBlit->w, it->x, it->y); @@ -845,7 +828,7 @@ void CBattleInterface::show(SDL_Surface * to) //showing in-game console LOCPLINT->cingconsole->show(to); - SRect posWithQueue = SRect(pos.x, pos.y, 800, 600); + Rect posWithQueue = Rect(pos.x, pos.y, 800, 600); if(curInt->sysOpts.showQueue) { @@ -891,12 +874,12 @@ void CBattleInterface::showAliveStacks(std::vector *aliveStacks, } } -void CBattleInterface::showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to) +void CBattleInterface::showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to) { - std::pair::const_iterator, std::multimap::const_iterator> obstRange = + std::pair::const_iterator, std::multimap::const_iterator> obstRange = hexToObstacle->equal_range(hex); - for(std::multimap::const_iterator it = obstRange.first; it != obstRange.second; ++it) + for(std::multimap::const_iterator it = obstRange.first; it != obstRange.second; ++it) { CObstacleInstance & curOb = obstacles[it->second]; std::pair shift = CGI->heroh->obstacles.find(curOb.ID)->second.posShift; @@ -963,7 +946,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) if ((int)creatureSpellToCast > -1) //use randomized spell (Faerie Dragon), or only avaliable spell (Archangel) { const CSpell * spell = CGI->spellh->spells[creatureSpellToCast]; - if (curInt->cb->battleCanCastThisSpell(spell, SBattleHex(myNumber)) == ESpellCastProblem::OK) + if (curInt->cb->battleCanCastThisSpell(spell, BattleHex(myNumber)) == ESpellCastProblem::OK) { if ((spell->positiveness > -1 && ourStack) || (spell->positiveness < 1 && !ourStack)) { @@ -1368,7 +1351,7 @@ void CBattleInterface::setBattleCursor(const int myNumber) attackingHex = myNumber + GameConstants::BFIELD_WIDTH - 1 + zigzagCorrection; //bottom left break; } - SBattleHex hex(attackingHex); + BattleHex hex(attackingHex); if (!hex.isValid()) attackingHex = -1; } @@ -1388,7 +1371,7 @@ void CBattleInterface::bOptionsf() CCS->curh->changeGraphic(0,0); - SRect tempRect = genRect(431, 481, 160, 84); + Rect tempRect = genRect(431, 481, 160, 84); tempRect += pos.topLeft(); CBattleOptionsWindow * optionsWin = new CBattleOptionsWindow(tempRect, this); GH.pushInt(optionsWin); @@ -1405,7 +1388,7 @@ void CBattleInterface::bSurrenderf() const CGHeroInstance *opponent = curInt->cb->battleGetFightingHero(1); std::string enemyHeroName = opponent ? opponent->name : "#ENEMY#"; //TODO: should surrendering without enemy hero be enabled? std::string surrenderMessage = boost::str(boost::format(CGI->generaltexth->allTexts[32]) % enemyHeroName % cost); //%s states: "I will accept your surrender and grant you and your troops safe passage for the price of %d gold." - curInt->showYesNoDialog(surrenderMessage, std::vector(), boost::bind(&CBattleInterface::reallySurrender,this), 0, false); + curInt->showYesNoDialog(surrenderMessage, std::vector(), boost::bind(&CBattleInterface::reallySurrender,this), 0, false); } } @@ -1417,11 +1400,11 @@ void CBattleInterface::bFleef() if( curInt->cb->battleCanFlee() ) { CFunctionList ony = boost::bind(&CBattleInterface::reallyFlee,this); - curInt->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector(), ony, 0, false); //Are you sure you want to retreat? + curInt->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector(), ony, 0, false); //Are you sure you want to retreat? } else { - std::vector comps; + std::vector comps; std::string heroName; //calculating fleeing hero's name if(attackingHeroInstance) @@ -1516,7 +1499,7 @@ void CBattleInterface::bConsoleDownf() void CBattleInterface::newStack(const CStack * stack) { - SPoint coords = CClickableHex::getXYUnitAnim(stack->position, stack->owner == attackingHeroInstance->tempOwner, stack, this);; + Point coords = CClickableHex::getXYUnitAnim(stack->position, stack->owner == attackingHeroInstance->tempOwner, stack, this);; if(stack->position < 0) //turret { @@ -1549,7 +1532,7 @@ void CBattleInterface::newStack(const CStack * stack) creAnims[stack->ID] = new CCreatureAnimation(stack->getCreature()->animDefName); } creAnims[stack->ID]->setType(CCreatureAnim::HOLDING); - creAnims[stack->ID]->pos = SRect(coords.x, coords.y, creAnims[stack->ID]->fullWidth, creAnims[stack->ID]->fullHeight); + creAnims[stack->ID]->pos = Rect(coords.x, coords.y, creAnims[stack->ID]->fullWidth, creAnims[stack->ID]->fullHeight); creDir[stack->ID] = stack->attackerOwned; } @@ -1568,13 +1551,13 @@ void CBattleInterface::stackActivated(const CStack * stack) //TODO: check it all activateStack(); } -void CBattleInterface::stackMoved(const CStack * stack, std::vector destHex, int distance) +void CBattleInterface::stackMoved(const CStack * stack, std::vector destHex, int distance) { addNewAnim(new CMovementAnimation(this, stack, destHex, distance)); waitForAnims(); } -void CBattleInterface::stacksAreAttacked(std::vector attackedInfos) +void CBattleInterface::stacksAreAttacked(std::vector attackedInfos) { for(size_t h = 0; h < attackedInfos.size(); ++h) { @@ -1605,7 +1588,7 @@ void CBattleInterface::stacksAreAttacked(std::vector attacke } } -void CBattleInterface::stackAttacking( const CStack * attacker, SBattleHex dest, const CStack * attacked, bool shooting ) +void CBattleInterface::stackAttacking( const CStack * attacker, BattleHex dest, const CStack * attacked, bool shooting ) { if (shooting) { @@ -1639,7 +1622,7 @@ void CBattleInterface::newRound(int number) } -void CBattleInterface::giveCommand(ui8 action, SBattleHex tile, ui32 stack, si32 additional) +void CBattleInterface::giveCommand(ui8 action, BattleHex tile, ui32 stack, si32 additional) { if(!curInt->cb->battleGetStackByID(stack) && action != 1 && action != 4 && action != 5) { @@ -1678,30 +1661,30 @@ void CBattleInterface::giveCommand(ui8 action, SBattleHex tile, ui32 stack, si32 } } -bool CBattleInterface::isTileAttackable(const SBattleHex & number) const +bool CBattleInterface::isTileAttackable(const BattleHex & number) const { for(size_t b=0; b obstacles = curInt->cb->battleGetAllObstacles(); - std::set coveredHexes; + std::set coveredHexes; for(size_t b = 0; b < obstacles.size(); ++b) { - std::vector blocked = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getBlocked(obstacles[b].pos); + std::vector blocked = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getBlocked(obstacles[b].pos); for(size_t w = 0; w < blocked.size(); ++w) coveredHexes.insert(blocked[w]); } return vstd::contains(coveredHexes, hex); } -bool CBattleInterface::isCatapultAttackable(SBattleHex hex) const +bool CBattleInterface::isCatapultAttackable(BattleHex hex) const { if(!siegeH) return false; @@ -1799,7 +1782,7 @@ void CBattleInterface::hexLclicked(int whichOne) if ((int)creatureSpellToCast > -1) //use randomized spell (Faerie Dragon), or only avaliable spell (Archangel) { const CSpell * spell = CGI->spellh->spells[creatureSpellToCast]; - if (curInt->cb->battleCanCastThisSpell(spell, SBattleHex(whichOne)) == ESpellCastProblem::OK) + if (curInt->cb->battleCanCastThisSpell(spell, BattleHex(whichOne)) == ESpellCastProblem::OK) { if ((spell->positiveness > -1 && ourStack) || (spell->positiveness < 1 && !ourStack)) { @@ -1880,7 +1863,7 @@ void CBattleInterface::hexLclicked(int whichOne) { if(actStack->doubleWide() && !actStack->attackerOwned) { - std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); if(vstd::contains(acc, whichOne)) attackFromHex = whichOne - 1; else @@ -1932,7 +1915,7 @@ void CBattleInterface::hexLclicked(int whichOne) { if(actStack->doubleWide() && actStack->attackerOwned) { - std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); if(vstd::contains(acc, whichOne)) attackFromHex = whichOne + 1; else @@ -2018,7 +2001,7 @@ void CBattleInterface::hexLclicked(int whichOne) CCS->curh->changeGraphic(1, 6); //cursor should be changed if(activeStack->doubleWide()) { - std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); int shiftedDest = whichOne + (activeStack->attackerOwned ? 1 : -1); if(vstd::contains(acc, whichOne)) giveCommand (BattleAction::WALK ,whichOne, activeStack->ID); @@ -2101,8 +2084,8 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc ) { //common ice bolt and magic arrow part //initial variables std::string animToDisplay; - SPoint srccoord = (sc->side ? SPoint(770, 60) : SPoint(30, 60)) + pos; - SPoint destcoord = CClickableHex::getXYUnitAnim(sc->tile, !sc->side, curInt->cb->battleGetStackByPos(sc->tile), this); //position attacked by arrow + Point srccoord = (sc->side ? Point(770, 60) : Point(30, 60)) + pos; + Point destcoord = CClickableHex::getXYUnitAnim(sc->tile, !sc->side, curInt->cb->battleGetStackByPos(sc->tile), this); //position attacked by arrow destcoord.x += 250; destcoord.y += 240; //animation angle @@ -2320,8 +2303,8 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc ) //mana absorption if (sc->manaGained) { - SPoint leftHero = SPoint(15, 30) + pos; - SPoint rightHero = SPoint(755, 30) + pos; + Point leftHero = Point(15, 30) + pos; + Point rightHero = Point(755, 30) + pos; addNewAnim(new CSpellEffectAnimation(this, sc->side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero.x, leftHero.y, 0, 0, false)); addNewAnim(new CSpellEffectAnimation(this, sc->side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero.x, rightHero.y, 0, 0, false)); } @@ -2608,7 +2591,7 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to) // As long as the projectile of the shooter-stack is flying incrementFrame should be false bool shootingFinished = true; - for (std::list::iterator it = projectiles.begin(); it != projectiles.end(); ++it) + for (std::list::iterator it = projectiles.begin(); it != projectiles.end(); ++it) { if (it->stackID == ID) { @@ -2632,7 +2615,7 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to) && !stack->hasBonusOfType(Bonus::SIEGE_WEAPON) //and not a war machine... ) { - const SBattleHex nextPos = stack->position + (stack->attackerOwned ? 1 : -1); + const BattleHex nextPos = stack->position + (stack->attackerOwned ? 1 : -1); const bool edge = stack->position % GameConstants::BFIELD_WIDTH == (stack->attackerOwned ? GameConstants::BFIELD_WIDTH - 2 : 1); const bool moveInside = !edge && !stackCountOutsideHexes[nextPos]; int xAdd = (stack->attackerOwned ? 220 : 202) + @@ -2675,7 +2658,7 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to) creAnims[ID]->pos.x + xAdd + 15, creAnims[ID]->pos.y + yAdd + 5, FONT_TINY, - zwykly, + Colors::Cornsilk, to ); } @@ -2769,9 +2752,9 @@ void CBattleInterface::redrawBackgroundWithHexes(const CStack * activeStack) if(curInt->sysOpts.printStackRange) { - std::vector hexesToShade = occupyableHexes; + std::vector hexesToShade = occupyableHexes; hexesToShade.insert(hexesToShade.end(), attackableHexes.begin(), attackableHexes.end()); - BOOST_FOREACH(SBattleHex hex, hexesToShade) + BOOST_FOREACH(BattleHex hex, hexesToShade) { int i = hex.getY(); //row int j = hex.getX()-1; //column @@ -2813,8 +2796,8 @@ void CBattleInterface::projectileShowHelper(SDL_Surface * to) { if(to == NULL) to = screen; - std::list< std::list::iterator > toBeDeleted; - for(std::list::iterator it=projectiles.begin(); it!=projectiles.end(); ++it) + std::list< std::list::iterator > toBeDeleted; + for(std::list::iterator it=projectiles.begin(); it!=projectiles.end(); ++it) { // Creature have to be in a shooting anim and the anim start delay must be over. // Otherwise abort to start moving the projectile. @@ -2880,7 +2863,7 @@ void CBattleInterface::projectileShowHelper(SDL_Surface * to) } } } - for(std::list< std::list::iterator >::iterator it = toBeDeleted.begin(); it!= toBeDeleted.end(); ++it) + for(std::list< std::list::iterator >::iterator it = toBeDeleted.begin(); it!= toBeDeleted.end(); ++it) { projectiles.erase(*it); } @@ -2937,7 +2920,7 @@ void CBattleInterface::hideQueue() if(!queue->embedded) { - moveBy(SPoint(0, -queue->pos.h / 2)); + moveBy(Point(0, -queue->pos.h / 2)); GH.totalRedraw(); } } @@ -2950,7 +2933,7 @@ void CBattleInterface::showQueue() if(!queue->embedded) { - moveBy(SPoint(0, +queue->pos.h / 2)); + moveBy(Point(0, +queue->pos.h / 2)); GH.totalRedraw(); } } @@ -3170,7 +3153,7 @@ std::string CBattleInterface::SiegeHelper::getSiegeName(ui16 what, ui16 additInf /// Positions are loaded from the config file: /config/wall_pos.txt void CBattleInterface::SiegeHelper::printPartOfWall(SDL_Surface * to, int what) { - SPoint pos = SPoint(-1, -1); + Point pos = Point(-1, -1); if (what >= 1 && what <= 17) { @@ -3184,7 +3167,7 @@ void CBattleInterface::SiegeHelper::printPartOfWall(SDL_Surface * to, int what) } } -double SCatapultSProjectileInfo::calculateY(double x) +double CatapultProjectileInfo::calculateY(double x) { return (facA * pow(10., -3.)) * pow(x, 2.0) + facB * x + facC; } diff --git a/client/BattleInterface/CBattleInterface.h b/client/BattleInterface/CBattleInterface.h index 2883b4c51..8a0971aee 100644 --- a/client/BattleInterface/CBattleInterface.h +++ b/client/BattleInterface/CBattleInterface.h @@ -4,10 +4,6 @@ #include "../../lib/CCreatureSet.h" #include "../../lib/ConstTransitivePtr.h" //may be reundant #include "../CAnimation.h" -#include "SStackAttackedInfo.h" -#include "CClickableHex.h" -#include "CShootingAnimation.h" -#include "../../lib/SBattleHex.h" #include "../../lib/GameConstants.h" /* @@ -26,7 +22,7 @@ class CGHeroInstance; class CDefHandler; class CStack; class CCallback; -class AdventureMapButton; +class CAdventureMapButton; class CHighlightableButton; class CHighlightableButtonsGroup; struct BattleResult; @@ -37,8 +33,7 @@ struct SetStackEffect;; struct BattleAction; class CGTownInstance; struct CatapultAttack; -class CBattleInterface; -struct SCatapultSProjectileInfo; +struct CatapultProjectileInfo; struct BattleTriggerEffect; class CBattleAnimation; class CBattleHero; @@ -46,6 +41,10 @@ class CBattleConsole; class CBattleResultWindow; class CStackQueue; class CPlayerInterface; +class CCreatureAnimation; +struct ProjectileInfo; +class CClickableHex; +struct BattleHex; /// Class which manages the locked hex fields that are blocked e.g. by obstacles class CBattleObstacle @@ -53,8 +52,20 @@ class CBattleObstacle std::vector lockedHexes; }; +/// Small struct which contains information about the id of the attacked stack, the damage dealt,... +struct StackAttackedInfo +{ + const CStack * defender; //attacked stack + int dmg; //damage dealt + int amountKilled; //how many creatures in stack has been killed + const CStack * attacker; //attacking stack + bool byShooting; //if true, stack has been attacked by shooting + bool killed; //if true, stack has been killed + bool rebirth; //if true, play rebirth animation after all +}; + /// Struct for battle effect animation e.g. morale, prayer, armageddon, bless,... -struct SBattleEffect +struct BattleEffect { int x, y; //position on the screen int frame, maxFrame; @@ -63,13 +74,13 @@ struct SBattleEffect }; /// Small struct which is needed for drawing the parabolic trajectory of the catapult cannon -struct SCatapultSProjectileInfo +struct CatapultProjectileInfo { const double facA, facB, facC; const int fromX, toX; - SCatapultSProjectileInfo() : facA(0), facB(0), facC(0), fromX(0), toX(0) { }; - SCatapultSProjectileInfo(double factorA, double factorB, double factorC, int fromXX, int toXX) : facA(factorA), facB(factorB), facC(factorC), + CatapultProjectileInfo() : facA(0), facB(0), facC(0), fromX(0), toX(0) { }; + CatapultProjectileInfo(double factorA, double factorB, double factorC, int fromXX, int toXX) : facA(factorA), facB(factorB), facC(factorC), fromX(fromXX), toX(toXX) { }; double calculateY(double x); @@ -85,7 +96,7 @@ class CBattleInterface : public CIntObject }; private: SDL_Surface * background, * menu, * amountNormal, * amountNegative, * amountPositive, * amountEffNeutral, * cellBorders, * backgroundWithHexes; - AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell, + CAdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell, * bWait, * bDefence, * bConsoleUp, * bConsoleDown, *btactNext, *btactEnd; CBattleConsole * console; CBattleHero * attackingHero, * defendingHero; //fighting heroes @@ -103,7 +114,7 @@ private: int mouseHoveredStack; //stack hovered by mouse; if -1 -> none time_t lastMouseHoveredStackAnimationTime; // time when last mouse hovered animation occurred static const time_t HOVER_ANIM_DELTA; - std::vector occupyableHexes, //hexes available for active stack + std::vector occupyableHexes, //hexes available for active stack attackableHexes; //hexes attackable by active stack bool stackCountOutsideHexes[GameConstants::BFIELD_SIZE]; // hexes that when in front of a unit cause it's amount box to move back int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago @@ -124,18 +135,18 @@ private: void showAliveStack(const CStack *stack, SDL_Surface * to); //helper function for function show void showAliveStacks(std::vector *aliveStacks, int hex, std::vector *flyingStacks, SDL_Surface *to); // loops through all stacks at a given hex position void showPieceOfWall(SDL_Surface * to, int hex, const std::vector & stacks); //helper function for show - void showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to); // show all obstacles at a given hex position + void showObstacles(std::multimap *hexToObstacle, std::vector &obstacles, int hex, SDL_Surface *to); // show all obstacles at a given hex position void redrawBackgroundWithHexes(const CStack * activeStack); void printConsoleAttacked(const CStack * defender, int dmg, int killed, const CStack * attacker, bool Multiple); - std::list projectiles; //projectiles flying on battlefield + std::list projectiles; //projectiles flying on battlefield void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield - void giveCommand(ui8 action, SBattleHex tile, ui32 stack, si32 additional=-1); - bool isTileAttackable(const SBattleHex & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles - bool blockedByObstacle(SBattleHex hex) const; - bool isCatapultAttackable(SBattleHex hex) const; //returns true if given tile can be attacked by catapult + void giveCommand(ui8 action, BattleHex tile, ui32 stack, si32 additional=-1); + bool isTileAttackable(const BattleHex & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles + bool blockedByObstacle(BattleHex hex) const; + bool isCatapultAttackable(BattleHex hex) const; //returns true if given tile can be attacked by catapult - std::list battleEffects; //different animations to display on the screen like spell effects + std::list battleEffects; //different animations to display on the screen like spell effects /// Class which is responsible for drawing the wall of a siege during battle class SiegeHelper @@ -177,7 +188,7 @@ public: void setAnimSpeed(int set); //speed of animation; 1 - slowest, 2 - medium, 4 - fastest int getAnimSpeed() const; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest - CClickableHex bfield[GameConstants::BFIELD_SIZE]; //11 lines, 17 hexes on each + std::vector bfield; //11 lines, 17 hexes on each //std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield SDL_Surface * cellBorder, * cellShade; CondSh *givenCommand; //data != NULL if we have i.e. moved current unit @@ -215,10 +226,10 @@ public: void newStack(const CStack * stack); //new stack appeared on battlefield void stackRemoved(int stackID); //stack disappeared from batlefiled void stackActivated(const CStack * stack); //active stack has been changed - void stackMoved(const CStack * stack, std::vector destHex, int distance); //stack with id number moved to destHex + void stackMoved(const CStack * stack, std::vector destHex, int distance); //stack with id number moved to destHex void waitForAnims(); - void stacksAreAttacked(std::vector attackedInfos); //called when a certain amount of stacks has been attacked - void stackAttacking(const CStack * attacker, SBattleHex dest, const CStack * attacked, bool shooting); //called when stack with id ID is attacking something on hex dest + void stacksAreAttacked(std::vector attackedInfos); //called when a certain amount of stacks has been attacked + void stackAttacking(const CStack * attacker, BattleHex dest, const CStack * attacked, bool shooting); //called when stack with id ID is attacking something on hex dest void newRoundFirst( int round ); void newRound(int number); //caled when round is ended; number is the number of round void hexLclicked(int whichOne); //hex only call-in @@ -238,7 +249,7 @@ public: friend class CPlayerInterface; - friend class AdventureMapButton; + friend class CAdventureMapButton; friend class CInGameConsole; friend class CBattleResultWindow; diff --git a/client/BattleInterface/CBattleInterfaceClasses.cpp b/client/BattleInterface/CBattleInterfaceClasses.cpp new file mode 100644 index 000000000..04c105a1d --- /dev/null +++ b/client/BattleInterface/CBattleInterfaceClasses.cpp @@ -0,0 +1,754 @@ +#include "StdInc.h" +#include "CBattleInterfaceClasses.h" + +#include "../UIFramework/SDL_Extensions.h" +#include "CBattleInterface.h" +#include "../CGameInfo.h" +#include "../CDefHandler.h" +#include "../UIFramework/CCursorHandler.h" +#include "../CPlayerInterface.h" +#include "../../CCallback.h" +#include "../CSpellWindow.h" +#include "../Graphics.h" +#include "../CConfigHandler.h" +#include "../UIFramework/CGuiHandler.h" +#include "../UIFramework/CIntObjectClasses.h" +#include "../../lib/CGeneralTextHandler.h" +#include "../../lib/NetPacks.h" +#include "../../lib/CCreatureHandler.h" +#include "../../lib/CObjectHandler.h" +#include "../../lib/BattleState.h" +#include "../CMusicHandler.h" +#include "../CVideoHandler.h" +#include "../../lib/CTownHandler.h" +#include "../CBitmapHandler.h" +#include "../CCreatureWindow.h" + +CBattleConsole::~CBattleConsole() +{ + texts.clear(); +} + +void CBattleConsole::show(SDL_Surface * to) +{ + if(ingcAlter.size()) + { + CSDL_Ext::printAtMiddleWB(ingcAlter, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::Cornsilk, to); + } + else if(alterTxt.size()) + { + CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::Cornsilk, to); + } + else if(texts.size()) + { + if(texts.size()==1) + { + CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::Cornsilk, to); + } + else + { + CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::Cornsilk, to); + CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 27, FONT_SMALL, 80, Colors::Cornsilk, to); + } + } +} + +bool CBattleConsole::addText(const std::string & text) +{ + if(text.size()>70) + return false; //text too long! + int firstInToken = 0; + for(size_t i = 0; i < text.size(); ++i) //tokenize + { + if(text[i] == 10) + { + texts.push_back( text.substr(firstInToken, i-firstInToken) ); + firstInToken = i+1; + } + } + + texts.push_back( text.substr(firstInToken, text.size()) ); + lastShown = texts.size()-1; + return true; +} + +void CBattleConsole::eraseText(ui32 pos) +{ + if(pos < texts.size()) + { + texts.erase(texts.begin() + pos); + if(lastShown == texts.size()) + --lastShown; + } +} + +void CBattleConsole::changeTextAt(const std::string & text, ui32 pos) +{ + if(pos >= texts.size()) //no such pos + return; + texts[pos] = text; +} + +void CBattleConsole::scrollUp(ui32 by) +{ + if(lastShown > static_cast(by)) + lastShown -= by; +} + +void CBattleConsole::scrollDown(ui32 by) +{ + if(lastShown + by < texts.size()) + lastShown += by; +} + +void CBattleHero::show(SDL_Surface * to) +{ + //animation of flag + if(flip) + { + SDL_Rect temp_rect = genRect( + flag->ourImages[flagAnim].bitmap->h, + flag->ourImages[flagAnim].bitmap->w, + pos.x + 61, + pos.y + 39); + CSDL_Ext::blit8bppAlphaTo24bpp( + flag->ourImages[flagAnim].bitmap, + NULL, + screen, + &temp_rect); + } + else + { + SDL_Rect temp_rect = genRect( + flag->ourImages[flagAnim].bitmap->h, + flag->ourImages[flagAnim].bitmap->w, + pos.x + 72, + pos.y + 39); + CSDL_Ext::blit8bppAlphaTo24bpp( + flag->ourImages[flagAnim].bitmap, + NULL, + screen, + &temp_rect); + } + ++flagAnimCount; + if(flagAnimCount%4==0) + { + ++flagAnim; + flagAnim %= flag->ourImages.size(); + } + //animation of hero + int tick=-1; + for(size_t i = 0; i < dh->ourImages.size(); ++i) + { + if(dh->ourImages[i].groupNumber==phase) + ++tick; + if(tick==image) + { + SDL_Rect posb = pos; + CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb); + if(phase != 4 || nextPhase != -1 || image < 4) + { + if(flagAnimCount%2==0) + { + ++image; + } + if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame + { + image = 0; + } + } + if(phase == 4 && nextPhase != -1 && image == 7) + { + phase = nextPhase; + nextPhase = -1; + image = 0; + } + break; + } + } +} + +void CBattleHero::activate() +{ + activateLClick(); +} +void CBattleHero::deactivate() +{ + deactivateLClick(); +} + +void CBattleHero::setPhase(int newPhase) +{ + if(phase != 4) + { + phase = newPhase; + image = 0; + } + else + { + nextPhase = newPhase; + } +} + +void CBattleHero::clickLeft(tribool down, bool previousState) +{ + if(myOwner->spellDestSelectMode) //we are casting a spell + return; + + if(!down && myHero != NULL && myOwner->myTurn && myOwner->curInt->cb->battleCanCastSpell()) //check conditions + { + for(int it=0; itbfield[it].hovered && myOwner->bfield[it].strictHovered) + return; + } + CCS->curh->changeGraphic(0,0); + + CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), myHero, myOwner->curInt); + GH.pushInt(spellWindow); + } +} + +CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, ui8 player, const CGHeroInstance * hero, const CBattleInterface * owner): flip(flipG), myHero(hero), myOwner(owner), phase(phaseG), nextPhase(-1), image(imageG), flagAnim(0), flagAnimCount(0) +{ + dh = CDefHandler::giveDef( defName ); + for(size_t i = 0; i < dh->ourImages.size(); ++i) //transforming images + { + if(flip) + { + SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap); + SDL_FreeSurface(dh->ourImages[i].bitmap); + dh->ourImages[i].bitmap = hlp; + } + CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap); + } + + if(flip) + flag = CDefHandler::giveDef("CMFLAGR.DEF"); + else + flag = CDefHandler::giveDef("CMFLAGL.DEF"); + + //coloring flag and adding transparency + for(size_t i = 0; i < flag->ourImages.size(); ++i) + { + CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap); + graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player); + } +} + +CBattleHero::~CBattleHero() +{ + delete dh; + delete flag; +} + +CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + pos = position; + background = new CPicture("comopbck.bmp"); + background->colorize(owner->curInt->playerID); + + viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[427].first)(3,CGI->generaltexth->zelp[427].first), CGI->generaltexth->zelp[427].second, false, "sysopchk.def", NULL, 25, 56, false); + viewGrid->select(owner->curInt->sysOpts.printCellBorders); + movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[428].first)(3,CGI->generaltexth->zelp[428].first), CGI->generaltexth->zelp[428].second, false, "sysopchk.def", NULL, 25, 89, false); + movementShadow->select(owner->curInt->sysOpts.printStackRange); + mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[429].first)(3,CGI->generaltexth->zelp[429].first), CGI->generaltexth->zelp[429].second, false, "sysopchk.def", NULL, 25, 122, false); + mouseShadow->select(owner->curInt->sysOpts.printMouseShadow); + + animSpeeds = new CHighlightableButtonsGroup(0); + animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[422].first),CGI->generaltexth->zelp[422].second, "sysopb9.def", 28, 225, 1); + animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[423].first),CGI->generaltexth->zelp[423].second, "sysob10.def", 92, 225, 2); + animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[424].first),CGI->generaltexth->zelp[424].second, "sysob11.def",156, 225, 4); + animSpeeds->select(owner->getAnimSpeed(), 1); + animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1); + + setToDefault = new CAdventureMapButton (CGI->generaltexth->zelp[393], boost::bind(&CBattleOptionsWindow::bDefaultf,this), 246, 359, "codefaul.def"); + setToDefault->swappedImages = true; + setToDefault->update(); + exit = new CAdventureMapButton (CGI->generaltexth->zelp[392], boost::bind(&CBattleOptionsWindow::bExitf,this), 357, 359, "soretrn.def",SDLK_RETURN); + exit->swappedImages = true; + exit->update(); + + //creating labels + labels.push_back(new CLabel(242, 32, FONT_BIG, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[392]));//window title + labels.push_back(new CLabel(122, 214, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[393]));//animation speed + labels.push_back(new CLabel(122, 293, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[394]));//music volume + labels.push_back(new CLabel(122, 359, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[395]));//effects' volume + labels.push_back(new CLabel(353, 66, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[396]));//auto - combat options + labels.push_back(new CLabel(353, 265, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[397]));//creature info + + //auto - combat options + labels.push_back(new CLabel(283, 86, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[398]));//creatures + labels.push_back(new CLabel(283, 116, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[399]));//spells + labels.push_back(new CLabel(283, 146, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[400]));//catapult + labels.push_back(new CLabel(283, 176, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[151]));//ballista + labels.push_back(new CLabel(283, 206, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[401]));//first aid tent + + //creature info + labels.push_back(new CLabel(283, 285, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[402]));//all stats + labels.push_back(new CLabel(283, 315, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[403]));//spells only + + //general options + labels.push_back(new CLabel(61, 57, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[404])); + labels.push_back(new CLabel(61, 90, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[405])); + labels.push_back(new CLabel(61, 123, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[406])); + labels.push_back(new CLabel(61, 156, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[407])); +} + +void CBattleOptionsWindow::bDefaultf() +{ +} + +void CBattleOptionsWindow::bExitf() +{ + GH.popIntTotally(this); +} + +CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect & pos, CBattleInterface * _owner) +: owner(_owner) +{ + this->pos = pos; + background = BitmapHandler::loadBitmap("CPRESULT.BMP", true); + graphics->blueToPlayersAdv(background, owner->curInt->playerID); + SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags); + SDL_FreeSurface(background); + background = pom; + exit = new CAdventureMapButton (std::string(), std::string(), boost::bind(&CBattleResultWindow::bExitf,this), 384 + pos.x, 505 + pos.y, "iok6432.def", SDLK_RETURN); + exit->borderColor = Colors::MetallicGold; + exit->borderEnabled = true; + + if(br.winner==0) //attacker won + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 59, 124, FONT_SMALL, Colors::Cornsilk, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 408, 124, FONT_SMALL, Colors::Cornsilk, background); + } + else //if(br.winner==1) + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 59, 124, FONT_SMALL, Colors::Cornsilk, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 412, 124, FONT_SMALL, Colors::Cornsilk, background); + } + + + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[407], 232, 302, FONT_BIG, Colors::Jasmine, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[408], 232, 332, FONT_BIG, Colors::Cornsilk, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[409], 237, 428, FONT_BIG, Colors::Cornsilk, background); + + std::string attackerName, defenderName; + + if(owner->attackingHeroInstance) //a hero attacked + { + SDL_Rect temp_rect = genRect(64, 58, 21, 38); + SDL_BlitSurface(graphics->portraitLarge[owner->attackingHeroInstance->portrait], NULL, background, &temp_rect); + //setting attackerName + attackerName = owner->attackingHeroInstance->name; + } + else //a monster attacked + { + int bestMonsterID = -1; + ui32 bestPower = 0; + for(TSlots::const_iterator it = owner->army1->Slots().begin(); it!=owner->army1->Slots().end(); ++it) + { + if(it->second->type->AIValue > bestPower) + { + bestPower = it->second->type->AIValue; + bestMonsterID = it->second->type->idNumber; + } + } + SDL_Rect temp_rect = genRect(64, 58, 21, 38); + SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &temp_rect); + //setting attackerName + attackerName = CGI->creh->creatures[bestMonsterID]->namePl; + } + if(owner->defendingHeroInstance) //a hero defended + { + SDL_Rect temp_rect = genRect(64, 58, 392, 38); + SDL_BlitSurface(graphics->portraitLarge[owner->defendingHeroInstance->portrait], NULL, background, &temp_rect); + //setting defenderName + defenderName = owner->defendingHeroInstance->name; + } + else //a monster defended + { + int bestMonsterID = -1; + ui32 bestPower = 0; + for(TSlots::const_iterator it = owner->army2->Slots().begin(); it!=owner->army2->Slots().end(); ++it) + { + if( it->second->type->AIValue > bestPower) + { + bestPower = it->second->type->AIValue; + bestMonsterID = it->second->type->idNumber; + } + } + SDL_Rect temp_rect = genRect(64, 58, 392, 38); + SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &temp_rect); + //setting defenderName + defenderName = CGI->creh->creatures[bestMonsterID]->namePl; + } + + //printing attacker and defender's names + CSDL_Ext::printAt(attackerName, 89, 37, FONT_SMALL, Colors::Cornsilk, background); + CSDL_Ext::printTo(defenderName, 381, 53, FONT_SMALL, Colors::Cornsilk, background); + //printing casualities + for(int step = 0; step < 2; ++step) + { + if(br.casualties[step].size()==0) + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[523], 235, 360 + 97*step, FONT_SMALL, Colors::Cornsilk, background); + } + else + { + int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture + int yPos = 344 + step*97; + for(std::map::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it) + { + blitAt(graphics->smallImgs[it->first], xPos, yPos, background); + std::ostringstream amount; + amount<second; + CSDL_Ext::printAtMiddle(amount.str(), xPos+16, yPos + 42, FONT_SMALL, Colors::Cornsilk, background); + xPos += 42; + } + } + } + //printing result description + bool weAreAttacker = (owner->curInt->playerID == owner->attackingHeroInstance->tempOwner); + if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won + { + int text=-1; + switch(br.result) + { + case 0: text = 304; break; + case 1: text = 303; break; + case 2: text = 302; break; + } + + CCS->musich->playMusic(musicBase::winBattle); + CCS->videoh->open(VIDEO_WIN); + std::string str = CGI->generaltexth->allTexts[text]; + + const CGHeroInstance * ourHero = weAreAttacker? owner->attackingHeroInstance : owner->defendingHeroInstance; + if (ourHero) + { + str += CGI->generaltexth->allTexts[305]; + boost::algorithm::replace_first(str,"%s",ourHero->name); + boost::algorithm::replace_first(str,"%d",boost::lexical_cast(br.exp[weAreAttacker?0:1])); + } + CSDL_Ext::printAtMiddleWB(str, 235, 235, FONT_SMALL, 55, Colors::Cornsilk, background); + } + else // we lose + { + switch(br.result) + { + case 0: //normal victory + { + CCS->musich->playMusic(musicBase::loseCombat); + CCS->videoh->open(VIDEO_LOSE_BATTLE_START); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[311], 235, 235, FONT_SMALL, Colors::Cornsilk, background); + break; + } + case 1: //flee + { + CCS->musich->playMusic(musicBase::retreatBattle); + CCS->videoh->open(VIDEO_RETREAT_START); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[310], 235, 235, FONT_SMALL, Colors::Cornsilk, background); + break; + } + case 2: //surrender + { + CCS->musich->playMusic(musicBase::surrenderBattle); + CCS->videoh->open(VIDEO_SURRENDER); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[309], 235, 220, FONT_SMALL, Colors::Cornsilk, background); + break; + } + } + } +} + +CBattleResultWindow::~CBattleResultWindow() +{ + SDL_FreeSurface(background); +} + +void CBattleResultWindow::activate() +{ + owner->curInt->showingDialog->set(true); + exit->activate(); +} + +void CBattleResultWindow::deactivate() +{ + exit->deactivate(); +} + +void CBattleResultWindow::show(SDL_Surface * to) +{ + //evaluating to + if(!to) + to = screen; + + CCS->videoh->update(107, 70, background, false, true); + + SDL_BlitSurface(background, NULL, to, &pos); + exit->showAll(to); +} + +void CBattleResultWindow::bExitf() +{ + if(LOCPLINT->cb->getStartInfo()->mode == StartInfo::DUEL) + { + std::exit(0); + } + + CPlayerInterface * intTmp = owner->curInt; + GH.popInts(2); //first - we; second - battle interface + intTmp->showingDialog->setn(false); + CCS->videoh->close(); +} + +Point CClickableHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * stack, const CBattleInterface * cbi) +{ + Point ret(-500, -500); //returned value + if(stack && stack->position < 0) //creatures in turrets + { + switch(stack->position) + { + case -2: //keep + ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][17]; + break; + case -3: //lower turret + ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][18]; + break; + case -4: //upper turret + ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][19]; + break; + } + } + else + { + ret.y = -139 + 42 * (hexNum/GameConstants::BFIELD_WIDTH); //counting y + //counting x + if(attacker) + { + ret.x = -160 + 22 * ( ((hexNum/GameConstants::BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % GameConstants::BFIELD_WIDTH); + } + else + { + ret.x = -219 + 22 * ( ((hexNum/GameConstants::BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % GameConstants::BFIELD_WIDTH); + } + //shifting position for double - hex creatures + if(stack && stack->doubleWide()) + { + if(attacker) + { + ret.x -= 44; + } + else + { + ret.x += 45; + } + } + } + //returning + return ret +CPlayerInterface::battleInt->pos; +} +void CClickableHex::activate() +{ + activateHover(); + activateMouseMove(); + activateLClick(); + activateRClick(); +} + +void CClickableHex::deactivate() +{ + deactivateHover(); + deactivateMouseMove(); + deactivateLClick(); + deactivateRClick(); +} + +void CClickableHex::hover(bool on) +{ + hovered = on; + //Hoverable::hover(on); + if(!on && setAlterText) + { + myInterface->console->alterTxt = std::string(); + setAlterText = false; + } +} + +CClickableHex::CClickableHex() : setAlterText(false), myNumber(-1), accessible(true), hovered(false), strictHovered(false), myInterface(NULL) +{ +} + +void CClickableHex::mouseMoved(const SDL_MouseMotionEvent &sEvent) +{ + if(myInterface->cellShade) + { + if(CSDL_Ext::SDL_GetPixel(myInterface->cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex + { + strictHovered = false; + } + else //hovered pixel is inside hex + { + strictHovered = true; + } + } + + if(hovered && strictHovered) //print attacked creature to console + { + const CStack * attackedStack = myInterface->curInt->cb->battleGetStackByPos(myNumber); + if(myInterface->console->alterTxt.size() == 0 &&attackedStack != NULL && + attackedStack->owner != myInterface->curInt->playerID && + attackedStack->alive()) + { + char tabh[160]; + const std::string & attackedName = attackedStack->count == 1 ? attackedStack->getCreature()->nameSing : attackedStack->getCreature()->namePl; + sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); + myInterface->console->alterTxt = std::string(tabh); + setAlterText = true; + } + } + else if(setAlterText) + { + myInterface->console->alterTxt = std::string(); + setAlterText = false; + } +} + +void CClickableHex::clickLeft(tribool down, bool previousState) +{ + if(!down && hovered && strictHovered) //we've been really clicked! + { + myInterface->hexLclicked(myNumber); + } +} + +void CClickableHex::clickRight(tribool down, bool previousState) +{ + const CStack * myst = myInterface->curInt->cb->battleGetStackByPos(myNumber); //stack info + if(hovered && strictHovered && myst!=NULL) + { + + if(!myst->alive()) return; + if(down) + { + GH.pushInt(createCreWindow(myst)); + } + } +} + +void CStackQueue::update() +{ + stacksSorted.clear(); + owner->curInt->cb->getStackQueue(stacksSorted, QUEUE_SIZE); + for (int i = 0; i < QUEUE_SIZE ; i++) + { + stackBoxes[i]->setStack(stacksSorted[i]); + } +} + +CStackQueue::CStackQueue(bool Embedded, CBattleInterface * _owner) +:embedded(Embedded), owner(_owner) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + if(embedded) + { + box = NULL; + bg = NULL; + pos.w = QUEUE_SIZE * 37; + pos.h = 32; //height of small creature img + pos.x = screen->w/2 - pos.w/2; + pos.y = (screen->h - 600)/2 + 10; + } + else + { + box = BitmapHandler::loadBitmap("CHRROP.pcx"); + bg = BitmapHandler::loadBitmap("DIBOXPI.pcx"); + pos.w = 600; + pos.h = bg->h; + } + + stackBoxes.resize(QUEUE_SIZE); + for (int i = 0; i < QUEUE_SIZE; i++) + { + stackBoxes[i] = new StackBox(box); + stackBoxes[i]->pos.x += 6 + (embedded ? 37 : 79)*i; + } +} + +CStackQueue::~CStackQueue() +{ + SDL_FreeSurface(box); +} + +void CStackQueue::showAll(SDL_Surface * to) +{ + blitBg(to); + + CIntObject::showAll(to); +} + +void CStackQueue::blitBg( SDL_Surface * to ) +{ + if(bg) + { + for (int w = 0; w < pos.w; w += bg->w) + { + blitAtLoc(bg, w, 0, to); + } + } +} + +void CStackQueue::StackBox::showAll(SDL_Surface * to) +{ + assert(my); + if(bg) + { + graphics->blueToPlayersAdv(bg, my->owner); + //SDL_UpdateRect(bg, 0, 0, 0, 0); + SDL_Rect temp_rect = genRect(bg->h, bg->w, pos.x, pos.y); + CSDL_Ext::blit8bppAlphaTo24bpp(bg, NULL, to, &temp_rect); + //blitAt(bg, pos, to); + blitAt(graphics->bigImgs[my->getCreature()->idNumber], pos.x +9, pos.y + 1, to); + printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 12, FONT_MEDIUM, Colors::Cornsilk, to); + } + else + { + blitAt(graphics->smallImgs[-2], pos, to); + blitAt(graphics->smallImgs[my->getCreature()->idNumber], pos, to); + const SDL_Color &ownerColor = (my->owner == 255 ? *graphics->neutralColor : graphics->playerColors[my->owner]); + CSDL_Ext::drawBorder(to, pos, int3(ownerColor.r, ownerColor.g, ownerColor.b)); + printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 8, FONT_TINY, Colors::Cornsilk, to); + } +} + +void CStackQueue::StackBox::setStack( const CStack *nStack ) +{ + my = nStack; +} + +CStackQueue::StackBox::StackBox(SDL_Surface *BG) +:my(NULL), bg(BG) +{ + if(bg) + { + pos.w = bg->w; + pos.h = bg->h; + } + else + { + pos.w = pos.h = 32; + } + + pos.y += 2; +} + +CStackQueue::StackBox::~StackBox() +{ +} + +void CStackQueue::StackBox::hover( bool on ) +{ + +} \ No newline at end of file diff --git a/client/BattleInterface/CBattleInterfaceClasses.h b/client/BattleInterface/CBattleInterfaceClasses.h new file mode 100644 index 000000000..4b9bcab6a --- /dev/null +++ b/client/BattleInterface/CBattleInterfaceClasses.h @@ -0,0 +1,159 @@ +#pragma once + +#include "../UIFramework/CIntObject.h" + +struct SDL_Surface; +class CDefHandler; +class CGHeroInstance; +class CBattleInterface; +class CPicture; +class CAdventureMapButton; +class CHighlightableButton; +class CHighlightableButtonsGroup; +class CLabel; +class BattleResult; +class CStack; + +/* + * CBattleInterfaceClasses.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +/// Class which shows the console at the bottom of the battle screen and manages the text of the console +class CBattleConsole : public CIntObject +{ +private: + std::vector< std::string > texts; //a place where texts are stored + int lastShown; //last shown line of text +public: + std::string alterTxt; //if it's not empty, this text is displayed + std::string ingcAlter; //alternative text set by in-game console - very important! + int whoSetAlter; //who set alter text; 0 - battle interface or none, 1 - button + CBattleConsole() : lastShown(-1), alterTxt(""), whoSetAlter(0) {} + ~CBattleConsole(); //d-tor + void show(SDL_Surface * to = 0); + bool addText(const std::string &text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters) + void eraseText(ui32 pos); //erases added text at position pos + void changeTextAt(const std::string &text, ui32 pos); //if we have more than pos texts, pos-th is changed to given one + void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions + void scrollDown(ui32 by = 1); //scrolls console up by 'by' positions +}; + +/// Hero battle animation +class CBattleHero : public CIntObject +{ +public: + bool flip; //false if it's attacking hero, true otherwise + CDefHandler *dh, *flag; //animation and flag + const CGHeroInstance * myHero; //this animation's hero instance + const CBattleInterface * myOwner; //battle interface to which this animation is assigned + int phase; //stage of animation + int nextPhase; //stage of animation to be set after current phase is fully displayed + int image; //frame of animation + ui8 flagAnim, flagAnimCount; //for flag animation + void show(SDL_Surface * to); //prints next frame of animation to to + void activate(); + void deactivate(); + void setPhase(int newPhase); //sets phase of hero animation + void clickLeft(tribool down, bool previousState); //call-in + CBattleHero(const std::string &defName, int phaseG, int imageG, bool filpG, ui8 player, const CGHeroInstance *hero, const CBattleInterface *owner); //c-tor + ~CBattleHero(); //d-tor +}; + +/// Class which manages the battle options window +class CBattleOptionsWindow : public CIntObject +{ +private: + CBattleInterface * myInt; + CPicture * background; + CAdventureMapButton * setToDefault, * exit; + CHighlightableButton * viewGrid, * movementShadow, * mouseShadow; + CHighlightableButtonsGroup * animSpeeds; + + std::vector labels; +public: + CBattleOptionsWindow(const SDL_Rect &position, CBattleInterface *owner); //c-tor + + void bDefaultf(); //default button callback + void bExitf(); //exit button callback +}; + +/// Class which is responsible for showing the battle result window +class CBattleResultWindow : public CIntObject +{ +private: + SDL_Surface *background; + CAdventureMapButton *exit; + CBattleInterface *owner; +public: + CBattleResultWindow(const BattleResult & br, const SDL_Rect & pos, CBattleInterface * _owner); //c-tor + ~CBattleResultWindow(); //d-tor + + void bExitf(); //exit button callback + + void activate(); + void deactivate(); + void show(SDL_Surface * to = 0); +}; + +/// Class which stands for a single hex field on a battlefield +class CClickableHex : public CIntObject +{ +private: + bool setAlterText; //if true, this hex has set alternative text in console and will clean it +public: + ui32 myNumber; //number of hex in commonly used format + bool accessible; //if true, this hex is accessible for units + //CStack * ourStack; + bool hovered, strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering) + CBattleInterface * myInterface; //interface that owns me + static Point getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * creature, const CBattleInterface * cbi); //returns (x, y) of left top corner of animation + + //for user interactions + void hover (bool on); + void activate(); + void deactivate(); + void mouseMoved (const SDL_MouseMotionEvent &sEvent); + void clickLeft(tribool down, bool previousState); + void clickRight(tribool down, bool previousState); + CClickableHex(); +}; + +/// Shows the stack queue +class CStackQueue : public CIntObject +{ + class StackBox : public CIntObject + { + public: + const CStack *my; + SDL_Surface *bg; + + void hover (bool on); + void showAll(SDL_Surface * to); + void setStack(const CStack *nStack); + StackBox(SDL_Surface *BG); + ~StackBox(); + }; + +public: + static const int QUEUE_SIZE = 10; + const bool embedded; + std::vector stacksSorted; + std::vector stackBoxes; + + SDL_Surface *box; + SDL_Surface *bg; + CBattleInterface * owner; + + void showAll(SDL_Surface * to); + CStackQueue(bool Embedded, CBattleInterface * _owner); + ~CStackQueue(); + void update(); + void blitBg( SDL_Surface * to ); + //void showAll(SDL_Surface * to); +}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleOptionsWindow.cpp b/client/BattleInterface/CBattleOptionsWindow.cpp deleted file mode 100644 index b0a429df7..000000000 --- a/client/BattleInterface/CBattleOptionsWindow.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "StdInc.h" -#include "CBattleOptionsWindow.h" - -#include "CBattleInterface.h" -#include "../GUIClasses.h" -#include "../AdventureMapButton.h" -#include "../CGameInfo.h" -#include "../CPlayerInterface.h" -#include "../../lib/CGeneralTextHandler.h" -#include "../UIFramework/CGuiHandler.h" - -CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - pos = position; - background = new CPicture("comopbck.bmp"); - background->colorize(owner->curInt->playerID); - - viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[427].first)(3,CGI->generaltexth->zelp[427].first), CGI->generaltexth->zelp[427].second, false, "sysopchk.def", NULL, 25, 56, false); - viewGrid->select(owner->curInt->sysOpts.printCellBorders); - movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[428].first)(3,CGI->generaltexth->zelp[428].first), CGI->generaltexth->zelp[428].second, false, "sysopchk.def", NULL, 25, 89, false); - movementShadow->select(owner->curInt->sysOpts.printStackRange); - mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[429].first)(3,CGI->generaltexth->zelp[429].first), CGI->generaltexth->zelp[429].second, false, "sysopchk.def", NULL, 25, 122, false); - mouseShadow->select(owner->curInt->sysOpts.printMouseShadow); - - animSpeeds = new CHighlightableButtonsGroup(0); - animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[422].first),CGI->generaltexth->zelp[422].second, "sysopb9.def", 28, 225, 1); - animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[423].first),CGI->generaltexth->zelp[423].second, "sysob10.def", 92, 225, 2); - animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[424].first),CGI->generaltexth->zelp[424].second, "sysob11.def",156, 225, 4); - animSpeeds->select(owner->getAnimSpeed(), 1); - animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1); - - setToDefault = new AdventureMapButton (CGI->generaltexth->zelp[393], boost::bind(&CBattleOptionsWindow::bDefaultf,this), 246, 359, "codefaul.def"); - setToDefault->swappedImages = true; - setToDefault->update(); - exit = new AdventureMapButton (CGI->generaltexth->zelp[392], boost::bind(&CBattleOptionsWindow::bExitf,this), 357, 359, "soretrn.def",SDLK_RETURN); - exit->swappedImages = true; - exit->update(); - - //creating labels - labels.push_back(new CLabel(242, 32, FONT_BIG, CENTER, tytulowy, CGI->generaltexth->allTexts[392]));//window title - labels.push_back(new CLabel(122, 214, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[393]));//animation speed - labels.push_back(new CLabel(122, 293, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[394]));//music volume - labels.push_back(new CLabel(122, 359, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[395]));//effects' volume - labels.push_back(new CLabel(353, 66, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[396]));//auto - combat options - labels.push_back(new CLabel(353, 265, FONT_MEDIUM, CENTER, tytulowy, CGI->generaltexth->allTexts[397]));//creature info - - //auto - combat options - labels.push_back(new CLabel(283, 86, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[398]));//creatures - labels.push_back(new CLabel(283, 116, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[399]));//spells - labels.push_back(new CLabel(283, 146, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[400]));//catapult - labels.push_back(new CLabel(283, 176, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[151]));//ballista - labels.push_back(new CLabel(283, 206, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[401]));//first aid tent - - //creature info - labels.push_back(new CLabel(283, 285, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[402]));//all stats - labels.push_back(new CLabel(283, 315, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[403]));//spells only - - //general options - labels.push_back(new CLabel(61, 57, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[404])); - labels.push_back(new CLabel(61, 90, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[405])); - labels.push_back(new CLabel(61, 123, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[406])); - labels.push_back(new CLabel(61, 156, FONT_MEDIUM, TOPLEFT, zwykly, CGI->generaltexth->allTexts[407])); -} - -void CBattleOptionsWindow::bDefaultf() -{ -} - -void CBattleOptionsWindow::bExitf() -{ - GH.popIntTotally(this); -} \ No newline at end of file diff --git a/client/BattleInterface/CBattleOptionsWindow.h b/client/BattleInterface/CBattleOptionsWindow.h deleted file mode 100644 index 91c89c624..000000000 --- a/client/BattleInterface/CBattleOptionsWindow.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "../UIFramework/CIntObject.h" - -class CBattleInterface; -class CPicture; -class AdventureMapButton; -class CHighlightableButton; -class CHighlightableButtonsGroup; -class CLabel; -struct SDL_Rect; - -/* - * CBattleOptionsWindow.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Class which manages the battle options window -class CBattleOptionsWindow : public CIntObject -{ -private: - CBattleInterface *myInt; - CPicture *background; - AdventureMapButton *setToDefault, *exit; - CHighlightableButton *viewGrid, *movementShadow, *mouseShadow; - CHighlightableButtonsGroup *animSpeeds; - - std::vector labels; -public: - CBattleOptionsWindow(const SDL_Rect &position, CBattleInterface *owner); //c-tor - - void bDefaultf(); //default button callback - void bExitf(); //exit button callback -}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleResultWindow.cpp b/client/BattleInterface/CBattleResultWindow.cpp deleted file mode 100644 index 44dd9de59..000000000 --- a/client/BattleInterface/CBattleResultWindow.cpp +++ /dev/null @@ -1,217 +0,0 @@ -#include "StdInc.h" -#include "CBattleResultWindow.h" - -#include "CBattleInterface.h" -#include "../AdventureMapButton.h" -#include "../CGameInfo.h" -#include "../../lib/CObjectHandler.h" -#include "../../lib/NetPacks.h" -#include "../../lib/CCreatureHandler.h" -#include "../../lib/CGeneralTextHandler.h" -#include "../CMusicHandler.h" -#include "../CPlayerInterface.h" -#include "../Graphics.h" -#include "../../CCallback.h" -#include "../CVideoHandler.h" -#include "../SDL_Extensions.h" -#include "../CBitmapHandler.h" -#include "../UIFramework/CGuiHandler.h" - -CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect & pos, CBattleInterface * _owner) -: owner(_owner) -{ - this->pos = pos; - background = BitmapHandler::loadBitmap("CPRESULT.BMP", true); - graphics->blueToPlayersAdv(background, owner->curInt->playerID); - SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags); - SDL_FreeSurface(background); - background = pom; - exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleResultWindow::bExitf,this), 384 + pos.x, 505 + pos.y, "iok6432.def", SDLK_RETURN); - exit->borderColor = Colors::MetallicGold; - exit->borderEnabled = true; - - if(br.winner==0) //attacker won - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 59, 124, FONT_SMALL, zwykly, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 408, 124, FONT_SMALL, zwykly, background); - } - else //if(br.winner==1) - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 59, 124, FONT_SMALL, zwykly, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 412, 124, FONT_SMALL, zwykly, background); - } - - - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[407], 232, 302, FONT_BIG, tytulowy, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[408], 232, 332, FONT_BIG, zwykly, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[409], 237, 428, FONT_BIG, zwykly, background); - - std::string attackerName, defenderName; - - if(owner->attackingHeroInstance) //a hero attacked - { - SDL_Rect temp_rect = genRect(64, 58, 21, 38); - SDL_BlitSurface(graphics->portraitLarge[owner->attackingHeroInstance->portrait], NULL, background, &temp_rect); - //setting attackerName - attackerName = owner->attackingHeroInstance->name; - } - else //a monster attacked - { - int bestMonsterID = -1; - ui32 bestPower = 0; - for(TSlots::const_iterator it = owner->army1->Slots().begin(); it!=owner->army1->Slots().end(); ++it) - { - if(it->second->type->AIValue > bestPower) - { - bestPower = it->second->type->AIValue; - bestMonsterID = it->second->type->idNumber; - } - } - SDL_Rect temp_rect = genRect(64, 58, 21, 38); - SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &temp_rect); - //setting attackerName - attackerName = CGI->creh->creatures[bestMonsterID]->namePl; - } - if(owner->defendingHeroInstance) //a hero defended - { - SDL_Rect temp_rect = genRect(64, 58, 392, 38); - SDL_BlitSurface(graphics->portraitLarge[owner->defendingHeroInstance->portrait], NULL, background, &temp_rect); - //setting defenderName - defenderName = owner->defendingHeroInstance->name; - } - else //a monster defended - { - int bestMonsterID = -1; - ui32 bestPower = 0; - for(TSlots::const_iterator it = owner->army2->Slots().begin(); it!=owner->army2->Slots().end(); ++it) - { - if( it->second->type->AIValue > bestPower) - { - bestPower = it->second->type->AIValue; - bestMonsterID = it->second->type->idNumber; - } - } - SDL_Rect temp_rect = genRect(64, 58, 392, 38); - SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &temp_rect); - //setting defenderName - defenderName = CGI->creh->creatures[bestMonsterID]->namePl; - } - - //printing attacker and defender's names - CSDL_Ext::printAt(attackerName, 89, 37, FONT_SMALL, zwykly, background); - CSDL_Ext::printTo(defenderName, 381, 53, FONT_SMALL, zwykly, background); - //printing casualities - for(int step = 0; step < 2; ++step) - { - if(br.casualties[step].size()==0) - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[523], 235, 360 + 97*step, FONT_SMALL, zwykly, background); - } - else - { - int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture - int yPos = 344 + step*97; - for(std::map::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it) - { - blitAt(graphics->smallImgs[it->first], xPos, yPos, background); - std::ostringstream amount; - amount<second; - CSDL_Ext::printAtMiddle(amount.str(), xPos+16, yPos + 42, FONT_SMALL, zwykly, background); - xPos += 42; - } - } - } - //printing result description - bool weAreAttacker = (owner->curInt->playerID == owner->attackingHeroInstance->tempOwner); - if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won - { - int text=-1; - switch(br.result) - { - case 0: text = 304; break; - case 1: text = 303; break; - case 2: text = 302; break; - } - - CCS->musich->playMusic(musicBase::winBattle); - CCS->videoh->open(VIDEO_WIN); - std::string str = CGI->generaltexth->allTexts[text]; - - const CGHeroInstance * ourHero = weAreAttacker? owner->attackingHeroInstance : owner->defendingHeroInstance; - if (ourHero) - { - str += CGI->generaltexth->allTexts[305]; - boost::algorithm::replace_first(str,"%s",ourHero->name); - boost::algorithm::replace_first(str,"%d",boost::lexical_cast(br.exp[weAreAttacker?0:1])); - } - CSDL_Ext::printAtMiddleWB(str, 235, 235, FONT_SMALL, 55, zwykly, background); - } - else // we lose - { - switch(br.result) - { - case 0: //normal victory - { - CCS->musich->playMusic(musicBase::loseCombat); - CCS->videoh->open(VIDEO_LOSE_BATTLE_START); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[311], 235, 235, FONT_SMALL, zwykly, background); - break; - } - case 1: //flee - { - CCS->musich->playMusic(musicBase::retreatBattle); - CCS->videoh->open(VIDEO_RETREAT_START); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[310], 235, 235, FONT_SMALL, zwykly, background); - break; - } - case 2: //surrender - { - CCS->musich->playMusic(musicBase::surrenderBattle); - CCS->videoh->open(VIDEO_SURRENDER); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[309], 235, 220, FONT_SMALL, zwykly, background); - break; - } - } - } -} - -CBattleResultWindow::~CBattleResultWindow() -{ - SDL_FreeSurface(background); -} - -void CBattleResultWindow::activate() -{ - owner->curInt->showingDialog->set(true); - exit->activate(); -} - -void CBattleResultWindow::deactivate() -{ - exit->deactivate(); -} - -void CBattleResultWindow::show(SDL_Surface *to) -{ - //evaluating to - if(!to) - to = screen; - - CCS->videoh->update(107, 70, background, false, true); - - SDL_BlitSurface(background, NULL, to, &pos); - exit->showAll(to); -} - -void CBattleResultWindow::bExitf() -{ - if(LOCPLINT->cb->getStartInfo()->mode == StartInfo::DUEL) - { - std::exit(0); - } - - CPlayerInterface * intTmp = owner->curInt; - GH.popInts(2); //first - we; second - battle interface - intTmp->showingDialog->setn(false); - CCS->videoh->close(); -} \ No newline at end of file diff --git a/client/BattleInterface/CBattleResultWindow.h b/client/BattleInterface/CBattleResultWindow.h deleted file mode 100644 index ecb97ff0f..000000000 --- a/client/BattleInterface/CBattleResultWindow.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "../UIFramework/CIntObject.h" - -struct SDL_Surface; -class AdventureMapButton; -class CBattleInterface; -struct SDL_Rect; -struct BattleResult; - -/* - * CBattleResultWindow.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Class which is responsible for showing the battle result window -class CBattleResultWindow : public CIntObject -{ -private: - SDL_Surface *background; - AdventureMapButton *exit; - CBattleInterface *owner; -public: - CBattleResultWindow(const BattleResult &br, const SDL_Rect &pos, CBattleInterface *_owner); //c-tor - ~CBattleResultWindow(); //d-tor - - void bExitf(); //exit button callback - - void activate(); - void deactivate(); - void show(SDL_Surface * to = 0); -}; \ No newline at end of file diff --git a/client/BattleInterface/CBattleStackAnimation.cpp b/client/BattleInterface/CBattleStackAnimation.cpp deleted file mode 100644 index f6dd972db..000000000 --- a/client/BattleInterface/CBattleStackAnimation.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "StdInc.h" -#include "CBattleStackAnimation.h" - -#include "CBattleInterface.h" -#include "../../lib/BattleState.h" - -CBattleStackAnimation::CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack) -: CBattleAnimation(_owner), stack(_stack) -{ -} - -bool CBattleStackAnimation::isToReverseHlp(SBattleHex hexFrom, SBattleHex hexTo, bool curDir) -{ - int fromMod = hexFrom % GameConstants::BFIELD_WIDTH; - int fromDiv = hexFrom / GameConstants::BFIELD_WIDTH; - int toMod = hexTo % GameConstants::BFIELD_WIDTH; - - if(curDir && fromMod < toMod) - return false; - else if(curDir && fromMod > toMod) - return true; - else if(curDir && fromMod == toMod) - { - return fromDiv % 2 == 0; - } - else if(!curDir && fromMod < toMod) - return true; - else if(!curDir && fromMod > toMod) - return false; - else if(!curDir && fromMod == toMod) - { - return fromDiv % 2 == 1; - } - tlog1 << "Catastrope in CBattleStackAnimation::isToReverse!" << std::endl; - return false; //should never happen -} - -bool CBattleStackAnimation::isToReverse(SBattleHex hexFrom, SBattleHex hexTo, bool curDir, bool toDoubleWide, bool toDir) -{ - if(hexTo < 0) //turret - return false; - - if(toDoubleWide) - { - return isToReverseHlp(hexFrom, hexTo, curDir) && - (toDir ? isToReverseHlp(hexFrom, hexTo-1, curDir) : isToReverseHlp(hexFrom, hexTo+1, curDir) ); - } - else - { - return isToReverseHlp(hexFrom, hexTo, curDir); - } -} - -CCreatureAnimation* CBattleStackAnimation::myAnim() -{ - return owner->creAnims[stack->ID]; -} \ No newline at end of file diff --git a/client/BattleInterface/CBattleStackAnimation.h b/client/BattleInterface/CBattleStackAnimation.h deleted file mode 100644 index 4e9ef9f62..000000000 --- a/client/BattleInterface/CBattleStackAnimation.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "CBattleAnimation.h" -#include "../../lib/SBattleHex.h" - -class CStack; -class CBattleInterface; -class CCreatureAnimation; - -/* - * CBattleStackAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Sub-class which is responsible for managing the battle stack animation. -class CBattleStackAnimation : public CBattleAnimation -{ -public: - const CStack * stack; //id of stack whose animation it is - - CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack); - static bool isToReverseHlp(SBattleHex hexFrom, SBattleHex hexTo, bool curDir); //helper for isToReverse - static bool isToReverse(SBattleHex hexFrom, SBattleHex hexTo, bool curDir /*if true, creature is in attacker's direction*/, bool toDoubleWide, bool toDir); //determines if creature should be reversed (it stands on hexFrom and should 'see' hexTo) - - CCreatureAnimation *myAnim(); //animation for our stack -}; \ No newline at end of file diff --git a/client/BattleInterface/CClickableHex.cpp b/client/BattleInterface/CClickableHex.cpp deleted file mode 100644 index a2f6142cd..000000000 --- a/client/BattleInterface/CClickableHex.cpp +++ /dev/null @@ -1,148 +0,0 @@ -#include "StdInc.h" -#include "CClickableHex.h" -#include "CBattleInterface.h" -#include "../../lib/BattleState.h" -#include "../CGameInfo.h" -#include "../CPlayerInterface.h" -#include "../../lib/CTownHandler.h" -#include "../Graphics.h" -#include "../../CCallback.h" -#include "../../lib/CGeneralTextHandler.h" -#include "../SDL_Extensions.h" -#include "../GUIClasses.h" -#include "CBattleConsole.h" -#include "../UIFramework/CGuiHandler.h" - -SPoint CClickableHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * stack, const CBattleInterface * cbi) -{ - SPoint ret(-500, -500); //returned value - if(stack && stack->position < 0) //creatures in turrets - { - switch(stack->position) - { - case -2: //keep - ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][17]; - break; - case -3: //lower turret - ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][18]; - break; - case -4: //upper turret - ret = graphics->wallPositions[cbi->siegeH->town->town->typeID][19]; - break; - } - } - else - { - ret.y = -139 + 42 * (hexNum/GameConstants::BFIELD_WIDTH); //counting y - //counting x - if(attacker) - { - ret.x = -160 + 22 * ( ((hexNum/GameConstants::BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % GameConstants::BFIELD_WIDTH); - } - else - { - ret.x = -219 + 22 * ( ((hexNum/GameConstants::BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % GameConstants::BFIELD_WIDTH); - } - //shifting position for double - hex creatures - if(stack && stack->doubleWide()) - { - if(attacker) - { - ret.x -= 44; - } - else - { - ret.x += 45; - } - } - } - //returning - return ret +CPlayerInterface::battleInt->pos; -} -void CClickableHex::activate() -{ - activateHover(); - activateMouseMove(); - activateLClick(); - activateRClick(); -} - -void CClickableHex::deactivate() -{ - deactivateHover(); - deactivateMouseMove(); - deactivateLClick(); - deactivateRClick(); -} - -void CClickableHex::hover(bool on) -{ - hovered = on; - //Hoverable::hover(on); - if(!on && setAlterText) - { - myInterface->console->alterTxt = std::string(); - setAlterText = false; - } -} - -CClickableHex::CClickableHex() : setAlterText(false), myNumber(-1), accessible(true), hovered(false), strictHovered(false), myInterface(NULL) -{ -} - -void CClickableHex::mouseMoved(const SDL_MouseMotionEvent &sEvent) -{ - if(myInterface->cellShade) - { - if(CSDL_Ext::SDL_GetPixel(myInterface->cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex - { - strictHovered = false; - } - else //hovered pixel is inside hex - { - strictHovered = true; - } - } - - if(hovered && strictHovered) //print attacked creature to console - { - const CStack * attackedStack = myInterface->curInt->cb->battleGetStackByPos(myNumber); - if(myInterface->console->alterTxt.size() == 0 &&attackedStack != NULL && - attackedStack->owner != myInterface->curInt->playerID && - attackedStack->alive()) - { - char tabh[160]; - const std::string & attackedName = attackedStack->count == 1 ? attackedStack->getCreature()->nameSing : attackedStack->getCreature()->namePl; - sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); - myInterface->console->alterTxt = std::string(tabh); - setAlterText = true; - } - } - else if(setAlterText) - { - myInterface->console->alterTxt = std::string(); - setAlterText = false; - } -} - -void CClickableHex::clickLeft(tribool down, bool previousState) -{ - if(!down && hovered && strictHovered) //we've been really clicked! - { - myInterface->hexLclicked(myNumber); - } -} - -void CClickableHex::clickRight(tribool down, bool previousState) -{ - const CStack * myst = myInterface->curInt->cb->battleGetStackByPos(myNumber); //stack info - if(hovered && strictHovered && myst!=NULL) - { - - if(!myst->alive()) return; - if(down) - { - GH.pushInt(createCreWindow(myst)); - } - } -} \ No newline at end of file diff --git a/client/BattleInterface/CClickableHex.h b/client/BattleInterface/CClickableHex.h deleted file mode 100644 index 3ce60d28c..000000000 --- a/client/BattleInterface/CClickableHex.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include "../UIFramework/CIntObject.h" - -class CBattleInterface; -class CStack; -struct SDL_MouseMotionEvent; - -/* - * CClickableHex.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Class which stands for a single hex field on a battlefield -class CClickableHex : public CIntObject -{ -private: - bool setAlterText; //if true, this hex has set alternative text in console and will clean it -public: - ui32 myNumber; //number of hex in commonly used format - bool accessible; //if true, this hex is accessible for units - //CStack * ourStack; - bool hovered, strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering) - CBattleInterface * myInterface; //interface that owns me - static SPoint getXYUnitAnim(const int &hexNum, const bool &attacker, const CStack *creature, const CBattleInterface *cbi); //returns (x, y) of left top corner of animation - - //for user interactions - void hover (bool on); - void activate(); - void deactivate(); - void mouseMoved (const SDL_MouseMotionEvent &sEvent); - void clickLeft(tribool down, bool previousState); - void clickRight(tribool down, bool previousState); - CClickableHex(); -}; \ No newline at end of file diff --git a/client/BattleInterface/CCreatureAnimation.cpp b/client/BattleInterface/CCreatureAnimation.cpp index 4658695ca..54d1d5daa 100644 --- a/client/BattleInterface/CCreatureAnimation.cpp +++ b/client/BattleInterface/CCreatureAnimation.cpp @@ -4,7 +4,7 @@ #include "../../lib/CLodHandler.h" #include "../../lib/VCMI_Lib.h" #include "../../lib/vcmi_endian.h" -#include "../SDL_Extensions.h" +#include "../UIFramework/SDL_Extensions.h" /* * CCreatureAnimation.cpp, part of VCMI engine diff --git a/client/BattleInterface/CDefenceAnimation.cpp b/client/BattleInterface/CDefenceAnimation.cpp deleted file mode 100644 index 0c32ec23c..000000000 --- a/client/BattleInterface/CDefenceAnimation.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include "StdInc.h" -#include "CDefenceAnimation.h" - -#include "CBattleInterface.h" -#include "../CGameInfo.h" -#include "CCreatureAnimation.h" -#include "../CPlayerInterface.h" -#include "../CMusicHandler.h" -#include "../../lib/BattleState.h" -#include "CReverseAnimation.h" -#include "CAttackAnimation.h" -#include "CShootingAnimation.h" - -bool CDefenceAnimation::init() -{ - //checking initial conditions - - //if(owner->creAnims[stackID]->getType() != 2) - //{ - // return false; - //} - - if(attacker == NULL && owner->battleEffects.size() > 0) - return false; - - ui32 lowestMoveID = owner->animIDhelper + 5; - for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - CDefenceAnimation * defAnim = dynamic_cast(it->first); - if(defAnim && defAnim->stack->ID != stack->ID) - continue; - - CAttackAnimation * attAnim = dynamic_cast(it->first); - if(attAnim && attAnim->stack->ID != stack->ID) - continue; - - if(attacker != NULL) - { - int attackerAnimType = owner->creAnims[attacker->ID]->getType(); - if( attackerAnimType == 11 && attackerAnimType == 12 && attackerAnimType == 13 && owner->creAnims[attacker->ID]->getFrame() < attacker->getCreature()->attackClimaxFrame ) - return false; - } - - CReverseAnimation * animAsRev = dynamic_cast(it->first); - - if(animAsRev && animAsRev->priority) - return false; - - if(it->first) - vstd::amin(lowestMoveID, it->first->ID); - } - if(ID > lowestMoveID) - return false; - - - - //reverse unit if necessary - if(attacker && isToReverse(stack->position, attacker->position, owner->creDir[stack->ID], attacker->doubleWide(), owner->creDir[attacker->ID])) - { - owner->addNewAnim(new CReverseAnimation(owner, stack, stack->position, true)); - return false; - } - //unit reversed - - if(byShooting) //delay hit animation - { - for(std::list::const_iterator it = owner->projectiles.begin(); it != owner->projectiles.end(); ++it) - { - if(it->creID == attacker->getCreature()->idNumber) - { - return false; - } - } - } - - //initializing - if(killed) - { - CCS->soundh->playSound(battle_sound(stack->getCreature(), killed)); - myAnim()->setType(CCreatureAnim::DEATH); //death - } - else - { - // TODO: this block doesn't seems correct if the unit is defending. - CCS->soundh->playSound(battle_sound(stack->getCreature(), wince)); - myAnim()->setType(CCreatureAnim::HITTED); //getting hit - } - - return true; //initialized successfuly -} - -void CDefenceAnimation::nextFrame() -{ - if(!killed && myAnim()->getType() != CCreatureAnim::HITTED) - { - myAnim()->setType(CCreatureAnim::HITTED); - } - - if(!myAnim()->onLastFrameInGroup()) - { - if( myAnim()->getType() == CCreatureAnim::DEATH && (owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0 - && !myAnim()->onLastFrameInGroup() ) - { - myAnim()->incrementFrame(); - } - } - else - { - endAnim(); - } - -} - -void CDefenceAnimation::endAnim() -{ - //restoring animType - - if(myAnim()->getType() == CCreatureAnim::HITTED) - myAnim()->setType(CCreatureAnim::HOLDING); - - //printing info to console - - //if(attacker!=NULL) - // owner->printConsoleAttacked(stack, dmg, amountKilled, attacker); - - //const CStack * attacker = owner->curInt->cb->battleGetStackByID(IDby, false); - //const CStack * attacked = owner->curInt->cb->battleGetStackByID(stackID, false); - - CBattleAnimation::endAnim(); - - delete this; -} - -CDefenceAnimation::CDefenceAnimation(SStackAttackedInfo _attackedInfo, CBattleInterface * _owner) -: CBattleStackAnimation(_owner, _attackedInfo.defender), dmg(_attackedInfo.dmg), -amountKilled(_attackedInfo.amountKilled), attacker(_attackedInfo.attacker), byShooting(_attackedInfo.byShooting), -killed(_attackedInfo.killed) -{ -} \ No newline at end of file diff --git a/client/BattleInterface/CDefenceAnimation.h b/client/BattleInterface/CDefenceAnimation.h deleted file mode 100644 index 0d35509b4..000000000 --- a/client/BattleInterface/CDefenceAnimation.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "CBattleStackAnimation.h" -#include "SStackAttackedInfo.h" - -class CStack; - -/* - * CDefenceAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Animation of a defending unit -class CDefenceAnimation : public CBattleStackAnimation -{ -private: - //std::vector attackedInfos; - int dmg; //damage dealt - int amountKilled; //how many creatures in stack has been killed - const CStack * attacker; //attacking stack - bool byShooting; //if true, stack has been attacked by shooting - bool killed; //if true, stack has been killed -public: - bool init(); - void nextFrame(); - void endAnim(); - - CDefenceAnimation(SStackAttackedInfo _attackedInfo, CBattleInterface * _owner); -}; \ No newline at end of file diff --git a/client/BattleInterface/CDummyAnimation.cpp b/client/BattleInterface/CDummyAnimation.cpp deleted file mode 100644 index 4040af1de..000000000 --- a/client/BattleInterface/CDummyAnimation.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "StdInc.h" -#include "CDummyAnimation.h" - -#include "CBattleInterface.h" - -bool CDummyAnimation::init() -{ - return true; -} - -void CDummyAnimation::nextFrame() -{ - counter++; - if(counter > howMany) - endAnim(); -} - -void CDummyAnimation::endAnim() -{ - CBattleAnimation::endAnim(); - - delete this; -} - -CDummyAnimation::CDummyAnimation(CBattleInterface * _owner, int howManyFrames) : CBattleAnimation(_owner), counter(0), howMany(howManyFrames) -{ -} \ No newline at end of file diff --git a/client/BattleInterface/CDummyAnimation.h b/client/BattleInterface/CDummyAnimation.h deleted file mode 100644 index ec6f37153..000000000 --- a/client/BattleInterface/CDummyAnimation.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "CBattleAnimation.h" - -class CBattleInterface; - -/* - * CDummyAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -class CDummyAnimation : public CBattleAnimation -{ -private: - int counter; - int howMany; -public: - bool init(); - void nextFrame(); - void endAnim(); - - CDummyAnimation(CBattleInterface *_owner, int howManyFrames); -}; \ No newline at end of file diff --git a/client/BattleInterface/CMeleeAttackAnimation.cpp b/client/BattleInterface/CMeleeAttackAnimation.cpp deleted file mode 100644 index 7116a6a63..000000000 --- a/client/BattleInterface/CMeleeAttackAnimation.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include "StdInc.h" -#include "CMeleeAttackAnimation.h" - -#include "CBattleInterface.h" -#include "CCreatureAnimation.h" -#include "../../lib/BattleState.h" -#include "CReverseAnimation.h" - -bool CMeleeAttackAnimation::init() -{ - if( !CAttackAnimation::checkInitialConditions() ) - return false; - - //if(owner->creAnims[stackID]->getType()!=2) - //{ - // return false; - //} - - if(!attackingStack || myAnim()->getType() == 5) - { - endAnim(); - - return false; - } - - bool toReverse = isToReverse(attackingStackPosBeforeReturn, dest, owner->creDir[stack->ID], attackedStack->doubleWide(), owner->creDir[attackedStack->ID]); - - if(toReverse) - { - - owner->addNewAnim(new CReverseAnimation(owner, stack, attackingStackPosBeforeReturn, true)); - return false; - } - //reversed - - shooting = false; - - static const CCreatureAnim::EAnimType mutPosToGroup[] = {CCreatureAnim::ATTACK_UP, CCreatureAnim::ATTACK_UP, - CCreatureAnim::ATTACK_FRONT, CCreatureAnim::ATTACK_DOWN, CCreatureAnim::ATTACK_DOWN, CCreatureAnim::ATTACK_FRONT}; - - int revShiftattacker = (attackingStack->attackerOwned ? -1 : 1); - - int mutPos = SBattleHex::mutualPosition(attackingStackPosBeforeReturn, dest); - if(mutPos == -1 && attackingStack->doubleWide()) - { - mutPos = SBattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->position); - } - if (mutPos == -1 && attackedStack->doubleWide()) - { - mutPos = SBattleHex::mutualPosition(attackingStackPosBeforeReturn, attackedStack->occupiedHex()); - } - if (mutPos == -1 && attackedStack->doubleWide() && attackingStack->doubleWide()) - { - mutPos = SBattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->occupiedHex()); - } - - - switch(mutPos) //attack direction - { - case 0: case 1: case 2: case 3: case 4: case 5: - group = mutPosToGroup[mutPos]; - break; - default: - tlog1<<"Critical Error! Wrong dest in stackAttacking! dest: "< >::const_iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - CBattleMoveStart * anim = dynamic_cast(it->first); - CReverseAnim * anim2 = dynamic_cast(it->first); - if( (anim && anim->stackID == stackID) || (anim2 && anim2->stackID == stackID ) ) - return; - }*/ - - CAttackAnimation::nextFrame(); -} - -void CMeleeAttackAnimation::endAnim() -{ - CBattleAnimation::endAnim(); - - delete this; -} - -CMeleeAttackAnimation::CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, SBattleHex _dest, const CStack * _attacked) - : CAttackAnimation(_owner, attacker, _dest, _attacked) -{ -} \ No newline at end of file diff --git a/client/BattleInterface/CMeleeAttackAnimation.h b/client/BattleInterface/CMeleeAttackAnimation.h deleted file mode 100644 index 3afd64872..000000000 --- a/client/BattleInterface/CMeleeAttackAnimation.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "CAttackAnimation.h" - - -class CBattleInterface; -class CStack; - -/* - * CMeleeAttackAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Hand-to-hand attack -class CMeleeAttackAnimation : public CAttackAnimation -{ -public: - bool init(); - void nextFrame(); - void endAnim(); - - CMeleeAttackAnimation(CBattleInterface *_owner, const CStack *attacker, SBattleHex _dest, const CStack *_attacked); -}; \ No newline at end of file diff --git a/client/BattleInterface/CMovementAnimation.cpp b/client/BattleInterface/CMovementAnimation.cpp deleted file mode 100644 index b86f0c503..000000000 --- a/client/BattleInterface/CMovementAnimation.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include "StdInc.h" -#include "CMovementAnimation.h" - -#include "CBattleInterface.h" -#include "CCreatureAnimation.h" -#include "../../lib/BattleState.h" -#include "../CGameInfo.h" -#include "../CMusicHandler.h" -#include "CReverseAnimation.h" -#include "CMovementEndAnimation.h" -#include "CClickableHex.h" - -bool CMovementAnimation::init() -{ - if( !isEarliest(false) ) - return false; - - //a few useful variables - steps = static_cast(myAnim()->framesInGroup(CCreatureAnim::MOVING) * owner->getAnimSpeedMultiplier() - 1); - if(steps == 0) //this creature seems to have no move animation so we can end it immediately - { - endAnim(); - return false; - } - whichStep = 0; - int hexWbase = 44, hexHbase = 42; - const CStack * movedStack = stack; - if(!movedStack || myAnim()->getType() == 5) - { - endAnim(); - return false; - } - //bool twoTiles = movedStack->doubleWide(); - - SPoint begPosition = CClickableHex::getXYUnitAnim(curStackPos, movedStack->attackerOwned, movedStack, owner); - SPoint endPosition = CClickableHex::getXYUnitAnim(nextHex, movedStack->attackerOwned, movedStack, owner); - - int mutPos = SBattleHex::mutualPosition(curStackPos, nextHex); - - //reverse unit if necessary - if((begPosition.x > endPosition.x) && owner->creDir[stack->ID] == true) - { - owner->addNewAnim(new CReverseAnimation(owner, stack, curStackPos, true)); - return false; - } - else if ((begPosition.x < endPosition.x) && owner->creDir[stack->ID] == false) - { - owner->addNewAnim(new CReverseAnimation(owner, stack, curStackPos, true)); - return false; - } - - if(myAnim()->getType() != CCreatureAnim::MOVING) - { - myAnim()->setType(CCreatureAnim::MOVING); - } - //unit reversed - - // if(owner->moveSh <= 0) - // owner->moveSh = CCS->soundh->playSound(battle_sound(movedStack->getCreature(), move), -1); - - //step shift calculation - posX = myAnim()->pos.x, posY = myAnim()->pos.y; // for precise calculations ;] - if(mutPos == -1 && movedStack->hasBonusOfType(Bonus::FLYING)) - { - steps *= distance; - steps /= 2; //to make animation faster - - stepX = (endPosition.x - begPosition.x) / static_cast(steps); - stepY = (endPosition.y - begPosition.y) / static_cast(steps); - } - else - { - switch(mutPos) - { - case 0: - stepX = -1.0 * (hexWbase / (2.0 * steps)); - stepY = -1.0 * (hexHbase / (static_cast(steps))); - break; - case 1: - stepX = hexWbase / (2.0 * steps); - stepY = -1.0 * hexHbase / (static_cast(steps)); - break; - case 2: - stepX = hexWbase / static_cast(steps); - stepY = 0.0; - break; - case 3: - stepX = hexWbase / (2.0 * steps); - stepY = hexHbase / static_cast(steps); - break; - case 4: - stepX = -1.0 * hexWbase / (2.0 * steps); - stepY = hexHbase / static_cast(steps); - break; - case 5: - stepX = -1.0 * hexWbase / static_cast(steps); - stepY = 0.0; - break; - } - } - //step shifts calculated - - return true; -} - -void CMovementAnimation::nextFrame() -{ - //moving instructions - posX += stepX; - myAnim()->pos.x = static_cast(posX); - posY += stepY; - myAnim()->pos.y = static_cast(posY); - - // Increments step count and check if we are finished with current animation - ++whichStep; - if(whichStep == steps) - { - // Sets the position of the creature animation sprites - SPoint coords = CClickableHex::getXYUnitAnim(nextHex, owner->creDir[stack->ID], stack, owner); - myAnim()->pos = coords; - - // true if creature haven't reached the final destination hex - if ((nextPos + 1) < destTiles.size()) - { - // update the next hex field which has to be reached by the stack - nextPos++; - curStackPos = nextHex; - nextHex = destTiles[nextPos]; - - // update position of double wide creatures - bool twoTiles = stack->doubleWide(); - if(twoTiles && bool(stack->attackerOwned) && (owner->creDir[stack->ID] != bool(stack->attackerOwned) )) //big attacker creature is reversed - myAnim()->pos.x -= 44; - else if(twoTiles && (! bool(stack->attackerOwned) ) && (owner->creDir[stack->ID] != bool(stack->attackerOwned) )) //big defender creature is reversed - myAnim()->pos.x += 44; - - // re-init animation - for(std::list >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - if (it->first == this) - { - it->second = false; - break; - } - } - } - else - endAnim(); - } -} - -void CMovementAnimation::endAnim() -{ - const CStack * movedStack = stack; - - CBattleAnimation::endAnim(); - - if(movedStack) - owner->addNewAnim(new CMovementEndAnimation(owner, stack, nextHex)); - - - if(owner->moveSh >= 0) - { - CCS->soundh->stopSound(owner->moveSh); - owner->moveSh = -1; - } - - delete this; -} - -CMovementAnimation::CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector _destTiles, int _distance) -: CBattleStackAnimation(_owner, _stack), destTiles(_destTiles), nextPos(0), distance(_distance), stepX(0.0), stepY(0.0) -{ - curStackPos = stack->position; - nextHex = destTiles.front(); -} \ No newline at end of file diff --git a/client/BattleInterface/CMovementAnimation.h b/client/BattleInterface/CMovementAnimation.h deleted file mode 100644 index 3d7cba533..000000000 --- a/client/BattleInterface/CMovementAnimation.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "CBattleStackAnimation.h" - - -class CBattleInterface; -class CStack; - -/* - * CMovementAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Move animation of a creature -class CMovementAnimation : public CBattleStackAnimation -{ -private: - std::vector destTiles; //destination - SBattleHex nextHex; - ui32 nextPos; - int distance; - double stepX, stepY; //how far stack is moved in one frame - double posX, posY; - int steps, whichStep; - int curStackPos; //position of stack before move -public: - bool init(); - void nextFrame(); - void endAnim(); - - CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector _destTiles, int _distance); -}; \ No newline at end of file diff --git a/client/BattleInterface/CMovementEndAnimation.cpp b/client/BattleInterface/CMovementEndAnimation.cpp deleted file mode 100644 index fbc80ae2f..000000000 --- a/client/BattleInterface/CMovementEndAnimation.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "StdInc.h" -#include "CMovementEndAnimation.h" - -#include "CCreatureAnimation.h" -#include "../CMusicHandler.h" -#include "../CGameInfo.h" -#include "../../lib/BattleState.h" -#include "../CCursorHandler.h" - -bool CMovementEndAnimation::init() -{ - if( !isEarliest(true) ) - return false; - - if(!stack || myAnim()->framesInGroup(CCreatureAnim::MOVE_END) == 0 || - myAnim()->getType() == CCreatureAnim::DEATH) - { - endAnim(); - - return false; - } - - CCS->soundh->playSound(battle_sound(stack->getCreature(), endMoving)); - - myAnim()->setType(CCreatureAnim::MOVE_END); - - return true; -} - -void CMovementEndAnimation::nextFrame() -{ - if(myAnim()->onLastFrameInGroup()) - { - endAnim(); - } -} - -void CMovementEndAnimation::endAnim() -{ - CBattleAnimation::endAnim(); - - if(myAnim()->getType() != CCreatureAnim::DEATH) - myAnim()->setType(CCreatureAnim::HOLDING); //resetting to default - - CCS->curh->show(); - delete this; -} - -CMovementEndAnimation::CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, SBattleHex destTile) -: CBattleStackAnimation(_owner, _stack), destinationTile(destTile) -{ -} \ No newline at end of file diff --git a/client/BattleInterface/CMovementEndAnimation.h b/client/BattleInterface/CMovementEndAnimation.h deleted file mode 100644 index 0db777d69..000000000 --- a/client/BattleInterface/CMovementEndAnimation.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include "CBattleStackAnimation.h" - - -class CBattleInterface; -class CStack; - -/* - * CMovementEndAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Move end animation of a creature -class CMovementEndAnimation : public CBattleStackAnimation -{ -private: - SBattleHex destinationTile; -public: - bool init(); - void nextFrame(); - void endAnim(); - - CMovementEndAnimation(CBattleInterface *_owner, const CStack *_stack, SBattleHex destTile); -}; \ No newline at end of file diff --git a/client/BattleInterface/CMovementStartAnimation.cpp b/client/BattleInterface/CMovementStartAnimation.cpp deleted file mode 100644 index 0a00db716..000000000 --- a/client/BattleInterface/CMovementStartAnimation.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "StdInc.h" -#include "CMovementStartAnimation.h" - -#include "../CMusicHandler.h" -#include "CBattleInterface.h" -#include "../CGameInfo.h" -#include "CCreatureAnimation.h" -#include "../../lib/BattleState.h" -#include "../CPlayerInterface.h" - -bool CMovementStartAnimation::init() -{ - if( !isEarliest(false) ) - return false; - - - if(!stack || myAnim()->getType() == 5) - { - CMovementStartAnimation::endAnim(); - return false; - } - - CCS->soundh->playSound(battle_sound(stack->getCreature(), startMoving)); - myAnim()->setType(CCreatureAnim::MOVE_START); - - return true; -} - -void CMovementStartAnimation::nextFrame() -{ - if(myAnim()->onLastFrameInGroup()) - { - endAnim(); - } - else - { - if((owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0) - myAnim()->incrementFrame(); - } -} - -void CMovementStartAnimation::endAnim() -{ - CBattleAnimation::endAnim(); - - delete this; -} - -CMovementStartAnimation::CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack) -: CBattleStackAnimation(_owner, _stack) -{ -} \ No newline at end of file diff --git a/client/BattleInterface/CMovementStartAnimation.h b/client/BattleInterface/CMovementStartAnimation.h deleted file mode 100644 index 582bbb4ab..000000000 --- a/client/BattleInterface/CMovementStartAnimation.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "CBattleStackAnimation.h" - -class CBattleInterface; -class CStack; - -/* - * CMovementStartAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Move start animation of a creature -class CMovementStartAnimation : public CBattleStackAnimation -{ -public: - bool init(); - void nextFrame(); - void endAnim(); - - CMovementStartAnimation(CBattleInterface *_owner, const CStack *_stack); -}; \ No newline at end of file diff --git a/client/BattleInterface/CReverseAnimation.cpp b/client/BattleInterface/CReverseAnimation.cpp deleted file mode 100644 index 951974e6e..000000000 --- a/client/BattleInterface/CReverseAnimation.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "StdInc.h" -#include "CReverseAnimation.h" - -#include "CCreatureAnimation.h" -#include "../../lib/BattleState.h" -#include "CBattleInterface.h" -#include "CClickableHex.h" - -bool CReverseAnimation::init() -{ - if(myAnim() == NULL || myAnim()->getType() == 5) - { - endAnim(); - - return false; //there is no such creature - } - - if(!priority && !isEarliest(false)) - return false; - - if(myAnim()->framesInGroup(CCreatureAnim::TURN_R)) - myAnim()->setType(CCreatureAnim::TURN_R); - else - setupSecondPart(); - - - return true; -} - -void CReverseAnimation::nextFrame() -{ - if(partOfAnim == 1) //first part of animation - { - if(myAnim()->onLastFrameInGroup()) - { - partOfAnim = 2; - } - } - else if(partOfAnim == 2) - { - if(!secondPartSetup) - { - setupSecondPart(); - } - if(myAnim()->onLastFrameInGroup()) - { - endAnim(); - } - } -} - -void CReverseAnimation::endAnim() -{ - CBattleAnimation::endAnim(); - if( stack->alive() )//don't do that if stack is dead - myAnim()->setType(CCreatureAnim::HOLDING); - - delete this; -} - -CReverseAnimation::CReverseAnimation(CBattleInterface * _owner, const CStack * stack, SBattleHex dest, bool _priority) -: CBattleStackAnimation(_owner, stack), partOfAnim(1), secondPartSetup(false), hex(dest), priority(_priority) -{ -} - -void CReverseAnimation::setupSecondPart() -{ - owner->creDir[stack->ID] = !owner->creDir[stack->ID]; - - if(!stack) - { - endAnim(); - return; - } - - SPoint coords = CClickableHex::getXYUnitAnim(hex, owner->creDir[stack->ID], stack, owner); - myAnim()->pos.x = coords.x; - //creAnims[stackID]->pos.y = coords.second; - - if(stack->doubleWide()) - { - if(stack->attackerOwned) - { - if(!owner->creDir[stack->ID]) - myAnim()->pos.x -= 44; - } - else - { - if(owner->creDir[stack->ID]) - myAnim()->pos.x += 44; - } - } - - secondPartSetup = true; - - if(myAnim()->framesInGroup(CCreatureAnim::TURN_L)) - myAnim()->setType(CCreatureAnim::TURN_L); - else - endAnim(); -} \ No newline at end of file diff --git a/client/BattleInterface/CReverseAnimation.h b/client/BattleInterface/CReverseAnimation.h deleted file mode 100644 index dac230e0b..000000000 --- a/client/BattleInterface/CReverseAnimation.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "CBattleStackAnimation.h" - - -class CStack; - -/* - * CReverseAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Class responsible for animation of stack chaning direction (left <-> right) -class CReverseAnimation : public CBattleStackAnimation -{ -private: - int partOfAnim; //1 - first, 2 - second - bool secondPartSetup; - SBattleHex hex; -public: - bool priority; //true - high, false - low - bool init(); - void nextFrame(); - - void setupSecondPart(); - void endAnim(); - - CReverseAnimation(CBattleInterface *_owner, const CStack *stack, SBattleHex dest, bool _priority); -}; \ No newline at end of file diff --git a/client/BattleInterface/CShootingAnimation.cpp b/client/BattleInterface/CShootingAnimation.cpp deleted file mode 100644 index 8f2f1c247..000000000 --- a/client/BattleInterface/CShootingAnimation.cpp +++ /dev/null @@ -1,192 +0,0 @@ -#include "StdInc.h" -#include -#include "CShootingAnimation.h" - -#include "../../lib/BattleState.h" -#include "CBattleInterface.h" -#include "CCreatureAnimation.h" -#include "../CGameInfo.h" -#include "../../lib/CTownHandler.h" -#include "CMovementStartAnimation.h" -#include "CReverseAnimation.h" -#include "CSpellEffectAnimation.h" -#include "CClickableHex.h" - -bool CShootingAnimation::init() -{ - if( !CAttackAnimation::checkInitialConditions() ) - return false; - - const CStack * shooter = attackingStack; - - if(!shooter || myAnim()->getType() == 5) - { - endAnim(); - return false; - } - - // Create the projectile animation - - double projectileAngle; //in radians; if positive, projectiles goes up - double straightAngle = 0.2; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value) - int fromHex = shooter->position; - projectileAngle = atan2(static_cast(abs(dest - fromHex) / GameConstants::BFIELD_WIDTH), static_cast(abs(dest - fromHex) % GameConstants::BFIELD_WIDTH)); - if(fromHex < dest) - projectileAngle = -projectileAngle; - - // Get further info about the shooter e.g. relative pos of projectile to unit. - // If the creature id is 149 then it's a arrow tower which has no additional info so get the - // actual arrow tower shooter instead. - const CCreature *shooterInfo = shooter->getCreature(); - if (shooterInfo->idNumber == 149) - { - int creID = CGI->creh->factionToTurretCreature[owner->siegeH->town->town->typeID]; - shooterInfo = CGI->creh->creatures[creID]; - } - - SProjectileInfo spi; - spi.creID = shooter->getCreature()->idNumber; - spi.stackID = shooter->ID; - spi.reverse = !shooter->attackerOwned; - - spi.step = 0; - spi.frameNum = 0; - if(vstd::contains(CGI->creh->idToProjectileSpin, shooterInfo->idNumber)) - spi.spin = CGI->creh->idToProjectileSpin[shooterInfo->idNumber]; - else - { - tlog2 << "Warning - no projectile spin for spi.creID " << shooterInfo->idNumber << std::endl; - spi.spin = false; - } - - SPoint xycoord = CClickableHex::getXYUnitAnim(shooter->position, true, shooter, owner); - SPoint destcoord; - - - // The "master" point where all projectile positions relate to. - static const SPoint projectileOrigin(181, 252); - - if (attackedStack) - { - destcoord = CClickableHex::getXYUnitAnim(dest, false, attackedStack, owner); - destcoord.x += 250; destcoord.y += 210; //TODO: find a better place to shoot - - // Calculate projectile start position. Offsets are read out of the CRANIM.TXT. - if (projectileAngle > straightAngle) - { - //upper shot - spi.x = xycoord.x + projectileOrigin.x + shooterInfo->upperRightMissleOffsetX; - spi.y = xycoord.y + projectileOrigin.y + shooterInfo->upperRightMissleOffsetY; - } - else if (projectileAngle < -straightAngle) - { - //lower shot - spi.x = xycoord.x + projectileOrigin.x + shooterInfo->lowerRightMissleOffsetX; - spi.y = xycoord.y + projectileOrigin.y + shooterInfo->lowerRightMissleOffsetY; - } - else - { - //straight shot - spi.x = xycoord.x + projectileOrigin.x + shooterInfo->rightMissleOffsetX; - spi.y = xycoord.y + projectileOrigin.y + shooterInfo->rightMissleOffsetY; - } - - double animSpeed = 23.0 * owner->getAnimSpeed(); // flight speed of projectile - spi.lastStep = static_cast(sqrt(static_cast((destcoord.x - spi.x) * (destcoord.x - spi.x) + (destcoord.y - spi.y) * (destcoord.y - spi.y))) / animSpeed); - if(spi.lastStep == 0) - spi.lastStep = 1; - spi.dx = (destcoord.x - spi.x) / spi.lastStep; - spi.dy = (destcoord.y - spi.y) / spi.lastStep; - spi.catapultInfo = 0; - } - else - { - // Catapult attack - // These are the values for equations of this kind: f(x) = ax^2 + bx + c - static const std::vector trajectoryCurves = boost::assign::list_of(new SCatapultSProjectileInfo(4.309, -3.198, 569.2, -296, 182)) - (new SCatapultSProjectileInfo(4.710, -3.11, 558.68, -258, 175))(new SCatapultSProjectileInfo(5.056, -3.003, 546.9, -236, 174)) - (new SCatapultSProjectileInfo(4.760, -2.74, 526.47, -216, 215))(new SCatapultSProjectileInfo(4.288, -2.496, 508.98, -223, 274)) - (new SCatapultSProjectileInfo(3.683, -3.018, 558.39, -324, 176))(new SCatapultSProjectileInfo(2.884, -2.607, 528.95, -366, 312)) - (new SCatapultSProjectileInfo(3.783, -2.364, 501.35, -227, 318)); - - static std::map hexToCurve = boost::assign::map_list_of(29, 0)(62, 1)(95, 2)(130, 3)(182, 4)(12, 5)(50, 6)(183, 7); - - std::map::iterator it = hexToCurve.find(dest.hex); - - if (it == hexToCurve.end()) - { - tlog1 << "For the hex position " << dest.hex << " is no curve defined."; - endAnim(); - return false; - } - else - { - int curveID = it->second; - spi.catapultInfo = trajectoryCurves[curveID]; - double animSpeed = 3.318 * owner->getAnimSpeed(); - spi.lastStep = static_cast((spi.catapultInfo->toX - spi.catapultInfo->fromX) / animSpeed); - spi.dx = animSpeed; - spi.dy = 0; - spi.x = xycoord.x + projectileOrigin.x + shooterInfo->rightMissleOffsetX + 17.; - spi.y = xycoord.y + projectileOrigin.y + shooterInfo->rightMissleOffsetY + 10.; - - // Add explosion anim - int xEnd = static_cast(spi.x + spi.lastStep * spi.dx); - int yEnd = static_cast(spi.catapultInfo->calculateY(xEnd)); - owner->addNewAnim( new CSpellEffectAnimation(owner, "SGEXPL.DEF", xEnd - 126, yEnd - 105)); - } - } - - // Set starting frame - if(spi.spin) - { - spi.frameNum = 0; - } - else - { - double pi = boost::math::constants::pi(); - spi.frameNum = static_cast(((pi / 2.0 - projectileAngle) / (2.0 * pi) + 1/(static_cast(2*(owner->idToProjectile[spi.creID]->ourImages.size()-1)))) * (owner->idToProjectile[spi.creID]->ourImages.size()-1)); - } - - // Set projectile animation start delay which is specified in frames - spi.animStartDelay = shooterInfo->attackClimaxFrame; - owner->projectiles.push_back(spi); - - //attack animation - - shooting = true; - - if(projectileAngle > straightAngle) //upper shot - group = CCreatureAnim::SHOOT_UP; - else if(projectileAngle < -straightAngle) //lower shot - group = CCreatureAnim::SHOOT_DOWN; - else //straight shot - group = CCreatureAnim::SHOOT_FRONT; - - return true; -} - -void CShootingAnimation::nextFrame() -{ - for(std::list >::const_iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it) - { - CMovementStartAnimation * anim = dynamic_cast(it->first); - CReverseAnimation * anim2 = dynamic_cast(it->first); - if( (anim && anim->stack->ID == stack->ID) || (anim2 && anim2->stack->ID == stack->ID && anim2->priority ) ) - return; - } - - CAttackAnimation::nextFrame(); -} - -void CShootingAnimation::endAnim() -{ - CBattleAnimation::endAnim(); - delete this; -} - -CShootingAnimation::CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, SBattleHex _dest, const CStack * _attacked, bool _catapult, int _catapultDmg) - : CAttackAnimation(_owner, attacker, _dest, _attacked), catapultDamage(_catapultDmg), catapult(_catapult) -{ - -} \ No newline at end of file diff --git a/client/BattleInterface/CShootingAnimation.h b/client/BattleInterface/CShootingAnimation.h deleted file mode 100644 index a2f1890da..000000000 --- a/client/BattleInterface/CShootingAnimation.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "CAttackAnimation.h" -#include "../../lib/SBattleHex.h" - -class CBattleInterface; -class CStack; -struct SCatapultSProjectileInfo; - -/* - * CShootingAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Small struct which contains information about the position and the velocity of a projectile -struct SProjectileInfo -{ - double x, y; //position on the screen - double 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 stackID; //ID of stack - 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) - bool reverse; //if true, projectile will be flipped by vertical asix - SCatapultSProjectileInfo *catapultInfo; // holds info about the parabolic trajectory of the cannon -}; - -/// Shooting attack -class CShootingAnimation : public CAttackAnimation -{ -private: - int catapultDamage; - bool catapult; -public: - bool init(); - void nextFrame(); - void endAnim(); - - //last param only for catapult attacks - CShootingAnimation(CBattleInterface *_owner, const CStack *attacker, - SBattleHex _dest, const CStack *_attacked, bool _catapult = false, int _catapultDmg = 0); -}; \ No newline at end of file diff --git a/client/BattleInterface/CSpellEffectAnimation.cpp b/client/BattleInterface/CSpellEffectAnimation.cpp deleted file mode 100644 index 8e31b936d..000000000 --- a/client/BattleInterface/CSpellEffectAnimation.cpp +++ /dev/null @@ -1,182 +0,0 @@ -#include "StdInc.h" -#include "CSpellEffectAnimation.h" - -#include "../Graphics.h" -#include "CBattleInterface.h" -#include "../CDefHandler.h" -#include "../CPlayerInterface.h" -#include "../../CCallback.h" -#include "../../lib/BattleState.h" -#include "../SDL_Extensions.h" -#include "../UIFramework/SRect.h" - -//effect animation -bool CSpellEffectAnimation::init() -{ - if(!isEarliest(true)) - return false; - - if(effect == 12) //armageddon - { - if(effect == -1 || graphics->battleACToDef[effect].size() != 0) - { - CDefHandler * anim; - if(customAnim.size()) - anim = CDefHandler::giveDef(customAnim); - else - anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); - - if (Vflip) - { - for (size_t v = 0; v < anim->ourImages.size(); ++v) - { - CSDL_Ext::VflipSurf(anim->ourImages[v].bitmap); - } - } - - for(int i=0; i * anim->width < owner->pos.w ; ++i) - { - for(int j=0; j * anim->height < owner->pos.h ; ++j) - { - SBattleEffect be; - be.effectID = ID; - be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); - if (Vflip) - { - for (size_t v = 0; v < be.anim->ourImages.size(); ++v) - { - CSDL_Ext::VflipSurf(be.anim->ourImages[v].bitmap); - } - } - be.frame = 0; - be.maxFrame = be.anim->ourImages.size(); - be.x = i * anim->width + owner->pos.x; - be.y = j * anim->height + owner->pos.y; - - owner->battleEffects.push_back(be); - } - } - } - else //there is nothing to play - { - endAnim(); - return false; - } - } - else // Effects targeted at a specific creature/hex. - { - if(effect == -1 || graphics->battleACToDef[effect].size() != 0) - { - const CStack* destStack = owner->curInt->cb->battleGetStackByPos(destTile, false); - SRect &tilePos = owner->bfield[destTile].pos; - SBattleEffect be; - be.effectID = ID; - if(customAnim.size()) - be.anim = CDefHandler::giveDef(customAnim); - else - be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); - - if (Vflip) - { - for (size_t v = 0; v < be.anim->ourImages.size(); ++v) - { - CSDL_Ext::VflipSurf(be.anim->ourImages[v].bitmap); - } - } - - be.frame = 0; - be.maxFrame = be.anim->ourImages.size(); - if(effect == 1) - be.maxFrame = 3; - - switch (effect) - { - case -1: - be.x = x; - be.y = y; - break; - case 0: // Prayer and Lightning Bolt. - case 1: - // Position effect with it's bottom center touching the bottom center of affected tile(s). - be.x = tilePos.x + tilePos.w/2 - be.anim->width/2; - be.y = tilePos.y + tilePos.h - be.anim->height; - break; - - default: - // Position effect with it's center touching the top center of affected tile(s). - be.x = tilePos.x + tilePos.w/2 - be.anim->width/2; - be.y = tilePos.y - be.anim->height/2; - break; - } - - // Correction for 2-hex creatures. - if (destStack != NULL && destStack->doubleWide()) - be.x += (destStack->attackerOwned ? -1 : 1)*tilePos.w/2; - - owner->battleEffects.push_back(be); - } - else //there is nothing to play - { - endAnim(); - return false; - } - } - //battleEffects - return true; -} - -void CSpellEffectAnimation::nextFrame() -{ - //notice: there may be more than one effect in owner->battleEffects correcponding to this animation (ie. armageddon) - for(std::list::iterator it = owner->battleEffects.begin(); it != owner->battleEffects.end(); ++it) - { - if(it->effectID == ID) - { - ++(it->frame); - - if(it->frame == it->maxFrame) - { - endAnim(); - break; - } - else - { - it->x += dx; - it->y += dy; - } - } - } -} - -void CSpellEffectAnimation::endAnim() -{ - CBattleAnimation::endAnim(); - - std::vector::iterator> toDel; - - for(std::list::iterator it = owner->battleEffects.begin(); it != owner->battleEffects.end(); ++it) - { - if(it->effectID == ID) - { - toDel.push_back(it); - } - } - - for(size_t b = 0; b < toDel.size(); ++b) - { - delete toDel[b]->anim; - owner->battleEffects.erase(toDel[b]); - } - - delete this; -} - -CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, SBattleHex _destTile, int _dx, int _dy, bool _Vflip) -:CBattleAnimation(_owner), effect(_effect), destTile(_destTile), customAnim(""), dx(_dx), dy(_dy), Vflip(_Vflip) -{ -} - -CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx, int _dy, bool _Vflip) -:CBattleAnimation(_owner), effect(-1), destTile(0), customAnim(_customAnim), x(_x), y(_y), dx(_dx), dy(_dy), Vflip(_Vflip) -{ -} \ No newline at end of file diff --git a/client/BattleInterface/CSpellEffectAnimation.h b/client/BattleInterface/CSpellEffectAnimation.h deleted file mode 100644 index 2528e5072..000000000 --- a/client/BattleInterface/CSpellEffectAnimation.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - - -#include "CBattleAnimation.h" -#include "../../lib/SBattleHex.h" - -class CBattleInterface; - -/* - * CSpellEffectAnimation.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// This class manages a spell effect animation -class CSpellEffectAnimation : public CBattleAnimation -{ -private: - ui32 effect; - SBattleHex destTile; - std::string customAnim; - int x, y, dx, dy; - bool Vflip; -public: - bool init(); - void nextFrame(); - void endAnim(); - - CSpellEffectAnimation(CBattleInterface *_owner, ui32 _effect, SBattleHex _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false); - CSpellEffectAnimation(CBattleInterface *_owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false); -}; \ No newline at end of file diff --git a/client/BattleInterface/CStackQueue.cpp b/client/BattleInterface/CStackQueue.cpp deleted file mode 100644 index 4a6b07eeb..000000000 --- a/client/BattleInterface/CStackQueue.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include "StdInc.h" -#include "CStackQueue.h" - -#include "CBattleInterface.h" -#include "../../lib/BattleState.h" -#include "../Graphics.h" -#include "../SDL_Extensions.h" -#include "../CPlayerInterface.h" -#include "../CBitmapHandler.h" -#include "../../CCallback.h" -#include "../UIFramework/CGuiHandler.h" - -void CStackQueue::update() -{ - stacksSorted.clear(); - owner->curInt->cb->getStackQueue(stacksSorted, QUEUE_SIZE); - for (int i = 0; i < QUEUE_SIZE ; i++) - { - stackBoxes[i]->setStack(stacksSorted[i]); - } -} - -CStackQueue::CStackQueue(bool Embedded, CBattleInterface * _owner) -:embedded(Embedded), owner(_owner) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - if(embedded) - { - box = NULL; - bg = NULL; - pos.w = QUEUE_SIZE * 37; - pos.h = 32; //height of small creature img - pos.x = screen->w/2 - pos.w/2; - pos.y = (screen->h - 600)/2 + 10; - } - else - { - box = BitmapHandler::loadBitmap("CHRROP.pcx"); - bg = BitmapHandler::loadBitmap("DIBOXPI.pcx"); - pos.w = 600; - pos.h = bg->h; - } - - stackBoxes.resize(QUEUE_SIZE); - for (int i = 0; i < QUEUE_SIZE; i++) - { - stackBoxes[i] = new StackBox(box); - stackBoxes[i]->pos.x += 6 + (embedded ? 37 : 79)*i; - } -} - -CStackQueue::~CStackQueue() -{ - SDL_FreeSurface(box); -} - -void CStackQueue::showAll( SDL_Surface *to ) -{ - blitBg(to); - - CIntObject::showAll(to); -} - -void CStackQueue::blitBg( SDL_Surface * to ) -{ - if(bg) - { - for (int w = 0; w < pos.w; w += bg->w) - { - blitAtLoc(bg, w, 0, to); - } - } -} - -void CStackQueue::StackBox::showAll( SDL_Surface *to ) -{ - assert(my); - if(bg) - { - graphics->blueToPlayersAdv(bg, my->owner); - //SDL_UpdateRect(bg, 0, 0, 0, 0); - SDL_Rect temp_rect = genRect(bg->h, bg->w, pos.x, pos.y); - CSDL_Ext::blit8bppAlphaTo24bpp(bg, NULL, to, &temp_rect); - //blitAt(bg, pos, to); - blitAt(graphics->bigImgs[my->getCreature()->idNumber], pos.x +9, pos.y + 1, to); - printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 12, FONT_MEDIUM, zwykly, to); - } - else - { - blitAt(graphics->smallImgs[-2], pos, to); - blitAt(graphics->smallImgs[my->getCreature()->idNumber], pos, to); - const SDL_Color &ownerColor = (my->owner == 255 ? *graphics->neutralColor : graphics->playerColors[my->owner]); - CSDL_Ext::drawBorder(to, pos, int3(ownerColor.r, ownerColor.g, ownerColor.b)); - printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 8, FONT_TINY, zwykly, to); - } -} - -void CStackQueue::StackBox::setStack( const CStack *nStack ) -{ - my = nStack; -} - -CStackQueue::StackBox::StackBox(SDL_Surface *BG) -:my(NULL), bg(BG) -{ - if(bg) - { - pos.w = bg->w; - pos.h = bg->h; - } - else - { - pos.w = pos.h = 32; - } - - pos.y += 2; -} - -CStackQueue::StackBox::~StackBox() -{ -} - -void CStackQueue::StackBox::hover( bool on ) -{ - -} \ No newline at end of file diff --git a/client/BattleInterface/CStackQueue.h b/client/BattleInterface/CStackQueue.h deleted file mode 100644 index b4ff8ccae..000000000 --- a/client/BattleInterface/CStackQueue.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include "../UIFramework/CIntObject.h" - -struct SDL_Surface; -class CStack; -class CBattleInterface; - -/* - * CStackQueue.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Shows the stack queue -class CStackQueue : public CIntObject -{ - class StackBox : public CIntObject - { - public: - const CStack *my; - SDL_Surface *bg; - - void hover (bool on); - void showAll(SDL_Surface *to); - void setStack(const CStack *nStack); - StackBox(SDL_Surface *BG); - ~StackBox(); - }; - -public: - static const int QUEUE_SIZE = 10; - const bool embedded; - std::vector stacksSorted; - std::vector stackBoxes; - - SDL_Surface *box; - SDL_Surface *bg; - CBattleInterface * owner; - - void showAll(SDL_Surface *to); - CStackQueue(bool Embedded, CBattleInterface * _owner); - ~CStackQueue(); - void update(); - void blitBg( SDL_Surface * to ); - //void showAll(SDL_Surface *to); -}; \ No newline at end of file diff --git a/client/BattleInterface/SStackAttackedInfo.h b/client/BattleInterface/SStackAttackedInfo.h deleted file mode 100644 index 40de274c1..000000000 --- a/client/BattleInterface/SStackAttackedInfo.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -class CStack; - -/* - * SStackAttackedInfo.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Small struct which contains information about the id of the attacked stack, the damage dealt,... -struct SStackAttackedInfo -{ - const CStack * defender; //attacked stack - int dmg; //damage dealt - int amountKilled; //how many creatures in stack has been killed - const CStack * attacker; //attacking stack - bool byShooting; //if true, stack has been attacked by shooting - bool killed; //if true, stack has been killed - bool rebirth; //if true, play rebirth animation after all -}; \ No newline at end of file diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index a2e562292..d4ef03abe 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -1,16 +1,15 @@ #include "StdInc.h" #include "CAdvmapInterface.h" -#include "AdventureMapButton.h" #include "../CCallback.h" #include "CCastleInterface.h" -#include "CCursorHandler.h" +#include "UIFramework/CCursorHandler.h" #include "CGameInfo.h" #include "CHeroWindow.h" #include "CKingdomInterface.h" #include "CMessage.h" #include "CPlayerInterface.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "CBitmapHandler.h" #include "CConfigHandler.h" #include "CSpellWindow.h" @@ -30,6 +29,7 @@ #include "../lib/CGameState.h" #include "CMusicHandler.h" #include "UIFramework/CGuiHandler.h" +#include "UIFramework/CIntObjectClasses.h" #ifdef _MSC_VER #pragma warning (disable : 4355) @@ -143,7 +143,7 @@ void CMinimap::draw(SDL_Surface * to) rx = static_cast((tilesw / static_cast(mapSizes.x)) * pos.w), //width ry = static_cast((tilesh / static_cast(mapSizes.y)) * pos.h); //height - CSDL_Ext::drawDashedBorder(temps, SRect(bx, by, rx, ry), int3(255,75,125)); + CSDL_Ext::drawDashedBorder(temps, Rect(bx, by, rx, ry), int3(255,75,125)); //blitAt(radar,bx,by,temps); blitAt(temps,pos.x,pos.y,to); @@ -181,7 +181,7 @@ void CMinimapSurfacesRef::initMap(int level) SDL_FreeSurface(map[g]); } map.clear();*/ - const SRect &minimap_pos = adventureInt->minimap.pos; + const Rect &minimap_pos = adventureInt->minimap.pos; std::map &colors = adventureInt->minimap.colors; std::map &colorsBlocked = adventureInt->minimap.colorsBlocked; int3 mapSizes = LOCPLINT->cb->getMapSize(); @@ -221,7 +221,7 @@ void CMinimapSurfacesRef::initFoW(int level) } FoW.clear();*/ - const SRect &minimap_pos = adventureInt->minimap.pos; + const Rect &minimap_pos = adventureInt->minimap.pos; int3 mapSizes = LOCPLINT->cb->getMapSize(); int mw = map_[0]->w, mh = map_[0]->h;//, //wo = mw/mapSizes.x, ho = mh/mapSizes.y; //TODO use me @@ -253,7 +253,7 @@ void CMinimapSurfacesRef::initFlaggableObjs(int level) } flObjs.clear();*/ - const SRect &minimap_pos = adventureInt->minimap.pos; + const Rect &minimap_pos = adventureInt->minimap.pos; int3 mapSizes = LOCPLINT->cb->getMapSize(); int mw = map_[0]->w, mh = map_[0]->h; for(int d=0; dmh->map->twoLevel+1; ++d) @@ -630,25 +630,25 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to) { if (hvx<0 && hvy<0) { - SRect dstRect = genRect(32, 32, x + moveX, y + moveY); + Rect dstRect = genRect(32, 32, x + moveX, y + moveY); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, to, &dstRect); } else if(hvx<0) { - SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0); - SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY); + Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0); + Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } else if (hvy<0) { - SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); - SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY); + Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); + Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } else { - SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); - SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY); + Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); + Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } } @@ -656,25 +656,25 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to) { if (hvx<0 && hvy<0) { - SRect dstRect = genRect(32, 32, x, y); + Rect dstRect = genRect(32, 32, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, to, &dstRect); } else if(hvx<0) { - SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0); - SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y); + Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0); + Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } else if (hvy<0) { - SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); - SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y); + Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); + Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } else { - SRect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); - SRect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y); + Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0); + Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y); CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect); } } @@ -774,24 +774,24 @@ void CResDataBar::draw(SDL_Surface * to) for (int i=0;i<7;i++) { SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10); - printAt(buf,txtpos[i].first,txtpos[i].second,FONT_SMALL,zwykly,to); + printAt(buf,txtpos[i].first,txtpos[i].second,FONT_SMALL,Colors::Cornsilk,to); } std::vector temp; 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,FONT_SMALL,zwykly,to); + printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,FONT_SMALL,Colors::Cornsilk,to); temp.clear(); //updateRect(&pos,screen); delete[] buf; } -void CResDataBar::show( SDL_Surface * to ) +void CResDataBar::show(SDL_Surface * to) { } -void CResDataBar::showAll( SDL_Surface * to ) +void CResDataBar::showAll(SDL_Surface * to) { draw(to); } @@ -874,7 +874,7 @@ void CInfoBar::blitAnim(int mode)//0 - day, 1 - week txt << CGI->generaltexth->allTexts[64] << " " << LOCPLINT->cb->getDate(1); } blitAt(anim->ourImages[pom].bitmap,pos.x+9,pos.y+10); - printAtMiddle(txt.str(),pos.x+95,pos.y+31,FONT_MEDIUM,zwykly); + printAtMiddle(txt.str(),pos.x+95,pos.y+31,FONT_MEDIUM,Colors::Cornsilk); if (pom == anim->ourImages.size()-1) toNextTick+=750; } @@ -914,9 +914,9 @@ void CInfoBar::newDay(int Day) blitAnim(mode); } -void CInfoBar::showComp(SComponent * comp, int time) +void CInfoBar::showComp(CComponent * comp, int time) { - if(comp->type != SComponent::hero) + if(comp->type != CComponent::hero) { curSel = NULL; } @@ -924,8 +924,8 @@ void CInfoBar::showComp(SComponent * comp, int time) SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp"); blitAt(b,pos.x+8,pos.y+11); blitAt(comp->getImg(),pos.x+52,pos.y+54); - printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,FONT_SMALL,zwykly); - printAtMiddleWB(comp->description,pos.x+94,pos.y+31,FONT_SMALL,26,zwykly); + printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,FONT_SMALL,Colors::Cornsilk); + printAtMiddleWB(comp->description,pos.x+94,pos.y+31,FONT_SMALL,26,Colors::Cornsilk); SDL_FreeSurface(b); if(!(active & TIME)) activateTimer(); @@ -958,7 +958,7 @@ void CInfoBar::tick() } } -void CInfoBar::show( SDL_Surface * to ) +void CInfoBar::show(SDL_Surface * to) { } @@ -1130,7 +1130,7 @@ void CAdvMapInt::fadventureOPtions() void CAdvMapInt::fsystemOptions() { - CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(SRect::createCentered(487, 481), LOCPLINT); + CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(Rect::createCentered(487, 481), LOCPLINT); GH.pushInt(sysopWindow); } @@ -1150,7 +1150,7 @@ void CAdvMapInt::fendTurn() for (int i = 0; i < LOCPLINT->wanderingHeroes.size(); i++) if (!isHeroSleeping(LOCPLINT->wanderingHeroes[i]) && (LOCPLINT->wanderingHeroes[i]->movement > 0)) { - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[55], std::vector(), boost::bind(&CAdvMapInt::endingTurn, this), 0, false); + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[55], std::vector(), boost::bind(&CAdvMapInt::endingTurn, this), 0, false); return; } endingTurn(); @@ -1274,7 +1274,7 @@ void CAdvMapInt::deactivate() if(LOCPLINT->cingconsole->active) //TODO LOCPLINT->cingconsole->deactivate(); } -void CAdvMapInt::showAll(SDL_Surface *to) +void CAdvMapInt::showAll(SDL_Surface * to) { blitAt(bg,0,0,to); @@ -1323,7 +1323,7 @@ void CAdvMapInt::setHeroSleeping(const CGHeroInstance *hero, bool sleep) updateNextHero(NULL); } -void CAdvMapInt::show(SDL_Surface *to) +void CAdvMapInt::show(SDL_Surface * to) { if(state != INGAME) return; @@ -1482,7 +1482,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) if(townWithMarket) //if any town has marketplace, open window GH.pushInt(new CMarketplaceWindow(townWithMarket)); else //if not - complain - LOCPLINT->showInfoDialog("No available marketplace!", std::vector(), soundBase::sound_todo); + LOCPLINT->showInfoDialog("No available marketplace!", std::vector(), soundBase::sound_todo); return; } default: @@ -2068,18 +2068,18 @@ CAdventureOptions::CAdventureOptions() bg = new CPicture("ADVOPTS.bmp"); graphics->blueToPlayersAdv(bg->bg, LOCPLINT->playerID); pos = bg->center(); - exit = new AdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 204, 313, "IOK6432.DEF",SDLK_RETURN); + exit = new CAdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 204, 313, "IOK6432.DEF",SDLK_RETURN); exit->assignedKeys.insert(SDLK_ESCAPE); - //scenInfo = new AdventureMapButton("","", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 24, 24, "ADVINFO.DEF",SDLK_i); - scenInfo = new AdventureMapButton("","", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 24, 198, "ADVINFO.DEF",SDLK_i); + //scenInfo = new CAdventureMapButton("","", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 24, 24, "ADVINFO.DEF",SDLK_i); + scenInfo = new CAdventureMapButton("","", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 24, 198, "ADVINFO.DEF",SDLK_i); scenInfo->callback += CAdventureOptions::showScenarioInfo; - //viewWorld = new AdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 204, 313, "IOK6432.DEF",SDLK_RETURN); + //viewWorld = new CAdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 204, 313, "IOK6432.DEF",SDLK_RETURN); - puzzle = new AdventureMapButton("","", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 24, 81, "ADVPUZ.DEF"); + puzzle = new CAdventureMapButton("","", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 24, 81, "ADVPUZ.DEF"); puzzle->callback += boost::bind(&CPlayerInterface::showPuzzleMap, LOCPLINT); - dig = new AdventureMapButton("","", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 24, 139, "ADVDIG.DEF"); + dig = new CAdventureMapButton("","", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 24, 139, "ADVDIG.DEF"); if(const CGHeroInstance *h = adventureInt->curHero()) dig->callback += boost::bind(&CPlayerInterface::tryDiggging, LOCPLINT, h); else diff --git a/client/CAdvmapInterface.h b/client/CAdvmapInterface.h index 7e0d24386..c0e355787 100644 --- a/client/CAdvmapInterface.h +++ b/client/CAdvmapInterface.h @@ -3,7 +3,7 @@ #include #include "SDL.h" -#include "AdventureMapButton.h" +#include "UIFramework/CIntObjectClasses.h" #include "GUIClasses.h" class CDefHandler; @@ -33,7 +33,7 @@ class CAdventureOptions : public CIntObject { public: CPicture *bg; - AdventureMapButton *exit, *viewWorld, *puzzle, *dig, *scenInfo, *replay; + CAdventureMapButton *exit, *viewWorld, *puzzle, *dig, *scenInfo, *replay; CAdventureOptions(); ~CAdventureOptions(); @@ -135,7 +135,7 @@ public: class CInfoBar : public CIntObject { CDefHandler *day, *week1, *week2, *week3, *week4; - SComponent * current; + CComponent * current; int pom; SDL_Surface *selInfoWin; //info box for selection CDefHandler * getAnim(int mode); @@ -146,7 +146,7 @@ public: CInfoBar(); ~CInfoBar(); void newDay(int Day); //start showing new day/week animation - void showComp(SComponent * comp, int time=5000); + void showComp(CComponent * comp, int time=5000); void tick(); void showAll(SDL_Surface * to); // if specific==0 function draws info about selected hero/town void blitAnim(int mode);//0 - day, 1 - week @@ -184,7 +184,7 @@ public: CMinimap minimap; CStatusBar statusbar; - AdventureMapButton kingOverview,//- kingdom overview + CAdventureMapButton kingOverview,//- kingdom overview underground,//- underground switch questlog,//- questlog sleepWake, //- sleep/wake hero diff --git a/client/CAnimation.cpp b/client/CAnimation.cpp index d36a444e5..40b8d5f03 100644 --- a/client/CAnimation.cpp +++ b/client/CAnimation.cpp @@ -8,7 +8,7 @@ #include "CBitmapHandler.h" #include "Graphics.h" #include "CAnimation.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" /* * CAnimation.cpp, part of VCMI engine @@ -39,7 +39,7 @@ public: inline void Load(size_t size, ui8 color=0); inline void EndLine(); //init image with these sizes and palette - inline void init(SPoint SpriteSize, SPoint Margins, SPoint FullSize, SDL_Color *pal); + inline void init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal); SDLImageLoader(SDLImage * Img); ~SDLImageLoader(); @@ -63,7 +63,7 @@ public: inline void Load(size_t size, ui8 color=0); inline void EndLine(); //init image with these sizes and palette - inline void init(SPoint SpriteSize, SPoint Margins, SPoint FullSize, SDL_Color *pal); + inline void init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal); CompImageLoader(CompImage * Img); ~CompImageLoader(); @@ -158,9 +158,9 @@ void CDefFile::loadFrame(size_t frame, size_t group, ImageLoader &loader) const ui32 currentOffset = sizeof(SSpriteDef); ui32 BaseOffset = sizeof(SSpriteDef); - loader.init(SPoint(sprite.width, sprite.height), - SPoint(sprite.leftMargin, sprite.topMargin), - SPoint(sprite.fullWidth, sprite.fullHeight), palette); + loader.init(Point(sprite.width, sprite.height), + Point(sprite.leftMargin, sprite.topMargin), + Point(sprite.fullWidth, sprite.fullHeight), palette); switch (sprite.format) { @@ -297,7 +297,7 @@ SDLImageLoader::SDLImageLoader(SDLImage * Img): { } -void SDLImageLoader::init(SPoint SpriteSize, SPoint Margins, SPoint FullSize, SDL_Color *pal) +void SDLImageLoader::init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal) { //Init image image->surf = SDL_CreateRGBSurface(SDL_SWSURFACE, SpriteSize.x, SpriteSize.y, 8, 0, 0, 0, 0); @@ -353,9 +353,9 @@ CompImageLoader::CompImageLoader(CompImage * Img): } -void CompImageLoader::init(SPoint SpriteSize, SPoint Margins, SPoint FullSize, SDL_Color *pal) +void CompImageLoader::init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal) { - image->sprite = SRect(Margins, SpriteSize); + image->sprite = Rect(Margins, SpriteSize); image->fullSize = FullSize; if (SpriteSize.x && SpriteSize.y) { @@ -588,17 +588,17 @@ SDLImage::SDLImage(std::string filename, bool compressed): } } -void SDLImage::draw(SDL_Surface *where, int posX, int posY, SRect *src, ui8 rotation) const +void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 rotation) const { if (!surf) return; - SRect sourceRect(margins.x, margins.y, surf->w, surf->h); + Rect sourceRect(margins.x, margins.y, surf->w, surf->h); //TODO: rotation and scaling if (src) { sourceRect = sourceRect & *src; } - SRect destRect(posX, posY, surf->w, surf->h); + Rect destRect(posX, posY, surf->w, surf->h); destRect += sourceRect.topLeft(); sourceRect -= margins; CSDL_Ext::blitSurface(surf, &sourceRect, where, &destRect); @@ -640,22 +640,22 @@ CompImage::CompImage(SDL_Surface * surf) assert(0); } -void CompImage::draw(SDL_Surface *where, int posX, int posY, SRect *src, ui8 alpha) const +void CompImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alpha) const { int rotation = 0; //TODO //rotation & 2 = horizontal rotation //rotation & 4 = vertical rotation if (!surf) return; - SRect sourceRect(sprite); + Rect sourceRect(sprite); //TODO: rotation and scaling if (src) sourceRect = sourceRect & *src; //Limit source rect to sizes of surface - sourceRect = sourceRect & SRect(0, 0, where->w, where->h); + sourceRect = sourceRect & Rect(0, 0, where->w, where->h); //Starting point on SDL surface - SPoint dest(posX+sourceRect.x, posY+sourceRect.y); + Point dest(posX+sourceRect.x, posY+sourceRect.y); if (rotation & 2) dest.y += sourceRect.h; if (rotation & 4) @@ -1166,7 +1166,7 @@ CAnimImage::~CAnimImage() delete anim; } -void CAnimImage::showAll(SDL_Surface *to) +void CAnimImage::showAll(SDL_Surface * to) { IImage *img = anim->getImage(frame, group); if (img) @@ -1285,7 +1285,7 @@ void CShowableAnim::clipRect(int posX, int posY, int width, int height) pos.h = height; } -void CShowableAnim::show(SDL_Surface *to) +void CShowableAnim::show(SDL_Surface * to) { if ( flags & BASE && frame != first) blitImage(first, group, to); @@ -1299,7 +1299,7 @@ void CShowableAnim::show(SDL_Surface *to) } } -void CShowableAnim::showAll(SDL_Surface *to) +void CShowableAnim::showAll(SDL_Surface * to) { if ( flags & BASE && frame != first) blitImage(first, group, to); @@ -1309,7 +1309,7 @@ void CShowableAnim::showAll(SDL_Surface *to) void CShowableAnim::blitImage(size_t frame, size_t group, SDL_Surface *to) { assert(to); - SRect src( xOffset, yOffset, pos.w, pos.h); + Rect src( xOffset, yOffset, pos.w, pos.h); IImage * img = anim.getImage(frame, group); if (img) img->draw(to, pos.x-xOffset, pos.y-yOffset, &src, alpha); @@ -1324,7 +1324,7 @@ void CShowableAnim::rotate(bool on, bool vertical) flags &= ~flag; } -CCreatureAnim::CCreatureAnim(int x, int y, std::string name, SRect picPos, ui8 flags, EAnimType type): +CCreatureAnim::CCreatureAnim(int x, int y, std::string name, Rect picPos, ui8 flags, EAnimType type): CShowableAnim(x,y,name,flags,3,type) { xOffset = picPos.x; diff --git a/client/CAnimation.h b/client/CAnimation.h index 86002fa65..794c6a4b4 100644 --- a/client/CAnimation.h +++ b/client/CAnimation.h @@ -60,7 +60,7 @@ class IImage public: //draws image on surface "where" at position - virtual void draw(SDL_Surface *where, int posX=0, int posY=0, SRect *src=NULL, ui8 alpha=255) const=0; + virtual void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=NULL, ui8 alpha=255) const=0; //decrease ref count, returns true if image can be deleted (refCount <= 0) bool decreaseRef(); @@ -83,9 +83,9 @@ public: //Surface without empty borders SDL_Surface * surf; //size of left and top borders - SPoint margins; + Point margins; //total size including borders - SPoint fullSize; + Point fullSize; public: //Load image from def file @@ -96,7 +96,7 @@ public: SDLImage(SDL_Surface * from, bool extraRef); ~SDLImage(); - void draw(SDL_Surface *where, int posX=0, int posY=0, SRect *src=NULL, ui8 alpha=255) const; + void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=NULL, ui8 alpha=255) const; void playerColored(int player); int width() const; int height() const; @@ -119,9 +119,9 @@ public: class CompImage : public IImage { //x,y - margins, w,h - sprite size - SRect sprite; + Rect sprite; //total size including borders - SPoint fullSize; + Point fullSize; //RLE-d data ui8 * surf; @@ -142,7 +142,7 @@ public: CompImage(SDL_Surface * surf); ~CompImage(); - void draw(SDL_Surface *where, int posX=0, int posY=0, SRect *src=NULL, ui8 alpha=255) const; + void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=NULL, ui8 alpha=255) const; void playerColored(int player); int width() const; int height() const; @@ -246,7 +246,7 @@ public: //makes image player-colored void playerColored(int player); - void showAll(SDL_Surface *to); + void showAll(SDL_Surface * to); }; /// Base class for displaying animation, used as superclass for different animations @@ -306,8 +306,8 @@ public: virtual void reset(); //show current frame and increase counter - void show(SDL_Surface *to); - void showAll(SDL_Surface *to); + void show(SDL_Surface * to); + void showAll(SDL_Surface * to); }; /// Creature-dependend animations like attacking, moving,... @@ -366,7 +366,7 @@ public: //clear queue and set animation to this sequence void clearAndSet(EAnimType type); - CCreatureAnim(int x, int y, std::string name, SRect picPos, + CCreatureAnim(int x, int y, std::string name, Rect picPos, ui8 flags= USE_RLE, EAnimType = HOLDING ); }; diff --git a/client/CCastleInterface.cpp b/client/CCastleInterface.cpp index cd865bd1e..fc1bbb54a 100644 --- a/client/CCastleInterface.cpp +++ b/client/CCastleInterface.cpp @@ -9,7 +9,6 @@ #include "../lib/CObjectHandler.h" #include "../lib/CSpellHandler.h" #include "../lib/CTownHandler.h" -#include "AdventureMapButton.h" #include "CAdvmapInterface.h" #include "CAnimation.h" #include "CBitmapHandler.h" @@ -20,9 +19,10 @@ #include "CMusicHandler.h" #include "CPlayerInterface.h" #include "Graphics.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "../lib/GameConstants.h" #include "UIFramework/CGuiHandler.h" +#include "UIFramework/CIntObjectClasses.h" using namespace boost::assign; @@ -123,8 +123,8 @@ void CBuildingRect::clickRight(tribool down, bool previousState) const CBuilding *bld = CGI->buildh->buildings[str->townID].find(bid)->second; if (bid < EBuilding::DWELL_FIRST) { - std::vector comps(1, - new SComponent(SComponent::building, bld->tid, bld->bid, + std::vector comps(1, + new CComponent(CComponent::building, bld->tid, bld->bid, LOCPLINT->castleInt->bicons->ourImages[bld->bid].bitmap, false)); CRClickPopup::createAndPush(bld->Description(), comps); @@ -146,7 +146,7 @@ SDL_Color multiplyColors (const SDL_Color &b, const SDL_Color &a, double f) return ret; } -void CBuildingRect::show(SDL_Surface *to) +void CBuildingRect::show(SDL_Surface * to) { const ui32 stageDelay = 16; @@ -200,7 +200,7 @@ void CBuildingRect::show(SDL_Surface *to) stateCounter++; } -void CBuildingRect::showAll(SDL_Surface *to) +void CBuildingRect::showAll(SDL_Surface * to) { if (stateCounter == 0) return; @@ -256,23 +256,23 @@ CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstanc background->colorize(LOCPLINT->playerID); pos.w = background->pos.w; pos.h = background->pos.h; - moveTo(SPoint(centerX - pos.w/2, centerY - pos.h/2)); + moveTo(Point(centerX - pos.w/2, centerY - pos.h/2)); const CCreature * creature = CGI->creh->creatures[Town->creatures[level].second.back()]; - title = new CLabel(80, 30, FONT_SMALL, CENTER, zwykly, creature->namePl); + title = new CLabel(80, 30, FONT_SMALL, CENTER, Colors::Cornsilk, creature->namePl); animation = new CCreaturePic(30, 44, creature, true, true); std::string text = boost::lexical_cast(Town->creatures[level].first); - available = new CLabel(80,190, FONT_SMALL, CENTER, zwykly, CGI->generaltexth->allTexts[217] + text); - costPerTroop = new CLabel(80, 227, FONT_SMALL, CENTER, zwykly, CGI->generaltexth->allTexts[346]); + available = new CLabel(80,190, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[217] + text); + costPerTroop = new CLabel(80, 227, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[346]); for(int i = 0; icost[i]) { resPicture.push_back(new CPicture(graphics->resources32->ourImages[i].bitmap, 0, 0, false)); - resAmount.push_back(new CLabel(0,0, FONT_SMALL, CENTER, zwykly, boost::lexical_cast(creature->cost[i]))); + resAmount.push_back(new CLabel(0,0, FONT_SMALL, CENTER, Colors::Cornsilk, boost::lexical_cast(creature->cost[i]))); } } @@ -280,8 +280,8 @@ CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstanc int posX = pos.w/2 - resAmount.size() * 25 + 5; for (size_t i=0; imoveBy(SPoint(posX, posY)); - resAmount[i]->moveBy(SPoint(posX+16, posY+43)); + resPicture[i]->moveBy(Point(posX, posY)); + resAmount[i]->moveBy(Point(posX+16, posY+43)); posX += 50; } } @@ -366,12 +366,12 @@ void CHeroGSlot::clickLeft(tribool down, bool previousState) { std::string tmp = CGI->generaltexth->allTexts[18]; //You already have %d adventuring heroes under your command. boost::algorithm::replace_first(tmp,"%d",boost::lexical_cast(LOCPLINT->cb->howManyHeroes(false))); - LOCPLINT->showInfoDialog(tmp,std::vector(), soundBase::sound_todo); + LOCPLINT->showInfoDialog(tmp,std::vector(), soundBase::sound_todo); allow = false; } else if(!other->hero->stacksCount()) //hero has no creatures - strange, but if we have appropriate error message... { - LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[19],std::vector(), soundBase::sound_todo); //This hero has no creatures. A hero must have creatures before he can brave the dangers of the countryside. + LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[19],std::vector(), soundBase::sound_todo); //This hero has no creatures. A hero must have creatures before he can brave the dangers of the countryside. allow = false; } } @@ -618,14 +618,14 @@ void CCastleBuildings::removeBuilding(int building) checkRules(); } -void CCastleBuildings::show(SDL_Surface *to) +void CCastleBuildings::show(SDL_Surface * to) { CIntObject::show(to); for (std::vector< CBuildingRect* >::const_iterator it=buildings.begin() ; it !=buildings.end(); it++ ) (*it)->show(to); } -void CCastleBuildings::showAll(SDL_Surface *to) +void CCastleBuildings::showAll(SDL_Surface * to) { CIntObject::showAll(to); for (std::vector< CBuildingRect* >::const_iterator it=buildings.begin() ; it !=buildings.end(); it++ ) @@ -797,8 +797,8 @@ void CCastleBuildings::enterBlacksmith(int ArtifactID) void CCastleBuildings::enterBuilding(int building) { - std::vector comps(1, - new SComponent(SComponent::building, town->subID,building, + std::vector comps(1, + new CComponent(CComponent::building, town->subID,building, LOCPLINT->castleInt->bicons->ourImages[building].bitmap, false)); LOCPLINT->showInfoDialog( @@ -836,8 +836,8 @@ void CCastleBuildings::enterDwelling(int level) void CCastleBuildings::enterFountain(int building) { - std::vector comps(1, - new SComponent(SComponent::building,town->subID,building, + std::vector comps(1, + new CComponent(CComponent::building,town->subID,building, LOCPLINT->castleInt->bicons->ourImages[building].bitmap,false)); std::string descr = CGI->buildh->buildings[town->subID].find(building)->second->Description(); @@ -868,7 +868,7 @@ void CCastleBuildings::enterMagesGuild() { CFunctionList functionList = boost::bind(&CCallback::buyArtifact,LOCPLINT->cb, hero,0); functionList += boost::bind(&CCastleBuildings::openMagesGuild,this); - std::vector components(1, new SComponent(SComponent::artifact,0,0)); + std::vector components(1, new CComponent(CComponent::artifact,0,0)); LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[214], components, functionList, 0, true); } @@ -887,7 +887,7 @@ void CCastleBuildings::enterTownHall() if(!vstd::contains(town->forbiddenBuildings, EBuilding::GRAIL)) { LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[597], //Do you wish this to be the permanent home of the Grail? - std::vector(), + std::vector(), boost::bind(&CCallback::buildBuilding, LOCPLINT->cb, town, EBuilding::GRAIL), boost::bind(&CCastleBuildings::openTownHall, this), true); } @@ -928,22 +928,22 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, int listPos): pos.h = builds->pos.h + panel->pos.h; center(); - garr = new CGarrisonInt(305, 387, 4, SPoint(0,96), panel->bg, SPoint(62,374), town->getUpperArmy(), town->visitingHero); - heroes = new HeroSlots(town, SPoint(241, 387), SPoint(241, 483), garr, true); - title = new CLabel(85, 387, FONT_MEDIUM, TOPLEFT, zwykly, town->name); + garr = new CGarrisonInt(305, 387, 4, Point(0,96), panel->bg, Point(62,374), town->getUpperArmy(), town->visitingHero); + heroes = new HeroSlots(town, Point(241, 387), Point(241, 483), garr, true); + title = new CLabel(85, 387, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, town->name); income = new CLabel(195, 443, FONT_SMALL, CENTER); icon = new CAnimImage("ITPT", 0, 0, 15, 387); - exit = new AdventureMapButton(CGI->generaltexth->tcommands[8], "", boost::bind(&CCastleInterface::close,this), 744, 544, "TSBTNS", SDLK_RETURN); + exit = new CAdventureMapButton(CGI->generaltexth->tcommands[8], "", boost::bind(&CCastleInterface::close,this), 744, 544, "TSBTNS", SDLK_RETURN); exit->assignedKeys.insert(SDLK_ESCAPE); exit->setOffset(4); - split = new AdventureMapButton(CGI->generaltexth->tcommands[3], "", boost::bind(&CGarrisonInt::splitClick,garr), 744, 382, "TSBTNS.DEF"); + split = new CAdventureMapButton(CGI->generaltexth->tcommands[3], "", boost::bind(&CGarrisonInt::splitClick,garr), 744, 382, "TSBTNS.DEF"); split->callback += boost::bind(&HeroSlots::splitClicked, heroes); removeChild(split); garr->addSplitBtn(split); - SRect barRect(9, 182, 732, 18); + Rect barRect(9, 182, 732, 18); statusbar = new CGStatusBar(new CPicture(*panel, barRect, 9, 555, false)); resdatabar = new CResDataBar("ZRESBAR", 3, 575, 32, 2, 85, 85); @@ -980,7 +980,7 @@ void CCastleInterface::close() GH.popIntTotally(this); } -void CCastleInterface::showAll(SDL_Surface *to) +void CCastleInterface::showAll(SDL_Surface * to) { CIntObject::showAll(to); if(screen->w != 800 || screen->h !=600) @@ -1045,13 +1045,13 @@ void CCastleInterface::recreateIcons() creainfo.clear(); for (size_t i=0; i<4; i++) - creainfo.push_back(new CCreaInfo(SPoint(14+55*i, 459), town, i)); + creainfo.push_back(new CCreaInfo(Point(14+55*i, 459), town, i)); for (size_t i=0; i<4; i++) - creainfo.push_back(new CCreaInfo(SPoint(14+55*i, 507), town, i+4)); + creainfo.push_back(new CCreaInfo(Point(14+55*i, 507), town, i+4)); } -CCreaInfo::CCreaInfo(SPoint position, const CGTownInstance *Town, int Level, bool compact, bool ShowAvailable): +CCreaInfo::CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool compact, bool ShowAvailable): town(Town), level(Level), showAvailable(ShowAvailable) @@ -1081,14 +1081,14 @@ CCreaInfo::CCreaInfo(SPoint position, const CGTownInstance *Town, int Level, boo if (compact) { - label = new CLabel(40, 32, FONT_TINY, BOTTOMRIGHT, zwykly, value); + label = new CLabel(40, 32, FONT_TINY, BOTTOMRIGHT, Colors::Cornsilk, value); pos.x += 8; pos.w = 32; pos.h = 32; } else { - label = new CLabel(24, 40, FONT_SMALL, CENTER, zwykly, value); + label = new CLabel(24, 40, FONT_SMALL, CENTER, Colors::Cornsilk, value); pos.w = 48; pos.h = 48; } @@ -1263,7 +1263,7 @@ void CCastleInterface::keyPressed( const SDL_KeyboardEvent & key ) } } -HeroSlots::HeroSlots(const CGTownInstance * Town, SPoint garrPos, SPoint visitPos, CGarrisonInt *Garrison, bool ShowEmpty): +HeroSlots::HeroSlots(const CGTownInstance * Town, Point garrPos, Point visitPos, CGarrisonInt *Garrison, bool ShowEmpty): showEmpty(ShowEmpty), town(Town), garr(Garrison) @@ -1337,7 +1337,7 @@ CHallInterface::CBuildingBox::CBuildingBox(int x, int y, const CGTownInstance * panel = new CAnimImage("TPTHBAR", panelIndex[state], 0, 1, 73); if ( iconIndex[state] >=0 ) icon = new CAnimImage("TPTHCHK", iconIndex[state], 0, 136, 56); - label = new CLabel(75, 81, FONT_SMALL, CENTER, zwykly, building->Name()); + label = new CLabel(75, 81, FONT_SMALL, CENTER, Colors::Cornsilk, building->Name()); } CHallInterface::CHallInterface(const CGTownInstance *Town): @@ -1351,11 +1351,11 @@ CHallInterface::CHallInterface(const CGTownInstance *Town): resdatabar = new CMinorResDataBar; resdatabar->pos.x += pos.x; resdatabar->pos.y += pos.y; - SRect barRect(5, 556, 740, 18); + Rect barRect(5, 556, 740, 18); statusBar = new CGStatusBar(new CPicture(*background, barRect, 5, 556, false)); - title = new CLabel(399, 12, FONT_MEDIUM, CENTER, zwykly, CGI->buildh->buildings[town->subID][town->hallLevel()+EBuilding::VILLAGE_HALL]->Name()); - exit = new AdventureMapButton(CGI->generaltexth->hcommands[8], "", + title = new CLabel(399, 12, FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->buildh->buildings[town->subID][town->hallLevel()+EBuilding::VILLAGE_HALL]->Name()); + exit = new CAdventureMapButton(CGI->generaltexth->hcommands[8], "", boost::bind(&CHallInterface::close,this), 748, 556, "TPMAGE1.DEF", SDLK_RETURN); exit->assignedKeys.insert(SDLK_ESCAPE); @@ -1454,13 +1454,13 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin background->colorize(LOCPLINT->playerID); buildingPic = new CAnimImage(graphics->buildingPics[town->subID], building->bid, 0, 125, 50); - SRect barRect(9, 494, 380, 18); + Rect barRect(9, 494, 380, 18); statusBar = new CGStatusBar(new CPicture(*background, barRect, 9, 494, false)); - title = new CLabel(197, 30, FONT_MEDIUM, CENTER, zwykly, + title = new CLabel(197, 30, FONT_MEDIUM, CENTER, Colors::Cornsilk, boost::str(boost::format(CGI->generaltexth->hcommands[7]) % building->Name())); - buildingDescr = new CTextBox(building->Description(), SRect(33, 135, 329, 67), 0, FONT_MEDIUM, CENTER); - buildingState = new CTextBox(getTextForState(state), SRect(33, 216, 329, 67), 0, FONT_SMALL, CENTER); + buildingDescr = new CTextBox(building->Description(), Rect(33, 135, 329, 67), 0, FONT_MEDIUM, CENTER); + buildingState = new CTextBox(getTextForState(state), Rect(33, 216, 329, 67), 0, FONT_SMALL, CENTER); //Create objects for all required resources for(int i = 0; iresources[i]) { resPicture.push_back(new CPicture(graphics->resources32->ourImages[i].bitmap, 0, 0, false)); - resAmount.push_back(new CLabel(0,0, FONT_SMALL, CENTER, zwykly, + resAmount.push_back(new CLabel(0,0, FONT_SMALL, CENTER, Colors::Cornsilk, boost::lexical_cast(building->resources[i]))); } } @@ -1493,8 +1493,8 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin int posX = pos.w/2 - rowSize[row] * 40 + 24; for (size_t i=0; imoveBy(SPoint(posX, posY)); - resAmount[index]->moveBy(SPoint(posX+16, posY+48)); + resPicture[index]->moveBy(Point(posX, posY)); + resAmount[index]->moveBy(Point(posX+16, posY+48)); posX += 80; index++; } @@ -1503,12 +1503,12 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin if(!mode) { - buy = new AdventureMapButton(boost::str(boost::format(CGI->generaltexth->allTexts[595]) % building->Name()), + buy = new CAdventureMapButton(boost::str(boost::format(CGI->generaltexth->allTexts[595]) % building->Name()), "", boost::bind(&CBuildWindow::buyFunc,this), 45, 446,"IBUY30", SDLK_RETURN); buy->borderColor = Colors::MetallicGold; buy->borderEnabled = true; - cancel = new AdventureMapButton(boost::str(boost::format(CGI->generaltexth->allTexts[596]) % building->Name()), + cancel = new CAdventureMapButton(boost::str(boost::format(CGI->generaltexth->allTexts[596]) % building->Name()), "", boost::bind(&CBuildWindow::close,this), 290, 445, "ICANCEL", SDLK_ESCAPE); cancel->borderColor = Colors::MetallicGold; cancel->borderEnabled = true; @@ -1539,20 +1539,20 @@ CFortScreen::CFortScreen(const CGTownInstance * town) pos = background->center(); const CBuilding *fortBuilding = CGI->buildh->buildings[town->subID][town->fortLevel()+6]; - title = new CLabel(400, 12, FONT_BIG, CENTER, zwykly, fortBuilding->Name()); + title = new CLabel(400, 12, FONT_BIG, CENTER, Colors::Cornsilk, fortBuilding->Name()); std::string text = boost::str(boost::format(CGI->generaltexth->fcommands[6]) % fortBuilding->Name()); - exit = new AdventureMapButton(text, "", boost::bind(&CFortScreen::close,this) ,748, 556, "TPMAGE1", SDLK_RETURN); + exit = new CAdventureMapButton(text, "", boost::bind(&CFortScreen::close,this) ,748, 556, "TPMAGE1", SDLK_RETURN); - std::vector positions; - positions += SPoint(10, 22), SPoint(404, 22), - SPoint(10, 155), SPoint(404,155), - SPoint(10, 288), SPoint(404,288); + std::vector positions; + positions += Point(10, 22), Point(404, 22), + Point(10, 155), Point(404,155), + Point(10, 288), Point(404,288); if (fortSize == GameConstants::CREATURES_PER_TOWN) - positions += SPoint(206,421); + positions += Point(206,421); else - positions += SPoint(10, 421), SPoint(404,421); + positions += Point(10, 421), Point(404,421); for (ui32 i=0; ipos.x += pos.x; resdatabar->pos.y += pos.y; - SRect barRect(4, 554, 740, 18); + Rect barRect(4, 554, 740, 18); statusBar = new CGStatusBar(new CPicture(*background, barRect, 4, 554, false)); } @@ -1583,7 +1583,7 @@ void CFortScreen::creaturesChanged() recAreas[i]->creaturesChanged(); } -LabeledValue::LabeledValue(SRect size, std::string name, std::string descr, int min, int max) +LabeledValue::LabeledValue(Rect size, std::string name, std::string descr, int min, int max) { pos.x+=size.x; pos.y+=size.y; @@ -1592,7 +1592,7 @@ LabeledValue::LabeledValue(SRect size, std::string name, std::string descr, int init(name, descr, min, max); } -LabeledValue::LabeledValue(SRect size, std::string name, std::string descr, int val) +LabeledValue::LabeledValue(Rect size, std::string name, std::string descr, int val) { pos.x+=size.x; pos.y+=size.y; @@ -1613,8 +1613,8 @@ void LabeledValue::init(std::string nameText, std::string descr, int min, int ma if (min != max) valueText += '-' + boost::lexical_cast(max); } - name = new CLabel(3, 0, FONT_SMALL, TOPLEFT, zwykly, nameText); - value = new CLabel(pos.w-3, pos.h-2, FONT_SMALL, BOTTOMRIGHT, zwykly, valueText); + name = new CLabel(3, 0, FONT_SMALL, TOPLEFT, Colors::Cornsilk, nameText); + value = new CLabel(pos.w-3, pos.h-2, FONT_SMALL, BOTTOMRIGHT, Colors::Cornsilk, valueText); } void LabeledValue::hover(bool on) @@ -1655,7 +1655,7 @@ CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance * hoverText = boost::str(boost::format(CGI->generaltexth->tcommands[21]) % creature->namePl); creatureAnim = new CCreaturePic(159, 4, creature, false); - SRect sizes(287, 4, 96, 18); + Rect sizes(287, 4, 96, 18); values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[190], CGI->generaltexth->fcommands[0], creature->attack)); sizes.y+=20; values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[191], CGI->generaltexth->fcommands[1], creature->defence)); @@ -1668,14 +1668,14 @@ CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance * sizes.y+=20; values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[194], CGI->generaltexth->fcommands[5], town->creatureGrowth(level))); - creatureName = new CLabel(78, 11, FONT_SMALL, CENTER, zwykly, creature->namePl); - dwellingName = new CLabel(78, 101, FONT_SMALL, CENTER, zwykly, CGI->buildh->buildings[town->subID][buildingID]->Name()); + creatureName = new CLabel(78, 11, FONT_SMALL, CENTER, Colors::Cornsilk, creature->namePl); + dwellingName = new CLabel(78, 101, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->buildh->buildings[town->subID][buildingID]->Name()); if (vstd::contains(town->builtBuildings, buildingID)) { ui32 available = town->creatures[level].first; std::string availableText = CGI->generaltexth->allTexts[217]+ boost::lexical_cast(available); - availableCount = new CLabel(78, 119, FONT_SMALL, CENTER, zwykly, availableText); + availableCount = new CLabel(78, 119, FONT_SMALL, CENTER, Colors::Cornsilk, availableText); } } @@ -1719,20 +1719,20 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner) resdatabar = new CMinorResDataBar; resdatabar->pos.x += pos.x; resdatabar->pos.y += pos.y; - SRect barRect(7, 556, 737, 18); + Rect barRect(7, 556, 737, 18); statusBar = new CGStatusBar(new CPicture(*background, barRect, 7, 556, false)); - exit = new AdventureMapButton(CGI->generaltexth->allTexts[593],"",boost::bind(&CMageGuildScreen::close,this), 748, 556,"TPMAGE1.DEF",SDLK_RETURN); + exit = new CAdventureMapButton(CGI->generaltexth->allTexts[593],"",boost::bind(&CMageGuildScreen::close,this), 748, 556,"TPMAGE1.DEF",SDLK_RETURN); exit->assignedKeys.insert(SDLK_ESCAPE); - std::vector > positions; + std::vector > positions; positions.resize(5); - positions[0] += SPoint(222,445), SPoint(312,445), SPoint(402,445), SPoint(520,445), SPoint(610,445), SPoint(700,445); - positions[1] += SPoint(48,53), SPoint(48,147), SPoint(48,241), SPoint(48,335), SPoint(48,429); - positions[2] += SPoint(570,82), SPoint(672,82), SPoint(570,157), SPoint(672,157); - positions[3] += SPoint(183,42), SPoint(183,148), SPoint(183,253); - positions[4] += SPoint(491,325), SPoint(591,325); + positions[0] += Point(222,445), Point(312,445), Point(402,445), Point(520,445), Point(610,445), Point(700,445); + positions[1] += Point(48,53), Point(48,147), Point(48,241), Point(48,335), Point(48,429); + positions[2] += Point(570,82), Point(672,82), Point(570,157), Point(672,157); + positions[3] += Point(183,42), Point(183,148), Point(183,253); + positions[4] += Point(491,325), Point(591,325); for(size_t i=0; itown->town->mageLevel; i++) { @@ -1752,7 +1752,7 @@ void CMageGuildScreen::close() GH.popIntTotally(this); } -CMageGuildScreen::Scroll::Scroll(SPoint position, const CSpell *Spell) +CMageGuildScreen::Scroll::Scroll(Point position, const CSpell *Spell) :spell(Spell) { OBJ_CONSTRUCTION_CAPTURING_ALL; @@ -1766,8 +1766,8 @@ void CMageGuildScreen::Scroll::clickLeft(tribool down, bool previousState) { if(down) { - std::vector comps(1, - new SComponent(SComponent::spell,spell->id,0) + std::vector comps(1, + new CComponent(CComponent::spell,spell->id,0) ); LOCPLINT->showInfoDialog(spell->descriptions[0],comps, soundBase::sound_todo); } @@ -1811,20 +1811,20 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, i animBG->needRefresh = true; const CCreature *creature = CGI->creh->creatures[creMachineID]; - anim = new CCreatureAnim(64, 50, creature->animDefName, SRect()); + anim = new CCreatureAnim(64, 50, creature->animDefName, Rect()); anim->clipRect(113,125,200,150); - title = new CLabel(165, 28, FONT_BIG, CENTER, tytulowy, + title = new CLabel(165, 28, FONT_BIG, CENTER, Colors::Jasmine, boost::str(boost::format(CGI->generaltexth->allTexts[274]) % creature->nameSing)); - costText = new CLabel(165, 218, FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->jktexts[43]); - costValue = new CLabel(165, 290, FONT_MEDIUM, CENTER, zwykly, + costText = new CLabel(165, 218, FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->jktexts[43]); + costValue = new CLabel(165, 290, FONT_MEDIUM, CENTER, Colors::Cornsilk, boost::lexical_cast(CGI->arth->artifacts[aid]->price)); std::string text = boost::str(boost::format(CGI->generaltexth->allTexts[595]) % creature->nameSing); - buy = new AdventureMapButton(text,"",boost::bind(&CBlacksmithDialog::close, this), 42, 312,"IBUY30.DEF",SDLK_RETURN); + buy = new CAdventureMapButton(text,"",boost::bind(&CBlacksmithDialog::close, this), 42, 312,"IBUY30.DEF",SDLK_RETURN); text = boost::str(boost::format(CGI->generaltexth->allTexts[596]) % creature->nameSing); - cancel = new AdventureMapButton(text,"",boost::bind(&CBlacksmithDialog::close, this), 224, 312,"ICANCEL.DEF",SDLK_ESCAPE); + cancel = new CAdventureMapButton(text,"",boost::bind(&CBlacksmithDialog::close, this), 224, 312,"ICANCEL.DEF",SDLK_ESCAPE); if(possible) buy->callback += boost::bind(&CCallback::buyArtifact,LOCPLINT->cb,LOCPLINT->cb->getHero(hid),aid); diff --git a/client/CCastleInterface.h b/client/CCastleInterface.h index f9d71d7d4..c593c1856 100644 --- a/client/CCastleInterface.h +++ b/client/CCastleInterface.h @@ -4,7 +4,7 @@ #include "CAnimation.h" #include "GUIClasses.h" -class AdventureMapButton; +class CAdventureMapButton; class CBuilding; class CCastleBuildings; class CCreaturePic; @@ -53,8 +53,8 @@ public: void clickLeft(tribool down, bool previousState); void clickRight(tribool down, bool previousState); void mouseMoved (const SDL_MouseMotionEvent & sEvent); - void show(SDL_Surface *to); - void showAll(SDL_Surface *to); + void show(SDL_Surface * to); + void showAll(SDL_Surface * to); }; /// Dwelling info box - right-click screen for dwellings @@ -104,7 +104,7 @@ public: CHeroGSlot * garrisonedHero; CHeroGSlot * visitingHero; - HeroSlots(const CGTownInstance * town, SPoint garrPos, SPoint visitPos, CGarrisonInt *Garrison, bool ShowEmpty); + HeroSlots(const CGTownInstance * town, Point garrPos, Point visitPos, CGarrisonInt *Garrison, bool ShowEmpty); void splitClicked(); //for hero meeting only (splitting stacks is handled by garrison int) void update(); @@ -146,8 +146,8 @@ public: void addBuilding(int building); void removeBuilding(int building);//FIXME: not tested!!! - void show(SDL_Surface *to); - void showAll(SDL_Surface *to); + void show(SDL_Surface * to); + void showAll(SDL_Surface * to); }; /// Creature info window @@ -165,7 +165,7 @@ class CCreaInfo : public CIntObject std::string genGrowthText(); public: - CCreaInfo(SPoint position, const CGTownInstance *Town, int Level, bool compact=false, bool showAvailable=false); + CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool compact=false, bool showAvailable=false); void update(); void hover(bool on); @@ -201,8 +201,8 @@ class CCastleInterface : public CWindowWithGarrison CTownInfo *hall, *fort; CTownList * townlist; - AdventureMapButton *exit; - AdventureMapButton *split; + CAdventureMapButton *exit; + CAdventureMapButton *split; std::vector creainfo;//small icons of creatures (bottom-left corner); @@ -221,7 +221,7 @@ public: void castleTeleport(int where); void townChange(); void keyPressed(const SDL_KeyboardEvent & key); - void showAll(SDL_Surface *to); + void showAll(SDL_Surface * to); void close(); void addBuilding(int bid); void removeBuilding(int bid); @@ -257,7 +257,7 @@ class CHallInterface : public CIntObject CLabel *title; CGStatusBar *statusBar; CMinorResDataBar * resdatabar; - AdventureMapButton *exit; + CAdventureMapButton *exit; public: CHallInterface(const CGTownInstance * Town); //c-tor @@ -274,8 +274,8 @@ class CBuildWindow: public CIntObject CPicture *background; CAnimImage *buildingPic; - AdventureMapButton *buy; - AdventureMapButton *cancel; + CAdventureMapButton *buy; + CAdventureMapButton *cancel; CLabel * title; CTextBox * buildingDescr; @@ -304,8 +304,8 @@ class LabeledValue : public CIntObject void init(std::string name, std::string descr, int min, int max); public: - LabeledValue(SRect size, std::string name, std::string descr, int min, int max); - LabeledValue(SRect size, std::string name, std::string descr, int val); + LabeledValue(Rect size, std::string name, std::string descr, int min, int max); + LabeledValue(Rect size, std::string name, std::string descr, int val); void hover(bool on); }; @@ -341,7 +341,7 @@ class CFortScreen : public CIntObject std::vector recAreas; CMinorResDataBar * resdatabar; CGStatusBar *statusBar; - AdventureMapButton *exit; + CAdventureMapButton *exit; public: CFortScreen(const CGTownInstance * town); //c-tor @@ -359,14 +359,14 @@ class CMageGuildScreen : public CIntObject CAnimImage *image; public: - Scroll(SPoint position, const CSpell *Spell); + Scroll(Point position, const CSpell *Spell); void clickLeft(tribool down, bool previousState); void clickRight(tribool down, bool previousState); void hover(bool on); }; CPicture *background; CPicture *window; - AdventureMapButton *exit; + CAdventureMapButton *exit; std::vector spells; CMinorResDataBar * resdatabar; CGStatusBar *statusBar; @@ -380,7 +380,7 @@ public: /// The blacksmith window where you can buy available in town war machine class CBlacksmithDialog : public CIntObject { - AdventureMapButton *buy, *cancel; + CAdventureMapButton *buy, *cancel; CPicture *background; CPicture *animBG; CCreatureAnim * anim; diff --git a/client/CCreatureWindow.cpp b/client/CCreatureWindow.cpp index fd4308814..d217666e4 100644 --- a/client/CCreatureWindow.cpp +++ b/client/CCreatureWindow.cpp @@ -8,19 +8,20 @@ #include "../CCallback.h" #include -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "CBitmapHandler.h" #include "CDefHandler.h" #include "Graphics.h" -#include "AdventureMapButton.h" #include "CPlayerInterface.h" #include "CConfigHandler.h" +#include "CAnimation.h" #include "../lib/CGameState.h" #include "../lib/BattleState.h" #include "../lib/CSpellHandler.h" #include "UIFramework/CGuiHandler.h" +#include "UIFramework/CIntObjectClasses.h" using namespace CSDL_Ext; @@ -83,7 +84,7 @@ CCreatureWindow::CCreatureWindow(const CStackInstance &st, int Type, boost::func for(TResources::nziterator i(upgradeCost); i.valid(); i++) { BLOCK_CAPTURING; - upgResCost.push_back(new SComponent(SComponent::resource, i->resType, i->resVal)); + upgResCost.push_back(new CComponent(CComponent::resource, i->resType, i->resVal)); } if(LOCPLINT->cb->getResourceAmount().canAfford(upgradeCost)) @@ -93,11 +94,11 @@ CCreatureWindow::CCreatureWindow(const CStackInstance &st, int Type, boost::func fs += boost::bind(&CCreatureWindow::close,this); CFunctionList cfl; cfl = boost::bind(&CPlayerInterface::showYesNoDialog, LOCPLINT, CGI->generaltexth->allTexts[207], boost::ref(upgResCost), fs, 0, false); - upgrade = new AdventureMapButton("",CGI->generaltexth->zelp[446].second,cfl,385, 148,"IVIEWCR.DEF",SDLK_u); + upgrade = new CAdventureMapButton("",CGI->generaltexth->zelp[446].second,cfl,385, 148,"IVIEWCR.DEF",SDLK_u); } else { - upgrade = new AdventureMapButton("",CGI->generaltexth->zelp[446].second,boost::function(),385, 148,"IVIEWCR.DEF"); + upgrade = new CAdventureMapButton("",CGI->generaltexth->zelp[446].second,boost::function(),385, 148,"IVIEWCR.DEF"); upgrade->callback.funcs.clear(); upgrade->setOffset(2); } @@ -110,8 +111,8 @@ CCreatureWindow::CCreatureWindow(const CStackInstance &st, int Type, boost::func fs[0] += Dsm; //dismiss fs[0] += boost::bind(&CCreatureWindow::close,this);//close this window CFunctionList cfl; - cfl = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],std::vector(),fs[0],fs[1],false); - dismiss = new AdventureMapButton("",CGI->generaltexth->zelp[445].second,cfl,333, 148,"IVIEWCR2.DEF",SDLK_d); + cfl = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],std::vector(),fs[0],fs[1],false); + dismiss = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second,cfl,333, 148,"IVIEWCR2.DEF",SDLK_d); } } } @@ -185,7 +186,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * pos = bitmap->center(); //Buttons - ok = new AdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CCreatureWindow::close,this), 489, 148, "hsbtns.def", SDLK_RETURN); + ok = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CCreatureWindow::close,this), 489, 148, "hsbtns.def", SDLK_RETURN); if (type <= BATTLE) //in battle or info window { @@ -206,8 +207,8 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * if (GameConstants::STACK_EXP) { int rank = std::min(stack->getExpRank(), 10); //hopefully nobody adds more - printAtMiddle(CGI->generaltexth->zcrexp[rank] + " [" + boost::lexical_cast(rank) + "]", 436, 62, FONT_MEDIUM, tytulowy,*bitmap); - printAtMiddle(boost::lexical_cast(stack->experience), 436, 82, FONT_SMALL, zwykly,*bitmap); + printAtMiddle(CGI->generaltexth->zcrexp[rank] + " [" + boost::lexical_cast(rank) + "]", 436, 62, FONT_MEDIUM, Colors::Jasmine,*bitmap); + printAtMiddle(boost::lexical_cast(stack->experience), 436, 82, FONT_SMALL, Colors::Cornsilk,*bitmap); if (type > BATTLE) //we need it only on adv. map { int tier = stack->type->level; @@ -244,7 +245,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * number = (stack->count * (expmax - expmin)) / expmin; boost::replace_first (expText, "%i", boost::lexical_cast(number)); //Maximum New Recruits to remain at Rank 10 if at Maximum Experience - expArea = new LRClickableAreaWTextComp(SRect(334, 49, 160, 44),SComponent::experience); + expArea = new LRClickableAreaWTextComp(Rect(334, 49, 160, 44),CComponent::experience); expArea->text = expText; expArea->bonusValue = 0; //TDO: some specific value or no number at all } @@ -256,8 +257,8 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * //creatureArtifact = new CArtPlace(NULL); //creatureArtifact->pos = rect; //creatureArtifact->ourOwner = NULL; //hmm? - leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, -1), 437, 98, "hsbtns3.def", SDLK_LEFT); - rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, +1), 516, 98, "hsbtns5.def", SDLK_RIGHT); + leftArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, -1), 437, 98, "hsbtns3.def", SDLK_LEFT); + rightArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, +1), 516, 98, "hsbtns5.def", SDLK_RIGHT); } else creatureArtifact = NULL; @@ -278,7 +279,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * int duration = battleStack->getBonus(Selector::source(Bonus::SPELL_EFFECT,effect))->turnsRemain; boost::replace_first (spellText, "%d", boost::lexical_cast(duration)); blitAt(graphics->spellEffectsPics->ourImages[effect + 1].bitmap, 20 + 52 * printed, 184, *bitmap); - spellEffects.push_back(new LRClickableAreaWText(SRect(20 + 52 * printed, 184, 50, 38), spellText, spellText)); + spellEffects.push_back(new LRClickableAreaWText(Rect(20 + 52 * printed, 184, 50, 38), spellText, spellText)); if (++printed >= 10) //we can fit only 10 effects break; } @@ -302,7 +303,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * void CCreatureWindow::printLine(int nr, const std::string &text, int baseVal, int val/*=-1*/, bool range/*=false*/) { - printAt(text, 162, 48 + nr*19, FONT_SMALL, zwykly, *bitmap); + printAt(text, 162, 48 + nr*19, FONT_SMALL, Colors::Cornsilk, *bitmap); std::string hlp; if(range && baseVal != val) @@ -312,7 +313,7 @@ void CCreatureWindow::printLine(int nr, const std::string &text, int baseVal, in else hlp = boost::lexical_cast(baseVal); - printTo(hlp, 325, 64 + nr*19, FONT_SMALL, zwykly, *bitmap); + printTo(hlp, 325, 64 + nr*19, FONT_SMALL, Colors::Cornsilk, *bitmap); } void CCreatureWindow::recreateSkillList(int Pos) @@ -329,7 +330,7 @@ void CCreatureWindow::recreateSkillList(int Pos) int offsetx = 257*j - (bonusRows == 4 ? 1 : 0); int offsety = 60*i + (bonusRows > 1 ? 1 : 0); //lack of precision :/ - bonusItems[n]->moveTo (SPoint(pos.x + offsetx + 10, pos.y + offsety + 230), true); + bonusItems[n]->moveTo (Point(pos.x + offsetx + 10, pos.y + offsety + 230), true); bonusItems[n]->visible = true; if (++j > 1) //next line @@ -348,7 +349,7 @@ void CCreatureWindow::showAll(SDL_Surface * to) { CIntObject::showAll(to); - printAtMiddle(c->namePl, 180, 30, FONT_SMALL, tytulowy,*bitmap); //creature name + printAtMiddle(c->namePl, 180, 30, FONT_SMALL, Colors::Jasmine,*bitmap); //creature name printLine(0, CGI->generaltexth->primarySkillNames[0], c->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), stackNode->Attack()); printLine(1, CGI->generaltexth->primarySkillNames[1], c->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), stackNode->Defense()); @@ -377,7 +378,7 @@ void CCreatureWindow::showAll(SDL_Surface * to) void CCreatureWindow::show(SDL_Surface * to) { if (count.size()) //army stack - printTo(count, pos.x + 114, pos.y + 174,FONT_TIMES, zwykly, to); + printTo(count, pos.x + 114, pos.y + 174,FONT_TIMES, Colors::Cornsilk, to); } @@ -428,7 +429,7 @@ CBonusItem::CBonusItem() } -CBonusItem::CBonusItem(const SRect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName) +CBonusItem::CBonusItem(const Rect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName) { OBJ_CONSTRUCTION; visible = false; @@ -447,8 +448,8 @@ void CBonusItem::showAll (SDL_Surface * to) { if (visible) { - printAt(name, pos.x + 72, pos.y + 6, FONT_SMALL, tytulowy, to); - printAt(description, pos.x + 72, pos.y + 30, FONT_SMALL, zwykly, to); + printAt(name, pos.x + 72, pos.y + 6, FONT_SMALL, Colors::Jasmine, to); + printAt(description, pos.x + 72, pos.y + 30, FONT_SMALL, Colors::Cornsilk, to); if (bonusGraphics && bonusGraphics->bg) blitAtLoc(bonusGraphics->bg, 12, 2, to); } @@ -458,3 +459,192 @@ CBonusItem::~CBonusItem() { //delete bonusGraphics; //automatic destruction } + +void CCreInfoWindow::show(SDL_Surface * to) +{ + CIntObject::show(to); + creatureCount->showAll(to); +} + +CCreInfoWindow::CCreInfoWindow(const CStackInstance &stack, bool LClicked, boost::function upgradeFunc, boost::function dismissFunc, UpgradeInfo *upgradeInfo) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + init(stack.type, &stack, dynamic_cast(stack.armyObj), stack.count, LClicked); + + //additional buttons if opened with left click + if(LClicked) + { + boost::function closeFunc = boost::bind(&CCreInfoWindow::close,this); + + if(upgradeFunc && upgradeInfo) + { + TResources upgradeCost = upgradeInfo->cost[0] * stack.count; + for(TResources::nziterator i(upgradeCost); i.valid(); i++) + { + BLOCK_CAPTURING; + upgResCost.push_back(new CComponent(CComponent::resource, i->resType, i->resVal)); + } + + CFunctionList onUpgrade; + onUpgrade += upgradeFunc; + onUpgrade += closeFunc; + + boost::function dialog = boost::bind(&CPlayerInterface::showYesNoDialog, + LOCPLINT, + CGI->generaltexth->allTexts[207], + boost::ref(upgResCost), + onUpgrade, 0, false); + + upgrade = new CAdventureMapButton("", CGI->generaltexth->zelp[446].second, dialog, 76, 237, "IVIEWCR", SDLK_u); + upgrade->block(!LOCPLINT->cb->getResourceAmount().canAfford(upgradeCost)); + } + + if(dismissFunc) + { + CFunctionList onDismiss; + onDismiss += dismissFunc; + onDismiss += closeFunc; + + boost::function dialog = boost::bind(&CPlayerInterface::showYesNoDialog, + LOCPLINT, + CGI->generaltexth->allTexts[12], + std::vector(), + onDismiss, 0, true); + + dismiss = new CAdventureMapButton("", CGI->generaltexth->zelp[445].second, dialog, 21, 237, "IVIEWCR2",SDLK_d); + } + + ok = new CAdventureMapButton("", CGI->generaltexth->zelp[445].second, + boost::bind(&CCreInfoWindow::close,this), 216, 237, "IOKAY.DEF", SDLK_RETURN); + } +} + +CCreInfoWindow::CCreInfoWindow(int creatureID, bool LClicked, int creatureCount) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + const CCreature *creature = CGI->creh->creatures[creatureID]; + init(creature, NULL, NULL, creatureCount, LClicked); +} + +CCreInfoWindow::CCreInfoWindow(const CStack &stack, bool LClicked) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + init(stack.getCreature(), &stack, stack.getMyHero(), stack.count, LClicked); +} + +CCreInfoWindow::~CCreInfoWindow() +{ + BOOST_FOREACH(CComponent* object, upgResCost) + delete object; +} + +void CCreInfoWindow::printLine(int position, const std::string &text, int baseVal, int val/*=-1*/, bool range/*=false*/) +{ + infoTexts[position].first = new CLabel(155, 48 + position*19, FONT_SMALL, TOPLEFT, Colors::Cornsilk, text); + std::string valueStr; + + if(range && baseVal != val) + valueStr = boost::str(boost::format("%d - %d") % baseVal % val); + + else if(baseVal != val && val>=0) + valueStr = boost::str(boost::format("%d (%d)") % baseVal % val); + + else + valueStr = boost::lexical_cast(baseVal); + + infoTexts[position].second = new CLabel(276, 63 + position*19, FONT_SMALL, BOTTOMRIGHT, Colors::Cornsilk, valueStr); +} + +void CCreInfoWindow::init(const CCreature *creature, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner, int count, bool LClicked) +{ + used = 0; + if (!LClicked) + used |= RCLICK; + + if(!stackNode) + stackNode = creature; + + background = new CPicture("CRSTKPU"); + background->colorize(LOCPLINT->playerID); + pos = background->center(); + + animation = new CCreaturePic(21, 48, creature); + + std::string countStr = boost::lexical_cast(count); + creatureCount = new CLabel(114, 174, FONT_TIMES, BOTTOMRIGHT, Colors::Cornsilk, countStr); + + creatureName = new CLabel(149, 30, FONT_SMALL, CENTER, Colors::Jasmine, creature->namePl); + + printLine(0, CGI->generaltexth->primarySkillNames[0], creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), stackNode->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK)); + printLine(1, CGI->generaltexth->primarySkillNames[1], creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), stackNode->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE)); + + if(stackNode->valOfBonuses(Bonus::SHOTS)) + printLine(2, CGI->generaltexth->allTexts[198], stackNode->valOfBonuses(Bonus::SHOTS)); + + //TODO + int dmgMultiply = 1; + if(heroOwner && stackNode->hasBonusOfType(Bonus::SIEGE_WEAPON)) + dmgMultiply += heroOwner->Attack(); + + printLine(3, CGI->generaltexth->allTexts[199], stackNode->getMinDamage() * dmgMultiply, stackNode->getMaxDamage() * dmgMultiply, true); + printLine(4, CGI->generaltexth->allTexts[388], creature->valOfBonuses(Bonus::STACK_HEALTH), stackNode->valOfBonuses(Bonus::STACK_HEALTH)); + printLine(6, CGI->generaltexth->zelp[441].first, creature->valOfBonuses(Bonus::STACKS_SPEED), stackNode->valOfBonuses(Bonus::STACKS_SPEED)); + + //setting morale + morale = new MoraleLuckBox(true, genRect(42, 42, 22, 186)); + morale->set(stackNode); + //setting luck + luck = new MoraleLuckBox(false, genRect(42, 42, 75, 186)); + luck->set(stackNode); + + if(!LClicked) + abilityText = new CLabel(17, 231, FONT_SMALL, TOPLEFT, Colors::Cornsilk, creature->abilityText); + else + abilityText = NULL; + + //if we are displying window fo r stack in battle, there are several more things that we need to display + if(const CStack *battleStack = dynamic_cast(stackNode)) + { + //print at most 3 spell effects + std::vector spells = battleStack->activeSpells(); + for (size_t i=0; i< std::min(spells.size(), size_t(3)); i++) + effects.push_back(new CAnimImage("SpellInt", spells[i]+1, 0, 127 + 52*i, 186)); + + //print current health + printLine(5, CGI->generaltexth->allTexts[200], battleStack->firstHPleft); + } +} + +void CCreInfoWindow::close() +{ + GH.popIntTotally(this); +} + +void CCreInfoWindow::clickRight(tribool down, bool previousState) +{ + close(); +} + +CIntObject * createCreWindow(const CStack *s) +{ + if(conf.cc.classicCreatureWindow) + return new CCreInfoWindow(*s); + else + return new CCreatureWindow(*s, CCreatureWindow::BATTLE); +} + +CIntObject * createCreWindow(int Cid, int Type, int creatureCount) +{ + if(conf.cc.classicCreatureWindow) + return new CCreInfoWindow(Cid, Type, creatureCount); + else + return new CCreatureWindow(Cid, Type, creatureCount); +} + +CIntObject * createCreWindow(const CStackInstance *s, int type, boost::function Upg, boost::function Dsm, UpgradeInfo *ui) +{ + if(conf.cc.classicCreatureWindow) + return new CCreInfoWindow(*s, type==3, Upg, Dsm, ui); + else + return new CCreatureWindow(*s, type, Upg, Dsm, ui); +} diff --git a/client/CCreatureWindow.h b/client/CCreatureWindow.h index 3c752f53c..97401c7bc 100644 --- a/client/CCreatureWindow.h +++ b/client/CCreatureWindow.h @@ -1,8 +1,8 @@ #pragma once - -#include "GUIClasses.h" +#include "UIFramework/CIntObject.h" #include "../lib/HeroBonus.h" +#include "GUIClasses.h" /* * CCreatureWindow.h, part of VCMI engine @@ -18,9 +18,23 @@ struct Bonus; class CCreature; class CStackInstance; class CStack; -class AdventureMapButton; +class CAdventureMapButton; class CBonusItem; +class CGHeroInstance; +class CComponent; +class LRClickableAreaWText; +class MoraleLuckBox; +class CAdventureMapButton; +struct UpgradeInfo; +class CPicture; +class CCreaturePic; +class LRClickableAreaWTextComp; +class CArtPlace; +class CSlider; +class CLabel; +class CAnimImage; +// Classical creature window class CCreatureWindow : public CIntObject { public: @@ -34,7 +48,7 @@ public: const CStackInstance *stack; const CBonusSystemNode *stackNode; const CGHeroInstance *heroOwner; - std::vector upgResCost; //cost of upgrade (if not possible then empty) + std::vector upgResCost; //cost of upgrade (if not possible then empty) std::vector bonusItems; std::vector spellEffects; @@ -44,8 +58,8 @@ public: LRClickableAreaWTextComp * expArea; //displays exp details CArtPlace *creatureArtifact; CSlider * slider; //Abilities - AdventureMapButton *dismiss, *upgrade, *ok; - AdventureMapButton * leftArtRoll, * rightArtRoll; //artifact selection + CAdventureMapButton *dismiss, *upgrade, *ok; + CAdventureMapButton * leftArtRoll, * rightArtRoll; //artifact selection //TODO: Artifact drop boost::function dsm; //dismiss button callback @@ -78,9 +92,44 @@ public: bool visible; CBonusItem(); - CBonusItem(const SRect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName); + CBonusItem(const Rect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName); ~CBonusItem(); void setBonus (const Bonus &bonus); void showAll (SDL_Surface * to); }; + +/// New Creature info window +class CCreInfoWindow : public CIntObject +{ +public: + CPicture * background; + CLabel * creatureCount; + CLabel * creatureName; + CLabel * abilityText; + + CCreaturePic * animation; + std::vector upgResCost; //cost of upgrade (if not possible then empty) + std::vector effects; + std::map > infoTexts; + + MoraleLuckBox * luck, * morale; + + CAdventureMapButton * dismiss, * upgrade, * ok; + + CCreInfoWindow(const CStackInstance & st, bool LClicked, boost::function Upg = 0, boost::function Dsm = 0, UpgradeInfo * ui = NULL); + CCreInfoWindow(const CStack & st, bool LClicked = 0); + CCreInfoWindow(int Cid, bool LClicked, int creatureCount); + ~CCreInfoWindow(); + + void init(const CCreature * cre, const CBonusSystemNode * stackNode, const CGHeroInstance * heroOwner, int creatureCount, bool LClicked); + void printLine(int nr, const std::string & text, int baseVal, int val = -1, bool range = false); + + void clickRight(tribool down, bool previousState); + void close(); + void show(SDL_Surface * to); +}; + +CIntObject *createCreWindow(const CStack *s); +CIntObject *createCreWindow(int Cid, int Type, int creatureCount); +CIntObject *createCreWindow(const CStackInstance *s, int type, boost::function Upg = 0, boost::function Dsm = 0, UpgradeInfo *ui = NULL); diff --git a/client/CHeroWindow.cpp b/client/CHeroWindow.cpp index 4ddda141c..1be224cf6 100644 --- a/client/CHeroWindow.cpp +++ b/client/CHeroWindow.cpp @@ -1,6 +1,5 @@ #include "StdInc.h" -#include "AdventureMapButton.h" #include "CAdvmapInterface.h" #include "../CCallback.h" #include "CGameInfo.h" @@ -8,7 +7,7 @@ #include "CMessage.h" #include "CKingdomInterface.h" #include "SDL.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "CBitmapHandler.h" #include "Graphics.h" #include "CSpellWindow.h" @@ -23,6 +22,7 @@ #include "../lib/CObjectHandler.h" #include "UIFramework/CGuiHandler.h" +#include "UIFramework/CIntObjectClasses.h" #undef min @@ -84,7 +84,7 @@ CHeroWindow * CHeroSwitcher::getOwner() CHeroSwitcher::CHeroSwitcher(int serial) { - pos = SRect(612, 87 + serial * 54, 48, 32) + pos; + pos = Rect(612, 87 + serial * 54, 48, 32) + pos; id = serial; used = LCLICK; } @@ -105,10 +105,10 @@ CHeroWindow::CHeroWindow(const CGHeroInstance *hero) //artifs = new CArtifactsOfHero(pos.topLeft(), true); ourBar = new CGStatusBar(7, 559, "ADROLLVR.bmp", 660); // new CStatusBar(pos.x+72, pos.y+567, "ADROLLVR.bmp", 660); - quitButton = new AdventureMapButton(CGI->generaltexth->heroscrn[17], std::string(),boost::bind(&CHeroWindow::quit,this), 609, 516, "hsbtns.def", SDLK_RETURN); + quitButton = new CAdventureMapButton(CGI->generaltexth->heroscrn[17], std::string(),boost::bind(&CHeroWindow::quit,this), 609, 516, "hsbtns.def", SDLK_RETURN); quitButton->assignedKeys.insert(SDLK_ESCAPE); - dismissButton = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[28], boost::bind(&CHeroWindow::dismissCurrent,this), 454, 429, "hsbtns2.def", SDLK_d); - questlogButton = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CHeroWindow::questlog,this), 314, 429, "hsbtns4.def", SDLK_q); + dismissButton = new CAdventureMapButton(std::string(), CGI->generaltexth->heroscrn[28], boost::bind(&CHeroWindow::dismissCurrent,this), 454, 429, "hsbtns2.def", SDLK_d); + questlogButton = new CAdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CHeroWindow::questlog,this), 314, 429, "hsbtns4.def", SDLK_q); formations = new CHighlightableButtonsGroup(0); formations->addButton(map_list_of(0,CGI->generaltexth->heroscrn[23]),CGI->generaltexth->heroscrn[29], "hsbtns6.def", 481, 483, 0, 0, SDLK_t); @@ -124,27 +124,27 @@ CHeroWindow::CHeroWindow(const CGHeroInstance *hero) flags = CDefHandler::giveDefEss("CREST58.DEF"); //areas - portraitArea = new LRClickableAreaWText(SRect(18, 18, 58, 64)); + portraitArea = new LRClickableAreaWText(Rect(18, 18, 58, 64)); for(int v=0; vtext = CGI->generaltexth->arraytxt[2+v]; area->type = v; area->hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1]) % CGI->generaltexth->primarySkillNames[v]); primSkillAreas.push_back(area); } - specArea = new LRClickableAreaWText(SRect(18, 180, 136, 42), CGI->generaltexth->heroscrn[27]); - expArea = new LRClickableAreaWText(SRect(18, 228, 136, 42), CGI->generaltexth->heroscrn[9]); - morale = new MoraleLuckBox(true, SRect(175,179,53,45)); - luck = new MoraleLuckBox(false, SRect(233,179,53,45)); - spellPointsArea = new LRClickableAreaWText(SRect(162,228, 136, 42), CGI->generaltexth->heroscrn[22]); + specArea = new LRClickableAreaWText(Rect(18, 180, 136, 42), CGI->generaltexth->heroscrn[27]); + expArea = new LRClickableAreaWText(Rect(18, 228, 136, 42), CGI->generaltexth->heroscrn[9]); + morale = new MoraleLuckBox(true, Rect(175,179,53,45)); + luck = new MoraleLuckBox(false, Rect(233,179,53,45)); + spellPointsArea = new LRClickableAreaWText(Rect(162,228, 136, 42), CGI->generaltexth->heroscrn[22]); for(int i = 0; i < std::min(hero->secSkills.size(), 8u); ++i) { - SRect r = SRect(i%2 == 0 ? 18 : 162, 276 + 48 * (i/2), 136, 42); - secSkillAreas.push_back(new LRClickableAreaWTextComp(r, SComponent::secskill)); + Rect r = Rect(i%2 == 0 ? 18 : 162, 276 + 48 * (i/2), 136, 42); + secSkillAreas.push_back(new LRClickableAreaWTextComp(r, CComponent::secskill)); } //////////////////////////////////////////////////////////////////////////??????????????? @@ -193,21 +193,21 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded /*= fals portraitArea->text = curHero->getBiography(); { - AdventureMapButton * split = NULL; + CAdventureMapButton * split = NULL; OBJ_CONSTRUCTION_CAPTURING_ALL; if(!garr) { - garr = new CGarrisonInt(15, 485, 8, SPoint(), background->bg, SPoint(15,485), curHero); + garr = new CGarrisonInt(15, 485, 8, Point(), background->bg, Point(15,485), curHero); { BLOCK_CAPTURING; - split = new AdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::bind(&CGarrisonInt::splitClick,garr), pos.x + 539, pos.y + 519, "hsbtns9.def", false, NULL, false); //deleted by garrison destructor + split = new CAdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::bind(&CGarrisonInt::splitClick,garr), pos.x + 539, pos.y + 519, "hsbtns9.def", false, NULL, false); //deleted by garrison destructor boost::algorithm::replace_first(split->hoverTexts[0],"%s",CGI->generaltexth->allTexts[43]); } garr->addSplitBtn(split); } if(!artSets.size()) { - CArtifactsOfHero *arts = new CArtifactsOfHero(SPoint(-65, -8), true); + CArtifactsOfHero *arts = new CArtifactsOfHero(Point(-65, -8), true); arts->setHero(curHero); artSets.push_back(arts); } @@ -287,7 +287,7 @@ void CHeroWindow::dismissCurrent() { CFunctionList ony = boost::bind(&CHeroWindow::quit,this); ony += boost::bind(&CCallback::dismissHero,LOCPLINT->cb,curHero); - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[22],std::vector(), ony, 0, false); + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[22],std::vector(), ony, 0, false); } void CHeroWindow::questlog() @@ -301,41 +301,41 @@ void CHeroWindow::showAll(SDL_Surface * to) blitAtLoc(graphics->portraitLarge[curHero->portrait], 19, 19, to); //printing hero's name - printAtMiddleLoc(curHero->name, 190, 38, FONT_BIG, tytulowy, to); + printAtMiddleLoc(curHero->name, 190, 38, FONT_BIG, Colors::Jasmine, to); //printing hero's level std::string secondLine= CGI->generaltexth->allTexts[342]; boost::algorithm::replace_first(secondLine,"%d",boost::lexical_cast(curHero->level)); boost::algorithm::replace_first(secondLine,"%s",curHero->type->heroClass->name); - printAtMiddleLoc(secondLine, 190, 65, FONT_MEDIUM, zwykly, to); + printAtMiddleLoc(secondLine, 190, 65, FONT_MEDIUM, Colors::Cornsilk, to); //primary skills names - printAtMiddleLoc(CGI->generaltexth->jktexts[1], 52, 99, FONT_SMALL, tytulowy, to); - printAtMiddleLoc(CGI->generaltexth->jktexts[2], 123, 99, FONT_SMALL, tytulowy, to); - printAtMiddleLoc(CGI->generaltexth->jktexts[3], 193, 99, FONT_SMALL, tytulowy, to); - printAtMiddleLoc(CGI->generaltexth->jktexts[4], 262, 99, FONT_SMALL, tytulowy, to); + printAtMiddleLoc(CGI->generaltexth->jktexts[1], 52, 99, FONT_SMALL, Colors::Jasmine, to); + printAtMiddleLoc(CGI->generaltexth->jktexts[2], 123, 99, FONT_SMALL, Colors::Jasmine, to); + printAtMiddleLoc(CGI->generaltexth->jktexts[3], 193, 99, FONT_SMALL, Colors::Jasmine, to); + printAtMiddleLoc(CGI->generaltexth->jktexts[4], 262, 99, FONT_SMALL, Colors::Jasmine, to); //dismiss / quest log std::vector toPrin = CMessage::breakText(CGI->generaltexth->jktexts[8]); if(toPrin.size()==1) { - printAtLoc(toPrin[0], 372, 439, FONT_SMALL, zwykly, to); + printAtLoc(toPrin[0], 372, 439, FONT_SMALL, Colors::Cornsilk, to); } else { - printAtLoc(toPrin[0], 372, 430, FONT_SMALL, zwykly, to); - printAtLoc(toPrin[1], 372, 446, FONT_SMALL, zwykly, to); + printAtLoc(toPrin[0], 372, 430, FONT_SMALL, Colors::Cornsilk, to); + printAtLoc(toPrin[1], 372, 446, FONT_SMALL, Colors::Cornsilk, to); } toPrin = CMessage::breakText(CGI->generaltexth->jktexts[9]); if(toPrin.size()==1) { - printAtLoc(toPrin[0], 512, 439, FONT_SMALL, zwykly, to); + printAtLoc(toPrin[0], 512, 439, FONT_SMALL, Colors::Cornsilk, to); } else { - printAtLoc(toPrin[0], 512, 430, FONT_SMALL, zwykly, to); - printAtLoc(toPrin[1], 512, 446, FONT_SMALL, zwykly, to); + printAtLoc(toPrin[0], 512, 430, FONT_SMALL, Colors::Cornsilk, to); + printAtLoc(toPrin[1], 512, 446, FONT_SMALL, Colors::Cornsilk, to); } //printing primary skills' amounts @@ -343,7 +343,7 @@ void CHeroWindow::showAll(SDL_Surface * to) { std::ostringstream primarySkill; primarySkill << primSkillAreas[m]->bonusValue; - printAtMiddleLoc(primarySkill.str(), 53 + 70 * m, 166, FONT_SMALL, zwykly, to); + printAtMiddleLoc(primarySkill.str(), 53 + 70 * m, 166, FONT_SMALL, Colors::Cornsilk, to); } blitAtLoc(flags->ourImages[player].bitmap, 606, 8, to); @@ -376,22 +376,22 @@ void CHeroWindow::showAll(SDL_Surface * to) for(size_t v=0; vsecSkills.size()); ++v) { blitAtLoc(graphics->abils44->ourImages[curHero->secSkills[v].first*3+3+curHero->secSkills[v].second-1].bitmap, v%2 ? 161 : 18, 276 + 48 * (v/2), to); - printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], v%2 ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, zwykly, to); - printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], v%2 ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, zwykly, to); + printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], v%2 ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to); + printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], v%2 ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to); } //printing special ability blitAtLoc(graphics->un44->ourImages[curHero->subID].bitmap, 18, 180, to); - printAtLoc(CGI->generaltexth->jktexts[5].substr(1, CGI->generaltexth->jktexts[5].size()-2), 69, 183, FONT_SMALL, tytulowy, to); - printAtLoc(CGI->generaltexth->hTxts[curHero->subID].bonusName, 69, 205, FONT_SMALL, zwykly, to); + printAtLoc(CGI->generaltexth->jktexts[5].substr(1, CGI->generaltexth->jktexts[5].size()-2), 69, 183, FONT_SMALL, Colors::Jasmine, to); + printAtLoc(CGI->generaltexth->hTxts[curHero->subID].bonusName, 69, 205, FONT_SMALL, Colors::Cornsilk, to); //printing necessery texts - printAtLoc(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 232, FONT_SMALL, tytulowy, to); + printAtLoc(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 232, FONT_SMALL, Colors::Jasmine, to); std::ostringstream expstr; expstr << curHero->exp; - printAtLoc(expstr.str(), 68, 252, FONT_SMALL, zwykly, to); - printAtLoc(CGI->generaltexth->jktexts[7].substr(1, CGI->generaltexth->jktexts[7].size()-2), 213, 232, FONT_SMALL, tytulowy, to); + printAtLoc(expstr.str(), 68, 252, FONT_SMALL, Colors::Cornsilk, to); + printAtLoc(CGI->generaltexth->jktexts[7].substr(1, CGI->generaltexth->jktexts[7].size()-2), 213, 232, FONT_SMALL, Colors::Jasmine, to); std::ostringstream manastr; manastr << curHero->mana << '/' << heroWArt.manaLimit(); - printAtLoc(manastr.str(), 211, 252, FONT_SMALL, zwykly, to); + printAtLoc(manastr.str(), 211, 252, FONT_SMALL, Colors::Cornsilk, to); } \ No newline at end of file diff --git a/client/CHeroWindow.h b/client/CHeroWindow.h index 2059b225d..a99f356fd 100644 --- a/client/CHeroWindow.h +++ b/client/CHeroWindow.h @@ -15,7 +15,7 @@ * */ -class AdventureMapButton; +class CAdventureMapButton; struct SDL_Surface; class CGHeroInstance; class CDefHandler; @@ -60,7 +60,7 @@ class CHeroWindow: public CWindowWithGarrison, public CWindowWithArtifacts CDefEssential *flags; //buttons - //AdventureMapButton * gar4button; //splitting + //CAdventureMapButton * gar4button; //splitting std::vector heroListMi; //new better list of heroes //clickable areas @@ -75,7 +75,7 @@ class CHeroWindow: public CWindowWithGarrison, public CWindowWithArtifacts public: const CGHeroInstance * curHero; - AdventureMapButton * quitButton, * dismissButton, * questlogButton; //general + CAdventureMapButton * quitButton, * dismissButton, * questlogButton; //general CHighlightableButton *tacticsButton; //garrison / formation handling; CHighlightableButtonsGroup *formations; diff --git a/client/CKingdomInterface.cpp b/client/CKingdomInterface.cpp index d088d3171..2bb9b6e37 100644 --- a/client/CKingdomInterface.cpp +++ b/client/CKingdomInterface.cpp @@ -6,7 +6,6 @@ #include "../lib/CGeneralTextHandler.h" #include "../lib/CObjectHandler.h" //Hero/Town objects #include "../lib/CHeroHandler.h" // only for calculating required xp? worth it? -#include "AdventureMapButton.h" #include "CAnimation.h" //CAnimImage #include "CAdvmapInterface.h" //CResDataBar #include "CCastleInterface.h" //various town-specific classes @@ -14,6 +13,7 @@ #include "CGameInfo.h" #include "CPlayerInterface.h" //LOCPLINT #include "UIFramework/CGuiHandler.h" +#include "UIFramework/CIntObjectClasses.h" /* * CKingdomInterface.cpp, part of VCMI engine @@ -27,7 +27,7 @@ extern SDL_Surface *screenBuf; -InfoBox::InfoBox(SPoint position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data): +InfoBox::InfoBox(Point position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data): size(Size), infoPos(Pos), data(Data), @@ -45,21 +45,21 @@ InfoBox::InfoBox(SPoint position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data pos = image->pos; if (infoPos == POS_CORNER) - value = new CLabel(pos.w, pos.h, font, BOTTOMRIGHT, zwykly, data->getValueText()); + value = new CLabel(pos.w, pos.h, font, BOTTOMRIGHT, Colors::Cornsilk, data->getValueText()); if (infoPos == POS_INSIDE) - value = new CLabel(pos.w/2, pos.h-6, font, CENTER, zwykly, data->getValueText()); + value = new CLabel(pos.w/2, pos.h-6, font, CENTER, Colors::Cornsilk, data->getValueText()); if (infoPos == POS_UP_DOWN || infoPos == POS_DOWN) - value = new CLabel(pos.w/2, pos.h+8, font, CENTER, zwykly, data->getValueText()); + value = new CLabel(pos.w/2, pos.h+8, font, CENTER, Colors::Cornsilk, data->getValueText()); if (infoPos == POS_UP_DOWN) - name = new CLabel(pos.w/2, -12, font, CENTER, zwykly, data->getNameText()); + name = new CLabel(pos.w/2, -12, font, CENTER, Colors::Cornsilk, data->getNameText()); if (infoPos == POS_RIGHT) { - name = new CLabel(pos.w+6, 6, font, TOPLEFT, zwykly, data->getNameText()); - value = new CLabel(pos.w+6, pos.h-16, font, TOPLEFT, zwykly, data->getValueText()); + name = new CLabel(pos.w+6, 6, font, TOPLEFT, Colors::Cornsilk, data->getNameText()); + value = new CLabel(pos.w+6, pos.h-16, font, TOPLEFT, Colors::Cornsilk, data->getValueText()); } pos = image->pos; if (name) @@ -67,7 +67,7 @@ InfoBox::InfoBox(SPoint position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data if (value) pos = pos | value->pos; - hover = new HoverableArea; + hover = new CHoverableArea; hover->hoverText = data->getHoverText(); hover->pos = pos; } @@ -81,7 +81,7 @@ void InfoBox::clickRight(tribool down, bool previousState) { if (down) { - SComponent *comp; + CComponent *comp; std::string text; data->prepareMessage(text, &comp); if (comp) @@ -95,11 +95,11 @@ void InfoBox::clickLeft(tribool down, bool previousState) { if((!down) && previousState) { - SComponent *comp; + CComponent *comp; std::string text; data->prepareMessage(text, &comp); - std::vector compVector; + std::vector compVector; if (comp) compVector.push_back(comp); LOCPLINT->showInfoDialog(text, compVector); @@ -253,7 +253,7 @@ size_t InfoBoxAbstractHeroData::getImageIndex() } } -bool InfoBoxAbstractHeroData::prepareMessage(std::string &text, SComponent **comp) +bool InfoBoxAbstractHeroData::prepareMessage(std::string &text, CComponent **comp) { switch (type) { @@ -263,7 +263,7 @@ bool InfoBoxAbstractHeroData::prepareMessage(std::string &text, SComponent **com return true; case HERO_PRIMARY_SKILL: text = CGI->generaltexth->arraytxt[2+getSubID()]; - *comp =new SComponent(SComponent::primskill, getSubID(), getValue()); + *comp =new CComponent(CComponent::primskill, getSubID(), getValue()); return true; case HERO_MANA: text = CGI->generaltexth->allTexts[149]; @@ -281,7 +281,7 @@ bool InfoBoxAbstractHeroData::prepareMessage(std::string &text, SComponent **com return false; text = CGI->generaltexth->skillInfoTexts[subID][value-1]; - *comp = new SComponent(SComponent::secskill, subID, value); + *comp = new CComponent(CComponent::secskill, subID, value); return true; } default: @@ -380,7 +380,7 @@ std::string InfoBoxHeroData::getValueText() } } -bool InfoBoxHeroData::prepareMessage(std::string &text, SComponent**comp) +bool InfoBoxHeroData::prepareMessage(std::string &text, CComponent**comp) { switch(type) { @@ -457,7 +457,7 @@ std::string InfoBoxCustom::getValueText() return valueText; } -bool InfoBoxCustom::prepareMessage(std::string &text, SComponent **comp) +bool InfoBoxCustom::prepareMessage(std::string &text, CComponent **comp) { return false; } @@ -470,7 +470,7 @@ CKingdomInterface::CKingdomInterface() pos = background->center(); ui32 footerPos = conf.go()->ac.overviewSize * 116; - tabArea = new CTabbedInt(boost::bind(&CKingdomInterface::createMainTab, this, _1), CTabbedInt::DestroyFunc(), SPoint(4,4)); + tabArea = new CTabbedInt(boost::bind(&CKingdomInterface::createMainTab, this, _1), CTabbedInt::DestroyFunc(), Point(4,4)); std::vector ownedObjects = LOCPLINT->cb->getMyObjects(); generateObjectsList(ownedObjects); @@ -531,7 +531,7 @@ void CKingdomInterface::generateObjectsList(const std::vector(obj.count); - return new InfoBox(SPoint(), InfoBox::POS_CORNER, InfoBox::SIZE_SMALL, + return new InfoBox(Point(), InfoBox::POS_CORNER, InfoBox::SIZE_SMALL, new InfoBoxCustom(value,"", "FLAGPORT", obj.imageID, obj.hoverText)); } return NULL; @@ -594,13 +594,13 @@ void CKingdomInterface::generateMinesList(const std::vector(minesCount[i]); - minesBox[i] = new InfoBox(SPoint(20+i*80, 31+footerPos), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, + minesBox[i] = new InfoBox(Point(20+i*80, 31+footerPos), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, new InfoBoxCustom(value, "", "OVMINES", i, CGI->generaltexth->mines[i].first)); } - incomeArea = new HoverableArea; - incomeArea->pos = SRect(pos.x+580, pos.y+31+footerPos, 136, 68); + incomeArea = new CHoverableArea; + incomeArea->pos = Rect(pos.x+580, pos.y+31+footerPos, 136, 68); incomeArea->hoverText = CGI->generaltexth->allTexts[255]; - incomeAmount = new CLabel(628, footerPos + 70, FONT_SMALL, TOPLEFT, zwykly, boost::lexical_cast(totalIncome)); + incomeAmount = new CLabel(628, footerPos + 70, FONT_SMALL, TOPLEFT, Colors::Cornsilk, boost::lexical_cast(totalIncome)); } void CKingdomInterface::generateButtons() @@ -608,31 +608,31 @@ void CKingdomInterface::generateButtons() ui32 footerPos = conf.go()->ac.overviewSize * 116; //Main control buttons - btnHeroes = new AdventureMapButton (CGI->generaltexth->overview[11], CGI->generaltexth->overview[6], + btnHeroes = new CAdventureMapButton (CGI->generaltexth->overview[11], CGI->generaltexth->overview[6], boost::bind(&CKingdomInterface::activateTab, this, 0),748,28+footerPos,"OVBUTN1.DEF", SDLK_h); btnHeroes->block(true); - btnTowns = new AdventureMapButton (CGI->generaltexth->overview[12], CGI->generaltexth->overview[7], + btnTowns = new CAdventureMapButton (CGI->generaltexth->overview[12], CGI->generaltexth->overview[7], boost::bind(&CKingdomInterface::activateTab, this, 1),748,64+footerPos,"OVBUTN6.DEF", SDLK_t); - btnExit = new AdventureMapButton (CGI->generaltexth->allTexts[600],"", + btnExit = new CAdventureMapButton (CGI->generaltexth->allTexts[600],"", boost::bind(&CGuiHandler::popIntTotally,&GH, this),748,99+footerPos,"OVBUTN1.DEF", SDLK_RETURN); btnExit->assignedKeys.insert(SDLK_ESCAPE); btnExit->setOffset(3); //Object list control buttons - dwellTop = new AdventureMapButton ("", "", boost::bind(&CListBox::moveToPos, dwellingsList, 0), + dwellTop = new CAdventureMapButton ("", "", boost::bind(&CListBox::moveToPos, dwellingsList, 0), 733, 4, "OVBUTN4.DEF"); - dwellBottom = new AdventureMapButton ("", "", boost::bind(&CListBox::moveToPos, dwellingsList, -1), + dwellBottom = new CAdventureMapButton ("", "", boost::bind(&CListBox::moveToPos, dwellingsList, -1), 733, footerPos+2, "OVBUTN4.DEF"); dwellBottom->setOffset(2); - dwellUp = new AdventureMapButton ("", "", boost::bind(&CListBox::moveToPrev, dwellingsList), + dwellUp = new CAdventureMapButton ("", "", boost::bind(&CListBox::moveToPrev, dwellingsList), 733, 24, "OVBUTN4.DEF"); dwellUp->setOffset(4); - dwellDown = new AdventureMapButton ("", "", boost::bind(&CListBox::moveToNext, dwellingsList), + dwellDown = new CAdventureMapButton ("", "", boost::bind(&CListBox::moveToNext, dwellingsList), 733, footerPos-18, "OVBUTN4.DEF"); dwellDown->setOffset(6); } @@ -685,13 +685,13 @@ CKingdHeroList::CKingdHeroList(size_t maxSize) OBJ_CONSTRUCTION_CAPTURING_ALL; title = new CPicture("OVTITLE",16,0); title->colorize(LOCPLINT->playerID); - heroLabel = new CLabel(150, 10, FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->overview[0]); - skillsLabel = new CLabel(500, 10, FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->overview[1]); + heroLabel = new CLabel(150, 10, FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[0]); + skillsLabel = new CLabel(500, 10, FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[1]); ui32 townCount = LOCPLINT->cb->howManyHeroes(false); ui32 size = conf.go()->ac.overviewSize*116 + 19; heroes = new CListBox(boost::bind(&CKingdHeroList::createHeroItem, this, _1), boost::bind(&CKingdHeroList::destroyHeroItem, this, _1), - SPoint(19,21), SPoint(0,116), maxSize, townCount, 0, 1, SRect(-19, -21, size, size) ); + Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size) ); } void CKingdHeroList::updateGarrisons() @@ -737,14 +737,14 @@ CKingdTownList::CKingdTownList(size_t maxSize) OBJ_CONSTRUCTION_CAPTURING_ALL; title = new CPicture("OVTITLE",16,0); title->colorize(LOCPLINT->playerID); - townLabel = new CLabel(146,10,FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->overview[3]); - garrHeroLabel = new CLabel(375,10,FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->overview[4]); - visitHeroLabel = new CLabel(608,10,FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->overview[5]); + townLabel = new CLabel(146,10,FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[3]); + garrHeroLabel = new CLabel(375,10,FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[4]); + visitHeroLabel = new CLabel(608,10,FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[5]); ui32 townCount = LOCPLINT->cb->howManyTowns(); ui32 size = conf.go()->ac.overviewSize*116 + 19; towns = new CListBox(boost::bind(&CKingdTownList::createTownItem, this, _1), CListBox::DestroyFunc(), - SPoint(19,21), SPoint(0,116), maxSize, townCount, 0, 1, SRect(-19, -21, size, size) ); + Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size) ); } void CKingdTownList::townChanged(const CGTownInstance *town) @@ -784,14 +784,14 @@ CTownItem::CTownItem(const CGTownInstance* Town): { OBJ_CONSTRUCTION_CAPTURING_ALL; background = new CAnimImage("OVSLOT", 6); - name = new CLabel(74, 8, FONT_SMALL, TOPLEFT, zwykly, town->name); + name = new CLabel(74, 8, FONT_SMALL, TOPLEFT, Colors::Cornsilk, town->name); - income = new CLabel( 190, 60, FONT_SMALL, CENTER, zwykly, boost::lexical_cast(town->dailyIncome())); + income = new CLabel( 190, 60, FONT_SMALL, CENTER, Colors::Cornsilk, boost::lexical_cast(town->dailyIncome())); hall = new CTownInfo( 69, 31, town, true); fort = new CTownInfo(111, 31, town, false); - garr = new CGarrisonInt(313, 3, 4, SPoint(232,0), NULL, SPoint(313,2), town->getUpperArmy(), town->visitingHero, true, true, true); - heroes = new HeroSlots(town, SPoint(244,6), SPoint(475,6), garr, false); + garr = new CGarrisonInt(313, 3, 4, Point(232,0), NULL, Point(313,2), town->getUpperArmy(), town->visitingHero, true, true, true); + heroes = new HeroSlots(town, Point(244,6), Point(475,6), garr, false); size_t iconIndex = town->subID*2; if (!town->hasFort()) @@ -802,13 +802,13 @@ CTownItem::CTownItem(const CGTownInstance* Town): picture = new CAnimImage("ITPT", iconIndex, 0, 5, 6); townArea = new LRClickableAreaOpenTown; - townArea->pos = SRect(pos.x+5, pos.y+6, 58, 64); + townArea->pos = Rect(pos.x+5, pos.y+6, 58, 64); townArea->town = town; for (size_t i=0; icreatures.size(); i++) { - growth.push_back(new CCreaInfo(SPoint(401+37*i, 78), town, i, true, true)); - available.push_back(new CCreaInfo(SPoint(48+37*i, 78), town, i, true, false)); + growth.push_back(new CCreaInfo(Point(401+37*i, 78), town, i, true, true)); + available.push_back(new CCreaInfo(Point(48+37*i, 78), town, i, true, false)); } } @@ -847,7 +847,7 @@ public: background = new CAnimImage("OVSLOT", 4); pos = background->pos; for (size_t i=0; i<9; i++) - arts.push_back(new CArtPlace(SPoint(270+i*48, 65))); + arts.push_back(new CArtPlace(Point(270+i*48, 65))); } }; @@ -856,18 +856,18 @@ class BackpackTab : public CIntObject public: CAnimImage * background; std::vector arts; - AdventureMapButton *btnLeft; - AdventureMapButton *btnRight; + CAdventureMapButton *btnLeft; + CAdventureMapButton *btnRight; BackpackTab() { OBJ_CONSTRUCTION_CAPTURING_ALL; background = new CAnimImage("OVSLOT", 5); pos = background->pos; - btnLeft = new AdventureMapButton(std::string(), std::string(), CFunctionList(), 269, 66, "HSBTNS3"); - btnRight = new AdventureMapButton(std::string(), std::string(), CFunctionList(), 675, 66, "HSBTNS5"); + btnLeft = new CAdventureMapButton(std::string(), std::string(), CFunctionList(), 269, 66, "HSBTNS3"); + btnRight = new CAdventureMapButton(std::string(), std::string(), CFunctionList(), 675, 66, "HSBTNS5"); for (size_t i=0; i<8; i++) - arts.push_back(new CArtPlace(SPoint(295+i*48, 65))); + arts.push_back(new CArtPlace(Point(295+i*48, 65))); } }; @@ -887,7 +887,7 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart * arts2->recActions = DISPOSE | SHARE_POS; backpack->recActions = DISPOSE | SHARE_POS; - name = new CLabel(75, 7, FONT_SMALL, TOPLEFT, zwykly, hero->name); + name = new CLabel(75, 7, FONT_SMALL, TOPLEFT, Colors::Cornsilk, hero->name); std::vector arts; arts.insert(arts.end(), arts1->arts.begin(), arts1->arts.end()); @@ -911,39 +911,39 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart * size_t begin = overlay.find('{'); size_t end = overlay.find('}', begin); overlay = overlay.substr(begin+1, end - begin); - artButtons->buttons[it]->addTextOverlay(overlay, FONT_SMALL, tytulowy); + artButtons->buttons[it]->addTextOverlay(overlay, FONT_SMALL, Colors::Jasmine); } artButtons->onChange += boost::bind(&CTabbedInt::setActive, artsTabs, _1); artButtons->onChange += boost::bind(&CHeroItem::onArtChange, this, _1); artButtons->select(0,0); - garr = new CGarrisonInt(6, 78, 4, SPoint(), NULL, SPoint(), hero, NULL, true, true); + garr = new CGarrisonInt(6, 78, 4, Point(), NULL, Point(), hero, NULL, true, true); portrait = new CAnimImage("PortraitsLarge", hero->subID, 0, 5, 6); heroArea = new CHeroArea(5, 6, hero); - name = new CLabel(73, 7, FONT_SMALL, TOPLEFT, zwykly, hero->name); - artsText = new CLabel(320, 55, FONT_SMALL, CENTER, zwykly, CGI->generaltexth->overview[2]); + name = new CLabel(73, 7, FONT_SMALL, TOPLEFT, Colors::Cornsilk, hero->name); + artsText = new CLabel(320, 55, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[2]); for (size_t i=0; iset(hero); luck->set(hero); diff --git a/client/CKingdomInterface.h b/client/CKingdomInterface.h index 5f689d690..872196b94 100644 --- a/client/CKingdomInterface.h +++ b/client/CKingdomInterface.h @@ -3,7 +3,7 @@ #include "GUIClasses.h" -class AdventureMapButton; +class CAdventureMapButton; class CAnimImage; class CHighlightableButtonsGroup; class CResDataBar; @@ -61,10 +61,10 @@ private: CLabel * value; CLabel * name; CAnimImage * image; - HoverableArea *hover; + CHoverableArea *hover; public: - InfoBox(SPoint position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data); + InfoBox(Point position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data); ~InfoBox(); void clickRight(tribool down, bool previousState); @@ -100,7 +100,7 @@ public: virtual size_t getImageIndex()=0; //TODO: replace with something better - virtual bool prepareMessage(std::string &text, SComponent **comp)=0; + virtual bool prepareMessage(std::string &text, CComponent **comp)=0; }; class InfoBoxAbstractHeroData : public IInfoBoxData @@ -118,7 +118,7 @@ public: std::string getHoverText(); size_t getImageIndex(); - bool prepareMessage(std::string &text, SComponent **comp); + bool prepareMessage(std::string &text, CComponent **comp); }; class InfoBoxHeroData : public InfoBoxAbstractHeroData @@ -136,7 +136,7 @@ public: std::string getHoverText(); std::string getValueText(); - bool prepareMessage(std::string &text, SComponent **comp); + bool prepareMessage(std::string &text, CComponent **comp); }; class InfoBoxCustomHeroData : public InfoBoxAbstractHeroData @@ -168,7 +168,7 @@ public: std::string getHoverText(); size_t getImageIndex(); - bool prepareMessage(std::string &text, SComponent **comp); + bool prepareMessage(std::string &text, CComponent **comp); }; //TODO!!! @@ -208,17 +208,17 @@ private: CPicture * background; //Main buttons - AdventureMapButton *btnTowns; - AdventureMapButton *btnHeroes; - AdventureMapButton *btnExit; + CAdventureMapButton *btnTowns; + CAdventureMapButton *btnHeroes; + CAdventureMapButton *btnExit; //Buttons for scrolling dwellings list - AdventureMapButton *dwellUp, *dwellDown; - AdventureMapButton *dwellTop, *dwellBottom; + CAdventureMapButton *dwellUp, *dwellDown; + CAdventureMapButton *dwellTop, *dwellBottom; InfoBox * minesBox[7]; - HoverableArea * incomeArea; + CHoverableArea * incomeArea; CLabel * incomeAmount; CGStatusBar * statusbar; diff --git a/client/CMT.cpp b/client/CMT.cpp index 6b4a361ae..e5a659efa 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -3,15 +3,14 @@ #include "StdInc.h" #include #include -#include "SDL_Extensions.h" -#include "SDL_framerate.h" +#include "UIFramework/SDL_Extensions.h" #include "CGameInfo.h" #include "mapHandler.h" #include "CPreGame.h" #include "CCastleInterface.h" #include "../lib/CConsoleHandler.h" -#include "CCursorHandler.h" +#include "UIFramework/CCursorHandler.h" #include "../lib/CGameState.h" #include "../CCallback.h" #include "CPlayerInterface.h" diff --git a/client/CMessage.cpp b/client/CMessage.cpp index 24e3a9863..4a9178cdc 100644 --- a/client/CMessage.cpp +++ b/client/CMessage.cpp @@ -5,14 +5,14 @@ #include "CDefHandler.h" #include "CAnimation.h" #include "CGameInfo.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "../lib/CLodHandler.h" #include "../lib/CGeneralTextHandler.h" #include "Graphics.h" #include "GUIClasses.h" -#include "AdventureMapButton.h" #include "CConfigHandler.h" #include "CBitmapHandler.h" +#include "UIFramework/CIntObjectClasses.h" /* * CMessage.cpp, part of VCMI engine @@ -24,11 +24,6 @@ * */ -SDL_Color tytulowy = {229, 215, 123, 0}, - tlo = {66, 44, 24, 0}, - zwykly = {255, 243, 222, 0}, - darkTitle = {215, 175, 78, 0}; - extern SDL_Surface * screen; using namespace NMessage; @@ -106,8 +101,8 @@ SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for { for (int j=0; jh) { - SRect srcR(0,0,background->w, background->h); - SRect dstR(i,j,w,h); + Rect srcR(0,0,background->w, background->h); + Rect dstR(i,j,w,h); CSDL_Ext::blitSurface(background, &srcR, ret, &dstR); } } @@ -261,7 +256,7 @@ SDL_Surface * CMessage::blitTextOnSur(std::vector > * return ret; } -SDL_Surface * FNT_RenderText (EFonts font, std::string text, SDL_Color kolor= zwykly) +SDL_Surface * FNT_RenderText (EFonts font, std::string text, SDL_Color kolor= Colors::Cornsilk) { if (graphics->fontsTrueType[font]) return TTF_RenderText_Blended(graphics->fontsTrueType[font], text.c_str(), kolor); @@ -296,7 +291,7 @@ std::vector > * CMessage::drawText(std::vector > * CMessage::drawText(std::vectorw/2)-(bitmap->w/2),curh,ret); curh += bitmap->h + 5; - CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+10,FONT_SMALL,zwykly,ret); + CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+10,FONT_SMALL,Colors::Cornsilk,ret); delete txtg; return ret; } @@ -389,7 +384,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player) //int fontHeight = f.height; if(dynamic_cast(ret)) //it's selection window, so we'll blit "or" between components - _or = FNT_RenderText(FONT_MEDIUM,CGI->generaltexth->allTexts[4],zwykly); + _or = FNT_RenderText(FONT_MEDIUM,CGI->generaltexth->allTexts[4],Colors::Cornsilk); const int sizes[][2] = {{400, 125}, {500, 150}, {600, 200}, {480, 400}}; @@ -446,7 +441,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player) curh = (ret->bitmap->h - ret->text->pos.h)/2; } - ret->text->moveBy(SPoint(xOffset, curh)); + ret->text->moveBy(Point(xOffset, curh)); curh += ret->text->pos.h; @@ -463,7 +458,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player) for(size_t i=0; ibuttons.size(); i++) { - ret->buttons[i]->moveBy(SPoint(bw, curh)); + ret->buttons[i]->moveBy(Point(bw, curh)); bw += ret->buttons[i]->pos.w + 20; } } @@ -493,8 +488,8 @@ void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int cur_w = box[6]->w; // Top border - SRect srcR(0, 0, cur_w, box[6]->h); - SRect dstR(start_x, y, 0, 0); + Rect srcR(0, 0, cur_w, box[6]->h); + Rect dstR(start_x, y, 0, 0); CSDL_Ext::blitSurface(box[6], &srcR, ret, &dstR); // Bottom border @@ -514,8 +509,8 @@ void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int cur_h = box[4]->h; // Left border - SRect srcR(0, 0, box[4]->w, cur_h); - SRect dstR(x, start_y, 0, 0); + Rect srcR(0, 0, box[4]->w, cur_h); + Rect dstR(x, start_y, 0, 0); CSDL_Ext::blitSurface(box[4], &srcR, ret, &dstR); // Right border @@ -526,16 +521,16 @@ void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int } //corners - SRect dstR(x, y, box[0]->w, box[0]->h); + Rect dstR(x, y, box[0]->w, box[0]->h); CSDL_Ext::blitSurface(box[0], NULL, ret, &dstR); - dstR=SRect(x+w-box[1]->w, y, box[1]->w, box[1]->h); + dstR=Rect(x+w-box[1]->w, y, box[1]->w, box[1]->h); CSDL_Ext::blitSurface(box[1], NULL, ret, &dstR); - dstR=SRect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h); + dstR=Rect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h); CSDL_Ext::blitSurface(box[2], NULL, ret, &dstR); - dstR=SRect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h); + dstR=Rect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h); CSDL_Ext::blitSurface(box[3], NULL, ret, &dstR); } @@ -547,7 +542,7 @@ ComponentResolved::ComponentResolved() txtFontHeight = 0; } -ComponentResolved::ComponentResolved( SComponent *Comp ) +ComponentResolved::ComponentResolved( CComponent *Comp ) { comp = Comp; img = comp->getImg(); @@ -577,7 +572,7 @@ ComponentsToBlit::~ComponentsToBlit() } -ComponentsToBlit::ComponentsToBlit(std::vector & SComps, int maxw, SDL_Surface* _or) +ComponentsToBlit::ComponentsToBlit(std::vector & SComps, int maxw, SDL_Surface* _or) { w = h = 0; if(SComps.empty()) diff --git a/client/CMessage.h b/client/CMessage.h index d43fd034f..32324ee6f 100644 --- a/client/CMessage.h +++ b/client/CMessage.h @@ -20,7 +20,7 @@ class MapSel; class CSimpleWindow; class CInfoWindow; class CDefHandler; -class SComponent; +class CComponent; class CSelWindow; class CSelectableComponent; namespace NMessage @@ -32,14 +32,14 @@ namespace NMessage struct ComponentResolved { - SComponent *comp; + CComponent *comp; SDL_Surface *img; std::vector > * txt; int txtFontHeight; ComponentResolved(); //c-tor - ComponentResolved(SComponent *Comp); //c-tor + ComponentResolved(CComponent *Comp); //c-tor ~ComponentResolved(); //d-tor }; @@ -49,7 +49,7 @@ struct ComponentsToBlit int w, h; void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret); - ComponentsToBlit(std::vector & SComps, int maxw, SDL_Surface* _or); //c-tor + ComponentsToBlit(std::vector & SComps, int maxw, SDL_Surface* _or); //c-tor ~ComponentsToBlit(); //d-tor }; diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 31630cc94..92c959272 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -2,18 +2,17 @@ #include "CAdvmapInterface.h" #include "BattleInterface/CBattleInterface.h" -#include "BattleInterface/CBattleConsole.h" +#include "BattleInterface/CBattleInterfaceClasses.h" #include "../CCallback.h" #include "CCastleInterface.h" -#include "CCursorHandler.h" +#include "UIFramework/CCursorHandler.h" #include "CKingdomInterface.h" #include "CGameInfo.h" #include "CHeroWindow.h" #include "CMessage.h" #include "CPlayerInterface.h" -//#include "SDL_Extensions.h" -#include "SDL_Extensions.h" -#include "SDL_framerate.h" +//#include "UIFramework/SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "CConfigHandler.h" #include "BattleInterface/CCreatureAnimation.h" #include "Graphics.h" @@ -187,8 +186,8 @@ void CPlayerInterface::yourTurn() makingTurn = true; std::string msg = CGI->generaltexth->allTexts[13]; boost::replace_first(msg, "%s", cb->getStartInfo()->playerInfos.find(playerID)->second.name); - std::vector cmp; - cmp.push_back(new SComponent(SComponent::flag, playerID, 0)); + std::vector cmp; + cmp.push_back(new CComponent(CComponent::flag, playerID, 0)); showInfoDialog(msg, cmp); } else @@ -756,7 +755,7 @@ void CPlayerInterface::battleEnd(const BattleResult *br) battleInt->battleFinished(*br); } -void CPlayerInterface::battleStackMoved(const CStack * stack, std::vector dest, int distance) +void CPlayerInterface::battleStackMoved(const CStack * stack, std::vector dest, int distance) { if(LOCPLINT != this) { //another local interface should do this @@ -802,7 +801,7 @@ void CPlayerInterface::battleStacksAttacked(const std::vector arg; + std::vector arg; for(std::vector::const_iterator i = bsa.begin(); i != bsa.end(); i++) { const CStack *defender = cb->battleGetStackByID(i->stackAttacked, false); @@ -812,7 +811,7 @@ void CPlayerInterface::battleStacksAttacked(const std::vectorisSecondary()) battleInt->displayEffect(i->effect, defender->position); } - SStackAttackedInfo to_put = {defender, i->damageAmount, i->killedAmount, attacker, LOCPLINT->curAction->actionType==7, i->killed(), i->willRebirth()}; + StackAttackedInfo to_put = {defender, i->damageAmount, i->killedAmount, attacker, LOCPLINT->curAction->actionType==7, i->killed(), i->willRebirth()}; arg.push_back(to_put); } @@ -874,10 +873,10 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba) else { int shift = 0; - if(ba->counter() && SBattleHex::mutualPosition(curAction->destinationTile, attacker->position) < 0) + if(ba->counter() && BattleHex::mutualPosition(curAction->destinationTile, attacker->position) < 0) { - int distp = SBattleHex::getDistance(curAction->destinationTile + 1, attacker->position); - int distm = SBattleHex::getDistance(curAction->destinationTile - 1, attacker->position); + int distp = BattleHex::getDistance(curAction->destinationTile + 1, attacker->position); + int distm = BattleHex::getDistance(curAction->destinationTile - 1, attacker->position); if( distp < distm ) shift = 1; @@ -895,7 +894,7 @@ void CPlayerInterface::yourTacticPhase(int distance) boost::this_thread::sleep(boost::posix_time::millisec(1)); } -void CPlayerInterface::showComp(SComponent comp) +void CPlayerInterface::showComp(CComponent comp) { boost::unique_lock un(*pim); @@ -906,13 +905,13 @@ void CPlayerInterface::showComp(SComponent comp) void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector &components, int soundID) { - std::vector intComps; + std::vector intComps; for(int i=0;i & components, int soundID, bool delComps) +void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector & components, int soundID, bool delComps) { waitWhileDialog(); boost::unique_lock un(*pim); @@ -932,7 +931,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector } } -void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vector & components, CFunctionList onYes, CFunctionList onNo, bool DelComps) +void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vector & components, CFunctionList onYes, CFunctionList onNo, bool DelComps) { boost::unique_lock un(*pim); @@ -951,9 +950,9 @@ void CPlayerInterface::showBlockingDialog( const std::string &text, const std::v if(!selection && cancel) //simple yes/no dialog { - std::vector intComps; + std::vector intComps; for(int i=0;iarth->artifacts[artifactID]; std::string text = artifact.Description(); text += "\n\n"; - std::vector scs; + std::vector scs; if (assemble) { const CArtifact &assembledArtifact = *CGI->arth->artifacts[assembleTo]; @@ -1290,8 +1289,8 @@ void CPlayerInterface::showArtifactAssemblyDialog (ui32 artifactID, ui32 assembl text += boost::str(boost::format(CGI->generaltexth->allTexts[732]) % assembledArtifact.Name()); // Picture of assembled artifact at bottom. - SComponent* sc = new SComponent; - sc->type = SComponent::artifact; + CComponent* sc = new CComponent; + sc->type = CComponent::artifact; sc->subtype = assembledArtifact.id; sc->description = assembledArtifact.Description(); sc->subtitle = assembledArtifact.Name(); @@ -1994,7 +1993,7 @@ void CPlayerInterface::gameOver(ui8 player, bool victory ) { std::string txt = CGI->generaltexth->allTexts[5]; //%s has been vanquished! boost::algorithm::replace_first(txt, "%s", CGI->generaltexth->capColors[player]); - showInfoDialog(txt,std::vector(1, new SComponent(SComponent::flag, player, 0))); + showInfoDialog(txt,std::vector(1, new CComponent(CComponent::flag, player, 0))); } } } diff --git a/client/CPlayerInterface.h b/client/CPlayerInterface.h index 34d689ee2..eea570d21 100644 --- a/client/CPlayerInterface.h +++ b/client/CPlayerInterface.h @@ -4,7 +4,7 @@ #include "../lib/CondSh.h" #include "FunctionList.h" #include "../lib/CGameInterface.h" -#include "UIFramework/IUpdateable.h" +#include "UIFramework/CIntObject.h" #ifdef __GNUC__ #define sprintf_s snprintf @@ -28,7 +28,7 @@ */ class CDefEssential; -class AdventureMapButton; +class CAdventureMapButton; class CHighlightableButtonsGroup; class CDefHandler; struct TryMoveHero; @@ -38,7 +38,7 @@ class CAdvMapInt; class CCastleInterface; class CBattleInterface; class CStack; -class SComponent; +class CComponent; class CCreature; struct SDL_Surface; struct CGPath; @@ -218,7 +218,7 @@ public: void battleEnd(const BattleResult *br) OVERRIDE; //end of battle void battleNewRoundFirst(int round) OVERRIDE; //called at the beginning of each turn before changes are applied; used for HP regen handling void battleNewRound(int round) OVERRIDE; //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; + void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE; void battleSpellCast(const BattleSpellCast *sc) OVERRIDE; void battleStacksEffectsSet(const SetStackEffect & sse) OVERRIDE; //called when a specific effect is set to stacks void battleTriggerEffect(const BattleTriggerEffect & bte) OVERRIDE; //various one-shot effect @@ -240,15 +240,15 @@ public: bool ctrlPressed() const; //determines if ctrl key is pressed (left or right or both) bool altPressed() const; //determines if alt key is pressed (left or right or both) void redrawHeroWin(const CGHeroInstance * hero); - void showComp(SComponent comp); //TODO: comment me + void showComp(CComponent comp); //TODO: comment me void openTownWindow(const CGTownInstance * town); //shows townscreen void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero void updateInfo(const CGObjectInstance * specific); void init(CCallback * CB); int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on - void showInfoDialog(const std::string &text, const std::vector & components = std::vector(), int soundID = 0, bool delComps = false); - void showYesNoDialog(const std::string &text, const std::vector & components, CFunctionList onYes, CFunctionList onNo, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close + void showInfoDialog(const std::string &text, const std::vector & components = std::vector(), int soundID = 0, bool delComps = false); + void showYesNoDialog(const std::string &text, const std::vector & components, CFunctionList onYes, CFunctionList onNo, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close void stopMovement(); bool moveHero(const CGHeroInstance *h, CGPath path); void initMovement(const TryMoveHero &details, const CGHeroInstance * ho, const int3 &hp );//initializing objects and performing first step of move diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index b02af4996..d74bbca5c 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -3,9 +3,9 @@ #include #include "../lib/CStopWatch.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "CGameInfo.h" -#include "CCursorHandler.h" +#include "UIFramework/CCursorHandler.h" #include "CAnimation.h" #include "CDefHandler.h" #include "../lib/CDefObjInfoHandler.h" @@ -23,7 +23,6 @@ #include "../lib/Connection.h" #include "../lib/VCMIDirs.h" #include "../lib/map.h" -#include "AdventureMapButton.h" #include "GUIClasses.h" #include "CPlayerInterface.h" #include "../CCallback.h" @@ -40,6 +39,7 @@ #include "../lib/CFileUtility.h" #include "../lib/GameConstants.h" #include "UIFramework/CGuiHandler.h" +#include "UIFramework/CIntObjectClasses.h" /* * CPreGame.cpp, part of VCMI engine @@ -311,7 +311,7 @@ static boost::function genCommand(CMenuScreen* menu, std::vectorgeneraltexth->allTexts[69]), (const std::vector*)0, do_quit, 0, false, 1); + return boost::bind(CInfoWindow::showYesNoDialog, boost::ref(CGI->generaltexth->allTexts[69]), (const std::vector*)0, do_quit, 0, false, 1); } break; case 5://highscores { @@ -324,7 +324,7 @@ static boost::function genCommand(CMenuScreen* menu, std::vector(); } -AdventureMapButton* CMenuEntry::createButton(CMenuScreen* parent, const JsonNode& button) +CAdventureMapButton* CMenuEntry::createButton(CMenuScreen* parent, const JsonNode& button) { boost::function command = genCommand(parent, parent->menuNameToEntry, button["command"].String()); @@ -332,7 +332,7 @@ AdventureMapButton* CMenuEntry::createButton(CMenuScreen* parent, const JsonNode if (!button["help"].isNull() && button["help"].Float() > 0) help = CGI->generaltexth->zelp[button["help"].Float()]; - return new AdventureMapButton(help, command, button["x"].Float(), button["y"].Float(), button["name"].String(), button["hotkey"].Float()); + return new CAdventureMapButton(help, command, button["x"].Float(), button["y"].Float(), button["name"].String(), button["hotkey"].Float()); } CMenuEntry::CMenuEntry(CMenuScreen* parent, const JsonNode &config) @@ -361,11 +361,11 @@ CreditsScreen::CreditsScreen() std::string text = bitmaph->getTextFile("CREDITS"); size_t firstQuote = text.find('\"')+1; text = text.substr(firstQuote, text.find('\"', firstQuote) - firstQuote ); - credits = new CTextBox(text, SRect(450, 600, 350, 32000), 0, FONT_CREDITS, CENTER, zwykly); + credits = new CTextBox(text, Rect(450, 600, 350, 32000), 0, FONT_CREDITS, CENTER, Colors::Cornsilk); credits->pos.h = credits->maxH; } -void CreditsScreen::show(SDL_Surface *to) +void CreditsScreen::show(SDL_Surface * to) { static int count = 0; count++; @@ -542,20 +542,20 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti { card->difficulty->onChange = bind(&CSelectionScreen::difficultyChange, this, _1); card->difficulty->select(1, 0); - AdventureMapButton *select = new AdventureMapButton(CGI->generaltexth->zelp[45], bind(&CSelectionScreen::toggleTab, this, sel), 411, 75, "GSPBUTT.DEF", SDLK_s); + CAdventureMapButton *select = new CAdventureMapButton(CGI->generaltexth->zelp[45], bind(&CSelectionScreen::toggleTab, this, sel), 411, 75, "GSPBUTT.DEF", SDLK_s); select->addTextOverlay(CGI->generaltexth->allTexts[500], FONT_SMALL); - AdventureMapButton *opts = new AdventureMapButton(CGI->generaltexth->zelp[46], bind(&CSelectionScreen::toggleTab, this, opt), 411, 503, "GSPBUTT.DEF", SDLK_a); + CAdventureMapButton *opts = new CAdventureMapButton(CGI->generaltexth->zelp[46], bind(&CSelectionScreen::toggleTab, this, opt), 411, 503, "GSPBUTT.DEF", SDLK_a); opts->addTextOverlay(CGI->generaltexth->allTexts[501], FONT_SMALL); - AdventureMapButton *random = new AdventureMapButton(CGI->generaltexth->zelp[47], bind(&CSelectionScreen::toggleTab, this, sel), 411, 99, "GSPBUTT.DEF", SDLK_r); + CAdventureMapButton *random = new CAdventureMapButton(CGI->generaltexth->zelp[47], bind(&CSelectionScreen::toggleTab, this, sel), 411, 99, "GSPBUTT.DEF", SDLK_r); random->addTextOverlay(CGI->generaltexth->allTexts[740], FONT_SMALL); - start = new AdventureMapButton(CGI->generaltexth->zelp[103], bind(&CSelectionScreen::startGame, this), 411, 529, "SCNRBEG.DEF", SDLK_b); + start = new CAdventureMapButton(CGI->generaltexth->zelp[103], bind(&CSelectionScreen::startGame, this), 411, 529, "SCNRBEG.DEF", SDLK_b); if(network) { - AdventureMapButton *hideChat = new AdventureMapButton(CGI->generaltexth->zelp[48], bind(&InfoCard::toggleChat, card), 619, 75, "GSPBUT2.DEF", SDLK_h); + CAdventureMapButton *hideChat = new CAdventureMapButton(CGI->generaltexth->zelp[48], bind(&InfoCard::toggleChat, card), 619, 75, "GSPBUT2.DEF", SDLK_h); hideChat->addTextOverlay(CGI->generaltexth->allTexts[531], FONT_SMALL); if(multiPlayer == CMenuScreen::MULTI_NETWORK_GUEST) @@ -572,15 +572,15 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti break; case CMenuScreen::loadGame: sel->recActions = 255; - start = new AdventureMapButton(CGI->generaltexth->zelp[103], bind(&CSelectionScreen::startGame, this), 411, 529, "SCNRLOD.DEF", SDLK_l); + start = new CAdventureMapButton(CGI->generaltexth->zelp[103], bind(&CSelectionScreen::startGame, this), 411, 529, "SCNRLOD.DEF", SDLK_l); break; case CMenuScreen::saveGame: sel->recActions = 255; - start = new AdventureMapButton("", CGI->generaltexth->zelp[103].second, bind(&CSelectionScreen::startGame, this), 411, 529, "SCNRSAV.DEF"); + start = new CAdventureMapButton("", CGI->generaltexth->zelp[103].second, bind(&CSelectionScreen::startGame, this), 411, 529, "SCNRSAV.DEF"); break; case CMenuScreen::campaignList: sel->recActions = 255; - start = new AdventureMapButton(std::pair(), bind(&CSelectionScreen::startCampaign, this), 411, 529, "SCNRLOD.DEF", SDLK_b); + start = new CAdventureMapButton(std::pair(), bind(&CSelectionScreen::startCampaign, this), 411, 529, "SCNRLOD.DEF", SDLK_b); break; } @@ -597,7 +597,7 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti backName = "SCNRBACK.DEF"; } - back = new AdventureMapButton("", CGI->generaltexth->zelp[105].second, bind(&CGuiHandler::popIntTotally, &GH, this), 581, 529, backName, SDLK_ESCAPE); + back = new CAdventureMapButton("", CGI->generaltexth->zelp[105].second, bind(&CGuiHandler::popIntTotally, &GH, this), 581, 529, backName, SDLK_ESCAPE); if(network) { @@ -792,7 +792,7 @@ void CSelectionScreen::startGame() { std::string hlp = CGI->generaltexth->allTexts[493]; //%s exists. Overwrite? boost::algorithm::replace_first(hlp, "%s", sel->txt->text); - LOCPLINT->showYesNoDialog(hlp, std::vector(), overWrite, 0, false); + LOCPLINT->showYesNoDialog(hlp, std::vector(), overWrite, 0, false); } else overWrite(); @@ -1089,7 +1089,7 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::functiongeneraltexth->zelp[54+i].second, bind(&SelectionTab::filter, this, sizes[i], true), 158 + 47*i, 46, names[i]); + new CAdventureMapButton("", CGI->generaltexth->zelp[54+i].second, bind(&SelectionTab::filter, this, sizes[i], true), 158 + 47*i, 46, names[i]); } //sort buttons buttons @@ -1137,14 +1137,14 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::functiongeneraltexth->zelp[107+i].second, bind(&SelectionTab::sortBy, this, i), xpos[i], 86, names[i]); + new CAdventureMapButton("", CGI->generaltexth->zelp[107+i].second, bind(&SelectionTab::sortBy, this, i), xpos[i], 86, names[i]); } } else { //sort by buttons - new AdventureMapButton("", "", bind(&SelectionTab::sortBy, this, _numOfMaps), 23, 86, "CamCusM.DEF"); //by num of maps - new AdventureMapButton("", "", bind(&SelectionTab::sortBy, this, _name), 55, 86, "CamCusL.DEF"); //by name + new CAdventureMapButton("", "", bind(&SelectionTab::sortBy, this, _numOfMaps), 23, 86, "CamCusM.DEF"); //by num of maps + new CAdventureMapButton("", "", bind(&SelectionTab::sortBy, this, _name), 55, 86, "CamCusL.DEF"); //by name } slider = new CSlider(372, 86, tabType != CMenuScreen::saveGame ? 480 : 430, bind(&SelectionTab::sliderMove, this, _1), positions, curItems.size(), 0, false, 1); @@ -1270,9 +1270,9 @@ void SelectionTab::printMaps(SDL_Surface *to) CMapInfo *currentItem = curItems[elemIdx]; if (elemIdx == selectionPos) - itemColor=tytulowy; + itemColor=Colors::Jasmine; else - itemColor=zwykly; + itemColor=Colors::Cornsilk; if(tabType != CMenuScreen::campaignList) { @@ -1367,7 +1367,7 @@ void SelectionTab::printMaps(SDL_Surface *to) #undef POS } -void SelectionTab::showAll( SDL_Surface * to ) +void SelectionTab::showAll(SDL_Surface * to) { CIntObject::showAll(to); printMaps(to); @@ -1388,10 +1388,10 @@ void SelectionTab::showAll( SDL_Surface * to ) break; } - CSDL_Ext::printAtMiddle(title, pos.x+205, pos.y+28, FONT_MEDIUM, tytulowy, to); //Select a Scenario to Play + CSDL_Ext::printAtMiddle(title, pos.x+205, pos.y+28, FONT_MEDIUM, Colors::Jasmine, to); //Select a Scenario to Play if(tabType != CMenuScreen::campaignList) { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[510], pos.x+87, pos.y+62, FONT_SMALL, tytulowy, to); //Map sizes + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[510], pos.x+87, pos.y+62, FONT_SMALL, Colors::Jasmine, to); //Map sizes } } @@ -1447,7 +1447,7 @@ void SelectionTab::onDoubleClick() int SelectionTab::getLine() { int line = -1; - SPoint clickPos(GH.current->button.x, GH.current->button.y); + Point clickPos(GH.current->button.x, GH.current->button.y); clickPos = clickPos - pos.topLeft(); if (clickPos.y > 115 && clickPos.y < 564 && clickPos.x > 22 && clickPos.x < 371) @@ -1475,7 +1475,7 @@ void SelectionTab::selectFName( const std::string &fname ) -CChatBox::CChatBox(const SRect &rect) +CChatBox::CChatBox(const Rect &rect) { OBJ_CONSTRUCTION; pos += rect; @@ -1483,9 +1483,9 @@ CChatBox::CChatBox(const SRect &rect) captureAllKeys = true; const int height = graphics->fonts[FONT_SMALL]->height; - inputBox = new CTextInput(SRect(0, rect.h - height, rect.w, height)); + inputBox = new CTextInput(Rect(0, rect.h - height, rect.w, height)); inputBox->used &= ~KEYBOARD; - chatHistory = new CTextBox("", SRect(0, 0, rect.w, rect.h - height), 1); + chatHistory = new CTextBox("", Rect(0, 0, rect.w, rect.h - height), 1); SDL_Color green = {0,252,0}; chatHistory->color = green; @@ -1518,13 +1518,13 @@ InfoCard::InfoCard( bool Network ) used = RCLICK; mapDescription = NULL; - SRect descriptionRect(26, 149, 320, 115); + Rect descriptionRect(26, 149, 320, 115); mapDescription = new CTextBox("", descriptionRect, 1); if(SEL->screenType == CMenuScreen::campaignList) { CSelectionScreen *ss = static_cast(parent); - CGuiHandler::moveChild(new CPicture(*ss->bg, descriptionRect + SPoint(-393, 0)), this, mapDescription, true); //move subpicture bg to our description control (by default it's our (Infocard) child) + CGuiHandler::moveChild(new CPicture(*ss->bg, descriptionRect + Point(-393, 0)), this, mapDescription, true); //move subpicture bg to our description control (by default it's our (Infocard) child) } else { @@ -1571,24 +1571,24 @@ InfoCard::~InfoCard() delete sFlags; } -void InfoCard::showAll( SDL_Surface * to ) +void InfoCard::showAll(SDL_Surface * to) { CIntObject::showAll(to); //blit texts if(SEL->screenType != CMenuScreen::campaignList) { - printAtLoc(CGI->generaltexth->allTexts[390] + ":", 24, 400, FONT_SMALL, zwykly, to); //Allies - printAtLoc(CGI->generaltexth->allTexts[391] + ":", 190, 400, FONT_SMALL, zwykly, to); //Enemies - printAtLoc(CGI->generaltexth->allTexts[494], 33, 430, FONT_SMALL, tytulowy, to);//"Map Diff:" - printAtLoc(CGI->generaltexth->allTexts[492] + ":", 133,430, FONT_SMALL, tytulowy, to); //player difficulty - printAtLoc(CGI->generaltexth->allTexts[218] + ":", 290,430, FONT_SMALL, tytulowy, to); //"Rating:" - printAtLoc(CGI->generaltexth->allTexts[495], 26, 22, FONT_SMALL, tytulowy, to); //Scenario Name: + printAtLoc(CGI->generaltexth->allTexts[390] + ":", 24, 400, FONT_SMALL, Colors::Cornsilk, to); //Allies + printAtLoc(CGI->generaltexth->allTexts[391] + ":", 190, 400, FONT_SMALL, Colors::Cornsilk, to); //Enemies + printAtLoc(CGI->generaltexth->allTexts[494], 33, 430, FONT_SMALL, Colors::Jasmine, to);//"Map Diff:" + printAtLoc(CGI->generaltexth->allTexts[492] + ":", 133,430, FONT_SMALL, Colors::Jasmine, to); //player difficulty + printAtLoc(CGI->generaltexth->allTexts[218] + ":", 290,430, FONT_SMALL, Colors::Jasmine, to); //"Rating:" + printAtLoc(CGI->generaltexth->allTexts[495], 26, 22, FONT_SMALL, Colors::Jasmine, to); //Scenario Name: if(!chatOn) { - printAtLoc(CGI->generaltexth->allTexts[496], 26, 132, FONT_SMALL, tytulowy, to); //Scenario Description: - printAtLoc(CGI->generaltexth->allTexts[497], 26, 283, FONT_SMALL, tytulowy, to); //Victory Condition: - printAtLoc(CGI->generaltexth->allTexts[498], 26, 339, FONT_SMALL, tytulowy, to); //Loss Condition: + printAtLoc(CGI->generaltexth->allTexts[496], 26, 132, FONT_SMALL, Colors::Jasmine, to); //Scenario Description: + printAtLoc(CGI->generaltexth->allTexts[497], 26, 283, FONT_SMALL, Colors::Jasmine, to); //Victory Condition: + printAtLoc(CGI->generaltexth->allTexts[498], 26, 339, FONT_SMALL, Colors::Jasmine, to); //Loss Condition: } else //players list { @@ -1598,7 +1598,7 @@ void InfoCard::showAll( SDL_Surface * to ) { if(i->second.human) { - printAtLoc(i->second.name, 24, 285 + playerSoFar++ * graphics->fonts[FONT_SMALL]->height, FONT_SMALL, zwykly, to); + printAtLoc(i->second.name, 24, 285 + playerSoFar++ * graphics->fonts[FONT_SMALL]->height, FONT_SMALL, Colors::Cornsilk, to); playerNames.erase(i->second.human); } } @@ -1606,7 +1606,7 @@ void InfoCard::showAll( SDL_Surface * to ) playerSoFar = 0; for (std::map::const_iterator i = playerNames.begin(); i != playerNames.end(); i++) { - printAtLoc(i->second, 193, 285 + playerSoFar++ * graphics->fonts[FONT_SMALL]->height, FONT_SMALL, zwykly, to); + printAtLoc(i->second, 193, 285 + playerSoFar++ * graphics->fonts[FONT_SMALL]->height, FONT_SMALL, Colors::Cornsilk, to); } } @@ -1625,7 +1625,7 @@ void InfoCard::showAll( SDL_Surface * to ) if (temp>20) temp=0; std::string sss = CGI->generaltexth->victoryConditions[temp]; if (temp && SEL->current->mapHeader->victoryCondition.allowNormalVictory) sss+= "/" + CGI->generaltexth->victoryConditions[0]; - printAtLoc(sss, 60, 307, FONT_SMALL, zwykly, to); + printAtLoc(sss, 60, 307, FONT_SMALL, Colors::Cornsilk, to); temp = SEL->current->mapHeader->victoryCondition.condition; if (temp>12) temp=11; @@ -1635,7 +1635,7 @@ void InfoCard::showAll( SDL_Surface * to ) temp = SEL->current->mapHeader->lossCondition.typeOfLossCon+1; if (temp>20) temp=0; sss = CGI->generaltexth->lossCondtions[temp]; - printAtLoc(sss, 60, 366, FONT_SMALL, zwykly, to); + printAtLoc(sss, 60, 366, FONT_SMALL, Colors::Cornsilk, to); temp=SEL->current->mapHeader->lossCondition.typeOfLossCon; if (temp>12) temp=3; @@ -1645,7 +1645,7 @@ void InfoCard::showAll( SDL_Surface * to ) //difficulty assert(SEL->current->mapHeader->difficulty <= 4); std::string &diff = CGI->generaltexth->arraytxt[142 + SEL->current->mapHeader->difficulty]; - printAtMiddleLoc(diff, 62, 472, FONT_SMALL, zwykly, to); + printAtMiddleLoc(diff, 62, 472, FONT_SMALL, Colors::Cornsilk, to); //selecting size icon switch (SEL->current->mapHeader->width) @@ -1670,7 +1670,7 @@ void InfoCard::showAll( SDL_Surface * to ) if(SEL->screenType == CMenuScreen::loadGame) - printToLoc((static_cast(SEL->current))->date,308,34, FONT_SMALL, zwykly, to); + printToLoc((static_cast(SEL->current))->date,308,34, FONT_SMALL, Colors::Cornsilk, to); //print flags int fx = 34 + graphics->fonts[FONT_SMALL]->getWidth(CGI->generaltexth->allTexts[390].c_str()); @@ -1709,7 +1709,7 @@ void InfoCard::showAll( SDL_Surface * to ) tob="200%"; break; } - printAtMiddleLoc(tob, 311, 472, FONT_SMALL, zwykly, to); + printAtMiddleLoc(tob, 311, 472, FONT_SMALL, Colors::Cornsilk, to); } //blit description @@ -1726,9 +1726,9 @@ void InfoCard::showAll( SDL_Surface * to ) //name if (name.length()) - printAtLoc(name, 26, 39, FONT_BIG, tytulowy, to); + printAtLoc(name, 26, 39, FONT_BIG, Colors::Jasmine, to); else - printAtLoc("Unnamed", 26, 39, FONT_BIG, tytulowy, to); + printAtLoc("Unnamed", 26, 39, FONT_BIG, Colors::Jasmine, to); } @@ -1753,7 +1753,7 @@ void InfoCard::changeSelection( const CMapInfo *to ) void InfoCard::clickRight( tribool down, bool previousState ) { - static const SRect flagArea(19, 397, 335, 23); + static const Rect flagArea(19, 397, 335, 23); if(down && SEL->current && isItInLoc(flagArea, GH.current->motion.x, GH.current->motion.y)) showTeamsPopup(); } @@ -1761,14 +1761,14 @@ void InfoCard::clickRight( tribool down, bool previousState ) void InfoCard::showTeamsPopup() { SDL_Surface *bmp = CMessage::drawBox1(256, 90 + 50 * SEL->current->mapHeader->howManyTeams); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[657], 128, 30, FONT_MEDIUM, tytulowy, bmp); //{Team Alignments} + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[657], 128, 30, FONT_MEDIUM, Colors::Jasmine, bmp); //{Team Alignments} for(int i = 0; i < SEL->current->mapHeader->howManyTeams; i++) { std::vector flags; std::string hlp = CGI->generaltexth->allTexts[656]; //Team %d hlp.replace(hlp.find("%d"), 2, boost::lexical_cast(i+1)); - CSDL_Ext::printAtMiddle(hlp, 128, 65 + 50*i, FONT_SMALL, zwykly, bmp); + CSDL_Ext::printAtMiddle(hlp, 128, 65 + 50*i, FONT_SMALL, Colors::Cornsilk, bmp); for(int j = 0; j < GameConstants::PLAYER_LIMIT; j++) if((SEL->current->mapHeader->players[j].canHumanPlay || SEL->current->mapHeader->players[j].canComputerPlay) @@ -1831,18 +1831,18 @@ OptionsTab::~OptionsTab() } -void OptionsTab::showAll( SDL_Surface * to ) +void OptionsTab::showAll(SDL_Surface * to) { CIntObject::showAll(to); - printAtMiddleLoc(CGI->generaltexth->allTexts[515], 222, 30, FONT_BIG, tytulowy, to); - printAtMiddleWBLoc(CGI->generaltexth->allTexts[516], 222, 58, FONT_SMALL, 55, zwykly, to); //Select starting options, handicap, and name for each player in the game. - printAtMiddleWBLoc(CGI->generaltexth->allTexts[517], 107, 102, FONT_SMALL, 14, tytulowy, to); //Player Name Handicap Type - printAtMiddleWBLoc(CGI->generaltexth->allTexts[518], 197, 102, FONT_SMALL, 10, tytulowy, to); //Starting Town - printAtMiddleWBLoc(CGI->generaltexth->allTexts[519], 273, 102, FONT_SMALL, 10, tytulowy, to); //Starting Hero - printAtMiddleWBLoc(CGI->generaltexth->allTexts[520], 349, 102, FONT_SMALL, 10, tytulowy, to); //Starting Bonus - printAtMiddleLoc(CGI->generaltexth->allTexts[521], 222, 538, FONT_SMALL, tytulowy, to); // Player Turn Duration + printAtMiddleLoc(CGI->generaltexth->allTexts[515], 222, 30, FONT_BIG, Colors::Jasmine, to); + printAtMiddleWBLoc(CGI->generaltexth->allTexts[516], 222, 58, FONT_SMALL, 55, Colors::Cornsilk, to); //Select starting options, handicap, and name for each player in the game. + printAtMiddleWBLoc(CGI->generaltexth->allTexts[517], 107, 102, FONT_SMALL, 14, Colors::Jasmine, to); //Player Name Handicap Type + printAtMiddleWBLoc(CGI->generaltexth->allTexts[518], 197, 102, FONT_SMALL, 10, Colors::Jasmine, to); //Starting Town + printAtMiddleWBLoc(CGI->generaltexth->allTexts[519], 273, 102, FONT_SMALL, 10, Colors::Jasmine, to); //Starting Hero + printAtMiddleWBLoc(CGI->generaltexth->allTexts[520], 349, 102, FONT_SMALL, 10, Colors::Jasmine, to); //Starting Bonus + printAtMiddleLoc(CGI->generaltexth->allTexts[521], 222, 538, FONT_SMALL, Colors::Jasmine, to); // Player Turn Duration if (turnDuration) - printAtMiddleLoc(CGI->generaltexth->turnDurations[turnDuration->value], 319,559, FONT_SMALL, zwykly, to);//Turn duration value + printAtMiddleLoc(CGI->generaltexth->turnDurations[turnDuration->value], 319,559, FONT_SMALL, Colors::Cornsilk, to);//Turn duration value } void OptionsTab::nextCastle( int player, int dir ) @@ -2129,7 +2129,7 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSet serial++; } - pos = parent->pos + SPoint(54, 122 + serial*50); + pos = parent->pos + Point(54, 122 + serial*50); static const char *flags[] = {"AOFLGBR.DEF", "AOFLGBB.DEF", "AOFLGBY.DEF", "AOFLGBG.DEF", "AOFLGBO.DEF", "AOFLGBP.DEF", "AOFLGBT.DEF", "AOFLGBS.DEF"}; @@ -2139,12 +2139,12 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSet bg = new CPicture(BitmapHandler::loadBitmap(bgs[s.color]), 0, 0, true); if(SEL->screenType == CMenuScreen::newGame) { - btns[0] = new AdventureMapButton(CGI->generaltexth->zelp[132], bind(&OptionsTab::nextCastle, owner, s.color, -1), 107, 5, "ADOPLFA.DEF"); - btns[1] = new AdventureMapButton(CGI->generaltexth->zelp[133], bind(&OptionsTab::nextCastle, owner, s.color, +1), 168, 5, "ADOPRTA.DEF"); - btns[2] = new AdventureMapButton(CGI->generaltexth->zelp[148], bind(&OptionsTab::nextHero, owner, s.color, -1), 183, 5, "ADOPLFA.DEF"); - btns[3] = new AdventureMapButton(CGI->generaltexth->zelp[149], bind(&OptionsTab::nextHero, owner, s.color, +1), 244, 5, "ADOPRTA.DEF"); - btns[4] = new AdventureMapButton(CGI->generaltexth->zelp[164], bind(&OptionsTab::nextBonus, owner, s.color, -1), 259, 5, "ADOPLFA.DEF"); - btns[5] = new AdventureMapButton(CGI->generaltexth->zelp[165], bind(&OptionsTab::nextBonus, owner, s.color, +1), 320, 5, "ADOPRTA.DEF"); + btns[0] = new CAdventureMapButton(CGI->generaltexth->zelp[132], bind(&OptionsTab::nextCastle, owner, s.color, -1), 107, 5, "ADOPLFA.DEF"); + btns[1] = new CAdventureMapButton(CGI->generaltexth->zelp[133], bind(&OptionsTab::nextCastle, owner, s.color, +1), 168, 5, "ADOPRTA.DEF"); + btns[2] = new CAdventureMapButton(CGI->generaltexth->zelp[148], bind(&OptionsTab::nextHero, owner, s.color, -1), 183, 5, "ADOPLFA.DEF"); + btns[3] = new CAdventureMapButton(CGI->generaltexth->zelp[149], bind(&OptionsTab::nextHero, owner, s.color, +1), 244, 5, "ADOPRTA.DEF"); + btns[4] = new CAdventureMapButton(CGI->generaltexth->zelp[164], bind(&OptionsTab::nextBonus, owner, s.color, -1), 259, 5, "ADOPLFA.DEF"); + btns[5] = new CAdventureMapButton(CGI->generaltexth->zelp[165], bind(&OptionsTab::nextBonus, owner, s.color, +1), 320, 5, "ADOPRTA.DEF"); } else for(int i = 0; i < 6; i++) @@ -2166,7 +2166,7 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSet && SEL->current->mapHeader->players[s.color].canHumanPlay && SEL->multiPlayer != CMenuScreen::MULTI_NETWORK_GUEST) { - flag = new AdventureMapButton(CGI->generaltexth->zelp[180], bind(&OptionsTab::flagPressed, owner, s.color), -43, 2, flags[s.color]); + flag = new CAdventureMapButton(CGI->generaltexth->zelp[180], bind(&OptionsTab::flagPressed, owner, s.color), -43, 2, flags[s.color]); flag->hoverable = true; } else @@ -2174,18 +2174,18 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSet defActions &= ~SHARE_POS; town = new SelectedBox(TOWN, s.color); - town->pos += pos + SPoint(119, 2); + town->pos += pos + Point(119, 2); hero = new SelectedBox(HERO, s.color); - hero->pos += pos + SPoint(195, 2); + hero->pos += pos + Point(195, 2); bonus = new SelectedBox(BONUS, s.color); - bonus->pos += pos + SPoint(271, 2); + bonus->pos += pos + Point(271, 2); } -void OptionsTab::PlayerOptionsEntry::showAll( SDL_Surface * to ) +void OptionsTab::PlayerOptionsEntry::showAll(SDL_Surface * to) { CIntObject::showAll(to); - printAtMiddleLoc(s.name, 55, 10, FONT_SMALL, zwykly, to); - printAtMiddleWBLoc(CGI->generaltexth->arraytxt[206+whoCanPlay], 28, 34, FONT_TINY, 8, zwykly, to); + printAtMiddleLoc(s.name, 55, 10, FONT_SMALL, Colors::Cornsilk, to); + printAtMiddleWBLoc(CGI->generaltexth->arraytxt[206+whoCanPlay], 28, 34, FONT_TINY, 8, Colors::Cornsilk, to); } void OptionsTab::PlayerOptionsEntry::selectButtons() @@ -2229,13 +2229,13 @@ void OptionsTab::PlayerOptionsEntry::selectButtons() } } -void OptionsTab::SelectedBox::showAll( SDL_Surface * to ) +void OptionsTab::SelectedBox::showAll(SDL_Surface * to) { //PlayerSettings &s = SEL->sInfo.playerInfos[player]; SDL_Surface *toBlit = getImg(); const std::string *toPrint = getText(); blitAt(toBlit, pos, to); - printAtMiddleLoc(*toPrint, 23, 39, FONT_TINY, zwykly, to); + printAtMiddleLoc(*toPrint, 23, 39, FONT_TINY, Colors::Cornsilk, to); } OptionsTab::SelectedBox::SelectedBox( SelType Which, ui8 Player ) @@ -2445,7 +2445,7 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState ) } if(description) - CSDL_Ext::printAtMiddleWB(*description, 125, 145, FONT_SMALL, 37, zwykly, bmp); + CSDL_Ext::printAtMiddleWB(*description, 125, 145, FONT_SMALL, 37, Colors::Cornsilk, bmp); } else if(val == -2) { @@ -2456,7 +2456,7 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState ) bmp = CMessage::drawBox1(256, 319); title = &CGI->generaltexth->allTexts[80]; - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[79], 135, 137, FONT_MEDIUM, tytulowy, bmp); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[79], 135, 137, FONT_MEDIUM, Colors::Jasmine, bmp); const CTown &t = CGI->townh->towns[val]; //print creatures @@ -2465,7 +2465,7 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState ) { int c = t.basicCreatures[i]; blitAt(graphics->smallImgs[c], x, y, bmp); - CSDL_Ext::printAtMiddleWB(CGI->creh->creatures[c]->nameSing, x + 16, y + 45, FONT_TINY, 10, zwykly, bmp); + CSDL_Ext::printAtMiddleWB(CGI->creh->creatures[c]->nameSing, x + 16, y + 45, FONT_TINY, 10, Colors::Cornsilk, bmp); if(i == 2) { @@ -2485,24 +2485,24 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState ) bmp = CMessage::drawBox1(320, 255); title = &CGI->generaltexth->allTexts[77]; - CSDL_Ext::printAtMiddle(*title, 167, 36, FONT_MEDIUM, tytulowy, bmp); - CSDL_Ext::printAtMiddle(*subTitle + " - " + h->heroClass->name, 160, 99, FONT_SMALL, zwykly, bmp); + CSDL_Ext::printAtMiddle(*title, 167, 36, FONT_MEDIUM, Colors::Jasmine, bmp); + CSDL_Ext::printAtMiddle(*subTitle + " - " + h->heroClass->name, 160, 99, FONT_SMALL, Colors::Cornsilk, bmp); blitAt(getImg(), 136, 56, bmp); //print specialty - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[78], 166, 132, FONT_MEDIUM, tytulowy, bmp); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[78], 166, 132, FONT_MEDIUM, Colors::Jasmine, bmp); blitAt(graphics->un44->ourImages[val].bitmap, 140, 150, bmp); - CSDL_Ext::printAtMiddle(CGI->generaltexth->hTxts[val].bonusName, 166, 203, FONT_SMALL, zwykly, bmp); + CSDL_Ext::printAtMiddle(CGI->generaltexth->hTxts[val].bonusName, 166, 203, FONT_SMALL, Colors::Cornsilk, bmp); GH.pushInt(new CInfoPopup(bmp, true)); return; } if(title) - CSDL_Ext::printAtMiddle(*title, 135, 36, FONT_MEDIUM, tytulowy, bmp); + CSDL_Ext::printAtMiddle(*title, 135, 36, FONT_MEDIUM, Colors::Jasmine, bmp); if(subTitle) - CSDL_Ext::printAtMiddle(*subTitle, 127, 103, FONT_SMALL, zwykly, bmp); + CSDL_Ext::printAtMiddle(*subTitle, 127, 103, FONT_SMALL, Colors::Cornsilk, bmp); blitAt(getImg(), 104, 60, bmp); @@ -2539,7 +2539,7 @@ CScenarioInfo::CScenarioInfo(const CMapHeader *mapHeader, const StartInfo *start opt->recreate(); card->difficulty->select(startInfo->difficulty, 0); - back = new AdventureMapButton("", CGI->generaltexth->zelp[105].second, bind(&CGuiHandler::popIntTotally, &GH, this), 584, 535, "SCNRBACK.DEF", SDLK_ESCAPE); + back = new CAdventureMapButton("", CGI->generaltexth->zelp[105].second, bind(&CGuiHandler::popIntTotally, &GH, this), 584, 535, "SCNRBACK.DEF", SDLK_ESCAPE); } CScenarioInfo::~CScenarioInfo() @@ -2616,14 +2616,14 @@ CMultiMode::CMultiMode() blitAt(CPicture("MUMAP.bmp"), 16, 77, *bg); //blit img pos = bg->center(); //center, window has size of bg graphic - bar = new CGStatusBar(new CPicture(SRect(7, 465, 440, 18), 0));//226, 472 - txt = new CTextInput(SRect(19, 436, 334, 16), *bg); + bar = new CGStatusBar(new CPicture(Rect(7, 465, 440, 18), 0));//226, 472 + txt = new CTextInput(Rect(19, 436, 334, 16), *bg); txt->setText(GDefaultOptions.playerName); //Player - btns[0] = new AdventureMapButton(CGI->generaltexth->zelp[266], bind(&CMultiMode::openHotseat, this), 373, 78, "MUBHOT.DEF"); - btns[1] = new AdventureMapButton("Host TCP/IP game", "", bind(&CMultiMode::hostTCP, this), 373, 78 + 57*1, "MUBHOST.DEF"); - btns[2] = new AdventureMapButton("Join TCP/IP game", "", bind(&CMultiMode::joinTCP, this), 373, 78 + 57*2, "MUBJOIN.DEF"); - btns[6] = new AdventureMapButton(CGI->generaltexth->zelp[288], bind(&CGuiHandler::popIntTotally, ref(GH), this), 373, 424, "MUBCANC.DEF", SDLK_ESCAPE); + btns[0] = new CAdventureMapButton(CGI->generaltexth->zelp[266], bind(&CMultiMode::openHotseat, this), 373, 78, "MUBHOT.DEF"); + btns[1] = new CAdventureMapButton("Host TCP/IP game", "", bind(&CMultiMode::hostTCP, this), 373, 78 + 57*1, "MUBHOST.DEF"); + btns[2] = new CAdventureMapButton("Join TCP/IP game", "", bind(&CMultiMode::joinTCP, this), 373, 78 + 57*2, "MUBJOIN.DEF"); + btns[6] = new CAdventureMapButton(CGI->generaltexth->zelp[288], bind(&CGuiHandler::popIntTotally, ref(GH), this), 373, 424, "MUBCANC.DEF", SDLK_ESCAPE); } void CMultiMode::openHotseat() @@ -2653,18 +2653,18 @@ CHotSeatPlayers::CHotSeatPlayers(const std::string &firstPlayer) std::string text = CGI->generaltexth->allTexts[446]; boost::replace_all(text, "\t","\n"); - SRect boxRect(25, 20, 315, 50); - title = new CTextBox(text, boxRect, 0, FONT_BIG, CENTER, zwykly);//HOTSEAT Please enter names + Rect boxRect(25, 20, 315, 50); + title = new CTextBox(text, boxRect, 0, FONT_BIG, CENTER, Colors::Cornsilk);//HOTSEAT Please enter names for(int i = 0; i < ARRAY_COUNT(txt); i++) { - txt[i] = new CTextInput(SRect(60, 85 + i*30, 280, 16), *bg); + txt[i] = new CTextInput(Rect(60, 85 + i*30, 280, 16), *bg); txt[i]->cb += boost::bind(&CHotSeatPlayers::onChange, this, _1); } - ok = new AdventureMapButton(CGI->generaltexth->zelp[560], bind(&CHotSeatPlayers::enterSelectionScreen, this), 95, 338, "MUBCHCK.DEF", SDLK_RETURN); - cancel = new AdventureMapButton(CGI->generaltexth->zelp[561], bind(&CGuiHandler::popIntTotally, ref(GH), this), 205, 338, "MUBCANC.DEF", SDLK_ESCAPE); - bar = new CGStatusBar(new CPicture(SRect(7, 381, 348, 18), 0));//226, 472 + ok = new CAdventureMapButton(CGI->generaltexth->zelp[560], bind(&CHotSeatPlayers::enterSelectionScreen, this), 95, 338, "MUBCHCK.DEF", SDLK_RETURN); + cancel = new CAdventureMapButton(CGI->generaltexth->zelp[561], bind(&CGuiHandler::popIntTotally, ref(GH), this), 205, 338, "MUBCANC.DEF", SDLK_ESCAPE); + bar = new CGStatusBar(new CPicture(Rect(7, 381, 348, 18), 0));//226, 472 txt[0]->setText(firstPlayer, true); txt[0]->giveFocus(); @@ -2711,31 +2711,31 @@ CBonusSelection::CBonusSelection( CCampaignState * _ourCampaign ) blitAt(panel, 456, 6, background); - startB = new AdventureMapButton("", "", bind(&CBonusSelection::startMap, this), 475, 536, "CBBEGIB.DEF", SDLK_RETURN); - backB = new AdventureMapButton("", "", bind(&CBonusSelection::goBack, this), 624, 536, "CBCANCB.DEF", SDLK_ESCAPE); + startB = new CAdventureMapButton("", "", bind(&CBonusSelection::startMap, this), 475, 536, "CBBEGIB.DEF", SDLK_RETURN); + backB = new CAdventureMapButton("", "", bind(&CBonusSelection::goBack, this), 624, 536, "CBCANCB.DEF", SDLK_ESCAPE); startB->setState(CButtonBase::BLOCKED); //campaign name if (ourCampaign->camp->header.name.length()) - printAtLoc(ourCampaign->camp->header.name, 481, 28, FONT_BIG, tytulowy, background); + printAtLoc(ourCampaign->camp->header.name, 481, 28, FONT_BIG, Colors::Jasmine, background); else - printAtLoc("Unnamed", 481, 28, FONT_BIG, tytulowy, background); + printAtLoc("Unnamed", 481, 28, FONT_BIG, Colors::Jasmine, background); //map size icon sizes = CDefHandler::giveDef("SCNRMPSZ.DEF"); //campaign description - printAtLoc(CGI->generaltexth->allTexts[38], 481, 63, FONT_SMALL, tytulowy, background); + printAtLoc(CGI->generaltexth->allTexts[38], 481, 63, FONT_SMALL, Colors::Jasmine, background); - cmpgDesc = new CTextBox(ourCampaign->camp->header.description, SRect(480, 86, 286, 117), 1); + cmpgDesc = new CTextBox(ourCampaign->camp->header.description, Rect(480, 86, 286, 117), 1); cmpgDesc->showAll(background); //map description - mapDesc = new CTextBox("", SRect(480, 280, 286, 117), 1); + mapDesc = new CTextBox("", Rect(480, 280, 286, 117), 1); //bonus choosing - printAtLoc(CGI->generaltexth->allTexts[71], 511, 432, FONT_MEDIUM, zwykly, background); //Choose a bonus: + printAtLoc(CGI->generaltexth->allTexts[71], 511, 432, FONT_MEDIUM, Colors::Cornsilk, background); //Choose a bonus: bonuses = new CHighlightableButtonsGroup(bind(&CBonusSelection::selectBonus, this, _1)); //set left part of window @@ -2765,15 +2765,15 @@ CBonusSelection::CBonusSelection( CCampaignState * _ourCampaign ) } //allies / enemies - printAtLoc(CGI->generaltexth->allTexts[390] + ":", 486, 407, FONT_SMALL, zwykly, background); //Allies - printAtLoc(CGI->generaltexth->allTexts[391] + ":", 619, 407, FONT_SMALL, zwykly, background); //Enemies + printAtLoc(CGI->generaltexth->allTexts[390] + ":", 486, 407, FONT_SMALL, Colors::Cornsilk, background); //Allies + printAtLoc(CGI->generaltexth->allTexts[391] + ":", 619, 407, FONT_SMALL, Colors::Cornsilk, background); //Enemies SDL_FreeSurface(panel); //difficulty std::vector difficulty; boost::split(difficulty, CGI->generaltexth->allTexts[492], boost::is_any_of(" ")); - printAtLoc(difficulty.back(), 689, 432, FONT_MEDIUM, zwykly, background); //Difficulty + printAtLoc(difficulty.back(), 689, 432, FONT_MEDIUM, Colors::Cornsilk, background); //Difficulty //difficulty pics for (int b=0; bcamp->header.difficultyChoosenByPlayer) { - diffLb = new AdventureMapButton("", "", bind(&CBonusSelection::changeDiff, this, false), 694, 508, "SCNRBLF.DEF"); - diffRb = new AdventureMapButton("", "", bind(&CBonusSelection::changeDiff, this, true), 738, 508, "SCNRBRT.DEF"); + diffLb = new CAdventureMapButton("", "", bind(&CBonusSelection::changeDiff, this, false), 694, 508, "SCNRBLF.DEF"); + diffRb = new CAdventureMapButton("", "", bind(&CBonusSelection::changeDiff, this, true), 738, 508, "SCNRBRT.DEF"); } //load miniflags @@ -2815,7 +2815,7 @@ void CBonusSelection::goBack() GH.popIntTotally(this); } -void CBonusSelection::showAll( SDL_Surface * to ) +void CBonusSelection::showAll(SDL_Surface * to) { blitAt(background, pos.x, pos.y, to); CIntObject::showAll(to); @@ -2879,7 +2879,7 @@ void CBonusSelection::selectMap( int whichOne ) updateBonusSelection(); } -void CBonusSelection::show( SDL_Surface * to ) +void CBonusSelection::show(SDL_Surface * to) { //blitAt(background, pos.x, pos.y, to); @@ -2887,12 +2887,12 @@ void CBonusSelection::show( SDL_Surface * to ) std::string mapName = ourHeader->name; if (mapName.length()) - printAtLoc(mapName, 481, 219, FONT_BIG, tytulowy, to); + printAtLoc(mapName, 481, 219, FONT_BIG, Colors::Jasmine, to); else - printAtLoc("Unnamed", 481, 219, FONT_BIG, tytulowy, to); + printAtLoc("Unnamed", 481, 219, FONT_BIG, Colors::Jasmine, to); //map description - printAtLoc(CGI->generaltexth->allTexts[496], 481, 253, FONT_SMALL, tytulowy, to); + printAtLoc(CGI->generaltexth->allTexts[496], 481, 253, FONT_SMALL, Colors::Jasmine, to); mapDesc->showAll(to); //showAll because CTextBox has no show() @@ -3117,7 +3117,7 @@ void CBonusSelection::updateBonusSelection() CAnimation * anim = new CAnimation(); anim->setCustom(picName, 0); bonusButton->setImage(anim); - bonusButton->borderColor = Colors::Yellow; // yellow border + bonusButton->borderColor = Colors::Maize; // yellow border bonuses->addButton(bonusButton); } if (active) @@ -3240,7 +3240,7 @@ void CBonusSelection::CRegion::clickRight( tribool down, bool previousState ) } } -void CBonusSelection::CRegion::show( SDL_Surface * to ) +void CBonusSelection::CRegion::show(SDL_Surface * to) { //const SCampPositions::SRegionDesc & desc = owner->campDescriptions[owner->ourCampaign->camp->header.mapVersion].regions[myNumber]; if (!accessible) @@ -3495,7 +3495,7 @@ CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode &config ) used |= LCLICK | HOVER; image = new CPicture(config["image"].String()); - hoverLabel = new CLabel(pos.w / 2, pos.h + 20, FONT_MEDIUM, CENTER, tytulowy, ""); + hoverLabel = new CLabel(pos.w / 2, pos.h + 20, FONT_MEDIUM, CENTER, Colors::Jasmine, ""); CGuiHandler::moveChild(hoverLabel, this, parent); } @@ -3524,7 +3524,7 @@ void CCampaignScreen::CCampaignButton::hover(bool on) hoverLabel->setTxt(" "); } -void CCampaignScreen::CCampaignButton::show(SDL_Surface *to) +void CCampaignScreen::CCampaignButton::show(SDL_Surface * to) { if (status == CCampaignScreen::DISABLED) return; @@ -3546,14 +3546,14 @@ void CCampaignScreen::CCampaignButton::show(SDL_Surface *to) } } -AdventureMapButton* CCampaignScreen::createExitButton(const JsonNode& button) +CAdventureMapButton* CCampaignScreen::createExitButton(const JsonNode& button) { std::pair help; if (!button["help"].isNull() && button["help"].Float() > 0) help = CGI->generaltexth->zelp[button["help"].Float()]; boost::function close = boost::bind(&CGuiHandler::popIntTotally, &GH, this); - return new AdventureMapButton(help, close, button["x"].Float(), button["y"].Float(), button["name"].String(), button["hotkey"].Float()); + return new CAdventureMapButton(help, close, button["x"].Float(), button["y"].Float(), button["name"].String(), button["hotkey"].Float()); } diff --git a/client/CPreGame.h b/client/CPreGame.h index a2281b76e..f35d0b63c 100644 --- a/client/CPreGame.h +++ b/client/CPreGame.h @@ -6,7 +6,6 @@ #include "GUIClasses.h" #include "FunctionList.h" #include "../lib/CMapInfo.h" -#include "UIFramework/IUpdateable.h" /* * CPreGame.h, part of VCMI engine @@ -77,9 +76,9 @@ public: class CMenuEntry : public CIntObject { std::vector images; - std::vector buttons; + std::vector buttons; - AdventureMapButton* createButton(CMenuScreen* parent, const JsonNode& button); + CAdventureMapButton* createButton(CMenuScreen* parent, const JsonNode& button); public: CMenuEntry(CMenuScreen* parent, const JsonNode &config); }; @@ -90,7 +89,7 @@ class CreditsScreen : public CIntObject public: CreditsScreen(); - void show(SDL_Surface *to); + void show(SDL_Surface * to); void clickLeft(tribool down, bool previousState); void clickRight(tribool down, bool previousState); @@ -103,7 +102,7 @@ public: CTextBox *chatHistory; CTextInput *inputBox; - CChatBox(const SRect &rect); + CChatBox(const Rect &rect); void keyPressed(const SDL_KeyboardEvent & key); @@ -204,8 +203,8 @@ public: PlayerInfo π PlayerSettings &s; CPicture *bg; - AdventureMapButton *btns[6]; //left and right for town, hero, bonus - AdventureMapButton *flag; + CAdventureMapButton *btns[6]; //left and right for town, hero, bonus + CAdventureMapButton *flag; SelectedBox *town; SelectedBox *hero; SelectedBox *bonus; @@ -279,7 +278,7 @@ public: CPicture *bg; //general bg image InfoCard *card; OptionsTab *opt; - AdventureMapButton *start, *back; + CAdventureMapButton *start, *back; SelectionTab *sel; CIntObject *curTab; @@ -326,7 +325,7 @@ public: class CScenarioInfo : public CIntObject, public ISelectionScreenInfo { public: - AdventureMapButton *back; + CAdventureMapButton *back; InfoCard *card; OptionsTab *opt; @@ -340,7 +339,7 @@ class CMultiMode : public CIntObject public: CPicture *bg; CTextInput *txt; - AdventureMapButton *btns[7]; //0 - hotseat, 6 - cancel + CAdventureMapButton *btns[7]; //0 - hotseat, 6 - cancel CGStatusBar *bar; CMultiMode(); @@ -355,7 +354,7 @@ class CHotSeatPlayers : public CIntObject CPicture *bg; CTextBox *title; CTextInput* txt[8]; - AdventureMapButton *ok, *cancel; + CAdventureMapButton *ok, *cancel; CGStatusBar *bar; void onChange(std::string newText); @@ -369,7 +368,7 @@ public: class CBonusSelection : public CIntObject { SDL_Surface * background; - AdventureMapButton * startB, * backB; + CAdventureMapButton * startB, * backB; //campaign & map descriptions: CTextBox * cmpgDesc, * mapDesc; @@ -416,7 +415,7 @@ class CBonusSelection : public CIntObject CMapHeader *ourHeader; CDefHandler *sizes; //icons of map sizes SDL_Surface* diffPics[5]; //pictures of difficulties, user-selectable (or not if campaign locks this) - AdventureMapButton * diffLb, * diffRb; //buttons for changing difficulty + CAdventureMapButton * diffLb, * diffRb; //buttons for changing difficulty void changeDiff(bool increase); //if false, then decrease //bonus selection @@ -468,14 +467,14 @@ private: public: CCampaignButton(const JsonNode &config ); - void show(SDL_Surface *to); + void show(SDL_Surface * to); }; - AdventureMapButton *back; + CAdventureMapButton *back; std::vector campButtons; std::vector images; - AdventureMapButton* createExitButton(const JsonNode& button); + CAdventureMapButton* createExitButton(const JsonNode& button); public: enum CampaignSet {ROE, AB, SOD, WOG}; diff --git a/client/CSpellWindow.cpp b/client/CSpellWindow.cpp index b292d88d3..e1dc4fd97 100644 --- a/client/CSpellWindow.cpp +++ b/client/CSpellWindow.cpp @@ -10,7 +10,7 @@ #include "CAdvmapInterface.h" #include "BattleInterface/CBattleInterface.h" #include "CGameInfo.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "CMessage.h" #include "CPlayerInterface.h" #include "../CCallback.h" @@ -31,7 +31,6 @@ */ extern SDL_Surface * screen; -extern SDL_Color tytulowy, zwykly, darkTitle; SpellbookInteractiveArea::SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function funcL, const std::string & textR, boost::function funcHon, boost::function funcHoff, CPlayerInterface * _myInt) @@ -318,14 +317,14 @@ void CSpellWindow::fRcornerb() GH.breakEventHandling(); } -void CSpellWindow::showAll(SDL_Surface *to) +void CSpellWindow::showAll(SDL_Surface * to) { CSDL_Ext::blitSurface(background, NULL, to, &pos); blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 88 + pos.y, to); std::ostringstream mana; mana<mana; - CSDL_Ext::printAtMiddle(mana.str(), pos.x+435, pos.y +426, FONT_SMALL, tytulowy, to); + CSDL_Ext::printAtMiddle(mana.str(), pos.x+435, pos.y +426, FONT_SMALL, Colors::Jasmine, to); statusBar->showAll(to); @@ -611,7 +610,7 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState) if((sp->combatSpell && !owner->myInt->battleInt) || (!sp->combatSpell && owner->myInt->battleInt)) { - std::vector hlp(1, new SComponent(SComponent::spell, mySpell, 0)); + std::vector hlp(1, new CComponent(CComponent::spell, mySpell, 0)); LOCPLINT->showInfoDialog(sp->descriptions[schoolLevel], hlp); return; } @@ -805,7 +804,7 @@ void CSpellWindow::SpellArea::hover(bool on) } } -void CSpellWindow::SpellArea::showAll(SDL_Surface *to) +void CSpellWindow::SpellArea::showAll(SDL_Surface * to) { if(mySpell < 0) return; @@ -819,13 +818,13 @@ void CSpellWindow::SpellArea::showAll(SDL_Surface *to) if(spellCost > owner->myHero->mana) //hero cannot cast this spell { static const SDL_Color unavailableSpell = {239, 189, 33, 0}; - firstLineColor = zwykly; + firstLineColor = Colors::Cornsilk; secondLineColor = unavailableSpell; } else { - firstLineColor = tytulowy; - secondLineColor = zwykly; + firstLineColor = Colors::Jasmine; + secondLineColor = Colors::Cornsilk; } //printing spell's name CSDL_Ext::printAtMiddle(spell->name, pos.x + 39, pos.y + 70, FONT_TINY, firstLineColor, to); diff --git a/client/CSpellWindow.h b/client/CSpellWindow.h index 93d9d23f0..a3cbb53ae 100644 --- a/client/CSpellWindow.h +++ b/client/CSpellWindow.h @@ -57,7 +57,7 @@ private: void clickLeft(tribool down, bool previousState); void clickRight(tribool down, bool previousState); void hover(bool on); - void showAll(SDL_Surface *to); + void showAll(SDL_Surface * to); }; SDL_Surface * background, * leftCorner, * rightCorner; diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index 0912f7d95..e361ad82b 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -3,7 +3,7 @@ #include "CSndHandler.h" #include "CVideoHandler.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "CPlayerInterface.h" extern SystemOptions GDefaultOptions; @@ -568,7 +568,6 @@ bool CVideoPlayer::playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey) #endif #include -#include "SDL_framerate.h" extern "C" { #include diff --git a/client/Client.cpp b/client/Client.cpp index ce0fa55b8..f243228ea 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -553,7 +553,7 @@ void CClient::battleStarted(const BattleInfo * info) def = NULL; if(att || def || gs->scenarioOps->mode == StartInfo::DUEL) - new CBattleInterface(info->belligerents[0], info->belligerents[1], info->heroes[0], info->heroes[1], SRect((conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2, 800, 600), att, def); + new CBattleInterface(info->belligerents[0], info->belligerents[1], info->heroes[0], info->heroes[1], Rect((conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2, 800, 600), att, def); if(vstd::contains(battleints,info->sides[0])) battleints[info->sides[0]]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 0); diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 37f7726b8..5c9e2a529 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -1,19 +1,18 @@ #include "StdInc.h" #include "GUIClasses.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "CAdvmapInterface.h" #include "BattleInterface/CBattleInterface.h" -#include "BattleInterface/CBattleConsole.h" +#include "BattleInterface/CBattleInterfaceClasses.h" #include "../CCallback.h" #include "CCastleInterface.h" #include "CCreatureWindow.h" -#include "CCursorHandler.h" +#include "UIFramework/CCursorHandler.h" #include "CGameInfo.h" #include "CHeroWindow.h" #include "CMessage.h" #include "CConfigHandler.h" -#include "SDL_framerate.h" #include "CConfigHandler.h" #include "BattleInterface/CCreatureAnimation.h" #include "CPlayerInterface.h" @@ -330,7 +329,7 @@ void CGarrisonSlot::showAll(SDL_Surface * to) char buf[15]; SDL_itoa(count,buf,10); blitAt(imgs[creature->idNumber],pos,to); - printTo(buf, pos.x+pos.w, pos.y+pos.h+1, owner->smallIcons ? FONT_TINY : FONT_MEDIUM, zwykly, to); + printTo(buf, pos.x+pos.w, pos.y+pos.h+1, owner->smallIcons ? FONT_TINY : FONT_MEDIUM, Colors::Cornsilk, to); if((owner->highlighted==this) || (owner->splitting && owner->highlighted->creature == creature)) @@ -351,7 +350,7 @@ CGarrisonInt::~CGarrisonInt() delete splitButtons[i];*/ } -void CGarrisonInt::addSplitBtn(AdventureMapButton * button) +void CGarrisonInt::addSplitBtn(CAdventureMapButton * button) { addChild(button); button->recActions = defActions; @@ -438,8 +437,8 @@ void CGarrisonInt::splitStacks(int am2) LOCPLINT->cb->splitStack(armedObjs[highlighted->upg], armedObjs[pb], highlighted->ID, p2, am2); } -CGarrisonInt::CGarrisonInt(int x, int y, int inx, const SPoint &garsOffset, - SDL_Surface *pomsur, const SPoint& SurOffset, +CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset, + SDL_Surface *pomsur, const Point& SurOffset, const CArmedInstance *s1, const CArmedInstance *s2, bool _removableUnits, bool smallImgs, bool _twoRows ) : interx(inx), garOffset(garsOffset), highlighted(NULL), splitting(false), @@ -475,14 +474,14 @@ CInfoWindow::CInfoWindow(std::string Text, int player, const TCompsInfo &comps, ID = -1; for(int i=0;iborderColor = Colors::MetallicGold; button->borderEnabled = true; button->callback.add(Buttons[i].second); //each button will close the window apart from call-defined actions buttons.push_back(button); } - text = new CTextBox(Text, SRect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, zwykly); + text = new CTextBox(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, Colors::Cornsilk); if(!text->slider) { text->pos.w = text->maxW; @@ -535,19 +534,19 @@ CInfoWindow::~CInfoWindow() } } -void CInfoWindow::showAll( SDL_Surface * to ) +void CInfoWindow::showAll(SDL_Surface * to) { CSimpleWindow::show(to); CIntObject::showAll(to); } -void CInfoWindow::showYesNoDialog(const std::string & text, const std::vector *components, const CFunctionList &onYes, const CFunctionList &onNo, bool DelComps, int player) +void CInfoWindow::showYesNoDialog(const std::string & text, const std::vector *components, const CFunctionList &onYes, const CFunctionList &onNo, bool DelComps, int player) { assert(!LOCPLINT || LOCPLINT->showingDialog->get()); std::vector > > pom; pom.push_back(std::pair >("IOKAY.DEF",0)); pom.push_back(std::pair >("ICANCEL.DEF",0)); - CInfoWindow * temp = new CInfoWindow(text, player, components ? *components : std::vector(), pom, DelComps); + CInfoWindow * temp = new CInfoWindow(text, player, components ? *components : std::vector(), pom, DelComps); for(int i=0;ibuttons[0]->callback += onYes.funcs[i]; for(int i=0;i *components /*= NULL*/, bool DelComps) +CInfoWindow * CInfoWindow::create(const std::string &text, int playerID /*= 1*/, const std::vector *components /*= NULL*/, bool DelComps) { std::vector > > pom; pom.push_back(std::pair >("IOKAY.DEF",0)); - CInfoWindow * ret = new CInfoWindow(text, playerID, components ? *components : std::vector(), pom, DelComps); + CInfoWindow * ret = new CInfoWindow(text, playerID, components ? *components : std::vector(), pom, DelComps); return ret; } void CInfoWindow::setDelComps(bool DelComps) { delComps = DelComps; - BOOST_FOREACH(SComponent *comp, components) + BOOST_FOREACH(CComponent *comp, components) { if(delComps) comp->recActions |= DISPOSE; @@ -576,56 +575,6 @@ void CInfoWindow::setDelComps(bool DelComps) } } -void CRClickPopup::clickRight(tribool down, bool previousState) -{ - if(down) - return; - close(); -} - -void CRClickPopup::activate() -{ - activateRClick(); -} - -void CRClickPopup::deactivate() -{ - deactivateRClick(); -} - -void CRClickPopup::close() -{ - GH.popIntTotally(this); -} - -void CRClickPopup::createAndPush(const std::string &txt, const CInfoWindow::TCompsInfo &comps) -{ - int player = LOCPLINT ? LOCPLINT->playerID : 1; //if no player, then use blue - - CSimpleWindow * temp = new CInfoWindow(txt, player, comps); - temp->center(SPoint(GH.current->motion)); //center on mouse - temp->fitToScreen(10); - CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true); - GH.pushInt(rcpi); -} - -void CRClickPopup::createAndPush(const CGObjectInstance *obj, const SPoint &p, EAlignment alignment /*= BOTTOMRIGHT*/) -{ - SDL_Surface *iWin = LOCPLINT->infoWin(obj); //try get custom infowindow for this obj - if(iWin) - GH.pushInt(new CInfoPopup(iWin, p, alignment, true)); - else - CRClickPopup::createAndPush(obj->getHoverText()); -} - -CRClickPopup::CRClickPopup() -{ -} - -CRClickPopup::~CRClickPopup() -{ -} - CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free) :free(Free),bitmap(Bitmap) { @@ -633,7 +582,7 @@ CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free) } -CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, const SPoint &p, EAlignment alignment, bool Free/*=false*/) +CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free/*=false*/) : free(Free),bitmap(Bitmap) { switch(alignment) @@ -699,7 +648,7 @@ void CInfoPopup::init(int x, int y) vstd::amin(pos.y, conf.cc.resy - bitmap->h); } -void SComponent::init(Etype Type, int Subtype, int Val) +void CComponent::init(Etype Type, int Subtype, int Val) { std::ostringstream oss; switch (Type) @@ -785,12 +734,12 @@ void SComponent::init(Etype Type, int Subtype, int Val) pos.w = temp->w; pos.h = temp->h; } -SComponent::SComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur):img(sur),free(freeSur) +CComponent::CComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur):img(sur),free(freeSur) { init(Type,Subtype,Val); } -SComponent::SComponent(const Component &c) +CComponent::CComponent(const Component &c) { if(c.id==5) init(experience,c.subtype,c.val); @@ -803,21 +752,21 @@ SComponent::SComponent(const Component &c) subtitle += CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2); } -SComponent::SComponent() +CComponent::CComponent() { img = NULL; } -SComponent::~SComponent() +CComponent::~CComponent() { if (free && img) SDL_FreeSurface(img); } -SDL_Surface * SComponent::setSurface(std:: string defname, int imagepos) +SDL_Surface * CComponent::setSurface(std:: string defname, int imagepos) { if (img) - tlog1<<"SComponent::setSurface: Warning - surface is already set!\n"; + tlog1<<"CComponent::setSurface: Warning - surface is already set!\n"; CDefEssential * def = CDefHandler::giveDefEss(defname); free = true; @@ -827,12 +776,12 @@ SDL_Surface * SComponent::setSurface(std:: string defname, int imagepos) return img; } -void SComponent::show(SDL_Surface * to) +void CComponent::show(SDL_Surface * to) { blitAt(getImg(),pos.x,pos.y,to); } -SDL_Surface * SComponent::getImg() +SDL_Surface * CComponent::getImg() { if (img) return img; @@ -867,16 +816,16 @@ SDL_Surface * SComponent::getImg() } return NULL; } -void SComponent::clickRight(tribool down, bool previousState) +void CComponent::clickRight(tribool down, bool previousState) { if(description.size()) adventureInt->handleRightClick(description,down); } -void SComponent::activate() +void CComponent::activate() { activateRClick(); } -void SComponent::deactivate() +void CComponent::deactivate() { deactivateRClick(); } @@ -894,12 +843,12 @@ void CSelectableComponent::init() selected = false; } CSelectableComponent::CSelectableComponent(const Component &c, boost::function OnSelect) -:SComponent(c),onSelect(OnSelect) +:CComponent(c),onSelect(OnSelect) { init(); } CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, boost::function OnSelect) -:SComponent(Type,Sub,Val),onSelect(OnSelect) +:CComponent(Type,Sub,Val),onSelect(OnSelect) { init(); } @@ -909,13 +858,13 @@ CSelectableComponent::~CSelectableComponent() void CSelectableComponent::activate() { activateKeys(); - SComponent::activate(); + CComponent::activate(); activateLClick(); } void CSelectableComponent::deactivate() { deactivateKeys(); - SComponent::deactivate(); + CComponent::deactivate(); deactivateLClick(); } void CSelectableComponent::select(bool on) @@ -935,204 +884,10 @@ void CSelectableComponent::show(SDL_Surface * to) blitAt(getImg(),pos.x,pos.y,to); if(selected) { - CSDL_Ext::drawBorder(to, SRect::around(SRect(pos.x, pos.y, getImg()->w, getImg()->h)), int3(239,215,123)); + CSDL_Ext::drawBorder(to, Rect::around(Rect(pos.x, pos.y, getImg()->w, getImg()->h)), int3(239,215,123)); } - printAtMiddleWB(subtitle,pos.x+pos.w/2,pos.y+pos.h+25,FONT_SMALL,12,zwykly,to); -} - -static void intDeleter(CIntObject* object) -{ - delete object; -} - -CObjectList::CObjectList(CreateFunc create, DestroyFunc destroy): - createObject(create), - destroyObject(destroy) -{ - if (!destroyObject) - destroyObject = intDeleter; -} - -void CObjectList::deleteItem(CIntObject* item) -{ - if (!item) - return; - if (active) - item->deactivate(); - removeChild(item); - destroyObject(item); -} - -CIntObject* CObjectList::createItem(size_t index) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - CIntObject * item = createObject(index); - if (item == NULL) - item = new CIntObject(); - - item->recActions = defActions; - - //May happen if object was created before call to getObject() - if(item->parent != this) - { - if (item->parent) - CGuiHandler::moveChild(item, item->parent, this); - else - addChild(item); - } - - if (item && active) - item->activate(); - return item; -} - -CTabbedInt::CTabbedInt(CreateFunc create, DestroyFunc destroy, SPoint position, size_t ActiveID): - CObjectList(create, destroy), - activeTab(NULL), - activeID(ActiveID) -{ - pos += position; - reset(); -} - -void CTabbedInt::setActive(size_t which) -{ - if (which != activeID) - { - activeID = which; - reset(); - } -} - -void CTabbedInt::reset() -{ - deleteItem(activeTab); - activeTab = createItem(activeID); - activeTab->moveTo(pos.topLeft()); - - if (active) - redraw(); -} - -CIntObject * CTabbedInt::getItem() -{ - return activeTab; -} - -CListBox::CListBox(CreateFunc create, DestroyFunc destroy, SPoint Pos, SPoint ItemOffset, size_t VisibleSize, - size_t TotalSize, size_t InitialPos, int Slider, SRect SliderPos): - CObjectList(create, destroy), - first(InitialPos), - totalSize(TotalSize), - itemOffset(ItemOffset) -{ - pos += Pos; - items.resize(VisibleSize, NULL); - - if (Slider & 1) - { - OBJ_CONSTRUCTION_CAPTURING_ALL; - slider = new CSlider(SliderPos.x, SliderPos.y, SliderPos.w, boost::bind(&CListBox::moveToPos, this, _1), - VisibleSize, TotalSize, InitialPos, Slider & 2, Slider & 4); - } - reset(); -} - -// Used to move active items after changing list position -void CListBox::updatePositions() -{ - SPoint itemPos = pos.topLeft(); - for (std::list::iterator it = items.begin(); it!=items.end(); it++) - { - (*it)->moveTo(itemPos); - itemPos += itemOffset; - } - if (active) - { - redraw(); - if (slider) - slider->moveTo(first); - } -} - -void CListBox::reset() -{ - size_t current = first; - for (std::list::iterator it = items.begin(); it!=items.end(); it++) - { - deleteItem(*it); - *it = createItem(current++); - } - updatePositions(); -} - -void CListBox::moveToPos(size_t which) -{ - //Calculate new position - size_t maxPossible; - if (totalSize > items.size()) - maxPossible = totalSize - items.size(); - else - maxPossible = 0; - - size_t newPos = std::min(which, maxPossible); - - //If move distance is 1 (most of calls from Slider) - use faster shifts instead of resetting all items - if (first - newPos == 1) - moveToPrev(); - else if (newPos - first == 1) - moveToNext(); - else if (newPos != first) - { - first = newPos; - reset(); - } -} - -void CListBox::moveToNext() -{ - //Remove front item and insert new one to end - if (first + items.size() < totalSize) - { - first++; - deleteItem(items.front()); - items.pop_front(); - items.push_back(createItem(first+items.size())); - updatePositions(); - } -} - -void CListBox::moveToPrev() -{ - //Remove last item and insert new one at start - if (first) - { - first--; - deleteItem(items.back()); - items.pop_back(); - items.push_front(createItem(first)); - updatePositions(); - } -} - -std::list CListBox::getItems() -{ - return items; -} - -void CSimpleWindow::show(SDL_Surface * to) -{ - if(bitmap) - blitAt(bitmap,pos.x,pos.y,to); -} -CSimpleWindow::~CSimpleWindow() -{ - if (bitmap) - { - SDL_FreeSurface(bitmap); - bitmap=NULL; - } + printAtMiddleWB(subtitle,pos.x+pos.w/2,pos.y+pos.h+25,FONT_SMALL,12,Colors::Cornsilk,to); } void CSelWindow::selectionChange(unsigned to) @@ -1152,13 +907,13 @@ CSelWindow::CSelWindow(const std::string &Text, int player, int charperline, con ID = askID; for(int i=0;i= 0) buttons.back()->callback += boost::bind(&CSelWindow::madeChoice,this); buttons[i]->callback += boost::bind(&CInfoWindow::close,this); //each button will close the window apart from call-defined actions } - text = new CTextBox(Text, SRect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, zwykly); + text = new CTextBox(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, Colors::Cornsilk); text->redrawParentOnScrolling = true; buttons.front()->assignedKeys.insert(SDLK_RETURN); //first button - reacts on enter @@ -1178,7 +933,7 @@ CSelWindow::CSelWindow(const std::string &Text, int player, int charperline, con } CMessage::drawIWindow(this, Text, player); - BOOST_FOREACH(SComponent *c, components) + BOOST_FOREACH(CComponent *c, components) c->subtitle = "";//workaround - erase subtitles since they were hard-blitted by function drawing window } @@ -1197,100 +952,6 @@ void CSelWindow::madeChoice() LOCPLINT->cb->selectionMade(ret+1,ID); } - - -CStatusBar::CStatusBar(int x, int y, std::string name, int maxw) -{ - bg=BitmapHandler::loadBitmap(name); - SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); - pos.x += x; - pos.y += y; - if(maxw >= 0) - pos.w = std::min(bg->w,maxw); - else - pos.w=bg->w; - pos.h=bg->h; - middlex=(pos.w/2)+pos.x; - middley=(bg->h/2)+pos.y; -} - -CStatusBar::~CStatusBar() -{ - SDL_FreeSurface(bg); -} - -void CStatusBar::clear() -{ - if(LOCPLINT->cingconsole->enteredText == "") //for appropriate support for in-game console - { - current=""; - redraw(); - } -} - -void CStatusBar::print(const std::string & text) -{ - if(LOCPLINT->cingconsole->enteredText == "" || text == LOCPLINT->cingconsole->enteredText) //for appropriate support for in-game console - { - current=text; - redraw(); - } -} - -void CStatusBar::show(SDL_Surface * to) -{ - SDL_Rect srcRect = genRect(pos.h,pos.w,0,0); - SDL_Rect dstRect = genRect(pos.h,pos.w,pos.x,pos.y); - CSDL_Ext::blitSurface(bg,&srcRect,to,&dstRect); - printAtMiddle(current,middlex,middley,FONT_SMALL,zwykly,to); -} - -std::string CStatusBar::getCurrent() -{ - return current; -} - -void CList::activate() -{ - activateLClick(); - activateRClick(); - activateHover(); - activateKeys(); - activateMouseMove(); -}; - -void CList::deactivate() -{ - deactivateLClick(); - deactivateRClick(); - deactivateHover(); - deactivateKeys(); - deactivateMouseMove(); -}; - -void CList::clickLeft(tribool down, bool previousState) -{ -}; - -CList::CList(int Size) -:SIZE(Size) -{ -} - -void CList::fixPos() -{ - if(selected < 0) //no selection, do nothing - return; - if(selected < from) //scroll up - from = selected; - else if(from + SIZE <= selected) - from = selected - SIZE + 1; - - vstd::amin(from, size() - SIZE); - vstd::amax(from, 0); - draw(screen); -} - CHeroList::CHeroList(int Size) :CList(Size) { @@ -1323,8 +984,8 @@ void CHeroList::init() { int w = pos.w+1, h = pos.h+4; bg = CSDL_Ext::newSurface(w,h,screen); - SRect srcRect = genRect(w, h, pos.x, pos.y); - SRect dstRect = genRect(w, h, 0, 0); + Rect srcRect = genRect(w, h, pos.x, pos.y); + Rect dstRect = genRect(w, h, 0, 0); CSDL_Ext::blitSurface(adventureInt->bg, &srcRect, bg, &dstRect); } @@ -1579,12 +1240,12 @@ int CHeroList::getPosOfHero(const CGHeroInstance* h) return vstd::find_pos(LOCPLINT->wanderingHeroes, h, std::equal_to()); } -void CHeroList::show( SDL_Surface * to ) +void CHeroList::show(SDL_Surface * to) { } -void CHeroList::showAll( SDL_Surface * to ) +void CHeroList::showAll(SDL_Surface * to) { draw(to); } @@ -1820,12 +1481,12 @@ void CTownList::draw(SDL_Surface * to) blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y,to); } -void CTownList::show( SDL_Surface * to ) +void CTownList::show(SDL_Surface * to) { } -void CTownList::showAll( SDL_Surface * to ) +void CTownList::showAll(SDL_Surface * to) { draw(to); } @@ -1846,7 +1507,7 @@ CCreaturePic::CCreaturePic(int x, int y, const CCreature *cre, bool Big, bool An else bg = new CPicture(graphics->backgroundsm[cre->faction],0,0,false); bg->needRefresh = true; - anim = new CCreatureAnim(0, 0, cre->animDefName, SRect()); + anim = new CCreatureAnim(0, 0, cre->animDefName, Rect()); anim->clipRect(cre->doubleWide?170:150, 155, bg->pos.w, bg->pos.h); anim->startPreview(); } @@ -1906,7 +1567,7 @@ void CRecruitmentWindow::clickLeft(tribool down, bool previousState) { for(int i=0;imotion.x, GH.current->motion.y)) { which = i; @@ -1931,7 +1592,7 @@ void CRecruitmentWindow::clickRight(tribool down, bool previousState) for(int i=0;imotion.x, GH.current->motion.y)) { CIntObject *popup = createCreWindow(creatures[i].ID, 0, 0); @@ -1943,16 +1604,16 @@ void CRecruitmentWindow::clickRight(tribool down, bool previousState) } } -void CRecruitmentWindow::showAll( SDL_Surface * to ) +void CRecruitmentWindow::showAll(SDL_Surface * to) { CIntObject::showAll(to); char pom[15]; SDL_itoa(creatures[which].amount-slider->value,pom,10); //available - printAtMiddleLoc(pom,205,253,FONT_SMALL,zwykly,to); + printAtMiddleLoc(pom,205,253,FONT_SMALL,Colors::Cornsilk,to); SDL_itoa(slider->value,pom,10); //recruit - printAtMiddleLoc(pom,279,253,FONT_SMALL,zwykly,to); - printAtMiddleLoc(CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures[creatures[which].ID]->namePl,243,32,FONT_BIG,tytulowy,to); //eg "Recruit Dragon flies" + printAtMiddleLoc(pom,279,253,FONT_SMALL,Colors::Cornsilk,to); + printAtMiddleLoc(CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures[creatures[which].ID]->namePl,243,32,FONT_BIG,Colors::Jasmine,to); //eg "Recruit Dragon flies" int curx = 122-creatures[which].res.size()*24; for(int i=creatures[which].res.size()-1; i>=0; i--)// decrement used to make gold displayed as first res @@ -1960,9 +1621,9 @@ void CRecruitmentWindow::showAll( SDL_Surface * to ) blitAtLoc(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx,243,to); blitAtLoc(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx+258,243,to); SDL_itoa(creatures[which].res[i].second,pom,10); - printAtMiddleLoc(pom,curx+15,287,FONT_SMALL,zwykly,to); + printAtMiddleLoc(pom,curx+15,287,FONT_SMALL,Colors::Cornsilk,to); SDL_itoa(creatures[which].res[i].second * slider->value,pom,10); - printAtMiddleLoc(pom,curx+15+258,287,FONT_SMALL,zwykly,to); + printAtMiddleLoc(pom,curx+15+258,287,FONT_SMALL,Colors::Cornsilk,to); curx+=32+16;//size of bitmap + distance between them } @@ -1986,21 +1647,21 @@ CRecruitmentWindow::CRecruitmentWindow(const CGDwelling *Dwelling, int Level, co bitmap = new CPicture("TPRCRT.bmp"); bitmap->colorizeAndConvert(LOCPLINT->playerID); bitmap->center(); - pos = (bitmap->pos += SPoint(0, y_offset)); + pos = (bitmap->pos += Point(0, y_offset)); bar = new CGStatusBar(8, 370, "APHLFTRT.bmp", 471); - max = new AdventureMapButton(CGI->generaltexth->zelp[553],boost::bind(&CRecruitmentWindow::Max,this),134,313,"IRCBTNS.DEF",SDLK_m); - buy = new AdventureMapButton(CGI->generaltexth->zelp[554],boost::bind(&CRecruitmentWindow::Buy,this),212,313,"IBY6432.DEF",SDLK_RETURN); - cancel = new AdventureMapButton(CGI->generaltexth->zelp[555],boost::bind(&CRecruitmentWindow::Cancel,this),290,313,"ICN6432.DEF",SDLK_ESCAPE); + max = new CAdventureMapButton(CGI->generaltexth->zelp[553],boost::bind(&CRecruitmentWindow::Max,this),134,313,"IRCBTNS.DEF",SDLK_m); + buy = new CAdventureMapButton(CGI->generaltexth->zelp[554],boost::bind(&CRecruitmentWindow::Buy,this),212,313,"IBY6432.DEF",SDLK_RETURN); + cancel = new CAdventureMapButton(CGI->generaltexth->zelp[555],boost::bind(&CRecruitmentWindow::Cancel,this),290,313,"ICN6432.DEF",SDLK_ESCAPE); slider = new CSlider(176,279,135,0,0,0,0,true); slider->moved = boost::bind(&CRecruitmentWindow::sliderMoved,this, _1); initCres(); - printAtMiddle(CGI->generaltexth->allTexts[346],113,232,FONT_SMALL,zwykly,*bitmap); //cost per troop t - printAtMiddle(CGI->generaltexth->allTexts[465],205,233,FONT_SMALL,zwykly,*bitmap); //available t - printAtMiddle(CGI->generaltexth->allTexts[16],279,233,FONT_SMALL,zwykly,*bitmap); //recruit t - printAtMiddle(CGI->generaltexth->allTexts[466],371,232,FONT_SMALL,zwykly,*bitmap); //total cost t + printAtMiddle(CGI->generaltexth->allTexts[346],113,232,FONT_SMALL,Colors::Cornsilk,*bitmap); //cost per troop t + printAtMiddle(CGI->generaltexth->allTexts[465],205,233,FONT_SMALL,Colors::Cornsilk,*bitmap); //available t + printAtMiddle(CGI->generaltexth->allTexts[16],279,233,FONT_SMALL,Colors::Cornsilk,*bitmap); //recruit t + printAtMiddle(CGI->generaltexth->allTexts[466],371,232,FONT_SMALL,Colors::Cornsilk,*bitmap); //total cost t drawBorder(*bitmap,172,222,67,42,int3(239,215,123)); drawBorder(*bitmap,246,222,67,42,int3(239,215,123)); drawBorder(*bitmap,64,222,99,76,int3(239,215,123)); @@ -2083,8 +1744,8 @@ CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last, int pos.y = screen->h/2 - bitmap->h/2; pos.w = bitmap->w; pos.h = bitmap->h; - ok = new AdventureMapButton("","",boost::bind(&CSplitWindow::split,this),pos.x+20,pos.y+263,"IOK6432.DEF",SDLK_RETURN); - cancel = new AdventureMapButton("","",boost::bind(&CSplitWindow::close,this),pos.x+214,pos.y+263,"ICN6432.DEF",SDLK_ESCAPE); + ok = new CAdventureMapButton("","",boost::bind(&CSplitWindow::split,this),pos.x+20,pos.y+263,"IOK6432.DEF",SDLK_RETURN); + cancel = new CAdventureMapButton("","",boost::bind(&CSplitWindow::close,this),pos.x+214,pos.y+263,"ICN6432.DEF",SDLK_ESCAPE); int sliderPositions = max - (last>=0) - (last==2); slider = new CSlider(pos.x+21,pos.y+194,257,boost::bind(&CSplitWindow::sliderMoved,this,_1),0,sliderPositions,val,true); a1 = max-val; @@ -2094,7 +1755,7 @@ CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last, int std::string title = CGI->generaltexth->allTexts[256]; boost::algorithm::replace_first(title,"%s",CGI->creh->creatures[cid]->namePl); - printAtMiddle(title,150,34,FONT_BIG,tytulowy,bitmap); + printAtMiddle(title,150,34,FONT_BIG,Colors::Jasmine,bitmap); } CSplitWindow::~CSplitWindow() //d-tor @@ -2150,8 +1811,8 @@ void CSplitWindow::show(SDL_Surface * to) ok->showAll(to); cancel->showAll(to); slider->showAll(to); - printAtMiddle(boost::lexical_cast(a1) + (!which ? "_" : ""),pos.x+70,pos.y+237,FONT_BIG,zwykly,to); - printAtMiddle(boost::lexical_cast(a2) + (which ? "_" : ""),pos.x+233,pos.y+237,FONT_BIG,zwykly,to); + printAtMiddle(boost::lexical_cast(a1) + (!which ? "_" : ""),pos.x+70,pos.y+237,FONT_BIG,Colors::Cornsilk,to); + printAtMiddle(boost::lexical_cast(a2) + (which ? "_" : ""),pos.x+233,pos.y+237,FONT_BIG,Colors::Cornsilk,to); animLeft->show(to); animRight->show(to); } @@ -2206,180 +1867,15 @@ void CSplitWindow::clickLeft(tribool down, bool previousState) { if(down) { - SPoint click(GH.current->motion.x,GH.current->motion.y); + Point click(GH.current->motion.x,GH.current->motion.y); click = click - pos.topLeft(); - if(SRect(19,216,105,40).isIn(click)) //left picture + if(Rect(19,216,105,40).isIn(click)) //left picture which = 0; - else if(SRect(175,216,105,40).isIn(click)) //right picture + else if(Rect(175,216,105,40).isIn(click)) //right picture which = 1; } } -void CCreInfoWindow::show(SDL_Surface *to) -{ - CIntObject::show(to); - creatureCount->showAll(to); -} - -CCreInfoWindow::CCreInfoWindow(const CStackInstance &stack, bool LClicked, boost::function upgradeFunc, boost::function dismissFunc, UpgradeInfo *upgradeInfo) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - init(stack.type, &stack, dynamic_cast(stack.armyObj), stack.count, LClicked); - - //additional buttons if opened with left click - if(LClicked) - { - boost::function closeFunc = boost::bind(&CCreInfoWindow::close,this); - - if(upgradeFunc && upgradeInfo) - { - TResources upgradeCost = upgradeInfo->cost[0] * stack.count; - for(TResources::nziterator i(upgradeCost); i.valid(); i++) - { - BLOCK_CAPTURING; - upgResCost.push_back(new SComponent(SComponent::resource, i->resType, i->resVal)); - } - - CFunctionList onUpgrade; - onUpgrade += upgradeFunc; - onUpgrade += closeFunc; - - boost::function dialog = boost::bind(&CPlayerInterface::showYesNoDialog, - LOCPLINT, - CGI->generaltexth->allTexts[207], - boost::ref(upgResCost), - onUpgrade, 0, false); - - upgrade = new AdventureMapButton("", CGI->generaltexth->zelp[446].second, dialog, 76, 237, "IVIEWCR", SDLK_u); - upgrade->block(!LOCPLINT->cb->getResourceAmount().canAfford(upgradeCost)); - } - - if(dismissFunc) - { - CFunctionList onDismiss; - onDismiss += dismissFunc; - onDismiss += closeFunc; - - boost::function dialog = boost::bind(&CPlayerInterface::showYesNoDialog, - LOCPLINT, - CGI->generaltexth->allTexts[12], - std::vector(), - onDismiss, 0, true); - - dismiss = new AdventureMapButton("", CGI->generaltexth->zelp[445].second, dialog, 21, 237, "IVIEWCR2",SDLK_d); - } - - ok = new AdventureMapButton("", CGI->generaltexth->zelp[445].second, - boost::bind(&CCreInfoWindow::close,this), 216, 237, "IOKAY.DEF", SDLK_RETURN); - } -} - -CCreInfoWindow::CCreInfoWindow(int creatureID, bool LClicked, int creatureCount) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - const CCreature *creature = CGI->creh->creatures[creatureID]; - init(creature, NULL, NULL, creatureCount, LClicked); -} - -CCreInfoWindow::CCreInfoWindow(const CStack &stack, bool LClicked) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - init(stack.getCreature(), &stack, stack.getMyHero(), stack.count, LClicked); -} - -CCreInfoWindow::~CCreInfoWindow() -{ - BOOST_FOREACH(SComponent* object, upgResCost) - delete object; -} - -void CCreInfoWindow::printLine(int position, const std::string &text, int baseVal, int val/*=-1*/, bool range/*=false*/) -{ - infoTexts[position].first = new CLabel(155, 48 + position*19, FONT_SMALL, TOPLEFT, zwykly, text); - std::string valueStr; - - if(range && baseVal != val) - valueStr = boost::str(boost::format("%d - %d") % baseVal % val); - - else if(baseVal != val && val>=0) - valueStr = boost::str(boost::format("%d (%d)") % baseVal % val); - - else - valueStr = boost::lexical_cast(baseVal); - - infoTexts[position].second = new CLabel(276, 63 + position*19, FONT_SMALL, BOTTOMRIGHT, zwykly, valueStr); -} - -void CCreInfoWindow::init(const CCreature *creature, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner, int count, bool LClicked) -{ - used = 0; - if (!LClicked) - used |= RCLICK; - - if(!stackNode) - stackNode = creature; - - background = new CPicture("CRSTKPU"); - background->colorize(LOCPLINT->playerID); - pos = background->center(); - - animation = new CCreaturePic(21, 48, creature); - - std::string countStr = boost::lexical_cast(count); - creatureCount = new CLabel(114, 174, FONT_TIMES, BOTTOMRIGHT, zwykly, countStr); - - creatureName = new CLabel(149, 30, FONT_SMALL, CENTER, tytulowy, creature->namePl); - - printLine(0, CGI->generaltexth->primarySkillNames[0], creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), stackNode->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK)); - printLine(1, CGI->generaltexth->primarySkillNames[1], creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), stackNode->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE)); - - if(stackNode->valOfBonuses(Bonus::SHOTS)) - printLine(2, CGI->generaltexth->allTexts[198], stackNode->valOfBonuses(Bonus::SHOTS)); - - //TODO - int dmgMultiply = 1; - if(heroOwner && stackNode->hasBonusOfType(Bonus::SIEGE_WEAPON)) - dmgMultiply += heroOwner->Attack(); - - printLine(3, CGI->generaltexth->allTexts[199], stackNode->getMinDamage() * dmgMultiply, stackNode->getMaxDamage() * dmgMultiply, true); - printLine(4, CGI->generaltexth->allTexts[388], creature->valOfBonuses(Bonus::STACK_HEALTH), stackNode->valOfBonuses(Bonus::STACK_HEALTH)); - printLine(6, CGI->generaltexth->zelp[441].first, creature->valOfBonuses(Bonus::STACKS_SPEED), stackNode->valOfBonuses(Bonus::STACKS_SPEED)); - - //setting morale - morale = new MoraleLuckBox(true, genRect(42, 42, 22, 186)); - morale->set(stackNode); - //setting luck - luck = new MoraleLuckBox(false, genRect(42, 42, 75, 186)); - luck->set(stackNode); - - if(!LClicked) - abilityText = new CLabel(17, 231, FONT_SMALL, TOPLEFT, zwykly, creature->abilityText); - else - abilityText = NULL; - - //if we are displying window fo r stack in battle, there are several more things that we need to display - if(const CStack *battleStack = dynamic_cast(stackNode)) - { - //print at most 3 spell effects - std::vector spells = battleStack->activeSpells(); - for (size_t i=0; i< std::min(spells.size(), size_t(3)); i++) - effects.push_back(new CAnimImage("SpellInt", spells[i]+1, 0, 127 + 52*i, 186)); - - //print current health - printLine(5, CGI->generaltexth->allTexts[200], battleStack->firstHPleft); - } -} - -void CCreInfoWindow::close() -{ - GH.popIntTotally(this); -} - -void CCreInfoWindow::clickRight(tribool down, bool previousState) -{ - close(); -} - void CLevelWindow::close() { for(int i=0;igetSecSkillLevel( static_cast(skills[i]) )+1, boost::bind(&CLevelWindow::selectionChanged,this,i))); comps.back()->assignedKeys.insert(SDLK_1 + i); @@ -2416,20 +1912,20 @@ CLevelWindow::CLevelWindow(const CGHeroInstance *hero, int pskill, std::vectorh/2 - bitmap->h/2; pos.w = bitmap->w; pos.h = bitmap->h; - ok = new AdventureMapButton("","",boost::bind(&CLevelWindow::close,this),pos.x+297,pos.y+413,"IOKAY.DEF",SDLK_RETURN); + ok = new CAdventureMapButton("","",boost::bind(&CLevelWindow::close,this),pos.x+297,pos.y+413,"IOKAY.DEF",SDLK_RETURN); //draw window char buf[100], buf2[100]; strcpy(buf2,CGI->generaltexth->allTexts[444].c_str()); //%s has gained a level. sprintf(buf,buf2,hero->name.c_str()); - printAtMiddle(buf,192,33,FONT_MEDIUM,zwykly,bitmap); + printAtMiddle(buf,192,33,FONT_MEDIUM,Colors::Cornsilk,bitmap); strcpy(buf2,CGI->generaltexth->allTexts[445].c_str()); //%s is now a level %d %s. sprintf(buf,buf2,hero->name.c_str(),hero->level,hero->type->heroClass->name.c_str()); - printAtMiddle(buf,192,162,FONT_MEDIUM,zwykly,bitmap); + printAtMiddle(buf,192,162,FONT_MEDIUM,Colors::Cornsilk,bitmap); blitAt(graphics->pskillsm->ourImages[pskill].bitmap,174,190,bitmap); - printAtMiddle((CGI->generaltexth->primarySkillNames[pskill] + " +1"),192,253,FONT_MEDIUM,zwykly,bitmap); + printAtMiddle((CGI->generaltexth->primarySkillNames[pskill] + " +1"),192,253,FONT_MEDIUM,Colors::Cornsilk,bitmap); const Font *f = graphics->fonts[FONT_MEDIUM]; std::string text = CGI->generaltexth->allTexts[4]; @@ -2443,7 +1939,7 @@ CLevelWindow::CLevelWindow(const CGHeroInstance *hero, int pskill, std::vectorcb->getResourceAmount(i),buf,10); - CSDL_Ext::printAtMiddle(buf,pos.x + 50 + 76*i,pos.y+pos.h/2,FONT_SMALL,zwykly,to); + CSDL_Ext::printAtMiddle(buf,pos.x + 50 + 76*i,pos.y+pos.h/2,FONT_SMALL,Colors::Cornsilk,to); } std::vector temp; SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp.push_back(std::string(buf)); @@ -2511,7 +2007,7 @@ void CMinorResDataBar::show(SDL_Surface * to) + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s",temp) - ,pos.x+545+(pos.w-545)/2,pos.y+pos.h/2,FONT_SMALL,zwykly,to); + ,pos.x+545+(pos.w-545)/2,pos.y+pos.h/2,FONT_SMALL,Colors::Cornsilk,to); } void CMinorResDataBar::showAll(SDL_Surface * to) @@ -2552,8 +2048,8 @@ CObjectListWindow::CObjectListWindow(const std::vector &_items, CPicture * bg->colorizeAndConvert(LOCPLINT->playerID); slider = new CSlider(277, 120, 256, boost::bind(&CObjectListWindow::moveList,this, _1), length, items.size(), 0, false, 0); - ok = new AdventureMapButton("","",boost::bind(&CObjectListWindow::elementSelected, this),15,402,"IOKAY.DEF", SDLK_RETURN); - exit = new AdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally,&GH, this),228,402,"ICANCEL.DEF",SDLK_ESCAPE); + ok = new CAdventureMapButton("","",boost::bind(&CObjectListWindow::elementSelected, this),15,402,"IOKAY.DEF", SDLK_RETURN); + exit = new CAdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally,&GH, this),228,402,"ICANCEL.DEF",SDLK_ESCAPE); pos.w = bg->pos.w; pos.h = bg->pos.h; titleImage = titlePic; @@ -2653,8 +2149,8 @@ void CObjectListWindow::showAll(SDL_Surface * to) { ok->block((selected<0)?2:0); CIntObject::showAll(to); - CSDL_Ext::printAtMiddle(title,pos.x+152,pos.y+27,FONT_BIG,tytulowy,to);//"castle gate" - CSDL_Ext::printAtMiddle(descr,pos.x+145,pos.y+133,FONT_SMALL,zwykly,to);//"select destination" + CSDL_Ext::printAtMiddle(title,pos.x+152,pos.y+27,FONT_BIG,Colors::Jasmine,to);//"castle gate" + CSDL_Ext::printAtMiddle(descr,pos.x+145,pos.y+133,FONT_SMALL,Colors::Cornsilk,to);//"select destination" titleImage->showAll(to); if ( selected >= slider->value && selected < slider->value+length )//if selected item is visible { @@ -2665,7 +2161,7 @@ void CObjectListWindow::showAll(SDL_Surface * to) int position = slider->value; for ( int i = 0; i<9 && imh->map->objects[items[i+position]]->hoverName,pos.x+145,pos.y+163+25*i, - FONT_SMALL, zwykly, to);//print item names in list + FONT_SMALL, Colors::Cornsilk, to);//print item names in list } CTradeWindow::CTradeableItem::CTradeableItem( EType Type, int ID, bool Left, int Serial) @@ -2681,39 +2177,39 @@ CTradeWindow::CTradeableItem::CTradeableItem( EType Type, int ID, bool Left, int void CTradeWindow::CTradeableItem::showAll(SDL_Surface * to) { - SPoint posToBitmap; - SPoint posToSubCenter; + Point posToBitmap; + Point posToSubCenter; switch(type) { case RESOURCE: - posToBitmap = SPoint(19,9); - posToSubCenter = SPoint(36, 59); + posToBitmap = Point(19,9); + posToSubCenter = Point(36, 59); break; case CREATURE_PLACEHOLDER: case CREATURE: - posToSubCenter = SPoint(29, 76); + posToSubCenter = Point(29, 76); if(downSelection) posToSubCenter.y += 5; break; case PLAYER: - posToSubCenter = SPoint(31, 76); + posToSubCenter = Point(31, 76); break; case ARTIFACT_PLACEHOLDER: case ARTIFACT_INSTANCE: - posToSubCenter = SPoint(19, 55); + posToSubCenter = Point(19, 55); if(downSelection) posToSubCenter.y += 8; break; case ARTIFACT_TYPE: - posToSubCenter = SPoint(19, 58); + posToSubCenter = Point(19, 58); break; } if(SDL_Surface *hlp = getSurface()) blitAt(hlp, pos + posToBitmap, to); - printAtMiddleLoc(subtitle, posToSubCenter, FONT_SMALL, zwykly, to); + printAtMiddleLoc(subtitle, posToSubCenter, FONT_SMALL, Colors::Cornsilk, to); } void CTradeWindow::CTradeableItem::clickLeft(tribool down, bool previousState) @@ -2786,9 +2282,9 @@ SDL_Surface * CTradeWindow::CTradeableItem::getSurface() } } -void CTradeWindow::CTradeableItem::showAllAt(const SPoint &dstPos, const std::string &customSub, SDL_Surface * to) +void CTradeWindow::CTradeableItem::showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to) { - SRect oldPos = pos; + Rect oldPos = pos; std::string oldSub = subtitle; downSelection = true; @@ -2941,7 +2437,7 @@ void CTradeWindow::initItems(bool Left) CTradeableItem *hlp = new CTradeableItem(itemsType[Left], -1, 1, 0); hlp->recActions &= ~(UPDATE | SHOWALL); - hlp->pos += SRect(137, 469, 42, 42); + hlp->pos += Rect(137, 469, 42, 42); items[Left].push_back(hlp); } else //ARTIFACT_EXP @@ -2951,7 +2447,7 @@ void CTradeWindow::initItems(bool Left) } BLOCK_CAPTURING; - arts = new CArtifactsOfHero(SPoint(pos.x+xOffset, pos.y+yOffset)); + arts = new CArtifactsOfHero(Point(pos.x+xOffset, pos.y+yOffset)); arts->commonInfo = new CArtifactsOfHero::SCommonPart; arts->commonInfo->participants.insert(arts); arts->recActions = 255; @@ -2966,7 +2462,7 @@ void CTradeWindow::initItems(bool Left) } std::vector *ids = getItemsIds(Left); - std::vector pos; + std::vector pos; int amount = -1; getPositionsFor(pos, Left, itemsType[Left]); @@ -3036,7 +2532,7 @@ std::vector *CTradeWindow::getItemsIds(bool Left) return ids; } -void CTradeWindow::getPositionsFor(std::vector &poss, bool Left, EType type) const +void CTradeWindow::getPositionsFor(std::vector &poss, bool Left, EType type) const { if(mode == EMarketMode::ARTIFACT_EXP && !Left) { @@ -3049,10 +2545,10 @@ void CTradeWindow::getPositionsFor(std::vector &poss, bool Left, EType ty dy = 70; for (int i = 0; i < 4 ; i++) for (int j = 0; j < 5 ; j++) - poss += SRect(x + dx*j, y + dy*i, w, h); + poss += Rect(x + dx*j, y + dy*i, w, h); - poss += SRect(x + dx*1.5, y + dy*4, w, h); - poss += SRect(x + dx*2.5, y + dy*4, w, h); + poss += Rect(x + dx*1.5, y + dy*4, w, h); + poss += Rect(x + dx*2.5, y + dy*4, w, h); } else { @@ -3070,7 +2566,7 @@ void CTradeWindow::getPositionsFor(std::vector &poss, bool Left, EType ty if(!Left) { - BOOST_FOREACH(SRect &r, poss) + BOOST_FOREACH(Rect &r, poss) r.x += leftToRightOffset; } } @@ -3237,18 +2733,18 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan if(market->o->ID == 7) //black market { - printAtMiddle(CGI->generaltexth->allTexts[349],300,27,FONT_BIG,tytulowy,*bg); //title + printAtMiddle(CGI->generaltexth->allTexts[349],300,27,FONT_BIG,Colors::Jasmine,*bg); //title } else if(market->o->ID == 99 || market->o->ID == 221) //trading post { - printAtMiddle(CGI->generaltexth->allTexts[159],300,27,FONT_BIG,tytulowy,*bg); //title + printAtMiddle(CGI->generaltexth->allTexts[159],300,27,FONT_BIG,Colors::Jasmine,*bg); //title } else if(mode == EMarketMode::CREATURE_RESOURCE) { if(market->o->ID == GameConstants::TOWNI_TYPE) - printAtMiddle(CGI->buildh->buildings[6][21]->Name(), 300, 27, FONT_BIG, tytulowy, *bg); //title + printAtMiddle(CGI->buildh->buildings[6][21]->Name(), 300, 27, FONT_BIG, Colors::Jasmine, *bg); //title else - printAtMiddle(market->o->getHoverText(), 300, 27, FONT_BIG, tytulowy, *bg); //title + printAtMiddle(market->o->getHoverText(), 300, 27, FONT_BIG, Colors::Jasmine, *bg); //title } else if(mode == EMarketMode::RESOURCE_ARTIFACT || mode == EMarketMode::ARTIFACT_RESOURCE) { @@ -3256,19 +2752,19 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan ? CGI->buildh->buildings[market->o->subID][17]->Name() : market->o->getHoverText(); - printAtMiddle(title, 300, 27, FONT_BIG, tytulowy, *bg); //title + printAtMiddle(title, 300, 27, FONT_BIG, Colors::Jasmine, *bg); //title } else { - printAtMiddle(CGI->generaltexth->allTexts[158],300,27,FONT_BIG,tytulowy,*bg); //marketplace + printAtMiddle(CGI->generaltexth->allTexts[158],300,27,FONT_BIG,Colors::Jasmine,*bg); //marketplace } initItems(false); initItems(true); - ok = new AdventureMapButton(CGI->generaltexth->zelp[600],boost::bind(&CGuiHandler::popIntTotally,&GH,this),516,520,"IOK6432.DEF",SDLK_RETURN); + ok = new CAdventureMapButton(CGI->generaltexth->zelp[600],boost::bind(&CGuiHandler::popIntTotally,&GH,this),516,520,"IOK6432.DEF",SDLK_RETURN); ok->assignedKeys.insert(SDLK_ESCAPE); - deal = new AdventureMapButton(CGI->generaltexth->zelp[595],boost::bind(&CMarketplaceWindow::makeDeal,this),307,520,"TPMRKB.DEF"); + deal = new CAdventureMapButton(CGI->generaltexth->zelp[595],boost::bind(&CMarketplaceWindow::makeDeal,this),307,520,"TPMRKB.DEF"); deal->block(true); @@ -3277,17 +2773,17 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan { slider = new CSlider(231,490,137,0,0,0); slider->moved = boost::bind(&CMarketplaceWindow::sliderMoved,this,_1); - max = new AdventureMapButton(CGI->generaltexth->zelp[596],boost::bind(&CMarketplaceWindow::setMax,this),229,520,"IRCBTNS.DEF"); + max = new CAdventureMapButton(CGI->generaltexth->zelp[596],boost::bind(&CMarketplaceWindow::setMax,this),229,520,"IRCBTNS.DEF"); max->block(true); } else { slider = NULL; max = NULL; - deal->moveBy(SPoint(-30, 0)); + deal->moveBy(Point(-30, 0)); } - SRect traderTextRect; + Rect traderTextRect; //left side switch(Mode) @@ -3295,13 +2791,13 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan case EMarketMode::RESOURCE_RESOURCE: case EMarketMode::RESOURCE_PLAYER: case EMarketMode::RESOURCE_ARTIFACT: - printAtMiddle(CGI->generaltexth->allTexts[270],154,148,FONT_SMALL,zwykly,*bg); //kingdom res. + printAtMiddle(CGI->generaltexth->allTexts[270],154,148,FONT_SMALL,Colors::Cornsilk,*bg); //kingdom res. break; case EMarketMode::CREATURE_RESOURCE: - printAtMiddle(boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->name), 152, 102, FONT_SMALL, zwykly, *bg); //%s's Creatures + printAtMiddle(boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->name), 152, 102, FONT_SMALL, Colors::Cornsilk, *bg); //%s's Creatures break; case EMarketMode::ARTIFACT_RESOURCE: - printAtMiddle(boost::str(boost::format(CGI->generaltexth->allTexts[271]) % hero->name), 152, 57, FONT_SMALL, zwykly, *bg); //%s's Artifacts + printAtMiddle(boost::str(boost::format(CGI->generaltexth->allTexts[271]) % hero->name), 152, 57, FONT_SMALL, Colors::Cornsilk, *bg); //%s's Artifacts break; } @@ -3312,12 +2808,12 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan case EMarketMode::CREATURE_RESOURCE: case EMarketMode::RESOURCE_ARTIFACT: case EMarketMode::ARTIFACT_RESOURCE: - printAtMiddle(CGI->generaltexth->allTexts[168],445,148,FONT_SMALL,zwykly,*bg); //available for trade - traderTextRect = SRect(316, 48, 260, 75); + printAtMiddle(CGI->generaltexth->allTexts[168],445,148,FONT_SMALL,Colors::Cornsilk,*bg); //available for trade + traderTextRect = Rect(316, 48, 260, 75); break; case EMarketMode::RESOURCE_PLAYER: - printAtMiddle(CGI->generaltexth->allTexts[169],445,55,FONT_SMALL,zwykly,*bg); //players - traderTextRect = SRect(28, 48, 260, 75); + printAtMiddle(CGI->generaltexth->allTexts[169],445,55,FONT_SMALL,Colors::Cornsilk,*bg); //players + traderTextRect = Rect(28, 48, 260, 75); break; } @@ -3325,15 +2821,15 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan int specialOffset = mode == EMarketMode::ARTIFACT_RESOURCE ? 35 : 0; //in selling artifacts mode we need to move res-res and art-res buttons down if(printButtonFor(EMarketMode::RESOURCE_PLAYER)) - new AdventureMapButton(CGI->generaltexth->zelp[612],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::RESOURCE_PLAYER), 18, 520,"TPMRKBU1.DEF"); + new CAdventureMapButton(CGI->generaltexth->zelp[612],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::RESOURCE_PLAYER), 18, 520,"TPMRKBU1.DEF"); if(printButtonFor(EMarketMode::RESOURCE_RESOURCE)) - new AdventureMapButton(CGI->generaltexth->zelp[605],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::RESOURCE_RESOURCE), 516, 450 + specialOffset,"TPMRKBU5.DEF"); + new CAdventureMapButton(CGI->generaltexth->zelp[605],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::RESOURCE_RESOURCE), 516, 450 + specialOffset,"TPMRKBU5.DEF"); if(printButtonFor(EMarketMode::CREATURE_RESOURCE)) - new AdventureMapButton(CGI->generaltexth->zelp[599],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::CREATURE_RESOURCE), 516, 485,"TPMRKBU4.DEF"); //was y=450, changed to not overlap res-res in some conditions + new CAdventureMapButton(CGI->generaltexth->zelp[599],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::CREATURE_RESOURCE), 516, 485,"TPMRKBU4.DEF"); //was y=450, changed to not overlap res-res in some conditions if(printButtonFor(EMarketMode::RESOURCE_ARTIFACT)) - new AdventureMapButton(CGI->generaltexth->zelp[598],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::RESOURCE_ARTIFACT), 18, 450 + specialOffset,"TPMRKBU2.DEF"); + new CAdventureMapButton(CGI->generaltexth->zelp[598],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::RESOURCE_ARTIFACT), 18, 450 + specialOffset,"TPMRKBU2.DEF"); if(printButtonFor(EMarketMode::ARTIFACT_RESOURCE)) - new AdventureMapButton(CGI->generaltexth->zelp[613],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::ARTIFACT_RESOURCE), 18, 485,"TPMRKBU3.DEF"); //was y=450, changed to not overlap res-art in some conditions + new CAdventureMapButton(CGI->generaltexth->zelp[613],boost::bind(&CMarketplaceWindow::setMode,this, EMarketMode::ARTIFACT_RESOURCE), 18, 485,"TPMRKBU3.DEF"); //was y=450, changed to not overlap res-art in some conditions updateTraderText(); } @@ -3525,18 +3021,18 @@ std::string CMarketplaceWindow::selectionSubtitle(bool Left) const return "???"; } -SPoint CMarketplaceWindow::selectionOffset(bool Left) const +Point CMarketplaceWindow::selectionOffset(bool Left) const { if(Left) { switch(itemsType[1]) { case RESOURCE: - return SPoint(122, 446); + return Point(122, 446); case CREATURE: - return SPoint(128, 450); + return Point(128, 450); case ARTIFACT_INSTANCE: - return SPoint(134, 466); + return Point(134, 466); } } else @@ -3545,18 +3041,18 @@ SPoint CMarketplaceWindow::selectionOffset(bool Left) const { case RESOURCE: if(mode == EMarketMode::ARTIFACT_RESOURCE) - return SPoint(410, 469); + return Point(410, 469); else - return SPoint(410, 446); + return Point(410, 446); case ARTIFACT_TYPE: - return SPoint(425, 447); + return Point(425, 447); case PLAYER: - return SPoint(417, 451); + return Point(417, 451); } } assert(0); - return SPoint(0,0); + return Point(0,0); } void CMarketplaceWindow::resourceChanged(int type, int val) @@ -3670,16 +3166,16 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*= if(Mode == EMarketMode::CREATURE_EXP) { - printAtMiddle(boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->name), 155, 30, FONT_SMALL, tytulowy, *bg); //%s's Creatures - printAtMiddle(CGI->generaltexth->allTexts[479], 450, 30, FONT_SMALL, tytulowy, *bg); //Altar of Sacrifice - printAtMiddleWB(CGI->generaltexth->allTexts[480], 450, 70, FONT_SMALL, 45, tytulowy, *bg); //To sacrifice creatures, move them from your army on to the Altar and click Sacrifice + printAtMiddle(boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->name), 155, 30, FONT_SMALL, Colors::Jasmine, *bg); //%s's Creatures + printAtMiddle(CGI->generaltexth->allTexts[479], 450, 30, FONT_SMALL, Colors::Jasmine, *bg); //Altar of Sacrifice + printAtMiddleWB(CGI->generaltexth->allTexts[480], 450, 70, FONT_SMALL, 45, Colors::Jasmine, *bg); //To sacrifice creatures, move them from your army on to the Altar and click Sacrifice slider = new CSlider(231,481,137,0,0,0); slider->moved = boost::bind(&CAltarWindow::sliderMoved,this,_1); - max = new AdventureMapButton(CGI->generaltexth->zelp[578],boost::bind(&CSlider::moveToMax, slider),147,520,"IRCBTNS.DEF"); + max = new CAdventureMapButton(CGI->generaltexth->zelp[578],boost::bind(&CSlider::moveToMax, slider),147,520,"IRCBTNS.DEF"); sacrificedUnits.resize(GameConstants::ARMY_SIZE, 0); - sacrificeAll = new AdventureMapButton(CGI->generaltexth->zelp[579],boost::bind(&CAltarWindow::SacrificeAll,this),393,520,"ALTARMY.DEF"); + sacrificeAll = new CAdventureMapButton(CGI->generaltexth->zelp[579],boost::bind(&CAltarWindow::SacrificeAll,this),393,520,"ALTARMY.DEF"); sacrificeBackpack = NULL; initItems(true); @@ -3687,12 +3183,12 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*= } else { - printAtMiddle(CGI->generaltexth->allTexts[477], 450, 34, FONT_SMALL, tytulowy, *bg); //Sacrifice artifacts for experience - printAtMiddle(CGI->generaltexth->allTexts[478], 302, 423, FONT_SMALL, tytulowy, *bg); //%s's Creatures + printAtMiddle(CGI->generaltexth->allTexts[477], 450, 34, FONT_SMALL, Colors::Jasmine, *bg); //Sacrifice artifacts for experience + printAtMiddle(CGI->generaltexth->allTexts[478], 302, 423, FONT_SMALL, Colors::Jasmine, *bg); //%s's Creatures - sacrificeAll = new AdventureMapButton(CGI->generaltexth->zelp[571],boost::bind(&CAltarWindow::SacrificeAll,this),393,520,"ALTFILL.DEF"); + sacrificeAll = new CAdventureMapButton(CGI->generaltexth->zelp[571],boost::bind(&CAltarWindow::SacrificeAll,this),393,520,"ALTFILL.DEF"); sacrificeAll->block(!hero->artifactsInBackpack.size() && !hero->artifactsWorn.size()); - sacrificeBackpack = new AdventureMapButton(CGI->generaltexth->zelp[570],boost::bind(&CAltarWindow::SacrificeBackpack,this),147,520,"ALTEMBK.DEF"); + sacrificeBackpack = new CAdventureMapButton(CGI->generaltexth->zelp[570],boost::bind(&CAltarWindow::SacrificeBackpack,this),147,520,"ALTEMBK.DEF"); sacrificeBackpack->block(!hero->artifactsInBackpack.size()); slider = NULL; @@ -3702,19 +3198,19 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*= initItems(false); } - printAtMiddleWB(CGI->generaltexth->allTexts[475], 72, 437, FONT_SMALL, 17, tytulowy, *bg); //Experience needed to reach next level - printAtMiddleWB(CGI->generaltexth->allTexts[476], 72, 505, FONT_SMALL, 17, tytulowy, *bg); //Total experience on the Altar + printAtMiddleWB(CGI->generaltexth->allTexts[475], 72, 437, FONT_SMALL, 17, Colors::Jasmine, *bg); //Experience needed to reach next level + printAtMiddleWB(CGI->generaltexth->allTexts[476], 72, 505, FONT_SMALL, 17, Colors::Jasmine, *bg); //Total experience on the Altar new CGStatusBar(302, 576); - ok = new AdventureMapButton(CGI->generaltexth->zelp[568],boost::bind(&CGuiHandler::popIntTotally,&GH,this),516,520,"IOK6432.DEF",SDLK_RETURN); + ok = new CAdventureMapButton(CGI->generaltexth->zelp[568],boost::bind(&CGuiHandler::popIntTotally,&GH,this),516,520,"IOK6432.DEF",SDLK_RETURN); ok->assignedKeys.insert(SDLK_ESCAPE); - deal = new AdventureMapButton(CGI->generaltexth->zelp[585],boost::bind(&CAltarWindow::makeDeal,this),269,520,"ALTSACR.DEF"); + deal = new CAdventureMapButton(CGI->generaltexth->zelp[585],boost::bind(&CAltarWindow::makeDeal,this),269,520,"ALTSACR.DEF"); if(Hero->getAlignment() != ::EAlignment::EVIL && Mode == EMarketMode::CREATURE_EXP) - new AdventureMapButton(CGI->generaltexth->zelp[580], boost::bind(&CTradeWindow::setMode,this, EMarketMode::ARTIFACT_EXP), 516, 421, "ALTART.DEF"); + new CAdventureMapButton(CGI->generaltexth->zelp[580], boost::bind(&CTradeWindow::setMode,this, EMarketMode::ARTIFACT_EXP), 516, 421, "ALTART.DEF"); if(Hero->getAlignment() != ::EAlignment::GOOD && Mode == EMarketMode::ARTIFACT_EXP) - new AdventureMapButton(CGI->generaltexth->zelp[572], boost::bind(&CTradeWindow::setMode,this, EMarketMode::CREATURE_EXP), 516, 421, "ALTSACC.DEF"); + new CAdventureMapButton(CGI->generaltexth->zelp[572], boost::bind(&CTradeWindow::setMode,this, EMarketMode::CREATURE_EXP), 516, 421, "ALTSACC.DEF"); expPerUnit.resize(GameConstants::ARMY_SIZE, 0); getExpValues(); @@ -3855,7 +3351,7 @@ void CAltarWindow::selectionChanged(bool side) void CAltarWindow::mimicCres() { - std::vector positions; + std::vector positions; getPositionsFor(positions, false, CREATURE); BOOST_FOREACH(CTradeableItem *t, items[1]) @@ -3866,12 +3362,12 @@ void CAltarWindow::mimicCres() } } -SPoint CAltarWindow::selectionOffset(bool Left) const +Point CAltarWindow::selectionOffset(bool Left) const { if(Left) - return SPoint(150, 421); + return Point(150, 421); else - return SPoint(396, 421); + return Point(396, 421); } std::string CAltarWindow::selectionSubtitle(bool Left) const @@ -4003,7 +3499,7 @@ void CAltarWindow::showAll(SDL_Surface * to) int dmp, val; market->getOffer(arts->commonInfo->src.art->artType->id, 0, dmp, val, EMarketMode::ARTIFACT_EXP); - printAtMiddleLoc(boost::lexical_cast(val), 304, 498, FONT_SMALL, zwykly, to); + printAtMiddleLoc(boost::lexical_cast(val), 304, 498, FONT_SMALL, Colors::Cornsilk, to); } } @@ -4072,40 +3568,40 @@ CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &pos, CPlayerInterface SDL_FreeSurface(hhlp); //printing texts - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[568], 242, 32, FONT_BIG, tytulowy, background); //window title - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[569], 122, 64, FONT_MEDIUM, tytulowy, background); //hero speed - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[570], 122, 130, FONT_MEDIUM, tytulowy, background); //enemy speed - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[571], 122, 196, FONT_MEDIUM, tytulowy, background); //map scroll speed - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[20], 122, 262, FONT_MEDIUM, tytulowy, background); //video quality - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 347, FONT_MEDIUM, tytulowy, background); //music volume - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 412, FONT_MEDIUM, tytulowy, background); //effects volume + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[568], 242, 32, FONT_BIG, Colors::Jasmine, background); //window title + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[569], 122, 64, FONT_MEDIUM, Colors::Jasmine, background); //hero speed + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[570], 122, 130, FONT_MEDIUM, Colors::Jasmine, background); //enemy speed + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[571], 122, 196, FONT_MEDIUM, Colors::Jasmine, background); //map scroll speed + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[20], 122, 262, FONT_MEDIUM, Colors::Jasmine, background); //video quality + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 347, FONT_MEDIUM, Colors::Jasmine, background); //music volume + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 412, FONT_MEDIUM, Colors::Jasmine, background); //effects volume - CSDL_Ext::printAt(CGI->generaltexth->allTexts[572], 282, 57, FONT_MEDIUM, zwykly, background); //show move path - CSDL_Ext::printAt(CGI->generaltexth->allTexts[573], 282, 89, FONT_MEDIUM, zwykly, background); //show hero reminder - CSDL_Ext::printAt(CGI->generaltexth->allTexts[574], 282, 121, FONT_MEDIUM, zwykly, background); //quick combat - CSDL_Ext::printAt(CGI->generaltexth->allTexts[575], 282, 153, FONT_MEDIUM, zwykly, background); //video subtitles - CSDL_Ext::printAt(CGI->generaltexth->allTexts[576], 282, 185, FONT_MEDIUM, zwykly, background); //town building outlines - CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 282, 217, FONT_MEDIUM, zwykly, background); //spell book animation + CSDL_Ext::printAt(CGI->generaltexth->allTexts[572], 282, 57, FONT_MEDIUM, Colors::Cornsilk, background); //show move path + CSDL_Ext::printAt(CGI->generaltexth->allTexts[573], 282, 89, FONT_MEDIUM, Colors::Cornsilk, background); //show hero reminder + CSDL_Ext::printAt(CGI->generaltexth->allTexts[574], 282, 121, FONT_MEDIUM, Colors::Cornsilk, background); //quick combat + CSDL_Ext::printAt(CGI->generaltexth->allTexts[575], 282, 153, FONT_MEDIUM, Colors::Cornsilk, background); //video subtitles + CSDL_Ext::printAt(CGI->generaltexth->allTexts[576], 282, 185, FONT_MEDIUM, Colors::Cornsilk, background); //town building outlines + CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 282, 217, FONT_MEDIUM, Colors::Cornsilk, background); //spell book animation //setting up buttons - // load = new AdventureMapButton (CGI->generaltexth->zelp[321].first, CGI->generaltexth->zelp[321].second, boost::bind(&CSystemOptionsWindow::loadf, this), pos.x+246, pos.y+298, "SOLOAD.DEF", SDLK_l); + // load = new CAdventureMapButton (CGI->generaltexth->zelp[321].first, CGI->generaltexth->zelp[321].second, boost::bind(&CSystemOptionsWindow::loadf, this), pos.x+246, pos.y+298, "SOLOAD.DEF", SDLK_l); // std::swap(save->imgs[0][0], load->imgs[0][1]); - save = new AdventureMapButton (CGI->generaltexth->zelp[322].first, CGI->generaltexth->zelp[322].second, boost::bind(&CSystemOptionsWindow::bsavef, this), 357, 298, "SOSAVE.DEF", SDLK_s); + save = new CAdventureMapButton (CGI->generaltexth->zelp[322].first, CGI->generaltexth->zelp[322].second, boost::bind(&CSystemOptionsWindow::bsavef, this), 357, 298, "SOSAVE.DEF", SDLK_s); save->swappedImages = true; save->update(); - // restart = new AdventureMapButton (CGI->generaltexth->zelp[323].first, CGI->generaltexth->zelp[323].second, boost::bind(&CSystemOptionsWindow::bmainmenuf, this), pos.x+346, pos.y+357, "SORSTRT", SDLK_r); + // restart = new CAdventureMapButton (CGI->generaltexth->zelp[323].first, CGI->generaltexth->zelp[323].second, boost::bind(&CSystemOptionsWindow::bmainmenuf, this), pos.x+346, pos.y+357, "SORSTRT", SDLK_r); // std::swap(save->imgs[0][0], restart->imgs[0][1]); - mainMenu = new AdventureMapButton (CGI->generaltexth->zelp[320].first, CGI->generaltexth->zelp[320].second, boost::bind(&CSystemOptionsWindow::bmainmenuf, this), 357, 357, "SOMAIN.DEF", SDLK_m); + mainMenu = new CAdventureMapButton (CGI->generaltexth->zelp[320].first, CGI->generaltexth->zelp[320].second, boost::bind(&CSystemOptionsWindow::bmainmenuf, this), 357, 357, "SOMAIN.DEF", SDLK_m); mainMenu->swappedImages = true; mainMenu->update(); - quitGame = new AdventureMapButton (CGI->generaltexth->zelp[324].first, CGI->generaltexth->zelp[324].second, boost::bind(&CSystemOptionsWindow::bquitf, this), 246, 415, "soquit.def", SDLK_q); + quitGame = new CAdventureMapButton (CGI->generaltexth->zelp[324].first, CGI->generaltexth->zelp[324].second, boost::bind(&CSystemOptionsWindow::bquitf, this), 246, 415, "soquit.def", SDLK_q); quitGame->swappedImages = true; quitGame->update(); - backToMap = new AdventureMapButton (CGI->generaltexth->zelp[325].first, CGI->generaltexth->zelp[325].second, boost::bind(&CSystemOptionsWindow::breturnf, this), 357, 415, "soretrn.def", SDLK_RETURN); + backToMap = new CAdventureMapButton (CGI->generaltexth->zelp[325].first, CGI->generaltexth->zelp[325].second, boost::bind(&CSystemOptionsWindow::breturnf, this), 357, 415, "soretrn.def", SDLK_RETURN); backToMap->swappedImages = true; backToMap->update(); backToMap->assignedKeys.insert(SDLK_ESCAPE); @@ -4159,7 +3655,7 @@ void CSystemOptionsWindow::pushSDLEvent(int type, int usercode) void CSystemOptionsWindow::bquitf() { - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], std::vector(), boost::bind(&CSystemOptionsWindow::pushSDLEvent, this, SDL_QUIT, 0), 0, false); + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], std::vector(), boost::bind(&CSystemOptionsWindow::pushSDLEvent, this, SDL_QUIT, 0), 0, false); } void CSystemOptionsWindow::breturnf() @@ -4169,7 +3665,7 @@ void CSystemOptionsWindow::breturnf() void CSystemOptionsWindow::bmainmenuf() { - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], std::vector(), boost::bind(&CSystemOptionsWindow::pushSDLEvent, this, SDL_USEREVENT, 2), 0, false); + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], std::vector(), boost::bind(&CSystemOptionsWindow::pushSDLEvent, this, SDL_USEREVENT, 2), 0, false); } void CSystemOptionsWindow::bsavef() @@ -4182,10 +3678,10 @@ void CSystemOptionsWindow::bsavef() std::string fname = fnameStream.str(); boost::algorithm::replace_all(fname,":",""); boost::algorithm::replace_all(fname," ","-"); - LOCPLINT->showYesNoDialog("Do you want to save current game as " + fname, std::vector(), boost::bind(&CCallback::save, LOCPLINT->cb, fname), boost::bind(&CSystemOptionsWindow::activate, this), false);*/ + LOCPLINT->showYesNoDialog("Do you want to save current game as " + fname, std::vector(), boost::bind(&CCallback::save, LOCPLINT->cb, fname), boost::bind(&CSystemOptionsWindow::activate, this), false);*/ } -void CSystemOptionsWindow::showAll(SDL_Surface *to) +void CSystemOptionsWindow::showAll(SDL_Surface * to) { CSDL_Ext::blitSurface(background, NULL, to, &pos); @@ -4212,16 +3708,16 @@ CTavernWindow::CTavernWindow(const CGObjectInstance *TavernObj) pos = center(bg->pos); - printAtMiddle(CGI->generaltexth->jktexts[37],200,35,FONT_BIG,tytulowy,*bg); - printAtMiddle("2500",320,328,FONT_SMALL,zwykly,*bg); -// printAtMiddle(CGI->generaltexth->jktexts[38],146,283,FONT_BIG,tytulowy,bg); //what is this??? - printAtMiddleWB(LOCPLINT->cb->getTavernGossip(tavernObj), 200, 220, FONT_SMALL, 50, zwykly, *bg); + printAtMiddle(CGI->generaltexth->jktexts[37],200,35,FONT_BIG,Colors::Jasmine,*bg); + printAtMiddle("2500",320,328,FONT_SMALL,Colors::Cornsilk,*bg); +// printAtMiddle(CGI->generaltexth->jktexts[38],146,283,FONT_BIG,Colors::Jasmine,bg); //what is this??? + printAtMiddleWB(LOCPLINT->cb->getTavernGossip(tavernObj), 200, 220, FONT_SMALL, 50, Colors::Cornsilk, *bg); bar = new CGStatusBar(8, 478, "APHLFTRT.bmp", 380); - cancel = new AdventureMapButton(CGI->generaltexth->tavernInfo[7],"", boost::bind(&CTavernWindow::close, this), 310, 428, "ICANCEL.DEF", SDLK_ESCAPE); - recruit = new AdventureMapButton("", "", boost::bind(&CTavernWindow::recruitb, this), 272, 355, "TPTAV01.DEF", SDLK_RETURN); - thiefGuild = new AdventureMapButton(CGI->generaltexth->tavernInfo[5],"", boost::bind(&CTavernWindow::thievesguildb, this), 22, 428, "TPTAV02.DEF", SDLK_t); + cancel = new CAdventureMapButton(CGI->generaltexth->tavernInfo[7],"", boost::bind(&CTavernWindow::close, this), 310, 428, "ICANCEL.DEF", SDLK_ESCAPE); + recruit = new CAdventureMapButton("", "", boost::bind(&CTavernWindow::recruitb, this), 272, 355, "TPTAV01.DEF", SDLK_RETURN); + thiefGuild = new CAdventureMapButton(CGI->generaltexth->tavernInfo[5],"", boost::bind(&CTavernWindow::thievesguildb, this), 22, 428, "TPTAV02.DEF", SDLK_t); if(LOCPLINT->cb->getResourceAmount(6) < 2500) //not enough gold { @@ -4290,7 +3786,7 @@ void CTavernWindow::show(SDL_Surface * to) boost::algorithm::replace_first(recruit->hoverTexts[0],"%s",sel->h->type->heroClass->name); } - printAtMiddleWB(sel->descr,pos.x+146,pos.y+389,FONT_SMALL,40,zwykly,to); + printAtMiddleWB(sel->descr,pos.x+146,pos.y+389,FONT_SMALL,40,Colors::Cornsilk,to); CSDL_Ext::drawBorder(to,sel->pos.x-2,sel->pos.y-2,sel->pos.w+4,sel->pos.h+4,int3(247,223,123)); } } @@ -4370,7 +3866,7 @@ void CInGameConsole::show(SDL_Surface * to) for(std::list< std::pair< std::string, int > >::iterator it = texts.begin(); it != texts.end(); ++it, ++number) { SDL_Color green = {0,0xff,0,0}; - SPoint leftBottomCorner(0, screen->h); + Point leftBottomCorner(0, screen->h); if(LOCPLINT->battleInt) { leftBottomCorner = LOCPLINT->battleInt->pos.bottomLeft(); @@ -4579,13 +4075,13 @@ CGarrisonWindow::CGarrisonWindow( const CArmedInstance *up, const CGHeroInstance bg->colorizeAndConvert(LOCPLINT->playerID); pos = bg->center(); - garr = new CGarrisonInt(92, 127, 4, SPoint(0,96), bg->bg, SPoint(93,127), up, down, removableUnits); + garr = new CGarrisonInt(92, 127, 4, Point(0,96), bg->bg, Point(93,127), up, down, removableUnits); { - AdventureMapButton *split = new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),88,314,"IDV6432.DEF"); + CAdventureMapButton *split = new CAdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),88,314,"IDV6432.DEF"); removeChild(split); garr->addSplitBtn(split); } - quit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CGarrisonWindow::close,this),399,314,"IOK6432.DEF",SDLK_RETURN); + quit = new CAdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CGarrisonWindow::close,this),399,314,"IOK6432.DEF",SDLK_RETURN); std::string titleText; if (garr->armedObjs[1]->tempOwner == garr->armedObjs[0]->tempOwner) @@ -4595,7 +4091,7 @@ CGarrisonWindow::CGarrisonWindow( const CArmedInstance *up, const CGHeroInstance titleText = CGI->generaltexth->allTexts[35]; boost::algorithm::replace_first(titleText, "%s", garr->armedObjs[0]->Slots().begin()->second->type->namePl); } - title = new CLabel(275, 30, FONT_BIG, CENTER, tytulowy, titleText); + title = new CLabel(275, 30, FONT_BIG, CENTER, Colors::Jasmine, titleText); } CGarrisonWindow::~CGarrisonWindow() @@ -4625,42 +4121,12 @@ void CWindowWithGarrison::updateGarrisons() garr->recreateSlots(); } -void CRClickPopupInt::show(SDL_Surface * to) -{ - inner->show(to); -} - -CRClickPopupInt::CRClickPopupInt( IShowActivatable *our, bool deleteInt ) -{ - CCS->curh->hide(); - inner = our; - delInner = deleteInt; -} - -CRClickPopupInt::~CRClickPopupInt() -{ -// //workaround for hero window issue - if it's our interface, call dispose to properly reset it's state -// //TODO? it might be better to rewrite hero window so it will bee newed/deleted on opening / closing (not effort-worthy now, but on some day...?) -// if(LOCPLINT && inner == adventureInt->heroWindow) -// adventureInt->heroWindow->dispose(); - - if(delInner) - delete inner; - - CCS->curh->show(); -} - -void CRClickPopupInt::showAll(SDL_Surface * to) -{ - inner->showAll(to); -} - CArtPlace::CArtPlace(const CArtifactInstance* Art) :picked(false), marked(false), locked(false), ourArt(Art) { } -CArtPlace::CArtPlace(SPoint position, const CArtifactInstance * Art): +CArtPlace::CArtPlace(Point position, const CArtifactInstance * Art): picked(false), marked(false), locked(false), ourArt(Art) { pos += position; @@ -4722,7 +4188,7 @@ void CArtPlace::clickLeft(tribool down, bool previousState) { if(ourArt->artType->id == 3) //catapult cannot be highlighted { - std::vector catapult(1, new SComponent(SComponent::artifact, 3, 0)); + std::vector catapult(1, new CComponent(CComponent::artifact, 3, 0)); LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[312], catapult); //The Catapult must be equipped. return; } @@ -4903,7 +4369,7 @@ void CArtPlace::deactivate() } } -void CArtPlace::showAll(SDL_Surface *to) +void CArtPlace::showAll(SDL_Surface * to) { if (ourArt && !picked && ourArt == ourOwner->curHero->getArt(slotID, false)) //last condition is needed for disassembling -> artifact may be gone, but we don't know yet TODO: real, nice solution { @@ -4978,7 +4444,7 @@ void CArtPlace::setArtifact(const CArtifactInstance *art) text = text.replace(nameStart, nameEnd - nameStart + 1, CGI->spellh->spells[spellID]->name); //add spell component info (used to provide a pic in r-click popup) - baseType = SComponent::spell; + baseType = CComponent::spell; type = spellID; bonusValue = 0; } @@ -4991,75 +4457,24 @@ void CArtPlace::setArtifact(const CArtifactInstance *art) } } -void HoverableArea::hover (bool on) -{ - if (on) - GH.statusbar->print(hoverText); - else if (GH.statusbar->getCurrent()==hoverText) - GH.statusbar->clear(); -} - -HoverableArea::HoverableArea() -{ - used |= HOVER; -} - -HoverableArea::~HoverableArea() -{ -} - -void LRClickableAreaWText::clickLeft(tribool down, bool previousState) -{ - if(!down && previousState) - { - LOCPLINT->showInfoDialog(text); - } -} -void LRClickableAreaWText::clickRight(tribool down, bool previousState) -{ - adventureInt->handleRightClick(text, down); -} - -LRClickableAreaWText::LRClickableAreaWText() -{ - init(); -} - -LRClickableAreaWText::LRClickableAreaWText(const SRect &Pos, const std::string &HoverText /*= ""*/, const std::string &ClickText /*= ""*/) -{ - init(); - pos = Pos + pos; - hoverText = HoverText; - text = ClickText; -} - -LRClickableAreaWText::~LRClickableAreaWText() -{ -} - -void LRClickableAreaWText::init() -{ - used = LCLICK | RCLICK | HOVER; -} - void LRClickableAreaWTextComp::clickLeft(tribool down, bool previousState) { if((!down) && previousState) { - std::vector comp(1, createComponent()); + std::vector comp(1, createComponent()); LOCPLINT->showInfoDialog(text, comp); } } -LRClickableAreaWTextComp::LRClickableAreaWTextComp(const SRect &Pos, int BaseType) +LRClickableAreaWTextComp::LRClickableAreaWTextComp(const Rect &Pos, int BaseType) : LRClickableAreaWText(Pos), baseType(BaseType), bonusValue(-1) { } -SComponent * LRClickableAreaWTextComp::createComponent() const +CComponent * LRClickableAreaWTextComp::createComponent() const { if(baseType >= 0) - return new SComponent(SComponent::Etype(baseType), type, bonusValue); + return new CComponent(CComponent::Etype(baseType), type, bonusValue); else return NULL; } @@ -5068,7 +4483,7 @@ void LRClickableAreaWTextComp::clickRight(tribool down, bool previousState) { if(down) { - if(SComponent *comp = createComponent()) + if(CComponent *comp = createComponent()) { CRClickPopup::createAndPush(text, CInfoWindow::TCompsInfo(1, comp)); return; @@ -5130,7 +4545,7 @@ void LRClickableAreaOpenTown::clickRight(tribool down, bool previousState) } LRClickableAreaOpenTown::LRClickableAreaOpenTown() - : LRClickableAreaWTextComp(SRect(0,0,0,0), -1) + : LRClickableAreaWTextComp(Rect(0,0,0,0), -1) { } @@ -5357,7 +4772,7 @@ void CArtifactsOfHero::eraseSlotData (CArtPlace* artPlace, int slotID) } CArtifactsOfHero::CArtifactsOfHero(std::vector ArtWorn, std::vector Backpack, - AdventureMapButton *leftScroll, AdventureMapButton *rightScroll, bool createCommonPart): + CAdventureMapButton *leftScroll, CAdventureMapButton *rightScroll, bool createCommonPart): curHero(NULL), artWorn(ArtWorn), backpack(Backpack), @@ -5389,7 +4804,7 @@ CArtifactsOfHero::CArtifactsOfHero(std::vector ArtWorn, std::vector rightArtRoll->callback += boost::bind(&CArtifactsOfHero::scrollBackpack,this,+1); } -CArtifactsOfHero::CArtifactsOfHero(const SPoint& position, bool createCommonPart /*= false*/) +CArtifactsOfHero::CArtifactsOfHero(const Point& position, bool createCommonPart /*= false*/) : curHero(NULL), backpackPos(0), commonInfo(NULL), updateState(false), allowedAssembling(true), highlightModeCallback(0) { if(createCommonPart) @@ -5402,7 +4817,7 @@ CArtifactsOfHero::CArtifactsOfHero(const SPoint& position, bool createCommonPart pos += position; artWorn.resize(19); - std::vector slotPos; + std::vector slotPos; slotPos += genRect(44,44,509,30), genRect(44,44,567,240), genRect(44,44,509,80), genRect(44,44,383,68), genRect(44,44,564,183), genRect(44,44,509,130), genRect(44,44,431,68), genRect(44,44,610,183), genRect(44,44,515,295), @@ -5434,8 +4849,8 @@ CArtifactsOfHero::CArtifactsOfHero(const SPoint& position, bool createCommonPart backpack.push_back(add); } - leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CArtifactsOfHero::scrollBackpack,this,-1), 379, 364, "hsbtns3.def", SDLK_LEFT); - rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CArtifactsOfHero::scrollBackpack,this,+1), 632, 364, "hsbtns5.def", SDLK_RIGHT); + leftArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind(&CArtifactsOfHero::scrollBackpack,this,-1), 379, 364, "hsbtns3.def", SDLK_LEFT); + rightArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind(&CArtifactsOfHero::scrollBackpack,this,+1), 632, 364, "hsbtns5.def", SDLK_RIGHT); } CArtifactsOfHero::~CArtifactsOfHero() @@ -5671,9 +5086,9 @@ void CExchangeWindow::prepareBackground() //printing heroes' names and levels std::ostringstream os, os2; os<name<<", Level "<level<<" "<type->heroClass->name; - CSDL_Ext::printAtMiddle(os.str(), 147, 25, FONT_SMALL, zwykly, bg); + CSDL_Ext::printAtMiddle(os.str(), 147, 25, FONT_SMALL, Colors::Cornsilk, bg); os2<name<<", Level "<level<<" "<type->heroClass->name; - CSDL_Ext::printAtMiddle(os2.str(), 653, 25, FONT_SMALL, zwykly, bg); + CSDL_Ext::printAtMiddle(os2.str(), 653, 25, FONT_SMALL, Colors::Cornsilk, bg); //printing primary skills CDefHandler * skilldef = CDefHandler::giveDef("PSKIL32.DEF"); @@ -5693,7 +5108,7 @@ void CExchangeWindow::prepareBackground() { std::ostringstream primarySkill; primarySkill << heroWArt.getPrimSkillLevel(m); - CSDL_Ext::printAtMiddle(primarySkill.str(), 352 + 93 * b, 35 + 36 * m, FONT_SMALL, zwykly, bg); + CSDL_Ext::printAtMiddle(primarySkill.str(), 352 + 93 * b, 35 + 36 * m, FONT_SMALL, Colors::Cornsilk, bg); } //printing secondary skills @@ -5707,11 +5122,11 @@ void CExchangeWindow::prepareBackground() //experience blitAt(skilldef->ourImages[4].bitmap, 103 + 490*b, 45, bg); - printAtMiddle( makeNumberShort(heroInst[b]->exp), 119 + 490*b, 71, FONT_SMALL, zwykly, bg ); + printAtMiddle( makeNumberShort(heroInst[b]->exp), 119 + 490*b, 71, FONT_SMALL, Colors::Cornsilk, bg ); //mana points blitAt(skilldef->ourImages[5].bitmap, 139 + 490*b, 45, bg); - printAtMiddle( makeNumberShort(heroInst[b]->mana), 155 + 490*b, 71, FONT_SMALL, zwykly, bg ); + printAtMiddle( makeNumberShort(heroInst[b]->mana), 155 + 490*b, 71, FONT_SMALL, Colors::Cornsilk, bg ); //setting morale blitAt(graphics->morale30->ourImages[heroWArt.MoraleVal()+3].bitmap, 177 + 490*b, 45, bg); @@ -5742,11 +5157,11 @@ CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) : bg(NULL) pos.h = screen->h; - artifs[0] = new CArtifactsOfHero(SPoint(pos.x + -334, pos.y + 150)); + artifs[0] = new CArtifactsOfHero(Point(pos.x + -334, pos.y + 150)); artifs[0]->commonInfo = new CArtifactsOfHero::SCommonPart; artifs[0]->commonInfo->participants.insert(artifs[0]); artifs[0]->setHero(heroInst[0]); - artifs[1] = new CArtifactsOfHero(SPoint(pos.x + 96, pos.y + 150)); + artifs[1] = new CArtifactsOfHero(Point(pos.x + 96, pos.y + 150)); artifs[1]->commonInfo = artifs[0]->commonInfo; artifs[1]->commonInfo->participants.insert(artifs[1]); artifs[1]->setHero(heroInst[1]); @@ -5818,21 +5233,21 @@ CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) : bg(NULL) } //buttons - quit = new AdventureMapButton(CGI->generaltexth->tcommands[8], "", boost::bind(&CExchangeWindow::close, this), pos.x+732, pos.y+567, "IOKAY.DEF", SDLK_RETURN); - questlogButton[0] = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CExchangeWindow::questlog,this, 0), pos.x+10, pos.y+44, "hsbtns4.def"); - questlogButton[1] = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CExchangeWindow::questlog,this, 1), pos.x+740, pos.y+44, "hsbtns4.def"); + quit = new CAdventureMapButton(CGI->generaltexth->tcommands[8], "", boost::bind(&CExchangeWindow::close, this), pos.x+732, pos.y+567, "IOKAY.DEF", SDLK_RETURN); + questlogButton[0] = new CAdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CExchangeWindow::questlog,this, 0), pos.x+10, pos.y+44, "hsbtns4.def"); + questlogButton[1] = new CAdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CExchangeWindow::questlog,this, 1), pos.x+740, pos.y+44, "hsbtns4.def"); //statusbar //FIXME - this image is a bit bigger than required - part of background should be used instead ourBar = new CGStatusBar(pos.x + 3, pos.y + 577, "KSTATBAR"); //garrison interface - garr = new CGarrisonInt(pos.x + 69, pos.y + 131, 4, SPoint(418,0), bg, SPoint(69,131), heroInst[0],heroInst[1], true, true); + garr = new CGarrisonInt(pos.x + 69, pos.y + 131, 4, Point(418,0), bg, Point(69,131), heroInst[0],heroInst[1], true, true); { BLOCK_CAPTURING; - garr->addSplitBtn(new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+10,pos.y+132,"TSBTNS.DEF")); - garr->addSplitBtn(new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+740,pos.y+132,"TSBTNS.DEF")); + garr->addSplitBtn(new CAdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+10,pos.y+132,"TSBTNS.DEF")); + garr->addSplitBtn(new CAdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+740,pos.y+132,"TSBTNS.DEF")); } } @@ -5856,7 +5271,7 @@ CShipyardWindow::CShipyardWindow(const std::vector &cost, int state, int b std::string boatFilenames[3] = {"AB01_", "AB02_", "AB03_"}; - SPoint waterCenter = SPoint(bgWater->pos.x+bgWater->pos.w/2, bgWater->pos.y+bgWater->pos.h/2); + Point waterCenter = Point(bgWater->pos.x+bgWater->pos.w/2, bgWater->pos.y+bgWater->pos.h/2); bgShip = new CAnimImage(boatFilenames[boatType], 0, 7, 120, 96, CShowableAnim::USE_RLE); bgShip->center(waterCenter); @@ -5864,14 +5279,14 @@ CShipyardWindow::CShipyardWindow(const std::vector &cost, int state, int b std::string goldValue = boost::lexical_cast(cost[Res::GOLD]); std::string woodValue = boost::lexical_cast(cost[Res::WOOD]); - goldCost = new CLabel(118, 294, FONT_SMALL, CENTER, zwykly, goldValue); - woodCost = new CLabel(212, 294, FONT_SMALL, CENTER, zwykly, woodValue); + goldCost = new CLabel(118, 294, FONT_SMALL, CENTER, Colors::Cornsilk, goldValue); + woodCost = new CLabel(212, 294, FONT_SMALL, CENTER, Colors::Cornsilk, woodValue); goldPic = new CAnimImage("RESOURCE", Res::GOLD, 0, 100, 244); woodPic = new CAnimImage("RESOURCE", Res::WOOD, 0, 196, 244); - quit = new AdventureMapButton(CGI->generaltexth->allTexts[599], "", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 224, 312, "ICANCEL", SDLK_RETURN); - build = new AdventureMapButton(CGI->generaltexth->allTexts[598], "", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 42, 312, "IBUY30", SDLK_RETURN); + quit = new CAdventureMapButton(CGI->generaltexth->allTexts[599], "", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 224, 312, "ICANCEL", SDLK_RETURN); + build = new CAdventureMapButton(CGI->generaltexth->allTexts[598], "", boost::bind(&CGuiHandler::popIntTotally, &GH, this), 42, 312, "IBUY30", SDLK_RETURN); build->callback += onBuy; for(size_t i = 0; i < cost.size(); i++) @@ -5885,8 +5300,8 @@ CShipyardWindow::CShipyardWindow(const std::vector &cost, int state, int b statusBar = new CGStatusBar(bg->pos.w/2, bg->pos.h-16); - title = new CLabel(164, 27, FONT_BIG, CENTER, tytulowy, CGI->generaltexth->jktexts[13]); - costLabel = new CLabel(164, 220, FONT_MEDIUM, CENTER, zwykly, CGI->generaltexth->jktexts[14]); + title = new CLabel(164, 27, FONT_BIG, CENTER, Colors::Jasmine, CGI->generaltexth->jktexts[13]); + costLabel = new CLabel(164, 220, FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->jktexts[14]); } CPuzzleWindow::CPuzzleWindow(const int3 &grailPos, double discoveredRatio) @@ -5900,7 +5315,7 @@ CPuzzleWindow::CPuzzleWindow(const int3 &grailPos, double discoveredRatio) background = SDL_ConvertSurface(back, screen->format, back->flags); SDL_FreeSurface(back); pos = genRect(background->h, background->w, (conf.cc.resx - background->w) / 2, (conf.cc.resy - background->h) / 2); - quitb = new AdventureMapButton(CGI->generaltexth->allTexts[599], "", boost::bind(&CGuiHandler::popIntTotally, &GH, this), pos.x+670, pos.y+538, "IOK6432.DEF", SDLK_RETURN); + quitb = new CAdventureMapButton(CGI->generaltexth->allTexts[599], "", boost::bind(&CGuiHandler::popIntTotally, &GH, this), pos.x+670, pos.y+538, "IOK6432.DEF", SDLK_RETURN); quitb->assignedKeys.insert(SDLK_ESCAPE); quitb->borderColor = Colors::MetallicGold; quitb->borderEnabled = true; @@ -5910,7 +5325,7 @@ CPuzzleWindow::CPuzzleWindow(const int3 &grailPos, double discoveredRatio) //printing necessary things to background int3 moveInt = int3(8, 9, 0); - SRect mapRect = genRect(544, 591, 8, 8); + Rect mapRect = genRect(544, 591, 8, 8); CGI->mh->terrainRect (grailPos - moveInt, adventureInt->anim, &LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim, @@ -5998,7 +5413,7 @@ void CTransformerWindow::CItem::showAll(SDL_Surface * to) { SDL_Surface * backgr = graphics->bigImgs[parent->army->getCreature(id)->idNumber]; blitAt(backgr, pos.x, pos.y, to); - printAtMiddle(boost::lexical_cast(size),pos.x+28, pos.y+76,FONT_SMALL,zwykly,to);//stack size + printAtMiddle(boost::lexical_cast(size),pos.x+28, pos.y+76,FONT_SMALL,Colors::Cornsilk,to);//stack size } void CTransformerWindow::CItem::move() @@ -6039,10 +5454,10 @@ CTransformerWindow::CItem::~CItem() void CTransformerWindow::showAll(SDL_Surface * to) { CIntObject::showAll(to); - printAtMiddleLoc( CGI->generaltexth->allTexts[485], 153, 29,FONT_SMALL, tytulowy,to);//holding area - printAtMiddleLoc( CGI->generaltexth->allTexts[486], 153+295, 29,FONT_SMALL, tytulowy,to);//transformer - printAtMiddleWBLoc(CGI->generaltexth->allTexts[487], 153, 75,FONT_MEDIUM, 32,tytulowy,to);//move creatures to create skeletons - printAtMiddleWBLoc(CGI->generaltexth->allTexts[488], 153+295, 75,FONT_MEDIUM, 32,tytulowy,to);//creatures here will become skeletons + printAtMiddleLoc( CGI->generaltexth->allTexts[485], 153, 29,FONT_SMALL, Colors::Jasmine,to);//holding area + printAtMiddleLoc( CGI->generaltexth->allTexts[486], 153+295, 29,FONT_SMALL, Colors::Jasmine,to);//transformer + printAtMiddleWBLoc(CGI->generaltexth->allTexts[487], 153, 75,FONT_MEDIUM, 32,Colors::Jasmine,to);//move creatures to create skeletons + printAtMiddleWBLoc(CGI->generaltexth->allTexts[488], 153+295, 75,FONT_MEDIUM, 32,Colors::Jasmine,to);//creatures here will become skeletons } void CTransformerWindow::makeDeal() @@ -6076,9 +5491,9 @@ CTransformerWindow::CTransformerWindow(const CGHeroInstance * _hero, const CGTow if ( army->getCreature(i) ) items.push_back(new CItem(this, army->getStackCount(i), i)); - all = new AdventureMapButton(CGI->generaltexth->zelp[590],boost::bind(&CTransformerWindow::addAll,this), 146,416,"ALTARMY.DEF",SDLK_a); - convert= new AdventureMapButton(CGI->generaltexth->zelp[591],boost::bind(&CTransformerWindow::makeDeal,this), 269,416,"ALTSACR.DEF",SDLK_RETURN); - cancel = new AdventureMapButton(CGI->generaltexth->zelp[592],boost::bind(&CGuiHandler::popIntTotally,&GH, this),392,416,"ICANCEL.DEF",SDLK_ESCAPE); + all = new CAdventureMapButton(CGI->generaltexth->zelp[590],boost::bind(&CTransformerWindow::addAll,this), 146,416,"ALTARMY.DEF",SDLK_a); + convert= new CAdventureMapButton(CGI->generaltexth->zelp[591],boost::bind(&CTransformerWindow::makeDeal,this), 269,416,"ALTSACR.DEF",SDLK_RETURN); + cancel = new CAdventureMapButton(CGI->generaltexth->zelp[592],boost::bind(&CGuiHandler::popIntTotally,&GH, this),392,416,"ICANCEL.DEF",SDLK_ESCAPE); bar = new CGStatusBar(304, 469); } @@ -6154,8 +5569,8 @@ void CUniversityWindow::CItem::showAll(SDL_Surface * to) blitAtLoc(bar->bg, -28, -22, to); blitAtLoc(bar->bg, -28, 48, to); - printAtMiddleLoc (CGI->generaltexth->skillName[ID], 22, -13, FONT_SMALL, zwykly,to);//Name - printAtMiddleLoc (CGI->generaltexth->levels[0], 22, 57, FONT_SMALL, zwykly,to);//Level(always basic) + printAtMiddleLoc (CGI->generaltexth->skillName[ID], 22, -13, FONT_SMALL, Colors::Cornsilk,to);//Name + printAtMiddleLoc (CGI->generaltexth->levels[0], 22, 57, FONT_SMALL, Colors::Cornsilk,to);//Level(always basic) CPicture::showAll(to); } @@ -6194,8 +5609,8 @@ CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket else tlog0<<"Error: Image for university was not found!\n";//This should not happen - printAtMiddleWBLoc(CGI->generaltexth->allTexts[603], 232, 153, FONT_SMALL, 70,zwykly,bg->bg);//Clerk speech - printAtMiddleLoc (CGI->generaltexth->allTexts[602], 231, 26 , FONT_MEDIUM ,tytulowy,bg->bg);//University + printAtMiddleWBLoc(CGI->generaltexth->allTexts[603], 232, 153, FONT_SMALL, 70,Colors::Cornsilk,bg->bg);//Clerk speech + printAtMiddleLoc (CGI->generaltexth->allTexts[602], 231, 26 , FONT_MEDIUM ,Colors::Jasmine,bg->bg);//University std::vector list = market->availableItemsIds(EMarketMode::RESOURCE_SKILL); if (list.size()!=4) @@ -6204,7 +5619,7 @@ CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket items.push_back(new CItem(this, list[i], pos.x+54+i*104, pos.y+234)); pos = center(bg->pos); - cancel = new AdventureMapButton(CGI->generaltexth->zelp[632], + cancel = new CAdventureMapButton(CGI->generaltexth->zelp[632], boost::bind(&CGuiHandler::popIntTotally,&GH, this),200,313,"IOKAY.DEF",SDLK_RETURN); bar = new CGStatusBar(232, 371); @@ -6226,10 +5641,10 @@ CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bo boost::replace_first(text, "%s", CGI->generaltexth->skillName[SKILL]); boost::replace_first(text, "%d", "2000"); - printAtMiddleWBLoc(text, 230, 163, FONT_SMALL, 65,zwykly,bg->bg);//Clerk speech - printAtMiddleLoc (CGI->generaltexth-> skillName[SKILL], 230, 37, FONT_SMALL, zwykly,bg->bg);//Skill name - printAtMiddleLoc (CGI->generaltexth->levels[1], 230, 107, FONT_SMALL, zwykly,bg->bg);//Skill level - printAtMiddleLoc ("2000", 230, 267, FONT_SMALL, zwykly,bg->bg);//Cost + printAtMiddleWBLoc(text, 230, 163, FONT_SMALL, 65,Colors::Cornsilk,bg->bg);//Clerk speech + printAtMiddleLoc (CGI->generaltexth-> skillName[SKILL], 230, 37, FONT_SMALL, Colors::Cornsilk,bg->bg);//Skill name + printAtMiddleLoc (CGI->generaltexth->levels[1], 230, 107, FONT_SMALL, Colors::Cornsilk,bg->bg);//Skill level + printAtMiddleLoc ("2000", 230, 267, FONT_SMALL, Colors::Cornsilk,bg->bg);//Cost blitAtLoc(graphics->abils44->ourImages[SKILL*3+3].bitmap, 211, 51, bg->bg);//skill blitAtLoc(graphics->resources32->ourImages[6].bitmap, 210, 210, bg->bg);//gold @@ -6243,11 +5658,11 @@ CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bo boost::replace_first(text, "%s", CGI->generaltexth->skillName[SKILL]); boost::replace_first(text, "%d", "2000"); - confirm= new AdventureMapButton(hoverText, text, boost::bind(&CUnivConfirmWindow::makeDeal, this, SKILL), + confirm= new CAdventureMapButton(hoverText, text, boost::bind(&CUnivConfirmWindow::makeDeal, this, SKILL), 148,299,"IBY6432.DEF",SDLK_RETURN); confirm->block(!available); - cancel = new AdventureMapButton(CGI->generaltexth->zelp[631],boost::bind(&CGuiHandler::popIntTotally, &GH, this), + cancel = new CAdventureMapButton(CGI->generaltexth->zelp[631],boost::bind(&CGuiHandler::popIntTotally, &GH, this), 252,299,"ICANCEL.DEF",SDLK_ESCAPE); bar = new CGStatusBar(232, 371); } @@ -6268,7 +5683,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectIn bg = new CPicture("APHLFTBK.PCX"); bg->colorizeAndConvert(LOCPLINT->playerID); - printAtMiddleLoc (fort->hoverName, 325, 32, FONT_BIG, tytulowy, bg->bg);//Hill Fort + printAtMiddleLoc (fort->hoverName, 325, 32, FONT_BIG, Colors::Jasmine, bg->bg);//Hill Fort pos = center(bg->pos); heroPic = new CHeroArea(30, 60, hero); @@ -6281,19 +5696,19 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectIn for (int i=0; iblock(currState[i] == -1); } files.clear(); files += "APHLF4R.DEF", "APHLF4Y.DEF", "APHLF4G.DEF"; currState[slotsCount] = getState(slotsCount); - upgradeAll = new AdventureMapButton(CGI->generaltexth->allTexts[432],"",boost::bind(&CHillFortWindow::makeDeal, this, slotsCount), + upgradeAll = new CAdventureMapButton(CGI->generaltexth->allTexts[432],"",boost::bind(&CHillFortWindow::makeDeal, this, slotsCount), 30, 231, "", SDLK_0, &files); - quit = new AdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 294, 275, "IOKAY.DEF", SDLK_RETURN); + quit = new CAdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 294, 275, "IOKAY.DEF", SDLK_RETURN); bar = new CGStatusBar(327, 332); - garr = new CGarrisonInt(108, 60, 18, SPoint(),bg->bg,SPoint(108,60),hero,NULL); + garr = new CGarrisonInt(108, 60, 18, Point(),bg->bg,Point(108,60),hero,NULL); updateGarrisons(); } @@ -6348,11 +5763,11 @@ void CHillFortWindow::makeDeal(int slot) { case 0: LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[314 + offset], - std::vector(), soundBase::sound_todo); + std::vector(), soundBase::sound_todo); break; case 1: LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[313 + offset], - std::vector(), soundBase::sound_todo); + std::vector(), soundBase::sound_todo); break; case 2: for (int i=0; iourImages[j].bitmap, 104+76*i, curY, to); - printToLoc(boost::lexical_cast(val), 168+76*i, curY+16, FONT_SMALL, zwykly, to); + printToLoc(boost::lexical_cast(val), 168+76*i, curY+16, FONT_SMALL, Colors::Cornsilk, to); curY += 20; } } else//free upgrade - print gold image and "Free" text { blitAtLoc(resources->ourImages[6].bitmap, 104+76*i, 128, to); - printToLoc(CGI->generaltexth->allTexts[344], 168+76*i, 144, FONT_SMALL, zwykly, to); + printToLoc(CGI->generaltexth->allTexts[344], 168+76*i, 144, FONT_SMALL, Colors::Cornsilk, to); } } } @@ -6400,7 +5815,7 @@ void CHillFortWindow::showAll (SDL_Surface *to) if (totalSumm[i])//this resource is used - display it { blitAtLoc(resources->ourImages[i].bitmap, 104+76*i, 237, to); - printToLoc(boost::lexical_cast(totalSumm[i]), 166+76*i, 253, FONT_SMALL, zwykly, to); + printToLoc(boost::lexical_cast(totalSumm[i]), 166+76*i, 253, FONT_SMALL, Colors::Cornsilk, to); } } } @@ -6486,7 +5901,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner) SThievesGuildInfo tgi; //info to be displayed LOCPLINT->cb->getThievesGuildInfo(tgi, owner); - pos = center(SRect(0,0,800,600));// SRect( (conf.cc.resx - 800) / 2, (conf.cc.resy - 600) / 2, 800, 600 ); + pos = center(Rect(0,0,800,600));// Rect( (conf.cc.resx - 800) / 2, (conf.cc.resy - 600) / 2, 800, 600 ); //loading backround and converting to more bpp form SDL_Surface * bg = background = BitmapHandler::loadBitmap("TpRank.bmp", false); @@ -6495,7 +5910,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner) blitAt(bg, 0, 0, background); SDL_FreeSurface(bg); - exitb = new AdventureMapButton (std::string(), std::string(), boost::bind(&CThievesGuildWindow::bexitf,this), 748, 556, "TPMAGE1.def", SDLK_RETURN); + exitb = new CAdventureMapButton (std::string(), std::string(), boost::bind(&CThievesGuildWindow::bexitf,this), 748, 556, "TPMAGE1.def", SDLK_RETURN); statusBar = new CGStatusBar(3, 555, "TStatBar.bmp", 742); resdatabar = new CMinorResDataBar(); @@ -6529,7 +5944,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner) } std::string text = CGI->generaltexth->jktexts[24+g]; boost::algorithm::trim_if(text,boost::algorithm::is_any_of("\"")); - printAtMiddle(text, 135, y, FONT_MEDIUM, tytulowy, background); + printAtMiddle(text, 135, y, FONT_MEDIUM, Colors::Jasmine, background); } CDefHandler * strips = CDefHandler::giveDef("PRSTRIPS.DEF"); @@ -6542,7 +5957,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner) { blitAt(strips->ourImages[g-1].bitmap, 250 + 66*g, 7, background); } - printAtMiddle(CGI->generaltexth->jktexts[16+g], 283 + 66*g, 24, FONT_BIG, tytulowy, background); + printAtMiddle(CGI->generaltexth->jktexts[16+g], 283 + 66*g, 24, FONT_BIG, Colors::Jasmine, background); SDL_Surface * box = BitmapHandler::loadBitmap(colorToBox[tgi.playerColors[g]]); blitAt(box, 253 + 66*g, 334, background); SDL_FreeSurface(box); @@ -6585,12 +6000,12 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner) //printing stats if(it->second.details) { - printAtWB(CGI->generaltexth->allTexts[184], 191 + 66*counter, 396, FONT_TINY, 10, zwykly, background); + printAtWB(CGI->generaltexth->allTexts[184], 191 + 66*counter, 396, FONT_TINY, 10, Colors::Cornsilk, background); for (int i=0; isecond.details->primskills.size(); ++i) { std::ostringstream skill; skill << it->second.details->primskills[i]; - printTo(skill.str(), 244 + 66 * counter, 407 + 11*i, FONT_TINY, zwykly, background); + printTo(skill.str(), 244 + 66 * counter, 407 + 11*i, FONT_TINY, Colors::Cornsilk, background); } } @@ -6619,7 +6034,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner) toPrint = 168 + it->second; } - printAtMiddle(CGI->generaltexth->arraytxt[toPrint], 283 + 66*counter, 459, FONT_SMALL, zwykly, background); + printAtMiddle(CGI->generaltexth->arraytxt[toPrint], 283 + 66*counter, 459, FONT_SMALL, Colors::Cornsilk, background); counter++; } @@ -6639,7 +6054,7 @@ void MoraleLuckBox::set(const IBonusBearer *node) const int textId[] = {62, 88}; //eg %s \n\n\n {Current Luck Modifiers:} const int noneTxtId = 108; //Russian version uses same text for neutral morale\luck const int neutralDescr[] = {60, 86}; //eg {Neutral Morale} \n\n Neutral morale means your armies will neither be blessed with extra attacks or freeze in combat. - const int componentType[] = {SComponent::luck, SComponent::morale}; + const int componentType[] = {CComponent::luck, CComponent::morale}; const int hoverTextBase[] = {7, 4}; const Bonus::BonusType bonusType[] = {Bonus::LUCK, Bonus::MORALE}; int (IBonusBearer::*getValue[])() const = {&IBonusBearer::LuckVal, &IBonusBearer::MoraleVal}; @@ -6686,10 +6101,10 @@ void MoraleLuckBox::showAll(SDL_Surface * to) def = morale ? graphics->morale42 : graphics->luck42; SDL_Surface *img = def->ourImages[bonusValue + 3].bitmap; - blitAt(img, SRect(img).centerIn(pos), to); //put img in the center of our pos + blitAt(img, Rect(img).centerIn(pos), to); //put img in the center of our pos } -MoraleLuckBox::MoraleLuckBox(bool Morale, const SRect &r, bool Small) +MoraleLuckBox::MoraleLuckBox(bool Morale, const Rect &r, bool Small) :morale(Morale), small(Small) { @@ -6702,343 +6117,6 @@ MoraleLuckBox::~MoraleLuckBox() } -void CLabel::showAll(SDL_Surface * to) -{ - CIntObject::showAll(to); - std::string *hlpText = NULL; //if NULL, text field will be used - if(ignoreLeadingWhitespace) - { - hlpText = new std::string(text); - boost::trim_left(*hlpText); - } - - std::string &toPrint = hlpText ? *hlpText : text; - if(!toPrint.length()) - return; - - static void (*printer[3])(const std::string &, int, int, EFonts, SDL_Color, SDL_Surface *) = {&CSDL_Ext::printAt, &CSDL_Ext::printAtMiddle, &CSDL_Ext::printTo}; //array of printing functions - printer[alignment](toPrint, pos.x + textOffset.x, pos.y + textOffset.y, font, color, to); -} - -CLabel::CLabel(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment Align, const SDL_Color &Color /*= zwykly*/, const std::string &Text /*= ""*/) -:alignment(Align), font(Font), color(Color), text(Text) -{ - autoRedraw = true; - pos.x += x; - pos.y += y; - pos.w = pos.h = 0; - bg = NULL; - ignoreLeadingWhitespace = false; -} - -void CLabel::setTxt(const std::string &Txt) -{ - text = Txt; - if(autoRedraw) - { - if(bg || !parent) - redraw(); - else - parent->redraw(); - } -} - -CTextBox::CTextBox(std::string Text, const SRect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= zwykly*/) - :CLabel(rect.x, rect.y, Font, Align, Color, Text), sliderStyle(SliderStyle), slider(NULL) -{ - redrawParentOnScrolling = false; - autoRedraw = false; - pos.h = rect.h; - pos.w = rect.w; - assert(Align == TOPLEFT || Align == CENTER); //TODO: support for other alignments - assert(pos.w >= 80); //we need some space - setTxt(Text); -} - -void CTextBox::showAll(SDL_Surface * to) -{ - CIntObject::showAll(to); - - const Font &f = *graphics->fonts[font]; - int dy = f.height; //line height - int base_y = pos.y; - if(alignment == CENTER) - base_y += std::max((pos.h - maxH)/2,0); - - int howManyLinesToPrint = slider ? slider->capacity : lines.size(); - int firstLineToPrint = slider ? slider->value : 0; - - for (int i = 0; i < howManyLinesToPrint; i++) - { - const std::string &line = lines[i + firstLineToPrint]; - if(!line.size()) continue; - - int x = pos.x; - if(alignment == CENTER) - { - x += (pos.w - f.getWidth(line.c_str())) / 2; - if(slider) - x -= slider->pos.w / 2 + 5; - } - - if(line[0] == '{' && line[line.size()-1] == '}') - printAt(line, x, base_y + i*dy, font, tytulowy, to); - else - printAt(line, x, base_y + i*dy, font, color, to); - } - -} - -void CTextBox::setTxt(const std::string &Txt) -{ - recalculateLines(Txt); - CLabel::setTxt(Txt); -} - -void CTextBox::sliderMoved(int to) -{ - if(!slider) - return; - - if(redrawParentOnScrolling) - parent->redraw(); - redraw(); -} - -void CTextBox::setBounds(int limitW, int limitH) -{ - pos.h = limitH; - pos.w = limitW; - recalculateLines(text); -} - -void CTextBox::recalculateLines(const std::string &Txt) -{ - delChildNUll(slider, true); - lines.clear(); - - const Font &f = *graphics->fonts[font]; - int lineHeight = f.height; - int lineCapacity = pos.h / lineHeight; - - lines = CMessage::breakText(Txt, pos.w, font); - if(lines.size() > lineCapacity) //we need to add a slider - { - lines = CMessage::breakText(Txt, pos.w - 32 - 10, font); - OBJ_CONSTRUCTION_CAPTURING_ALL; - slider = new CSlider(pos.w - 32, 0, pos.h, boost::bind(&CTextBox::sliderMoved, this, _1), lineCapacity, lines.size(), 0, false, sliderStyle); - if(active) - slider->activate(); - } - - maxH = lineHeight * lines.size(); - maxW = 0; - BOOST_FOREACH(const std::string &line, lines) - vstd::amax(maxW, f.getWidth(line.c_str())); -} - -void CGStatusBar::print(const std::string & Text) -{ - setTxt(Text); -} - -void CGStatusBar::clear() -{ - setTxt(""); -} - -std::string CGStatusBar::getCurrent() -{ - return text; -} - -CGStatusBar::CGStatusBar(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment Align, const SDL_Color &Color /*= zwykly*/, const std::string &Text /*= ""*/) - : CLabel(x, y, Font, Align, Color, Text) -{ - init(); -} - -CGStatusBar::CGStatusBar(CPicture *BG, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= CENTER*/, const SDL_Color &Color /*= zwykly*/) - : CLabel(BG->pos.x, BG->pos.y, Font, Align, Color, "") -{ - init(); - bg = BG; - CGuiHandler::moveChild(bg, bg->parent, this); - pos = bg->pos; - calcOffset(); -} - -CGStatusBar::CGStatusBar(int x, int y, std::string name/*="ADROLLVR.bmp"*/, int maxw/*=-1*/) - : CLabel(x, y, FONT_SMALL, CENTER) -{ - OBJ_CONSTRUCTION_CAPTURING_ALL; - init(); - bg = new CPicture(name); - pos = bg->pos; - if(maxw < pos.w) - { - vstd::amin(pos.w, maxw); - bg->srcRect = new SRect(0, 0, maxw, pos.h); - } - calcOffset(); -} - -CGStatusBar::~CGStatusBar() -{ - GH.statusbar = oldStatusBar; -} - -void CGStatusBar::show(SDL_Surface * to) -{ - -} - -void CGStatusBar::init() -{ - oldStatusBar = GH.statusbar; - GH.statusbar = this; -} - -void CGStatusBar::calcOffset() -{ - switch(alignment) - { - case CENTER: - textOffset = SPoint(pos.w/2, pos.h/2); - break; - case BOTTOMRIGHT: - textOffset = SPoint(pos.w, pos.h); - break; - } -} - -CTextInput::CTextInput( const SRect &Pos, const SPoint &bgOffset, const std::string &bgName, const CFunctionList &CB ) -:cb(CB) -{ - focus = false; - pos += Pos; - captureAllKeys = true; - OBJ_CONSTRUCTION; - bg = new CPicture(bgName, bgOffset.x, bgOffset.y); - used = LCLICK | KEYBOARD; - giveFocus(); -} - -CTextInput::CTextInput(const SRect &Pos, SDL_Surface *srf) -{ - focus = false; - pos += Pos; - captureAllKeys = true; - OBJ_CONSTRUCTION; - bg = new CPicture(Pos, 0, true); - SRect hlp = Pos; - if(srf) - CSDL_Ext::blitSurface(srf, &hlp, *bg, NULL); - else - SDL_FillRect(*bg, NULL, 0); - pos.w = bg->pos.w; - pos.h = bg->pos.h; - bg->pos = pos; - used = LCLICK | KEYBOARD; - giveFocus(); -} - -void CTextInput::showAll( SDL_Surface * to ) -{ - CIntObject::showAll(to); - const std::string toPrint = focus ? text + "_" : text; - CSDL_Ext::printAt(toPrint, pos.x, pos.y, FONT_SMALL, zwykly, to); -} - -void CTextInput::clickLeft( tribool down, bool previousState ) -{ - if(down && !focus) - giveFocus(); -} - -void CTextInput::keyPressed( const SDL_KeyboardEvent & key ) -{ - if(!focus || key.state != SDL_PRESSED) - return; - - if(key.keysym.sym == SDLK_TAB) - { - moveFocus(); - GH.breakEventHandling(); - return; - } - - switch(key.keysym.sym) - { - case SDLK_BACKSPACE: - if(text.size()) - text.resize(text.size()-1); - break; - default: - char c = key.keysym.unicode; //TODO 16-/>8 - static const std::string forbiddenChars = "<>:\"/\\|?*"; //if we are entering a filename, some special characters won't be allowed - if(!vstd::contains(forbiddenChars,c) && std::isprint(c)) - text += c; - break; - } - redraw(); - cb(text); -} - -void CTextInput::setText( const std::string &nText, bool callCb ) -{ - text = nText; - redraw(); - if(callCb) - cb(text); -} - -CTextInput::~CTextInput() -{ -} - -CFocusable::CFocusable() -{ - focusables.push_back(this); -} - -CFocusable::~CFocusable() -{ - if(inputWithFocus == this) - inputWithFocus = NULL; - - focusables -= this; -} -void CFocusable::giveFocus() -{ - if(inputWithFocus) - { - inputWithFocus->focus = false; - inputWithFocus->redraw(); - } - - focus = true; - inputWithFocus = this; - redraw(); -} - -void CFocusable::moveFocus() -{ - std::list::iterator i = vstd::find(focusables, this), - ourIt = i; - for(i++; i != ourIt; i++) - { - if(i == focusables.end()) - i = focusables.begin(); - - if((*i)->active) - { - (*i)->giveFocus(); - break;; - } - } -} - CArtifactHolder::CArtifactHolder() { type |= WITH_ARTIFACTS; @@ -7107,26 +6185,82 @@ bool CArtifactsOfHero::SCommonPart::Artpos::valid() return art == AOH->curHero->getArt(slotID); } -CIntObject * createCreWindow(const CStack *s) +void CRClickPopup::clickRight(tribool down, bool previousState) { - if(conf.cc.classicCreatureWindow) - return new CCreInfoWindow(*s); - else - return new CCreatureWindow(*s, CCreatureWindow::BATTLE); + if(down) + return; + close(); } -CIntObject * createCreWindow(int Cid, int Type, int creatureCount) +void CRClickPopup::activate() { - if(conf.cc.classicCreatureWindow) - return new CCreInfoWindow(Cid, Type, creatureCount); - else - return new CCreatureWindow(Cid, Type, creatureCount); + activateRClick(); } -CIntObject * createCreWindow(const CStackInstance *s, int type, boost::function Upg, boost::function Dsm, UpgradeInfo *ui) +void CRClickPopup::deactivate() { - if(conf.cc.classicCreatureWindow) - return new CCreInfoWindow(*s, type==3, Upg, Dsm, ui); - else - return new CCreatureWindow(*s, type, Upg, Dsm, ui); + deactivateRClick(); +} + +void CRClickPopup::close() +{ + GH.popIntTotally(this); +} + +void CRClickPopup::createAndPush(const std::string &txt, const CInfoWindow::TCompsInfo &comps) +{ + int player = LOCPLINT ? LOCPLINT->playerID : 1; //if no player, then use blue + + CSimpleWindow * temp = new CInfoWindow(txt, player, comps); + temp->center(Point(GH.current->motion)); //center on mouse + temp->fitToScreen(10); + CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true); + GH.pushInt(rcpi); +} + +void CRClickPopup::createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment /*= BOTTOMRIGHT*/) +{ + SDL_Surface *iWin = LOCPLINT->infoWin(obj); //try get custom infowindow for this obj + if(iWin) + GH.pushInt(new CInfoPopup(iWin, p, alignment, true)); + else + CRClickPopup::createAndPush(obj->getHoverText()); +} + +CRClickPopup::CRClickPopup() +{ +} + +CRClickPopup::~CRClickPopup() +{ +} + +void CRClickPopupInt::show(SDL_Surface * to) +{ + inner->show(to); +} + +CRClickPopupInt::CRClickPopupInt( IShowActivatable *our, bool deleteInt ) +{ + CCS->curh->hide(); + inner = our; + delInner = deleteInt; +} + +CRClickPopupInt::~CRClickPopupInt() +{ + // //workaround for hero window issue - if it's our interface, call dispose to properly reset it's state + // //TODO? it might be better to rewrite hero window so it will bee newed/deleted on opening / closing (not effort-worthy now, but on some day...?) + // if(LOCPLINT && inner == adventureInt->heroWindow) + // adventureInt->heroWindow->dispose(); + + if(delInner) + delete inner; + + CCS->curh->show(); +} + +void CRClickPopupInt::showAll(SDL_Surface * to) +{ + inner->showAll(to); } diff --git a/client/GUIClasses.h b/client/GUIClasses.h index d7c435adf..df2a651ba 100644 --- a/client/GUIClasses.h +++ b/client/GUIClasses.h @@ -4,10 +4,8 @@ #include "FunctionList.h" #include "../lib/ResourceSet.h" #include "../lib/GameConstants.h" -#include "UIFramework/CSimpleWindow.h" -#include "UIFramework/IStatusBar.h" -#include "UIFramework/CPicture.h" -#include "UIFramework/CKeyShortcut.h" +#include "UIFramework/CIntObject.h" +#include "UIFramework/CIntObjectClasses.h" #ifdef max #undef max @@ -31,7 +29,7 @@ class CStackBasicDescriptor; class CBonusSystemNode; class CArtifact; class CDefEssential; -class AdventureMapButton; +class CAdventureMapButton; class CHighlightableButtonsGroup; class CDefHandler; struct HeroMoveDetails; @@ -41,7 +39,7 @@ class CAdvMapInt; class CCastleInterface; class CBattleInterface; class CStack; -class SComponent; +class CComponent; class CCreature; struct SDL_Surface; struct CPath; @@ -75,8 +73,6 @@ class IBonusBearer; class CArtPlace; class CAnimImage; -extern SDL_Color tytulowy, tlo, zwykly ; - /// text + comp. + ok button class CInfoWindow : public CSimpleWindow { //window able to delete its components when closed @@ -84,11 +80,11 @@ class CInfoWindow : public CSimpleWindow public: typedef std::vector > > TButtonsInfo; - typedef std::vector TCompsInfo; + typedef std::vector TCompsInfo; int ID; //for identification CTextBox *text; - std::vector buttons; - std::vector components; + std::vector buttons; + std::vector components; CSlider *slider; void setDelComps(bool DelComps); @@ -102,8 +98,8 @@ public: CInfoWindow(); //c-tor ~CInfoWindow(); //d-tor - static void showYesNoDialog( const std::string & text, const std::vector *components, const CFunctionList &onYes, const CFunctionList &onNo, bool DelComps = true, int player = 1); //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then) - static CInfoWindow *create(const std::string &text, int playerID = 1, const std::vector *components = NULL, bool DelComps = false); + static void showYesNoDialog( const std::string & text, const std::vector *components, const CFunctionList &onYes, const CFunctionList &onNo, bool DelComps = true, int player = 1); //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then) + static CInfoWindow *create(const std::string &text, int playerID = 1, const std::vector *components = NULL, bool DelComps = false); }; /// component selection window @@ -130,7 +126,7 @@ public: virtual ~CRClickPopup(); //d-tor static void createAndPush(const std::string &txt, const CInfoWindow::TCompsInfo &comps = CInfoWindow::TCompsInfo()); - static void createAndPush(const CGObjectInstance *obj, const SPoint &p, EAlignment alignment = BOTTOMRIGHT); + static void createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment = BOTTOMRIGHT); }; /// popup displayed on R-click @@ -154,7 +150,7 @@ public: void close(); void show(SDL_Surface * to); CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor - CInfoPopup(SDL_Surface * Bitmap, const SPoint &p, EAlignment alignment, bool Free=false); //c-tor + CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false); //c-tor CInfoPopup(SDL_Surface *Bitmap = NULL, bool Free = false); //default c-tor void init(int x, int y); @@ -162,7 +158,7 @@ public: }; /// common popup window component -class SComponent : public virtual CIntObject +class CComponent : public virtual CIntObject { public: enum Etype @@ -181,10 +177,10 @@ public: SDL_Surface * setSurface(std::string defName, int imgPos); void init(Etype Type, int Subtype, int Val); - SComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur=NULL, bool freeSur=false); //c-tor - SComponent(const Component &c); //c-tor - SComponent();; //c-tor - virtual ~SComponent(); //d-tor + CComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur=NULL, bool freeSur=false); //c-tor + CComponent(const Component &c); //c-tor + CComponent();; //c-tor + virtual ~CComponent(); //d-tor void clickRight(tribool down, bool previousState); //call-in SDL_Surface * getImg(); @@ -193,7 +189,7 @@ public: virtual void deactivate(); }; -class CSelectableComponent : public SComponent, public CKeyShortcut +class CSelectableComponent : public CComponent, public CKeyShortcut { public: bool selected; //if true, this component is selected @@ -212,83 +208,6 @@ public: //////////////////////////////////////////////////////////////////////////////// -/// Used as base for Tabs and List classes -class CObjectList : public CIntObject -{ -public: - typedef boost::function CreateFunc; - typedef boost::function DestroyFunc; - -private: - CreateFunc createObject; - DestroyFunc destroyObject; - -protected: - //Internal methods for safe creation of items (Children capturing and activation/deactivation if needed) - void deleteItem(CIntObject* item); - CIntObject* createItem(size_t index); - - CObjectList(CreateFunc create, DestroyFunc destroy = DestroyFunc());//Protected constructor -}; - -/// Window element with multiple tabs -class CTabbedInt : public CObjectList -{ -private: - CIntObject * activeTab; - size_t activeID; - -public: - //CreateFunc, DestroyFunc - see CObjectList - //Pos - position of object, all tabs will be moved to this position - //ActiveID - ID of initially active tab - CTabbedInt(CreateFunc create, DestroyFunc destroy = DestroyFunc(), SPoint position=SPoint(), size_t ActiveID=0); - - void setActive(size_t which); - //recreate active tab - void reset(); - - //return currently active item - CIntObject * getItem(); -}; - -/// List of IntObjects with optional slider -class CListBox : public CObjectList -{ -private: - std::list< CIntObject* > items; - size_t first; - size_t totalSize; - - SPoint itemOffset; - CSlider * slider; - - void updatePositions(); -public: - //CreateFunc, DestroyFunc - see CObjectList - //Pos - position of first item - //ItemOffset - distance between items in the list - //VisibleSize - maximal number of displayable at once items - //TotalSize - //Slider - slider style, bit field: 1 = present(disabled), 2=horisontal(vertical), 4=blue(brown) - //SliderPos - position of slider, if present - CListBox(CreateFunc create, DestroyFunc destroy, SPoint Pos, SPoint ItemOffset, size_t VisibleSize, - size_t TotalSize, size_t InitialPos=0, int Slider=0, SRect SliderPos=SRect() ); - - //recreate all visible items - void reset(); - - //return currently active items - std::list< CIntObject * > getItems(); - - //scroll list - void moveToPos(size_t which); - void moveToNext(); - void moveToPrev(); -}; - -//////////////////////////////////////////////////////////////////////////////// - class CGarrisonInt; @@ -321,9 +240,9 @@ class CGarrisonInt :public CIntObject { public: int interx; //space between slots - SPoint garOffset; //offset between garrisons (not used if only one hero) + Point garOffset; //offset between garrisons (not used if only one hero) CGarrisonSlot *highlighted; //chosen slot - std::vector splitButtons; //may be empty if no buttons + std::vector splitButtons; //may be empty if no buttons int p2, //TODO: comment me shiftPos;//1st slot of the second row, set shiftPoint for effect @@ -341,7 +260,7 @@ public: //const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns) void setArmy(const CArmedInstance *army, bool bottomGarrison); - void addSplitBtn(AdventureMapButton * button); + void addSplitBtn(CAdventureMapButton * button); void createSet(std::vector &ret, const CCreatureSet * set, int posX, int distance, int posY, int Upg ); void activate(); @@ -358,152 +277,10 @@ public: //removableUnits - you can take units from top; //smallImgs - units images size 64x58 or 32x32; //twoRows - display slots in 2 row (1st row = 4, 2nd = 3) - CGarrisonInt(int x, int y, int inx, const SPoint &garsOffset, SDL_Surface *pomsur, const SPoint &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=NULL, bool _removableUnits = true, bool smallImgs = false, bool _twoRows=false); //c-tor + CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *pomsur, const Point &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=NULL, bool _removableUnits = true, bool smallImgs = false, bool _twoRows=false); //c-tor ~CGarrisonInt(); //d-tor }; -/// Status bar which is shown at the bottom of the in-game screens -class CStatusBar - : public CIntObject, public IStatusBar -{ -public: - SDL_Surface * bg; //background - int middlex, middley; //middle of statusbar - std::string current; //text currently printed - - CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor - ~CStatusBar(); //d-tor - void print(const std::string & text); //prints text and refreshes statusbar - void clear();//clears statusbar and refreshes - void show(SDL_Surface * to); //shows statusbar (with current text) - std::string getCurrent(); //getter for current -}; - -/// Label which shows text -class CLabel - : public virtual CIntObject -{ -public: - EAlignment alignment; - EFonts font; - SDL_Color color; - std::string text; - CPicture *bg; - bool autoRedraw; //whether control will redraw itself on setTxt - SPoint textOffset; //text will be blitted at pos + textOffset with appropriate alignment - bool ignoreLeadingWhitespace; - - virtual void setTxt(const std::string &Txt); - void showAll(SDL_Surface * to); //shows statusbar (with current text) - CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly, const std::string &Text = ""); -}; - -/// a multi-line label that tries to fit text with given available width and height; if not possible, it creates a slider for scrolling text -class CTextBox - : public CLabel -{ -public: - int maxW; //longest line of text in px - int maxH; //total height needed to print all lines - - int sliderStyle; - bool redrawParentOnScrolling; - - std::vector lines; - std::vector effects; - CSlider *slider; - - //CTextBox( std::string Text, const SPoint &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly); - CTextBox(std::string Text, const SRect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly); - void showAll(SDL_Surface * to); //shows statusbar (with current text) - void setTxt(const std::string &Txt); - void setBounds(int limitW, int limitH); - void recalculateLines(const std::string &Txt); - - void sliderMoved(int to); -}; - -/// Status bar which is shown at the bottom of the in-game screens -class CGStatusBar - : public CLabel, public IStatusBar -{ - void init(); -public: - IStatusBar *oldStatusBar; - - //statusbar interface overloads - void print(const std::string & Text); //prints text and refreshes statusbar - void clear();//clears statusbar and refreshes - std::string getCurrent(); //returns currently displayed text - void show(SDL_Surface * to); //shows statusbar (with current text) - - CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly, const std::string &Text = ""); - CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar - CGStatusBar(int x, int y, std::string name, int maxw=-1); - - ~CGStatusBar(); - void calcOffset(); -}; - -/// UIElement which can get input focus -class CFocusable - : public virtual CIntObject -{ -public: - bool focus; //only one focusable control can have focus at one moment - - void giveFocus(); //captures focus - void moveFocus(); //moves focus to next active control (may be used for tab switching) - - static std::list focusables; //all existing objs - static CFocusable *inputWithFocus; //who has focus now - CFocusable(); - ~CFocusable(); -}; - -/// Text input box where players can enter text -class CTextInput - : public CLabel, public CFocusable -{ -public: - CFunctionList cb; - - void setText(const std::string &nText, bool callCb = false); - - CTextInput(const SRect &Pos, const SPoint &bgOffset, const std::string &bgName, const CFunctionList &CB); - CTextInput(const SRect &Pos, SDL_Surface *srf = NULL); - ~CTextInput(); - void showAll(SDL_Surface * to); - void clickLeft(tribool down, bool previousState); - void keyPressed(const SDL_KeyboardEvent & key); -}; - -/// Listbox UI Element -class CList : public CIntObject -{ -public: - SDL_Surface * bg; //background bitmap - CDefHandler *arrup, *arrdo; //button arrows for scrolling list - SDL_Surface *empty, *selection; - SDL_Rect arrupp, arrdop; //positions of arrows - int posw, posh; //position width/height - int selected, //id of selected position, <0 if none - from; - const int SIZE; //size of list - tribool pressed; //true=up; false=down; indeterminate=none - - CList(int Size = 5); //c-tor - void clickLeft(tribool down, bool previousState); - void activate(); - void deactivate(); - virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in - virtual void genList()=0; - virtual void select(int which)=0; - virtual void draw(SDL_Surface * to)=0; - virtual int size() = 0; //how many elements do we have - void fixPos(); //scrolls list, so the selection will be visible -}; - /// List of heroes which is shown at the right of the adventure map screen class CHeroList : public CList @@ -584,7 +361,7 @@ public: std::vector creatures; //recruitable creatures boost::function recruit; //void (int ID, int amount) <-- call to recruit creatures CSlider *slider; //for selecting amount - AdventureMapButton *max, *buy, *cancel; + CAdventureMapButton *max, *buy, *cancel; CPicture *bitmap; //background CGStatusBar *bar; int which; //which creature is active @@ -613,7 +390,7 @@ public: CGarrisonInt *gar; CSlider *slider; CCreaturePic *animLeft, *animRight; //creature's animation - AdventureMapButton *ok, *cancel; + CAdventureMapButton *ok, *cancel; SDL_Surface *bitmap; //background int a1, a2, c; //TODO: comment me bool which; //which creature is selected @@ -638,7 +415,7 @@ public: int heroPortrait; SDL_Surface *bitmap; //background std::vector comps; //skills to select - AdventureMapButton *ok; + CAdventureMapButton *ok; boost::function cb; void close(); @@ -672,9 +449,9 @@ public: CPicture *bg; //background CSlider *slider; CPicture *titleImage;//title image (castle gate\town portal picture) - AdventureMapButton *ok, *exit; + CAdventureMapButton *ok, *exit; - std::vector areas;//areas for each visible item + std::vector areas;//areas for each visible item std::vector items;//id of all items present in list int selected;//currently selected item int length;//size of list (=9) @@ -740,7 +517,7 @@ public: CFunctionList callback; bool downSelection; - void showAllAt(const SPoint &dstPos, const std::string &customSub, SDL_Surface * to); + void showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to); void clickRight(tribool down, bool previousState); void hover (bool on); @@ -762,7 +539,7 @@ public: EType itemsType[2]; EMarketMode::EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact - AdventureMapButton *ok, *max, *deal; + CAdventureMapButton *ok, *max, *deal; CSlider *slider; //for choosing amount to be exchanged bool readyToTrade; @@ -774,7 +551,7 @@ public: void initTypes(); void initItems(bool Left); std::vector *getItemsIds(bool Left); //NULL if default - void getPositionsFor(std::vector &poss, bool Left, EType type) const; + void getPositionsFor(std::vector &poss, bool Left, EType type) const; void removeItems(const std::set &toRemove); void removeItem(CTradeableItem * t); void getEmptySlots(std::set &toRemove); @@ -784,7 +561,7 @@ public: virtual void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const = 0; virtual void selectionChanged(bool side) = 0; //true == left - virtual SPoint selectionOffset(bool Left) const = 0; + virtual Point selectionOffset(bool Left) const = 0; virtual std::string selectionSubtitle(bool Left) const = 0; virtual void garrisonChanged() = 0; virtual void artifactsChanged(bool left) = 0; @@ -805,7 +582,7 @@ public: CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = NULL, EMarketMode::EMarketMode Mode = EMarketMode::RESOURCE_RESOURCE); //c-tor ~CMarketplaceWindow(); //d-tor - SPoint selectionOffset(bool Left) const; + Point selectionOffset(bool Left) const; std::string selectionSubtitle(bool Left) const; @@ -828,7 +605,7 @@ public: std::vector sacrificedUnits, //[slot_nr] -> how many creatures from that slot will be sacrificed expPerUnit; - AdventureMapButton *sacrificeAll, *sacrificeBackpack; + CAdventureMapButton *sacrificeAll, *sacrificeBackpack; CLabel *expToLevel, *expOnAltar; @@ -846,7 +623,7 @@ public: void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const; void mimicCres(); - SPoint selectionOffset(bool Left) const; + Point selectionOffset(bool Left) const; std::string selectionSubtitle(bool Left) const; void garrisonChanged(); void artifactsChanged(bool left); @@ -863,7 +640,7 @@ class CSystemOptionsWindow : public CIntObject { private: SDL_Surface * background; //background of window - AdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet + CAdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet CHighlightableButtonsGroup * heroMoveSpeed; CHighlightableButtonsGroup * mapScrollSpeed; CHighlightableButtonsGroup * musicVolume, * effectsVolume; @@ -909,7 +686,7 @@ public: int selected;//0 (left) or 1 (right) int oldSelected;//0 (left) or 1 (right) - AdventureMapButton *thiefGuild, *cancel, *recruit; + CAdventureMapButton *thiefGuild, *cancel, *recruit; const CGObjectInstance *tavernObj; CTavernWindow(const CGObjectInstance *TavernObj); //c-tor @@ -945,33 +722,6 @@ public: CInGameConsole(); //c-tor }; -/// Shows a text by moving the mouse cursor over the object -class HoverableArea: public virtual CIntObject -{ -public: - std::string hoverText; - - virtual void hover (bool on); - - HoverableArea(); - virtual ~HoverableArea(); -}; - -/// Can interact on left and right mouse clicks, plus it shows a text when by hovering over it -class LRClickableAreaWText: public HoverableArea -{ -public: - std::string text; - - LRClickableAreaWText(); - LRClickableAreaWText(const SRect &Pos, const std::string &HoverText = "", const std::string &ClickText = ""); - virtual ~LRClickableAreaWText(); - void init(); - - virtual void clickLeft(tribool down, bool previousState); - virtual void clickRight(tribool down, bool previousState); -}; - /// Can interact on left and right mouse clicks class LRClickableAreaWTextComp: public LRClickableAreaWText { @@ -981,8 +731,8 @@ public: virtual void clickLeft(tribool down, bool previousState); virtual void clickRight(tribool down, bool previousState); - LRClickableAreaWTextComp(const SRect &Pos = SRect(0,0,0,0), int BaseType = -1); - SComponent * createComponent() const; + LRClickableAreaWTextComp(const Rect &Pos = Rect(0,0,0,0), int BaseType = -1); + CComponent * createComponent() const; }; class MoraleLuckBox : public LRClickableAreaWTextComp @@ -994,7 +744,7 @@ public: void set(const IBonusBearer *node); void showAll(SDL_Surface * to); - MoraleLuckBox(bool Morale, const SRect &r, bool Small=false); + MoraleLuckBox(bool Morale, const Rect &r, bool Small=false); ~MoraleLuckBox(); }; @@ -1022,37 +772,6 @@ public: LRClickableAreaOpenTown(); }; -/// Creature info window -class CCreInfoWindow : public CIntObject -{ -public: - CPicture *background; - CLabel *creatureCount; - CLabel *creatureName; - CLabel *abilityText; - - CCreaturePic *animation; - std::vector upgResCost; //cost of upgrade (if not possible then empty) - std::vector effects; - std::map > infoTexts; - - MoraleLuckBox *luck, *morale; - - AdventureMapButton *dismiss, *upgrade, *ok; - - CCreInfoWindow(const CStackInstance &st, bool LClicked, boost::function Upg = 0, boost::function Dsm = 0, UpgradeInfo *ui = NULL); - CCreInfoWindow(const CStack &st, bool LClicked = 0); - CCreInfoWindow(int Cid, bool LClicked, int creatureCount); - ~CCreInfoWindow(); - - void init(const CCreature *cre, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner, int creatureCount, bool LClicked); - void printLine(int nr, const std::string &text, int baseVal, int val=-1, bool range=false); - - void clickRight(tribool down, bool previousState); - void close(); - void show(SDL_Surface * to); -}; - /// Artifacts can be placed there. Gets shown at the hero window class CArtPlace: public LRClickableAreaWTextComp { @@ -1066,7 +785,7 @@ public: const CArtifactInstance * ourArt; CArtPlace(const CArtifactInstance * Art); //c-tor - CArtPlace(SPoint position, const CArtifactInstance * Art = NULL); //c-tor + CArtPlace(Point position, const CArtifactInstance * Art = NULL); //c-tor void clickLeft(tribool down, bool previousState); void clickRight(tribool down, bool previousState); void select (); @@ -1114,7 +833,7 @@ public: bool updateState; // Whether the commonInfo should be updated on setHero or not. - AdventureMapButton * leftArtRoll, * rightArtRoll; + CAdventureMapButton * leftArtRoll, * rightArtRoll; bool allowedAssembling; std::multiset artifactsOnAltar; //artifacts id that are technically present in backpack but in GUI are moved to the altar - they'll be omitted in backpack slots boost::function highlightModeCallback; //if set, clicking on art place doesn't pick artifact but highlights the slot and calls this function @@ -1141,10 +860,10 @@ public: void updateSlot(int i); void eraseSlotData (CArtPlace* artPlace, int slotID); - CArtifactsOfHero(const SPoint& position, bool createCommonPart = false); + CArtifactsOfHero(const Point& position, bool createCommonPart = false); //Alternative constructor, used if custom artifacts positioning required (Kingdom interface) CArtifactsOfHero(std::vector ArtWorn, std::vector Backpack, - AdventureMapButton *leftScroll, AdventureMapButton *rightScroll, bool createCommonPart = false); + CAdventureMapButton *leftScroll, CAdventureMapButton *rightScroll, bool createCommonPart = false); ~CArtifactsOfHero(); //d-tor void updateParentWindow(); friend class CArtPlace; @@ -1170,7 +889,7 @@ class CGarrisonWindow : public CWindowWithGarrison public: CPicture *bg; //background surface CLabel *title; - AdventureMapButton *quit; + CAdventureMapButton *quit; void close(); void showAll(SDL_Surface * to); @@ -1183,7 +902,7 @@ class CExchangeWindow : public CWindowWithGarrison, public CWindowWithArtifacts CGStatusBar * ourBar; //internal statusbar SDL_Surface *bg; //background - AdventureMapButton * quit, * questlogButton[2]; + CAdventureMapButton * quit, * questlogButton[2]; std::vector secSkillAreas[2], primSkillAreas; @@ -1225,7 +944,7 @@ public: CLabel *woodCost, *goldCost; CAnimImage *bgShip; - AdventureMapButton *build, *quit; + CAdventureMapButton *build, *quit; CGStatusBar * statusBar; @@ -1237,7 +956,7 @@ class CPuzzleWindow : public CIntObject { private: SDL_Surface * background; - AdventureMapButton * quitb; + CAdventureMapButton * quitb; CResDataBar * resdatabar; std::vector > puzzlesToPullBack; @@ -1277,7 +996,7 @@ public: CPicture *bg; //background std::vector items; - AdventureMapButton *all, *convert, *cancel; + CAdventureMapButton *all, *convert, *cancel; CGStatusBar *bar; void showAll(SDL_Surface * to); void makeDeal(); @@ -1310,7 +1029,7 @@ public: CPicture *bg; //background std::vector items; - AdventureMapButton *cancel; + CAdventureMapButton *cancel; CGStatusBar *bar; CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market); //c-tor @@ -1324,7 +1043,7 @@ public: CUniversityWindow * parent; CPicture * bg; CGStatusBar *bar; - AdventureMapButton *confirm, *cancel; + CAdventureMapButton *confirm, *cancel; CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available); //c-tor void makeDeal(int skill); @@ -1340,7 +1059,7 @@ public: CDefEssential *resources; CPicture *bg; //background surface CHeroArea *heroPic;//clickable hero image - AdventureMapButton *quit,//closes window + CAdventureMapButton *quit,//closes window *upgradeAll,//upgrade all creatures *upgrade[7];//upgrade single creature @@ -1367,7 +1086,7 @@ class CThievesGuildWindow : public CIntObject const CGObjectInstance * owner; CGStatusBar * statusBar; - AdventureMapButton * exitb; + CAdventureMapButton * exitb; SDL_Surface * background; CMinorResDataBar * resdatabar; @@ -1380,7 +1099,3 @@ public: CThievesGuildWindow(const CGObjectInstance * _owner); ~CThievesGuildWindow(); }; - -CIntObject *createCreWindow(const CStack *s); -CIntObject *createCreWindow(int Cid, int Type, int creatureCount); -CIntObject *createCreWindow(const CStackInstance *s, int type, boost::function Upg = 0, boost::function Dsm = 0, UpgradeInfo *ui = NULL); diff --git a/client/Graphics.cpp b/client/Graphics.cpp index b3ff49ddb..e94126fcf 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -2,7 +2,7 @@ #include "Graphics.h" #include "CDefHandler.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include #include "../lib/CThreadHelper.h" #include "CGameInfo.h" @@ -50,7 +50,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const InfoAboutHero &curh) SDL_Surface * ret = SDL_DisplayFormat(hInfo); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); - printAt(curh.name,75,13,FONT_SMALL,zwykly,ret); //name + printAt(curh.name,75,13,FONT_SMALL,Colors::Cornsilk,ret); //name blitAt(graphics->portraitLarge[curh.portrait],11,12,ret); //portrait //army @@ -60,11 +60,11 @@ SDL_Surface * Graphics::drawHeroInfoWin(const InfoAboutHero &curh) if(curh.details) { SDL_itoa((*i).second.count,buf,10); - printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+41,FONT_TINY,zwykly,ret); + printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+41,FONT_TINY,Colors::Cornsilk,ret); } else { - printAtMiddle(VLC->generaltexth->arraytxt[174 + 3*(i->second.count)],slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+41,FONT_TINY,zwykly,ret); + printAtMiddle(VLC->generaltexth->arraytxt[174 + 3*(i->second.count)],slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+41,FONT_TINY,Colors::Cornsilk,ret); } } @@ -73,12 +73,12 @@ SDL_Surface * Graphics::drawHeroInfoWin(const InfoAboutHero &curh) for (int i = 0; i < GameConstants::PRIMARY_SKILLS; i++) { SDL_itoa(curh.details->primskills[i], buf, 10); - printAtMiddle(buf,84+28*i,70,FONT_SMALL,zwykly,ret); + printAtMiddle(buf,84+28*i,70,FONT_SMALL,Colors::Cornsilk,ret); } //mana points SDL_itoa(curh.details->mana,buf,10); - printAtMiddle(buf,167,108,FONT_TINY,zwykly,ret); + printAtMiddle(buf,167,108,FONT_TINY,Colors::Cornsilk,ret); blitAt(morale22->ourImages[curh.details->morale+3].bitmap,14,84,ret); //luck blitAt(luck22->ourImages[curh.details->morale+3].bitmap,14,101,ret); //morale @@ -107,7 +107,7 @@ SDL_Surface * Graphics::drawTownInfoWin( const InfoAboutTown & curh ) SDL_Surface * ret = SDL_DisplayFormat(tInfo); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); - printAt(curh.name,75,12,FONT_SMALL,zwykly,ret); //name + printAt(curh.name,75,12,FONT_SMALL,Colors::Cornsilk,ret); //name int pom = curh.fortLevel - 1; if(pom<0) pom = 3; //fort pic id blitAt(forts->ourImages[pom].bitmap,115,42,ret); //fort @@ -120,14 +120,14 @@ SDL_Surface * Graphics::drawTownInfoWin( const InfoAboutTown & curh ) { // Show exact creature amount. SDL_itoa((*i).second.count,buf,10); - printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+41,FONT_TINY,zwykly,ret); + printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+41,FONT_TINY,Colors::Cornsilk,ret); } else { // Show only a rough amount for creature stacks. // TODO: Deal with case when no information at all about size shold be presented. std::string roughAmount = curh.obj->getRoughAmount(i->first); - printAtMiddle(roughAmount,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+41,FONT_TINY,zwykly,ret); + printAtMiddle(roughAmount,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+41,FONT_TINY,Colors::Cornsilk,ret); } } @@ -149,7 +149,7 @@ SDL_Surface * Graphics::drawTownInfoWin( const InfoAboutTown & curh ) if (curh.details->goldIncome >= 0) { SDL_itoa(curh.details->goldIncome, buf, 10); //gold income - printAtMiddle(buf, 167, 70, FONT_TINY, zwykly, ret); + printAtMiddle(buf, 167, 70, FONT_TINY, Colors::Cornsilk, ret); } if(curh.details->garrisonedHero) //garrisoned hero icon blitAt(graphics->heroInGarrison,158,87,ret); @@ -365,7 +365,7 @@ void Graphics::loadWallPositions() int townID = town["id"].Float(); BOOST_FOREACH(const JsonNode &coords, town["pos"].Vector()) { - SPoint pt(coords["x"].Float(), coords["y"].Float()); + Point pt(coords["x"].Float(), coords["y"].Float()); wallPositions[townID].push_back(pt); } diff --git a/client/Graphics.h b/client/Graphics.h index 286d3bb6a..5f7131e54 100644 --- a/client/Graphics.h +++ b/client/Graphics.h @@ -3,8 +3,7 @@ #include "FontBase.h" #include "../lib/GameConstants.h" -#include "UIFramework/SPoint.h" -#include "UIFramework/SRect.h" +#include "UIFramework/Geometries.h" /* * Graphics.h, part of VCMI engine @@ -87,7 +86,7 @@ public: std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle std::map< int, std::vector < std::string > > battleACToDef; //maps AC format to vector of appropriate def names CDefEssential * spellEffectsPics; //bitmaps representing spells affecting a stack in battle - std::vector< SPoint > wallPositions[GameConstants::F_NUMBER]; //positions of different pieces of wall + std::vector< Point > wallPositions[GameConstants::F_NUMBER]; //positions of different pieces of wall //abilities CDefEssential * abils32, * abils44, * abils82; //spells diff --git a/client/Makefile.am b/client/Makefile.am index 262c553ec..0dc9b27f3 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -9,59 +9,26 @@ vcmiclient_LDFLAGS = -L$(top_builddir)/lib vcmiclient_SOURCES = \ ../CCallback.cpp \ ../CCallback.h \ - ./BattleInterface/CAttackAnimation.cpp \ - ./BattleInterface/CAttackAnimation.h \ - ./BattleInterface/CBattleAnimation.cpp \ - ./BattleInterface/CBattleAnimation.h \ - ./BattleInterface/CBattleConsole.cpp \ - ./BattleInterface/CBattleConsole.h \ - ./BattleInterface/CBattleHero.cpp \ - ./BattleInterface/CBattleHero.h \ + ./BattleInterface/CBattleAnimations.cpp \ + ./BattleInterface/CBattleAnimations.h \ ./BattleInterface/CBattleInterface.cpp \ ./BattleInterface/CBattleInterface.h \ - ./BattleInterface/CBattleOptionsWindow.cpp \ - ./BattleInterface/CBattleOptionsWindow.h \ - ./BattleInterface/CBattleResultWindow.cpp \ - ./BattleInterface/CBattleResultWindow.h \ - ./BattleInterface/CBattleStackAnimation.cpp \ - ./BattleInterface/CBattleStackAnimation.h \ + ./BattleInterface/CBattleInterfaceClasses.cpp \ + ./BattleInterface/CBattleInterfaceClasses.h \ ./BattleInterface/CCreatureAnimation.h \ ./BattleInterface/CCreatureAnimation.cpp \ - ./BattleInterface/CDefenceAnimation.cpp \ - ./BattleInterface/CDefenceAnimation.h \ - ./BattleInterface/CDummyAnimation.cpp \ - ./BattleInterface/CDummyAnimation.h \ - ./BattleInterface/CClickableHex.cpp \ - ./BattleInterface/CClickableHex.h \ - ./BattleInterface/CMeleeAttackAnimation.cpp \ - ./BattleInterface/CMeleeAttackAnimation.h \ - ./BattleInterface/CMovementAnimation.cpp \ - ./BattleInterface/CMovementAnimation.h \ - ./BattleInterface/CMovementEndAnimation.cpp \ - ./BattleInterface/CMovementEndAnimation.h \ - ./BattleInterface/CMovementStartAnimation.cpp \ - ./BattleInterface/CMovementStartAnimation.h \ - ./BattleInterface/CReverseAnimation.cpp \ - ./BattleInterface/CReverseAnimation.h \ - ./BattleInterface/CShootingAnimation.cpp \ - ./BattleInterface/CShootingAnimation.h \ - ./BattleInterface/CSpellEffectAnimation.cpp \ - ./BattleInterface/CSpellEffectAnimation.h \ - ./BattleInterface/CStackQueue.cpp \ - ./BattleInterface/CStackQueue.h \ - ./BattleInterface/SStackAttackedInfo.h \ ./UIFramework/CGuiHandler.cpp \ ./UIFramework/CGuiHandler.h \ ./UIFramework/CIntObject.cpp \ ./UIFramework/CIntObject.h \ - ./UIFramework/CKeyShortcut.cpp \ - ./UIFramework/CKeyShortcut.h \ - ./UIFramework/CPicture.cpp \ - ./UIFramework/CPicture.h \ - ./UIFramework/SRect.cpp \ - ./UIFramework/SRect.h \ - AdventureMapButton.cpp \ - AdventureMapButton.h \ + ./UIFramework/CIntObjectClasses.cpp \ + ./UIFramework/CIntObjectClasses.h \ + ./UIFramework/Geometries.cpp \ + ./UIFramework/Geometries.h \ + ./UIFramework/CCursorHandler.cpp \ + ./UIFramework/CCursorHandler.h \ + ./UIFramework/SDL_Extensions.cpp \ + ./UIFramework/SDL_Extensions.h \ CAdvmapInterface.cpp \ CAdvmapInterface.h \ CAnimation.cpp \ @@ -74,8 +41,6 @@ vcmiclient_SOURCES = \ CConfigHandler.h \ CCreatureWindow.cpp \ CCreatureWindow.h \ - CCursorHandler.cpp \ - CCursorHandler.h \ CDefHandler.cpp \ CDefHandler.h \ CGameInfo.cpp \ @@ -111,8 +76,4 @@ vcmiclient_SOURCES = \ GUIClasses.h \ mapHandler.cpp \ mapHandler.h \ - NetPacksClient.cpp \ - SDL_Extensions.cpp \ - SDL_Extensions.h \ - SDL_framerate.cpp \ - SDL_framerate.h + NetPacksClient.cpp \ No newline at end of file diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index 33b735010..d4b7c96f6 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -18,7 +18,7 @@ #include "mapHandler.h" #include "GUIClasses.h" #include "CConfigHandler.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "BattleInterface/CBattleInterface.h" #include "../lib/CCampaignHandler.h" #include "../lib/CGameState.h" @@ -766,7 +766,7 @@ void SetSelection::applyCl(CClient *cl) void ShowInInfobox::applyCl(CClient *cl) { - SComponent sc(c); + CComponent sc(c); text.toString(sc.description); if(vstd::contains(cl->playerint, player) && cl->playerint[player]->human) { diff --git a/client/CCursorHandler.cpp b/client/UIFramework/CCursorHandler.cpp similarity index 93% rename from client/CCursorHandler.cpp rename to client/UIFramework/CCursorHandler.cpp index 517005c45..e3ef3c5ca 100644 --- a/client/CCursorHandler.cpp +++ b/client/UIFramework/CCursorHandler.cpp @@ -1,10 +1,10 @@ #include "StdInc.h" #include "CCursorHandler.h" -#include "SDL.h" +#include #include "SDL_Extensions.h" -#include "CGameInfo.h" -#include "CDefHandler.h" +#include "../CGameInfo.h" +#include "../CDefHandler.h" /* * CCursorHandler.cpp, part of VCMI engine diff --git a/client/CCursorHandler.h b/client/UIFramework/CCursorHandler.h similarity index 100% rename from client/CCursorHandler.h rename to client/UIFramework/CCursorHandler.h diff --git a/client/UIFramework/CGuiHandler.cpp b/client/UIFramework/CGuiHandler.cpp index 60414ab55..36e963ec8 100644 --- a/client/UIFramework/CGuiHandler.cpp +++ b/client/UIFramework/CGuiHandler.cpp @@ -1,26 +1,17 @@ #include "StdInc.h" #include "CGuiHandler.h" -#include "IShowActivatable.h" -#include "../SDL_Extensions.h" +#include "SDL_Extensions.h" #include "CIntObject.h" #include "../CGameInfo.h" -#include "../CCursorHandler.h" +#include "CCursorHandler.h" #include "../../lib/CThreadHelper.h" #include "../CConfigHandler.h" -#include "../SDL_framerate.h" -#include "IUpdateable.h" extern SDL_Surface * screenBuf, * screen2, * screen; extern std::queue events; extern boost::mutex eventsM; -SDL_Color Colors::createColor(int r, int g, int b) -{ - SDL_Color temp = {r, g, b, 0}; - return temp; -} - SObjectConstruction::SObjectConstruction( CIntObject *obj ) :myObj(obj) { @@ -372,7 +363,7 @@ CGuiHandler::CGuiHandler() statusbar = NULL; // Creates the FPS manager and sets the framerate to 48 which is doubled the value of the original Heroes 3 FPS rate - mainFPSmng = new FPSManager(48); + mainFPSmng = new CFramerateManager(48); mainFPSmng->init(); // resets internal clock, needed for FPS manager } @@ -458,4 +449,32 @@ bool CGuiHandler::isNumKey( SDLKey key, bool number ) bool CGuiHandler::isArrowKey( SDLKey key ) { return key >= SDLK_UP && key <= SDLK_LEFT; +} + + +CFramerateManager::CFramerateManager(int rate) +{ + this->rate = rate; + this->rateticks = (1000.0 / rate); + this->fps = 0; +} + +void CFramerateManager::init() +{ + this->lastticks = SDL_GetTicks(); +} + +void CFramerateManager::framerateDelay() +{ + ui32 currentTicks = SDL_GetTicks(); + this->timeElapsed = currentTicks - this->lastticks; + + // FPS is higher than it should be, then wait some time + if (this->timeElapsed < this->rateticks) + { + SDL_Delay(ceil(this->rateticks) - this->timeElapsed); + } + + this->fps = ceil(1000.0 / this->timeElapsed); + this->lastticks = SDL_GetTicks(); } \ No newline at end of file diff --git a/client/UIFramework/CGuiHandler.h b/client/UIFramework/CGuiHandler.h index 448f82e3e..428a4ba13 100644 --- a/client/UIFramework/CGuiHandler.h +++ b/client/UIFramework/CGuiHandler.h @@ -1,9 +1,9 @@ #pragma once #include "../../lib/CStopWatch.h" -#include "SPoint.h" +#include "Geometries.h" -class FPSManager; +class CFramerateManager; class IStatusBar; class CIntObject; class IUpdateable; @@ -20,11 +20,28 @@ class IShowable; * */ +// A fps manager which holds game updates at a constant rate +class CFramerateManager +{ +private: + double rateticks; + ui32 lastticks, timeElapsed; + int rate; + +public: + int fps; // the actual fps value + + CFramerateManager(int rate); // initializes the manager with a given fps rate + void init(); // needs to be called directly before the main game loop to reset the internal timer + void framerateDelay(); // needs to be called every game update cycle + double getElapsedSeconds() const { return this->timeElapsed / 1000; } +}; + // Handles GUI logic and drawing class CGuiHandler { public: - FPSManager * mainFPSmng; //to keep const framerate + CFramerateManager * mainFPSmng; //to keep const framerate CStopWatch th; std::list listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on) IStatusBar * statusbar; @@ -45,7 +62,7 @@ public: SDL_Event * current; //current event - can be set to NULL to stop handling event IUpdateable *curInt; - SPoint lastClick; + Point lastClick; unsigned lastClickTime; bool terminate; @@ -105,10 +122,7 @@ struct SSetCaptureState namespace Colors { - SDL_Color createColor(int r, int g, int b); - - const SDL_Color MetallicGold = createColor(173, 142, 66); - const SDL_Color Yellow = createColor(242, 226, 110); + }; #define OBJ_CONSTRUCTION SObjectConstruction obj__i(this) diff --git a/client/UIFramework/CIntObject.cpp b/client/UIFramework/CIntObject.cpp index 3f30244d4..f9ecf7df4 100644 --- a/client/UIFramework/CIntObject.cpp +++ b/client/UIFramework/CIntObject.cpp @@ -1,7 +1,7 @@ #include "StdInc.h" #include "CIntObject.h" #include "CGuiHandler.h" -#include "../SDL_Extensions.h" +#include "SDL_Extensions.h" void CIntObject::activateLClick() { @@ -139,7 +139,7 @@ CIntObject::CIntObject() parent = NULL; } -void CIntObject::show( SDL_Surface * to ) +void CIntObject::show(SDL_Surface * to) { if(defActions & UPDATE) for(size_t i = 0; i < children.size(); i++) @@ -147,7 +147,7 @@ void CIntObject::show( SDL_Surface * to ) children[i]->show(to); } -void CIntObject::showAll( SDL_Surface * to ) +void CIntObject::showAll(SDL_Surface * to) { if(defActions & SHOWALL) { @@ -239,17 +239,17 @@ CIntObject::~CIntObject() parent->children -= this; } -void CIntObject::printAtLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ ) +void CIntObject::printAtLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::Cornsilk*/, SDL_Surface * dst/*=screen*/ ) { CSDL_Ext::printAt(text, pos.x + x, pos.y + y, font, kolor, dst); } -void CIntObject::printAtMiddleLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ ) +void CIntObject::printAtMiddleLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::Cornsilk*/, SDL_Surface * dst/*=screen*/ ) { CSDL_Ext::printAtMiddle(text, pos.x + x, pos.y + y, font, kolor, dst); } -void CIntObject::printAtMiddleLoc(const std::string & text, const SPoint &p, EFonts font, SDL_Color kolor, SDL_Surface * dst) +void CIntObject::printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, SDL_Color kolor, SDL_Surface * dst) { printAtMiddleLoc(text, p.x, p.y, font, kolor, dst); } @@ -259,7 +259,7 @@ void CIntObject::blitAtLoc( SDL_Surface * src, int x, int y, SDL_Surface * dst ) blitAt(src, pos.x + x, pos.y + y, dst); } -void CIntObject::blitAtLoc(SDL_Surface * src, const SPoint &p, SDL_Surface * dst) +void CIntObject::blitAtLoc(SDL_Surface * src, const Point &p, SDL_Surface * dst) { blitAtLoc(src, p.x, p.y, dst); } @@ -295,7 +295,7 @@ bool CIntObject::isItInLoc( const SDL_Rect &rect, int x, int y ) return isItIn(&rect, x - pos.x, y - pos.y); } -bool CIntObject::isItInLoc( const SDL_Rect &rect, const SPoint &p ) +bool CIntObject::isItInLoc( const SDL_Rect &rect, const Point &p ) { return isItIn(&rect, p.x - pos.x, p.y - pos.y); } @@ -338,7 +338,7 @@ void CIntObject::onDoubleClick() void CIntObject::fitToScreen(int borderWidth, bool propagate) { - SPoint newPos = pos.topLeft(); + Point newPos = pos.topLeft(); vstd::amax(newPos.x, borderWidth); vstd::amax(newPos.y, borderWidth); vstd::amin(newPos.x, screen->w - borderWidth - pos.w); @@ -347,7 +347,7 @@ void CIntObject::fitToScreen(int borderWidth, bool propagate) moveTo(newPos, propagate); } -void CIntObject::moveBy( const SPoint &p, bool propagate /*= true*/ ) +void CIntObject::moveBy( const Point &p, bool propagate /*= true*/ ) { pos.x += p.x; pos.y += p.y; @@ -356,9 +356,9 @@ void CIntObject::moveBy( const SPoint &p, bool propagate /*= true*/ ) children[i]->moveBy(p, propagate); } -void CIntObject::moveTo( const SPoint &p, bool propagate /*= true*/ ) +void CIntObject::moveTo( const Point &p, bool propagate /*= true*/ ) { - moveBy(SPoint(p.x - pos.x, p.y - pos.y), propagate); + moveBy(Point(p.x - pos.x, p.y - pos.y), propagate); } void CIntObject::delChild(CIntObject *child) @@ -403,7 +403,7 @@ void CIntObject::changeUsedEvents(ui16 what, bool enable, bool adjust /*= true*/ } } -void CIntObject::drawBorderLoc(SDL_Surface * sur, const SRect &r, const int3 &color) +void CIntObject::drawBorderLoc(SDL_Surface * sur, const Rect &r, const int3 &color) { CSDL_Ext::drawBorder(sur, r + pos, color); } @@ -422,22 +422,40 @@ void CIntObject::redraw() } } -const SRect & CIntObject::center( const SRect &r, bool propagate ) +const Rect & CIntObject::center( const Rect &r, bool propagate ) { pos.w = r.w; pos.h = r.h; - return center(SPoint(screen->w/2, screen->h/2), propagate); + return center(Point(screen->w/2, screen->h/2), propagate); } -const SRect & CIntObject::center( bool propagate ) +const Rect & CIntObject::center( bool propagate ) { return center(pos, propagate); } -const SRect & CIntObject::center(const SPoint &p, bool propagate /*= true*/) +const Rect & CIntObject::center(const Point &p, bool propagate /*= true*/) { - moveBy(SPoint(p.x - pos.w/2 - pos.x, + moveBy(Point(p.x - pos.w/2 - pos.x, p.y - pos.h/2 - pos.y), propagate); return pos; +} + +void CKeyShortcut::keyPressed(const SDL_KeyboardEvent & key) +{ + if(vstd::contains(assignedKeys,key.keysym.sym)) + { + bool prev = pressedL; + if(key.state == SDL_PRESSED) + { + pressedL = true; + clickLeft(true, prev); + } + else + { + pressedL = false; + clickLeft(false, prev); + } + } } \ No newline at end of file diff --git a/client/UIFramework/CIntObject.h b/client/UIFramework/CIntObject.h index e28c28d50..8cf8d1197 100644 --- a/client/UIFramework/CIntObject.h +++ b/client/UIFramework/CIntObject.h @@ -1,8 +1,7 @@ #pragma once #include -#include "IShowActivatable.h" -#include "SRect.h" +#include "Geometries.h" #include "../FontBase.h" struct SDL_Surface; @@ -19,6 +18,56 @@ struct SDL_Surface; using boost::logic::tribool; +// Defines a activate/deactive method +class IActivatable +{ +public: + virtual void activate()=0; + virtual void deactivate()=0; + virtual ~IActivatable(){}; //d-tor +}; + +class IUpdateable +{ +public: + virtual void update()=0; + virtual ~IUpdateable(){}; //d-tor +}; + +// Defines a show method +class IShowable +{ +public: + virtual void redraw()=0; + virtual void show(SDL_Surface * to) = 0; + virtual void showAll(SDL_Surface * to) + { + show(to); + } + virtual ~IShowable(){}; //d-tor +}; + +class IShowActivatable : public IShowable, public IActivatable +{ +public: + //redraw parent flag - this int may be semi-transparent and require redraw of parent window + enum {WITH_GARRISON = 1, BLOCK_ADV_HOTKEYS = 2, WITH_ARTIFACTS = 4, REDRAW_PARENT=8}; + int type; //bin flags using etype + IShowActivatable(); + virtual ~IShowActivatable(){}; //d-tor +}; + +// Status bar interface +class IStatusBar +{ +public: + virtual ~IStatusBar(){}; //d-tor + virtual void print(const std::string & text)=0; //prints text and refreshes statusbar + virtual void clear()=0;//clears statusbar and refreshes + virtual void show(SDL_Surface * to)=0; //shows statusbar (with current text) + virtual std::string getCurrent()=0; //returns currently displayed text +}; + // Base UI element class CIntObject : public IShowActivatable //interface object { @@ -26,7 +75,7 @@ public: CIntObject *parent; //parent object std::vector children; - SRect pos, //position of object on the screen + Rect pos, //position of object on the screen posRelative; //position of object in the parent (not used if no parent) CIntObject(); @@ -100,22 +149,22 @@ public: void showAll(SDL_Surface * to); void redraw(); - void drawBorderLoc(SDL_Surface * sur, const SRect &r, const int3 &color); + void drawBorderLoc(SDL_Surface * sur, const Rect &r, const int3 &color); void printAtLoc(const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst); void printToLoc(const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst); void printAtMiddleLoc(const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst); - void printAtMiddleLoc(const std::string & text, const SPoint &p, EFonts font, SDL_Color kolor, SDL_Surface * dst); + void printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, SDL_Color kolor, SDL_Surface * dst); void printAtMiddleWBLoc(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor, SDL_Surface * dst); void blitAtLoc(SDL_Surface * src, int x, int y, SDL_Surface * dst); - void blitAtLoc(SDL_Surface * src, const SPoint &p, SDL_Surface * dst); + void blitAtLoc(SDL_Surface * src, const Point &p, SDL_Surface * dst); bool isItInLoc(const SDL_Rect &rect, int x, int y); - bool isItInLoc(const SDL_Rect &rect, const SPoint &p); - const SRect & center(const SRect &r, bool propagate = true); //sets pos so that r will be in the center of screen, assigns sizes of r to pos, returns new position - const SRect & center(const SPoint &p, bool propagate = true); //moves object so that point p will be in its center - const SRect & center(bool propagate = true); //centers when pos.w and pos.h are set, returns new position + bool isItInLoc(const SDL_Rect &rect, const Point &p); + const Rect & center(const Rect &r, bool propagate = true); //sets pos so that r will be in the center of screen, assigns sizes of r to pos, returns new position + const Rect & center(const Point &p, bool propagate = true); //moves object so that point p will be in its center + const Rect & center(bool propagate = true); //centers when pos.w and pos.h are set, returns new position void fitToScreen(int borderWidth, bool propagate = true); //moves window to fit into screen - void moveBy(const SPoint &p, bool propagate = true); - void moveTo(const SPoint &p, bool propagate = true); + void moveBy(const Point &p, bool propagate = true); + void moveTo(const Point &p, bool propagate = true); void changeUsedEvents(ui16 what, bool enable, bool adjust = true); void addChild(CIntObject *child, bool adjustPosition = false); @@ -132,4 +181,16 @@ public: delChild(child); child = NULL; } +}; + +/// Class for binding keys to left mouse button clicks +/// Classes wanting use it should have it as one of their base classes +class CKeyShortcut : public virtual CIntObject +{ +public: + std::set assignedKeys; + CKeyShortcut(){}; //c-tor + CKeyShortcut(int key){assignedKeys.insert(key);}; //c-tor + CKeyShortcut(std::set Keys):assignedKeys(Keys){}; //c-tor + virtual void keyPressed(const SDL_KeyboardEvent & key); //call-in }; \ No newline at end of file diff --git a/client/UIFramework/CIntObjectClasses.cpp b/client/UIFramework/CIntObjectClasses.cpp new file mode 100644 index 000000000..da21e2b4f --- /dev/null +++ b/client/UIFramework/CIntObjectClasses.cpp @@ -0,0 +1,1490 @@ +#include "StdInc.h" +#include "CIntObjectClasses.h" + +#include "../CBitmapHandler.h" +#include "SDL_Extensions.h" +#include "../Graphics.h" +#include "../CAnimation.h" +#include "../CGameInfo.h" +#include "../../CCallback.h" +#include "../CConfigHandler.h" +#include "../BattleInterface/CBattleInterface.h" +#include "../BattleInterface/CBattleInterfaceClasses.h" +#include "../CPlayerInterface.h" +#include "../CMessage.h" +#include "../CMusicHandler.h" +#include "../GUIClasses.h" +#include "CGuiHandler.h" +#include "../CAdvmapInterface.h" + +CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free ) +{ + init(); + bg = BG; + freeSurf = Free; + pos.x += x; + pos.y += y; + pos.w = BG->w; + pos.h = BG->h; +} + +CPicture::CPicture( const std::string &bmpname, int x, int y ) +{ + init(); + bg = BitmapHandler::loadBitmap(bmpname); + freeSurf = true;; + pos.x += x; + pos.y += y; + if(bg) + { + pos.w = bg->w; + pos.h = bg->h; + } + else + { + pos.w = pos.h = 0; + } +} + +CPicture::CPicture(const Rect &r, const SDL_Color &color, bool screenFormat /*= false*/) +{ + init(); + createSimpleRect(r, screenFormat, SDL_MapRGB(bg->format, color.r, color.g,color.b)); +} + +CPicture::CPicture(const Rect &r, ui32 color, bool screenFormat /*= false*/) +{ + init(); + createSimpleRect(r, screenFormat, color); +} + +CPicture::CPicture(SDL_Surface *BG, const Rect &SrcRect, int x /*= 0*/, int y /*= 0*/, bool free /*= false*/) +{ + needRefresh = false; + srcRect = new Rect(SrcRect); + pos.x += x; + pos.y += y; + pos.w = srcRect->w; + pos.h = srcRect->h; + bg = BG; + freeSurf = free; +} + +CPicture::~CPicture() +{ + if(freeSurf) + SDL_FreeSurface(bg); + delete srcRect; +} + +void CPicture::init() +{ + needRefresh = false; + srcRect = NULL; +} + +void CPicture::show(SDL_Surface * to) +{ + if (needRefresh) + showAll(to); +} + +void CPicture::showAll(SDL_Surface * to) +{ + if(bg) + { + if(srcRect) + { + SDL_Rect srcRectCpy = *srcRect; + SDL_Rect dstRect = srcRectCpy; + dstRect.x = pos.x; + dstRect.y = pos.y; + + CSDL_Ext::blitSurface(bg, &srcRectCpy, to, &dstRect); + } + else + blitAt(bg, pos, to); + } +} + +void CPicture::convertToScreenBPP() +{ + SDL_Surface *hlp = bg; + bg = SDL_ConvertSurface(hlp,screen->format,0); + SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); + SDL_FreeSurface(hlp); +} + +void CPicture::createSimpleRect(const Rect &r, bool screenFormat, ui32 color) +{ + pos += r; + pos.w = r.w; + pos.h = r.h; + if(screenFormat) + bg = CSDL_Ext::newSurface(r.w, r.h); + else + bg = SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 8, 0, 0, 0, 0); + + SDL_FillRect(bg, NULL, color); + freeSurf = true; +} + +void CPicture::colorizeAndConvert(int player) +{ + assert(bg); + colorize(player); + convertToScreenBPP(); +} + +void CPicture::colorize(int player) +{ + assert(bg); + assert(bg->format->BitsPerPixel == 8); + graphics->blueToPlayersAdv(bg, player); +} + +CButtonBase::CButtonBase() +{ + swappedImages = keepFrame = false; + bitmapOffset = 0; + state=NORMAL; + image = NULL; + text = NULL; +} + +CButtonBase::~CButtonBase() +{ + +} + +void CButtonBase::update() +{ + if (text) + { + if (state == PRESSED) + text->moveTo(Point(pos.x+pos.w/2+1, pos.y+pos.h/2+1)); + else + text->moveTo(Point(pos.x+pos.w/2, pos.y+pos.h/2)); + } + + int newPos = (int)state + bitmapOffset; + if (newPos < 0) + newPos = 0; + + if (state == HIGHLIGHTED && image->size() < 4) + newPos = image->size()-1; + + if (swappedImages) + { + if (newPos == 0) newPos = 1; + else if (newPos == 1) newPos = 0; + } + + if (!keepFrame) + image->setFrame(newPos); + + if (active) + redraw(); +} + +void CButtonBase::addTextOverlay( const std::string &Text, EFonts font, SDL_Color color) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + delChild(text); + text = new CLabel(pos.w/2, pos.h/2, font, CENTER, color, Text); + update(); +} + +void CButtonBase::setOffset(int newOffset) +{ + if (bitmapOffset == newOffset) + return; + bitmapOffset = newOffset; + update(); +} + +void CButtonBase::setState(ButtonState newState) +{ + if (state == newState) + return; + state = newState; + update(); +} + +CButtonBase::ButtonState CButtonBase::getState() +{ + return state; +} + +bool CButtonBase::isBlocked() +{ + return state == BLOCKED; +} + +bool CButtonBase::isHighlighted() +{ + return state == HIGHLIGHTED; +} + +void CButtonBase::block(bool on) +{ + setState(on?BLOCKED:NORMAL); +} + +CAdventureMapButton::CAdventureMapButton () +{ + hoverable = actOnDown = borderEnabled = soundDisabled = false; + borderColor.unused = 1; // represents a transparent color, used for HighlightableButton + used = LCLICK | RCLICK | HOVER | KEYBOARD; +} + +CAdventureMapButton::CAdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, int x, int y, const std::string &defName,int key, std::vector * add, bool playerColoredButton ) +{ + std::map pom; + pom[0] = Name; + init(Callback, pom, HelpBox, playerColoredButton, defName, add, x, y, key); +} + +CAdventureMapButton::CAdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, config::ButtonInfo *info, int key/*=0*/ ) +{ + std::map pom; + pom[0] = Name; + init(Callback, pom, HelpBox, info->playerColoured, info->defName, &info->additionalDefs, info->x, info->y, key); +} + +CAdventureMapButton::CAdventureMapButton( const std::pair &help, const CFunctionList &Callback, int x, int y, const std::string &defName, int key/*=0*/, std::vector * add /*= NULL*/, bool playerColoredButton /*= false */ ) +{ + std::map pom; + pom[0] = help.first; + init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key); +} +void CAdventureMapButton::clickLeft(tribool down, bool previousState) +{ + if(isBlocked()) + return; + + if (down) + { + if (!soundDisabled) + CCS->soundh->playSound(soundBase::button); + setState(PRESSED); + } + else if(hoverable && hovered) + setState(HIGHLIGHTED); + else + setState(NORMAL); + + if (actOnDown && down) + { + callback(); + } + else if (!actOnDown && previousState && (down==false)) + { + callback(); + } +} + +void CAdventureMapButton::clickRight(tribool down, bool previousState) +{ + if(down && helpBox.size()) //there is no point to show window with nothing inside... + CRClickPopup::createAndPush(helpBox); +} + +void CAdventureMapButton::hover (bool on) +{ + if(hoverable) + { + if(on) + setState(HIGHLIGHTED); + else + setState(NORMAL); + } + + if(pressedL && on) + setState(PRESSED); + + std::string *name = (vstd::contains(hoverTexts,getState())) + ? (&hoverTexts[getState()]) + : (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL); + if(name && name->size() && !isBlocked()) //if there is no name, there is nohing to display also + { + if (LOCPLINT && LOCPLINT->battleInt) //for battle buttons + { + if(on && LOCPLINT->battleInt->console->alterTxt == "") + { + LOCPLINT->battleInt->console->alterTxt = *name; + LOCPLINT->battleInt->console->whoSetAlter = 1; + } + else if (LOCPLINT->battleInt->console->alterTxt == *name) + { + LOCPLINT->battleInt->console->alterTxt = ""; + LOCPLINT->battleInt->console->whoSetAlter = 0; + } + } + else if(GH.statusbar) //for other buttons + { + if (on) + GH.statusbar->print(*name); + else if ( GH.statusbar->getCurrent()==(*name) ) + GH.statusbar->clear(); + } + } +} + +void CAdventureMapButton::init(const CFunctionList &Callback, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key) +{ + currentImage = -1; + used = LCLICK | RCLICK | HOVER | KEYBOARD; + callback = Callback; + hoverable = actOnDown = borderEnabled = soundDisabled = false; + borderColor.unused = 1; // represents a transparent color, used for HighlightableButton + assignedKeys.insert(key); + hoverTexts = Name; + helpBox=HelpBox; + + pos.x += x; + pos.y += y; + + if (!defName.empty()) + imageNames.push_back(defName); + if (add) + for (size_t i=0; isize();i++ ) + imageNames.push_back(add->at(i)); + setIndex(0, playerColoredButton); +} + +void CAdventureMapButton::setIndex(size_t index, bool playerColoredButton) +{ + if (index == currentImage || index>=imageNames.size()) + return; + currentImage = index; + setImage(new CAnimation(imageNames[index]), playerColoredButton); +} + +void CAdventureMapButton::setImage(CAnimation* anim, bool playerColoredButton) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + + if (image && active) + image->deactivate(); + delChild(image); + image = new CAnimImage(anim, getState()); + if (active) + image->activate(); + if (playerColoredButton) + image->playerColored(LOCPLINT->playerID); + + pos.w = image->pos.w; + pos.h = image->pos.h; +} + +void CAdventureMapButton::setPlayerColor(int player) +{ + if (image) + image->playerColored(player); +} + +void CAdventureMapButton::showAll(SDL_Surface * to) +{ + CIntObject::showAll(to); + + if (borderEnabled && borderColor.unused == 0) + CSDL_Ext::drawBorder(to, pos.x - 1, pos.y - 1, pos.w + 2, pos.h + 2, int3(borderColor.r, borderColor.g, borderColor.b)); +} + +void CHighlightableButton::select(bool on) +{ + selected = on; + if (on) + { + setState(HIGHLIGHTED); + callback(); + borderEnabled = true; + } + else + { + setState(NORMAL); + callback2(); + borderEnabled = false; + } + + if(hoverTexts.size()>1) + { + hover(false); + hover(true); + } +} + +void CHighlightableButton::clickLeft(tribool down, bool previousState) +{ + if(isBlocked()) + return; + + if (down && !(onlyOn && isHighlighted())) + { + CCS->soundh->playSound(soundBase::button); + setState(PRESSED); + } + + if(previousState && down == false && getState() == PRESSED) + { + //if(!onlyOn || !isHighlighted()) + select(!selected); + } +} + +CHighlightableButton::CHighlightableButton( const CFunctionList &onSelect, const CFunctionList &onDeselect, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key) +: onlyOn(false), selected(false), callback2(onDeselect) +{ + init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,key); +} + +CHighlightableButton::CHighlightableButton( const std::pair &help, const CFunctionList &onSelect, int x, int y, const std::string &defName, int myid, int key/*=0*/, std::vector * add /*= NULL*/, bool playerColoredButton /*= false */ ) +: onlyOn(false), selected(false) // TODO: callback2(???) +{ + ID = myid; + std::map pom; + pom[0] = help.first; + init(onSelect, pom, help.second, playerColoredButton, defName, add, x, y, key); +} + +CHighlightableButton::CHighlightableButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &onSelect, int x, int y, const std::string &defName, int myid, int key/*=0*/, std::vector * add /*= NULL*/, bool playerColoredButton /*= false */ ) +: onlyOn(false), selected(false) // TODO: callback2(???) +{ + ID = myid; + std::map pom; + pom[0] = Name; + init(onSelect, pom,HelpBox, playerColoredButton, defName, add, x, y, key); +} + +void CHighlightableButtonsGroup::addButton(CHighlightableButton* bt) +{ + if (bt->parent) + bt->parent->removeChild(bt); + addChild(bt); + bt->recActions = defActions;//FIXME: not needed? + + bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID); + bt->onlyOn = true; + buttons.push_back(bt); +} + +void CHighlightableButtonsGroup::addButton(const std::map &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList &OnSelect, int key) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + CHighlightableButton *bt = new CHighlightableButton(OnSelect, 0, tooltip, HelpBox, false, defName, 0, x, y, key); + if(musicLike) + { + if (buttons.size() > 3) + bt->setOffset(buttons.size()-3); + } + bt->ID = uid; + bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID); + bt->onlyOn = true; + buttons.push_back(bt); +} + +CHighlightableButtonsGroup::CHighlightableButtonsGroup(const CFunctionList2 &OnChange, bool musicLikeButtons) +: onChange(OnChange), musicLike(musicLikeButtons) +{} + +CHighlightableButtonsGroup::~CHighlightableButtonsGroup() +{ + +} + +void CHighlightableButtonsGroup::select(int id, bool mode) +{ + CHighlightableButton *bt = NULL; + if(mode) + { + for(size_t i=0;iID == id) + bt = buttons[i]; + } + else + { + bt = buttons[id]; + } + bt->select(true); + selectionChanged(bt->ID); +} + +void CHighlightableButtonsGroup::selectionChanged(int to) +{ + for(size_t i=0;iID!=to && buttons[i]->isHighlighted()) + buttons[i]->select(false); + onChange(to); + if (parent) + parent->redraw(); +} + +void CHighlightableButtonsGroup::show(SDL_Surface * to) +{ + if (musicLike) + { + for(size_t i=0;iisHighlighted()) + buttons[i]->show(to); + } + else + CIntObject::show(to); +} + +void CHighlightableButtonsGroup::showAll(SDL_Surface * to) +{ + if (musicLike) + { + for(size_t i=0;iisHighlighted()) + buttons[i]->showAll(to); + } + else + CIntObject::showAll(to); +} + +void CHighlightableButtonsGroup::block( ui8 on ) +{ + for(size_t i=0;iblock(on); + } +} + +void CSlider::sliderClicked() +{ + if(!(active & MOVE)) + { + activateMouseMove(); + used |= MOVE; + } +} + +void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent) +{ + double v = 0; + if(horizontal) + { + if( std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2+40 || std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2 ) + return; + v = sEvent.x - pos.x - 24; + v *= positions; + v /= (pos.w - 48); + } + else + { + if(std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2+40 || std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2 ) + return; + v = sEvent.y - pos.y - 24; + v *= positions; + v /= (pos.h - 48); + } + v += 0.5; + if(v!=value) + { + moveTo(v); + redrawSlider(); + } +} + +void CSlider::redrawSlider() +{ + //slider->show(screenBuf); +} + +void CSlider::moveLeft() +{ + moveTo(value-1); +} + +void CSlider::moveRight() +{ + moveTo(value+1); +} + +void CSlider::moveTo(int to) +{ + vstd::amax(to, 0); + vstd::amin(to, positions); + + //same, old position? + if(value == to) + return; + + value = to; + if(horizontal) + { + if(positions) + { + double part = static_cast(to) / positions; + part*=(pos.w-48); + int newPos = part + pos.x + 16 - slider->pos.x; + slider->moveBy(Point(newPos, 0)); + } + else + slider->moveTo(Point(pos.x+16, pos.y)); + } + else + { + if(positions) + { + double part = static_cast(to) / positions; + part*=(pos.h-48); + int newPos = part + pos.y + 16 - slider->pos.y; + slider->moveBy(Point(0, newPos)); + } + else + slider->moveTo(Point(pos.x, pos.y+16)); + } + + if(moved) + moved(to); +} + +void CSlider::clickLeft(tribool down, bool previousState) +{ + if(down && !slider->isBlocked()) + { + double pw = 0; + double rw = 0; + if(horizontal) + { + pw = GH.current->motion.x-pos.x-25; + rw = pw / static_cast(pos.w - 48); + } + else + { + pw = GH.current->motion.y-pos.y-24; + rw = pw / (pos.h-48); + } + if(pw < -8 || pw > (horizontal ? pos.w : pos.h) - 40) + return; + // if (rw>1) return; + // if (rw<0) return; + slider->clickLeft(true, slider->pressedL); + moveTo(rw * positions + 0.5); + return; + } + if(active & MOVE) + { + deactivateMouseMove(); + used &= ~MOVE; + } +} + +CSlider::~CSlider() +{ + +} + +CSlider::CSlider(int x, int y, int totalw, boost::function Moved, int Capacity, int Amount, int Value, bool Horizontal, int style) +:capacity(Capacity),amount(Amount),horizontal(Horizontal), moved(Moved) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + setAmount(amount); + + used = LCLICK; + strongInterest = true; + + + left = new CAdventureMapButton(); + right = new CAdventureMapButton(); + slider = new CAdventureMapButton(); + + pos.x += x; + pos.y += y; + + if(horizontal) + { + left->pos.y = slider->pos.y = right->pos.y = pos.y; + left->pos.x = pos.x; + right->pos.x = pos.x + totalw - 16; + } + else + { + left->pos.x = slider->pos.x = right->pos.x = pos.x; + left->pos.y = pos.y; + right->pos.y = pos.y + totalw - 16; + } + + left->callback = boost::bind(&CSlider::moveLeft,this); + right->callback = boost::bind(&CSlider::moveRight,this); + slider->callback = boost::bind(&CSlider::sliderClicked,this); + left->pos.w = left->pos.h = right->pos.w = right->pos.h = slider->pos.w = slider->pos.h = 16; + if(horizontal) + { + pos.h = 16; + pos.w = totalw; + } + else + { + pos.w = 16; + pos.h = totalw; + } + + if(style == 0) + { + std::string name = horizontal?"IGPCRDIV.DEF":"OVBUTN2.DEF"; + CAnimation *animLeft = new CAnimation(name); + left->setImage(animLeft); + left->setOffset(0); + + CAnimation *animRight = new CAnimation(name); + right->setImage(animRight); + right->setOffset(2); + + CAnimation *animSlider = new CAnimation(name); + slider->setImage(animSlider); + slider->setOffset(4); + } + else + { + left->setImage(new CAnimation(horizontal ? "SCNRBLF.DEF" : "SCNRBUP.DEF")); + right->setImage(new CAnimation(horizontal ? "SCNRBRT.DEF" : "SCNRBDN.DEF")); + slider->setImage(new CAnimation("SCNRBSL.DEF")); + } + slider->actOnDown = true; + slider->soundDisabled = true; + left->soundDisabled = true; + right->soundDisabled = true; + + value = -1; + moveTo(Value); +} + +void CSlider::block( bool on ) +{ + left->block(on); + right->block(on); + slider->block(on); +} + +void CSlider::setAmount( int to ) +{ + amount = to; + positions = to - capacity; + vstd::amax(positions, 0); +} + +void CSlider::showAll(SDL_Surface * to) +{ + CSDL_Ext::fillRect(to, &pos, 0); + CIntObject::showAll(to); +} + +void CSlider::wheelScrolled(bool down, bool in) +{ + moveTo(value + 3 * (down ? +1 : -1)); +} + +void CSlider::keyPressed(const SDL_KeyboardEvent & key) +{ + if(key.state != SDL_PRESSED) return; + + int moveDest = 0; + switch(key.keysym.sym) + { + case SDLK_UP: + moveDest = value - 1; + break; + case SDLK_DOWN: + moveDest = value + 1; + break; + case SDLK_PAGEUP: + moveDest = value - capacity + 1; + break; + case SDLK_PAGEDOWN: + moveDest = value + capacity - 1; + break; + case SDLK_HOME: + moveDest = 0; + break; + case SDLK_END: + moveDest = amount - capacity; + break; + default: + return; + } + + moveTo(moveDest); +} + +void CSlider::moveToMax() +{ + moveTo(amount); +} + +static void intDeleter(CIntObject* object) +{ + delete object; +} + +CObjectList::CObjectList(CreateFunc create, DestroyFunc destroy): +createObject(create), +destroyObject(destroy) +{ + if (!destroyObject) + destroyObject = intDeleter; +} + +void CObjectList::deleteItem(CIntObject* item) +{ + if (!item) + return; + if (active) + item->deactivate(); + removeChild(item); + destroyObject(item); +} + +CIntObject* CObjectList::createItem(size_t index) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + CIntObject * item = createObject(index); + if (item == NULL) + item = new CIntObject(); + + item->recActions = defActions; + + //May happen if object was created before call to getObject() + if(item->parent != this) + { + if (item->parent) + CGuiHandler::moveChild(item, item->parent, this); + else + addChild(item); + } + + if (item && active) + item->activate(); + return item; +} + +CTabbedInt::CTabbedInt(CreateFunc create, DestroyFunc destroy, Point position, size_t ActiveID): +CObjectList(create, destroy), +activeTab(NULL), +activeID(ActiveID) +{ + pos += position; + reset(); +} + +void CTabbedInt::setActive(size_t which) +{ + if (which != activeID) + { + activeID = which; + reset(); + } +} + +void CTabbedInt::reset() +{ + deleteItem(activeTab); + activeTab = createItem(activeID); + activeTab->moveTo(pos.topLeft()); + + if (active) + redraw(); +} + +CIntObject * CTabbedInt::getItem() +{ + return activeTab; +} + +CListBox::CListBox(CreateFunc create, DestroyFunc destroy, Point Pos, Point ItemOffset, size_t VisibleSize, + size_t TotalSize, size_t InitialPos, int Slider, Rect SliderPos): +CObjectList(create, destroy), +first(InitialPos), +totalSize(TotalSize), +itemOffset(ItemOffset) +{ + pos += Pos; + items.resize(VisibleSize, NULL); + + if (Slider & 1) + { + OBJ_CONSTRUCTION_CAPTURING_ALL; + slider = new CSlider(SliderPos.x, SliderPos.y, SliderPos.w, boost::bind(&CListBox::moveToPos, this, _1), + VisibleSize, TotalSize, InitialPos, Slider & 2, Slider & 4); + } + reset(); +} + +// Used to move active items after changing list position +void CListBox::updatePositions() +{ + Point itemPos = pos.topLeft(); + for (std::list::iterator it = items.begin(); it!=items.end(); it++) + { + (*it)->moveTo(itemPos); + itemPos += itemOffset; + } + if (active) + { + redraw(); + if (slider) + slider->moveTo(first); + } +} + +void CListBox::reset() +{ + size_t current = first; + for (std::list::iterator it = items.begin(); it!=items.end(); it++) + { + deleteItem(*it); + *it = createItem(current++); + } + updatePositions(); +} + +void CListBox::moveToPos(size_t which) +{ + //Calculate new position + size_t maxPossible; + if (totalSize > items.size()) + maxPossible = totalSize - items.size(); + else + maxPossible = 0; + + size_t newPos = std::min(which, maxPossible); + + //If move distance is 1 (most of calls from Slider) - use faster shifts instead of resetting all items + if (first - newPos == 1) + moveToPrev(); + else if (newPos - first == 1) + moveToNext(); + else if (newPos != first) + { + first = newPos; + reset(); + } +} + +void CListBox::moveToNext() +{ + //Remove front item and insert new one to end + if (first + items.size() < totalSize) + { + first++; + deleteItem(items.front()); + items.pop_front(); + items.push_back(createItem(first+items.size())); + updatePositions(); + } +} + +void CListBox::moveToPrev() +{ + //Remove last item and insert new one at start + if (first) + { + first--; + deleteItem(items.back()); + items.pop_back(); + items.push_front(createItem(first)); + updatePositions(); + } +} + +std::list CListBox::getItems() +{ + return items; +} + +void CSimpleWindow::show(SDL_Surface * to) +{ + if(bitmap) + blitAt(bitmap,pos.x,pos.y,to); +} +CSimpleWindow::~CSimpleWindow() +{ + if (bitmap) + { + SDL_FreeSurface(bitmap); + bitmap=NULL; + } +} + +CStatusBar::CStatusBar(int x, int y, std::string name, int maxw) +{ + bg=BitmapHandler::loadBitmap(name); + SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); + pos.x += x; + pos.y += y; + if(maxw >= 0) + pos.w = std::min(bg->w,maxw); + else + pos.w=bg->w; + pos.h=bg->h; + middlex=(pos.w/2)+pos.x; + middley=(bg->h/2)+pos.y; +} + +CStatusBar::~CStatusBar() +{ + SDL_FreeSurface(bg); +} + +void CStatusBar::clear() +{ + if(LOCPLINT->cingconsole->enteredText == "") //for appropriate support for in-game console + { + current=""; + redraw(); + } +} + +void CStatusBar::print(const std::string & text) +{ + if(LOCPLINT->cingconsole->enteredText == "" || text == LOCPLINT->cingconsole->enteredText) //for appropriate support for in-game console + { + current=text; + redraw(); + } +} + +void CStatusBar::show(SDL_Surface * to) +{ + SDL_Rect srcRect = genRect(pos.h,pos.w,0,0); + SDL_Rect dstRect = genRect(pos.h,pos.w,pos.x,pos.y); + CSDL_Ext::blitSurface(bg,&srcRect,to,&dstRect); + CSDL_Ext::printAtMiddle(current,middlex,middley,FONT_SMALL,Colors::Cornsilk,to); +} + +std::string CStatusBar::getCurrent() +{ + return current; +} + +void CList::activate() +{ + activateLClick(); + activateRClick(); + activateHover(); + activateKeys(); + activateMouseMove(); +}; + +void CList::deactivate() +{ + deactivateLClick(); + deactivateRClick(); + deactivateHover(); + deactivateKeys(); + deactivateMouseMove(); +}; + +void CList::clickLeft(tribool down, bool previousState) +{ +}; + +CList::CList(int Size) +:SIZE(Size) +{ +} + +void CList::fixPos() +{ + if(selected < 0) //no selection, do nothing + return; + if(selected < from) //scroll up + from = selected; + else if(from + SIZE <= selected) + from = selected - SIZE + 1; + + vstd::amin(from, size() - SIZE); + vstd::amax(from, 0); + draw(screen); +} + +void CHoverableArea::hover (bool on) +{ + if (on) + GH.statusbar->print(hoverText); + else if (GH.statusbar->getCurrent()==hoverText) + GH.statusbar->clear(); +} + +CHoverableArea::CHoverableArea() +{ + used |= HOVER; +} + +CHoverableArea::~CHoverableArea() +{ +} + +void LRClickableAreaWText::clickLeft(tribool down, bool previousState) +{ + if(!down && previousState) + { + LOCPLINT->showInfoDialog(text); + } +} +void LRClickableAreaWText::clickRight(tribool down, bool previousState) +{ + adventureInt->handleRightClick(text, down); +} + +LRClickableAreaWText::LRClickableAreaWText() +{ + init(); +} + +LRClickableAreaWText::LRClickableAreaWText(const Rect &Pos, const std::string &HoverText /*= ""*/, const std::string &ClickText /*= ""*/) +{ + init(); + pos = Pos + pos; + hoverText = HoverText; + text = ClickText; +} + +LRClickableAreaWText::~LRClickableAreaWText() +{ +} + +void LRClickableAreaWText::init() +{ + used = LCLICK | RCLICK | HOVER; +} + +void CLabel::showAll(SDL_Surface * to) +{ + CIntObject::showAll(to); + std::string *hlpText = NULL; //if NULL, text field will be used + if(ignoreLeadingWhitespace) + { + hlpText = new std::string(text); + boost::trim_left(*hlpText); + } + + std::string &toPrint = hlpText ? *hlpText : text; + if(!toPrint.length()) + return; + + static void (*printer[3])(const std::string &, int, int, EFonts, SDL_Color, SDL_Surface *) = {&CSDL_Ext::printAt, &CSDL_Ext::printAtMiddle, &CSDL_Ext::printTo}; //array of printing functions + printer[alignment](toPrint, pos.x + textOffset.x, pos.y + textOffset.y, font, color, to); +} + +CLabel::CLabel(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment Align, const SDL_Color &Color /*= Colors::Cornsilk*/, const std::string &Text /*= ""*/) +:alignment(Align), font(Font), color(Color), text(Text) +{ + autoRedraw = true; + pos.x += x; + pos.y += y; + pos.w = pos.h = 0; + bg = NULL; + ignoreLeadingWhitespace = false; +} + +void CLabel::setTxt(const std::string &Txt) +{ + text = Txt; + if(autoRedraw) + { + if(bg || !parent) + redraw(); + else + parent->redraw(); + } +} + +CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= Colors::Cornsilk*/) +:CLabel(rect.x, rect.y, Font, Align, Color, Text), sliderStyle(SliderStyle), slider(NULL) +{ + redrawParentOnScrolling = false; + autoRedraw = false; + pos.h = rect.h; + pos.w = rect.w; + assert(Align == TOPLEFT || Align == CENTER); //TODO: support for other alignments + assert(pos.w >= 80); //we need some space + setTxt(Text); +} + +void CTextBox::showAll(SDL_Surface * to) +{ + CIntObject::showAll(to); + + const Font &f = *graphics->fonts[font]; + int dy = f.height; //line height + int base_y = pos.y; + if(alignment == CENTER) + base_y += std::max((pos.h - maxH)/2,0); + + int howManyLinesToPrint = slider ? slider->capacity : lines.size(); + int firstLineToPrint = slider ? slider->value : 0; + + for (int i = 0; i < howManyLinesToPrint; i++) + { + const std::string &line = lines[i + firstLineToPrint]; + if(!line.size()) continue; + + int x = pos.x; + if(alignment == CENTER) + { + x += (pos.w - f.getWidth(line.c_str())) / 2; + if(slider) + x -= slider->pos.w / 2 + 5; + } + + if(line[0] == '{' && line[line.size()-1] == '}') + CSDL_Ext::printAt(line, x, base_y + i*dy, font, Colors::Jasmine, to); + else + CSDL_Ext::printAt(line, x, base_y + i*dy, font, color, to); + } + +} + +void CTextBox::setTxt(const std::string &Txt) +{ + recalculateLines(Txt); + CLabel::setTxt(Txt); +} + +void CTextBox::sliderMoved(int to) +{ + if(!slider) + return; + + if(redrawParentOnScrolling) + parent->redraw(); + redraw(); +} + +void CTextBox::setBounds(int limitW, int limitH) +{ + pos.h = limitH; + pos.w = limitW; + recalculateLines(text); +} + +void CTextBox::recalculateLines(const std::string &Txt) +{ + delChildNUll(slider, true); + lines.clear(); + + const Font &f = *graphics->fonts[font]; + int lineHeight = f.height; + int lineCapacity = pos.h / lineHeight; + + lines = CMessage::breakText(Txt, pos.w, font); + if(lines.size() > lineCapacity) //we need to add a slider + { + lines = CMessage::breakText(Txt, pos.w - 32 - 10, font); + OBJ_CONSTRUCTION_CAPTURING_ALL; + slider = new CSlider(pos.w - 32, 0, pos.h, boost::bind(&CTextBox::sliderMoved, this, _1), lineCapacity, lines.size(), 0, false, sliderStyle); + if(active) + slider->activate(); + } + + maxH = lineHeight * lines.size(); + maxW = 0; + BOOST_FOREACH(const std::string &line, lines) + vstd::amax(maxW, f.getWidth(line.c_str())); +} + +void CGStatusBar::print(const std::string & Text) +{ + setTxt(Text); +} + +void CGStatusBar::clear() +{ + setTxt(""); +} + +std::string CGStatusBar::getCurrent() +{ + return text; +} + +CGStatusBar::CGStatusBar(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment Align, const SDL_Color &Color /*= Colors::Cornsilk*/, const std::string &Text /*= ""*/) +: CLabel(x, y, Font, Align, Color, Text) +{ + init(); +} + +CGStatusBar::CGStatusBar(CPicture *BG, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= CENTER*/, const SDL_Color &Color /*= Colors::Cornsilk*/) +: CLabel(BG->pos.x, BG->pos.y, Font, Align, Color, "") +{ + init(); + bg = BG; + CGuiHandler::moveChild(bg, bg->parent, this); + pos = bg->pos; + calcOffset(); +} + +CGStatusBar::CGStatusBar(int x, int y, std::string name/*="ADROLLVR.bmp"*/, int maxw/*=-1*/) +: CLabel(x, y, FONT_SMALL, CENTER) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + init(); + bg = new CPicture(name); + pos = bg->pos; + if(maxw < pos.w) + { + vstd::amin(pos.w, maxw); + bg->srcRect = new Rect(0, 0, maxw, pos.h); + } + calcOffset(); +} + +CGStatusBar::~CGStatusBar() +{ + GH.statusbar = oldStatusBar; +} + +void CGStatusBar::show(SDL_Surface * to) +{ + +} + +void CGStatusBar::init() +{ + oldStatusBar = GH.statusbar; + GH.statusbar = this; +} + +void CGStatusBar::calcOffset() +{ + switch(alignment) + { + case CENTER: + textOffset = Point(pos.w/2, pos.h/2); + break; + case BOTTOMRIGHT: + textOffset = Point(pos.w, pos.h); + break; + } +} + +CTextInput::CTextInput( const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList &CB ) +:cb(CB) +{ + focus = false; + pos += Pos; + captureAllKeys = true; + OBJ_CONSTRUCTION; + bg = new CPicture(bgName, bgOffset.x, bgOffset.y); + used = LCLICK | KEYBOARD; + giveFocus(); +} + +CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf) +{ + focus = false; + pos += Pos; + captureAllKeys = true; + OBJ_CONSTRUCTION; + bg = new CPicture(Pos, 0, true); + Rect hlp = Pos; + if(srf) + CSDL_Ext::blitSurface(srf, &hlp, *bg, NULL); + else + SDL_FillRect(*bg, NULL, 0); + pos.w = bg->pos.w; + pos.h = bg->pos.h; + bg->pos = pos; + used = LCLICK | KEYBOARD; + giveFocus(); +} + +void CTextInput::showAll(SDL_Surface * to) +{ + CIntObject::showAll(to); + const std::string toPrint = focus ? text + "_" : text; + CSDL_Ext::printAt(toPrint, pos.x, pos.y, FONT_SMALL, Colors::Cornsilk, to); +} + +void CTextInput::clickLeft( tribool down, bool previousState ) +{ + if(down && !focus) + giveFocus(); +} + +void CTextInput::keyPressed( const SDL_KeyboardEvent & key ) +{ + if(!focus || key.state != SDL_PRESSED) + return; + + if(key.keysym.sym == SDLK_TAB) + { + moveFocus(); + GH.breakEventHandling(); + return; + } + + switch(key.keysym.sym) + { + case SDLK_BACKSPACE: + if(text.size()) + text.resize(text.size()-1); + break; + default: + char c = key.keysym.unicode; //TODO 16-/>8 + static const std::string forbiddenChars = "<>:\"/\\|?*"; //if we are entering a filename, some special characters won't be allowed + if(!vstd::contains(forbiddenChars,c) && std::isprint(c)) + text += c; + break; + } + redraw(); + cb(text); +} + +void CTextInput::setText( const std::string &nText, bool callCb ) +{ + text = nText; + redraw(); + if(callCb) + cb(text); +} + +CTextInput::~CTextInput() +{ +} + +CFocusable::CFocusable() +{ + focusables.push_back(this); +} + +CFocusable::~CFocusable() +{ + if(inputWithFocus == this) + inputWithFocus = NULL; + + focusables -= this; +} +void CFocusable::giveFocus() +{ + if(inputWithFocus) + { + inputWithFocus->focus = false; + inputWithFocus->redraw(); + } + + focus = true; + inputWithFocus = this; + redraw(); +} + +void CFocusable::moveFocus() +{ + std::list::iterator i = vstd::find(focusables, this), + ourIt = i; + for(i++; i != ourIt; i++) + { + if(i == focusables.end()) + i = focusables.begin(); + + if((*i)->active) + { + (*i)->giveFocus(); + break;; + } + } +} \ No newline at end of file diff --git a/client/UIFramework/CIntObjectClasses.h b/client/UIFramework/CIntObjectClasses.h new file mode 100644 index 000000000..64c931eb0 --- /dev/null +++ b/client/UIFramework/CIntObjectClasses.h @@ -0,0 +1,450 @@ +#pragma once + +#include "CIntObject.h" +#include "SDL_Extensions.h" +#include "../FunctionList.h" + +struct SDL_Surface; +struct Rect; +class CAnimImage; +class CLabel; +class CAnimation; +class CDefHandler; + +/* + * CPicture.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +// Window GUI class +class CSimpleWindow : public CIntObject +{ +public: + SDL_Surface * bitmap; //background + virtual void show(SDL_Surface * to); + CSimpleWindow():bitmap(NULL){}; //c-tor + virtual ~CSimpleWindow(); //d-tor +}; + +// Image class +class CPicture : public CIntObject +{ +public: + SDL_Surface * bg; + Rect * srcRect; //if NULL then whole surface will be used + bool freeSurf; //whether surface will be freed upon CPicture destruction + bool needRefresh;//Surface needs to be displayed each frame + + operator SDL_Surface*() + { + return bg; + } + + CPicture(const Rect & r, const SDL_Color & color, bool screenFormat = false); //rect filled with given color + CPicture(const Rect & r, ui32 color, bool screenFormat = false); //rect filled with given color + CPicture(SDL_Surface * BG, int x = 0, int y=0, bool Free = true); //wrap existing SDL_Surface + CPicture(const std::string &bmpname, int x=0, int y=0); + CPicture(SDL_Surface *BG, const Rect &SrcRext, int x = 0, int y = 0, bool free = false); //wrap subrect of given surface + ~CPicture(); + void init(); + + void createSimpleRect(const Rect &r, bool screenFormat, ui32 color); + void show(SDL_Surface * to); + void showAll(SDL_Surface * to); + void convertToScreenBPP(); + void colorizeAndConvert(int player); + void colorize(int player); +}; + +namespace config{struct ButtonInfo;} + +/// Base class for buttons. +class CButtonBase : public CKeyShortcut +{ +public: + enum ButtonState + { + NORMAL=0, + PRESSED=1, + BLOCKED=2, + HIGHLIGHTED=3 + }; +private: + int bitmapOffset; // base offset of visible bitmap from animation + ButtonState state;//current state of button from enum + +public: + bool swappedImages,//fix for some buttons: normal and pressed image are swapped + keepFrame; // don't change visual representation + + void addTextOverlay(const std::string &Text, EFonts font, SDL_Color color = Colors::Cornsilk); + void update();//to refresh button after image or text change + + void setOffset(int newOffset); + void setState(ButtonState newState); + ButtonState getState(); + + //just to make code clearer + void block(bool on); + bool isBlocked(); + bool isHighlighted(); + + CAnimImage * image; //image for this button + CLabel * text;//text overlay + + CButtonBase(); //c-tor + virtual ~CButtonBase(); //d-tor +}; + +/// Typical Heroes 3 button which can be inactive or active and can +/// hold further information if you right-click it +class CAdventureMapButton : public CButtonBase +{ + std::vector imageNames;//store list of images that can be used by this button + size_t currentImage; +public: + std::map hoverTexts; //text for statusbar + std::string helpBox; //for right-click help + CFunctionList callback; + bool actOnDown,//runs when mouse is pressed down over it, not when up + hoverable,//if true, button will be highlighted when hovered + borderEnabled, + soundDisabled; + SDL_Color borderColor; + + void clickRight(tribool down, bool previousState); + virtual void clickLeft(tribool down, bool previousState); + void hover (bool on); + + CAdventureMapButton(); //c-tor + CAdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, int x, int y, const std::string &defName, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor + CAdventureMapButton( const std::pair &help, const CFunctionList &Callback, int x, int y, const std::string &defName, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor + CAdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, config::ButtonInfo *info, int key=0);//c-tor + + void init(const CFunctionList &Callback, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key ); + + void setIndex(size_t index, bool playerColoredButton=false); + void setImage(CAnimation* anim, bool playerColoredButton=false); + void setPlayerColor(int player); + void showAll(SDL_Surface * to); +}; + +/// A button which can be selected/deselected +class CHighlightableButton + : public CAdventureMapButton +{ +public: + CHighlightableButton(const CFunctionList &onSelect, const CFunctionList &onDeselect, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key=0); + CHighlightableButton(const std::pair &help, const CFunctionList &onSelect, int x, int y, const std::string &defName, int myid, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor + CHighlightableButton(const std::string &Name, const std::string &HelpBox, const CFunctionList &onSelect, int x, int y, const std::string &defName, int myid, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor + bool onlyOn;//button can not be de-selected + bool selected;//state of highlightable button + int ID; //for identification + CFunctionList callback2; //when de-selecting + void select(bool on); + void clickLeft(tribool down, bool previousState); +}; + +/// A group of buttons where one button can be selected +class CHighlightableButtonsGroup : public CIntObject +{ +public: + CFunctionList2 onChange; //called when changing selected button with new button's id + std::vector buttons; + bool musicLike; //determines the behaviour of this group + + //void addButton(const std::map &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid); + void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor + void addButton(const std::map &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList &OnSelect=0, int key=0); //creates new button + CHighlightableButtonsGroup(const CFunctionList2 &OnChange, bool musicLikeButtons = false); + ~CHighlightableButtonsGroup(); + void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id + void selectionChanged(int to); + void show(SDL_Surface * to); + void showAll(SDL_Surface * to); + void block(ui8 on); +}; + +/// A typical slider which can be orientated horizontally/vertically. +class CSlider : public CIntObject +{ +public: + CAdventureMapButton *left, *right, *slider; //if vertical then left=up + int capacity,//how many elements can be active at same time + amount, //how many elements + positions, //number of highest position (0 if there is only one) + value; //first active element + bool horizontal; + bool wheelScrolling; + bool keyScrolling; + + boost::function moved; + + void redrawSlider(); + void sliderClicked(); + void moveLeft(); + void moveRight(); + void moveTo(int to); + void block(bool on); + void setAmount(int to); + + void keyPressed(const SDL_KeyboardEvent & key); + void wheelScrolled(bool down, bool in); + void clickLeft(tribool down, bool previousState); + void mouseMoved (const SDL_MouseMotionEvent & sEvent); + void showAll(SDL_Surface * to); + + CSlider(int x, int y, int totalw, boost::function Moved, int Capacity, int Amount, + int Value=0, bool Horizontal=true, int style = 0); //style 0 - brown, 1 - blue + ~CSlider(); + void moveToMax(); +}; + +/// Used as base for Tabs and List classes +class CObjectList : public CIntObject +{ +public: + typedef boost::function CreateFunc; + typedef boost::function DestroyFunc; + +private: + CreateFunc createObject; + DestroyFunc destroyObject; + +protected: + //Internal methods for safe creation of items (Children capturing and activation/deactivation if needed) + void deleteItem(CIntObject* item); + CIntObject* createItem(size_t index); + + CObjectList(CreateFunc create, DestroyFunc destroy = DestroyFunc());//Protected constructor +}; + +/// Window element with multiple tabs +class CTabbedInt : public CObjectList +{ +private: + CIntObject * activeTab; + size_t activeID; + +public: + //CreateFunc, DestroyFunc - see CObjectList + //Pos - position of object, all tabs will be moved to this position + //ActiveID - ID of initially active tab + CTabbedInt(CreateFunc create, DestroyFunc destroy = DestroyFunc(), Point position=Point(), size_t ActiveID=0); + + void setActive(size_t which); + //recreate active tab + void reset(); + + //return currently active item + CIntObject * getItem(); +}; + +/// List of IntObjects with optional slider +class CListBox : public CObjectList +{ +private: + std::list< CIntObject* > items; + size_t first; + size_t totalSize; + + Point itemOffset; + CSlider * slider; + + void updatePositions(); +public: + //CreateFunc, DestroyFunc - see CObjectList + //Pos - position of first item + //ItemOffset - distance between items in the list + //VisibleSize - maximal number of displayable at once items + //TotalSize + //Slider - slider style, bit field: 1 = present(disabled), 2=horisontal(vertical), 4=blue(brown) + //SliderPos - position of slider, if present + CListBox(CreateFunc create, DestroyFunc destroy, Point Pos, Point ItemOffset, size_t VisibleSize, + size_t TotalSize, size_t InitialPos=0, int Slider=0, Rect SliderPos=Rect() ); + + //recreate all visible items + void reset(); + + //return currently active items + std::list< CIntObject * > getItems(); + + //scroll list + void moveToPos(size_t which); + void moveToNext(); + void moveToPrev(); +}; + +/// Status bar which is shown at the bottom of the in-game screens +class CStatusBar + : public CIntObject, public IStatusBar +{ +public: + SDL_Surface * bg; //background + int middlex, middley; //middle of statusbar + std::string current; //text currently printed + + CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor + ~CStatusBar(); //d-tor + void print(const std::string & text); //prints text and refreshes statusbar + void clear();//clears statusbar and refreshes + void show(SDL_Surface * to); //shows statusbar (with current text) + std::string getCurrent(); //getter for current +}; + +/// Label which shows text +class CLabel + : public virtual CIntObject +{ +public: + EAlignment alignment; + EFonts font; + SDL_Color color; + std::string text; + CPicture *bg; + bool autoRedraw; //whether control will redraw itself on setTxt + Point textOffset; //text will be blitted at pos + textOffset with appropriate alignment + bool ignoreLeadingWhitespace; + + virtual void setTxt(const std::string &Txt); + void showAll(SDL_Surface * to); //shows statusbar (with current text) + CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk, const std::string &Text = ""); +}; + +/// a multi-line label that tries to fit text with given available width and height; if not possible, it creates a slider for scrolling text +class CTextBox + : public CLabel +{ +public: + int maxW; //longest line of text in px + int maxH; //total height needed to print all lines + + int sliderStyle; + bool redrawParentOnScrolling; + + std::vector lines; + std::vector effects; + CSlider *slider; + + //CTextBox( std::string Text, const Point &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk); + CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk); + void showAll(SDL_Surface * to); //shows statusbar (with current text) + void setTxt(const std::string &Txt); + void setBounds(int limitW, int limitH); + void recalculateLines(const std::string &Txt); + + void sliderMoved(int to); +}; + +/// Status bar which is shown at the bottom of the in-game screens +class CGStatusBar + : public CLabel, public IStatusBar +{ + void init(); +public: + IStatusBar *oldStatusBar; + + //statusbar interface overloads + void print(const std::string & Text); //prints text and refreshes statusbar + void clear();//clears statusbar and refreshes + std::string getCurrent(); //returns currently displayed text + void show(SDL_Surface * to); //shows statusbar (with current text) + + CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = Colors::Cornsilk, const std::string &Text = ""); + CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = Colors::Cornsilk); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar + CGStatusBar(int x, int y, std::string name, int maxw=-1); + + ~CGStatusBar(); + void calcOffset(); +}; + +/// UIElement which can get input focus +class CFocusable + : public virtual CIntObject +{ +public: + bool focus; //only one focusable control can have focus at one moment + + void giveFocus(); //captures focus + void moveFocus(); //moves focus to next active control (may be used for tab switching) + + static std::list focusables; //all existing objs + static CFocusable *inputWithFocus; //who has focus now + CFocusable(); + ~CFocusable(); +}; + +/// Text input box where players can enter text +class CTextInput + : public CLabel, public CFocusable +{ +public: + CFunctionList cb; + + void setText(const std::string &nText, bool callCb = false); + + CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList &CB); + CTextInput(const Rect &Pos, SDL_Surface *srf = NULL); + ~CTextInput(); + void showAll(SDL_Surface * to); + void clickLeft(tribool down, bool previousState); + void keyPressed(const SDL_KeyboardEvent & key); +}; + +/// Listbox UI Element +class CList : public CIntObject +{ +public: + SDL_Surface * bg; //background bitmap + CDefHandler *arrup, *arrdo; //button arrows for scrolling list + SDL_Surface *empty, *selection; + SDL_Rect arrupp, arrdop; //positions of arrows + int posw, posh; //position width/height + int selected, //id of selected position, <0 if none + from; + const int SIZE; //size of list + tribool pressed; //true=up; false=down; indeterminate=none + + CList(int Size = 5); //c-tor + void clickLeft(tribool down, bool previousState); + void activate(); + void deactivate(); + virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in + virtual void genList()=0; + virtual void select(int which)=0; + virtual void draw(SDL_Surface * to)=0; + virtual int size() = 0; //how many elements do we have + void fixPos(); //scrolls list, so the selection will be visible +}; + +/// Shows a text by moving the mouse cursor over the object +class CHoverableArea: public virtual CIntObject +{ +public: + std::string hoverText; + + virtual void hover (bool on); + + CHoverableArea(); + virtual ~CHoverableArea(); +}; + +/// Can interact on left and right mouse clicks, plus it shows a text when by hovering over it +class LRClickableAreaWText: public CHoverableArea +{ +public: + std::string text; + + LRClickableAreaWText(); + LRClickableAreaWText(const Rect &Pos, const std::string &HoverText = "", const std::string &ClickText = ""); + virtual ~LRClickableAreaWText(); + void init(); + + virtual void clickLeft(tribool down, bool previousState); + virtual void clickRight(tribool down, bool previousState); +}; \ No newline at end of file diff --git a/client/UIFramework/CKeyShortcut.cpp b/client/UIFramework/CKeyShortcut.cpp deleted file mode 100644 index e807fedce..000000000 --- a/client/UIFramework/CKeyShortcut.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "StdInc.h" -#include "CKeyShortcut.h" - -void CKeyShortcut::keyPressed(const SDL_KeyboardEvent & key) -{ - if(vstd::contains(assignedKeys,key.keysym.sym)) - { - bool prev = pressedL; - if(key.state == SDL_PRESSED) - { - pressedL = true; - clickLeft(true, prev); - } - else - { - pressedL = false; - clickLeft(false, prev); - } - } -} \ No newline at end of file diff --git a/client/UIFramework/CKeyShortcut.h b/client/UIFramework/CKeyShortcut.h deleted file mode 100644 index ce1d685c7..000000000 --- a/client/UIFramework/CKeyShortcut.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "CIntObject.h" - -/* - * CKeyShortcut.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -/// Class for binding keys to left mouse button clicks -/// Classes wanting use it should have it as one of their base classes -class CKeyShortcut : public virtual CIntObject -{ -public: - std::set assignedKeys; - CKeyShortcut(){}; //c-tor - CKeyShortcut(int key){assignedKeys.insert(key);}; //c-tor - CKeyShortcut(std::set Keys):assignedKeys(Keys){}; //c-tor - virtual void keyPressed(const SDL_KeyboardEvent & key); //call-in -}; \ No newline at end of file diff --git a/client/UIFramework/CPicture.cpp b/client/UIFramework/CPicture.cpp deleted file mode 100644 index e9bb738c4..000000000 --- a/client/UIFramework/CPicture.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "StdInc.h" -#include "CPicture.h" - -#include "../CBitmapHandler.h" -#include "../SDL_Extensions.h" -#include "../Graphics.h" - - -CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free ) -{ - init(); - bg = BG; - freeSurf = Free; - pos.x += x; - pos.y += y; - pos.w = BG->w; - pos.h = BG->h; -} - -CPicture::CPicture( const std::string &bmpname, int x, int y ) -{ - init(); - bg = BitmapHandler::loadBitmap(bmpname); - freeSurf = true;; - pos.x += x; - pos.y += y; - if(bg) - { - pos.w = bg->w; - pos.h = bg->h; - } - else - { - pos.w = pos.h = 0; - } -} - -CPicture::CPicture(const SRect &r, const SDL_Color &color, bool screenFormat /*= false*/) -{ - init(); - createSimpleRect(r, screenFormat, SDL_MapRGB(bg->format, color.r, color.g,color.b)); -} - -CPicture::CPicture(const SRect &r, ui32 color, bool screenFormat /*= false*/) -{ - init(); - createSimpleRect(r, screenFormat, color); -} - -CPicture::CPicture(SDL_Surface *BG, const SRect &SrcRect, int x /*= 0*/, int y /*= 0*/, bool free /*= false*/) -{ - needRefresh = false; - srcRect = new SRect(SrcRect); - pos.x += x; - pos.y += y; - pos.w = srcRect->w; - pos.h = srcRect->h; - bg = BG; - freeSurf = free; -} - -CPicture::~CPicture() -{ - if(freeSurf) - SDL_FreeSurface(bg); - delete srcRect; -} - -void CPicture::init() -{ - needRefresh = false; - srcRect = NULL; -} - -void CPicture::show( SDL_Surface * to ) -{ - if (needRefresh) - showAll(to); -} - -void CPicture::showAll( SDL_Surface * to ) -{ - if(bg) - { - if(srcRect) - { - SDL_Rect srcRectCpy = *srcRect; - SDL_Rect dstRect = srcRectCpy; - dstRect.x = pos.x; - dstRect.y = pos.y; - - CSDL_Ext::blitSurface(bg, &srcRectCpy, to, &dstRect); - } - else - blitAt(bg, pos, to); - } -} - -void CPicture::convertToScreenBPP() -{ - SDL_Surface *hlp = bg; - bg = SDL_ConvertSurface(hlp,screen->format,0); - SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); - SDL_FreeSurface(hlp); -} - -void CPicture::createSimpleRect(const SRect &r, bool screenFormat, ui32 color) -{ - pos += r; - pos.w = r.w; - pos.h = r.h; - if(screenFormat) - bg = CSDL_Ext::newSurface(r.w, r.h); - else - bg = SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 8, 0, 0, 0, 0); - - SDL_FillRect(bg, NULL, color); - freeSurf = true; -} - -void CPicture::colorizeAndConvert(int player) -{ - assert(bg); - colorize(player); - convertToScreenBPP(); -} - -void CPicture::colorize(int player) -{ - assert(bg); - assert(bg->format->BitsPerPixel == 8); - graphics->blueToPlayersAdv(bg, player); -} \ No newline at end of file diff --git a/client/UIFramework/CPicture.h b/client/UIFramework/CPicture.h deleted file mode 100644 index 581100187..000000000 --- a/client/UIFramework/CPicture.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include "CIntObject.h" - -struct SDL_Surface; -struct SRect; - -/* - * CPicture.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -// Image class -class CPicture : public CIntObject -{ -public: - SDL_Surface * bg; - SRect * srcRect; //if NULL then whole surface will be used - bool freeSurf; //whether surface will be freed upon CPicture destruction - bool needRefresh;//Surface needs to be displayed each frame - - operator SDL_Surface*() - { - return bg; - } - - CPicture(const SRect & r, const SDL_Color & color, bool screenFormat = false); //rect filled with given color - CPicture(const SRect & r, ui32 color, bool screenFormat = false); //rect filled with given color - CPicture(SDL_Surface * BG, int x = 0, int y=0, bool Free = true); //wrap existing SDL_Surface - CPicture(const std::string &bmpname, int x=0, int y=0); - CPicture(SDL_Surface *BG, const SRect &SrcRext, int x = 0, int y = 0, bool free = false); //wrap subrect of given surface - ~CPicture(); - void init(); - - void createSimpleRect(const SRect &r, bool screenFormat, ui32 color); - void show(SDL_Surface * to); - void showAll(SDL_Surface * to); - void convertToScreenBPP(); - void colorizeAndConvert(int player); - void colorize(int player); -}; \ No newline at end of file diff --git a/client/UIFramework/CSimpleWindow.h b/client/UIFramework/CSimpleWindow.h deleted file mode 100644 index d2649a602..000000000 --- a/client/UIFramework/CSimpleWindow.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "UIFramework/CIntObject.h" - -/* - * CSimpleWindow.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -// Window GUI class -class CSimpleWindow : public CIntObject -{ -public: - SDL_Surface * bitmap; //background - virtual void show(SDL_Surface * to); - CSimpleWindow():bitmap(NULL){}; //c-tor - virtual ~CSimpleWindow(); //d-tor -}; \ No newline at end of file diff --git a/client/UIFramework/Geometries.cpp b/client/UIFramework/Geometries.cpp new file mode 100644 index 000000000..d0bfdf10a --- /dev/null +++ b/client/UIFramework/Geometries.cpp @@ -0,0 +1,19 @@ +#include "StdInc.h" +#include "Geometries.h" + +extern SDL_Surface * screen; + +Rect Rect::createCentered( int w, int h ) +{ + return Rect(screen->w/2 - w/2, screen->h/2 - h/2, w, h); +} + +Rect Rect::around(const Rect &r, int width /*= 1*/) /*creates rect around another */ +{ + return Rect(r.x - width, r.y - width, r.w + width * 2, r.h + width * 2); +} + +Rect Rect::centerIn(const Rect &r) +{ + return Rect(r.x + (r.w - w) / 2, r.y + (r.h - h) / 2, w, h); +} \ No newline at end of file diff --git a/client/UIFramework/Geometries.h b/client/UIFramework/Geometries.h new file mode 100644 index 000000000..5a7aa2ceb --- /dev/null +++ b/client/UIFramework/Geometries.h @@ -0,0 +1,262 @@ +#pragma once + +#include +#include +#include "../../lib/int3.h" + +/* + * Geometries.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#ifdef max +#undef max +#endif +#ifdef min +#undef min +#endif + + +// A point with x/y coordinate, used mostly for graphic rendering +struct Point +{ + int x, y; + + //constructors + Point() + { + x = y = 0; + }; + Point(int X, int Y) + :x(X),y(Y) + {}; + Point(const int3 &a) + :x(a.x),y(a.y) + {} + Point(const SDL_MouseMotionEvent &a) + :x(a.x),y(a.y) + {} + + template + Point operator+(const T &b) const + { + return Point(x+b.x,y+b.y); + } + + template + Point operator*(const T &mul) const + { + return Point(x*mul, y*mul); + } + + template + Point& operator+=(const T &b) + { + x += b.x; + y += b.y; + return *this; + } + + template + Point operator-(const T &b) const + { + return Point(x - b.x, y - b.y); + } + + template + Point& operator-=(const T &b) + { + x -= b.x; + y -= b.y; + return *this; + } + bool operator<(const Point &b) const //product order + { + return x < b.x && y < b.y; + } + template Point& operator=(const T &t) + { + x = t.x; + y = t.y; + return *this; + } + template bool operator==(const T &t) const + { + return x == t.x && y == t.y; + } + template bool operator!=(const T &t) const + { + return !(*this == t); + } +}; + +/// Rectangle class, which have a position and a size +struct Rect : public SDL_Rect +{ + Rect()//default c-tor + { + x = y = w = h = -1; + } + Rect(int X, int Y, int W, int H) //c-tor + { + x = X; + y = Y; + w = W; + h = H; + } + Rect(const Point & position, const Point & size) //c-tor + { + x = position.x; + y = position.y; + w = size.x; + h = size.y; + } + Rect(const SDL_Rect & r) //c-tor + { + x = r.x; + y = r.y; + w = r.w; + h = r.h; + } + explicit Rect(const SDL_Surface * const &surf) + { + x = y = 0; + w = surf->w; + h = surf->h; + } + + Rect centerIn(const Rect &r); + static Rect createCentered(int w, int h); + static Rect around(const Rect &r, int width = 1); //creates rect around another + + bool isIn(int qx, int qy) const //determines if given point lies inside rect + { + if (qx > x && qxy && qy Rect operator-(const T &t) + { + return Rect(x - t.x, y - t.y, w, h); + } + Rect operator&(const Rect &p) const //rect intersection + { + bool intersect = true; + + if(p.topLeft().y < y && p.bottomLeft().y < y) //rect p is above *this + { + intersect = false; + } + else if(p.topLeft().y > y+h && p.bottomLeft().y > y+h) //rect p is below *this + { + intersect = false; + } + else if(p.topLeft().x > x+w && p.topRight().x > x+w) //rect p is on the right hand side of this + { + intersect = false; + } + else if(p.topLeft().x < x && p.topRight().x < x) //rect p is on the left hand side of this + { + intersect = false; + } + + if(intersect) + { + Rect ret; + ret.x = std::max(this->x, p.x); + ret.y = std::max(this->y, p.y); + Point bR; //bottomRight point of returned rect + bR.x = std::min(this->w+this->x, p.w+p.x); + bR.y = std::min(this->h+this->y, p.h+p.y); + ret.w = bR.x - ret.x; + ret.h = bR.y - ret.y; + return ret; + } + else + { + return Rect(); + } + } + Rect operator|(const Rect &p) const //union of two rects + { + Rect ret; + ret.x = std::min(p.x, this->x); + ret.y = std::min(p.y, this->y); + int x2 = std::max(p.x+p.w, this->x+this->w); + int y2 = std::max(p.y+p.h, this->y+this->h); + ret.w = x2 -ret.x; + ret.h = y2 -ret.y; + return ret; + } +}; \ No newline at end of file diff --git a/client/UIFramework/IActivatable.h b/client/UIFramework/IActivatable.h deleted file mode 100644 index 8608290ec..000000000 --- a/client/UIFramework/IActivatable.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -/* - * IActivatable.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -// Defines a activate/deactive method -class IActivatable -{ -public: - virtual void activate()=0; - virtual void deactivate()=0; - virtual ~IActivatable(){}; //d-tor -}; \ No newline at end of file diff --git a/client/UIFramework/IShowActivatable.h b/client/UIFramework/IShowActivatable.h deleted file mode 100644 index a448b9aeb..000000000 --- a/client/UIFramework/IShowActivatable.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "IShowable.h" -#include "IActivatable.h" - -/* - * IShowActivatable.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -class IShowActivatable : public IShowable, public IActivatable -{ -public: - //redraw parent flag - this int may be semi-transparent and require redraw of parent window - enum {WITH_GARRISON = 1, BLOCK_ADV_HOTKEYS = 2, WITH_ARTIFACTS = 4, REDRAW_PARENT=8}; - int type; //bin flags using etype - IShowActivatable(); - virtual ~IShowActivatable(){}; //d-tor -}; \ No newline at end of file diff --git a/client/UIFramework/IShowable.h b/client/UIFramework/IShowable.h deleted file mode 100644 index cb503fa3d..000000000 --- a/client/UIFramework/IShowable.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -struct SDL_Surface; - -/* - * IShowable.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -// Defines a show method -class IShowable -{ -public: - virtual void redraw()=0; - virtual void show(SDL_Surface * to)=0; - virtual void showAll(SDL_Surface * to) - { - show(to); - } - virtual ~IShowable(){}; //d-tor -}; \ No newline at end of file diff --git a/client/UIFramework/IStatusBar.h b/client/UIFramework/IStatusBar.h deleted file mode 100644 index 97973820d..000000000 --- a/client/UIFramework/IStatusBar.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -struct SDL_Surface; - -/* - * IStatusBar.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -// Status bar interface -class IStatusBar -{ -public: - virtual ~IStatusBar(){}; //d-tor - virtual void print(const std::string & text)=0; //prints text and refreshes statusbar - virtual void clear()=0;//clears statusbar and refreshes - virtual void show(SDL_Surface * to)=0; //shows statusbar (with current text) - virtual std::string getCurrent()=0; //returns currently displayed text -}; \ No newline at end of file diff --git a/client/UIFramework/IUpdateable.h b/client/UIFramework/IUpdateable.h deleted file mode 100644 index abec612fa..000000000 --- a/client/UIFramework/IUpdateable.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -/* - * IUpdateable.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -class IUpdateable -{ -public: - virtual void update()=0; - virtual ~IUpdateable(){}; //d-tor -}; \ No newline at end of file diff --git a/client/SDL_Extensions.cpp b/client/UIFramework/SDL_Extensions.cpp similarity index 94% rename from client/SDL_Extensions.cpp rename to client/UIFramework/SDL_Extensions.cpp index 92d8e87b6..e2a45f8ca 100644 --- a/client/SDL_Extensions.cpp +++ b/client/UIFramework/SDL_Extensions.cpp @@ -1,11 +1,11 @@ #include "StdInc.h" #include "SDL_Extensions.h" -#include "SDL_ttf.h" -#include "CGameInfo.h" -#include "CMessage.h" -#include "CDefHandler.h" -#include "Graphics.h" +#include +#include "../CGameInfo.h" +#include "../CMessage.h" +#include "../CDefHandler.h" +#include "../Graphics.h" /* * SDL_Extensions.cpp, part of VCMI engine @@ -17,6 +17,12 @@ * */ +SDL_Color Colors::createColor(int r, int g, int b, int a /*= 0*/) +{ + SDL_Color temp = {r, g, b, a}; + return temp; +} + template STRONG_INLINE void ColorPutter::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color) { @@ -298,7 +304,7 @@ void CSDL_Ext::printAtWB(const std::string & text, int x, int y, EFonts font, in } -void CSDL_Ext::printAtMiddleWB( const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor/*=tytulowy*/, SDL_Surface * dst/*=screen*/ ) +void CSDL_Ext::printAtMiddleWB( const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor/*=Colors::Jasmine*/, SDL_Surface * dst/*=screen*/ ) { if (graphics->fontsTrueType[font]) { @@ -347,7 +353,7 @@ void printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_ SDL_FreeSurface(temp); } -void CSDL_Ext::printAtMiddle( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ ) +void CSDL_Ext::printAtMiddle( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::Cornsilk*/, SDL_Surface * dst/*=screen*/ ) { if (graphics->fontsTrueType[font]) { @@ -395,7 +401,7 @@ void printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color -void CSDL_Ext::printAt( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ ) +void CSDL_Ext::printAt( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::Cornsilk*/, SDL_Surface * dst/*=screen*/ ) { if(!text.size()) return; @@ -488,7 +494,7 @@ void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color SDL_FreeSurface(temp); } -void CSDL_Ext::printTo( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ ) +void CSDL_Ext::printTo( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::Cornsilk*/, SDL_Surface * dst/*=screen*/ ) { if (graphics->fontsTrueType[font]) { @@ -1019,7 +1025,7 @@ void CSDL_Ext::drawBorder( SDL_Surface * sur, const SDL_Rect &r, const int3 &col drawBorder(sur, r.x, r.y, r.w, r.h, color); } -void CSDL_Ext::drawDashedBorder(SDL_Surface * sur, const SRect &r, const int3 &color) +void CSDL_Ext::drawDashedBorder(SDL_Surface * sur, const Rect &r, const int3 &color) { const int y1 = r.y, y2 = r.y + r.h-1; for (int i=0; iw, dst->h); + betterDst = Rect(0, 0, dst->w, dst->h); } SDL_BlitSurface(src, srcRect, dst, &betterDst); @@ -1285,7 +1291,7 @@ void CSDL_Ext::fillRect( SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color ) } else { - newRect = SRect(0, 0, dst->w, dst->h); + newRect = Rect(0, 0, dst->w, dst->h); } SDL_FillRect(dst, &newRect, color); } diff --git a/client/SDL_Extensions.h b/client/UIFramework/SDL_Extensions.h similarity index 88% rename from client/SDL_Extensions.h rename to client/UIFramework/SDL_Extensions.h index c42be8008..2c8624975 100644 --- a/client/SDL_Extensions.h +++ b/client/UIFramework/SDL_Extensions.h @@ -1,11 +1,10 @@ #pragma once - -#include "../lib/int3.h" -#include "SDL_video.h" -#include "SDL_ttf.h" -#include "FontBase.h" -#include "UIFramework/SRect.h" +#include +#include +#include "../../lib/int3.h" +#include "../FontBase.h" +#include "Geometries.h" /* * SDL_Extensions.h, part of VCMI engine @@ -34,12 +33,21 @@ struct Rect; extern SDL_Surface * screen, *screen2, *screenBuf; -extern SDL_Color tytulowy, tlo, zwykly ; void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen); void blitAt(SDL_Surface * src, const SDL_Rect & pos, SDL_Surface * dst=screen); void updateRect (SDL_Rect * rect, SDL_Surface * scr = screen); bool isItIn(const SDL_Rect * rect, int x, int y); +namespace Colors +{ + SDL_Color createColor(int r, int g, int b, int a = 0); + + const SDL_Color Jasmine = createColor(229, 215, 123, 0); // http://en.wikipedia.org/wiki/Jasmine_%28color%29 + const SDL_Color Cornsilk = createColor(255, 243, 222, 0); // http://en.wikipedia.org/wiki/Shades_of_white + const SDL_Color MetallicGold = createColor(173, 142, 66); // http://en.wikipedia.org/wiki/Gold_%28color%29 + const SDL_Color Maize = createColor(242, 226, 110); // http://en.wikipedia.org/wiki/Maize_%28color%29 +} + template std::string makeNumberShort(IntType number) //the output is a string containing at most 5 characters [4 if positive] (eg. intead 10000 it gives 10k) { @@ -162,16 +170,16 @@ namespace CSDL_Ext int blit8bppAlphaTo24bpp(const SDL_Surface * src, const SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface Uint32 colorToUint32(const SDL_Color * color); //little endian only - void printAtWB(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor=zwykly, SDL_Surface * dst=screen); - void printAt(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=zwykly, SDL_Surface * dst=screen); - void printTo(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=zwykly, SDL_Surface * dst=screen); - void printAtMiddle(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=zwykly, SDL_Surface * dst=screen); - void printAtMiddleWB(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen); + void printAtWB(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor=Colors::Cornsilk, SDL_Surface * dst=screen); + void printAt(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=Colors::Cornsilk, SDL_Surface * dst=screen); + void printTo(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=Colors::Cornsilk, SDL_Surface * dst=screen); + void printAtMiddle(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=Colors::Cornsilk, SDL_Surface * dst=screen); + void printAtMiddleWB(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor=Colors::Jasmine, SDL_Surface * dst=screen); void update(SDL_Surface * what = screen); //updates whole surface (default - main screen) void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color); void drawBorder(SDL_Surface * sur, const SDL_Rect &r, const int3 &color); - void drawDashedBorder(SDL_Surface * sur, const SRect &r, const int3 &color); + void drawDashedBorder(SDL_Surface * sur, const Rect &r, const int3 &color); void setPlayerColor(SDL_Surface * sur, ui8 player); //sets correct color of flags; -1 for neutral std::string processStr(std::string str, std::vector & tor); //replaces %s in string SDL_Surface * newSurface(int w, int h, SDL_Surface * mod=screen); //creates new surface, with flags/format same as in surface given diff --git a/client/UIFramework/SPoint.h b/client/UIFramework/SPoint.h deleted file mode 100644 index f722780d5..000000000 --- a/client/UIFramework/SPoint.h +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once - -#include "../../lib/int3.h" -#include - -/* - * SPoint.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -// A point with x/y coordinate, used mostly for graphic rendering -struct SPoint -{ - int x, y; - - //constructors - SPoint() - { - x = y = 0; - }; - SPoint(int X, int Y) - :x(X),y(Y) - {}; - SPoint(const int3 &a) - :x(a.x),y(a.y) - {} - SPoint(const SDL_MouseMotionEvent &a) - :x(a.x),y(a.y) - {} - - template - SPoint operator+(const T &b) const - { - return SPoint(x+b.x,y+b.y); - } - - template - SPoint operator*(const T &mul) const - { - return SPoint(x*mul, y*mul); - } - - template - SPoint& operator+=(const T &b) - { - x += b.x; - y += b.y; - return *this; - } - - template - SPoint operator-(const T &b) const - { - return SPoint(x - b.x, y - b.y); - } - - template - SPoint& operator-=(const T &b) - { - x -= b.x; - y -= b.y; - return *this; - } - bool operator<(const SPoint &b) const //product order - { - return x < b.x && y < b.y; - } - template SPoint& operator=(const T &t) - { - x = t.x; - y = t.y; - return *this; - } - template bool operator==(const T &t) const - { - return x == t.x && y == t.y; - } - template bool operator!=(const T &t) const - { - return !(*this == t); - } -}; \ No newline at end of file diff --git a/client/UIFramework/SRect.cpp b/client/UIFramework/SRect.cpp deleted file mode 100644 index b4f016dd1..000000000 --- a/client/UIFramework/SRect.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "StdInc.h" -#include "SRect.h" - -extern SDL_Surface * screen; - -SRect SRect::createCentered( int w, int h ) -{ - return SRect(screen->w/2 - w/2, screen->h/2 - h/2, w, h); -} - -SRect SRect::around(const SRect &r, int width /*= 1*/) /*creates rect around another */ -{ - return SRect(r.x - width, r.y - width, r.w + width * 2, r.h + width * 2); -} - -SRect SRect::centerIn(const SRect &r) -{ - return SRect(r.x + (r.w - w) / 2, r.y + (r.h - h) / 2, w, h); -} \ No newline at end of file diff --git a/client/UIFramework/SRect.h b/client/UIFramework/SRect.h deleted file mode 100644 index bcb005460..000000000 --- a/client/UIFramework/SRect.h +++ /dev/null @@ -1,187 +0,0 @@ -#pragma once - -#include -#include "SPoint.h" - -/* - * SRect.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -#ifdef max -#undef max -#endif -#ifdef min -#undef min -#endif - -/// Rectangle class, which have a position and a size -struct SRect : public SDL_Rect -{ - SRect()//default c-tor - { - x = y = w = h = -1; - } - SRect(int X, int Y, int W, int H) //c-tor - { - x = X; - y = Y; - w = W; - h = H; - } - SRect(const SPoint & position, const SPoint & size) //c-tor - { - x = position.x; - y = position.y; - w = size.x; - h = size.y; - } - SRect(const SDL_Rect & r) //c-tor - { - x = r.x; - y = r.y; - w = r.w; - h = r.h; - } - explicit SRect(const SDL_Surface * const &surf) - { - x = y = 0; - w = surf->w; - h = surf->h; - } - - SRect centerIn(const SRect &r); - static SRect createCentered(int w, int h); - static SRect around(const SRect &r, int width = 1); //creates rect around another - - bool isIn(int qx, int qy) const //determines if given point lies inside rect - { - if (qx > x && qxy && qy SRect operator-(const T &t) - { - return SRect(x - t.x, y - t.y, w, h); - } - SRect operator&(const SRect &p) const //rect intersection - { - bool intersect = true; - - if(p.topLeft().y < y && p.bottomLeft().y < y) //rect p is above *this - { - intersect = false; - } - else if(p.topLeft().y > y+h && p.bottomLeft().y > y+h) //rect p is below *this - { - intersect = false; - } - else if(p.topLeft().x > x+w && p.topRight().x > x+w) //rect p is on the right hand side of this - { - intersect = false; - } - else if(p.topLeft().x < x && p.topRight().x < x) //rect p is on the left hand side of this - { - intersect = false; - } - - if(intersect) - { - SRect ret; - ret.x = std::max(this->x, p.x); - ret.y = std::max(this->y, p.y); - SPoint bR; //bottomRight point of returned rect - bR.x = std::min(this->w+this->x, p.w+p.x); - bR.y = std::min(this->h+this->y, p.h+p.y); - ret.w = bR.x - ret.x; - ret.h = bR.y - ret.y; - return ret; - } - else - { - return SRect(); - } - } - SRect operator|(const SRect &p) const //union of two rects - { - SRect ret; - ret.x = std::min(p.x, this->x); - ret.y = std::min(p.y, this->y); - int x2 = std::max(p.x+p.w, this->x+this->w); - int y2 = std::max(p.y+p.h, this->y+this->h); - ret.w = x2 -ret.x; - ret.h = y2 -ret.y; - return ret; - } -}; \ No newline at end of file diff --git a/client/VCMI_client.vcxproj b/client/VCMI_client.vcxproj index 4dc7d49cf..6336b412f 100644 --- a/client/VCMI_client.vcxproj +++ b/client/VCMI_client.vcxproj @@ -219,30 +219,10 @@ - - false - false - - - - - + - - - - + - - - - - - - - - - @@ -250,7 +230,6 @@ - @@ -268,42 +247,23 @@ - - Create StdInc.h + - - - + + + - - - - - + - - - - + - - - - - - - - - - - @@ -311,7 +271,6 @@ - @@ -332,21 +291,13 @@ - - + - - - - - - - - - - + + + diff --git a/client/VCMI_client.vcxproj.filters b/client/VCMI_client.vcxproj.filters index fe0c4514f..e8f18ab62 100644 --- a/client/VCMI_client.vcxproj.filters +++ b/client/VCMI_client.vcxproj.filters @@ -1,7 +1,6 @@  - @@ -9,7 +8,6 @@ - @@ -27,62 +25,9 @@ - - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface + + UIFramework UIFramework @@ -90,16 +35,22 @@ UIFramework - + UIFramework - + UIFramework - + UIFramework - + + BattleInterface + + + BattleInterface + + BattleInterface @@ -107,7 +58,6 @@ - @@ -115,7 +65,6 @@ - @@ -136,65 +85,10 @@ - - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface - - - BattleInterface + + + UIFramework UIFramework @@ -202,38 +96,22 @@ UIFramework - + UIFramework - + UIFramework - + UIFramework - - UIFramework + + BattleInterface - - UIFramework + + BattleInterface - - UIFramework - - - UIFramework - - - UIFramework - - - UIFramework - - - UIFramework - - - + BattleInterface diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index 3ad0ac222..56ea14610 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -1,7 +1,7 @@ #include "StdInc.h" #include "mapHandler.h" -#include "SDL_Extensions.h" +#include "UIFramework/SDL_Extensions.h" #include "CGameInfo.h" #include "../lib/CLodHandler.h" #include "../lib/CDefObjInfoHandler.h" diff --git a/lib/BattleAction.cpp b/lib/BattleAction.cpp index 00f6b23e7..97b3a8a23 100644 --- a/lib/BattleAction.cpp +++ b/lib/BattleAction.cpp @@ -32,7 +32,7 @@ BattleAction BattleAction::makeDefend(const CStack *stack) } -BattleAction BattleAction::makeMeleeAttack(const CStack *stack, const CStack * attacked, SBattleHex attackFrom /*= SBattleHex::INVALID*/) +BattleAction BattleAction::makeMeleeAttack(const CStack *stack, const CStack * attacked, BattleHex attackFrom /*= BattleHex::INVALID*/) { BattleAction ba; ba.side = !stack->attackerOwned; @@ -62,7 +62,7 @@ BattleAction BattleAction::makeShotAttack(const CStack *shooter, const CStack *t return ba; } -BattleAction BattleAction::makeMove(const CStack *stack, SBattleHex dest) +BattleAction BattleAction::makeMove(const CStack *stack, BattleHex dest) { BattleAction ba; ba.side = !stack->attackerOwned; diff --git a/lib/BattleAction.h b/lib/BattleAction.h index 84b508838..3e6f76b93 100644 --- a/lib/BattleAction.h +++ b/lib/BattleAction.h @@ -1,7 +1,7 @@ #pragma once -#include "SBattleHex.h" +#include "BattleHex.h" /* * BattleAction.h, part of VCMI engine @@ -26,7 +26,7 @@ struct DLL_LINKAGE BattleAction STACK_HEAL, DAEMON_SUMMONING }; si8 actionType; //use ActionType enum for values - SBattleHex destinationTile; + BattleHex destinationTile; si32 additionalInfo; // e.g. spell number if type is 1 || 10; tile to attack if type is 6 template void serialize(Handler &h, const int version) { @@ -37,8 +37,8 @@ struct DLL_LINKAGE BattleAction static BattleAction makeDefend(const CStack *stack); static BattleAction makeWait(const CStack *stack); - static BattleAction makeMeleeAttack(const CStack *stack, const CStack * attacked, SBattleHex attackFrom = SBattleHex::INVALID); + static BattleAction makeMeleeAttack(const CStack *stack, const CStack * attacked, BattleHex attackFrom = BattleHex::INVALID); static BattleAction makeShotAttack(const CStack *shooter, const CStack *target); - static BattleAction makeMove(const CStack *stack, SBattleHex dest); + static BattleAction makeMove(const CStack *stack, BattleHex dest); static BattleAction makeEndOFTacticPhase(ui8 side); }; diff --git a/lib/SBattleHex.cpp b/lib/BattleHex.cpp similarity index 71% rename from lib/SBattleHex.cpp rename to lib/BattleHex.cpp index 95f3cf1cb..07afc655e 100644 --- a/lib/SBattleHex.cpp +++ b/lib/BattleHex.cpp @@ -1,7 +1,7 @@ #include "StdInc.h" -#include "SBattleHex.h" +#include "BattleHex.h" -void SBattleHex::operator+=(EDir dir) +void BattleHex::operator+=(EDir dir) { si16 x = getX(), y = getY(); @@ -27,21 +27,21 @@ void SBattleHex::operator+=(EDir dir) setXY(x-1, y); break; default: - throw std::string("Disaster: wrong direction in SBattleHex::operator+=!\n"); + throw std::string("Disaster: wrong direction in BattleHex::operator+=!\n"); break; } } -SBattleHex SBattleHex::operator+(EDir dir) const +BattleHex BattleHex::operator+(EDir dir) const { - SBattleHex ret(*this); + BattleHex ret(*this); ret += dir; return ret; } -std::vector SBattleHex::neighbouringTiles() const +std::vector BattleHex::neighbouringTiles() const { - std::vector ret; + std::vector ret; const int WN = GameConstants::BFIELD_WIDTH; checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), ret); checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), ret); @@ -53,7 +53,7 @@ std::vector SBattleHex::neighbouringTiles() const return ret; } -signed char SBattleHex::mutualPosition(SBattleHex hex1, SBattleHex hex2) +signed char BattleHex::mutualPosition(BattleHex hex1, BattleHex hex2) { if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left return 0; @@ -70,16 +70,16 @@ signed char SBattleHex::mutualPosition(SBattleHex hex1, SBattleHex hex2) return -1; } -char SBattleHex::getDistance(SBattleHex hex1, SBattleHex hex2) +char BattleHex::getDistance(BattleHex hex1, BattleHex hex2) { int xDst = std::abs(hex1 % GameConstants::BFIELD_WIDTH - hex2 % GameConstants::BFIELD_WIDTH), yDst = std::abs(hex1 / GameConstants::BFIELD_WIDTH - hex2 / GameConstants::BFIELD_WIDTH); return std::max(xDst, yDst) + std::min(xDst, yDst) - (yDst + 1)/2; } -void SBattleHex::checkAndPush(int tile, std::vector & ret) +void BattleHex::checkAndPush(int tile, std::vector & ret) { if( tile>=0 && tile - SBattleHex(inttype x, inttype y) + BattleHex(inttype x, inttype y) { setXY(x, y); } template - SBattleHex(std::pair xy) + BattleHex(std::pair xy) { setXY(xy); } @@ -89,21 +89,21 @@ struct DLL_LINKAGE SBattleHex //moving to direction void operator+=(EDir dir); - //generates new SBattleHex moved by given dir - SBattleHex operator+(EDir dir) const; + //generates new BattleHex moved by given dir + BattleHex operator+(EDir dir) const; - std::vector neighbouringTiles() const; + std::vector neighbouringTiles() const; //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left) - static signed char mutualPosition(SBattleHex hex1, SBattleHex hex2); + static signed char mutualPosition(BattleHex hex1, BattleHex hex2); //returns distance between given hexes - static char getDistance(SBattleHex hex1, SBattleHex hex2); + static char getDistance(BattleHex hex1, BattleHex hex2); template void serialize(Handler &h, const int version) { h & hex; } - static void checkAndPush(int tile, std::vector & ret); + static void checkAndPush(int tile, std::vector & ret); }; \ No newline at end of file diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index 8343cf40f..8ecad1d83 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -103,7 +103,7 @@ const CStack * BattleInfo::getStack(int stackID, bool onlyAlive) const return const_cast(this)->getStack(stackID, onlyAlive); } -CStack * BattleInfo::getStackT(SBattleHex tileID, bool onlyAlive) +CStack * BattleInfo::getStackT(BattleHex tileID, bool onlyAlive) { for(ui32 g=0; g(this)->getStackT(tileID, onlyAlive); } -void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack * stackToOmmit) const +void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack * stackToOmmit) const { memset(accessibility, 1, GameConstants::BFIELD_SIZE); //initialize array with trues @@ -153,7 +153,7 @@ void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool atta //obstacles for(ui32 b=0; b blocked = VLC->heroh->obstacles[obstacles[b].ID].getBlocked(obstacles[b].pos); + std::vector blocked = VLC->heroh->obstacles[obstacles[b].ID].getBlocked(obstacles[b].pos); for(ui32 c=0; c=0 && blocked[c] < GameConstants::BFIELD_SIZE) @@ -170,9 +170,9 @@ void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool atta accessibility[permanentlyLocked[b]] = false; } - static const std::pair lockedIfNotDestroyed[] = //(which part of wall, which hex is blocked if this part of wall is not destroyed - {std::make_pair(2, SBattleHex(182)), std::make_pair(3, SBattleHex(130)), - std::make_pair(4, SBattleHex(62)), std::make_pair(5, SBattleHex(29))}; + static const std::pair lockedIfNotDestroyed[] = //(which part of wall, which hex is blocked if this part of wall is not destroyed + {std::make_pair(2, BattleHex(182)), std::make_pair(3, BattleHex(130)), + std::make_pair(4, BattleHex(62)), std::make_pair(5, BattleHex(29))}; for(int b=0; b rem; //tiles to unlock + std::set rem; //tiles to unlock for(int h=0; h > hexq; //bfs queue (second filed used only if fillPredecessors is true) + std::queue< std::pair > hexq; //bfs queue (second filed used only if fillPredecessors is true) hexq.push(std::make_pair(start, true)); dists[hexq.front().first] = 0; int curNext = -1; //for bfs loop only (helper var) while(!hexq.empty()) //bfs loop { - std::pair curHex = hexq.front(); - std::vector neighbours = curHex.first.neighbouringTiles(); + std::pair curHex = hexq.front(); + std::vector neighbours = curHex.first.neighbouringTiles(); hexq.pop(); for(ui32 nr=0; nr BattleInfo::getAccessibility( const CStack * stack, bool addOccupiable, std::vector * attackable ) const +std::vector BattleInfo::getAccessibility( const CStack * stack, bool addOccupiable, std::vector * attackable ) const { - std::vector ret; + std::vector ret; bool ac[GameConstants::BFIELD_SIZE]; if(stack->position < 0) //turrets - return std::vector(); + return std::vector(); - std::set occupyable; + std::set occupyable; getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, addOccupiable, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack); - SBattleHex pr[GameConstants::BFIELD_SIZE]; + BattleHex pr[GameConstants::BFIELD_SIZE]; int dist[GameConstants::BFIELD_SIZE]; makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false); @@ -285,7 +285,7 @@ std::vector BattleInfo::getAccessibility( const CStack * stack, bool { if(!addOccupiable) { - std::vector rem; + std::vector rem; for(int b=0; b BattleInfo::getAccessibility( const CStack * stack, bool { struct HLP { - static bool meleeAttackable(SBattleHex hex, const std::vector & baseRng) + static bool meleeAttackable(BattleHex hex, const std::vector & baseRng) { - BOOST_FOREACH(SBattleHex h, baseRng) + BOOST_FOREACH(BattleHex h, baseRng) { - if(SBattleHex::mutualPosition(h, hex) > 0) + if(BattleHex::mutualPosition(h, hex) > 0) return true; } @@ -347,7 +347,7 @@ std::vector BattleInfo::getAccessibility( const CStack * stack, bool if(otherSt->owner == stack->owner) continue; - std::vector occupiedBySecond; + std::vector occupiedBySecond; occupiedBySecond.push_back(otherSt->position); if(otherSt->doubleWide()) occupiedBySecond.push_back(otherSt->occupiedHex()); @@ -360,7 +360,7 @@ std::vector BattleInfo::getAccessibility( const CStack * stack, bool } - BOOST_FOREACH(SBattleHex he, occupiedBySecond) + BOOST_FOREACH(BattleHex he, occupiedBySecond) { if(HLP::meleeAttackable(he, ret)) attackable->push_back(he); @@ -386,7 +386,7 @@ int BattleInfo::getAvaliableHex(TCreature creID, bool attackerOwned, int initial } bool ac[GameConstants::BFIELD_SIZE]; - std::set occupyable; + std::set occupyable; bool twoHex = VLC->creh->creatures[creID]->isDoubleWide(); bool flying = VLC->creh->creatures[creID]->isFlying();// vstd::contains(VLC->creh->creatures[creID]->bonuses, Bonus::FLYING); getAccessibilityMap(ac, twoHex, attackerOwned, true, occupyable, flying); @@ -419,21 +419,21 @@ bool BattleInfo::isStackBlocked(const CStack * stack) const return false; } -std::pair< std::vector, int > BattleInfo::getPath(SBattleHex start, SBattleHex dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned) +std::pair< std::vector, int > BattleInfo::getPath(BattleHex start, BattleHex dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned) { - SBattleHex predecessor[GameConstants::BFIELD_SIZE]; //for getting the Path + BattleHex predecessor[GameConstants::BFIELD_SIZE]; //for getting the Path int dist[GameConstants::BFIELD_SIZE]; //calculated distances makeBFS(start, accessibility, predecessor, dist, twoHex, attackerOwned, flyingCreature, false); if(predecessor[dest] == -1) //cannot reach destination { - return std::make_pair(std::vector(), 0); + return std::make_pair(std::vector(), 0); } //making the Path - std::vector path; - SBattleHex curElem = dest; + std::vector path; + BattleHex curElem = dest; while(curElem != start) { path.push_back(curElem); @@ -721,7 +721,7 @@ void BattleInfo::calculateCasualties( std::map *casualties ) const } } -std::set BattleInfo::getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, SBattleHex destinationTile ) +std::set BattleInfo::getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, BattleHex destinationTile ) { std::set attackedHexes = s->rangeInHexes(destinationTile, skillLevel); std::set attackedCres; /*std::set to exclude multiple occurrences of two hex creatures*/ @@ -801,24 +801,24 @@ std::set BattleInfo::getAttackedCreatures(const CSpell * s, int skillLe } return attackedCres; } -void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos) +void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos) { const int WN = GameConstants::BFIELD_WIDTH; - ui16 hex = (attackerPos != SBattleHex::INVALID) ? attackerPos.hex : attacker->position.hex; //real or hypothetical (cursor) position + ui16 hex = (attackerPos != BattleHex::INVALID) ? attackerPos.hex : attacker->position.hex; //real or hypothetical (cursor) position if (attacker->hasBonusOfType(Bonus::ATTACKS_ALL_ADJACENT)) { - std::vector hexes = attacker->getSurroundingHexes(attackerPos); - BOOST_FOREACH (SBattleHex tile, hexes) + std::vector hexes = attacker->getSurroundingHexes(attackerPos); + BOOST_FOREACH (BattleHex tile, hexes) { at.hostileCreaturePositions.insert(tile); } } if (attacker->hasBonusOfType(Bonus::THREE_HEADED_ATTACK)) { - std::vector hexes = attacker->getSurroundingHexes(attackerPos); - BOOST_FOREACH (SBattleHex tile, hexes) + std::vector hexes = attacker->getSurroundingHexes(attackerPos); + BOOST_FOREACH (BattleHex tile, hexes) { - if ((SBattleHex::mutualPosition(tile, destinationTile) > -1 && SBattleHex::mutualPosition(tile, hex) > -1) //adjacent both to attacker's head and attacked tile + if ((BattleHex::mutualPosition(tile, destinationTile) > -1 && BattleHex::mutualPosition(tile, hex) > -1) //adjacent both to attacker's head and attacked tile || tile == destinationTile) //or simply attacked directly { CStack * st = getStackT(tile, true); @@ -831,26 +831,26 @@ void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack } if (attacker->hasBonusOfType(Bonus::TWO_HEX_ATTACK_BREATH)) { - std::vector hexes; //only one, in fact + std::vector hexes; //only one, in fact int pseudoVector = destinationTile.hex - hex; switch (pseudoVector) { case 1: case -1: - SBattleHex::checkAndPush(destinationTile.hex + pseudoVector, hexes); + BattleHex::checkAndPush(destinationTile.hex + pseudoVector, hexes); break; case WN: //17 case WN + 1: //18 case -WN: //-17 case -WN + 1: //-16 - SBattleHex::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : -1 ), hexes); + BattleHex::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : -1 ), hexes); break; case WN-1: //16 case -WN-1: //-18 - SBattleHex::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : 0), hexes); + BattleHex::checkAndPush(destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : 0), hexes); break; } - BOOST_FOREACH (SBattleHex tile, hexes) + BOOST_FOREACH (BattleHex tile, hexes) { CStack * st = getStackT(tile, true); if(st) //friendly stacks can also be damaged by Dragon Breath @@ -860,12 +860,12 @@ void BattleInfo::getPotentiallyAttackableHexes(AttackableTiles &at, const CStack } } } -std::set BattleInfo::getAttackedCreatures(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos) +std::set BattleInfo::getAttackedCreatures(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos) { //TODO: caching? AttackableTiles at; getPotentiallyAttackableHexes(at, attacker, destinationTile, attackerPos); std::set attackedCres; - BOOST_FOREACH (SBattleHex tile, at.hostileCreaturePositions) //all around & three-headed attack + BOOST_FOREACH (BattleHex tile, at.hostileCreaturePositions) //all around & three-headed attack { CStack * st = getStackT(tile, true); if(st && st->owner != attacker->owner) //only hostile stacks - does it work well with Berserk? @@ -873,7 +873,7 @@ std::set BattleInfo::getAttackedCreatures(const CStack* attacker, SBatt attackedCres.insert(st); } } - BOOST_FOREACH (SBattleHex tile, at.friendlyCreaturePositions) + BOOST_FOREACH (BattleHex tile, at.friendlyCreaturePositions) { CStack * st = getStackT(tile, true); if(st) //friendly stacks can also be damaged by Dragon Breath @@ -884,12 +884,12 @@ std::set BattleInfo::getAttackedCreatures(const CStack* attacker, SBatt return attackedCres; } -std::set BattleInfo::getAttackedHexes(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos) +std::set BattleInfo::getAttackedHexes(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos) { AttackableTiles at; getPotentiallyAttackableHexes(at, attacker, destinationTile, attackerPos); - std::set attackedHexes; - BOOST_FOREACH (SBattleHex tile, at.hostileCreaturePositions) + std::set attackedHexes; + BOOST_FOREACH (BattleHex tile, at.hostileCreaturePositions) { CStack * st = getStackT(tile, true); if(st && st->owner != attacker->owner) //only hostile stacks - does it work well with Berserk? @@ -897,7 +897,7 @@ std::set BattleInfo::getAttackedHexes(const CStack* attacker, SBattl attackedHexes.insert(tile); } } - BOOST_FOREACH (SBattleHex tile, at.friendlyCreaturePositions) + BOOST_FOREACH (BattleHex tile, at.friendlyCreaturePositions) { CStack * st = getStackT(tile, true); if(st) //friendly stacks can also be damaged by Dragon Breath @@ -913,7 +913,7 @@ std::set BattleInfo::getAdjacentCreatures (const CStack * stack) const std::set stacks; CStack * localStack; - BOOST_FOREACH (SBattleHex hex, stack->getSurroundingHexes()) + BOOST_FOREACH (BattleHex hex, stack->getSurroundingHexes()) { localStack = const_cast(getStackT(hex, true)); //only alive? if (localStack) @@ -940,7 +940,7 @@ int BattleInfo::calculateSpellDuration( const CSpell * spell, const CGHeroInstan } } -CStack * BattleInfo::generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, SBattleHex position) const +CStack * BattleInfo::generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, BattleHex position) const { int owner = attackerOwned ? sides[0] : sides[1]; assert((owner >= GameConstants::PLAYER_LIMIT) || @@ -950,7 +950,7 @@ CStack * BattleInfo::generateNewStack(const CStackInstance &base, int stackID, b ret->position = position; return ret; } -CStack * BattleInfo::generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, SBattleHex position) const +CStack * BattleInfo::generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, BattleHex position) const { int owner = attackerOwned ? sides[0] : sides[1]; CStack * ret = new CStack(&base, owner, stackID, attackerOwned, slot); @@ -981,7 +981,7 @@ ui32 BattleInfo::getSpellCost(const CSpell * sp, const CGHeroInstance * caster) return ret - manaReduction + manaIncrease; } -int BattleInfo::hexToWallPart(SBattleHex hex) const +int BattleInfo::hexToWallPart(BattleHex hex) const { if(siege == 0) //there is no battle! return -1; @@ -1007,14 +1007,14 @@ int BattleInfo::lineToWallHex( int line ) const return lineToHex[line]; } -std::pair BattleInfo::getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const +std::pair BattleInfo::getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const { bool ac[GameConstants::BFIELD_SIZE]; - std::set occupyable; + std::set occupyable; getAccessibilityMap(ac, closest->doubleWide(), closest->attackerOwned, false, occupyable, closest->hasBonusOfType(Bonus::FLYING), closest); - SBattleHex predecessor[GameConstants::BFIELD_SIZE]; + BattleHex predecessor[GameConstants::BFIELD_SIZE]; int dist[GameConstants::BFIELD_SIZE]; makeBFS(closest->position, ac, predecessor, dist, closest->doubleWide(), closest->attackerOwned, closest->hasBonusOfType(Bonus::FLYING), true); @@ -1055,7 +1055,7 @@ std::pair BattleInfo::getNearestStack(const CStack * return std::make_pair(minPair.second, predecessor[minPair.first.second]); } - return std::make_pair(NULL, SBattleHex::INVALID); + return std::make_pair(NULL, BattleHex::INVALID); } ui32 BattleInfo::calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature) const { @@ -1251,13 +1251,13 @@ void BattleInfo::getStackQueue( std::vector &out, int howMany, i } } -si8 BattleInfo::hasDistancePenalty( const CStack * stack, SBattleHex destHex ) const +si8 BattleInfo::hasDistancePenalty( const CStack * stack, BattleHex destHex ) const { struct HLP { - static bool lowerAnalyze(const CStack * stack, SBattleHex hex) + static bool lowerAnalyze(const CStack * stack, BattleHex hex) { - int distance = SBattleHex::getDistance(hex, stack->position); + int distance = BattleHex::getDistance(hex, stack->position); //I hope it's approximately correct return distance > 10 && !stack->hasBonusOfType(Bonus::NO_DISTANCE_PENALTY); @@ -1283,7 +1283,7 @@ si8 BattleInfo::sameSideOfWall(int pos1, int pos2) const return stackLeft != destLeft; } -si8 BattleInfo::hasWallPenalty( const CStack* stack, SBattleHex destHex ) const +si8 BattleInfo::hasWallPenalty( const CStack* stack, BattleHex destHex ) const { if (!siege || stack->hasBonusOfType(Bonus::NO_WALL_PENALTY)) { @@ -1308,11 +1308,11 @@ si8 BattleInfo::hasWallPenalty( const CStack* stack, SBattleHex destHex ) const return false; } -si8 BattleInfo::canTeleportTo(const CStack * stack, SBattleHex destHex, int telportLevel) const +si8 BattleInfo::canTeleportTo(const CStack * stack, BattleHex destHex, int telportLevel) const { bool ac[GameConstants::BFIELD_SIZE]; - std::set occupyable; + std::set occupyable; getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack); @@ -1327,7 +1327,7 @@ si8 BattleInfo::canTeleportTo(const CStack * stack, SBattleHex destHex, int telp } -bool BattleInfo::battleCanShoot(const CStack * stack, SBattleHex dest) const +bool BattleInfo::battleCanShoot(const CStack * stack, BattleHex dest) const { const CStack *dst = getStackT(dest); @@ -1375,7 +1375,7 @@ bool BattleInfo::battleCanFlee(int player) const return true; } -const CStack * BattleInfo::battleGetStack(SBattleHex pos, bool onlyAlive) +const CStack * BattleInfo::battleGetStack(BattleHex pos, bool onlyAlive) { CStack * stack = NULL; for(ui32 g=0; gdoubleWide() && stacks[g]->attackerOwned) { - stacks[g]->position += SBattleHex::RIGHT; + stacks[g]->position += BattleHex::RIGHT; } else if(stacks[g]->doubleWide() && !stacks[g]->attackerOwned) { if (stacks[g]->position.getX() > 1) - stacks[g]->position += SBattleHex::LEFT; + stacks[g]->position += BattleHex::LEFT; } } @@ -1663,7 +1663,7 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const coi.uniqueID = curB->obstacles.size(); coi.ID = possibleObstacles[rand()%possibleObstacles.size()]; coi.pos = rand()%GameConstants::BFIELD_SIZE; - std::vector block = VLC->heroh->obstacles[coi.ID].getBlocked(coi.pos); + std::vector block = VLC->heroh->obstacles[coi.ID].getBlocked(coi.pos); bool badObstacle = false; for(int b=0; b 0 && dest.getX() <= tacticDistance) @@ -1931,7 +1931,7 @@ ESpellCastProblem::ESpellCastProblem BattleInfo::battleCanCastThisSpell( int pla return ESpellCastProblem::OK; } -ESpellCastProblem::ESpellCastProblem BattleInfo::battleCanCastThisSpellHere( int player, const CSpell * spell, ECastingMode::ECastingMode mode, SBattleHex dest ) const +ESpellCastProblem::ESpellCastProblem BattleInfo::battleCanCastThisSpellHere( int player, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest ) const { ESpellCastProblem::ESpellCastProblem moreGeneralProblem = battleCanCastThisSpell(player, spell, mode); if(moreGeneralProblem != ESpellCastProblem::OK) @@ -2093,7 +2093,7 @@ bool BattleInfo::battleTestElementalImmunity(const CStack * subject, const CSpel return false; } -ESpellCastProblem::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, ECastingMode::ECastingMode mode, SBattleHex dest) const +ESpellCastProblem::ESpellCastProblem BattleInfo::battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest) const { const CStack * subject = getStackT(dest, false); if(subject) @@ -2320,7 +2320,7 @@ void CStack::init() owner = 255; slot = 255; attackerOwned = false; - position = SBattleHex(); + position = BattleHex(); counterAttacks = -1; } @@ -2605,7 +2605,7 @@ bool CStack::doubleWide() const return getCreature()->doubleWide; } -SBattleHex CStack::occupiedHex() const +BattleHex CStack::occupiedHex() const { if (doubleWide()) { @@ -2616,54 +2616,54 @@ SBattleHex CStack::occupiedHex() const } else { - return SBattleHex::INVALID; + return BattleHex::INVALID; } } -std::vector CStack::getHexes() const +std::vector CStack::getHexes() const { - std::vector hexes; - hexes.push_back(SBattleHex(position)); - SBattleHex occupied = occupiedHex(); + std::vector hexes; + hexes.push_back(BattleHex(position)); + BattleHex occupied = occupiedHex(); if(occupied.isValid()) hexes.push_back(occupied); return hexes; } -bool CStack::coversPos(SBattleHex pos) const +bool CStack::coversPos(BattleHex pos) const { return vstd::contains(getHexes(), pos); } -std::vector CStack::getSurroundingHexes(SBattleHex attackerPos) const +std::vector CStack::getSurroundingHexes(BattleHex attackerPos) const { - SBattleHex hex = (attackerPos != SBattleHex::INVALID) ? attackerPos : position; //use hypothetical position - std::vector hexes; + BattleHex hex = (attackerPos != BattleHex::INVALID) ? attackerPos : position; //use hypothetical position + std::vector hexes; if (doubleWide()) { const int WN = GameConstants::BFIELD_WIDTH; if(attackerOwned) { //position is equal to front hex - SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+2 : WN+1 ), hexes); - SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); - SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); - SBattleHex::checkAndPush(hex - 2, hexes); - SBattleHex::checkAndPush(hex + 1, hexes); - SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-2 : WN-1 ), hexes); - SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); - SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); + BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+2 : WN+1 ), hexes); + BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); + BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); + BattleHex::checkAndPush(hex - 2, hexes); + BattleHex::checkAndPush(hex + 1, hexes); + BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-2 : WN-1 ), hexes); + BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); + BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); } else { - SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); - SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); - SBattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN-2 ), hexes); - SBattleHex::checkAndPush(hex + 2, hexes); - SBattleHex::checkAndPush(hex - 1, hexes); - SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); - SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); - SBattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN+1 : WN+2 ), hexes); + BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes); + BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes); + BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN-2 ), hexes); + BattleHex::checkAndPush(hex + 2, hexes); + BattleHex::checkAndPush(hex - 1, hexes); + BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes); + BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes); + BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN+1 : WN+2 ), hexes); } return hexes; } @@ -2764,7 +2764,7 @@ void CStack::prepareAttacked(BattleStackAttacked &bsa) const } } -bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defender, SBattleHex attackerPos /*= SBattleHex::INVALID*/, SBattleHex defenderPos /*= SBattleHex::INVALID*/) +bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defender, BattleHex attackerPos /*= BattleHex::INVALID*/, BattleHex defenderPos /*= BattleHex::INVALID*/) { if (!attackerPos.isValid()) { @@ -2776,13 +2776,13 @@ bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defen } return - (SBattleHex::mutualPosition(attackerPos, defenderPos) >= 0) //front <=> front + (BattleHex::mutualPosition(attackerPos, defenderPos) >= 0) //front <=> front || (attacker->doubleWide() //back <=> front - && SBattleHex::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos) >= 0) + && BattleHex::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos) >= 0) || (defender->doubleWide() //front <=> back - && SBattleHex::mutualPosition(attackerPos, defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0) + && BattleHex::mutualPosition(attackerPos, defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0) || (defender->doubleWide() && attacker->doubleWide()//back <=> back - && SBattleHex::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0); + && BattleHex::mutualPosition(attackerPos + (attacker->attackerOwned ? -1 : 1), defenderPos + (defender->attackerOwned ? -1 : 1)) >= 0); } diff --git a/lib/BattleState.h b/lib/BattleState.h index 2b15989b3..660ce9b7a 100644 --- a/lib/BattleState.h +++ b/lib/BattleState.h @@ -1,7 +1,7 @@ #pragma once -#include "SBattleHex.h" +#include "BattleHex.h" #include "HeroBonus.h" #include "CCreatureSet.h" #include "CObjectHandler.h" @@ -41,8 +41,8 @@ struct DLL_LINKAGE SiegeInfo struct DLL_LINKAGE AttackableTiles { - std::set hostileCreaturePositions; - std::set friendlyCreaturePositions; //for Dragon Breath + std::set hostileCreaturePositions; + std::set friendlyCreaturePositions; //for Dragon Breath template void serialize(Handler &h, const int version) { h & hostileCreaturePositions & friendlyCreaturePositions; @@ -87,14 +87,14 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode void getStackQueue(std::vector &out, int howMany, int turn = 0, int lastMoved = -1) const; //returns stack in order of their movement action CStack * getStack(int stackID, bool onlyAlive = true); const CStack * getStack(int stackID, bool onlyAlive = true) const; - CStack * getStackT(SBattleHex tileID, bool onlyAlive = true); - const CStack * getStackT(SBattleHex tileID, bool onlyAlive = true) const; - void getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack* stackToOmmit = NULL) const; //send pointer to at least 187 allocated bytes - static bool isAccessible(SBattleHex hex, bool * accessibility, bool twoHex, bool attackerOwned, bool flying, bool lastPos); //helper for makeBFS + CStack * getStackT(BattleHex tileID, bool onlyAlive = true); + const CStack * getStackT(BattleHex tileID, bool onlyAlive = true) const; + void getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack* stackToOmmit = NULL) const; //send pointer to at least 187 allocated bytes + static bool isAccessible(BattleHex hex, bool * accessibility, bool twoHex, bool attackerOwned, bool flying, bool lastPos); //helper for makeBFS int getAvaliableHex(TCreature creID, bool attackerOwned, int initialPos = -1) const; //find place for summon / clone effects - void makeBFS(SBattleHex start, bool*accessibility, SBattleHex *predecessor, int *dists, bool twoHex, bool attackerOwned, bool flying, bool fillPredecessors) const; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result - std::pair< std::vector, int > getPath(SBattleHex start, SBattleHex dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned); //returned value: pair; length may be different than number of elements in path since flying vreatures jump between distant hexes - std::vector getAccessibility(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL) const; //returns vector of accessible tiles (taking into account the creature range) + void makeBFS(BattleHex start, bool*accessibility, BattleHex *predecessor, int *dists, bool twoHex, bool attackerOwned, bool flying, bool fillPredecessors) const; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result + std::pair< std::vector, int > getPath(BattleHex start, BattleHex dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned); //returned value: pair; length may be different than number of elements in path since flying vreatures jump between distant hexes + std::vector getAccessibility(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL) const; //returns vector of accessible tiles (taking into account the creature range) bool isStackBlocked(const CStack * stack) const; //returns true if there is neighboring enemy stack @@ -102,35 +102,35 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode TDmgRange calculateDmgRange(const CStack* attacker, const CStack* defender, TQuantity attackerCount, TQuantity defenderCount, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky, bool deathBlow, bool ballistaDoubleDmg) const; //charge - number of hexes travelled before attack (for champion's jousting); returns pair TDmgRange calculateDmgRange(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky, bool deathBlow, bool ballistaDoubleDmg) const; //charge - number of hexes travelled before attack (for champion's jousting); returns pair void calculateCasualties(std::map *casualties) const; //casualties are array of maps size 2 (attacker, defeneder), maps are (crid => amount) - std::set getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, SBattleHex destinationTile); //calculates stack affected by given spell - void getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos); //hexes around target that could be attacked in melee - std::set getAttackedCreatures(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos = SBattleHex::INVALID); //calculates range of multi-hex attacks - std::set getAttackedHexes(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos = SBattleHex::INVALID); //calculates range of multi-hex attacks + std::set getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, BattleHex destinationTile); //calculates stack affected by given spell + void getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos); //hexes around target that could be attacked in melee + std::set getAttackedCreatures(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos = BattleHex::INVALID); //calculates range of multi-hex attacks + std::set getAttackedHexes(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos = BattleHex::INVALID); //calculates range of multi-hex attacks std::set getAdjacentCreatures (const CStack * stack) const; static int calculateSpellDuration(const CSpell * spell, const CGHeroInstance * caster, int usedSpellPower); - CStack * generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, SBattleHex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield - CStack * generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, SBattleHex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield + CStack * generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, BattleHex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield + CStack * generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, BattleHex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield ui32 getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //returns cost of given spell - int hexToWallPart(SBattleHex hex) const; //returns part of destructible wall / gate / keep under given hex or -1 if not found + int hexToWallPart(BattleHex hex) const; //returns part of destructible wall / gate / keep under given hex or -1 if not found int lineToWallHex(int line) const; //returns hex with wall in given line - std::pair getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const; //if attackerOwned is indetermnate, returened stack is of any owner; hex is the number of hex we should be looking from; returns (nerarest creature, predecessorHex) + std::pair getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const; //if attackerOwned is indetermnate, returened stack is of any owner; hex is the number of hex we should be looking from; returns (nerarest creature, predecessorHex) ui32 calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature) const; ui32 calculateSpellDmg(const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature, int spellSchoolLevel, int usedSpellPower) const; //calculates damage inflicted by spell ui32 calculateHealedHP(const CGHeroInstance * caster, const CSpell * spell, const CStack * stack) const; ui32 calculateHealedHP(int healedHealth, const CSpell * spell, const CStack * stack) const; //for Archangel ui32 calculateHealedHP(const CSpell * spell, int usedSpellPower, int spellSchoolLevel, const CStack * stack) const; //unused bool resurrects(TSpell spellid) const; //TODO: move it to spellHandler? - si8 hasDistancePenalty(const CStack * stackID, SBattleHex destHex) const; //determines if given stack has distance penalty shooting given pos + si8 hasDistancePenalty(const CStack * stackID, BattleHex destHex) const; //determines if given stack has distance penalty shooting given pos si8 sameSideOfWall(int pos1, int pos2) const; //determines if given positions are on the same side of wall - si8 hasWallPenalty(const CStack * stack, SBattleHex destHex) const; //determines if given stack has wall penalty shooting given pos - si8 canTeleportTo(const CStack * stack, SBattleHex destHex, int telportLevel) const; //determines if given stack can teleport to given place - bool battleCanShoot(const CStack * stack, SBattleHex dest) const; //determines if stack with given ID shoot at the selected destination + si8 hasWallPenalty(const CStack * stack, BattleHex destHex) const; //determines if given stack has wall penalty shooting given pos + si8 canTeleportTo(const CStack * stack, BattleHex destHex, int telportLevel) const; //determines if given stack can teleport to given place + bool battleCanShoot(const CStack * stack, BattleHex dest) const; //determines if stack with given ID shoot at the selected destination const CGHeroInstance * getHero(int player) const; //returns fighting hero that belongs to given player ESpellCastProblem::ESpellCastProblem battleCanCastSpell(int player, ECastingMode::ECastingMode mode) const; //returns true if there are no general issues preventing from casting a spell ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(int player, const CSpell * spell, ECastingMode::ECastingMode mode) const; //checks if given player can cast given spell - ESpellCastProblem::ESpellCastProblem battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, ECastingMode::ECastingMode mode, SBattleHex dest) const; //checks for creature immunity / anything that prevent casting *at given hex* - doesn't take into acount general problems such as not having spellbook or mana points etc. - ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(int player, const CSpell * spell, ECastingMode::ECastingMode mode, SBattleHex dest) const; //checks if given player can cast given spell at given tile in given mode + ESpellCastProblem::ESpellCastProblem battleIsImmune(const CGHeroInstance * caster, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest) const; //checks for creature immunity / anything that prevent casting *at given hex* - doesn't take into acount general problems such as not having spellbook or mana points etc. + ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(int player, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest) const; //checks if given player can cast given spell at given tile in given mode bool battleTestElementalImmunity(const CStack * subject, const CSpell * spell, Bonus::BonusType element, bool damageSpell) const; TSpell getRandomBeneficialSpell(const CStack * subject) const; TSpell getRandomCastedSpell(const CStack * caster) const; //called at the beginning of turn for Faerie Dragon @@ -139,12 +139,12 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode bool battleCanFlee(int player) const; //returns true if player can flee from the battle - const CStack * battleGetStack(SBattleHex pos, bool onlyAlive); //returns stack at given tile + const CStack * battleGetStack(BattleHex pos, bool onlyAlive); //returns stack at given tile const CGHeroInstance * battleGetOwner(const CStack * stack) const; //returns hero that owns given stack; NULL if none si8 battleMinSpellLevel() const; //calculates minimum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned void localInit(); static BattleInfo * setupBattle( int3 tile, int terrain, int terType, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town ); - bool isInTacticRange( SBattleHex dest ) const; + bool isInTacticRange( BattleHex dest ) const; int getSurrenderingCost(int player) const; int theOtherPlayer(int player) const; @@ -161,7 +161,7 @@ public: ui32 firstHPleft; //HP of first creature in stack ui8 owner, slot; //owner - player colour (255 for neutrals), slot - position in garrison (may be 255 for neutrals/called creatures) ui8 attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle) - SBattleHex position; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower + BattleHex position; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower ui8 counterAttacks; //how many counter attacks can be performed more in this turn (by default set at the beginning of the round to 1) si16 shots; //how many shots left ui8 casts; //how many casts left @@ -207,13 +207,13 @@ public: return ret; } - static bool isMeleeAttackPossible(const CStack * attacker, const CStack * defender, SBattleHex attackerPos = SBattleHex::INVALID, SBattleHex defenderPos = SBattleHex::INVALID); + static bool isMeleeAttackPossible(const CStack * attacker, const CStack * defender, BattleHex attackerPos = BattleHex::INVALID, BattleHex defenderPos = BattleHex::INVALID); bool doubleWide() const; - SBattleHex occupiedHex() const; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1 - std::vector getHexes() const; //up to two occupied hexes, starting from front - bool coversPos(SBattleHex position) const; //checks also if unit is double-wide - std::vector getSurroundingHexes(SBattleHex attackerPos = SBattleHex::INVALID) const; // get six or 8 surrounding hexes depending on creature size + BattleHex occupiedHex() const; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1 + std::vector getHexes() const; //up to two occupied hexes, starting from front + bool coversPos(BattleHex position) const; //checks also if unit is double-wide + std::vector getSurroundingHexes(BattleHex attackerPos = BattleHex::INVALID) const; // get six or 8 surrounding hexes depending on creature size void prepareAttacked(BattleStackAttacked &bsa) const; //requires bsa.damageAmout filled diff --git a/lib/CGameInterface.cpp b/lib/CGameInterface.cpp index c40b02553..a558f8c29 100644 --- a/lib/CGameInterface.cpp +++ b/lib/CGameInterface.cpp @@ -170,7 +170,7 @@ void CAdventureAI::battleNewStackAppeared(const CStack * stack) battleAI->battleNewStackAppeared(stack); } -void CAdventureAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) +void CAdventureAI::battleStackMoved(const CStack * stack, std::vector dest, int distance) { battleAI->battleStackMoved(stack, dest, distance); } diff --git a/lib/CGameInterface.h b/lib/CGameInterface.h index 97729ebe5..4b6400dd3 100644 --- a/lib/CGameInterface.h +++ b/lib/CGameInterface.h @@ -95,7 +95,7 @@ public: virtual void yourTurn() OVERRIDE{}; virtual void heroKilled(const CGHeroInstance*){}; virtual void heroCreated(const CGHeroInstance*) OVERRIDE{}; - virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE{}; + virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance) OVERRIDE{}; virtual void battleStackAttacking(int ID, int dest) {}; virtual void battleStacksAttacked(const std::vector & bsa) OVERRIDE{}; virtual BattleAction activeStack(const CStack * stack) OVERRIDE; @@ -127,7 +127,7 @@ public: virtual void battleStacksRemoved(const BattleStacksRemoved & bsr); virtual void battleObstaclesRemoved(const std::set & removedObstacles); virtual void battleNewStackAppeared(const CStack * stack); - virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance); + virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance); virtual void battleAttack(const BattleAttack *ba); virtual void battleSpellCast(const BattleSpellCast *sc); virtual void battleEnd(const BattleResult *br); diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 5f750f8ff..1abb5711d 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -92,9 +92,9 @@ int CObstacleInfo::getHeight() const return ret; } -std::vector CObstacleInfo::getBlocked(SBattleHex hex) const +std::vector CObstacleInfo::getBlocked(BattleHex hex) const { - std::vector ret; + std::vector ret; int cur = hex; //currently browsed hex int curBeg = hex; //beginning of current line for(int h=0; h CObstacleInfo::getBlocked(SBattleHex hex) const return ret; } -SBattleHex CObstacleInfo::getMaxBlocked(SBattleHex hex) const +BattleHex CObstacleInfo::getMaxBlocked(BattleHex hex) const { - std::vector blocked = getBlocked(hex); + std::vector blocked = getBlocked(hex); return *std::max_element(blocked.begin(), blocked.end()); } diff --git a/lib/CHeroHandler.h b/lib/CHeroHandler.h index 16e99455a..d19abb32c 100644 --- a/lib/CHeroHandler.h +++ b/lib/CHeroHandler.h @@ -1,7 +1,7 @@ #pragma once -#include "SBattleHex.h" +#include "BattleHex.h" #include "../lib/ConstTransitivePtr.h" #include "GameConstants.h" @@ -96,8 +96,8 @@ struct DLL_LINKAGE CObstacleInfo std::pair posShift; //shift of obstacle's position in the battlefield , eg. if it's <-1, 2> obstacle will be printed one pixel to the left and two to the bottom int getWidth() const; //returns width of obstacle in hexes int getHeight() const; //returns height of obstacle in hexes - std::vector getBlocked(SBattleHex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex' - SBattleHex getMaxBlocked(SBattleHex hex) const; //returns maximal hex (max number) covered by this obstacle + std::vector getBlocked(BattleHex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex' + BattleHex getMaxBlocked(BattleHex hex) const; //returns maximal hex (max number) covered by this obstacle template void serialize(Handler &h, const int version) { h & ID & defName & blockmap & allowedTerrains & posShift; diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index e197953ce..f5d15619c 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -39,31 +39,31 @@ boost::shared_mutex& CCallbackBase::getGsMutex() return *gs->mx; } -si8 CBattleInfoCallback::battleHasDistancePenalty( const CStack * stack, SBattleHex destHex ) +si8 CBattleInfoCallback::battleHasDistancePenalty( const CStack * stack, BattleHex destHex ) { return gs->curB->hasDistancePenalty(stack, destHex); } -si8 CBattleInfoCallback::battleHasWallPenalty( const CStack * stack, SBattleHex destHex ) +si8 CBattleInfoCallback::battleHasWallPenalty( const CStack * stack, BattleHex destHex ) { return gs->curB->hasWallPenalty(stack, destHex); } -si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, SBattleHex destHex, int telportLevel) +si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, BattleHex destHex, int telportLevel) { return gs->curB->canTeleportTo(stack, destHex, telportLevel); } -std::vector CBattleInfoCallback::battleGetDistances(const CStack * stack, SBattleHex hex /*= SBattleHex::INVALID*/, SBattleHex * predecessors /*= NULL*/) +std::vector CBattleInfoCallback::battleGetDistances(const CStack * stack, BattleHex hex /*= BattleHex::INVALID*/, BattleHex * predecessors /*= NULL*/) { if(!hex.isValid()) hex = stack->position; std::vector ret; bool ac[GameConstants::BFIELD_SIZE] = {0}; - std::set occupyable; + std::set occupyable; gs->curB->getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack); - SBattleHex pr[GameConstants::BFIELD_SIZE]; + BattleHex pr[GameConstants::BFIELD_SIZE]; int dist[GameConstants::BFIELD_SIZE]; gs->curB->makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false); @@ -77,18 +77,18 @@ std::vector CBattleInfoCallback::battleGetDistances(const CStack * stack, S if(predecessors) { - memcpy(predecessors, pr, GameConstants::BFIELD_SIZE * sizeof(SBattleHex)); + memcpy(predecessors, pr, GameConstants::BFIELD_SIZE * sizeof(BattleHex)); } return ret; } -std::set CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos /*= SBattleHex::INVALID*/) +std::set CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos /*= BattleHex::INVALID*/) { if(!gs->curB) { tlog1 << "battleGetAttackedHexes called when there is no battle!\n"; - std::set set; + std::set set; return set; } @@ -107,7 +107,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell return gs->curB->battleCanCastThisSpell(player, spell, ECastingMode::HERO_CASTING); } -ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell(const CSpell * spell, SBattleHex destination) +ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell(const CSpell * spell, BattleHex destination) { if(!gs->curB) { @@ -185,7 +185,7 @@ int CBattleInfoCallback::battleGetBattlefieldType() return gs->curB->battlefieldType; } -int CBattleInfoCallback::battleGetObstaclesAtTile(SBattleHex tile) //returns bitfield +int CBattleInfoCallback::battleGetObstaclesAtTile(BattleHex tile) //returns bitfield { //TODO - write return -1; @@ -207,26 +207,26 @@ const CStack* CBattleInfoCallback::battleGetStackByID(int ID, bool onlyAlive) return gs->curB->getStack(ID, onlyAlive); } -const CStack* CBattleInfoCallback::battleGetStackByPos(SBattleHex pos, bool onlyAlive) +const CStack* CBattleInfoCallback::battleGetStackByPos(BattleHex pos, bool onlyAlive) { //boost::shared_lock lock(*gs->mx); return gs->curB->battleGetStack(pos, onlyAlive); } -SBattleHex CBattleInfoCallback::battleGetPos(int stack) +BattleHex CBattleInfoCallback::battleGetPos(int stack) { //boost::shared_lock lock(*gs->mx); if(!gs->curB) { tlog2<<"battleGetPos called when there is no battle!"<curB->stacks.size(); ++g) { if(gs->curB->stacks[g]->ID == stack) return gs->curB->stacks[g]->position; } - return SBattleHex::INVALID; + return BattleHex::INVALID; } TStacks CBattleInfoCallback::battleGetStacks(EStackOwnership whose /*= MINE_AND_ENEMY*/, bool onlyAlive /*= true*/) @@ -268,24 +268,24 @@ void CBattleInfoCallback::battleGetStackCountOutsideHexes(bool *ac) for (int i = 0; i < GameConstants::BFIELD_SIZE; ++i) ac[i] = false; } else { - std::set ignored; + std::set ignored; gs->curB->getAccessibilityMap(ac, false /*ignored*/, false, false, ignored, false /*ignored*/, NULL); } } -std::vector CBattleInfoCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable) +std::vector CBattleInfoCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable) { //boost::shared_lock lock(*gs->mx); if(!gs->curB) { tlog2<<"battleGetAvailableHexes called when there is no battle!"<(); + return std::vector(); } return gs->curB->getAccessibility(stack, addOccupiable, attackable); //return gs->battleGetRange(ID); } -bool CBattleInfoCallback::battleCanShoot(const CStack * stack, SBattleHex dest) +bool CBattleInfoCallback::battleCanShoot(const CStack * stack, BattleHex dest) { //boost::shared_lock lock(*gs->mx); @@ -324,7 +324,7 @@ ui8 CBattleInfoCallback::battleGetWallState(int partOfWall) return gs->curB->si.wallState[partOfWall]; } -int CBattleInfoCallback::battleGetWallUnderHex(SBattleHex hex) +int CBattleInfoCallback::battleGetWallUnderHex(BattleHex hex) { if(!gs->curB || gs->curB->siege == 0) { diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index bde5a4ec3..bf4df568b 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -1,7 +1,7 @@ #pragma once -#include "SBattleHex.h" +#include "BattleHex.h" #include "../client/FunctionList.h" #include "CObstacleInstance.h" #include "ResourceSet.h" @@ -94,33 +94,33 @@ public: //battle int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship - int battleGetObstaclesAtTile(SBattleHex tile); //returns bitfield + int battleGetObstaclesAtTile(BattleHex tile); //returns bitfield std::vector battleGetAllObstacles(); //returns all obstacles on the battlefield const CStack * battleGetStackByID(int ID, bool onlyAlive = true); //returns stack info by given ID - const CStack * battleGetStackByPos(SBattleHex pos, bool onlyAlive = true); //returns stack info by given pos - SBattleHex battleGetPos(int stack); //returns position (tile ID) of stack + const CStack * battleGetStackByPos(BattleHex pos, bool onlyAlive = true); //returns stack info by given pos + BattleHex battleGetPos(int stack); //returns position (tile ID) of stack TStacks battleGetStacks(EStackOwnership whose = MINE_AND_ENEMY, bool onlyAlive = true); //returns stacks on battlefield void getStackQueue( std::vector &out, int howMany ); //returns vector of stack in order of their move sequence void battleGetStackCountOutsideHexes(bool *ac); // returns hexes which when in front of a stack cause us to move the amount box back - std::vector battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL); //returns numbers of hexes reachable by creature with id ID - std::vector battleGetDistances(const CStack * stack, SBattleHex hex = SBattleHex::INVALID, SBattleHex * predecessors = NULL); //returns vector of distances to [dest hex number] - std::set battleGetAttackedHexes(const CStack* attacker, SBattleHex destinationTile, SBattleHex attackerPos = SBattleHex::INVALID); - bool battleCanShoot(const CStack * stack, SBattleHex dest); //returns true if unit with id ID can shoot to dest + std::vector battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL); //returns numbers of hexes reachable by creature with id ID + std::vector battleGetDistances(const CStack * stack, BattleHex hex = BattleHex::INVALID, BattleHex * predecessors = NULL); //returns vector of distances to [dest hex number] + std::set battleGetAttackedHexes(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos = BattleHex::INVALID); + bool battleCanShoot(const CStack * stack, BattleHex dest); //returns true if unit with id ID can shoot to dest bool battleCanCastSpell(); //returns true, if caller can cast a spell ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell); //determines if given spell can be casted (and returns problem description) - ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell, SBattleHex destination); //determines if creature can cast a spell here + ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(const CSpell * spell, BattleHex destination); //determines if creature can cast a spell here ui32 battleGetRandomStackSpell(const CStack * stack, ERandomSpell mode); bool battleCanFlee(); //returns true if caller can flee from the battle int battleGetSurrenderCost(); //returns cost of surrendering battle, -1 if surrendering is not possible const CGTownInstance * battleGetDefendedTown(); //returns defended town if current battle is a siege, NULL instead ui8 battleGetWallState(int partOfWall); //for determining state of a part of the wall; format: parameter [0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; returned value: 1 - intact, 2 - damaged, 3 - destroyed; 0 - no battle - int battleGetWallUnderHex(SBattleHex hex); //returns part of destructible wall / gate / keep under given hex or -1 if not found + int battleGetWallUnderHex(BattleHex hex); //returns part of destructible wall / gate / keep under given hex or -1 if not found std::pair battleEstimateDamage(const CStack * attacker, const CStack * defender, std::pair * retaliationDmg = NULL); //estimates damage dealt by attacker to defender; it may be not precise especially when stack has randomly working bonuses; returns pair ui8 battleGetSiegeLevel(); //returns 0 when there is no siege, 1 if fort, 2 is citadel, 3 is castle const CGHeroInstance * battleGetFightingHero(ui8 side) const; //returns hero corresponding to given side (0 - attacker, 1 - defender) - si8 battleHasDistancePenalty(const CStack * stack, SBattleHex destHex); //checks if given stack has distance penalty - si8 battleHasWallPenalty(const CStack * stack, SBattleHex destHex); //checks if given stack has wall penalty - si8 battleCanTeleportTo(const CStack * stack, SBattleHex destHex, int telportLevel); //checks if teleportation of given stack to given position can take place + si8 battleHasDistancePenalty(const CStack * stack, BattleHex destHex); //checks if given stack has distance penalty + si8 battleHasWallPenalty(const CStack * stack, BattleHex destHex); //checks if given stack has wall penalty + si8 battleCanTeleportTo(const CStack * stack, BattleHex destHex, int telportLevel); //checks if teleportation of given stack to given position can take place si8 battleGetTacticDist(); //returns tactic distance for calling player or 0 if player is not in tactic phase ui8 battleGetMySide(); //return side of player in battle (attacker/defender) diff --git a/lib/IGameEventsReceiver.h b/lib/IGameEventsReceiver.h index 8db5226cf..7f14f3b9b 100644 --- a/lib/IGameEventsReceiver.h +++ b/lib/IGameEventsReceiver.h @@ -1,7 +1,7 @@ #pragma once -#include "SBattleHex.h" +#include "BattleHex.h" #include "int3.h" class CGTownInstance; @@ -45,7 +45,7 @@ public: virtual void battleEnd(const BattleResult *br){}; virtual void battleNewRoundFirst(int round){}; //called at the beginning of each turn before changes are applied; virtual void battleNewRound(int round){}; //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance){}; + virtual void battleStackMoved(const CStack * stack, std::vector dest, int distance){}; virtual void battleSpellCast(const BattleSpellCast *sc){}; virtual void battleStacksEffectsSet(const SetStackEffect & sse){};//called when a specific effect is set to stacks virtual void battleTriggerEffect(const BattleTriggerEffect & bte){}; //called for various one-shot effects diff --git a/lib/Makefile.am b/lib/Makefile.am index 1c6fdf49e..3beffb232 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -67,8 +67,8 @@ libvcmi_la_SOURCES = \ ResourceSet.cpp \ ResourceSet.h \ RegisterTypes.h \ - SBattleHex.cpp \ - SBattleHex.h \ + BattleHex.cpp \ + BattleHex.h \ VCMIDirs.h \ VCMI_Lib.cpp \ VCMI_Lib.h \ diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 2c18f2b02..373ed3a97 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -1214,7 +1214,7 @@ struct BattleResult : public CPackForClient//3003 struct BattleStackMoved : public CPackForClient//3004 { ui32 stack; - std::vector tilesToMove; + std::vector tilesToMove; ui8 distance, teleporting; BattleStackMoved(){type = 3004;}; void applyFirstCl(CClient *cl); @@ -1382,7 +1382,7 @@ struct BattleSpellCast : public CPackForClient//3009 ui8 skill; //caster's skill level ui8 spellCost; ui8 manaGained; //mana channeling ability - SBattleHex tile; //destination tile (may not be set in some global/mass spells + BattleHex tile; //destination tile (may not be set in some global/mass spells std::vector resisted; //ids of creatures that resisted this spell std::set affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure) TCreature attackerType;//id of caster to generate console message; -1 if not set (eg. spell casted by artifact) diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 4d628e6cb..4e5330284 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -1150,7 +1150,7 @@ DLL_LINKAGE void StacksHealedOrResurrected::applyGs( CGameState *gs ) CStack * changedStack = gs->curB->getStack(healedStacks[g].stackID, false); //checking if we resurrect a stack that is under a living stack - std::vector access = gs->curB->getAccessibility(changedStack, true); + std::vector access = gs->curB->getAccessibility(changedStack, true); bool acc[GameConstants::BFIELD_SIZE]; for(int h=0; h + @@ -241,7 +242,6 @@ - VCMI_DLL;%(PreprocessorDefinitions) Create @@ -254,6 +254,7 @@ + @@ -291,7 +292,6 @@ - diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 1b0c53434..c52eca24a 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -682,7 +682,7 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) tlog1 << "Ended handling connection\n"; } -int CGameHandler::moveStack(int stack, SBattleHex dest) +int CGameHandler::moveStack(int stack, BattleHex dest) { int ret = 0; @@ -699,7 +699,7 @@ int CGameHandler::moveStack(int stack, SBattleHex dest) //initing necessary tables bool accessibility[GameConstants::BFIELD_SIZE]; - std::vector accessible = gs->curB->getAccessibility(curStack, false); + std::vector accessible = gs->curB->getAccessibility(curStack, false); for(int b=0; battackerOwned) { if(accessibility[dest+1]) - dest += SBattleHex::RIGHT; + dest += BattleHex::RIGHT; } else { if(accessibility[dest-1]) - dest += SBattleHex::LEFT; + dest += BattleHex::LEFT; } } @@ -728,7 +728,7 @@ int CGameHandler::moveStack(int stack, SBattleHex dest) return 0; bool accessibilityWithOccupyable[GameConstants::BFIELD_SIZE]; - std::vector accOc = gs->curB->getAccessibility(curStack, true); + std::vector accOc = gs->curB->getAccessibility(curStack, true); for(int b=0; b curStack->creature->speed && !(stackAtEnd && dists[dest] == curStack->creature->speed+1)) //we can attack a stack if we can go to adjacent hex // return false; - std::pair< std::vector, int > path = gs->curB->getPath(curStack->position, dest, accessibilityWithOccupyable, curStack->hasBonusOfType(Bonus::FLYING), curStack->doubleWide(), curStack->attackerOwned); + std::pair< std::vector, int > path = gs->curB->getPath(curStack->position, dest, accessibilityWithOccupyable, curStack->hasBonusOfType(Bonus::FLYING), curStack->doubleWide(), curStack->attackerOwned); ret = path.second; @@ -754,7 +754,7 @@ int CGameHandler::moveStack(int stack, SBattleHex dest) //inform clients about move BattleStackMoved sm; sm.stack = curStack->ID; - std::vector tiles; + std::vector tiles; tiles.push_back(path.first[0]); sm.tilesToMove = tiles; sm.distance = path.second; @@ -765,7 +765,7 @@ int CGameHandler::moveStack(int stack, SBattleHex dest) else //for non-flying creatures { // send one package with the creature path information - std::vector tiles; + std::vector tiles; int tilesToMove = std::max((int)(path.first.size() - creSpeed), 0); for(int v=path.first.size()-1; v>=tilesToMove; --v) { @@ -3330,7 +3330,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) CStack * stack = gs->curB->getStack(ba.stackNumber); int spellID = ba.additionalInfo; - SBattleHex destination(ba.destinationTile); + BattleHex destination(ba.destinationTile); int spellLvl = 0; Bonus * bonus = stack->getBonus(Selector::typeSubtype(Bonus::SPELLCASTER, spellID)); @@ -3486,7 +3486,7 @@ void CGameHandler::playerMessage( ui8 player, const std::string &message ) } } -void CGameHandler::handleSpellCasting( int spellID, int spellLvl, SBattleHex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack) +void CGameHandler::handleSpellCasting( int spellID, int spellLvl, BattleHex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack) { const CSpell *spell = VLC->spellh->spells[spellID]; @@ -3737,7 +3737,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, SBattleHex des BattleStackMoved bsm; bsm.distance = -1; bsm.stack = gs->curB->activeStack; - std::vector tiles; + std::vector tiles; tiles.push_back(destination); bsm.tilesToMove = tiles; bsm.teleporting = true; @@ -3826,7 +3826,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, SBattleHex des ObstaclesRemoved obr; for(int g=0; gcurB->obstacles.size(); ++g) { - std::vector blockedHexes = VLC->heroh->obstacles[gs->curB->obstacles[g].ID].getBlocked(gs->curB->obstacles[g].pos); + std::vector blockedHexes = VLC->heroh->obstacles[gs->curB->obstacles[g].ID].getBlocked(gs->curB->obstacles[g].pos); if(vstd::contains(blockedHexes, destination)) //this obstacle covers given hex { diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 1a635dd5e..14581ec30 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -101,7 +101,7 @@ public: bool isAllowedExchange(int id1, int id2); bool isAllowedArrangePack(const ArrangeStacks *pack); void giveSpells(const CGTownInstance *t, const CGHeroInstance *h); - int moveStack(int stack, SBattleHex dest); //returned value - travelled distance + int moveStack(int stack, BattleHex dest); //returned value - travelled distance void startBattle(const CArmedInstance *armies[2], int3 tile, const CGHeroInstance *heroes[2], bool creatureBank, boost::function cb, const CGTownInstance *town = NULL); //use hero=NULL for no hero void runBattle(); void checkLossVictory(ui8 player); @@ -192,7 +192,7 @@ public: void playerMessage( ui8 player, const std::string &message); bool makeBattleAction(BattleAction &ba); - void handleSpellCasting(int spellID, int spellLvl, SBattleHex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack); + void handleSpellCasting(int spellID, int spellLvl, BattleHex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, ECastingMode::ECastingMode mode, const CStack * stack); bool makeCustomAction(BattleAction &ba); void stackTurnTrigger(const CStack * stack); bool queryReply( ui32 qid, ui32 answer, ui8 player );