PageRenderTime 40ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llinventory/lleconomy.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 288 lines | 220 code | 37 blank | 31 comment | 12 complexity | 433b3b30dc4ad4ab2d24d734f8ef61be MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lleconomy.cpp
  3. *
  4. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #include "linden_common.h"
  26. #include "lleconomy.h"
  27. #include "llerror.h"
  28. #include "message.h"
  29. #include "v3math.h"
  30. LLGlobalEconomy::LLGlobalEconomy()
  31. : mObjectCount( -1 ),
  32. mObjectCapacity( -1 ),
  33. mPriceObjectClaim( -1 ),
  34. mPricePublicObjectDecay( -1 ),
  35. mPricePublicObjectDelete( -1 ),
  36. mPriceEnergyUnit( -1 ),
  37. mPriceUpload( -1 ),
  38. mPriceRentLight( -1 ),
  39. mTeleportMinPrice( -1 ),
  40. mTeleportPriceExponent( -1 ),
  41. mPriceGroupCreate( -1 )
  42. { }
  43. LLGlobalEconomy::~LLGlobalEconomy()
  44. { }
  45. void LLGlobalEconomy::addObserver(LLEconomyObserver* observer)
  46. {
  47. mObservers.push_back(observer);
  48. }
  49. void LLGlobalEconomy::removeObserver(LLEconomyObserver* observer)
  50. {
  51. std::list<LLEconomyObserver*>::iterator it =
  52. std::find(mObservers.begin(), mObservers.end(), observer);
  53. if (it != mObservers.end())
  54. {
  55. mObservers.erase(it);
  56. }
  57. }
  58. void LLGlobalEconomy::notifyObservers()
  59. {
  60. for (std::list<LLEconomyObserver*>::iterator it = mObservers.begin();
  61. it != mObservers.end();
  62. ++it)
  63. {
  64. (*it)->onEconomyDataChange();
  65. }
  66. }
  67. // static
  68. void LLGlobalEconomy::processEconomyData(LLMessageSystem *msg, LLGlobalEconomy* econ_data)
  69. {
  70. S32 i;
  71. F32 f;
  72. msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCapacity, i);
  73. econ_data->setObjectCapacity(i);
  74. msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCount, i);
  75. econ_data->setObjectCount(i);
  76. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceEnergyUnit, i);
  77. econ_data->setPriceEnergyUnit(i);
  78. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceObjectClaim, i);
  79. econ_data->setPriceObjectClaim(i);
  80. msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDecay, i);
  81. econ_data->setPricePublicObjectDecay(i);
  82. msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDelete, i);
  83. econ_data->setPricePublicObjectDelete(i);
  84. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceUpload, i);
  85. econ_data->setPriceUpload(i);
  86. #if LL_LINUX
  87. // We can optionally fake the received upload price for testing.
  88. // Note that the server is within its rights to not obey our fake
  89. // price. :)
  90. const char* fakeprice_str = getenv("LL_FAKE_UPLOAD_PRICE");
  91. if (fakeprice_str)
  92. {
  93. S32 fakeprice = (S32)atoi(fakeprice_str);
  94. llwarns << "LL_FAKE_UPLOAD_PRICE: Faking upload price as L$" << fakeprice << llendl;
  95. econ_data->setPriceUpload(fakeprice);
  96. }
  97. #endif
  98. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceRentLight, i);
  99. econ_data->setPriceRentLight(i);
  100. msg->getS32Fast(_PREHASH_Info, _PREHASH_TeleportMinPrice, i);
  101. econ_data->setTeleportMinPrice(i);
  102. msg->getF32Fast(_PREHASH_Info, _PREHASH_TeleportPriceExponent, f);
  103. econ_data->setTeleportPriceExponent(f);
  104. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceGroupCreate, i);
  105. econ_data->setPriceGroupCreate(i);
  106. econ_data->notifyObservers();
  107. }
  108. S32 LLGlobalEconomy::calculateTeleportCost(F32 distance) const
  109. {
  110. S32 min_cost = getTeleportMinPrice();
  111. F32 exponent = getTeleportPriceExponent();
  112. F32 divisor = 100.f * pow(3.f, exponent);
  113. S32 cost = (U32)(distance * pow(log10(distance), exponent) / divisor);
  114. if (cost < 0)
  115. {
  116. cost = 0;
  117. }
  118. else if (cost < min_cost)
  119. {
  120. cost = min_cost;
  121. }
  122. return cost;
  123. }
  124. S32 LLGlobalEconomy::calculateLightRent(const LLVector3& object_size) const
  125. {
  126. F32 intensity_mod = llmax(object_size.magVec(), 1.f);
  127. return (S32)(intensity_mod * getPriceRentLight());
  128. }
  129. void LLGlobalEconomy::print()
  130. {
  131. llinfos << "Global Economy Settings: " << llendl;
  132. llinfos << "Object Capacity: " << mObjectCapacity << llendl;
  133. llinfos << "Object Count: " << mObjectCount << llendl;
  134. llinfos << "Claim Price Per Object: " << mPriceObjectClaim << llendl;
  135. llinfos << "Claim Price Per Public Object: " << mPricePublicObjectDecay << llendl;
  136. llinfos << "Delete Price Per Public Object: " << mPricePublicObjectDelete << llendl;
  137. llinfos << "Release Price Per Public Object: " << getPricePublicObjectRelease() << llendl;
  138. llinfos << "Price Per Energy Unit: " << mPriceEnergyUnit << llendl;
  139. llinfos << "Price Per Upload: " << mPriceUpload << llendl;
  140. llinfos << "Light Base Price: " << mPriceRentLight << llendl;
  141. llinfos << "Teleport Min Price: " << mTeleportMinPrice << llendl;
  142. llinfos << "Teleport Price Exponent: " << mTeleportPriceExponent << llendl;
  143. llinfos << "Price for group creation: " << mPriceGroupCreate << llendl;
  144. }
  145. LLRegionEconomy::LLRegionEconomy()
  146. : LLGlobalEconomy(),
  147. mPriceObjectRent( -1.f ),
  148. mPriceObjectScaleFactor( -1.f ),
  149. mEnergyEfficiency( -1.f ),
  150. mBasePriceParcelClaimDefault(-1),
  151. mBasePriceParcelClaimActual(-1),
  152. mPriceParcelClaimFactor(-1.f),
  153. mBasePriceParcelRent(-1),
  154. mAreaOwned(-1.f),
  155. mAreaTotal(-1.f)
  156. { }
  157. LLRegionEconomy::~LLRegionEconomy()
  158. { }
  159. BOOL LLRegionEconomy::hasData() const
  160. {
  161. return (mBasePriceParcelRent != -1);
  162. }
  163. // static
  164. void LLRegionEconomy::processEconomyData(LLMessageSystem *msg, void** user_data)
  165. {
  166. S32 i;
  167. F32 f;
  168. LLRegionEconomy *this_ptr = (LLRegionEconomy*)user_data;
  169. LLGlobalEconomy::processEconomyData(msg, this_ptr);
  170. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceParcelClaim, i);
  171. this_ptr->setBasePriceParcelClaimDefault(i);
  172. msg->getF32(_PREHASH_Info, _PREHASH_PriceParcelClaimFactor, f);
  173. this_ptr->setPriceParcelClaimFactor(f);
  174. msg->getF32Fast(_PREHASH_Info, _PREHASH_EnergyEfficiency, f);
  175. this_ptr->setEnergyEfficiency(f);
  176. msg->getF32Fast(_PREHASH_Info, _PREHASH_PriceObjectRent, f);
  177. this_ptr->setPriceObjectRent(f);
  178. msg->getF32Fast(_PREHASH_Info, _PREHASH_PriceObjectScaleFactor, f);
  179. this_ptr->setPriceObjectScaleFactor(f);
  180. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceParcelRent, i);
  181. this_ptr->setBasePriceParcelRent(i);
  182. }
  183. // static
  184. void LLRegionEconomy::processEconomyDataRequest(LLMessageSystem *msg, void **user_data)
  185. {
  186. LLRegionEconomy *this_ptr = (LLRegionEconomy*)user_data;
  187. if (!this_ptr->hasData())
  188. {
  189. llwarns << "Dropping EconomyDataRequest, because EconomyData message "
  190. << "has not been processed" << llendl;
  191. }
  192. msg->newMessageFast(_PREHASH_EconomyData);
  193. msg->nextBlockFast(_PREHASH_Info);
  194. msg->addS32Fast(_PREHASH_ObjectCapacity, this_ptr->getObjectCapacity());
  195. msg->addS32Fast(_PREHASH_ObjectCount, this_ptr->getObjectCount());
  196. msg->addS32Fast(_PREHASH_PriceEnergyUnit, this_ptr->getPriceEnergyUnit());
  197. msg->addS32Fast(_PREHASH_PriceObjectClaim, this_ptr->getPriceObjectClaim());
  198. msg->addS32Fast(_PREHASH_PricePublicObjectDecay, this_ptr->getPricePublicObjectDecay());
  199. msg->addS32Fast(_PREHASH_PricePublicObjectDelete, this_ptr->getPricePublicObjectDelete());
  200. msg->addS32Fast(_PREHASH_PriceParcelClaim, this_ptr->mBasePriceParcelClaimActual);
  201. msg->addF32Fast(_PREHASH_PriceParcelClaimFactor, this_ptr->mPriceParcelClaimFactor);
  202. msg->addS32Fast(_PREHASH_PriceUpload, this_ptr->getPriceUpload());
  203. msg->addS32Fast(_PREHASH_PriceRentLight, this_ptr->getPriceRentLight());
  204. msg->addS32Fast(_PREHASH_TeleportMinPrice, this_ptr->getTeleportMinPrice());
  205. msg->addF32Fast(_PREHASH_TeleportPriceExponent, this_ptr->getTeleportPriceExponent());
  206. msg->addF32Fast(_PREHASH_EnergyEfficiency, this_ptr->getEnergyEfficiency());
  207. msg->addF32Fast(_PREHASH_PriceObjectRent, this_ptr->getPriceObjectRent());
  208. msg->addF32Fast(_PREHASH_PriceObjectScaleFactor, this_ptr->getPriceObjectScaleFactor());
  209. msg->addS32Fast(_PREHASH_PriceParcelRent, this_ptr->getPriceParcelRent());
  210. msg->addS32Fast(_PREHASH_PriceGroupCreate, this_ptr->getPriceGroupCreate());
  211. msg->sendReliable(msg->getSender());
  212. }
  213. S32 LLRegionEconomy::getPriceParcelClaim() const
  214. {
  215. //return (S32)((F32)mBasePriceParcelClaim * (mAreaTotal / (mAreaTotal - mAreaOwned)));
  216. return (S32)((F32)mBasePriceParcelClaimActual * mPriceParcelClaimFactor);
  217. }
  218. S32 LLRegionEconomy::getPriceParcelRent() const
  219. {
  220. return mBasePriceParcelRent;
  221. }
  222. void LLRegionEconomy::print()
  223. {
  224. this->LLGlobalEconomy::print();
  225. llinfos << "Region Economy Settings: " << llendl;
  226. llinfos << "Land (square meters): " << mAreaTotal << llendl;
  227. llinfos << "Owned Land (square meters): " << mAreaOwned << llendl;
  228. llinfos << "Daily Object Rent: " << mPriceObjectRent << llendl;
  229. llinfos << "Daily Land Rent (per meter): " << getPriceParcelRent() << llendl;
  230. llinfos << "Energey Efficiency: " << mEnergyEfficiency << llendl;
  231. }
  232. void LLRegionEconomy::setBasePriceParcelClaimDefault(S32 val)
  233. {
  234. mBasePriceParcelClaimDefault = val;
  235. if(mBasePriceParcelClaimActual == -1)
  236. {
  237. mBasePriceParcelClaimActual = val;
  238. }
  239. }
  240. void LLRegionEconomy::setBasePriceParcelClaimActual(S32 val)
  241. {
  242. mBasePriceParcelClaimActual = val;
  243. }
  244. void LLRegionEconomy::setPriceParcelClaimFactor(F32 val)
  245. {
  246. mPriceParcelClaimFactor = val;
  247. }
  248. void LLRegionEconomy::setBasePriceParcelRent(S32 val)
  249. {
  250. mBasePriceParcelRent = val;
  251. }