Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / client_sheets / flora_sheet.cpp
blob445d0fbe86b21927d7a8ac796c2288fb461577a0
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
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/>.
19 #include "stdpch.h"
20 #include "flora_sheet.h"
22 #include "nel/georges/u_form_elm.h"
24 using namespace NLGEORGES;
26 // ***************************************************************************************************
27 CFloraSheet::CFloraSheet()
29 Type = FLORA;
30 _TotalWeight = 0;
33 // ***************************************************************************************************
34 void CFloraSheet::build(const NLGEORGES::UFormElm &item)
36 const UFormElm *plantArray = NULL;
37 if (item.getNodeByName(&plantArray, "Plants") && plantArray)
39 uint numPlants;
40 nlverify(plantArray->getArraySize(numPlants));
41 _Plants.reserve(numPlants);
42 for(uint k = 0; k < numPlants; ++k)
44 const UFormElm *subNode = NULL;
45 if (plantArray->getArrayNode(&subNode, k) && subNode)
47 CPlantInfo pi;
48 pi.build(*subNode);
49 pi.CumulatedWeight = _TotalWeight;
50 _TotalWeight += pi.Weight;
51 _Plants.push_back(pi);
55 item.getValueByName(MicroLifeThreshold, "MicroLifeThreshold");
58 // ***************************************************************************************************
59 void CFloraSheet::serial(NLMISC::IStream &f)
61 f.serialCont(_Plants);
62 f.serial(MicroLifeThreshold);
63 f.serial(_TotalWeight);
66 // ***************************************************************************************************
67 void CPlantInfo::build(const NLGEORGES::UFormElm &item)
69 item.getValueByName(SheetName, "File name");
70 item.getValueByName(Weight, "MicroLifeWeight");
71 if (Weight == 0)
73 nlwarning("Plant with weight equal to 0");
77 // ***************************************************************************************************
78 void CPlantInfo::serial(NLMISC::IStream &f)
80 f.serial(SheetName);
81 f.serial(CumulatedWeight);
84 // ***************************************************************************************************
85 const CPlantInfo *CFloraSheet::getPlantInfoFromWeightedIndex(uint64 index) const
87 if (_TotalWeight == 0) return NULL;
88 CPlantInfo comp;
89 comp.CumulatedWeight = index;
90 std::vector<CPlantInfo>::const_iterator it = std::lower_bound(_Plants.begin(), _Plants.end(), comp);
91 if (it == _Plants.end()) return &(_Plants.back());
92 if (it == _Plants.begin()) return &(_Plants.front());
93 return it->CumulatedWeight == index ? &(*it) : &(*(it - 1));