City View UI update - Local Happiness/Maintenance

Fikes

Chieftain
Joined
Jan 9, 2013
Messages
17
attachment.php


Release Information
Version 2
Shows local maintenance and city happiness in the upper left hand corner of the city view.

Where to find
Steam workshop -> Interface (http://steamcommunity.com/sharedfiles/filedetails/?id=120547096)
Civ Fanatics: http://forums.civfanatics.com/downloads.php?do=file&id=20743 (in moderation queue as of 1/15/2013)

Description
This mod adds a display to the city view screen that indicates the local happiness provided vs the population as well as city income vs maintenance.

This allows the player to make better decisions regarding local happiness and additional buildings. The local happiness count does factor in all policies and religions in Gods and Kings/Vanilla. Modified buildings will also be counted correctly. HOWEVER, a mod that adds local happiness through some other means (for example, +1 happiness if nearby a desert tile) will NOT be counted.

VERSION 2: Version 2 is a minor revision that includes a single spelling error fix and support Vanilla Civilization V. It also includes support for mods which use the "building.IsVisilbe" function.

Vanilla Support: One quick note on Vanilla support is that the game will run fine, but your city view screen will include a line for faith with no value after it.

If for some reason the mod doesn't show up in your mod list after you subscribe, it can be downloaded directly from CivFanatics at http://forums.civfanatics.com/downloads.php?do=file&id=20743 . Once downloaded place it in your "\My Games\Sid Meier's Civilization 5\MODS" folder.

Note: These UI updates directly modify the cityview.lua and xml files and is therefore not compatible with any other cityview modifications.

Some of the code for this mod was taken (with permission) from whoward69's pick and mix mods found at http://www.picknmixmods.com/
 
Nice! Will give it a try. I'm sure this info could be extra interesting for other mods as well (e.g. using local happiness for "stability").

One thing: the most common use of a custom CityView.lua is to make dummy buildings (adding an effect in e.g. the UA) invisible. There seems to be consensus to add an "IsVisible" column for buildings (as introduced by Thalassicus). Could you include this functionality in the mod? It's really straightforward and will add compatibility with a fair amount of custom civs :)

Spoiler :
It's just one line really: in the function "AddBuildingButton", make the second line:

if (pCity:IsHasBuilding(buildingID)) and building.IsVisible then -- "and ..." added by Thalassicus

With an sql query to to introduce the column, if not there already:

ALTER TABLE Buildings
ADD IsVisible boolean DEFAULT 1;
 
I'll definitely add that line to my code. I won't upload it right away though, I want to give it a week or two so people can find spelling errors (such as "producting") or anything else I missed.

I am not sure exactly how the code you mentioned is supposed to look though... is this right?

Code:
function AddBuildingButton( pCity, building )
local buildingID= building.ID

	--Modified ER 1/21/2013
	--Added to support Unique abilites in other mods.
	--UNTESTED
	if (pCity:IsHasBuilding(buildingID)) and building.IsVisible then -- "and ..." added by Thalassicus

	else
	DB.Query("ALTER TABLE Buildings ADD IsVisible boolean DEFAULT 1")
	end

I am also thinking of other things I can do to make the cityview screen more friendly. Maybe a drop down that limits what the production window shows (only air units, only naval units, only buildings that impact science, ect). I am open to ideas.

One other thing about the mod that I am not sure how to explain, is what mods it will work with. For example, any mod that adds a building that produces happiness or changes the happiness produced by a building will work, included those that do this through policies or beliefs.

However, any mod that adds happiness in a different way (for example, Goddess of Love adds 1 happiness at 6 citizens) won't be counted, since I had to call those out explicitly.
 
I am not sure exactly how the code you mentioned is supposed to look though... is this right?
The "else" part shouldn't be there. Basically if the IsVisible flag is false, the AddBuildingButton method should end, as if the building is not present in the city at all.
The query should be executed in an sql file, so that every building has the IsVisible flag, before anything in CityView.lua is ever executed.

To see what's the point of my suggestion you can have a look at Tomatekh's recent Mali mod, which has a "dummy building folder", to be deleted in case of compatibility issues (i.e. another modded CityView.lua or CivilopediaScreen.lua).
All this if you think it is interesting for you of course :)

I am also thinking of other things I can do to make the cityview screen more friendly. Maybe a drop down that limits what the production window shows (only air units, only naval units, only buildings that impact science, ect).
Sounds good, especially for mods that add more buildings, or cut on building prerequisites.

However, any mod that adds happiness in a different way (for example, Goddess of Love adds 1 happiness at 6 citizens) won't be counted, since I had to call those out explicitly.
"Will not show local happiness from modded non-building sources."? Maybe many people won't get the meaning, but when it applies to their game and they think the display is bugged, this info should be enough for them to figure out the cause. Expect questions nevertheless.
 
+1 for filtered building queues.
 
Well Fikes it doesn't look like it likes vanilla...
Its playable but this is what i see:
 

Attachments

  • 2013-01-25_00001.jpg
    2013-01-25_00001.jpg
    245 KB · Views: 230
Well Fikes it doesn't look like it likes vanilla...
Its playable but this is what i see:

I think I know what the problem is there but if you could do something for me it would help.

If you download the SDK you can run the program "Firetuner". Open that up and then open Civ V and enable the mod and start a game.

When you go into the city screen the "LUA console" portion of Firetuner will throw out a bunch of stuff. Most of it will just be notes I made to myself for debugging, but if you can copy the line with the word "Exception" in it, it will tell me where the error is.

Unfortunately I have moved bases and the internet here sucks, so I won't be able to upload until I get home in a couple of weeks.
 
Fikes,
thats to much hassle on my end. as like Whohoward stated its only works for G&K.
 
I actually don't use GetLocalHappiness(), I just count up all the happiness provided by all the buildings, beliefs and policies. More than likely I forgot to check if the installation was Gods and Kings somewhere.

But I also bet there is something in the cityview.xml that requires Gods and Kings and is causing it to crash.
 
All three city view files (.lua, .xml and _small.xml) have specific G&K versions
 
I was able to add Vanilla support, but the city screen still has a line for faith. I think that is okay.

The only other modification at this point is one spelling correction. Oh, and a check for building.isVisible.

Whoward, if you want to add vanilla support to your mod you can take my get local happiness function (which references your "gethappinessbuildings() fnction). I don't use the build in one because I don't think it calculates quite correct. maybe it includes your city's impact on global happiness?

Anyways, here is the code for that function.

Spoiler :

Code:
		g_iERBuildingHappiness = 0
  			-- Modified ER 1/9/2013
			-- Building Happiness numbers
			--local pERPlayer = Players[pCity:GetOwner()];
		for _,building in pairs(happinessBuildings) do
			local iBuilding = building.ID
			local buildingClass = GameInfo.BuildingClasses[building.BuildingClass]
			if (pCity:IsHasBuilding(iBuilding)) then
				g_iERBuildingHappiness = g_iERBuildingHappiness + building.Happiness; --+ pERPlayer.GetExtraBuildingHappinessFromPolicies[buildingID];
				print("Calculating Happiness::: Happy Building ID" .. " " .. building.ID .. " Happyiness " .. building.Happiness .. " Building Class " .. building.BuildingClass)
			end
		end


		if (isGandK) then
			local pReligion
			if (pPlayer:HasCreatedReligion()) then
				pReligion = pPlayer:GetReligionCreatedByPlayer()
			elseif (pPlayer:HasCreatedPantheon()) then
				pReligion = 0
			end 
		
			local cReligion = pCity:GetReligiousMajority()

			print("Player created religion = " .. tostring(pReligion) .. " City religion = " .. tostring(cReligion))

			if  cReligion == pReligion then
				local beliefs = GetPlayerBeliefs(pPlayer)
				print("Start Loop")

				if (beliefs[14]) then
					print("Extra local happy from river!")
					pPlot = Map.GetPlot(pCity:GetX(), pCity:GetY())
					if pPlot:IsRiver() then
						print("City is on a river!!!")
						g_iERBuildingHappiness = g_iERBuildingHappiness +1
					else
						print("City is not on a river")
					end
				else
					print("No extra river happy")
				end
				if (beliefs[15]) then
					print("Extra local happy for +6")
					if (pCity:GetPopulation() >= 6) then
						g_iERBuildingHappiness = g_iERBuildingHappiness +1
						print("And population is high enough!")
					else
						print("But Population is too low.")
					end
				else
					print("No extra love happy")
				end		
			end
		end

		if pPlayer:HasPolicy(16) then
			print("Player has Military Caste. Extra Happy from garrison.")
			if (pCity:GetGarrisonedUnit() ~= nil) then
				print("And a unit is here")
				g_iERBuildingHappiness = g_iERBuildingHappiness + 1
			else
				print("But no unit is here")
			end
		else
			print("Player does nto have Military Caste.")
		end

		print("Stop loop")


Ignore all the print stuff, obviously, those just help me debug in the LUA console.

At the end of this g_iERBuildingHappiness is to total of all local happiness, which I then just compare to the city population.
 
I wanted to give you guys a preview of Version 3 and get a little advice.

V3 will add filtering to Units and Buildings/Wonders. Units will filter based on combat type, while buildings will filter based on what they yield/Improve. It is a modification to the ProductionPopup (the screen you see when you hit "Choose Production" from the city view.

My first question is, can you guess at what the filter buttons will filter by? The goal here is to make the interface BETTER, not confusing in a different way :crazyeye:

Slightly related is that if anyone wants to make a better sit of buttons, please do! I know there is an offical place to request Icons, but I want a better idea of what I need before I go there. Those buttons are 30x30 and since they are buttons, they have 3 states. Stationary, Mouse Over, and Click. The way the icons work is that you can specify an off set on an image sheet for the stationary mode. It will then look directly below it for the mouse over and below that for the click. I have the one I use if anyone wants to take a gander.

Secondly, the code for buildings does not run very fast. I have a decent computer (Intel I7), but it can take 3 full seconds of frozen screen to filter out buildings when you start a game and add all techs to a player (that should be worse case scenario, since it would be the max building and wonder number.) The worst part is so far I am only checking for yields in one way (just looking for buildings that give you a flat bonus).

Does anyone see anything I can do to speed this check up or know of a way to check for yields that doesn't involve a DB query?

Code:
for row in DB.Query("SELECT b.ID, b.Type, y.YieldType FROM Building_YieldChanges y, Buildings b WHERE b.Type = y.BuildingType AND y.YieldType = \"" .. tostring(g_ERShowType_B) .. "\"") do
						print("Building description " .. building.Description .. " building.BuildingType = " .. tostring(row.type ) .. " row.YieldType =  " .. tostring(row.YieldType) )
						if building.ID == row.ID then
							AddProductionButton( buildingID, building.Description, OrderTypes.ORDER_CONSTRUCT, strTurnsLeft, col, isDisabled, YieldTypes.NO_YIELD );
				
							if col == 2 then
								numBuildingButtons = numBuildingButtons + 1;
							else
								numWonderButtons = numWonderButtons + 1;
							end
							break;
						end
 

Attachments

  • UIV3.png
    UIV3.png
    251.1 KB · Views: 277
The building buttons are self-explanatory to me (maybe add one for wonders). The unit buttons make sense, but I think I would try to have fewer buttons for units. I would go with:

1) non-combat (settlers, workers, prophets, etc)
2) naval units
3) air units
4) siege & melee units
5) whatever I'm forgetting.

I'm looking forward to trying this out! :goodjob:

Also, would this be compatible with the City View for Notebooks MOD?
http://steamcommunity.com/sharedfiles/filedetails/?id=85139931&searchtext=
 
The building buttons are self-explanatory to me (maybe add one for wonders). The unit buttons make sense, but I think I would try to have fewer buttons for units. I would go with:

1) non-combat (settlers, workers, prophets, etc)
2) naval units
3) air units
4) siege & melee units
5) whatever I'm forgetting.

I'm looking forward to trying this out! :goodjob:

Also, would this be compatible with the City View for Notebooks MOD?
http://steamcommunity.com/sharedfiles/filedetails/?id=85139931&searchtext=

Definitely not compatible with that mod.

Maybe I will combine down the buttons. At any given time you only have 1 or 2 types of units, I guess it makes sense. Do Non-Combat, Land, Naval, Air.

As for buildings and wonders... currently the mod will filter both, so if you select "gold" you will see all buildings and wonders that provide a flat or percentage bonus to gold production. I could set it up so wonders are left alone but I am not really sure which I like more.

Also, without some serious work, special effects of wonders won't be counted. For instance Ironworks bonus for each iron source is buried deep in the database so without doing a specific check for that wonder, it won't be counted as a production building.
 
I will definitely give this a try, but ultimately, I would have to choose between this and the notebook view. Boo!
 
Maybe I will subscribe to Notebook view and get some more ideas for my mod.

What features specifically do you like in that mod?
 
Back
Top Bottom