Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / 3d / tile_vegetable_desc.cpp
blob849f195033509fde4142805f993083eaf3751e87
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
17 #include "std3d.h"
19 #include "nel/3d/tile_vegetable_desc.h"
20 #include "nel/misc/common.h"
21 #include "nel/3d/vegetable_manager.h"
24 using namespace NLMISC;
25 using namespace std;
27 #ifdef DEBUG_NEW
28 #define new DEBUG_NEW
29 #endif
31 namespace NL3D
36 // ***************************************************************************
37 CTileVegetableDesc::CTileVegetableDesc()
39 _Empty= true;
42 // ***************************************************************************
43 void CTileVegetableDesc::clear()
45 for(sint i=0; i<NL3D_VEGETABLE_BLOCK_NUMDIST; i++)
47 _VegetableList[i].clear();
49 _Empty= true;
52 // ***************************************************************************
53 void CTileVegetableDesc::build(const std::vector<CVegetable> &vegetables)
55 uint i;
57 // first clear().
58 clear();
60 // Parse all landscape vegetables, and store them in appropriate distance Type.
61 for(i=0;i<vegetables.size();i++)
63 uint distType= vegetables[i].DistType;
64 distType= min(distType, (uint)(NL3D_VEGETABLE_BLOCK_NUMDIST-1));
65 _VegetableList[distType].push_back(vegetables[i]);
68 // Compute Seed such that creation of one vegetable for a tile will never receive same seed.
69 uint sumVeget= 0;
70 for(i=0; i<NL3D_VEGETABLE_BLOCK_NUMDIST; i++)
72 _VegetableSeed[i]= sumVeget;
73 // add number of vegetable for next seed.
74 sumVeget+= (uint)_VegetableList[i].size();
77 // compile some data
78 compileRunTime();
81 // ***************************************************************************
82 void CTileVegetableDesc::registerToManager(CVegetableManager *vegetableManager)
84 // Pasre all distanceType.
85 for(uint i=0; i<NL3D_VEGETABLE_BLOCK_NUMDIST; i++)
87 // Parse all vegetables of the list.
88 for(uint j=0; j<_VegetableList[i].size(); j++)
90 // register the vegetable to the manager
91 _VegetableList[i][j].registerToManager(vegetableManager);
96 // ***************************************************************************
97 void CTileVegetableDesc::serial(NLMISC::IStream &f)
99 (void)f.serialVersion(0);
101 nlassert(NL3D_VEGETABLE_BLOCK_NUMDIST==5);
102 for(uint i=0; i<NL3D_VEGETABLE_BLOCK_NUMDIST; i++)
104 f.serialCont(_VegetableList[i]);
105 f.serial(_VegetableSeed[i]);
108 // compile some data
109 if(f.isReading())
110 compileRunTime();
113 // ***************************************************************************
114 const std::vector<CVegetable> &CTileVegetableDesc::getVegetableList(uint distType) const
116 nlassert(distType < NL3D_VEGETABLE_BLOCK_NUMDIST);
118 return _VegetableList[distType];
121 // ***************************************************************************
122 uint CTileVegetableDesc::getVegetableSeed(uint distType) const
124 nlassert(distType < NL3D_VEGETABLE_BLOCK_NUMDIST);
126 return _VegetableSeed[distType];
129 // ***************************************************************************
130 void CTileVegetableDesc::compileRunTime()
132 // Compute _Empty flag
133 _Empty= true;
134 for(uint i=0; i<NL3D_VEGETABLE_BLOCK_NUMDIST; i++)
136 if(!_VegetableList[i].empty())
138 _Empty= false;
139 break;
146 } // NL3D