Merge branch '164-crash-on-patching-and-possibly-right-after-login' into main/gingo...
[ryzomcore.git] / ryzom / client / src / outpost.cpp
blob9f9723b625620dc4c8fbf2e13893c0bf024c88b3
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdpch.h"
22 #include "outpost.h"
23 #include "zone_util.h"
24 #include "pacs_client.h"
25 #include "client_cfg.h"
26 #include "village.h"
28 using namespace NLMISC;
29 using namespace NLPACS;
32 // ***************************************************************************
33 COutpost::COutpost()
35 _OutpostId= -1;
38 // ***************************************************************************
39 COutpost::~COutpost()
41 removeOutpost();
44 // ***************************************************************************
45 COutpost::COutpost(const COutpost &other)
47 for(uint i=0;i<RZ_MAX_BUILDING_PER_OUTPOST;i++)
48 _Buildings[i]= other._Buildings[i];
49 // must not have addedprims, else dtor crash
50 nlassert(other._AddedPrims.empty());
51 _OutpostId= other._OutpostId;
52 _Village= other._Village;
55 // ***************************************************************************
56 bool COutpost::setupOutpost(const CContinentParameters::CZC &zone, sint32 outpostId, CVillage *village)
58 // Yoyo. legacy code. should no more be needed now. Still let for check (useful?)
59 NLMISC::CVector2f zonePos;
60 if (!getPosFromZoneName(zone.Name, zonePos))
62 nlwarning("Outpost : invalid zone name (%s)", zone.Name.c_str());
63 return false;
66 // set the outpost id
67 _OutpostId = outpostId;
69 // set the village for ruins display (if any)
70 _Village= village;
72 return true;
76 // ***************************************************************************
77 void COutpost::setBuildingPosition (uint building, const NLMISC::CQuat &rot, const NLMISC::CVector &pos)
79 // Set the building position and rotation
80 if (building<RZ_MAX_BUILDING_PER_OUTPOST)
82 _Buildings[building].Rotation = rot;
83 _Buildings[building].Position = pos;
86 // if a village is setuped for ruins display, setup it
87 if(_Village)
88 _Village->setBuildingPosition(building, rot, pos);
91 // ***************************************************************************
92 void COutpost::initOutpost ()
94 // remove the outpost from col, if any
95 removeOutpost();
97 // Add collisions, if correclty setuped
98 if (_OutpostId > -1)
100 // Register RZ_MAX_BUILDING_PER_OUTPOST observers for the RZ_MAX_BUILDING_PER_OUTPOST buildings
101 uint i;
102 for (i=0; i<RZ_MAX_BUILDING_PER_OUTPOST; i++)
104 // Put the ZC pacs_prim
105 TPacsPrimMap::iterator pbIt = PacsPrims.find(NLMISC::toLowerAscii(NLMISC::CFile::getFilenameWithoutExtension(ClientCfg.ZCPacsPrim)));
106 if (pbIt != PacsPrims.end())
108 // Build the building matrix
109 NLMISC::CMatrix instanceMatrix;
110 instanceMatrix.identity();
111 instanceMatrix.setRot(_Buildings[i].Rotation);
112 instanceMatrix.setPos(_Buildings[i].Position);
114 // Compute orientation and position
115 NLMISC::CVector pos;
116 float angle;
117 NLPACS::UMoveContainer::getPACSCoordsFromMatrix(pos, angle, instanceMatrix);
119 // insert the matching primitive block
120 if (PACS)
121 PACS->addCollisionnablePrimitiveBlock(pbIt->second, 0, 1, &_AddedPrims, angle, pos, true, CVector(1,1,1));
126 // add 3D if needed
127 if(_Village)
128 _Village->initOutpost();
131 // ***************************************************************************
132 void COutpost::removeOutpost ()
134 // remove collisions
135 if(PACS)
137 for(uint i=0; i<_AddedPrims.size(); i++)
139 PACS->removePrimitive(_AddedPrims[i]);
141 _AddedPrims.clear();
144 // remove 3D
145 if(_Village)
146 _Village->removeOutpost();