[SDK]Problems viewing the unhappiness in a city

Afforess

The White Wizard
Joined
Jul 31, 2007
Messages
12,239
Location
Austin, Texas
I've added two new tags to the SDK, for civics, that involve happiness. One, is CivicHappiness, which adds happiness in all cities, instead of just the largest ones, and the other is a clone of the HappyperMilitaryUnits, but turned into a percent, so that I can have 25 = 25% of one happy face or 4 troops = 1 happiness.

I seem to have coded everything almost right, because they show up in the civilopedia fine, and read from the XML fine, and show up in the city okay, except that now, the unhappiness half of the bar is gone, so that a city only shows how happy it is. I believe a screenshot is in order:
Spoiler :



Anyway, I think it has to do with something that I've done wrong in CvGameTextMgr, but I'm not sure.
 
Could you have set the value (or changed the initialization, or something along those lines) that triggers the no-unhappy effect that the Globe Theatre gives? It would be the code related to the bNoUnhappiness tag from BuildingInfo. Or, perhaps, set this to 1 for the palace in the XML?
 
Could you have set the value (or changed the initialization, or something along those lines) that triggers the no-unhappy effect that the Globe Theatre gives? It would be the code related to the bNoUnhappiness tag from BuildingInfo. Or, perhaps, set this to 1 for the palace in the XML?

Impossible, I think. Everything seems to be working, other than that bug.

However, I commented out all my changes in the CvGameTextMgr and the problem still persist. Could it be related to BUG 4.0?
 
BUG doesn't change the happiness hover. BULL does, but not BUG. Can you post your CvGameTextMgr.cpp? Code is always the best way to find bugs. ;)
 
BUG doesn't change the happiness hover. BULL does, but not BUG. Can you post your CvGameTextMgr.cpp? Code is always the best way to find bugs. ;)

Well, Since I'm using a alpha of RevDCM, and it has BULL, that might be why.

Sorry if the commenting for the new addons is poor. I usually add the detailed comments after I've got the code working... But everything should be commented with "Afforess"
View attachment 229923
 
The only thing that BULL does is add buildings at the end of the hover text. I can't see how BULL could affect the list of happiness causes at the top. I'll take a look when I get a chance, but perhaps your debugging skills could help you here. Place a breakpoint near the top and step through the code.
 
The only thing that BULL does is add buildings at the end of the hover text. I can't see how BULL could affect the list of happiness causes at the top. I'll take a look when I get a chance, but perhaps your debugging skills could help you here. Place a breakpoint near the top and step through the code.

Can't. I can not compile debug dll's. (At least, I don't think RevDCM has fixed their makefile problems.)This is like the 4th or 5th thing I need a debug dll for.

My list of things I can still work on is shrinking...
 
I just noticed in the screenshot that the city screen itself is reporting a net 8:). Given that it has +8:), it must have 0:( to add up to 8:). So it looks like the hover text is correct, and I think God-Emperor might be right that the city thinks it has a Globe Theater. Do all cities show the same thing?
 
There are, I think, 2 things that can be happening:
1) The bNoUnhappiness flag is set somehow (or whatever value that flag in the XML sets in the DLL).
2) It isn't - which means the problem is either entirely with the display, which doesn't match what is actually going on, or the entire unhappyness counting mechanism is broken in a way that has it always 0 everywhere in the code.

What happens if you set the city's population to 9?

If an angry citizen shows up and the happyface/unhappyface counts and pop-up still show no unhappy, then the problem is in the happy/unhappy display. If no angry citizens show up, can you actually select 9 tiles to work? If not then it is still a display probem, but if you can then it is aparently generating no unhappyness and it must think the bNoUnhappiness flag is set (or some equivalent) - or the code that counts the unhappy points is so broken that it returns/sets a value of 0 .
 
However, I commented out all my changes in the CvGameTextMgr and the problem still persist. Could it be related to BUG 4.0?

One debugging technique is to make copies of all your changed files, and then replace the originals and do a full rebuild. I can't remember how many times I have thought, "I didn't change anything but it's broken now!" and it turns out I had forgotten to reverse one change. Get back to the point where it's working again, and then re-introduce your changes.
 
One debugging technique is to make copies of all your changed files, and then replace the originals and do a full rebuild. I can't remember how many times I have thought, "I didn't change anything but it's broken now!" and it turns out I had forgotten to reverse one change. Get back to the point where it's working again, and then re-introduce your changes.

I do do that. I have 300mb+ of older revisions of sources, all named appropriately.

I'm going to try God-Emperor's suggestions and see where I get...
 
I don't have the code in front of me right now, but doesn't CvGameTextMgr do something like this?

Code:
if (pCity->unhappyLevel(0) > 0)
{
    ... check all sources of unhappiness ...
}

If so, the problem is most likely in unhappyLevel(), especially since the net happiness is calculating out as if unhappyLevel() returns 0.
 
I do do that. I have 300mb+ of older revisions of sources, all named appropriately.


Wow, that sounds confusing. It seems as if you think this may be a problem with RevDCM/BULL, not your code. To prove that, you need to drop back to a version which has none of your changes, and see if the behavior happens.
 
If an angry citizen shows up and the happyface/unhappyface counts and pop-up still show no unhappy, then the problem is in the happy/unhappy display. If no angry citizens show up, can you actually select 9 tiles to work? If not then it is still a display probem, but if you can then it is aparently generating no unhappyness and it must think the bNoUnhappiness flag is set (or some equivalent) - or the code that counts the unhappy points is so broken that it returns/sets a value of 0 .

I set the city size to 55, and had the unhappy faces show up. It appears to be showing 2 less unhappy faces than there are, which may be leading to the problem.

The thing is that my happiness changes is supposed to be adding two happiness (in the XML, I made it so a starting civic had a value of 2). But in game, it's showing two extra happiness and two less unhappiness. This leads me to believe my coding of it in CvCity is to blame. Here's my coding, see if you can tell me what the flaws are.

CvCity.cpp:

Code:
int CvCity::getCivicHappiness() const //Afforess
{
    return GET_PLAYER(getOwnerINLINE()).getCivicHappiness();
}
...
int CvCity::unhappyLevel(int iExtra) const
{
...
        iUnhappiness -= std::max(0, getCivicHappiness()); //Afforess
    }
...
int CvCity::happyLevel() const
{
...
    iHappiness += std::max(0, getCivicHappiness()); //Afforess
}
...


Wow, that sounds confusing. It seems as if you think this may be a problem with RevDCM/BULL, not your code. To prove that, you need to drop back to a version which has none of your changes, and see if the behavior happens.

No, it's proved to be helpful in the past. It's just the price you pay for liking lots of SDK modcomps. If you name them all correctly, it's pretty easy to sort through.
 
Your unhappyLevel() change uses max() instead of min(). "level -= min(0, value)" is used to add the unhappy component of value only if it is negative. If the value is positive (happy), it is ignored. You are subtracting the happy component instead. You want this:

Code:
iUnhappiness -= std::[B][COLOR="Red"]min[/COLOR][/B](0, getCivicHappiness()); //Afforess
 
Top Bottom