Civilization Wiki
Advertisement
Civilization Wiki

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

--Sub pages : 
--/Buildings
--/Techs
--/Units
--/Wonders
--/Resources
--/Terrain
--/Strengths
--/Civs
--/Governments
--/Worker Actions

local p = {}
local utils = require("Module:TemplateUtils")
 
 --Templates
local buildingrow = [[|-
|%s
|%s
|%s
|%s
|%s
|
%s
]]

local techrow = [[|-
|%s
|%s
|%s
|%s
|%s
|%s
]]

local unitrow= [[|-
|%s
|%s
| style="text-align:right;" |%s
| style="text-align:right;" |%s
| style="text-align:right;" |%s
| style="text-align:right;" |%s
| style="text-align:right;" |%s
| style="text-align:right;" |%s
| style="text-align:right;" |%s
| style="text-align:right;" |%s
]]

local strategicResourceRow = [[|-
|%s
|%s
|%s
|%s
|%s
]]

local resourcerow = [[|-
|%s
|%s
|%s
|%s
]]

local terrainrow = [[|-
|%s
|%s
|%s
|%s
|%s
|%s
|%s
]]

local strengthrow = [[|-
|%s
|%s
]]

local civrow = [[|-
|%s
|%s
|%s
|%s
|%s
]]

local strategicResourcePage = [=[<infobox>
<title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Revealed by</label>
        <default>%s</default></data>
    <data><label>Found in</label>
        <default>%s</default></data>
    <data><label>Allows</label>
        <default>%s</default></data>
    <data><label>Tile bonus</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|List of resources in Civ3|The list of resources}}{{#if:{{NAMESPACE}} | |[[Category:Resources (Civ3)]]}}]=]

local resourcepage = [=[<infobox>
<title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Found in</label>
        <default>%s</default></data>
    <data><label>Tile bonus</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|List of resources in Civ3|The list of resources}}{{#if:{{NAMESPACE}} | |[[Category:Resources (Civ3)]]}}]=]

local terrainpage = [=[<infobox>
<title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Movement cost</label>
        <default>%s</default></data>
    <data><label>Defense bonus</label>
        <default>%s</default></data>
    <data><label>Food</label>
        <default>%s</default></data>
    <data><label>Shields</label>
        <default>%s</default></data>
    <data><label>Commerce</label>
        <default>%s</default></data>
    <data><label>Notes</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|List of terrains in Civ3|The list of terrains}}{{#if:{{NAMESPACE}} | |[[Category:Terrains (Civ3)]]}}]=]

local strengthpage = [=[<infobox>
<title><default>%s</default></title>
    <data><default>%s</default></data>
</infobox>
{{BackArrow|List of strengths in Civ3|The list of strengths}}{{#if:{{NAMESPACE}} | |[[Category:Strengths (Civ3)]]}}]=]

local governmentPage = [=[<infobox>
<title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Advance required</label>
        <default>%s</default></data>
    <data><label>Allows</label>
        <default>%s</default></data>
    <data><label>Worker efficiency</label>
        <default>%s</default></data>
    <data><label>Hurry Method</label>
        <default>%s</default></data>
    <data><label>Corruption / Waste</label>
        <default>%s</default></data>
    <data><label>War Weariness</label>
        <default>%s</default></data>
    <data><label>Draft Rate</label>
        <default>%s</default></data>
    <data><label>Military Police Limit</label>
        <default>%s</default></data>
    <data><label>Units Support per town</label>
        <default>%s</default></data>
    <data><label>Units Support per city</label>
        <default>%s</default></data>
    <data><label>Units Support per metropolis</label>
        <default>%s</default></data>
    <data><label>Support cost per unit per turn</label>
        <default>%s</default></data>
    <data><label>Assimilation chance</label>
        <default>%s</default></data>
    <data><label>Spies</label>
        <default>%s</default></data>
    <data><label>Notes</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|Government (Civ3)}}{{#if:{{NAMESPACE}} | |[[Category:Governments (Civ3)]]}}]=]

local workerActionPage = [=[<infobox>
<title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Advance required</label>
        <default>%s</default></data>
    <data><label>Improvement required</label>
        <default>%s</default></data>
    <data><label>Terrain required</label>
        <default>%s</default></data>
    <data><label>Resources required</label>
        <default>%s</default></data>
    <data><label>Base turns to complete</label>
        <default>%s</default></data>
    <data><label>Consumes worker?</label>
        <default>%s</default></data>
    <data><label>Effect</label>
        <default>%s</default></data>
    <data><label>Notes</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|Worker Action (Civ3)}}{{#if:{{NAMESPACE}} | |[[Category:Worker Actions (Civ3)]]}}]=]


--Utility functions
local function Link(s)
	return "[["..s.." (Civ3)|"..s.."]]"
end

local function Linkg(s)
	return "[["..s.." (government) (Civ3)|"..s.."]]"
end

local function LinkAll(t)
	local s = ""
	local first = true
	for k,v in pairs(t) do
		s = s..(first and "" or "<br/>")..Link(v)
		first = false
	end
	return s
end

--local function LinkCapitalized(s)
--    return(s:gsub("%u%w*", function(c) return "[["..c.." (Civ3)|"..c.."]]" end))
--end

--Does not support triple capitalization, i.e. "Link This Text" -> "[[Link This (Civ3)|Link This]] [[Text (Civ3)|Text]]" (instead of one link)
local function LinkCapitalized(s)
    --Start processing pairs of capitalized words
    s = s:gsub("%u%w*%s%u%w*", function(c) return ("[["..c.." (Civ3)|"..c.."]]"):lower() end)
    --Fully process single capitalized words
    s = s:gsub("%u%w*", function(c) return "[["..c.." (Civ3)|"..c.."]]" end)
    --Fully process pairs of capitalized words
    return(s:gsub("[%[][%[]%l[^%]]*[%]][%]]", function(c) return c:gsub("(%l)(%w*)", function(start, finish) return start:upper()..finish end) end))
end

local function LinkCapitalizedExceptFirst(s)
    local firstWord = s:match("%w*")
    local everythingAfterwards = s:match(firstWord.."(.*)")
    return(firstWord..LinkCapitalized(everythingAfterwards))
end

local function GetTechLeadsTo(data, name)
	local leadsto = {}
	for k,v in pairs(data) do
		if v.reqtech then
			for i,j in pairs(v.reqtech) do
				if j == name then table.insert(leadsto,k) end
			end
		end
	end
	return leadsto
end
 
local function BuildingNotes(building)
	local s = ""
	if building.upgrade then
		s = "'''Upgrades to '''"..Link(building.upgrade).."\r\n"
	elseif building.reqbuilding then
		s = "'''Requires '''"..Link(building.reqbuilding).."\r\n"
	end
	return s..building.notes
end
 --Public functions
function p.GetBuildingRow(frame)
	local displayname = frame.args[1]
	local name = string.gsub(displayname , " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Buildings")
	local building = data[name]

	return frame:preprocess(string.format(buildingrow,
	"[[Image:"..displayname.." (Civ3).png|64px|link="..displayname.." (Civ3)]]",
	"[["..displayname.." (Civ3)|"..name.."]]",
	building.reqtech and Link(building.reqtech) or "None",
	building.cost and building.cost or "None",
	building.maintenance and building.maintenance or "None",
	BuildingNotes(building)))
end

local buildingpage = [=[<infobox>
<title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Technology required</label>
        <default>%s</default></data>
    <data><label>Resources required</label>
        <default>%s</default></data>
    <data><label>{{shield3}} cost</label>
        <default>%s</default></data>
    <data><label>Maintenance</label>
        <default>%s</default></data>
    <data><label>Effect</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|List of buildings in Civ3|The list of buildings}}{{#if:{{NAMESPACE}} | |[[Category:Buildings (Civ3)]]}}]=]

function p.GetBuildingPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Buildings")[name]
	
	return frame:preprocess(string.format(buildingpage,
	name,
	"[[Image:"..PAGENAME..".png|120px]]",
	data.reqtech and Link(data.reqtech) or "None",
	data.reqresource and LinkAll(data.reqresource) or "None",
	data.cost and data.cost or "None",
	data.maintenance and data.maintenance.." {{Gold3}}" or "None",
	BuildingNotes(data)))
end

function p.GetTechRow(frame)
	local displayname = frame.args[1]
	local name = string.gsub(displayname , " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Techs")
	local tech = data[name]
 
	local leadsto = GetTechLeadsTo(data,name)

	return frame:preprocess(string.format(techrow,
	"[[Image:"..displayname.." (Civ3).png|64px|link="..displayname.." (Civ3)]]",
	"[["..displayname.." (Civ3)|"..name.."]]",
	tech.reqtech and LinkAll(tech.reqtech) or "None",
	tech.leadsto and LinkAll(tech.leadsto) or "None",
	tech.enables and LinkAll(tech.enables) or "None",
	tech.obsoletes and LinkAll(tech.obsoletes) or "None"))
end
 
local techpage = [=[<infobox>
<title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Requires</label>
        <default>%s</default></data>
    <data><label>Leads to</label>
        <default>%s</default></data>
    <data><label>Enables</label>
        <default>%s</default></data>
    <data><label>[[Obsolete|Obsoletes]]</label>
        <default>%s</default></data>
    <data><label>Notes</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|List of advances in Civ3|Back to the list of advances}}{{#if:{{NAMESPACE}} | |[[Category:Technologies (Civ3)]]}}]=]

function p.GetTechPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Techs")
	local tech = data[name]
	
	local leadsto = GetTechLeadsTo(data,name)

	return frame:preprocess(string.format(techpage,
	name,
	"[[Image:"..PAGENAME..".png|120px]]",
	tech.reqtech and LinkAll(tech.reqtech) or "None",
	tech.leadsto and LinkAll(tech.leadsto) or "None",
	tech.enables and LinkAll(tech.enables) or "None",
	tech.obsoletes and LinkAll(tech.obsoletes) or "",
	tech.notes or "None"))
end

function p.GetUnitRow(frame)
	local displayname = frame.args[1]
	local name = string.gsub(displayname, " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Units")
	local unit = data[name]

	return frame:preprocess(string.format(unitrow,
	"[[Image:"..displayname.." (Civ3).png|32px|link="..displayname.." (Civ3)]]",
	"[["..displayname.." (Civ3)|"..name.."]]",
	unit.reqtech and Link(unit.reqtech) or "None",
	unit.cost or "None",
	unit.attack or "0",
	unit.defense or "0",
	unit.moves or "None",
	unit.bombard or "0",
	unit.range or "0",
	unit.rateoffire or "0"))
end

local unitpage = [=[<infobox>
    <title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Technology required</label>
        <default>%s</default></data>
    <data><label>[[Resource_(Civ3)#Strategic_Resources|Resource]] required</label>
        <default>%s</default></data>
    <data><label>{{shield3}} cost</label>
        <default>%s</default></data>
    <data><label>Attack/&#8203;Defense</label>
        <default>%s</default></data>
    <data><label>Moves</label>
        <default>%s</default></data>
    <data><label>[[Bombard (Civ3)|Bombard]]</label>
        <default>%s</default></data>
    <data><label>Range</label>
        <default>%s</default></data>
    <data><label>[[Bombard (Civ3)#Rate_of_fire|Rate of fire]]</label>
        <default>%s</default></data>
    <data><label>Transport Capacity:</label>
        <default>%s</default>
    </data>
    <data><label>Upgrades to</label>
        <default>%s</default></data>
    <data><label>Notes</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|List of units in Civ3|The list of units}}{{#if:{{NAMESPACE}} | |[[Category:Units (Civ3)]]}}]=]

function p.GetUnitPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Units")[name]
		
	return frame:preprocess(string.format(unitpage ,
	name,
	"[[Image:"..PAGENAME..".png|120px]]",
	data.reqtech and Link(data.reqtech) or "None",
	data.reqresource and LinkAll(data.reqresource) or "None",
	data.cost or "None",
	(data.attack or "0").."/"..(data.defense or "0"),
	data.moves or "None",
        data.bombard or "0",
	data.range or "0",
        data.rateoffire or "0",
        data.transports or "",
	data.upgrade and LinkAll(data.upgrade) or "None",
	data.notes or "None"))
end

local wonderpage = [=[<infobox>
    <title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Technology required</label>
        <default>%s</default></data>
    <data><label>Resources required</label>
        <default>%s</default></data>
    <data><label>{{shield3}} cost</label>
        <default>%s</default></data>
    <data><label>Culture</label>
        <default>%s</default></data>
    <data><label>Obsoleted by</label>
        <default>%s</default></data>
    <data><label>Effect</label>
        <default>%s</default></data>
    <data><label>Notes</label>
        <default>%s</default></data>
</infobox>
{{BackArrow|List of wonders in Civ3|Back to the list of wonders}}{{#if:{{NAMESPACE}} | |[[Category:Wonders (Civ3)]]}}]=]

function p.GetWonderPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Wonders")[name]
	
	return frame:preprocess(string.format(wonderpage,
	name,
	"[[Image:"..PAGENAME..".png|120px]]",
	data.reqtech and Link(data.reqtech) or "None",
	data.reqresource and LinkAll(data.reqresource) or "None",
	data.cost and data.cost or "None",
	data.culture and data.culture.." {{Culture3}}" or "None",
	data.obsolete and Link(data.obsolete) or "None",
	data.effect or "None",
	data.notes or "None"))
end

function p.GetResourceRow(frame)
	local displayname = frame.args[1]
	local name = string.gsub(displayname , " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Resources")
	local resource = data[name]

    if resource.resType == "Strategic" then
	    return frame:preprocess(string.format(strategicResourceRow,
	    "[[Image:"..displayname.." (Civ3).png|64px|link="..displayname.." (Civ3)]]",
	    "[["..displayname.." (Civ3)|"..name.."]]",
	    resource.reqtech and Link(resource.reqtech) or "None",
	    resource.found and LinkAll(resource.found) or "None",
	    resource.tilebonus and resource.tilebonus or "None"))
    elseif name == "Gold" then
        return frame:preprocess(string.format(resourcerow,
	    "[[Image:Gold (Resource) (Civ3).png|64px|link="..displayname.." (Civ3)]]",
	    "[["..displayname.." (Civ3)|"..name.."]]",
	    resource.found and LinkAll(resource.found) or "None",
	    resource.tilebonus and resource.tilebonus or "None"))
    else
        return frame:preprocess(string.format(resourcerow,
	    "[[Image:"..displayname.." (Civ3).png|64px|link="..displayname.." (Civ3)]]",
	    "[["..displayname.." (Civ3)|"..name.."]]",
	    resource.found and LinkAll(resource.found) or "None",
	    resource.tilebonus and resource.tilebonus or "None"))
    end
end

function p.GetResourcePage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Resources")[name]
	
	if data.resType == "Strategic" then
	    return frame:preprocess(string.format(strategicResourcePage,
	    name,
	    "[[Image:"..PAGENAME..".png|120px]]",
	    data.reqtech and Link(data.reqtech) or "None",
	    data.found and LinkAll(data.found) or "None",
	    data.enables and LinkAll(data.enables) or "None",
	    data.tilebonus or "None"))
    elseif name == "Gold" then
        return frame:preprocess(string.format(resourcepage,
	    name,
	    "[[Image:Gold (Resource) (Civ3).png|120px]]",
	    data.found and LinkAll(data.found) or "None",
	    data.tilebonus or "None"))
    else
        return frame:preprocess(string.format(resourcepage,
	    name,
	    "[[Image:"..PAGENAME..".png|120px]]",
	    data.found and LinkAll(data.found) or "None",
	    data.tilebonus or "None"))
	end
end

function p.GetTerrainRow(frame, articlename)
	local displayname = articlename or frame.args[1]
	local name = string.gsub(displayname , " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Terrain")
	local terrain = data[name]

	return utils.PreProcess(frame,string.format(terrainrow,
	"[[Image:"..displayname.." (Civ3).png|64px|link="..displayname.." (Civ3)]]",
	"[["..displayname.." (Civ3)|"..name.."]]",
	terrain.movement or "None",
	terrain.defense or "None",
	terrain.food or "0",
	terrain.shields or "0",
	terrain.commerce or "0"))
end

function p.GetTerrainPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Terrain")[name]
	
	return frame:preprocess(string.format(terrainpage,
	name,
	"[[Image:"..PAGENAME..".png|120px]]",
	data.movement or "None",
	data.defense or "None",
	data.food or "0",
	data.shields or "0",
	data.commerce or "0",
	data.notes or "None"))
end

function p.GetStrengthRow(frame)
	local displayname = frame.args[1]
	local name = string.gsub(displayname , " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Strengths")
	local strength = data[name]

	return frame:preprocess(string.format(strengthrow,
	"[["..displayname.." (Civ3)|"..name.."]]",
	strength.notes or "None"))
end

function p.GetStrengthPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Strengths")[name]
	
	return frame:preprocess(string.format(strengthpage,
	name,
	data.notes or "None"))
end

function p.GetCivRow(frame)
	local displayname = frame.args[1]
	local name = string.gsub(displayname, " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Civs")
	local unit = data[name]

	return frame:preprocess(string.format(civrow,
	"[[Image:"..displayname.." (Civ3).png|64px|link="..displayname.." (Civ3)]]",
	"[["..displayname.." (Civ3)|"..name.."]]",
	unit.strengths and LinkAll(unit.strengths) or "None",
	unit.startingtechs and LinkAll(unit.startingtechs) or "None",
	unit.culturegroup or "None"))
end

local civpage = [=[<infobox>
    <title><default>%s</default></title>
    <image><default>%s.png</default></image>
    <data><label>Leader</label>
        <default>%s</default></data>
    <data><label>Strengths</label>
        <default>%s</default></data>
    <data><label>Unique unit</label>
        <default>%s</default></data>
    <data><label>Starting<br>advances</label>
        <default>%s</default></data>
    <data><label>Aggression</label>
        <default>%s/5</default></data>
    <data><label>Favorite government</label>
        <default>%s</default></data>
    <data><label>Shunned government</label>
        <default>%s</default></data>
    <data><label>Culture group</label>
        <default>%s</default></data>
    <data><label>Production emphasis</label>
        <default>%s</default></data>
    <data><label>Default color</label>
        <default><P style="background-color: %s">&nbsp;</P></default></data>
    <data><label>Alternate color</label>
        <default><P style="background-color: %s">&nbsp;</P></default></data>
</infobox>
{{BackArrow|List of civilizations in Civ3|Back to the list of civilizations}}{{#if:{{NAMESPACE}} | |[[Category:Civilizations (Civ3)]]}}]=]

function p.GetCivPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local data = mw.loadData("Module:Data/Civ3/Civs")[name]
		
	return frame:preprocess(string.format(civpage,
	name,
	"[[Image:"..PAGENAME..".png|130px]]",
	data.leader and Link(data.leader) or "?",
	data.strengths and LinkAll(data.strengths) or "None",
	data.unique and Link(data.unique) or "None",
	data.startingtechs and LinkAll(data.startingtechs) or "None",
    data.aggression or "0",
	data.favgov and Linkg(data.favgov) or "None",
        data.shungov and Linkg(data.shungov) or "None",
	data.culturegroup or "None",
        data.production or "None",
	data.color1 or "None",
	data.color2 or "None"))
end

function p.GetGovernmentPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local government = mw.loadData("Module:Data/Civ3/Governments")[name]
		
	return frame:preprocess(string.format(governmentPage,
	name,
	"[[Image:"..(name == "Feudalism" and name.." (Government)" or name).." (Civ3).png|130px]]",
	government.reqtech and Link(government.reqtech) or "None",
	government.allows and Link(government.allows) or "None",
	government.workerEfficiency and tostring(government.workerEfficiency).."%" or "?",
	government.hurryMethod or "None",
    government.corruption or "?",
	government.warWeariness or "?",
    government.draftRate or "?",
	government.militaryPolice or "?",
    government.unitsSupport[1] or "?",
    government.unitsSupport[2] or "?",
    government.unitsSupport[3] or "?",
	government.supportPerUnit or "?",
	government.assimilationChance and tostring(government.assimilationChance).."%" or "?",
	government.spies or "?",
	government.notes or "None"))
end

function p.GetWorkerActionPage(frame)
	local PAGENAME = mw.title.getCurrentTitle().text
	local name = string.gsub(PAGENAME, " %(.*","")
	local action = mw.loadData("Module:Data/Civ3/Worker Actions")[name]
		
	return frame:preprocess(string.format(workerActionPage,
	name,
	"[[Image:"..name.." (Civ3).png|130px]]",
	action.reqtech and Link(action.reqtech) or "None",
	action.requiredImprovement and LinkCapitalized(action.requiredImprovement) or "None",
	action.requiredTerrain and LinkCapitalized(action.requiredTerrain) or "None",
	action.requiredResources and LinkAll(action.requiredResources) or "None",
    tostring(action.turns) or "?",
	action.consumesWorker and "Yes" or "No",
    action.effect and LinkCapitalizedExceptFirst(action.effect) or "None",
	action.notes and LinkCapitalizedExceptFirst(action.notes) or "None"))
end

function p.ImageAndLink(frame)
	return frame:preprocess("[[Image:"..frame.args[1].." (Civ3).png|link="..frame.args[1].." (Civ3)]] "..Link(frame.args[1]))
end

return p