PageRenderTime 57ms CodeModel.GetById 10ms app.highlight 42ms RepoModel.GetById 2ms 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
  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
 26#include "linden_common.h"
 27
 28#include "lleconomy.h"
 29#include "llerror.h"
 30#include "message.h"
 31#include "v3math.h"
 32
 33
 34LLGlobalEconomy::LLGlobalEconomy()
 35:	mObjectCount( -1 ),
 36	mObjectCapacity( -1 ),
 37	mPriceObjectClaim( -1 ),
 38	mPricePublicObjectDecay( -1 ),
 39	mPricePublicObjectDelete( -1 ),
 40	mPriceEnergyUnit( -1 ),
 41	mPriceUpload( -1 ),
 42	mPriceRentLight( -1 ),
 43	mTeleportMinPrice( -1 ),
 44	mTeleportPriceExponent( -1 ),
 45	mPriceGroupCreate( -1 )
 46{ }
 47
 48LLGlobalEconomy::~LLGlobalEconomy()
 49{ }
 50
 51void LLGlobalEconomy::addObserver(LLEconomyObserver* observer)
 52{
 53	mObservers.push_back(observer);
 54}
 55
 56void LLGlobalEconomy::removeObserver(LLEconomyObserver* observer)
 57{
 58	std::list<LLEconomyObserver*>::iterator it =
 59		std::find(mObservers.begin(), mObservers.end(), observer);
 60	if (it != mObservers.end())
 61	{
 62		mObservers.erase(it);
 63	}
 64}
 65
 66void LLGlobalEconomy::notifyObservers()
 67{
 68	for (std::list<LLEconomyObserver*>::iterator it = mObservers.begin();
 69		it != mObservers.end();
 70		++it)
 71	{
 72		(*it)->onEconomyDataChange();
 73	}
 74}
 75
 76// static
 77void LLGlobalEconomy::processEconomyData(LLMessageSystem *msg, LLGlobalEconomy* econ_data)
 78{
 79	S32 i;
 80	F32 f;
 81
 82	msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCapacity, i);
 83	econ_data->setObjectCapacity(i);
 84	msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCount, i);
 85	econ_data->setObjectCount(i);
 86	msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceEnergyUnit, i);
 87	econ_data->setPriceEnergyUnit(i);
 88	msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceObjectClaim, i);
 89	econ_data->setPriceObjectClaim(i);
 90	msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDecay, i);
 91	econ_data->setPricePublicObjectDecay(i);
 92	msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDelete, i);
 93	econ_data->setPricePublicObjectDelete(i);
 94	msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceUpload, i);
 95	econ_data->setPriceUpload(i);
 96#if LL_LINUX
 97	// We can optionally fake the received upload price for testing.
 98	// Note that the server is within its rights to not obey our fake
 99	// price. :)
100	const char* fakeprice_str = getenv("LL_FAKE_UPLOAD_PRICE");
101	if (fakeprice_str)
102	{
103		S32 fakeprice = (S32)atoi(fakeprice_str);
104		llwarns << "LL_FAKE_UPLOAD_PRICE: Faking upload price as L$" << fakeprice << llendl;
105		econ_data->setPriceUpload(fakeprice);
106	}
107#endif
108	msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceRentLight, i);
109	econ_data->setPriceRentLight(i);
110	msg->getS32Fast(_PREHASH_Info, _PREHASH_TeleportMinPrice, i);
111	econ_data->setTeleportMinPrice(i);
112	msg->getF32Fast(_PREHASH_Info, _PREHASH_TeleportPriceExponent, f);
113	econ_data->setTeleportPriceExponent(f);
114	msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceGroupCreate, i);
115	econ_data->setPriceGroupCreate(i);
116
117	econ_data->notifyObservers();
118}
119
120S32	LLGlobalEconomy::calculateTeleportCost(F32 distance) const
121{
122	S32 min_cost = getTeleportMinPrice();
123	F32 exponent = getTeleportPriceExponent();
124	F32 divisor = 100.f * pow(3.f, exponent);
125	S32 cost = (U32)(distance * pow(log10(distance), exponent) / divisor);
126	if (cost < 0)
127	{
128		cost = 0;
129	}
130	else if (cost < min_cost)
131	{
132		cost = min_cost;
133	}
134
135	return cost;
136}
137
138S32	LLGlobalEconomy::calculateLightRent(const LLVector3& object_size) const
139{
140	F32 intensity_mod = llmax(object_size.magVec(), 1.f);
141	return (S32)(intensity_mod * getPriceRentLight());
142}
143
144void LLGlobalEconomy::print()
145{
146	llinfos << "Global Economy Settings: " << llendl;
147	llinfos << "Object Capacity: " << mObjectCapacity << llendl;
148	llinfos << "Object Count: " << mObjectCount << llendl;
149	llinfos << "Claim Price Per Object: " << mPriceObjectClaim << llendl;
150	llinfos << "Claim Price Per Public Object: " << mPricePublicObjectDecay << llendl;
151	llinfos << "Delete Price Per Public Object: " << mPricePublicObjectDelete << llendl;
152	llinfos << "Release Price Per Public Object: " << getPricePublicObjectRelease() << llendl;
153	llinfos << "Price Per Energy Unit: " << mPriceEnergyUnit << llendl;
154	llinfos << "Price Per Upload: " << mPriceUpload << llendl;
155	llinfos << "Light Base Price: " << mPriceRentLight << llendl;
156	llinfos << "Teleport Min Price: " << mTeleportMinPrice << llendl;
157	llinfos << "Teleport Price Exponent: " << mTeleportPriceExponent << llendl;
158	llinfos << "Price for group creation: " << mPriceGroupCreate << llendl;
159}
160
161LLRegionEconomy::LLRegionEconomy()
162:	LLGlobalEconomy(),
163	mPriceObjectRent( -1.f ),
164	mPriceObjectScaleFactor( -1.f ),
165	mEnergyEfficiency( -1.f ),
166	mBasePriceParcelClaimDefault(-1),
167	mBasePriceParcelClaimActual(-1),
168	mPriceParcelClaimFactor(-1.f),
169	mBasePriceParcelRent(-1),
170	mAreaOwned(-1.f),
171	mAreaTotal(-1.f)
172{ }
173
174LLRegionEconomy::~LLRegionEconomy()
175{ }
176
177BOOL LLRegionEconomy::hasData() const
178{
179	return (mBasePriceParcelRent != -1);
180}
181
182// static
183void LLRegionEconomy::processEconomyData(LLMessageSystem *msg, void** user_data)
184{
185	S32 i;
186	F32 f;
187
188	LLRegionEconomy *this_ptr = (LLRegionEconomy*)user_data;
189
190	LLGlobalEconomy::processEconomyData(msg, this_ptr);
191
192	msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceParcelClaim, i);
193	this_ptr->setBasePriceParcelClaimDefault(i);
194	msg->getF32(_PREHASH_Info, _PREHASH_PriceParcelClaimFactor, f);
195	this_ptr->setPriceParcelClaimFactor(f);
196	msg->getF32Fast(_PREHASH_Info, _PREHASH_EnergyEfficiency, f);
197	this_ptr->setEnergyEfficiency(f);
198	msg->getF32Fast(_PREHASH_Info, _PREHASH_PriceObjectRent, f);
199	this_ptr->setPriceObjectRent(f);
200	msg->getF32Fast(_PREHASH_Info, _PREHASH_PriceObjectScaleFactor, f);
201	this_ptr->setPriceObjectScaleFactor(f);
202	msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceParcelRent, i);
203	this_ptr->setBasePriceParcelRent(i);
204}
205
206// static
207void LLRegionEconomy::processEconomyDataRequest(LLMessageSystem *msg, void **user_data)
208{
209	LLRegionEconomy *this_ptr = (LLRegionEconomy*)user_data;
210	if (!this_ptr->hasData())
211	{
212		llwarns << "Dropping EconomyDataRequest, because EconomyData message "
213				<< "has not been processed" << llendl;
214	}
215
216	msg->newMessageFast(_PREHASH_EconomyData);
217	msg->nextBlockFast(_PREHASH_Info);
218	msg->addS32Fast(_PREHASH_ObjectCapacity, this_ptr->getObjectCapacity());
219	msg->addS32Fast(_PREHASH_ObjectCount, this_ptr->getObjectCount());
220	msg->addS32Fast(_PREHASH_PriceEnergyUnit, this_ptr->getPriceEnergyUnit());
221	msg->addS32Fast(_PREHASH_PriceObjectClaim, this_ptr->getPriceObjectClaim());
222	msg->addS32Fast(_PREHASH_PricePublicObjectDecay, this_ptr->getPricePublicObjectDecay());
223	msg->addS32Fast(_PREHASH_PricePublicObjectDelete, this_ptr->getPricePublicObjectDelete());
224	msg->addS32Fast(_PREHASH_PriceParcelClaim, this_ptr->mBasePriceParcelClaimActual);
225	msg->addF32Fast(_PREHASH_PriceParcelClaimFactor, this_ptr->mPriceParcelClaimFactor);
226	msg->addS32Fast(_PREHASH_PriceUpload, this_ptr->getPriceUpload());
227	msg->addS32Fast(_PREHASH_PriceRentLight, this_ptr->getPriceRentLight());
228	msg->addS32Fast(_PREHASH_TeleportMinPrice, this_ptr->getTeleportMinPrice());
229	msg->addF32Fast(_PREHASH_TeleportPriceExponent, this_ptr->getTeleportPriceExponent());
230
231	msg->addF32Fast(_PREHASH_EnergyEfficiency, this_ptr->getEnergyEfficiency());
232	msg->addF32Fast(_PREHASH_PriceObjectRent, this_ptr->getPriceObjectRent());
233	msg->addF32Fast(_PREHASH_PriceObjectScaleFactor, this_ptr->getPriceObjectScaleFactor());
234	msg->addS32Fast(_PREHASH_PriceParcelRent, this_ptr->getPriceParcelRent());
235	msg->addS32Fast(_PREHASH_PriceGroupCreate, this_ptr->getPriceGroupCreate());
236
237	msg->sendReliable(msg->getSender());
238}
239
240
241S32 LLRegionEconomy::getPriceParcelClaim() const
242{
243	//return (S32)((F32)mBasePriceParcelClaim * (mAreaTotal / (mAreaTotal - mAreaOwned)));
244	return (S32)((F32)mBasePriceParcelClaimActual * mPriceParcelClaimFactor);
245}
246
247S32 LLRegionEconomy::getPriceParcelRent() const
248{
249	return mBasePriceParcelRent;
250}
251
252
253void LLRegionEconomy::print()
254{
255	this->LLGlobalEconomy::print();
256
257	llinfos << "Region Economy Settings: " << llendl;
258	llinfos << "Land (square meters): " << mAreaTotal << llendl;
259	llinfos << "Owned Land (square meters): " << mAreaOwned << llendl;
260	llinfos << "Daily Object Rent: " << mPriceObjectRent << llendl;
261	llinfos << "Daily Land Rent (per meter): " << getPriceParcelRent() << llendl;
262	llinfos << "Energey Efficiency: " << mEnergyEfficiency << llendl;
263}
264
265
266void LLRegionEconomy::setBasePriceParcelClaimDefault(S32 val)
267{
268	mBasePriceParcelClaimDefault = val;
269	if(mBasePriceParcelClaimActual == -1)
270	{
271		mBasePriceParcelClaimActual = val;
272	}
273}
274
275void LLRegionEconomy::setBasePriceParcelClaimActual(S32 val)
276{
277	mBasePriceParcelClaimActual = val;
278}
279
280void LLRegionEconomy::setPriceParcelClaimFactor(F32 val)
281{
282	mPriceParcelClaimFactor = val;
283}
284
285void LLRegionEconomy::setBasePriceParcelRent(S32 val)
286{
287	mBasePriceParcelRent = val;
288}