1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Extending the generic property system

Discussion in 'Civ4 - Caveman 2 Cosmos' started by AIAndy, Jan 20, 2012.

  1. AIAndy

    AIAndy Deity

    Joined:
    Jun 8, 2011
    Messages:
    3,420
    The crime building sources are currently all constant sources (type PROPERTYSOURCE_CONSTANT). Law buildings are negative crime sources.
    CvPropertySourceConstant::getAmountPerTurn() returns the amount of the property, CvPropertySource::getProperty() the property type.

    There is also a global crime source that adds crime per population each turn to each city (type PROPERTYSOURCE_ATTRIBUTE_CONSTANT). Currently set to 5 per population and turn.
    The decay (type PROPERTYSOURCE_DECAY) currently decays 4% of crime (or law) each turn.

    Crime diffuses from cities to surrounding plots with 5% each turn and from plot to plot with 4%.
    There is also a diffusion to cities that a city has a trade route with (5%).

    There are a number of pseudo buildings representing crimes that are auto built when the crime rating is in a certain range (and the prerequisites of the building are met).
    So the cost of having a certain crime rating compared to another can be evaluated by the value of the buildings that are built/removed by the change.
     
  2. Koshling

    Koshling Vorlon

    Joined:
    Apr 11, 2011
    Messages:
    9,254
    Ok. I'll work on it early next week.
     
  3. BlueGenie

    BlueGenie Emperor

    Joined:
    Apr 23, 2009
    Messages:
    1,575
    Crime can go into a negative value. Maybe, just a thought, that should be stopped? I don't really see how crime can be below zero, and if anything starts increasing crime it should be from 0, not from -100 something (which it will get to due to Palace reducing crime property).

    Cheers
     
  4. Koshling

    Koshling Vorlon

    Joined:
    Apr 11, 2011
    Messages:
    9,254
    @AIAndy - I suggest we add a range cap to the property definition (iMin, iMax), both for cosmetic reasons (like this one) and to gaurd against runaway growth conditions. It need have no semantic effect but to cap the final value after the turn's sources etc. are processed to the specified range.
     
  5. BlueGenie

    BlueGenie Emperor

    Joined:
    Apr 23, 2009
    Messages:
    1,575
    Runaway growth seems to be needed. Also if it's possible to add to the City UI somewhere what the current total crime modifiers are. It's micromanagement on a high level to check every turn how much crime changes in a city so one knows what crime fighting buildings to add, or what crime buildings one can afford to add.

    I also feel the need to point out that the crime buildings you can build, i.e. assassin's den and those, also add to crime which means that it's basically never a good idea to build them as they only serve to give a little extra gold before you end up paying a lot more due to even more rapid increase in crime in the city. I'd think that building those would mean trying to get the crime under check, or at least get a piece of the cake, rather than add to the problem.

    Might want to issue a warning to those playing on versions without crime in as it seems recalculating assets retroactively adds crime, and it's buildings, to a saved game. At least it seems that was the case with Joseph's save.
    Even if it doesn't a warning to players of crime and it's effects might be a good idea. Seems several have pointed out strange gold behaviour, which I can see most likely stemming from crime buildings due to increased and accelerated crime.

    Cheers

    Edit: Forgot to mention that the automatic crime buildings can be demolished via CTRL-A in city view. That might be a bug and unintended...

    Cheers
     
  6. AIAndy

    AIAndy Deity

    Joined:
    Jun 8, 2011
    Messages:
    3,420
    This is on purpose. Negative crime rating in this case means specifically strong law abiding and law enforcement.
    It could be argued that we don't want that of course. I leave that to the designers to decide.
     
  7. Koshling

    Koshling Vorlon

    Joined:
    Apr 11, 2011
    Messages:
    9,254
    With the currently defined crime-enabled buildings crime is meaningless below a value of +10 (or above +750). Obviously that can change as Hydro defines more crime effect buildings, but I think it would be a sensible design choice (to avoid end user confusion) if crime levels were always positive. Strong policing is not negative crime, it's a large negative crime source (i.e. - a clean up rate), so while negative sources make lots of sense, negative actual crime doesn't IMO. Right now that design choice cannot be made, since the designer has no way to cap the property value. That's why I think limit tags are needed on the actual property values, which would put it back in the hands of the designer.

    BTW, on the subject of visibility, does the total current per-turn level show up in the UI on each game object? Cities at least?
     
  8. AIAndy

    AIAndy Deity

    Joined:
    Jun 8, 2011
    Messages:
    3,420
    No, the difference is not even calculated yet. But it definitely is something that I should add (as it is also a helpful value for the AI).
     
  9. Koshling

    Koshling Vorlon

    Joined:
    Apr 11, 2011
    Messages:
    9,254
    @Hydro & AIAndy (in particular though anyone welcome to comment):

    I'm still testing the AI code for evaluating, but I wanted to outline the approach I'm taking for comment.

    I have decided to simplfiy things a bit in the interests of getting something reasonable out with v22. To this end I am making use of the existing property (fixed amount) evaluation the AI already has (which is used for flammability in fact). To do this, when considering a building, it converts any property per turn sources on the building in question to an effective equivalent fixed amount for the purposes of the calculation, then uses the existing code.

    The way the conversion takes place is to evaluate the steady-state amount of the property the city will end up reaching with and without the building. This is the level at which the net decay takes out the same amount each turn as the sum of all the sources put in. So the code finds decay manipulators for the city object (just one is defined in current assets at 4%, but the code in generic). It then finds the total amount being added per turn, currently considering ONLY constant property sources on buildings, and constant attribute sources on the city itself. This allows it to assess the equilibrium level with and without the building - it then passes the difference to the existing code that is used to evaluate buildings that add a fixed amount.

    There are a few corrolaries of this:
    1. Non-constant sources are not considered, so diffusions from units or tiles won't be accounted for. However, in so far as these eventually move the level of the property on the city this will effect the value given to reducing it further in the existing code, so this shouldn't really matter (it doesn't really effect building choice)
    2. The evaluation makes NO ATTEMPT AT ALL to accurately evaluate (or even look at) the crime buildings that different crime levels imply. Because it uses the pre-existing property evaluation code it uses the same basis it did in v21 to decide what consistutes a good or a bad value, and ASSUMES that there are consequences that are roughly proportional to the level of the property. This means that you must set the tags iOperationalRangeMin, iOperationalRangeMax, AIScaleType, and iAIWeight appropriately in the property definition

    Currently the tags are not set correctly. I have modified them in my own copy for testing purposes (iAIWeight=-100,iOperationalRangeMin=0,iOperationalRangeMax=800) and I'll let you know how that seems. It should be about right for the range, since the key factor is that the range encompasses (without too much slop at the ends) the range over which effects occur (i.e. - the levels that trigger the crime buildings in this case). The weight of -100 matches that used for flammability which has a similar range, so I think it should be approximately ok. Since these are in one of Hydro's files I assume he will prefer to make the master edit, so I'll let you know if these values work out ok in testing.

    Another restriction of the current implementation (though fairly easily resolved if we need to for v22) is that I am only evaluating building property manipulators that apply to their own city only. If we have any buildings that adjust crime in all (or area or whatever) cities I will need to do a bit more work. I don't **think** we have any of these yet do we? Hence this can probably wait until after v22 launch. Similarly we don't currently have any property effects from civics do we? (which will also need AI code if we do)
     
  10. Koshling

    Koshling Vorlon

    Joined:
    Apr 11, 2011
    Messages:
    9,254
    You might want to wait until tomorrow then after I check the AI code in, because it does at least elements of what you might need.
     
  11. AIAndy

    AIAndy Deity

    Joined:
    Jun 8, 2011
    Messages:
    3,420
    Excellent :goodjob:
    All sources are currently local (and I don't think I want to change that). Buildings that want to increase crime in all cities do that by giving free buildings to the cities which then apply the effect.
    So the code you have now should work.

    In the case of the property change recording and display I would just add a second vector to each property object that accumulates the change and then reset that before solving the property equations.
     
  12. Koshling

    Koshling Vorlon

    Joined:
    Apr 11, 2011
    Messages:
    9,254
    Not sure when this happened (I dont THINK its anything I've done), but my crime and flammability values are not showing up in the city screen 'properties' tab. They are there as headings but have no displayed value (not even 0). They ARE present and correct in the city hover help from the main map, so the actual values are still present but for some reason not being displayed.
     
  13. AIAndy

    AIAndy Deity

    Joined:
    Jun 8, 2011
    Messages:
    3,420
    I changed them to be displayed right justified in the second column of the table. That is the same table that is used to display the bonuses so do you see the entries in the second column of the bonus table?
    What resolution do you have?
     
  14. Koshling

    Koshling Vorlon

    Joined:
    Apr 11, 2011
    Messages:
    9,254
    nvm - it's working fine now - I wasn''t running what I thought I was!
     
  15. BlueGenie

    BlueGenie Emperor

    Joined:
    Apr 23, 2009
    Messages:
    1,575
    Done some checking on what happens in my city with the crime rate and it's exhibiting some strange behaviour, as well as going up higher than I think it should.

    Rev:2100
    I have in my lone pop 4 city a Palace (-20 crime) and a Village Hall (+5 crime). To me the Palace should be enough to easily counter the crime in the city with it's inherent -20 crime, but it doesn't. In the attached save crime is at 14 and should, according to how it has fluctuated recently, reach 20 crime in 3 turns.
    If every pop gives 4 crime I'd be in the positive with +21 and -20. Didn't think every pop would give quite that much though. A 100 pop city in the endgame would need law buildings equaling -400 crime then, and that's only if NO buildings adding crime are built. So I'm extrapolating that every pop at most gives +2 crime, in which case my city really should have a stable 0 crime.

    Fluctuation of crime isn't necessarily a bad thing. In the save every other turn is the same constant change to crime, and every other turn is another constant change.
    It goes like this: -4 crime, +5 crime, -4 crime, +5 crime, -4 crime, +5 crime, and so on.
    First I thought this had to do with the high negative values in the adjacent plots but those are no longer so high and it's still doing the same cycle.
    I am still playing the scenario and I was right. 19 crime the next turn, to 15, to 20, to 16, to 21, to 17. I'm betting until I get another + or - crime effect, probably next pop increase, it'll keep doing that.

    Just trying to help iron this new and very good system out.

    Cheers
     
  16. Koshling

    Koshling Vorlon

    Joined:
    Apr 11, 2011
    Messages:
    9,254
    In the current assets (it's in the property XML) each population gives 5. Based on my saved game I'd say that is too much also. The fluctuation you see sounds like a bug to me.

    Incidentally, I think managing crime is going to be a major factor in v22, and because of that I think we're going to need properties (the full set, which is currently just 2) adding to the sort-by drop-downs in the city screen.
     
  17. BlueGenie

    BlueGenie Emperor

    Joined:
    Apr 23, 2009
    Messages:
    1,575
    5? *whistle* Yeah, you're right, version 22 will be all about battling crime...

    Cheers
     
  18. Hydromancerx

    Hydromancerx C2C Modder

    Joined:
    Feb 27, 2008
    Messages:
    16,281
    Location:
    California, USA
    @AIAndy

    Is there a way to add anti-crime to a promotion? I would like to give the law enforcement promotion an anti-crime bonus to whatever tile they are standing on. Thus if you have enough police units in your city it can counter your crime.

    Likewise I would like to make a new "Criminal" promotion that gives increased crime to whatever tile they are on. Thus allowing you to increase crime in rival nations with Mercenaries or Thieves.

    I thought if a building has the cost of -1 it cannot be demolished. Is there a way to make a building so you cannot demolish it?

    I think we should keep it in case we make special anti-crime buildings that are only unlocked with a high safety score. Perhaps some bonus to military XP or special promotions if you get a city with a high enough safety. Or just a bonus to happiness and health. There is lots of potential.

    Well 1 per pop was too little. I am guessing that 3 might be a more balanced number. But that's what this testing is all about. During the freeze we need everyone to test out this crime stuff and give feed back. I mean I would be super lucky to have it perfectly balanced the first time. So keep giving feedback everyone so we can make crime more balanced.
     
  19. AIAndy

    AIAndy Deity

    Joined:
    Jun 8, 2011
    Messages:
    3,420
    Yes, you can. Actually I have not yet added the ability to have a promotion source apply to a city but you can use a source on a promotion or the unit type for the unit and then also add a propagator to get the crime or security to the city or plot.
    But mind that the AI will not understand that without further AI coding.
    So I think it might be something for after the freeze.

    Yes, I already changed that. The check in there was actually specifically for if it is a free building and not if it is a building with a cost of -1.

    Funny would be unhappiness at high security if you have civics that value freedom (people feel oppressed from too much surveillance). And that high security could give you some espionage and counter spy stuff.
     
  20. Dancing Hoskuld

    Dancing Hoskuld Deity

    Joined:
    Jul 5, 2004
    Messages:
    23,540
    Gender:
    Male
    Location:
    Canberra, Australia
    Now we need to decide if this is OK for all buildings built only by units. It probably is but if some have costs associated with them then it may be a problem.
     

Share This Page