--Not sure what this is for function Sound (...) return arg end function UnitBlueprint (...) unit = unpack(arg) end function ProjectileBlueprint (...) projectile = unpack(arg) end


-- Returns the unit name in the form Cybran T4 Heavy Siege Tank function getFullUnitName( unit ) if ( 0 ~= getTech(unit.Categories)) then return cleanFaction(unit.General.FactionName).." T"..getTech(unit.Categories).." "..stripAngles(unit.Description) else return cleanFaction(unit.General.FactionName).." "..stripAngles(unit.Description) end end


-- Cleans up the faction capitalization function cleanFaction( faction ) faction = string.lower(faction) if "aeon" == faction then return "Aeon" end if "cybran" == faction then return "Cybran" end if "uef" == faction then return "UEF" end if "seraphim" == faction then return "Seraphim" end print("Unknown faction: "..faction) os.exit(1) end

-- Strips angle brackets < and > at the beginning of a description string, if present function stripAngles( name ) if ( name ) then local result local i = 1 while i <= string.len(name) do char = string.byte(name,i) i = i + 1 if ( char == 60 ) then break else if result then result = result..string.char(char) else result = string.char(char) end end end while i <= string.len(name) do char = string.byte(name,i) i = i + 1 if ( char == 62 ) then break end end while i <= string.len(name) do char = string.byte(name,i) i = i + 1 if result then result = result..string.char(char) else result = string.char(char) end end return result else return "" end end


-- Interprets the "RULEUTL_(level)" text in TechLevel. -- Gets the unitcode from Description, which is in the form '<LOC uab1101_desc>Power Generator' function getUnitCode( Description ) if ( Description ) then return string.lower( string.sub( Description, 6, 12 ) ) end print ("No Description!") os.exit(1) end


-- Interprets the "RULEUTL_(type)" text in MotionType. -- The possibilities are RULEUMT_Air, RULEUMT_Amphibious, RULEUMT_AmphibiousFloating, RULEUMT_GiantHexaped -- RULEUMT_Hover, RULEUMT_Land, RULEUMT_None, RULEUMT_SurfacingSub, and RULEUMT_Water function getMotionType( MotionType ) if ( MotionType ) then -- Cut off the RULEUMT_ motiontype = string.sub(MotionType, 9, -1) if "None" == motiontype then return nil end return motiontype else return nil end end


-- Returns True if Category is in Categories. function inCategory( Categories, Category ) local cat1 cat1 = string.lower(Category) for i,cat2 in ipairs(Categories) do if ( cat1 == string.lower(cat2)) then return true end end return false end


-- Tech level is one of the Category fields, "TECH1", "TECH2", "TECH3" or "EXPERIMENTAL". "COMMAND" means ACU, and is lvl 0. function getTech( Categories ) if ( Categories ) then if inCategory( Categories, 'COMMAND' ) then return 0 end if inCategory( Categories, 'EXPERIMENTAL' ) then return 4 end if inCategory( Categories, 'TECH3' ) then return 3 end if inCategory( Categories, 'TECH2' ) then return 2 end if inCategory( Categories, 'TECH1' ) then return 1 end end return -1 end

-- Counts the number of muzzles in a weapon function countMuzzles( Weapon ) if ( Weapon and Weapon.RackBones and Weapon.RackBones[1].MuzzleBones) then return table.getn(Weapon.RackBones[1].MuzzleBones) else return 1 end end

function countRacks( Weapon ) if ( Weapon and Weapon.RackBones ) then return table.getn(Weapon.RackBones) else

       return 1

end end

function getProjectileType ( projectile ) if projectile.Categories then if inCategory( projectile.Categories, 'TORPEDO' ) then return "Torpedo" end if inCategory( projectile.Categories, 'ANTITORPEDO' ) then return "Anti Torpedo" end if inCategory( projectile.Categories, 'ANTIMISSILE' ) then return "Anti Missile" end if inCategory( projectile.Categories, 'MISSILE' ) then if inCategory( projectile.Categories, 'STRATEGIC' ) then return "Strategic Missile" end if inCategory( projectile.Categories, 'TACTICAL' ) then return "Tactical Missile" end end end

   if projectile.General then
       if projectile.General.Category == 'Bomb' then return "Bomb" end
       if projectile.General.EntityCategory then
           if inCategory( projectile.General.EntityCategory, 'TORPEDO' ) then return "Torpedo" end

if inCategory( projectile.General.EntityCategory, 'ANTITORPEDO' ) then return "Anti Torpedo" end if inCategory( projectile.General.EntityCategory, 'ANTIMISSILE' ) then return "Anti Missile" end if inCategory( projectile.General.EntityCategory, 'MISSILE' ) then if inCategory( projectile.General.EntityCategory, 'STRATEGIC' ) then return "Strategic Missile" end if inCategory( projectile.General.EntityCategory, 'TACTICAL' ) then return "Tactical Missile" end

   		end

if inCategory( projectile.General.EntityCategory, 'PROJECTILE' ) then return "Projectile" end end end if projectile.Categories then if inCategory( projectile.Categories, 'PROJECTILE' ) then return "Projectile" end end return nil end

function sec2Min(secs) local nSeconds = secs if nSeconds == 0 then return "0:00"; else nMins = string.format("%01.f", math.floor(nSeconds/60)); nSecs = string.format("%02.f", math.floor(nSeconds - nMins *60)); return nMins..":"..nSecs end end

function getWeaponOrder ( Weapons ) local count local key local Damage local weapons key = "" Damage = 0 weapons = {} count = 0 for line in io.lines( "processed.bp") do if ( string.sub( line, 1, 21 ) == " Damage = " and Damage == 0 ) then Damage = string.sub( line, 22, -2 ) end if ( string.sub( line, 1, 27 ) == " DisplayName = '" and Damage ~= 0) then key = string.sub( line, 28, -3 ) key = key .. Damage if ( weapons[count]==key ) then else table.insert(weapons, key) count = count + 1 end Damage = 0 key = "" end end return weapons end

function processWeapons( Weapons , BuildRate) processed = {} order = {} order = getWeaponOrder( Weapons ) for i,weap in ipairs(Weapons) do if ( weap.DisplayName ) then-- and -- First part is to create a Key with the weapon name and damage, to count it. local key ="" key = key .. weap.DisplayName key = key .. weap.Damage -- if ( weap.DoTPulses ) then -- key = key .. "_" .. ( weap.Damage * weap.DoTPulses ) -- else -- if weap.RateOfFire then -- key = key .. "_" .. weap.RateOfFire -- end -- end -- key = key .. "_" .. countMuzzles( weap ) -- if ( weap.DamageRadius ) then key = key.."_"..weap.DamageRadius end

if ( processed[key] ) then processed[key].Count = processed[key].Count + 1 else processed[key] = {} processed[key].Count = 1 processed[key].DisplayName = weap.DisplayName

--find the kind of projectile: if ( weap.ProjectileId ) then processed[key].ProjectileId = weap.ProjectileId processFile( "Proj"..processed[key].ProjectileId, "processedweap.bp" ) dofile("processedweap.bp")

        			if projectile then

if getProjectileType( projectile ) then processed[key].ProjectileType = getProjectileType( projectile ) end

    			    end	

end

local weaponDone = "False"

--switch if weapon is Death, Beam, Continuous Beam, manual launch or other -- Death Weapons if ( weap.Label == 'DeathWeapon' or weap.WeaponCategory == 'Death' or weap.WeaponCategory == 'Kamikaze' or DummyWeapon or weap.DisplayName == 'EMP' ) then processed[key].ProjectileType = nil processed[key].WeaponCategory = "Death"

if ( weap.NukeWeapon or weap.NukeInnerRingDamage ) then processed[key].NukeWeapon = "true" processed[key].NukeInnerRingDamage = weap.NukeInnerRingDamage processed[key].NukeInnerRingRadius = weap.NukeInnerRingRadius processed[key].NukeOuterRingDamage = weap.NukeOuterRingDamage processed[key].NukeOuterRingRadius = weap.NukeOuterRingRadius else if ( weap.DoTPulses ) then processed[key].Damage = ( weap.Damage * weap.DoTPulses ) processed[key].DoTTime = weap.DoTTime else processed[key].Damage = weap.Damage end processed[key].DamageRadius = weap.DamageRadius end weaponDone = "True" end

-- Continuous Beam if ( ( weap.ContinuousBeam or weap.BeamLifetime == 0 ) and weaponDone == "False" ) then processed[key].WeaponCategory = weap.WeaponCategory processed[key].ProjectileType = "Continuous Beam" processed[key].DPS = string.format("%.f", weap.Damage / ( weap.BeamCollisionDelay + 0.1 ) ) if ( weap.DamageRadius ) then processed[key].DamageRadius = weap.DamageRadius

     				end
     				if ( weap.MaxRadius ) then

processed[key].MaxRadius = weap.MaxRadius end

     				if ( weap.MinRadius ) then

processed[key].MinRadius = weap.MinRadius

     				end

weaponDone = "True" end

-- Beam if ( weap.BeamLifetime and weap.BeamLifetime~= 0 and weaponDone == "False" ) then processed[key].WeaponCategory = weap.WeaponCategory processed[key].ProjectileType = "Beam"

processed[key].SalvoSize = countMuzzles( weap ) * countRacks( weap )

processed[key].Damage = weap.Damage * math.ceil(weap.BeamLifetime / ( weap.BeamCollisionDelay + 0.1 ) )

-- Don't create Dot if beam hits only once processed[key].DoTTime = ( weap.BeamCollisionDelay + 0.1 ) * (math.ceil(weap.BeamLifetime / ( weap.BeamCollisionDelay + 0.1 ) ) - 1) if processed[key].DoTTime == 0 then processed[key].DoTTime = nil end

processed[key].DPS = processed[key].SalvoSize * processed[key].Damage * weap.RateOfFire

if ( weap.RateOfFire <= 1 ) then processed[key].ReloadTime = string.format("%.2g", 1 / weap.RateOfFire ) else processed[key].RateOfFire = string.format("%.2g", weap.RateOfFire ) end if ( weap.DamageRadius ) then processed[key].DamageRadius = weap.DamageRadius

     				end
     				if ( weap.MaxRadius ) then

processed[key].MaxRadius = weap.MaxRadius end

     				if ( weap.MinRadius ) then

processed[key].MinRadius = weap.MinRadius

     				end
     				-- Remove unused SalvoSize if == 1
     				if processed[key].SalvoSize == 1 then processed[key].SalvoSize = nil end

weaponDone = "True" end

-- ManualBuild if ( ( weap.ManualFire or weap.ManualFire or weap.CountedProjectile) and weaponDone == "False" ) then processed[key].WeaponCategory = weap.WeaponCategory

if projectile.Economy then processed[key].ProjectileCostEnergy = projectile.Economy.BuildCostEnergy processed[key].ProjectileCostMass = projectile.Economy.BuildCostMass processed[key].ProjectileCostTime = projectile.Economy.BuildTime processed[key].ProjectileTime = processed[key].ProjectileCostTime / BuildRate processed[key].ProjectileRateEnergy = processed[key].ProjectileCostEnergy / processed[key].ProjectileTime processed[key].ProjectileRateMass = processed[key].ProjectileCostMass / processed[key].ProjectileTime processed[key].ProjectileTime = sec2Min( processed[key].ProjectileTime ) end if ( weap.NukeWeapon or weap.NukeInnerRingDamage ) then processed[key].NukeWeapon = "true" processed[key].NukeInnerRingDamage = weap.NukeInnerRingDamage processed[key].NukeInnerRingRadius = weap.NukeInnerRingRadius processed[key].NukeOuterRingDamage = weap.NukeOuterRingDamage processed[key].NukeOuterRingRadius = weap.NukeOuterRingRadius else if ( weap.DoTPulses ) then processed[key].Damage = ( weap.Damage * weap.DoTPulses ) processed[key].DoTTime = weap.DoTTime else processed[key].Damage = weap.Damage end processed[key].DamageRadius = weap.DamageRadius end

     				if ( weap.MaxRadius ) then

processed[key].MaxRadius = weap.MaxRadius end

     				if ( weap.MinRadius ) then

processed[key].MinRadius = weap.MinRadius

     				end

weaponDone = "True" end

-- Other ( prob. projectile ) if ( weaponDone == "False" ) then processed[key].WeaponCategory = weap.WeaponCategory

if ( weap.DoTPulses ) then processed[key].Damage = ( weap.Damage * weap.DoTPulses ) processed[key].DoTTime = weap.DoTTime else processed[key].Damage = weap.Damage end if ( weap.EnergyRequired ) then processed[key].EnergyRequired = weap.EnergyRequired end if ( weap.EnergyDrainPerSecond ) then processed[key].EnergyDrainPerSecond = weap.EnergyDrainPerSecond end

-- count the Muzzle/Racks processed[key].Muzzles = countMuzzles( weap ) processed[key].Racks = countRacks( weap )

-- Start by counting salvo size: processed[key].SalvoSize = math.max(processed[key].Muzzles, weap.MuzzleSalvoSize)

-- Weapons were weap.RackFireTogether == true: if ((weap.RackFireTogether == true) and (processed[key].Racks ~= 1)) then processed[key].SalvoSize = processed[key].SalvoSize * processed[key].Racks processed[key].SalvoTest = processed[key].Muzzles * processed[key].Racks if (processed[key].SalvoTest < processed[key].SalvoSize) then print("Paul: Salvo size error! Check unit") print(processed[key].DisplayName) end end

-- -- Weapons were weap.RackFireTogether == true: -- if ( (weap.RackFireTogether == true) and (processed[key].Racks ~= 1)) then -- processed[key].SalvoSize = processed[key].Muzzles * processed[key].Racks -- else -- -- Weapons were weap.RackFireTogether == false -- -- If there is only 1 rack, then salvo size is salvoSize -- if (processed[key].Racks == 1) then -- processed[key].SalvoSize = weap.MuzzleSalvoSize -- end -- -- -- If there are multiple racks, then salvo size is Muzzles -- if (processed[key].Racks ~= 1) then -- processed[key].SalvoSize = processed[key].Muzzles -- end -- end

if ( weap.MuzzleChargeDelay ~= nil) then if ( weap.MuzzleChargeDelay > 0.1 ) then processed[key].MuzzleChargeDelay = weap.MuzzleChargeDelay - 0.1 else processed[key].MuzzleChargeDelay = weap.MuzzleChargeDelay end -- print("Paul: Muzzle charge delay") -- print(processed[key].DisplayName) else processed[key].MuzzleChargeDelay = 0 end

                   if ( weap.MuzzleSalvoDelay > 0.1 ) then

processed[key].MuzzleSalvoDelay = weap.MuzzleSalvoDelay - 0.1 else processed[key].MuzzleSalvoDelay = weap.MuzzleSalvoDelay end

-- Find salvo time (this is the time it takes from the first to last projectile) processed[key].SalvoTime = ( processed[key].SalvoSize - 1 ) * ( processed[key].MuzzleChargeDelay + processed[key].MuzzleSalvoDelay )

-- Find totalsalvo time (this is the total time it takes for the entire salvo to fire, before firing can happen again) processed[key].TotalSalvoTime = ( processed[key].SalvoSize ) * ( processed[key].MuzzleChargeDelay + processed[key].MuzzleSalvoDelay ) + 0.1

-- Find unit ROF: -- Step 1, find salvo fire time: processed[key].SalvoReload = math.max(1/weap.RateOfFire, processed[key].TotalSalvoTime) if (1/weap.RateOfFire < processed[key].TotalSalvoTime) then print("Paul: Weapon salvo time warning! Check unit") print(processed[key].DisplayName) end

-- Step 2, add RackTimes processed[key].ReloadTime = processed[key].SalvoReload + weap.RackSalvoChargeTime + weap.RackSalvoReloadTime if ( (weap.RackSalvoChargeTime ~= 0) or (weap.RackSalvoReloadTime ~= 0)) then print("Paul: Rack reload/Charge delays!") print(processed[key].DisplayName) end

-- Calculate DPS processed[key].DPS = string.format("%.f", processed[key].SalvoSize * processed[key].Damage / processed[key].ReloadTime )

-- Print ROF or Reload time, accordingly if ( processed[key].ReloadTime >= 1 ) then processed[key].ReloadTime = string.format("%.2g", processed[key].ReloadTime ) else processed[key].RateOfFire = string.format("%.2g", 1 / processed[key].ReloadTime ) processed[key].ReloadTime = nil end

if ( weap.DamageRadius ) then processed[key].DamageRadius = weap.DamageRadius

     				end
     				if ( weap.MaxRadius ) then

processed[key].MaxRadius = weap.MaxRadius end

     				if ( weap.MinRadius ) then

processed[key].MinRadius = weap.MinRadius

     				end
     				
     				-- Remove unused SalvoSize if == 1
     				if processed[key].SalvoSize == 1 then processed[key].SalvoSize = nil end

weaponDone = "True" end end else print ("No Weapon Name!") os.exit(1) end end

for i, key in pairs(order) do printWeapon(processed[key], i) end end


-- Prints the relevant parts of a Weapon function printWeapon( weapon, number ) -- print("{{unitbox weapon")

   if weapon.DisplayName then

print(" | DisplayName"..string.format("%.d", number ).." = "..weapon.DisplayName) else print(" | DisplayName"..string.format("%.d", number ).." = ") end if (weapon.Count > 1) then print(" | Count"..string.format("%.d", number ).." = "..weapon.Count) else print(" | Count"..string.format("%.d", number ).." = ") end

   if (weapon.WeaponCategory ) then

print(" | WeaponCategory"..string.format("%.d", number ).." = "..weapon.WeaponCategory) else print(" | WeaponCategory"..string.format("%.d", number ).." = ")

	end
   if (weapon.ProjectileType ) then

print(" | ProjectileType"..string.format("%.d", number ).." = "..weapon.ProjectileType) else print(" | ProjectileType"..string.format("%.d", number ).." = ")

	end
   if ( weapon.DPS ) then
 		print(" | DPS"..string.format("%.d", number ).."                  = "..weapon.DPS)

else print(" | DPS"..string.format("%.d", number ).." = ") end if ( weapon.Damage ) then

 		print(" | Damage"..string.format("%.d", number ).."               = "..weapon.Damage)

else print(" | Damage"..string.format("%.d", number ).." = ") end if ( weapon.DoTTime ) then print(" | DoTTime"..string.format("%.d", number ).." = "..weapon.DoTTime) else print(" | DoTTime"..string.format("%.d", number ).." = ") end if ( weapon.DamageRadius and weapon.DamageRadius ~= 0 ) then print(" | DamageRadius"..string.format("%.d", number ).." = "..weapon.DamageRadius) else print(" | DamageRadius"..string.format("%.d", number ).." = ") end if ( weapon.EnergyRequired and weapon.EnergyRequired ~= 0 ) then print(" | EnergyRequired"..string.format("%.d", number ).." = "..weapon.EnergyRequired ) else print(" | EnergyRequired"..string.format("%.d", number ).." = ") end if ( weapon.EnergyDrainPerSecond and weapon.EnergyDrainPerSecond ~= 0) then print(" | EnergyDrainPerSecond"..string.format("%.d", number ).." = "..weapon.EnergyDrainPerSecond ) else print(" | EnergyDrainPerSecond"..string.format("%.d", number ).." = ") end if ( weapon.SalvoSize ) then print(" | SalvoSize"..string.format("%.d", number ).." = "..weapon.SalvoSize) else print(" | SalvoSize"..string.format("%.d", number ).." = ") end if ( weapon.SalvoTime and weapon.SalvoTime ~= 0) then print(" | SalvoTime"..string.format("%.d", number ).." = "..weapon.SalvoTime) else print(" | SalvoTime"..string.format("%.d", number ).." = ") end if ( weapon.RateOfFire ) then print(" | RateOfFire"..string.format("%.d", number ).." = "..weapon.RateOfFire) else print(" | RateOfFire"..string.format("%.d", number ).." = ") end if ( weapon.ReloadTime ) then print(" | ReloadTime"..string.format("%.d", number ).." = "..weapon.ReloadTime) else print(" | ReloadTime"..string.format("%.d", number ).." = ") end

if ( weapon.MaxRadius and weapon.MaxRadius ~= 0 ) then print(" | MaxRadius"..string.format("%.d", number ).." = "..weapon.MaxRadius) else print(" | MaxRadius"..string.format("%.d", number ).." = ") end if ( weapon.MinRadius and weapon.MinRadius ~= 0 ) then print(" | MinRadius"..string.format("%.d", number ).." = "..weapon.MinRadius) else print(" | MinRadius"..string.format("%.d", number ).." = ") end

   if weapon.ProjectileCostEnergy then

print(" | ProjectileCostEnergy"..string.format("%.d", number ).." = "..weapon.ProjectileCostEnergy) print(" | ProjectileCostMass"..string.format("%.d", number ).." = "..weapon.ProjectileCostMass) print(" | ProjectileCostTime"..string.format("%.d", number ).." = "..weapon.ProjectileCostTime) print(" | ProjectileRateEnergy"..string.format("%.d", number ).." = "..weapon.ProjectileRateEnergy) print(" | ProjectileRateMass"..string.format("%.d", number ).." = "..weapon.ProjectileRateMass) print(" | ProjectileTime"..string.format("%.d", number ).." = "..weapon.ProjectileTime) end

   if weapon.NukeWeapon then

print(" | NukeInnerRingDamage"..string.format("%.d", number ).." = "..weapon.NukeInnerRingDamage) print(" | NukeInnerRingRadius"..string.format("%.d", number ).." = "..weapon.NukeInnerRingRadius) print(" | NukeOuterRingDamage"..string.format("%.d", number ).." = "..weapon.NukeOuterRingDamage) print(" | NukeOuterRingRadius"..string.format("%.d", number ).." = "..weapon.NukeOuterRingRadius) end

-- print("}}") end


-- Main Unit box creator function printUnitbox( unit ) if (unit ) then -- print("<noinclude>") -- print("This is the template data for the "..getFullUnitName( unit )..". This was created by an import script. Do not modify it.<br>") -- print("If you find a problem or a correction, please inform me about it, and I will correct the script.") -- print("</noinclude>") -- print("<includeonly>") -- print("{{Unitbox") print(pageMiddle.."{{Unitvalues")

-- Unit Name/Code etc print(" | UnitCode = "..string.upper(getUnitCode(unit.Description))) print(" | Faction = "..cleanFaction(unit.General.FactionName)) print(" | TechLevel = "..getTech(unit.Categories)) print(" | Description = "..stripAngles(unit.Description)) print(" | Description2 = "..stripAngles(unit.Description2)) if unit.General.UnitName then print(" | Nickname = "..stripAngles(unit.General.UnitName)) else print(" | Nickname = ") end

-- Economic print(" | BuildCostEnergy = "..unit.Economy.BuildCostEnergy) print(" | BuildCostMass = "..unit.Economy.BuildCostMass) print(" | BuildTime = "..unit.Economy.BuildTime) if unit.Economy.ProductionPerSecondEnergy then print(" | ProductionPerSecondEnergy = "..unit.Economy.ProductionPerSecondEnergy) else print(" | ProductionPerSecondEnergy = ") end if unit.Economy.ProductionPerSecondMass then print(" | ProductionPerSecondMass = "..unit.Economy.ProductionPerSecondMass) else print(" | ProductionPerSecondMass = ") end if unit.Economy.MaintenanceConsumptionPerSecondEnergy then print(" | MaintenanceConsumptionPerSecondEnergy = "..unit.Economy.MaintenanceConsumptionPerSecondEnergy) else print(" | MaintenanceConsumptionPerSecondEnergy = ") end if unit.Economy.MaintenanceConsumptionPerSecondMass then print(" | MaintenanceConsumptionPerSecondMass = "..unit.Economy.MaintenanceConsumptionPerSecondMass) else print(" | MaintenanceConsumptionPerSecondMass = ") end if unit.Economy.BuildRate then print(" | BuildRate = "..unit.Economy.BuildRate ) else print(" | BuildRate = ") end if ( unit.Enhancements) then if unit.Enhancements.AdvancedEngineering then print(" | BuildRate2 = "..unit.Enhancements.AdvancedEngineering.NewBuildRate ) else if unit.Enhancements.EngineeringThroughput then print(" | BuildRate2 = "..unit.Enhancements.EngineeringThroughput.NewBuildRate ) else print(" | BuildRate2 = " ) end end if unit.Enhancements.T3Engineering then print(" | BuildRate3 = "..unit.Enhancements.T3Engineering.NewBuildRate ) else print(" | BuildRate3 = ") end else print(" | BuildRate2 = ") print(" | BuildRate3 = ") end if unit.Economy.StorageEnergy then print(" | StorageEnergy = "..unit.Economy.StorageEnergy) else print(" | StorageEnergy = ") end if unit.Economy.StorageMass then print(" | StorageMass = "..unit.Economy.StorageMass) else print(" | StorageMass = ") end

       -- Health Defense etc

print(" | MaxHealth = "..unit.Defense.MaxHealth) if unit.Defense.RegenRate and unit.Defense.RegenRate ~= 0 then print(" | RegenRate = "..unit.Defense.RegenRate) else print(" | RegenRate = ") end if unit.Defense.Shield then if unit.Defense.Shield.ShieldMaxHealth then print(" | ShieldMaxHealth = "..unit.Defense.Shield.ShieldMaxHealth) else print(" | ShieldMaxHealth =" ) end if unit.Defense.Shield.ShieldRegenRate then print(" | ShieldRegenRate = "..unit.Defense.Shield.ShieldRegenRate) else print(" | ShieldRegenRate = ") end if unit.Defense.Shield.ShieldRechargeTime then

   			print(" | ShieldRechargeTime = "..unit.Defense.Shield.ShieldRechargeTime)

else print(" | ShieldRechargeTime = ") end if unit.Defense.Shield.ShieldRechargeTime and unit.Defense.Shield.ShieldMaxHealth then

   			print(" | ShieldRechargeRate = "..string.format("%.f", unit.Defense.Shield.ShieldMaxHealth / unit.Defense.Shield.ShieldRechargeTime ))

else print(" | ShieldRechargeRate = ") end

			if unit.Defense.Shield.PersonalShield then
   			print(" | ShieldRadius       = Self")

else print(" | ShieldRadius = "..unit.Defense.Shield.ShieldSize) end else print(" | ShieldMaxHealth = ") print(" | ShieldRegenRate = ") print(" | ShieldRechargeTime = ") print(" | ShieldRechargeRegenRate = ") print(" | ShieldRadius = ") end

-- Intel if unit.Intel then if unit.Intel.RadarStealthFieldRadius then print(" | StealthRadius = "..unit.Intel.RadarStealthFieldRadius) else

   			if unit.Intel.RadarStealth then

print(" | StealthRadius = Self") else print(" | StealthRadius = ") end end if unit.Intel.OmniRadius then print(" | OmniRadius = "..unit.Intel.OmniRadius) else print(" | OmniRadius = ") end if unit.Intel.RadarRadius then print(" | RadarRadius = "..unit.Intel.RadarRadius) else print(" | RadarRadius = ") end if unit.Intel.SonarRadius then print(" | SonarRadius = "..unit.Intel.SonarRadius) else print(" | SonarRadius = ") end if unit.Intel.WaterVisionRadius then print(" | WaterVisionRadius = "..unit.Intel.WaterVisionRadius) else print(" | WaterVisionRadius = ") end -- Cybran Sooth Sayer is special... if unit.Intel.VisionRadius and unit.Intel.VisionRadius ~= 0 then print(" | VisionRadius = "..unit.Intel.VisionRadius) else if unit.Intel.MaxVisionRadius then print(" | VisionRadius = "..unit.Intel.MaxVisionRadius) else print(" | VisionRadius = ") end end else print(" | OmniRadius = ") print(" | RadarRadius = ") print(" | SonarRadius = ") print(" | WaterVisionRadius = ") print(" | VisionRadius = ") end

-- speed etc mt = getMotionType(unit.Physics.MotionType) if mt then print(" | MotionType = "..mt) else print(" | MotionType = ") end -- Air Units should look for unit.Air.MaxAirspeed if (mt == "Air") then if ( unit.Air.MaxAirspeed and 0 ~= unit.Air.MaxAirspeed ) then print(" | MaxSpeed = "..unit.Air.MaxAirspeed) else print(" | MaxSpeed = ") end else if ( unit.Physics.MaxSpeed and 0 ~= unit.Physics.MaxSpeed ) then print(" | MaxSpeed = "..unit.Physics.MaxSpeed) else print(" | MaxSpeed = ") end end

 		if unit.Physics.FuelUseTime then

print(" | FuelUseTime = "..sec2Min(unit.Physics.FuelUseTime)) else print(" | FuelUseTime = ") end

       if ( unit.Veteran ) then
			print(" | Veteran            = "..unit.Veteran.Level1)

else print(" | Veteran = ") end if ( unit.Buffs ) then

			print(" | VeteranBuffRegen   = "..unit.Buffs.Regen.Level1)

else print(" | VeteranBuffRegen = ") end

print(" | StrategicIconName = "..unit.StrategicIconName) print(" | SupComVersion = 1.5.3599") -- print("}}") end end


-- Returns a human-readable sentence describing the Function function friendlyFunction( func ) if ( func == "Anti Air" ) then return "It is an anti-air unit." end if ( func == "Bomber" ) then return "It is a bomber." end if ( func == "Command" ) then return "It is a command unit." end if ( func == "Construction" ) then return "It is a construction unit." end if ( func == "Defense" ) then return "It is a defense unit." end if ( func == "Direct Fire" ) then return "It is a direct fire unit." end if ( func == "Economy" ) then return "It is an economy unit." end if ( func == "Experimental" ) then return "It is an experimental unit." end if ( func == "Factory" ) then return "It is a factory." end if ( func == "Fighter" ) then return "It is a fighter unit." end if ( func == "Gunship" ) then return "It is a gunship." end if ( func == "Indirect Fire" ) then return "It is an indirect fire unit." end if ( func == "Intelligence" ) then return "It is an intelligence unit." end if ( func == "Ship" ) then return "It is a ship." end if ( func == "Strategic" ) then return "It is a strategic unit." end if ( func == "Submarine" ) then return "It is a submarine unit." end if ( func == "Transport" ) then return "It is a transport unit." end if ( func == "Utility" ) then return "It is a utility unit." end if ( func == "Anti Navy" ) then return "It is an Anti Navy unit." end print("Error: unknown Function"..func) os.exit(1) end

-- unit page creator function printBaseUnit( unit ) nick = stripAngles( unit.General.UnitName )

text = [[

This article is a stub. You can help this wiki by expanding it.
<!-- Template:UnitNav- -->
{{Unitbox_]]

text = text..string.upper(getUnitCode(unit.Description))..[[}}

The Happypal/Script]] if ( nick and nick ~= "" ) then text = text..", nicknamed the "..nick.."," end fact = cleanFaction( unit.General.FactionName ) if ( fact == "Aeon" ) then text = text.." is an Aeon unit. " end if ( fact == "UEF" ) then text = text.." is a UEF unit. " end if ( fact == "Cybran" ) then text = text.." is a Cybran unit. " end if ( fact == "Seraphim" ) then text = text.." is a Seraphim unit. " end

text = text..friendlyFunction( unit.General.Category ) print( text ) end


-- returns false if the file is invalid function validFile( Description, Categories ) if ( Description ) then if(nil ~= string.find(string.lower(unit.Description), "civilian")) then return false end if(nil ~= string.find(string.lower(unit.Description), "crab egg")) then return false end if(nil ~= string.find(string.lower(unit.Description), "crab egg")) then return false end --Air stagin facility... if(nil ~= string.find(string.lower(unit.Description), "beacon")) then return false end if(nil ~= string.find(string.lower(unit.Description), "uef wall segment")) then return false end if(nil ~= string.find(string.lower(unit.Description), "test unit")) then return false end if(nil ~= string.find(string.lower(unit.Description), "build bot effect")) then return false end if(nil ~= string.find(string.lower(unit.Description), "scout-deployed land sensor")) then return false end if(nil ~= string.find(string.lower(unit.Description), "concrete")) then return false end else -- If there is no Description, then the file is bad return false end if ( Categories ) then if( inCategory( Categories, 'CIVILIAN' ) ) then return false end if( inCategory( Categories, 'BEACON' ) ) then return false end else -- If there is no Categories, then the file is bad return false end return true end


exportHeader = [[ <mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">

 <siteinfo>
   <sitename>Supreme Commander Wiki</sitename>
   <base>http://supcom.wikia.com/wiki/Main_Page</base>
   <generator>MediaWiki 1.9.3</generator>
   <case>first-letter</case>
     <namespaces>
     <namespace key="-2">Media</namespace>
     <namespace key="-1">Special</namespace>
     <namespace key="0" />
     <namespace key="1">Talk</namespace>
     <namespace key="2">User</namespace>
     <namespace key="3">User talk</namespace>
     <namespace key="4">Supreme Commander Wiki</namespace>
     <namespace key="5">Supreme Commander Wiki talk</namespace>
     <namespace key="6">Image</namespace>
     <namespace key="7">Image talk</namespace>
     <namespace key="8">MediaWiki</namespace>
     <namespace key="9">MediaWiki talk</namespace>
     <namespace key="10">Template</namespace>
     <namespace key="11">Template talk</namespace>
     <namespace key="12">Help</namespace>
     <namespace key="13">Help talk</namespace>
     <namespace key="14">Category</namespace>
     <namespace key="15">Category talk</namespace>
     <namespace key="110">Forum</namespace>
     <namespace key="111">Forum talk</namespace>
   </namespaces>
 </siteinfo>

]]

pageHeader = [[

 <page>
   <title>]]


pageMiddle = [[</title>

   <revision>
     <timestamp>2008-08-04T00:00:01Z</timestamp>
     <contributor>
       <username>HappypalImporter</username>
       <id>736011</id>
     </contributor>
     <comment></comment>
     <text xml:space="preserve">]]


pageFooter = [[}}</text>

   </revision>
 </page>

]]


exportFooter = [[</mediawiki> ]]

function processFile( fileNameIn, fileNameOut ) file, msg = io.open (fileNameIn, "r") processedfile = io.open (fileNameOut, "w") if file then

		file:close()

for line in io.lines(fileNameIn) do comment = false local i = 1 while (not comment) and (i < string.len(line)) do char = string.byte(line,i) if ( char == 32 or char == 9 ) then -- skip whitespace -- skip tab i = i + 1 elseif ( char == 35 ) then -- found incorrect # comment marker comment = true else -- Not whitespace or a comment, print the line break end end if (not comment) then processedfile:write(line.."\n") end end end processedfile:close() end

filelistgood = io.open ("filelistgood.txt", "w") filelistbad = io.open ("filelistbad.txt", "w") print( exportHeader ) dofile("unitdescription.lua") for curfile in io.lines("filelist.txt") do valid = true reason = "None" if(nil == string.find(string.lower(curfile),"ope")) then processFile( "Units\\"..curfile, "processed.bp" )

dofile("processed.bp") if ( unit ) then if ( validFile(unit.Description, unit.Categories) and ( -1 ~= getTech(unit.Categories) ) ) then --********************** --This is the loop where stuff can happen for valid files. filelistgood:write(curfile.."\n")

-- -- Base unit page -- if ( "Cybran" == cleanFaction(unit.General.FactionName)) then -- print( pageHeader..getFullUnitName( unit )..pageMiddle ) -- printBaseUnit( unit ) -- print( pageFooter ) -- end

-- Unitbox template

				if ( "UEF" == cleanFaction(unit.General.FactionName) ) then

-- if ( 1 ) then unit.Description2 = (Description[getUnitCode(unit.Description)]) print( pageHeader.."Template:Unitvalues_"..string.upper(getUnitCode(unit.Description)) ) printUnitbox(unit) if unit.Weapon then

    					processWeapons( unit.Weapon, unit.Economy.BuildRate )
    				end

-- print("}}") -- print("</includeonly>") print( pageFooter ) end

-- Weaponbox template -- if ( 1 ) then

               --    print ( getFullUnitName( unit ) )
               --    if unit.Weapon then
               --    	processWeapons( unit.Weapon, unit.Economy.BuildRate )
               --    end

--end

-- Create nickname redirect -- if ( unit.General.UnitName and "Seraphim" == cleanFaction(unit.General.FactionName)) then -- print( pageHeader..stripAngles(unit.General.UnitName)..pageMiddle.."#REDIRECT "..getFullUnitName( unit )..""..pageFooter ) -- end

--This was the loop where stuff can happen for valid files. --********************** else filelistbad:write(curfile.."\n") end end -- For debug reasons, do not remove -- os.remove ("processed.bp") else filelistbad:write(curfile.."\n") end end print( exportFooter ) filelistgood = io.close() filelistbad = io.close()

Community content is available under CC-BY-SA unless otherwise noted.