Ryan F. Mercer
Whys
Version: 6 (build: 2010.11.20.0000)
Allows buildings to produce resources. This mod is available in the in-game mod screen by the name of "Building Resources -- Template".
Template includes Alchemist building which gives 1 gold resource and 1 iron. Additional resources from buildings can be easily added to the XML.
Includes 2 custom notifications that appear when a resource building is gained or lost and mouseover tooltip displays specific resources and amounts. Left click to go to corresponding location or right click to dismiss.
Known Issue: when a luxury resource is first gained from a building, empire happiness in TopPanel does not update properly until unit moved or next turn.
Technical: This mod uses SaveUtils.lua with ShareData.lua for compliant use of serialized ScriptData with deserialized cache shared as super-global. All concurrent mods and lua states that include SaveUtils will operate on the same shared cache.
A brief tutorial on how to merge this mod with your own mod or mod compilations:
http://forums.civfanatics.com/showthread.php?t=395995&p=9868011
BuildingResources.lua
Template XML & SQL:
CIV5BuildingClasses.xml
CIV5Buildings.xml
Text.sql:
This mod uses SaveUtils.lua
You can find it here: http://forums.civfanatics.com/showthread.php?t=392958
This mod uses ShareData.lua
You can find it here: http://forums.civfanatics.com/showthread.php?t=398814
This mod uses CustomNotificationPanel.lua
You can find it here: http://forums.civfanatics.com/showthread.php?p=9899079
This mod uses WhysUtils.lua
Allows buildings to produce resources. This mod is available in the in-game mod screen by the name of "Building Resources -- Template".
Template includes Alchemist building which gives 1 gold resource and 1 iron. Additional resources from buildings can be easily added to the XML.
Includes 2 custom notifications that appear when a resource building is gained or lost and mouseover tooltip displays specific resources and amounts. Left click to go to corresponding location or right click to dismiss.
Known Issue: when a luxury resource is first gained from a building, empire happiness in TopPanel does not update properly until unit moved or next turn.
Technical: This mod uses SaveUtils.lua with ShareData.lua for compliant use of serialized ScriptData with deserialized cache shared as super-global. All concurrent mods and lua states that include SaveUtils will operate on the same shared cache.
A brief tutorial on how to merge this mod with your own mod or mod compilations:
http://forums.civfanatics.com/showthread.php?t=395995&p=9868011
BuildingResources.lua
Spoiler :
Code:
-- vymdt.06.2010.11.20.0000
-- Created by: Whys Alives -Open source
--===========================================================================
-- BuildingResources.lua
--===========================================================================
--[[
Allows buildings to produce resources.
Template includes Alchemist building which gives 1 gold resource and 1 iron.
Additional resources from buildings can be easily added to the XML.
Includes 2 custom notifications that appear when a resource building is
gained or lost and mouseover tooltip displays specific resources and amounts.
Left click to go to corresponding location or right click to dismiss.
Known Issue: when a luxury resource is first gained from a building, empire
happiness in TopPanel does not update properly until unit moved or next turn.
Technical: This mod uses SaveUtils.lua with ShareData.lua for compliant use
of serialized ScriptData with deserialized cache shared as super-global. All
concurrent mods and lua states that include SaveUtils will operate on the
same shared cache.
]]
include( "SaveUtils" ); MY_MOD_NAME = "BuildingResources--vymdt.06.2010.11.20.0000";
include( "WhysUtils" );
--===========================================================================
--[[
Adds and removes resources provided by buildings.
]]
function applyBuildingResources()
--setCacheState( 0 ); --no cache.
--build resource change table.
local changeTable = {};
for row in GameInfo.Building_ResourceChange() do
changeTable[row.BuildingType] = changeTable[row.BuildingType] or {};
changeTable[row.BuildingType][row.ResourceType] = row.ResourceChange;
end
--loop thru all live players (human and AI).
for index,pPlayer in pairs( Players ) do
if pPlayer ~= nil and pPlayer:IsAlive() then
--previously applied building resources and city locations.
local applied_prev = load( pPlayer, "applied" ) or {};
local located_prev = load( pPlayer, "located" ) or {};
--currently applied building resources and city locations.
local applied_curr = {};
local located_curr = {};
--loop thru player cities.
for pCity in pPlayer:Cities() do
local cityID = pCity:GetID();
applied_prev[cityID] = applied_prev[cityID] or {};
applied_curr[cityID] = {};
located_curr[cityID] = { pCity:GetX(), pCity:GetY() };
--loop thru relevant building types.
for buildingType,resourceTable in pairs( changeTable ) do
local buildingID = GameInfo.Buildings[buildingType].ID;
local buildingDescription = GameInfo.Buildings[buildingType].Description;
--look for matching buildings.
if pCity:IsHasBuilding( buildingID ) then
applied_curr[cityID][buildingID] = buildingType;
--apply resources for new buildings.
if applied_prev[cityID][buildingID] == nil then
local toolTip = ""; --for custom notification.
--loop thru resource changes.
for resourceType,resourceChange in pairs( resourceTable ) do
local resourceID = GameInfo.Resources[resourceType].ID;
local resourceDescription = GameInfo.Resources[resourceType].Description;
local resourceIconString = GameInfo.Resources[resourceType].IconString;
pPlayer:ChangeNumResourceTotal( resourceID, resourceChange ); --cumulative.
if toolTip ~= "" then toolTip = toolTip.."[NEWLINE]"; end
toolTip = toolTip.."[ICON_BULLET][COLOR_POSITIVE_TEXT]"
..resourceChange.."[ENDCOLOR] "..resourceIconString.." "
..Locale.ConvertTextKey( resourceDescription );
end --END resource loop.
--activate notification.
if pPlayer:GetID() == Game.GetActivePlayer() then
toolTip = "[COLOR_POSITIVE_TEXT]Gained[ENDCOLOR] "
..Locale.ConvertTextKey( buildingDescription )
..":[NEWLINE]"..toolTip;
LuaEvents.CustomNotification( 1001 --BuildingResourcesGain.
, "[COLOR_POSITIVE_TEXT]Resource Gain[ENDCOLOR]", toolTip
, { ["location"] = located_curr[cityID]
, ["buildingType"] = buildingType } );
end
end
--remove handled building case.
applied_prev[cityID][buildingID] = nil;
end
end --END building loop.
--remove empty city case.
if len( applied_prev[cityID] ) == 0 then applied_prev[cityID] = nil; end
end --END city loop.
--save applied building resources and city locations.
save( pPlayer, "applied", applied_curr );
save( pPlayer, "located", located_curr );
--unapply resources for lost buildings.
for cityID,buildingTable in pairs( applied_prev ) do
for buildingID,buildingType in pairs( buildingTable ) do
local buildingID = GameInfo.Buildings[buildingType].ID;
local buildingDescription = GameInfo.Buildings[buildingType].Description;
local toolTip = ""; --for custom notification.
--loop thru resource changes.
for resourceType,resourceChange in pairs( changeTable[buildingType] ) do
local resourceID = GameInfo.Resources[resourceType].ID;
local resourceDescription = GameInfo.Resources[resourceType].Description;
local resourceIconString = GameInfo.Resources[resourceType].IconString;
pPlayer:ChangeNumResourceTotal( resourceID, -resourceChange ); --cumulative.
if toolTip ~= "" then toolTip = toolTip.."[NEWLINE]"; end
toolTip = toolTip.."[ICON_BULLET][COLOR_NEGATIVE_TEXT]"
..resourceChange.."[ENDCOLOR] "..resourceIconString.." "
..Locale.ConvertTextKey( resourceDescription );
end --END resource loop.
--activate notification.
if pPlayer:GetID() == Game.GetActivePlayer() then
toolTip = "[COLOR_NEGATIVE_TEXT]Lost[ENDCOLOR] "
..Locale.ConvertTextKey( buildingDescription )..":[NEWLINE]"
..toolTip;
LuaEvents.CustomNotification( 1002 --BuildingResourcesLoss.
, "[COLOR_NEGATIVE_TEXT]Resource Loss[ENDCOLOR]", toolTip
, { ["location"] = located_prev[cityID]
, ["buildingType"] = buildingType } );
end
end --END building loop.
end --END city loop.
end
end --END player loop.
LuaEvents.BuildingResourcesApplied();
end
Events.ActivePlayerTurnStart.Add( applyBuildingResources );
--===========================================================================
--END BuildingResources.lua
--===========================================================================
-- Created by: Whys Alives -Open source
Template XML & SQL:
Spoiler :
CIV5BuildingClasses.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<GameData>
<BuildingClasses>
<!-- Table data -->
<Row>
<Type>BUILDINGCLASS_ALCHEMIST</Type>
<DefaultBuilding>BUILDING_ALCHEMIST</DefaultBuilding>
<Description>TXT_KEY_BUILDING_ALCHEMIST</Description>
</Row>
</BuildingClasses>
</GameData>
Code:
<?xml version="1.0" encoding="utf-8"?>
<GameData>
<!-- Table definition -->
<Table name="Building_ResourceChange">
<Column name="BuildingType" type="text" reference="Buildings(Type)"/>
<Column name="ResourceType" type="text" reference="Resources(Type)"/>
<Column name="ResourceChange" type="integer"/>
</Table>
<!-- Table data -->
<Buildings>
<Row>
<Type>BUILDING_ALCHEMIST</Type>
<BuildingClass>BUILDINGCLASS_ALCHEMIST</BuildingClass>
<Cost>1</Cost>
<GoldMaintenance>1</GoldMaintenance>
<Help>TXT_KEY_BUILDING_ALCHEMIST_HELP</Help>
<Description>TXT_KEY_BUILDING_ALCHEMIST</Description>
<Civilopedia>TXT_KEY_BUILDING_ALCHEMIST_PEDIA</Civilopedia>
<Strategy>TXT_KEY_BUILDING_ALCHEMIST_STRATEGY</Strategy>
<ArtDefineTag>ART_DEF_BUILDING_FORGE</ArtDefineTag>
<MinAreaSize>-1</MinAreaSize>
<ConquestProb>0</ConquestProb>
<HurryCostModifier>-1</HurryCostModifier>
<IconAtlas>CIV_COLOR_ATLAS_LEGENDS</IconAtlas>
<PortraitIndex>3</PortraitIndex>
</Row>
</Buildings>
<Building_ResourceChange>
<Row>
<BuildingType>BUILDING_ALCHEMIST</BuildingType>
<ResourceType>RESOURCE_GOLD</ResourceType>
<ResourceChange>1</ResourceChange>
</Row>
<Row>
<BuildingType>BUILDING_ALCHEMIST</BuildingType>
<ResourceType>RESOURCE_IRON</ResourceType>
<ResourceChange>1</ResourceChange>
</Row>
</Building_ResourceChange>
</GameData>
Code:
INSERT INTO Language_en_US ( 'Tag', 'Text' )
VALUES ( 'TXT_KEY_BUILDING_ALCHEMIST', 'Alchemist' );
INSERT INTO Language_en_US ( 'Tag', 'Text' )
VALUES ( 'TXT_KEY_BUILDING_ALCHEMIST_HELP', 'Produces 1 gold resource and 1 iron.' );
INSERT INTO Language_en_US ( 'Tag', 'Text' )
VALUES ( 'TXT_KEY_BUILDING_ALCHEMIST_PEDIA', 'The alchemist produces gold and iron.' );
INSERT INTO Language_en_US ( 'Tag', 'Text' )
VALUES ( 'TXT_KEY_BUILDING_ALCHEMIST_STRATEGY', 'Turn lead into gold!' );
This mod uses SaveUtils.lua
You can find it here: http://forums.civfanatics.com/showthread.php?t=392958
This mod uses ShareData.lua
You can find it here: http://forums.civfanatics.com/showthread.php?t=398814
This mod uses CustomNotificationPanel.lua
You can find it here: http://forums.civfanatics.com/showthread.php?p=9899079
This mod uses WhysUtils.lua
Spoiler :
Code:
-- vymdt.01.2010.11.17.0000
-- Created by: Whys Alives -Open source
--===========================================================================
-- WhysUtils.lua
--===========================================================================
--[[
Global Functions: len(), out().
]]
--===========================================================================
--[[
Returns length of both tables and strings. Returns false when given boolean,
function, userdata, or thread.
]]
function len( p )
local r = 0; local t = type( p );
if t == "boolean" or t == "function" or t == "userdata" or t == "thread"
then r = false; print( "len(): Invalid type: "..t ); --error.
elseif t == "table" then for k,v in pairs( p ) do r = r +1; end
elseif t == "string" then r = p:len();
end
return r;
end
--===========================================================================
--[[
Returns a string representation of any given data type.
]]
function out( p )
local r = ""; local t = type( p );
if p ~= nil then
if t ~= "table" then
if t == "boolean" or t == "number" or t == "function"
or t == "userdata" or t == "thread" then
r = tostring( p );
else r = '"'..p..'"';
end
else
r = "{"; local b = false;
for k,v in pairs( p ) do
if b then r = r..","; end
r = r..out( k ).."="..out( v );
b = true;
end
r = r.."}"
end
end
return r;
end
--===========================================================================
--END WhysUtils.lua
--===========================================================================
-- Created by: Whys Alives -Open source