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 not mw then
-- diet --
+
local DefInfo = DefInfo or require "Module:Test"
----------
+
else
 +
local 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'}
 +
  }
 +
  if not Util.table.checkMultiple(def, filters) then return nil end
  
    for _,tool in ipairs(def.tools) do
+
  local projectile = DefInfo.getDef(def.verbs[1].defaultProjectile)
      if tool.power and tool.cooldownTime then
+
  local warmup    = def.verbs[1].warmupTime
        local dps = tool.power / tool.cooldownTime
+
  local cooldown  = def.statBases.RangedWeapon_Cooldown
        tool.DPS = Util.round(dps, 3)
 
      end
 
    end
 
    return true
 
  end,
 
  
   ---------------
+
   if not projectile then return nil 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 burst      = def.verbs[1].burstShotCount
     local damageDef
+
  local pause      = def.verbs[1].ticksBetweenBurstShots
 +
  local damage     = Util.table.check(projectile, 'projectile', 'damageAmountBase') and projectile.projectile.damageAmountBase
 +
  local dps
  
     local damage
+
  if burst and pause then
    local warmup
+
     dps = damage * burst / (warmup + cooldown + burst*(pause/60))
    local cooldown
+
  else
    local burst
+
     dps = damage / (warmup + cooldown)
    local burstPause
+
  end
     local dps
 
  
    projectileDef = DefInfo.getDef(def.verbs[1].defaultProjectile, false)
+
  if dps then
    if not projectileDef then return nil end
+
     def.verbs[1].DPS = Util.round(dps, 3)
 
+
  end
     -- def.verbs[1].defaultProjectile = projectile
+
end
 
 
    if Util.table.check(projectileDef, 'projectile', 'damageAmountBase') then
 
      damage = projectileDef.projectile.damageAmountBase
 
    elseif Util.table.check(projectileDef, 'projectile', 'damageDef') and projectileDef.projectile.damageDef == 'Bomb' then
 
      damageDef = DefInfo.getDef(projectileDef.projectile.damageDef, false)
 
      if damageDef then
 
        damage = damageDef.defaultDamage
 
        -- def.verbs[1].defaultProjectile.projectile.damageDef = damageDef
 
      end
 
    end
 
 
 
    warmup    = def.verbs[1].warmupTime
 
    burst      = def.verbs[1].burstShotCount
 
    burstPause = def.verbs[1].ticksBetweenBurstShots
 
    cooldown  = def.statBases.RangedWeapon_Cooldown
 
 
 
    if burst and pause then
 
      dps = damage * burst / (warmup + cooldown + (burst-1)*(burstPause/60))
 
    else
 
      dps = damage / (warmup + cooldown)
 
    end
 
  
    if dps then
+
-------------------------------------
      def.verbs[1].DPS = Util.round(dps, 3)
+
-- naturally lives in these biomes --
      return true
+
-------------------------------------
    end
+
function VF.vfields.raceLivesIn(def)
  end,
+
  if def.thingClass ~= 'Pawn' then return nil end
  
   -------------------------------------
+
   local biomes = {}
  -- naturally lives in these biomes --
 
  -------------------------------------
 
  pawnLivesIn = function (def)
 
    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 biomeK,biome in pairs(Data) do
+
      for animalK,animal in pairs(biome.wildAnimals) do
      if Util.table.check(biome, 'wildAnimals') then
+
        if animalK == def.defName then
        for animalK,animal in pairs(biome.wildAnimals) do
+
          table.insert(biomes, biome.defName)
          if animalK == def.defName then
 
            table.insert(biomes, biome.defName)
 
          end
 
 
         end
 
         end
 
       end
 
       end
 
     end
 
     end
 +
  end
  
    if #biomes > 0 then
+
  if #biomes > 0 then
      def._.livesIn = biomes
+
    def._.livesIn = biomes
      return true
+
   end
    end
+
end
  end,
 
 
 
   -----------------------
 
  -- 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
 
    local flags = {}
 
    local expandedFoodTypes = {}
 
 
 
    for _,foodType in ipairs(diet) do
 
      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
 
  
    for flag,_ in pairs(flags) do
+
------------------------
      table.insert(expandedFoodTypes, flag)
+
-- module entry point --
    end
+
------------------------
 
+
function VF.expand(mergedDef)
    if #expandedFoodTypes > 0 then
+
  for k,func in pairs(VF.vfields) do
      def.race.foodTypeExpanded = expandedFoodTypes
+
     func(mergedDef)
      return true
 
    end
 
  end,
 
 
 
  -----------------
 
  -- MarketValue -- works only for items (not stuffables)
 
  -----------------
 
  MarketValue = function (def)
 
    if Util.table.check(def, 'statBases', 'MarketValue') then return nil end
 
    if not Util.table.check(def, 'statBases', 'WorkToMake') then return nil end
 
    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)