Module:Test/data/virtual

From RimWorld Wiki
< Module:Test‎ | data
Revision as of 21:07, 17 May 2021 by Dr. Strangelove (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

----------
-- diet --
----------
local VF = {}
VF.diet = {}
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
--~       return "Never eats"
--~   end
--~   if util.diet[foodType].Tree then
--~       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

--~ ------------------------
--~ -- module entry point --
--~ ------------------------
--~ function VF.expand(mergedDef)
--~   for k,func in pairs(VF.vfields) do
--~     func(mergedDef)
--~   end
--~ end

return {

  --------------
  -- tool DPS --
  --------------
  toolDPS = function (def)
    if not def.tools then return nil end

    for _,tool in ipairs(def.tools) do
      if tool.power and tool.cooldownTime then
        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 warmup
    local cooldown
    local burst
    local burstPause
    local dps

    projectileDef = DefInfo.getDef(def.verbs[1].defaultProjectile, false)
    if not projectileDef then return nil end

    -- def.verbs[1].defaultProjectile = projectile

    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)
      return true
    end
  end,

  -------------------------------------
  -- 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 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
      return true
    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)
    end

    if #expandedFoodTypes > 0 then
      def.race.foodTypeExpanded = expandedFoodTypes
      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


}