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

- a bit less memory usage during compilation with gcc, new file - RegisterTypes.cpp

- fixed several issues related to visiting town by ally
- fixed #1215
This commit is contained in:
Ivan Savenko
2013-02-23 12:22:23 +00:00
parent fbb1ae1bb8
commit 74ac44662c
18 changed files with 87 additions and 86 deletions

View File

@@ -200,10 +200,12 @@ int CBattleCallback::sendRequest(const CPack *request)
void CCallback::swapGarrisonHero( const CGTownInstance *town )
{
if(town->tempOwner != *player) return;
GarrisonHeroSwap pack(town->id);
sendRequest(&pack);
if(town->tempOwner == *player
|| (town->garrisonHero && town->garrisonHero->tempOwner == *player ))
{
GarrisonHeroSwap pack(town->id);
sendRequest(&pack);
}
}
void CCallback::buyArtifact(const CGHeroInstance *hero, ArtifactID aid)

View File

@@ -899,7 +899,7 @@ void CCastleInterface::close()
{
if(town->tempOwner == LOCPLINT->playerID) //we may have opened window for an allied town
{
if(town->visitingHero)
if(town->visitingHero && town->visitingHero->tempOwner == LOCPLINT->playerID)
adventureInt->select(town->visitingHero);
else
adventureInt->select(town);

View File

@@ -132,7 +132,6 @@ void init()
loadDLLClasses();
const_cast<CGameInfo*>(CGI)->setFromLib();
CCS->soundh->initCreaturesSounds(CGI->creh->creatures);
CCS->soundh->initSpellsSounds(CGI->spellh->spells);
tlog0<<"Initializing VCMI_Lib: "<<tmh.getDiff()<<std::endl;

View File

@@ -187,31 +187,14 @@ soundBase::soundID CSoundHandler::getSoundID(const std::string &fileName)
return it->second;
}
void CSoundHandler::initCreaturesSounds(const std::vector<ConstTransitivePtr< CCreature> > &creatures)
{
//commented to avoid spurious warnings
/*
// Find creatures without sounds
for(ui32 i=0;i<creatures.size();i++)
{
// Note: this will exclude war machines, but it's better
// than nothing.
if (vstd::contains(CGI->creh->notUsedMonsters, i))
continue;
CCreature &c = creatures[i];
if (c.sounds.killed == soundBase::invalid)
tlog1 << "creature " << c.idNumber << " doesn't have sounds" << std::endl;
}*/
}
void CSoundHandler::initSpellsSounds(const std::vector< ConstTransitivePtr<CSpell> > &spells)
{
const JsonNode config(ResourceID("config/sp_sounds.json"));
if (!config["spell_sounds"].isNull()) {
BOOST_FOREACH(const JsonNode &node, config["spell_sounds"].Vector()) {
if (!config["spell_sounds"].isNull())
{
BOOST_FOREACH(const JsonNode &node, config["spell_sounds"].Vector())
{
int spellid = node["id"].Float();
const CSpell *s = CGI->spellh->spells[spellid];

View File

@@ -56,7 +56,6 @@ public:
void init();
void release();
void initCreaturesSounds(const std::vector<ConstTransitivePtr<CCreature> > &creatures);
void initSpellsSounds(const std::vector< ConstTransitivePtr<CSpell> > &spells);
void setVolume(ui32 percent);

View File

@@ -499,13 +499,15 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
if(town->garrisonHero && vstd::contains(wanderingHeroes,town->garrisonHero)) //wandering hero moved to the garrison
{
CGI->mh->hideObject(town->garrisonHero);
wanderingHeroes -= town->garrisonHero;
if (town->garrisonHero->tempOwner == playerID) // our hero
wanderingHeroes -= town->garrisonHero;
}
if(town->visitingHero && !vstd::contains(wanderingHeroes,town->visitingHero)) //hero leaves garrison
{
CGI->mh->printObject(town->visitingHero);
wanderingHeroes.push_back(town->visitingHero);
if (town->visitingHero == playerID) // our hero
wanderingHeroes.push_back(town->visitingHero);
}
adventureInt->heroList.update();
adventureInt->updateNextHero(NULL);

View File

@@ -450,8 +450,22 @@ void SetAvailableCreatures::applyCl( CClient *cl )
void SetHeroesInTown::applyCl( CClient *cl )
{
CGTownInstance *t = GS(cl)->getTown(tid);
if(vstd::contains(cl->playerint,t->tempOwner))
cl->playerint[t->tempOwner]->heroInGarrisonChange(t);
CGHeroInstance *hGarr = GS(cl)->getHero(this->garrison);
CGHeroInstance *hVisit = GS(cl)->getHero(this->visiting);
std::set<TPlayerColor> playersToNotify;
if(vstd::contains(cl->playerint,t->tempOwner)) // our town
playersToNotify.insert(t->tempOwner);
if (hGarr && vstd::contains(cl->playerint, hGarr->tempOwner))
playersToNotify.insert(hGarr->tempOwner);
if (hVisit && vstd::contains(cl->playerint, hVisit->tempOwner))
playersToNotify.insert(hVisit->tempOwner);
BOOST_FOREACH(auto playerID, playersToNotify)
cl->playerint[playerID]->heroInGarrisonChange(t);
}
// void SetHeroArtifacts::applyCl( CClient *cl )
@@ -776,7 +790,7 @@ void SaveGame::applyCl(CClient *cl)
CResourceHandler::get()->createResource(info.getStem() + ".vcgm1");
//FIXME: Workaround for a file that was created by server and in future should be used only by server
CResourceHandler::get()->createResource(info.getStem() + ".vlgm1");
CResourceHandler::get()->createResource(info.getStem() + ".vsgm1");
try
{

View File

@@ -48,18 +48,6 @@ class CGObjectInstance;
*
*/
void foofoofoo()
{
//never called function to force instantation of templates
int *ccc = NULL;
registerTypes((CISer<CConnection>&)*ccc);
registerTypes((COSer<CConnection>&)*ccc);
registerTypes((CSaveFile&)*ccc);
registerTypes((CLoadFile&)*ccc);
registerTypes((CLoadIntegrityValidator&)*ccc);
registerTypes((CTypeList&)*ccc);
}
template <typename T> class CApplyOnGS;
class CBaseForGSApply

View File

@@ -50,6 +50,7 @@ set(lib_SRCS
JsonNode.cpp
NetPacksLib.cpp
ResourceSet.cpp
RegisterTypes.cpp
VCMI_Lib.cpp
)

View File

@@ -1,27 +1,7 @@
#include "StdInc.h"
#include "Connection.h"
#ifndef _MSC_VER
#include "RegisterTypes.h"
#endif
//for smart objs serialization over net
#include "Mapping/CMapInfo.h"
#include "StartInfo.h"
#include "BattleState.h"
#include "CGameState.h"
#include "Mapping/CMap.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CSpellHandler.h"
#include "CTownHandler.h"
#include "Mapping/CCampaignHandler.h"
#include "NetPacks.h"
#include "CDefObjInfoHandler.h"
#include <boost/asio.hpp>
@@ -37,7 +17,13 @@
using namespace boost;
using namespace boost::asio::ip;
template<typename Serializer> DLL_LINKAGE void registerTypes(Serializer &s); //defined elsewhere and explicitly instantiated for used serializers
extern template void registerTypes<CISer<CConnection> >(CISer<CConnection>& s);
extern template void registerTypes<COSer<CConnection> >(COSer<CConnection>& s);
extern template void registerTypes<CSaveFile>(CSaveFile & s);
extern template void registerTypes<CLoadFile>(CLoadFile & s);
extern template void registerTypes<CTypeList>(CTypeList & s);
extern template void registerTypes<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);
CTypeList typeList;

View File

@@ -12,15 +12,7 @@
#pragma once
#include <typeinfo> //XXX this is in namespace std if you want w/o use typeinfo.h?
#include <boost/type_traits/is_fundamental.hpp>
#include <boost/type_traits/is_enum.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <type_traits>
#include <boost/variant.hpp>
#include <boost/mpl/eval_if.hpp>

View File

@@ -252,7 +252,6 @@ EResType::Type EResTypeHelper::getTypeFromExtension(std::string extension)
(".SND", EResType::ARCHIVE_SND)
(".PAL", EResType::PALETTE)
(".VCGM1", EResType::CLIENT_SAVEGAME)
(".VLGM1", EResType::LIB_SAVEGAME)
(".VSGM1", EResType::SERVER_SAVEGAME)
(".ERM", EResType::ERM)
(".ERT", EResType::ERT)
@@ -285,7 +284,6 @@ std::string EResTypeHelper::getEResTypeAsString(EResType::Type type)
MAP_ENUM(ARCHIVE_VID)
MAP_ENUM(PALETTE)
MAP_ENUM(CLIENT_SAVEGAME)
MAP_ENUM(LIB_SAVEGAME)
MAP_ENUM(SERVER_SAVEGAME)
MAP_ENUM(DIRECTORY)
MAP_ENUM(ERM)

View File

@@ -57,7 +57,6 @@ namespace EResType
ARCHIVE_LOD,
PALETTE,
CLIENT_SAVEGAME,
LIB_SAVEGAME,
SERVER_SAVEGAME,
DIRECTORY,
ERM,

View File

@@ -156,9 +156,9 @@ bool operator OP (const CLASS_NAME & b) const \
#define INSTID_LIKE_CLASS_COMMON(CLASS_NAME) \
public: \
CLASS_NAME() : BaseForID<CLASS_NAME>(-1) {} \
CLASS_NAME(const CLASS_NAME & other) \
CLASS_NAME(const CLASS_NAME & other): \
BaseForID<CLASS_NAME>(other) \
{ \
num = other.num; \
} \
CLASS_NAME & operator=(const CLASS_NAME & other) \
{ \

36
lib/RegisterTypes.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "Mapping/CMapInfo.h"
#include "StartInfo.h"
#include "BattleState.h"
#include "CGameState.h"
#include "Mapping/CMap.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CSpellHandler.h"
#include "CTownHandler.h"
#include "Mapping/CCampaignHandler.h"
#include "NetPacks.h"
#include "CDefObjInfoHandler.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
*
*/
template void registerTypes<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypes<COSer<CConnection>>(COSer<CConnection>& s);
template void registerTypes<CSaveFile>(CSaveFile & s);
template void registerTypes<CLoadFile>(CLoadFile & s);
template void registerTypes<CTypeList>(CTypeList & s);
template void registerTypes<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);

View File

@@ -256,7 +256,7 @@ void registerTypes4(Serializer &s)
}
template<typename Serializer>
void registerTypes(Serializer &s)
void DLL_LINKAGE registerTypes(Serializer &s)
{
registerTypes1(s);
registerTypes2(s);

View File

@@ -1722,6 +1722,8 @@ bool CGameHandler::moveHero( ObjectInstanceID hid, int3 dst, ui8 instant, TPlaye
&& complain("Cannot disembark hero, tile is blocked!"))
|| ( (distance(h->pos, dst) >= 1.5 && !instant)
&& complain("Tiles are not neighboring!"))
|| ( (h->inTownGarrison)
&& complain("Can not move garrisoned hero!"))
|| ((h->movement < cost && dst != h->pos && !instant)
&& complain("Hero doesn't have any movement points left!"))
|| (states.checkFlag(h->tempOwner, &PlayerStatus::engagedIntoBattle)

View File

@@ -178,18 +178,18 @@ then
data_dir="$temp_dir"/cddir
mkdir -p "$data_dir"
unshield -d "$data_dir" x "$cd1_dir"/_setup/data1.cab || fail "Error: failed to extract from Install Shield installer!" "rm -rf $data_dir"
# a bit tricky - different releases have different root directory. Move extracted files to data_dir
if [ -d "$data_dir"/Heroes3 ]
then
mv "$data_dir"/Heroes3/* "$data_dir"
mv "$data_dir"/Heroes3/* "$data_dir"
elif [ -d "$data_dir""/Program_Files" ]
then
mv "$data_dir"/Program_Files/* "$data_dir"
mv "$data_dir"/Program_Files/* "$data_dir"
else
echo "Error: failed to find extracted game files!"
echo "Extracted directories are: "
ls -la "$data_dir"
ls -la "$data_dir"
echo "Please report this on vcmi.eu"
exit 1;
fi
@@ -231,7 +231,7 @@ then
wget "http://download.vcmi.eu/WoG/wog.zip" -O "$temp_dir"/wog.zip || fail "Error: failed to download WoG archive!" "rm -f wog.zip"
wog_archive="$temp_dir"/wog.zip
fi
if [[ -z "$vcmi_archive" ]]
then
wget "http://download.vcmi.eu/core.zip" -O "$temp_dir"/core.zip || fail "Error: failed to download VCMI archive!" "rm -f core.zip"