Editing Module:Test/data/virtual

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
----------
+
if mw then
-- diet --
+
  DefInfo = DefInfo or require("Module:Test")
----------
+
else
 +
  DefInfo = DefInfo or require "DefInfo"
 +
end
 +
 
 
local VF = {}
 
local VF = {}
VF.diet = {}
+
VF.vfields = {}
VF.diet.foodType = {
 
  None = true,
 
  VegetableOrFruit = true,
 
  Meat = true,
 
  Fluid = true,
 
  Corpse = true,
 
  Seed = true,
 
  AnimalProduct = true,
 
  Plant = true,
 
  Tree = true,
 
  Meal = true,
 
  Processed = true,
 
  Liquor = true,
 
  Kibble = true,
 
  VegetarianAnimal = {
 
    VegetableOrFruit = true,
 
    Seed = true,
 
    Meal = true,
 
    Processed = true,
 
    Liquor = true,
 
    Kibble = true
 
  },
 
  VegetarianRoughAnimal = {
 
    VegetableOrFruit = true,
 
    Seed = true,
 
    Plant = true,
 
    Meal = true,
 
    Processed = true,
 
    Liquor = true,
 
    Kibble = true
 
  },
 
  CarnivoreAnimal = {
 
    Meat = true,
 
    Corpse = true,
 
    Meal = true,
 
    Processed = true,
 
    Kibble = true
 
  },
 
  CarnivoreAnimalStrict = {
 
    Meat = true,
 
    Corpse = true
 
  },
 
  OmnivoreAnimal = {
 
    VegetableOrFruit = true,
 
    Meat = true,
 
    Corpse = true,
 
    Seed = true,
 
    Meal = true,
 
    Processed = true,
 
    Liquor = true,
 
    Kibble = true
 
  },
 
  OmnivoreRoughAnimal = {
 
    VegetableOrFruit = true,
 
    Meat = true,
 
    Corpse = true,
 
    Seed = true,
 
    Plant = true,
 
    Meal = true,
 
    Processed = true,
 
    Liquor = true,
 
    Kibble = true
 
  },
 
  DendrovoreAnimal = {
 
    VegetableOrFruit = true,
 
    Seed = true,
 
    Tree = true,
 
    Processed = true,
 
    Kibble = true
 
  },
 
  OvivoreAnimal = {
 
    AnimalProduct = true,
 
    Meal = true,
 
    Processed = true,
 
    Kibble = true
 
  },
 
  OmnivoreHuman = {
 
    VegetableOrFruit = true,
 
    Meat = true,
 
    Fluid = true,
 
    Corpse = true,
 
    Seed = true,
 
    AnimalProduct = true,
 
    Meal = true,
 
    Processed = true,
 
    Liquor = true,
 
    Kibble = true
 
  }
 
}
 
  
--~ function VF.diet.resolveDietCategory(foodType)
+
---------------
--~  if util.diet[foodType].None then
+
-- tools.DPS --
--~      return "Never eats"
+
---------------
--~  end
+
function VF.vfields.unarmedDPS(def)
--~  if util.diet[foodType].Tree then
+
   if not def.tools then return nil end
--~      return "Dendrovorous"
 
--~  end
 
--~  if util.diet[foodType].Meat then
 
--~      if util.diet[foodType].VegetableOrFruit or util.diet[foodType].Plant then
 
--~          return "Omnivorous"
 
--~      end
 
--~      return "Carnivorous"
 
--~  end
 
--~  if util.diet[foodType].AnimalProduct then
 
--~      return "Ovivorous"
 
--~  end
 
--~   return "Herbivorous"
 
--~ end
 
  
--~ ------------------------
+
   for _,tool in ipairs(def.tools) do
--~ -- module entry point --
+
     local dps = tool.power / tool.cooldownTime
--~ ------------------------
+
    if dps then tool.DPS = Util.round(dps, 3) end
--~ function VF.expand(mergedDef)
+
   end
--~   for k,func in pairs(VF.vfields) do
+
end
--~     func(mergedDef)
 
--~   end
 
--~ end
 
  
return {
+
---------------
 
+
-- verbs.DPS --
  --------------
+
---------------
  -- tool DPS --
+
function VF.vfields.verbsDPS(def)
  --------------
+
  local filters = {
  toolDPS = function (def)
+
    {'verbs', 1, 'defaultProjectile'},
    if not def.tools then return nil end
+
    {'verbs', 1, 'warmupTime'},
 
+
    {'statBases', 'RangedWeapon_Cooldown'}
    for _,tool in ipairs(def.tools) do
+
  }
      if tool.power and tool.cooldownTime then
+
  if not Util.table.checkMultiple(def, filters) then return nil end
        local dps = tool.power / tool.cooldownTime
 
        tool.DPS = Util.round(dps, 3)
 
      end
 
    end
 
    return true
 
  end,
 
 
 
  ---------------
 
  -- verb DPS --
 
  ---------------
 
  verbDPS = function (def)
 
    local filters = {
 
      {'verbs', 1, 'defaultProjectile'},
 
      {'verbs', 1, 'warmupTime'},
 
      {'statBases', 'RangedWeapon_Cooldown'}
 
    }
 
    if not Util.table.checkMultiple(def, filters) then return nil end
 
 
 
    local projectileDef
 
    local damageDef
 
  
    local damage
+
  local projectile = DefInfo.getDef(def.verbs[1].defaultProjectile)
    local warmup
+
  if not projectile then return nil end
    local cooldown
 
    local burst
 
    local burstPause
 
    local dps
 
  
    projectileDef = DefInfo.getDef(def.verbs[1].defaultProjectile, false)
+
  def.verbs[1].defaultProjectile = projectile
    if not projectileDef then return nil end
 
  
    -- def.verbs[1].defaultProjectile = projectile
+
  local damage
  
    if Util.table.check(projectileDef, 'projectile', 'damageAmountBase') then
+
  if Util.table.check(projectile, 'projectile', 'damageAmountBase') then
      damage = projectileDef.projectile.damageAmountBase
+
    damage = projectile.projectile.damageAmountBase
    elseif Util.table.check(projectileDef, 'projectile', 'damageDef') and projectileDef.projectile.damageDef == 'Bomb' then
+
  elseif Util.table.check(projectile, 'projectile', 'damageDef') and projectile.projectile.damageDef == 'Bomb' then
      damageDef = DefInfo.getDef(projectileDef.projectile.damageDef, false)
+
    local bomb = DefInfo.getDef(projectile.projectile.damageDef)
      if damageDef then
+
    if bomb then
        damage = damageDef.defaultDamage
+
      damage = bomb.defaultDamage
        -- def.verbs[1].defaultProjectile.projectile.damageDef = damageDef
+
      def.verbs[1].defaultProjectile.projectile.damageDef = bomb
      end
 
 
     end
 
     end
 +
  end
  
    warmup    = def.verbs[1].warmupTime
+
  local warmup    = def.verbs[1].warmupTime
    burst      = def.verbs[1].burstShotCount
+
  local cooldown  = def.statBases.RangedWeapon_Cooldown
    burstPause = def.verbs[1].ticksBetweenBurstShots
+
  local burst      = def.verbs[1].burstShotCount
    cooldown  = def.statBases.RangedWeapon_Cooldown
+
  local pause      = def.verbs[1].ticksBetweenBurstShots
  
    if burst and pause then
+
  local dps
      dps = damage * burst / (warmup + cooldown + (burst-1)*(burstPause/60))
 
    else
 
      dps = damage / (warmup + cooldown)
 
    end
 
  
    if dps then
+
  if burst and pause then
      def.verbs[1].DPS = Util.round(dps, 3)
+
    dps = damage * burst / (warmup + cooldown + (burst-1)*(pause/60))
      return true
+
  else
     end
+
     dps = damage / (warmup + cooldown)
   end,
+
   end
  
   -------------------------------------
+
   if dps then
  -- naturally lives in these biomes --
+
     def.verbs[1].DPS = Util.round(dps, 3)
  -------------------------------------
+
  end
  pawnLivesIn = function (def)
+
end
    if def.thingClass ~= 'Pawn' then return nil end
 
 
 
     local biomes = {}
 
 
 
    for biomeK,biome in pairs(Data) do
 
      if Util.table.check(biome, 'wildAnimals') then
 
        for animalK,animal in pairs(biome.wildAnimals) do
 
          if animalK == def.defName then
 
            table.insert(biomes, biome.defName)
 
          end
 
        end
 
      end
 
    end
 
  
    if #biomes > 0 then
+
-------------------------------------
      def._.livesIn = biomes
+
-- naturally lives in these biomes --
      return true
+
-------------------------------------
    end
+
function VF.vfields.raceLivesIn(def)
  end,
+
  if def.thingClass ~= 'Pawn' then return nil end
  
   -----------------------
+
   local biomes = {}
  -- foodType expanded --
 
  -----------------------
 
  foodTypeExpanded = function (def)
 
    if def.thingClass ~= 'Pawn' then return nil end
 
    -- if not Util.table.check(def, 'race', 'foodType') then return nil end
 
  
    local diet = def.race.foodType
+
  for biomeK,biome in pairs(Data) do
    local flags = {}
+
    if Util.table.check(biome, 'wildAnimals') then
    local expandedFoodTypes = {}
+
       for animalK,animal in pairs(biome.wildAnimals) do
 
+
        if animalK == def.defName then
    for _,foodType in ipairs(diet) do
+
           table.insert(biomes, biome.defName)
      if type(VF.diet.foodType[foodType]) == "boolean" then
 
        flags[foodType] = true
 
       else
 
        for foodItem,_ in pairs(VF.diet.foodType[foodType]) do
 
           flags[foodItem] = true
 
 
         end
 
         end
 
       end
 
       end
 
     end
 
     end
 +
  end
  
    for flag,_ in pairs(flags) do
+
  if #biomes > 0 then
      table.insert(expandedFoodTypes, flag)
+
    def._.livesIn = biomes
    end
+
  end
 
+
end
    if #expandedFoodTypes > 0 then
 
      def.race.foodTypeExpanded = expandedFoodTypes
 
      return true
 
    end
 
  end,
 
  
  -----------------
+
------------------------
  -- MarketValue -- works only for items (not stuffables)
+
-- module entry point --
  -----------------
+
------------------------
  MarketValue = function (def)
+
function VF.expand(mergedDef)
    if Util.table.check(def, 'statBases', 'MarketValue') then return nil end
+
  for k,func in pairs(VF.vfields) do
    if not Util.table.check(def, 'statBases', 'WorkToMake') then return nil end
+
     func(mergedDef)
    if not Util.table.check(def, 'costList') then return nil end
 
 
 
    local workRate = 0.0036
 
    local workCost
 
    local ingredientCost = 0
 
 
 
    if def.costList then
 
      for k,v in pairs(def.costList) do
 
        ingredientCost = ingredientCost + Data['ThingDef:'..k].statBases.MarketValue * v
 
      end
 
     end
 
 
 
    workCost = def.statBases.WorkToMake * workRate
 
 
 
    def.statBases.MarketValue = ingredientCost + workCost
 
 
 
    return true
 
 
   end
 
   end
 +
end
  
 
+
return VF
}
 

Please note that all contributions to RimWorld Wiki are considered to be released under the CC BY-SA 3.0 (see RimWorld Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)