Planeshift

lootrandomizer.h

Go to the documentation of this file.
00001 /*
00002  * lootrandomizer.h by Stefano Angeleri
00003  *
00004  * Copyright (C) 2010 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  */
00018 
00019 #ifndef __LOOTRANDOMIZER_H__
00020 #define __LOOTRANDOMIZER_H__
00021 
00022 class RandomizedOverlay;
00023 
00032 struct LootModifier
00033 {
00034     uint32_t id;                       
00035     uint32_t mod_id;                   
00036     csString modifier_type;            
00037     csString name;                     
00038     csString effect;                   
00039     csString equip_script;             
00040     float    probability;              
00041     float    probabilityRange;         
00042     csString stat_req_modifier;        
00043     float    cost_modifier;            
00044     csString mesh;                     
00045     csString icon;                     
00046     csString not_usable_with;          
00047     csHash<bool, uint32_t> itemRestrain; 
00048 
00049     // Return true if this modifier is allowed with the given item stats ID.
00050     bool IsAllowed(uint32_t itemID);
00051 };
00052 
00057 struct ValueModifier
00058 {
00059     csString name;  
00060     csString op;    
00061     float value;    
00062 };
00063 
00064 class MathScript;
00069 class LootRandomizer
00070 {
00071 protected:
00072     csArray<LootModifier*> prefixes;   
00073     csArray<LootModifier*> suffixes;   
00074     csArray<LootModifier*> adjectives; 
00075     csHash<LootModifier*, uint32_t> LootModifiersById;  
00076 
00077     // precalculated max values for probability. min is always 0
00078     float prefix_max;
00079     float adjective_max;
00080     float suffix_max;
00081 
00082 public:
00088     LootRandomizer(CacheManager* cachemanager);
00092     ~LootRandomizer();
00093 
00097     void AddLootModifier(LootModifier* entry);
00098 
00105     LootModifier* GetModifier(uint32_t id);
00106  
00114     bool GetModifiers(uint32_t itemID, csArray<psGMSpawnMods::ItemModifier>& mods);
00115 
00123     psItem* SetModifiers(psItem* item, csArray<uint32_t>& mods);
00124 
00134     psItem* RandomizeItem(psItem* item,
00135                           float cost,
00136                           bool lootTesting = false,
00137                           size_t numModifiers = 0);
00138 
00146     float CalcModifierCostCap(psCharacter* chr);
00147 
00155     void ApplyModifier(psItemStats* baseItem, RandomizedOverlay* overlay, csArray<uint32_t> &modifiersIds);
00156 
00164     float GetModifierPercentProbability(int modifierID, int modifierType);
00165 
00166 protected:
00167     MathScript* modifierCostCalc; 
00168     CacheManager* cacheManager; 
00169 
00170 private:
00171     void AddModifier(LootModifier* oper1, LootModifier* oper2);
00172 
00185     bool SetAttribute(const csString &op, const csString &attrName, float modifier, RandomizedOverlay* overlay, psItemStats* baseItem, csArray<ValueModifier> &values);
00186 
00195     void SetAttributeApplyOP(float* value[], float modifier, size_t amount, const csString &op);
00196 
00206     csString GenerateScriptXML(csString &name, csString &equip_script, csArray<ValueModifier> &values);
00207 };
00208 
00211 #endif
00212