lleconomy.cpp

Go to the documentation of this file.
00001 
00031 #include "linden_common.h"
00032 
00033 #include "lleconomy.h"
00034 #include "llerror.h"
00035 #include "message.h"
00036 #include "v3math.h"
00037 
00038 LLGlobalEconomy *gGlobalEconomy = NULL;
00039 
00040 LLGlobalEconomy::LLGlobalEconomy()
00041 :       mObjectCount( -1 ),
00042         mObjectCapacity( -1 ),
00043         mPriceObjectClaim( -1 ),
00044         mPricePublicObjectDecay( -1 ),
00045         mPricePublicObjectDelete( -1 ),
00046         mPriceEnergyUnit( -1 ),
00047         mPriceUpload( -1 ),
00048         mPriceRentLight( -1 ),
00049         mTeleportMinPrice( -1 ),
00050         mTeleportPriceExponent( -1 ),
00051         mPriceGroupCreate( -1 )
00052 { }
00053 
00054 LLGlobalEconomy::~LLGlobalEconomy()
00055 { }
00056 
00057 // static
00058 void LLGlobalEconomy::processEconomyData(LLMessageSystem *msg, void** user_data)
00059 {
00060         S32 i;
00061         F32 f;
00062 
00063         LLGlobalEconomy *this_ptr = (LLGlobalEconomy*)user_data;
00064 
00065         msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCapacity, i);
00066         this_ptr->setObjectCapacity(i);
00067         msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCount, i);
00068         this_ptr->setObjectCount(i);
00069         msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceEnergyUnit, i);
00070         this_ptr->setPriceEnergyUnit(i);
00071         msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceObjectClaim, i);
00072         this_ptr->setPriceObjectClaim(i);
00073         msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDecay, i);
00074         this_ptr->setPricePublicObjectDecay(i);
00075         msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDelete, i);
00076         this_ptr->setPricePublicObjectDelete(i);
00077         msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceUpload, i);
00078         this_ptr->setPriceUpload(i);
00079         msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceRentLight, i);
00080         this_ptr->setPriceRentLight(i);
00081         msg->getS32Fast(_PREHASH_Info, _PREHASH_TeleportMinPrice, i);
00082         this_ptr->setTeleportMinPrice(i);
00083         msg->getF32Fast(_PREHASH_Info, _PREHASH_TeleportPriceExponent, f);
00084         this_ptr->setTeleportPriceExponent(f);
00085         msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceGroupCreate, i);
00086         this_ptr->setPriceGroupCreate(i);
00087 }
00088 
00089 S32     LLGlobalEconomy::calculateTeleportCost(F32 distance) const
00090 {
00091         S32 min_cost = getTeleportMinPrice();
00092         F32 exponent = getTeleportPriceExponent();
00093         F32 divisor = 100.f * pow(3.f, exponent);
00094         S32 cost = (U32)(distance * pow(log10(distance), exponent) / divisor);
00095         if (cost < 0)
00096         {
00097                 cost = 0;
00098         }
00099         else if (cost < min_cost)
00100         {
00101                 cost = min_cost;
00102         }
00103 
00104         return cost;
00105 }
00106 
00107 S32     LLGlobalEconomy::calculateLightRent(const LLVector3& object_size) const
00108 {
00109         F32 intensity_mod = llmax(object_size.magVec(), 1.f);
00110         return (S32)(intensity_mod * getPriceRentLight());
00111 }
00112 
00113 void LLGlobalEconomy::print()
00114 {
00115         llinfos << "Global Economy Settings: " << llendl;
00116         llinfos << "Object Capacity: " << mObjectCapacity << llendl;
00117         llinfos << "Object Count: " << mObjectCount << llendl;
00118         llinfos << "Claim Price Per Object: " << mPriceObjectClaim << llendl;
00119         llinfos << "Claim Price Per Public Object: " << mPricePublicObjectDecay << llendl;
00120         llinfos << "Delete Price Per Public Object: " << mPricePublicObjectDelete << llendl;
00121         llinfos << "Release Price Per Public Object: " << getPricePublicObjectRelease() << llendl;
00122         llinfos << "Price Per Energy Unit: " << mPriceEnergyUnit << llendl;
00123         llinfos << "Price Per Upload: " << mPriceUpload << llendl;
00124         llinfos << "Light Base Price: " << mPriceRentLight << llendl;
00125         llinfos << "Teleport Min Price: " << mTeleportMinPrice << llendl;
00126         llinfos << "Teleport Price Exponent: " << mTeleportPriceExponent << llendl;
00127         llinfos << "Price for group creation: " << mPriceGroupCreate << llendl;
00128 }
00129 
00130 LLRegionEconomy::LLRegionEconomy()
00131 :       LLGlobalEconomy(),
00132         mPriceObjectRent( -1.f ),
00133         mPriceObjectScaleFactor( -1.f ),
00134         mEnergyEfficiency( -1.f ),
00135         mBasePriceParcelClaimDefault(-1),
00136         mBasePriceParcelClaimActual(-1),
00137         mPriceParcelClaimFactor(-1.f),
00138         mBasePriceParcelRent(-1),
00139         mAreaOwned(-1.f),
00140         mAreaTotal(-1.f)
00141 { }
00142 
00143 LLRegionEconomy::~LLRegionEconomy()
00144 { }
00145 
00146 BOOL LLRegionEconomy::hasData() const
00147 {
00148         return (mBasePriceParcelRent != -1);
00149 }
00150 
00151 // static
00152 void LLRegionEconomy::processEconomyData(LLMessageSystem *msg, void** user_data)
00153 {
00154         S32 i;
00155         F32 f;
00156 
00157         LLGlobalEconomy::processEconomyData(msg, user_data);
00158 
00159         LLRegionEconomy *this_ptr = (LLRegionEconomy*)user_data;
00160 
00161         msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceParcelClaim, i);
00162         this_ptr->setBasePriceParcelClaimDefault(i);
00163         msg->getF32(_PREHASH_Info, _PREHASH_PriceParcelClaimFactor, f);
00164         this_ptr->setPriceParcelClaimFactor(f);
00165         msg->getF32Fast(_PREHASH_Info, _PREHASH_EnergyEfficiency, f);
00166         this_ptr->setEnergyEfficiency(f);
00167         msg->getF32Fast(_PREHASH_Info, _PREHASH_PriceObjectRent, f);
00168         this_ptr->setPriceObjectRent(f);
00169         msg->getF32Fast(_PREHASH_Info, _PREHASH_PriceObjectScaleFactor, f);
00170         this_ptr->setPriceObjectScaleFactor(f);
00171         msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceParcelRent, i);
00172         this_ptr->setBasePriceParcelRent(i);
00173 }
00174 
00175 // static
00176 void LLRegionEconomy::processEconomyDataRequest(LLMessageSystem *msg, void **user_data)
00177 {
00178         LLRegionEconomy *this_ptr = (LLRegionEconomy*)user_data;
00179         if (!this_ptr->hasData())
00180         {
00181                 llwarns << "Dropping EconomyDataRequest, because EconomyData message "
00182                                 << "has not been processed" << llendl;
00183         }
00184 
00185         msg->newMessageFast(_PREHASH_EconomyData);
00186         msg->nextBlockFast(_PREHASH_Info);
00187         msg->addS32Fast(_PREHASH_ObjectCapacity, this_ptr->getObjectCapacity());
00188         msg->addS32Fast(_PREHASH_ObjectCount, this_ptr->getObjectCount());
00189         msg->addS32Fast(_PREHASH_PriceEnergyUnit, this_ptr->getPriceEnergyUnit());
00190         msg->addS32Fast(_PREHASH_PriceObjectClaim, this_ptr->getPriceObjectClaim());
00191         msg->addS32Fast(_PREHASH_PricePublicObjectDecay, this_ptr->getPricePublicObjectDecay());
00192         msg->addS32Fast(_PREHASH_PricePublicObjectDelete, this_ptr->getPricePublicObjectDelete());
00193         msg->addS32Fast(_PREHASH_PriceParcelClaim, this_ptr->mBasePriceParcelClaimActual);
00194         msg->addF32Fast(_PREHASH_PriceParcelClaimFactor, this_ptr->mPriceParcelClaimFactor);
00195         msg->addS32Fast(_PREHASH_PriceUpload, this_ptr->getPriceUpload());
00196         msg->addS32Fast(_PREHASH_PriceRentLight, this_ptr->getPriceRentLight());
00197         msg->addS32Fast(_PREHASH_TeleportMinPrice, this_ptr->getTeleportMinPrice());
00198         msg->addF32Fast(_PREHASH_TeleportPriceExponent, this_ptr->getTeleportPriceExponent());
00199 
00200         msg->addF32Fast(_PREHASH_EnergyEfficiency, this_ptr->getEnergyEfficiency());
00201         msg->addF32Fast(_PREHASH_PriceObjectRent, this_ptr->getPriceObjectRent());
00202         msg->addF32Fast(_PREHASH_PriceObjectScaleFactor, this_ptr->getPriceObjectScaleFactor());
00203         msg->addS32Fast(_PREHASH_PriceParcelRent, this_ptr->getPriceParcelRent());
00204         msg->addS32Fast(_PREHASH_PriceGroupCreate, this_ptr->getPriceGroupCreate());
00205 
00206         msg->sendReliable(msg->getSender());
00207 }
00208 
00209 
00210 S32 LLRegionEconomy::getPriceParcelClaim() const
00211 {
00212         //return (S32)((F32)mBasePriceParcelClaim * (mAreaTotal / (mAreaTotal - mAreaOwned)));
00213         return (S32)((F32)mBasePriceParcelClaimActual * mPriceParcelClaimFactor);
00214 }
00215 
00216 S32 LLRegionEconomy::getPriceParcelRent() const
00217 {
00218         return mBasePriceParcelRent;
00219 }
00220 
00221 
00222 void LLRegionEconomy::print()
00223 {
00224         this->LLGlobalEconomy::print();
00225 
00226         llinfos << "Region Economy Settings: " << llendl;
00227         llinfos << "Land (square meters): " << mAreaTotal << llendl;
00228         llinfos << "Owned Land (square meters): " << mAreaOwned << llendl;
00229         llinfos << "Daily Object Rent: " << mPriceObjectRent << llendl;
00230         llinfos << "Daily Land Rent (per meter): " << getPriceParcelRent() << llendl;
00231         llinfos << "Energey Efficiency: " << mEnergyEfficiency << llendl;
00232 }
00233 
00234 
00235 void LLRegionEconomy::setBasePriceParcelClaimDefault(S32 val)
00236 {
00237         mBasePriceParcelClaimDefault = val;
00238         if(mBasePriceParcelClaimActual == -1)
00239         {
00240                 mBasePriceParcelClaimActual = val;
00241         }
00242 }
00243 
00244 void LLRegionEconomy::setBasePriceParcelClaimActual(S32 val)
00245 {
00246         mBasePriceParcelClaimActual = val;
00247 }
00248 
00249 void LLRegionEconomy::setPriceParcelClaimFactor(F32 val)
00250 {
00251         mPriceParcelClaimFactor = val;
00252 }
00253 
00254 void LLRegionEconomy::setBasePriceParcelRent(S32 val)
00255 {
00256         mBasePriceParcelRent = val;
00257 }

Generated on Thu Jul 1 06:08:28 2010 for Second Life Viewer by  doxygen 1.4.7