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