1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "nel/georges/u_form.h"
24 #include "nel/georges/u_form_elm.h"
25 #include "nel/misc/vector.h"
26 #include "nel/misc/vector_2f.h"
27 #include "client_sheets/village_sheet.h"
28 #include "client_sheets/entity_sheet.h"
29 #include "zone_util.h"
31 #include "ingame_database_manager.h"
32 #include "sheet_manager.h"
33 #include "pacs_client.h"
34 #include "client_cfg.h"
40 using namespace NLMISC
;
43 //===================================================================================
44 CVillage::CVillage() : _Scene(NULL
)
50 for (uint i
=0; i
<RZ_MAX_BUILDING_PER_OUTPOST
; i
++)
56 //===================================================================================
61 //===================================================================================
62 /*virtual*/ bool CVillage::needCompleteLoading(const NLMISC::CVector
&pos
) const
64 nlassert(_Scene
); // should call built
65 return _IG
.needCompleteLoading(pos
);
68 //===================================================================================
69 /*virtual*/ void CVillage::update(const NLMISC::CVector
&pos
)
71 nlassert(_Scene
); // should call built
75 //===================================================================================
76 /*virtual*/ void CVillage::forceUpdate(const NLMISC::CVector
&pos
, NLMISC::IProgressCallback
&progress
)
78 nlassert(_Scene
); // should call built
79 _IG
.forceUpdate(pos
, progress
);
82 //===================================================================================
83 bool CVillage::setupFromSheet(NL3D::UScene
*scene
, const CVillageSheet
&sheet
, CStreamableIG::TString2IG
*loadedIGMap
/*=NULL*/)
85 nlassert(!_Scene
); // should be built only once
92 pos
.z
= sheet
.Altitude
;
95 NLMISC::CVector2f zonePos
;
96 if (!getPosFromZoneName(sheet
.Zone
, zonePos
))
98 nlwarning("Village : invalid zone name (%s)", sheet
.Zone
.c_str());
101 pos
.x
= zonePos
.x
+ sheet
.CenterX
;
102 pos
.y
= zonePos
.y
+ sheet
.CenterY
;
104 _IG
.init(scene
, pos
, sheet
.ForceLoadDist
, sheet
.LoadDist
, sheet
.UnloadDist
);
105 _IG
.setLoadedIGMap(loadedIGMap
);
108 _IG
.reserve((uint
)sheet
.IGs
.size());
110 _IG
.Name
= sheet
.Name
;
113 for(uint k
= 0; k
< sheet
.IGs
.size(); ++k
)
115 _IG
.addIG(sheet
.IGs
[k
].IgName
, sheet
.IGs
[k
].ParentName
, CVector::Null
, CQuat::Identity
);
122 //===================================================================================
123 void CVillage::forceUnload()
128 //===================================================================================
129 void CVillage::registerObserver(IIGObserver
*obs
)
131 _IG
.registerObserver(obs
);
135 //===================================================================================
136 void CVillage::removeObserver(IIGObserver
*obs
)
138 _IG
.removeObserver(obs
);
142 //===================================================================================
143 bool CVillage::isObserver(IIGObserver
*obs
) const
145 return _IG
.isObserver(obs
);
148 //===================================================================================
149 bool CVillage::enumIGs(IIGEnum
*callback
)
151 return _IG
.enumIGs(callback
);
155 // ***************************************************************************
156 // ***************************************************************************
158 // ***************************************************************************
159 // ***************************************************************************
162 //===================================================================================
163 bool CVillage::setupOutpost(NL3D::UScene
*scene
, const CContinentParameters::CZC
&zone
, sint32
/* outpost */, CStreamableIG::TString2IG
*loadedIGMap
)
165 nlassert(!_Scene
); // should be built only once
168 // Get the zone position (for async loading)
170 NLMISC::CVector2f zonePos
;
171 if (!getPosFromZoneName(zone
.Name
, zonePos
))
173 nlwarning("Outpost : invalid zone name (%s)", zone
.Name
.c_str());
181 _IG
.init(scene
, pos
, zone
.ForceLoadDist
, zone
.LoadDist
, zone
.UnloadDist
);
182 _IG
.setLoadedIGMap(loadedIGMap
);
183 _IG
.reserve(RZ_MAX_BUILDING_PER_OUTPOST
);
190 //===================================================================================
191 void CVillage::setBuildingPosition (uint building
, const NLMISC::CQuat
&rot
, const NLMISC::CVector
&pos
)
193 // Set the building position and rotation
194 if (building
<RZ_MAX_BUILDING_PER_OUTPOST
)
196 _Buildings
[building
].Rotation
= rot
;
197 _Buildings
[building
].Position
= pos
;
201 //===================================================================================
202 void CVillage::initOutpost ()
206 // Init the ZC with ruins
207 CSheetId
ruins ("ruins.building");
208 for (uint i
=0; i
<RZ_MAX_BUILDING_PER_OUTPOST
; i
++)
210 updateBuilding(i
, ruins
);
215 //===================================================================================
216 void CVillage::removeOutpost ()
220 // Force form to be reseted so next time outpost is reloaded
221 for (uint i
=0; i
<RZ_MAX_BUILDING_PER_OUTPOST
; i
++)
223 _Buildings
[i
].CurrentSheetId
= CSheetId::Unknown
;
228 //===================================================================================
229 void CVillage::updateBuilding(uint buildingId
, NLMISC::CSheetId newForm
)
231 if(buildingId
>=RZ_MAX_BUILDING_PER_OUTPOST
)
233 CBuilding
&building
= _Buildings
[buildingId
];
235 // Form has changed ?
236 if (building
.CurrentSheetId
!= newForm
)
238 // Resize the streamable ig, if needed
239 for (uint i
=_IG
.getIGNum(); i
<RZ_MAX_BUILDING_PER_OUTPOST
; i
++)
241 // todo hulud add rotation
242 _IG
.addIG("", "", _Buildings
[i
].Position
, _Buildings
[i
].Rotation
);
245 // Ig name for this building
248 // If the Sheet id is unknown, just remove the old building if there was one.
249 if(newForm
!= CSheetId::Unknown
)
251 // Get a pointer on the converted sheet into the client.
252 CEntitySheet
*entitySheet
= SheetMngr
.get(newForm
);
253 const CBuildingSheet
*bldSh
= dynamic_cast<const CBuildingSheet
*>(entitySheet
);
256 // todo hulud here, manage multi igs for multi building state
257 igName
= bldSh
->BuildedIg
;
261 // Set the building IG
262 _IG
.setIG(building
.Id
, igName
, "");
263 building
.CurrentSheetId
= newForm
;