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

Hipfot's veyDer's User Events

Discussion in 'Civ5 - Mod Components' started by Hipfot, May 3, 2011.

  1. skodkim

    skodkim Deity

    Joined:
    Jan 16, 2004
    Messages:
    2,295
    Location:
    Denmark
    I'm very sorry but I just don't get it. Just spent the entire morning trying to get the tech requirements to work and all I got was frustrations...

    Looked through your mod for examples of how Teams and TeamTechs functions work but as the structure thre is so different from this I really have no idea of where to begin and where to end.

    Then I tried messing about with

    I also spent a lot of time trying to figure out how Gameinfo and GameInfoTypes work.

    The original condition function went like this

    Spoiler :
    Code:
    function NewIronCond( player, city, unit, plot )
    	return city and not plot:IsCity() and plot:GetResourceType() == -1 and _PlayerHasTech( player, "TECH_IRON_WORKING") and not plot:IsFlatlands() and plot:GetImprovementType() == GameInfo.Improvements[ "IMPROVEMENT_MINE" ].ID;
    end
    [/SPOILER]
    As I understood your last post nr.1 priority was using the Teams and TeamTechs functions but if I did use _PlayerHasTech I had to mess around with the GameInfoTypes functions and/or GameInfo.Technologies. Unfortunately I haven't been able to understand exactly what they do so I had to try and learn from examples from mods/threads and trial and error.

    I tried changing the code to:

    Spoiler :
    Code:
    function NewIronCond( player, city, unit, plot )
    	local thisTech = GameInfo.Technologies[0].ID;
    	return plot and not plot:IsCity() and _PlayerHasTech( player, thisTech ) and plot:GetResourceType() == -1 and plot:GetImprovementType() == GameInfo.Improvements[ "IMPROVEMENT_MINE" ].ID;
    end
    [/SPOILER]
    Thereby trying to make Agriculture the requirement for the function (as Agriculture has ID 0..?) and it seemed to work.

    In the firetuner I could see the ID for alle the techs I needed, e.g. Iron Working had ID 17, so I changed all the the condition functions to something similar to the one below

    Spoiler :
    Code:
    function NewIronCond( player, city, unit, plot )
    	local thisTech = GameInfo.Technologies[0].ID;
    	return plot and not plot:IsCity() and _PlayerHasTech( player, thisTech ) and plot:GetResourceType() == -1 and plot:GetImprovementType() == GameInfo.Improvements[ "IMPROVEMENT_MINE" ].ID;
    end
    [/SPOILER]
    and now it doesn't work...

    I'm really puzzled here. Is there any chance you could give an example of how you'd do the tech prereqs in a function like toe one above? Either change the line given above and paste it here or look at the mod in its current state (attached to post)

    \Skodkim
     
  2. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    GameInfoTypes.TECH_IRON_WORKING will just return 17. If you're hard-coding something internally to always key of a specific tech, this is the way to do it. You can use this same method for pretty much anything: GameInfoTypes.YIELD_PRODUCTION, GameInfoTypes.UNIT_WORKER, and so on; any XML table with an ID field can be done this way. It's assumed that you understand exactly WHICH table you're getting the ID for, but generally speaking this is the best way to go when you know exactly what you need.

    GameInfo.Technologies["TECH_IRON_WORKING"] returns the tech structure for Iron Working, so you can just do GameInfo.Technologies["TECH_IRON_WORKING"].ID to get that same 17. It's a bit longer to write, but this is the best when you don't know which tech you want to key off of, or when you want something other than ID. (Like GameInfo.Technologies["TECH_IRON_WORKING"].Description, if you want the text key for its name.) You see, each of the XML tables that has an ID field has a "key" entry, usually Type. Putting that Type variable, as a string, into the brackets is enough to identify the entry uniquely.
    This option is best when you're constructing a name on the fly. For instance, in my game you pick a Pantheon, like PANTHEON_GREEK. Each Pantheon is explicitly tied to a Project the player has (PROJECT_PANTHEON_GREEK), which is used as a prerequisite for Greek-specific units. So if I pass in the pantheon number (0, in this case, for GameInfoTypes.PANTHEON_GREEK) as a variable "panthID" and want to access the linked Project's structure, I just go
    Code:
    local Proj = GameInfo.Projects["PROJECT_"..GameInfo.Pantheons[panthID].Type];
    And then I can get Proj.Description, Proj.ID, and so on as necessary.

    As for the Teams/TeamTechs thing, the way you do it is something like
    Code:
    local pTnum = pPlayer:GetTeam();
    local pTeam = Teams[pTnum];
    if pTeam:IsHasTech(GameInfoTypes.TECH_IRON_WORKING) then
      (stuff here)
    end
    
    You can abbreviate this a bit, to something like
    Code:
    if Teams[pPlayer:GetTeam()]:IsHasTech(blah) then
    but I generally like spreading it out a bit.
    The point is that techs are not linked to the specific player, they're linked to the Team (which in a default game only has the single player). Yes, the devs provided a couple shortcuts to get this in other ways, but as I said before, this way ALWAYS works because it's how the database is built.

    TeamTechs is managed off of Teams, that is pTeamTechs = pTeam:TeamTechs(), and then you query pTeamTechs for what you need. If all you want to know is whether a person has a specific tech, then the pTeam check above is just fine, but if you want to do something more complex like find out how much progress they've made towards their next tech or which techs they're currently queued up to research, that information's only accessible through the TeamTechs structures.

    I'm on vacation. No Civ5 access at all, and limited internet access. So I'm doing this from memory, and can't look at any files you provide until the new year.
     
  3. skodkim

    skodkim Deity

    Joined:
    Jan 16, 2004
    Messages:
    2,295
    Location:
    Denmark
     
  4. St0Ne 4Ge

    St0Ne 4Ge Chieftain

    Joined:
    Sep 6, 2010
    Messages:
    9
    I will keep an eye on this mod it sounds like a good idea, once it's stable and works for the AI too i'll download for sure, good luck with it.
     
  5. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    Writing "Fnum = 1.0" creates a scalar, not an array, so you can't check Fnum[0], Fnum[1], etc. in that case. That's why you're getting the error message. You could write it as
    local Fnum = {1.0,1.0,1.0,1.0};
    instead, and it'd now work without that crash. Obviously, the size of the array would depend on the number of options you wanted each Event to have. In my mod, every event has exactly four options, so it has to be a 4-element array. If you've got different numbers of outcomes for each event, then you'd need something different for this, although if you just did a worst-case thing and wrote
    local Fnum = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0};
    then it'd be fine as long as you didn't put more than 10 options on each event.

    But really, the better idea is to remove the Fnum references entirely. Just change the line
    optWeight[nValid] = Fnum[option.order]*1.0;
    to
    optWeight[nValid] = 1.0;

    It'd still multiply this weighting by the Flavor values, but the starting value would be a stable 1.0 regardless of the number of options. Now, you could keep the Fnum part in there if you were to come up with some other way of weighting the options; maybe you'd want to add something where option #1 was always twice as common as the others, because it's the "safe" option. So there, you'd leave the Fnum declaration in place, and if there were always three outcomes you'd put
    local Fnum = {2.0,1.0,1.0};
    but again, this requires you to know exactly how many options the event has. Given that the two events you'd posted earlier didn't have the same number of options, this isn't practical, so you're probably just going to want to get rid of Fnum altogether. (Or, like I did above, make a huge array and just make the first element be 2.0.)
     
  6. skodkim

    skodkim Deity

    Joined:
    Jan 16, 2004
    Messages:
    2,295
    Location:
    Denmark
    Hi Spatzimaus

    Just popped in to say that I tried the solution above and it works - thanks! :p

    I'll see if I can get some testing of events and the AI part done over the holidays and if everything works out ok I guess it's ready for use. I'll upload a new version then.

    \Sk:)dkim
     
  7. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    No problem. The reason for the Fnum logic in my own version is that in my mod, these Events serve two separate purposes: they provide the direct effects of each outcome, just like your Events, but they also cause an alignment shift in my own 2-axis system. So, I needed a dynamic weighting basis related to my alignments, so that the AI would be less likely to take the options that'd cause it more long-term problems in the future and more likely to take the ones that'd put it in the best alignment positions, regardless of the Flavors involved.

    Specifically, in my Mythology mod the number of options you'll have when adding a new minor god will depend on a lot of factors (which pantheon you picked, which major god you have, which other minor gods you've added already), so the Fnum array just tells the AI how many minor god choices it'll have if it moves one space in each of the four directions. This way, the AI will tend to move towards the places where it'll have more choices the next time it wants to pick a new minor god, which is generally what the human player already does in the same position.

    I'm explaining this because while the simple solution for a true random event system was to remove the entire Fnum logic, anyone who wants to tie these events into something greater would find that sort of weighting method useful. It doesn't have to be nearly as complex as what I've done; if you've played the Galactic Civilizations games, they generally offered you three choices at each event, basically a Good, Neutral, or Evil option (where the Evil option was generally in the vein of "let a lot of your people die to get huge bonuses"). Other races might react to you differently based on how many times you picked the Evil outcomes, so the AIs would generally favor certain outcomes based on their personalities. So if you want to have any sort of accounting like that, you'd need some sort of baseline weighting like my Fnum.
     
  8. skodkim

    skodkim Deity

    Joined:
    Jan 16, 2004
    Messages:
    2,295
    Location:
    Denmark
    you're probably right. Il'' change the fnum version before I upload the new version - right now I'm just happy it all works.

    Have you or anyone else got any good ideas to how I test functionality for AI players? How do I test if events occour for them and test if they are ble to choose between them?

    \Skodkim
     
  9. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    Well, I just inserted a couple print statements into my own version of the logic to tell me whenever an event would trigger for an AI, the relative weightings of the four choices, and which one it picked. It seemed to be running smoothly, based on those diagnostics. (Also, this helped me debug the events much, much faster, since it didn't only fall to me to trigger the various events by hand. A dozen AI players hit all of the combinations much more quickly than I could.)

    I'd tell you exactly where to stick those print statements, but I'm on vacation and don't have access to my home machine from here. If you download my mod, I might have left them in there but commented out; I don't really remember how much I cleaned up the code after the last round of tests. In a week I'll be back home, and should be able to point you to it then, but it shouldn't be hard for you to figure out where these'd go without me.
     
  10. skodkim

    skodkim Deity

    Joined:
    Jan 16, 2004
    Messages:
    2,295
    Location:
    Denmark
    Hi everyone

    I've updated the mod so that
    • Events occur to AI players
    • AI players choose between possible outcomes through a flavor based system
    • The events giving new resources, e.g. iron, works properly

    First of all I'd like to thank Spatzimaus for his great help over the last weeks - anyone who's followed this thread would have noticed... I actually wound up using two of his updated files (with his permission in a previous thread) and updating them slightly to match this mod.

    Again I'm no modder and I'm not uploading this to maintain a mod - I'll probably not even be able to give much support! My hope is that people will be able to make new additions, tweaks, ... to the mod so that we can keep the idea of random events in Civ V going.


    \Skodkim
     
  11. Gilgamesch

    Gilgamesch Ancient Alien

    Joined:
    Dec 15, 2010
    Messages:
    2,228
    Location:
    good old germany
    Thanks for awesome work so far:D
    Iam now playing with the newest version, and something bugs me.
    I get a message like this, the wisman has left your city. But for me was no event triggering. (at this moment)
    So are this messages reports of the ai? That an event has triggered?
    Maybe someone can point this out.
     
  12. skodkim

    skodkim Deity

    Joined:
    Jan 16, 2004
    Messages:
    2,295
    Location:
    Denmark
    Hey Gilgamesch

    Thanks for your reply. I'm really glad someone's using the mod.

    I did actually see the repeating wiseman notification at one point. I took a quick look at the code this morning and can't find any explanation so I have no idea why it's there. It's actually one of the events I haven't touched (except stating flavors for sub events to make the AI able to choose with some kind of sense).

    Does the message appear every turn from turn 1 and forth or..?


    \Skodkim
     
  13. Gilgamesch

    Gilgamesch Ancient Alien

    Joined:
    Dec 15, 2010
    Messages:
    2,228
    Location:
    good old germany
    No, not every turn, and the messages are different. So like a Settler has left the city and was newer seen again...
    But one thing surprised me . My Capitol was getting a population boom and grows from 1 to 5.
    I played only 30 turns or so. I will report when i played more...:cool:
    Thanks for the quick response.
     
  14. skodkim

    skodkim Deity

    Joined:
    Jan 16, 2004
    Messages:
    2,295
    Location:
    Denmark
    The settler thing is a new event I added. Some of the code was based on the Wiseman event so I guess that's the explanation both events come up with these notifications.

    The population boom is one of the older events. I've had it happen to me once or twice too.

    Yes - it would be great if you'd report back. :goodjob:

    \Skodkim
     
  15. Dunkah

    Dunkah Emperor

    Joined:
    Feb 7, 2007
    Messages:
    1,189
    Location:
    Just north of Boston
    I noticed the same thing. Seems to only happen at the begining of a game. Once I actually end up getting the first event I don't seem to see the messages anymore.

    Saw the wiseman has left the area message, also the settler has left. I think there was another but I didn't write them down.

    At the time I assumed that since I didn't have enough gold to do anything (maybe 30 gold), that perhaps the event simply didn't trigger. Which by the way would be cool.
     
  16. Gilgamesch

    Gilgamesch Ancient Alien

    Joined:
    Dec 15, 2010
    Messages:
    2,228
    Location:
    good old germany
    Last game, the events are triggering twice for me. Every time a event trigger its doubled.
    My capitol was infected, and decreased from 4-2-0, the nomads gave me two workers, the same for all others and the ghostly messages "wiseman has left, money decreased etc...
    Next game i will clear my cache and see if this happened again.
     
  17. skodkim

    skodkim Deity

    Joined:
    Jan 16, 2004
    Messages:
    2,295
    Location:
    Denmark
    I've never seen this and have run both many test sessions and have used the mod in games. Would recommend clearing your cache.

    On a side notice I think some of the shown notifications may be on AI events but I'm not entirely sure how the notifications work as I've used Spatzimaus files for it. If you have the Firetuner open while playing you'll see AI events in the Lua Console.

    \Skodkim
     
  18. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    Correct. Several of the events included in veyDer's original pack included an alert message that'd trigger whenever the event occurs (or whenever a certain option is selected); since only the active player (you) could experience events, there was no problem. If you're using my mechanisms to allow the AI to experience events (which you are), then you need to make sure that any events you add have a player ID check around the message, to see if it's the active player. That is, unless you WANT the active player to know when certain events happened to another empire...

    veyDer's original version included its own alert message function; I just use Game:GameplayAlertMessage instead whenever I need to make those sorts of notifications. But really, there's little reason to bother with messages if the event was controlled by a popup with options, unless the effects include some sort of random component. (Example: if one option for an event says "one of your cities loses 1 population", you'd want to know WHICH city took the hit.) So I don't think any of the events in my Mythology mod had any kind of alert message.
     
  19. Gilgamesch

    Gilgamesch Ancient Alien

    Joined:
    Dec 15, 2010
    Messages:
    2,228
    Location:
    good old germany
    Cleared the cache, and the events are triggering double again. Maybe some ghost mods ( i have a mod who uses a later version, but i deleted it) cause this.
    Another point i get is a loading loop at the beginning of my turn.
    I will try to fix the problem.
     
  20. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    I haven't downloaded the mod in this thread, so I can't check this for myself, but double-triggered Lua functions can easily happen if you're loading the Lua through the usual InGameUIAddin access function as well as setting VFS=true. If something's being added through the Contents or Actions tabs of the mod, then its VFS needs to stay False. (This is especially problematic when you're using a bunch of "include" commands, to where a certain function might be effectively loaded twice.)
     

Share This Page