Module:AmmoTable

From BTAWiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:AmmoTable/doc

-- Module:AmmoTable creates a fancy-pants table of ammo

-- declare p at the top, return p at the bottom. Functions of p are what's
-- exposed to #invoke calls.
local p = {}

-- we use the getArgs function from the args module to get the args out
-- of either the invoke call, or the template that called invoke.
local getArgs = require('Module:Arguments').getArgs
-- import the Gear module so that we can use its core.cargo.query function,
-- which does the table joins for you. we'll only import 'core', which has
-- the kind of library functions that we want.
local gear = require('Module:Gear').core

-- functions always take a frame as an argument. The frame describes the
-- page that's calling the function
function p.make_ammo(frame)
  -- just always start with this, trust me.
  local tpl_args = getArgs(frame, {parentFirst=true})

  -- now, let's say the parameter on the template for this is just category,
  -- and the template gets a whole category of ammunition.
  local category = tpl_args['Category']

  -- now we are going to query the ammo table. We want to replicate something
  -- similar to the ammo tables created by hand earlier, so we'll use the fields
  -- UIName, Tonnage, Capacity, and Effects.
  -- the database has both fields Name and UIName, and they're slightly different.
  -- check the database first and pick the one that fits best.
  local fields = 'Gear.UIName,Gear.Tonnage,Ammunition.Capacity,Gear.Bonuses,Ammunition.PerUnitCost'
  -- we only want the ammo types that match the category that the caller
  -- specified, so we'll set up a where argument. to make this easier, we
  -- will use string.format.
  local args = { where = string.format('Ammunition.Category="%s"', category) }
  local ammoRows = gear.cargo.query(gear.schema.ammunition, fields, args)

  -- now, we'll use scribunto's html library to build a pretty table
  -- start with, obviously, a table
  local ammoTable = mw.html.create('table')
  -- note here we use a colon : instead of a period. that's because this is
  -- a method call in Lua, not a function call.
  ammoTable:addClass('wikitable')

  -- now, we can set up the table headings
  local heading = ammoTable:tag('tr')
  heading:tag('th'):wikitext('Name')
  heading:tag('th'):wikitext('Tonnage')
  heading:tag('th'):wikitext('Capacity')
  heading:tag('th'):wikitext('Cost per shot')
  heading:tag('th'):wikitext('Effects')

  -- now we get to the meat of the code, where we're looping through the
  -- query results
  for _, ammo in ipairs(ammoRows) do
    local row = ammoTable:tag('tr')
    row:tag('td'):wikitext(ammo['Gear.UIName'])
    row:tag('td'):wikitext(ammo['Gear.Tonnage'])
    row:tag('td'):wikitext(ammo['Ammunition.Capacity'])
    row:tag('td'):wikitext(ammo['Ammunition.PerUnitCost'])

    -- now here comes a bit of a weird part. In blatant disregard for 
    -- the First Normal Form, the Bonuses field is a comma-separated list.
    -- we want to make it pretty though, so what we'll do is put the bonuses
    -- in a ul tag
    local bonusList = row:tag('td'):tag('ul')
    for _, bonus in ipairs(mw.text.split(ammo['Gear.Bonuses'], ',')) do
      -- skip including CostPerShot in the bonuses list, because it's covered
      -- in its own column in the table.
	  if (bonus == 'Caseless') then
	    bonusList:tag('li'):wikitext([[Caseless Ammo increases recoil but fits more ammo per bin.]])
	  
	  elseif (bonus == 'AlwaysStartsFire') then
	    bonusList:tag('li'):wikitext([[Always ignites forests.]])

	  elseif (bonus == 'AlwaysStartsFireAnywhere') then
	    bonusList:tag('li'):wikitext([[Always ignites all terrain.]])

	  elseif (bonus == 'SabotDmg: 20') then
	    bonusList:tag('li'):wikitext([[HEAP does 20 more damage per shot.]])

	  elseif (bonus == 'SabotPercent: 25') then
	    bonusList:tag('li'):wikitext([[HEAP does 25% more damage to armor and 25% less damage to structure.]])

	  elseif (bonus == 'FireTerrainSize: 1') then
	    bonusList:tag('li'):wikitext([[Area Of Burning Terrain: 1]])

	  elseif (bonus == 'FireTerrainSize: 10') then
	    bonusList:tag('li'):wikitext([[Area Of Burning Terrain: 10]])

	  elseif (bonus == 'FireTerrainDuration: 2') then
	    bonusList:tag('li'):wikitext([[Duration Of Burning Terrain: 2]])

	  elseif (bonus == 'FireTerrainDuration: 4') then
	    bonusList:tag('li'):wikitext([[Duration Of Burning Terrain: 4]])

	  elseif (bonus == 'FireTerrainStrength: 2') then
	    bonusList:tag('li'):wikitext([[Strength Of Burning Terrain: 2]])

	  elseif (bonus == 'FireTerrainStrength: 20') then
	    bonusList:tag('li'):wikitext([[Strength Of Burning Terrain: 20]])

	  elseif (bonus == 'FireTerrainStrength: 40') then
	    bonusList:tag('li'):wikitext([[Strength Of Burning Terrain: 40]])

	  elseif (bonus == 'OHDamage: 25%') then
	    bonusList:tag('li'):wikitext([[25% bonus Damage against overheating Targets.]])
		
	  elseif (bonus == 'OHDamage: 10%') then
	    bonusList:tag('li'):wikitext([[10% bonus Damage against overheating Targets.]])
		
	  elseif (bonus == 'ImpSight: -75%') then
	    bonusList:tag('li'):wikitext([[Target has 75% reduced Sight for 2 Turns]])

	  elseif (bonus == 'ImpSensors: -30%') then
	    bonusList:tag('li'):wikitext([[Target has 30% reduced Sensors for 2 Turns]])

	  elseif (bonus == 'Thunder') then
	    bonusList:tag('li'):wikitext([[FASCAM munitions will create a minefield wherever a missile hit the ground.]])
	  
  	  elseif (bonus == 'ThunderCripple') then
		bonusList:tag('li'):wikitext([[FASCAM munitions automatically damage the triggering unit's legs and will stop movement through them if they damage leg structure directly.]])

	  elseif (bonus == 'Airburst') then
	    bonusList:tag('li'):wikitext([[Airburst shells split into 4 bomblets after 210m, scattering their payload over the target area.]])

	  elseif (bonus == 'AirburstThumper') then
	    bonusList:tag('li'):wikitext([[Airburst shells split into 10 bomblets after 300m, scattering their payload over the target area.]])

	  elseif (bonus == 'AirburstArrowIV') then
	    bonusList:tag('li'):wikitext([[Airburst shells split into 20 bomblets after 300m, scattering their payload over the target area.]])

	  elseif (bonus == 'AirburstPenalty: 40%') then
	    bonusList:tag('li'):wikitext([[40% damage penalty to direct hits before the airburst shell splits normally, so under 300m.]])

	  elseif (bonus == 'PlasmaNoBoom') then
		bonusList:tag('li'):wikitext([[Plasma Ammo does not explode.]])

	  elseif (bonus == 'Acid: 20%') then
		bonusList:tag('li'):wikitext([[Targets take 20% more damage for 2 Turns - Multiple effects do not stack.]])

	  elseif (bonus == 'ThunderMines: 1') then
		bonusList:tag('li'):wikitext([[Mines Per Projectile: 1]])

	  elseif (bonus == 'ThunderMines: 2') then
		bonusList:tag('li'):wikitext([[Mines Per Projectile: 2]])
		
	  elseif (bonus == 'ThunderMines: 3') then
		bonusList:tag('li'):wikitext([[Mines Per Projectile: 3]])

	  elseif (bonus == 'ThunderChance: 80%') then
		bonusList:tag('li'):wikitext([[Mine Trigger Chance: 80%]])

	  elseif (bonus == 'ThunderChance: 20%') then
		bonusList:tag('li'):wikitext([[Mine Trigger Chance: 20%]])

	  elseif (bonus == 'ThunderAOERadius: 30') then
		bonusList:tag('li'):wikitext([[AOE Mine Explosion Radius: 30]])

	  elseif (bonus == 'ThunderRadius: 5') then
		bonusList:tag('li'):wikitext([[Mine Trigger Radius: 5]])

	  elseif (bonus == 'ThunderRadius: 6') then
		bonusList:tag('li'):wikitext([[Mine Trigger Radius: 6]])

	  elseif (bonus == 'ThunderDamage: 1') then
		bonusList:tag('li'):wikitext([[Direct Mine Damage: 1]])
		
	  elseif (bonus == 'ThunderDamage: 3') then
		bonusList:tag('li'):wikitext([[Direct Mine Damage: 3]])

	  elseif (bonus == 'ThunderDamage: 4') then
		bonusList:tag('li'):wikitext([[Direct Mine Damage: 4]])

	  elseif (bonus == 'ThunderDamage: 5') then
		bonusList:tag('li'):wikitext([[Direct Mine Damage: 5]])
		
	  elseif (bonus == 'ThunderHeatDamage: 1') then
		bonusList:tag('li'):wikitext([[Direct Mine Heat Damage: 1]])	  

	  elseif (bonus == 'ThunderHeatDamage: 3') then
		bonusList:tag('li'):wikitext([[Direct Mine Heat Damage: 3]])	 
		
	  elseif (bonus == 'ThunderHeatDamage: 5') then
		bonusList:tag('li'):wikitext([[Direct Mine Heat Damage: 5]])	 

	  elseif (bonus == 'ThunderAOEDamage: 5') then
		bonusList:tag('li'):wikitext([[AOE Mine Damage: 5]]) 	

	  elseif (bonus == 'ThunderAOEDamage: 10') then
		bonusList:tag('li'):wikitext([[AOE Mine Damage: 10]]) 

	  elseif (bonus == 'ThunderAOEHeatDamage: 5') then
		bonusList:tag('li'):wikitext([[AOE Mine Heat Damage: 5]]) 	

	  elseif (bonus == 'ThunderAOEStabDamage: 1') then
		bonusList:tag('li'):wikitext([[AOE Mine Stability Damage: 1]]) 

	  elseif (bonus == 'VariableDmg: 20') then
		bonusList:tag('li'):wikitext([[Damage can vary between +/- 20]]) 

	  elseif (bonus == 'VariableDmg: -10') then
		bonusList:tag('li'):wikitext([[Damage can vary between +/- 10]]) 
		
	  elseif (bonus == 'VariableDmg: -15') then
		bonusList:tag('li'):wikitext([[Damage can vary between +/- 15]]) 

	  elseif (bonus == 'DamageMod: -50%') then
		bonusList:tag('li'):wikitext([[Deals 50% less Damage to all targets.]]) 
		
	  elseif (bonus == 'DamageMod: -75%') then
		bonusList:tag('li'):wikitext([[Deals 75% less Damage to all targets.]]) 

	  elseif (bonus == 'StructureDmgMod: -50%') then
		bonusList:tag('li'):wikitext([[Deals 50% less Damage to Structure.]]) 

	  elseif (bonus == 'StructureDmgMod: -75%') then
		bonusList:tag('li'):wikitext([[Deals 75% less Damage to Structure.]]) 
		
	  elseif (bonus == 'StructureDmgMod: +25%') then
		bonusList:tag('li'):wikitext([[Deals 25% more Damage to Structure.]])

	  elseif (bonus == 'StructureDmgMod: 1') then
		bonusList:tag('li'):wikitext([[Deals 1 additional damage to Structure (ignoring armor).]])

	  elseif (bonus == 'StructureDmgMod: 8') then
		bonusList:tag('li'):wikitext([[Deals 8 additional damage to Structure (ignoring armor).]])

	  elseif (bonus == 'StructureDmgMod: 15') then
		bonusList:tag('li'):wikitext([[Deals 15 additional damage to Structure (ignoring armor).]])
		
	  elseif (bonus == 'StructureDmgMod: 20') then
		bonusList:tag('li'):wikitext([[Deals 20 additional damage to Structure (ignoring armor).]])

	  elseif (bonus == 'ArmorDmgMod: +15%') then
		bonusList:tag('li'):wikitext([[Deals 15% more Damage to Armor.]]) 

	  elseif (bonus == 'ArmorDmgMod: +25%') then
		bonusList:tag('li'):wikitext([[Deals 25% more Damage to Armor.]]) 

	  elseif (bonus == 'ArmorDmgMod: +50%') then
		bonusList:tag('li'):wikitext([[Deals 50% more Damage to Armor.]]) 

	  elseif (bonus == 'ArmorDmgMod: -50%') then
		bonusList:tag('li'):wikitext([[Deals 50% less Damage to Armor.]]) 		

	  elseif (bonus == 'MortarFlare: 100%') then
		bonusList:tag('li'):wikitext([[Flare shells illuminate an Area making targets 100% easier to Spot.]]) 	

	  elseif (bonus == 'MortarFlareSensor: 50%') then
		bonusList:tag('li'):wikitext([[Remote Sensors relay sensor data making targets 50% easier to Detect.]]) 	

	  elseif (bonus == 'Smoke') then
		bonusList:tag('li'):wikitext([[Smoke rounds cloud an Area with a mix of Sensor Inhibiting Materials and Thick Smoke.]]) 

	  elseif (bonus == 'Suppressant') then
		bonusList:tag('li'):wikitext([[Suppresses the target's heat dissipation systems, making them unable to sink as much heat.]]) 

	  elseif (bonus == 'DesignMask: Radiation') then
		bonusList:tag('li'):wikitext([[Radiation is created around the impact site.]]) 

	  elseif (bonus == 'IsNOOK') then
		bonusList:tag('li'):wikitext([[Davy Crockett Tactical Nuclear Missiles are launched from an Arrow IV Platform and are capable of eradicating anything in a large area.]])

	  elseif (bonus == 'Doubled') then
		bonusList:tag('li'):wikitext([[Double size Ammo bins provide additional ammo at twice the size.]]) 

	  elseif (bonus == 'Haywire') then
		bonusList:tag('li'):wikitext([[Targets suffer reduced Movement, Accuracy and Heat Management.]]) 

	  elseif (bonus == 'ImpAccuracy: 1') then
		bonusList:tag('li'):wikitext([[Target has 1 reduced Accuracy for 2 Turns.]])

	  elseif (bonus == 'ImpAccuracy: -1') then
		bonusList:tag('li'):wikitext([[Target has 1 reduced Accuracy for 2 Turns.]])
		
	  elseif (bonus == 'ImpMove: 10%') then
		bonusList:tag('li'):wikitext([[Target has 10% reduced Movement for 2 Turns.]])

	  elseif (bonus == 'ImpMove: 15%') then
		bonusList:tag('li'):wikitext([[Target has 15% reduced Movement for 2 Turns.]])

	  elseif (bonus == 'ImpHeatSink: 20%') then
		bonusList:tag('li'):wikitext([[Target has 20% reduced Heat Sinking for 2 Turns.]])

	  elseif (bonus == 'ImpHeatSink: -20%') then
		bonusList:tag('li'):wikitext([[Target has 20% reduced Heat Sinking for 2 Turns.]])

	  elseif (bonus == 'Painter: +1') then
		bonusList:tag('li'):wikitext([[Target Painters grant +1 improved Accuracy against its Target - Multiple effects do not Stack.]])

	  elseif (bonus == 'PainterSensors: 25%') then
		bonusList:tag('li'):wikitext([[Target Painter makes target 25% easier to Detect.]])

	  elseif (bonus == 'PainterSensors: 35%') then
		bonusList:tag('li'):wikitext([[Target Painter makes target 35% easier to Detect.]])
		
	  elseif (bonus == 'PainterVisibility: 25%') then
		bonusList:tag('li'):wikitext([[Target Painter makes target 25% easier to Spot.]])

	  elseif (bonus == 'PainterVisibility: 35%') then
		bonusList:tag('li'):wikitext([[Target Painter makes target 35% easier to Spot.]])

	  elseif (bonus == 'Inferno: 3') then
		bonusList:tag('li'):wikitext([[Target generates 3 Heat for 2 Turns.]])

	  elseif (bonus == 'Swarm: 60') then
		bonusList:tag('li'):wikitext([[Swarm Missile are indirect firing Missiles that ignore clustering rules and missed shots will search for any targets, including friendlies, in 60m around the target.]])

	  elseif (bonus == 'Swarm: 120') then
		bonusList:tag('li'):wikitext([[Swarm Missile are indirect firing Missiles that ignore clustering rules and missed shots will search for any targets, including friendlies, in 120m around the target.]])

	  elseif (bonus == 'AC2Ammo: 45') then
		bonusList:tag('li'):wikitext([[Contains 45 AC/2 shots per bin.]])

	  elseif (bonus == 'AreaOfEffect: 60') then
		bonusList:tag('li'):wikitext([[Has an Area Of Effect radius of 60 meters.]])
		
	  elseif (bonus == 'AreaOfEffectDmg: 4') then
		bonusList:tag('li'):wikitext([[Deals 4 additional area damage within the AOE radius.]])
		
	  elseif (bonus == 'AreaOfEffectSTABDmg: 2') then
		bonusList:tag('li'):wikitext([[Deals 2 additional Stability area damage within the AOE radius.]])
		
	  elseif (bonus == 'BonusAmmo: 50%') then
		bonusList:tag('li'):wikitext([[Contains 50% more ammunition than standard bins.]])
		
	  elseif (bonus == 'RecoilAC: +2') then
		bonusList:tag('li'):wikitext([[This ammo type has a +2 recoil penalty.]])

	  elseif (bonus == 'AC2Ammo: 68') then
		bonusList:tag('li'):wikitext([[Contains 68 AC/2 shots per bin.]])

	  elseif (bonus == 'Crits: X2') then
		bonusList:tag('li'):wikitext([[This ammo type has a 2x crit chance bonus.]])

	  elseif (bonus == 'AC2Ammo: 22') then
		bonusList:tag('li'):wikitext([[Contains 22 AC/2 shots per bin.]])

	  elseif (bonus == 'SabotDmg: 1') then
		bonusList:tag('li'):wikitext([[This ammo type deals +1 damage.]])

	  elseif (bonus == 'SabotArmPercent: 25') then
		bonusList:tag('li'):wikitext([[This ammo type does 25% more damage to Armor.]])

	  elseif (bonus == 'SabotStrPercent: 50') then
		bonusList:tag('li'):wikitext([[This ammo type does 50% less damage to Structure.]])

	  elseif (bonus == 'ACAccuracy: +1') then
		bonusList:tag('li'):wikitext([[This ammo type has a +1 Accuracy bonus.]])

	  elseif (bonus == 'AC5Ammo: 15') then
		bonusList:tag('li'):wikitext([[Contains 15 AC/5 shots per bin.]])
		
	  elseif (bonus == 'AreaOfEffectDmg: 22') then
		bonusList:tag('li'):wikitext([[Deals 22 additional area damage within the AOE radius.]])
		
	  elseif (bonus == 'AreaOfEffectSTABDmg: 5') then
		bonusList:tag('li'):wikitext([[Deals 5 additional Stability area damage within the AOE radius.]])

	  elseif (bonus == 'AC5Ammo: 28') then
		bonusList:tag('li'):wikitext([[Contains 28 AC/5 shots per bin.]])

	  elseif (bonus == 'AC5Ammo: 8') then
		bonusList:tag('li'):wikitext([[Contains 8 AC/5 shots per bin.]])
		
	  elseif (bonus == 'AC5Ammo: 7') then
		bonusList:tag('li'):wikitext([[Contains 7 AC/5 shots per bin.]])

	  elseif (bonus == 'SabotDmg: 4') then
		bonusList:tag('li'):wikitext([[This ammo type deals +4 damage.]])

	  elseif (bonus == 'AC10Ammo: 10') then
		bonusList:tag('li'):wikitext([[Contains 10 AC/10 shots per bin.]])

	  elseif (bonus == 'AreaOfEffectDmg: 30') then
		bonusList:tag('li'):wikitext([[Deals 30 additional area damage within the AOE radius.]])

	  elseif (bonus == 'AreaOfEffectSTABDmg: 10') then
		bonusList:tag('li'):wikitext([[Deals 10 additional Stability area damage within the AOE radius.]])

	  elseif (bonus == 'AC10Ammo: 20') then
		bonusList:tag('li'):wikitext([[Contains 20 AC/10 shots per bin.]])

	  elseif (bonus == 'AC10Ammo: 5') then
		bonusList:tag('li'):wikitext([[Contains 5 AC/10 shots per bin.]])

	  elseif (bonus == 'SabotDmg: 6') then
		bonusList:tag('li'):wikitext([[This ammo type deals +6 damage.]])

	  elseif (bonus == 'AC20Ammo: 5') then
		bonusList:tag('li'):wikitext([[Contains 5 AC/20 shots per bin.]])

	  elseif (bonus == 'AreaOfEffectDmg: 50') then
		bonusList:tag('li'):wikitext([[Deals 50 additional area damage within the AOE radius.]])

	  elseif (bonus == 'AreaOfEffectSTABDmg: 20') then
		bonusList:tag('li'):wikitext([[Deals 20 additional Stability area damage within the AOE radius.]])

	  elseif (bonus == 'AC20Ammo: 3') then
		bonusList:tag('li'):wikitext([[Contains 3 AC/20 shots per bin.]])

	  elseif (bonus == 'AC20Ammo: 2') then
		bonusList:tag('li'):wikitext([[Contains 2 AC/20 shots per bin.]])

	  elseif (bonus == 'SabotDmg: 10') then
		bonusList:tag('li'):wikitext([[This ammo type deals +10 damage.]])

	  elseif (bonus == '+50% Wpn Crits') then
		bonusList:tag('li'):wikitext([[This ammo type has a 50% critical chance bonus.]])

	  elseif (bonus == '+1 Wpn Accuracy') then
		bonusList:tag('li'):wikitext([[This ammo type has a +1 Accuracy bonus.]])
		
	  elseif (bonus == '+1 Pips Ignored') then
		bonusList:tag('li'):wikitext([[This ammo type ignores 1 evasion pip.]])

	  elseif (bonus == '-1 Accuracy') then
		bonusList:tag('li'):wikitext([[This ammo type has a -1 Accuracy penalty.]])

	  elseif (bonus == 'Weapon DMG -35') then
		bonusList:tag('li'):wikitext([[This ammo type has a -35 Damage penalty.]])

	  elseif (bonus == 'AreaOfEffect: 120') then
		bonusList:tag('li'):wikitext([[Has an Area Of Effect radius of 120 meters.]])
		
	  elseif (bonus == 'AreaOfEffectDmg: 35') then
		bonusList:tag('li'):wikitext([[Deals 35 additional area damage within the AOE radius.]])
		
	  elseif (bonus == 'AreaOfEffectSTABDmg: 10') then
		bonusList:tag('li'):wikitext([[Deals 10 additional Stability area damage within the AOE radius.]])

	  elseif (bonus == 'GrenadeAmmo: 5') then
		bonusList:tag('li'):wikitext([[Contains 5 Grenade shots per bin.]])

	  elseif (bonus == 'AreaOfEffect: 90') then
		bonusList:tag('li'):wikitext([[Has an Area Of Effect radius of 90 meters.]])
		
	  elseif (bonus == 'AreaOfEffectDmg: 20') then
		bonusList:tag('li'):wikitext([[Deals 20 additional area damage within the AOE radius.]])

	  elseif (bonus == 'AreaOfEffectHeatDmg: 10') then
		bonusList:tag('li'):wikitext([[Deals 10 additional Heat area damage within the AOE radius.]])

	  elseif (bonus == 'AreaOfEffect: 100') then
		bonusList:tag('li'):wikitext([[Has an Area Of Effect radius of 100 meters.]])
		
	  elseif not string.match(bonus, 'CostPerShot') then
		bonusList:tag('li'):wikitext(bonus)
      end
    end
  end

  -- finally, at the end, return the table we made
  return ammoTable
end

-- return p at the bottom, declare p at the top
return p