Announcement

Collapse
No announcement yet.

Tracking my caravan routes... any ideas?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tracking my caravan routes... any ideas?

    CURRENT NEWS:

    Download Current Version: 'Caravan Mod' Alpha

    An alpha version of the mod is up for testing. Please let me know what you think and what needs tweaking or is just plain broken.

    The last post contains all information about the release, I just edited here to put the download at the top of the page.




    ORIGINAL POST:

    I am currently making a mod to include a food caravan system to the game. The basic rules are pretty simple...

    Build 'Caravan' Unit (req: The Wheel and Animal Husbandry) in any city.

    Move the caravan to whichever city will be supplying the food (origin) and click the 'Begin caravan route' button.

    Clicking this button adds the PROMOTION_HASFOOD promotion to the unit and sets the units level to the ID of the origin city (something I need to find a better way to do.) The unit is also renamed from Caravan to 'Food from CITY_NAME (Caravan)' at this point.

    The player now moves the caravan unit to the city that needs the food (destination) and clicks the 'Complete caravan route' button in the action toolbar.

    This deletes the unit, creates a super specialist 'Outgoing Caravan' in the origin city (-3 food, -1 commerce), and creates another super specialist 'Incoming Caravan' in the destination city (+2 food)

    This is the point I'm stuck on... I need to now code a way for the player to cancel these routes once they have been founded and for the game to automatically cancel it if either city is captured or is cut off from the trade network. Basically, I need a nice, clean way to store an array of variables (originID, destinationID) for each active caravan route.

    Another change I haven't yet figured out are to make the 'Outgoing Caravan' specialist change to -2 food, -1 commerce with the discovery of refrigeration (I'd assume a refrigerated truck will no longer have the spoilage issues of the original mule and wagon caravan.)

    Finally, does anyone know if there's a way to allow the caravan units to only move on roads/railroads?

    If anyone has any solutions or tutorials that could help me out I'd appreciate it. Also, any suggestions for changes or balances would be nice also. I'm currently deciding if it would be worth it to make a variable commerce modifier based on distance between the cities (which I'd probably do with 3-4 'same name' specialists with different variables unless someone knows how to change their output on an individual basis.)

    Thanks in advance,
    -Jamison
    Last edited by JamisonP; April 10, 2006, 05:15.

  • #2
    Making the caravan cost 1 commerce definitely helps to keep it from unbalancing the game. I like it.

    Check the code for the Angkor Wat wonder--it adds +1 hammers to Priest specialists, and it sounds like you want to add +1 food to your new specialist type, which sounds similar. The cheap workaround would be to define a cheap-to-build National Wonder that grants +1 food to your Outgoing Caravan specialists.
    Those who live by the sword...get shot by those who live by the gun.

    Comment


    • #3
      This is the point I'm stuck on... I need to now code a way for the player to cancel these routes once they have been founded and for the game to automatically cancel it if either city is captured or is cut off from the trade network. Basically, I need a nice, clean way to store an array of variables (originID, destinationID) for each active caravan route.
      The most sensible way would probably be to have a dictionary of dictionaries of routes {fromCity: {toCity: iNumRoutes}} and to store that in the script data of CyGame. Whenever you add a route, check if the keys exist and update the number of routes if so, if not add the key(s). When removing a route manually go the other way: reduce the number of routes unless there's only 1, in that case remove the item. If a (rail)road is pillaged, check the entire dictionary to see if any cities got disconnected and if so, remove the item and kill the specialists. When a city is conquered/destroyed, search for all routes involving that city and destroy them.

      So:

      Code:
      ### start of game ###
      routesDict = {}
      CyGame().setScriptData(pickle.dumps(routesDict))
      
      
      ### new route established ###
      def addRoute(fromCity, toCity):
      	routesDict = pickle.loads(CyGame().getScriptData())
      
      	addSpecialists(fromCity, toCity)
      
      	if routesDict.has_key(fromCity):
      		if routesDict[fromCity].has_key(toCity):
      			routesDict[fromCity][toCity] += 1
      		else:
      			routesDict[fromCity] = {toCity: 1}
      	else:
      		routesDict[fromCity] = {toCity: 1}
      
      	CyGame().setScriptData(pickle.dumps(routesDict))
      
      
      ### route is disbanded manually ###
      def disbandRoute(fromCity, toCity):
      	routesDict = pickle.loads(CyGame().getScriptData())
      
      	killOutgoingSpecialists(fromCity, 1)
      	killIncomingSpecialists(toCity, 1)
      
      	if routesDict[fromCity][toCity] > 1:
      		routesDict[fromCity][toCity] -= 1
      	else:
      		del routesDict[fromCity][toCity]
      		if routesDict[fromCity] == {}:		# clean-up
      			del routesDict[fromCity]
      
      	CyGame().setScriptData(pickle.dumps(routesDict))
      
      
      ### (rail)road is pillaged ###
      def roadPillaged():
      	routesDict = pickle.loads(CyGame().getScriptData())
      
      	for fromCity in routesDict:
      		for toCity in routesDict[fromCity]:
      			if not fromCity.isConnectedTo(toCity):
      				iNumRoutes = routesDict[fromCity][toCity]
      				killOutgoingSpecialists(fromCity, iNumRoutes)
      				killIncomingSpecialists(toCity, iNumRoutes)
      				del routesDict[fromCity][toCity]
      		if routesDict[fromCity] == {}:		# clean-up
      			del routesDict[fromCity]
      
      	CyGame().setScriptData(pickle.dumps(routesDict))
      
      
      ### city is destroyed/conquered ###
      def cityConquered(conqueredCity):
      	routesDict = pickle.loads(CyGame().getScriptData())
      
      	for fromCity in routesDict:
      		if fromCity == conqueredCity:
      			for toCity in routesDict[fromCity]:
      				iNumRoutes = routesDict[fromCity][toCity]
      				killIncomingSpecialists(toCity, iNumRoutes)
      			del routesDict[fromCity]
      		else:
      			for toCity in routesDict[fromCity]:
      				if toCity == conqueredCity:
      					iNumRoutes = routesDict[fromCity][toCity]
      					killOutgoingSpecialists(fromCity, iNumRoutes)
      					del routesDict[fromCity][toCity]
      			if routesDict[fromCity] == {}:		# clean-up
      				del routesDict[fromCity]
      
      	CyGame().setScriptData(pickle.dumps(routesDict))
      
      def killIncomingSpecialists(city, iNum):
      	# not defined here
      
      def killOutgoingSpecialists(city, iNum):
      	# not defined here
      
      def addSpecialists(fromCity, toCity):
      	# not defined here
      Personally I think it'd be much nicer if you got rid of the whole caravan thingie though, it'd be much more elegant and less MM if you could set up trade routes through a UI screen that lets you select target and destination city from a list and set the number of routes you want to establish with a spinner. Allows you to show a nice overview of all existing food routes in your empire while you're at it.

      Of course, either way the AI won't be able to deal with any of this, which is a huge balance concern.

      Another change I haven't yet figured out are to make the 'Outgoing Caravan' specialist change to -2 food, -1 commerce with the discovery of refrigeration (I'd assume a refrigerated truck will no longer have the spoilage issues of the original mule and wagon caravan.)
      Either add a national wonder a la Angkor Wat in a player's capial (and make sure it moves with the capital if it's conquered), or define two types of specialists: one pre-Refrigeration and one post-Refrigeration.
      Last edited by Locutus; March 28, 2006, 06:17.
      Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

      Comment


      • #4
        Ijuin: Thanks for the idea, think I may take up that 'cheap workaround' as my strategy. Anyone care to take a stab at a name for this new wonder?

        Locutus: wow.... just.... wow! Thanks for all the help. I just got over my laziness and opened up some XML files for the first time last night, and one thing leads to another and I'm trying frantically to learn python now. I searched a lot of threads for info on storing variables across function calls, but until your reply, couldn't find anything on where to store the information. Hopefully this will take care of most of the remaining work to get a testable mod out there.

        Comment


        • #5
          Sound like a good idea. Keep it up!
          "Dumb people are always blissfully unaware of how dumb they really are."
          Check out my Blog!

          Comment


          • #6
            Update to the caravan mod:

            Caravans specialists are now -3 fpt and 1 to 3 cpt from main city depending on route distance (scaled by world size.) I'm hoping that this will curb the obvious abuse of the system to having a former GP farm start producing caravans during the late game when the ever-increasing GPP required reaches astronomical values.

            More to come:

            I need one of the more proficient modders to point me in the direction of a good way to make a popup screen for managing trade routes in a city as well as how I would go about adding an icon to the city screen and hooking clicks to that region to pop up my new window. I know that this is asking a lot, but I've honestly got no clue where to start in the GUI respect, short of changing unit/GP/promotion icons, etc.

            I'm looking to use this interface to suspend/commence or cancel caravan routes to/from the current city. The suspend idea came about to take care of issues where the origin city can no longer support the caravan (i.e. farm was pillaged, etc.) or the player simply has raised their happy/healthy cap and wants to let the origin city grow before giving their food away. I'm going to force the city to suspend caravan routes systematically if the city will have starvation in the turn, rather than watch cities drop dramatically in size due to an invasion.

            Let me know if anyone has any other ideas/suggestions, as I'm doing this more for practice and to see what can be done than actually to get an idea implemented.

            -Jamison

            Comment


            • #7
              I've attached an image of a city-screen portion with what I'd like to achieve. Just a warning... I did not implement this in the game and as of yet have absolutely no clue how to do so... this is simply playing around in MSPaint with a screenshot of a game to see where I could squeeze things in and make a decent display for this interface. Any feedback/comments extremely welcome.

              -Jamison
              Attached Files

              Comment


              • #8
                Originally posted by JamisonP
                I need one of the more proficient modders to point me in the direction of a good way to make a popup screen for managing trade routes in a city as well as how I would go about adding an icon to the city screen and hooking clicks to that region to pop up my new window. I know that this is asking a lot, but I've honestly got no clue where to start in the GUI respect, short of changing unit/GP/promotion icons, etc.
                The data structure setup was a simple contained little conceptual problem that I worked out in a few minutes, I love doing that sort of stuff so I'll always make time for it if I can. What you're asking here is a bit more complicated and mundane, I don't have time to talk you through step-by-step. But I can give you some pointers.

                To add the button to the existing UI, you'll want to mod Assets/Python/Screens/CvMainInterface.py. What you want is fairly similar to what the Mercenaries Mod does, except the place where you want to add your buttons is different. I'd look at the changes that that mod makes to MainInterface.py and compare that to the placement of the IncreaseSpecialist/DecreaseSpecialist buttons in that same file. You should hopefully be able to figure out how to do it then.

                To add a new screen to set up routes, once again look at the Mercenaries Mod, it adds a completely new screen to hire/fire Mercenaries, the code for that is in Assets/Python/Screens/CvMercenaryManager.py -- that should give you an idea on how to do that. Studying the code other interface screens that do similar things to what you want may also help (all code for interface screens is in Assets/Python/Screens).

                If you run into specific problems I'd be happy to help you if I can, but you're gonna have to do the grunt work yourself (or find someone else willing to do it of course )
                Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                Comment


                • #9
                  Locutus: Exactly what I was looking for, thank you. The whole point of making this mod is so I can get the basics of CivIV python down and start working on rediculous things with it, so I'm not looking for someone to make my mod, just suggestions as to where I can find decent examples so I don't have to reinvent the wheel.... which I already do a few times a week while playing Civ

                  -Jamison

                  Comment


                  • #10
                    Hey, you know, might it be possible to set up this system so that you can do the same thing with hammers as you are doing here with food? I like the idea of being able to pump a few extra hammers into a brand-new city. The commerce cost of the caravan route definitely would cut down on heavy abuse of the system though, but if that is not enough, maybe there can be a cap on the number of caravans that a city can be on the receiving end of?
                    Those who live by the sword...get shot by those who live by the gun.

                    Comment


                    • #11
                      I was thinking the same thing myself... adding an option to move production instead of hammers might make for an interesting addition to this mod. I'm at the point now where I need to finalize design so I can polish up the UI I created in the city screen (thanks for the link to mercenaries mod, Locutus, that helped me find the code I needed.)

                      I'll play around with the hammer/food trade off and see if I can't implement that without too much hassle.

                      Thanks for the suggeestion.

                      -Jamison

                      Comment


                      • #12
                        You can check out Heroes182's Hungry Hungry Cities mod at http://forums.civfanatics.com/showthread.php?t=160675 . I wrote the python for it. Basically it has two units you create that can move to another city and creat a building that gives +2 food. The city the unit came from loses 2 food as long as the building exists. After 20 turns it disappears.

                        Roger Bacon

                        Comment


                        • #13
                          Alright, I've gotten a lot of the wrinkles out of this mod now. One thing I'm attempting to do is have the routes not require super specialists in order to 'move' the food.

                          I was wondering if anyone knows of an entirely 'behind-the-scenes' way to add and remove food in a city such that there isn't a building or specialist causing it. I can add and remove the food through code easily enough, but then the stack bars don't display correct imformation of course. Anyone out there successfully modified the food output of a city based on code and been able to get it to show correctly, or am I stuck with little specialist wagons in the cities?

                          Another idea I just had was to stay with the specialist method, but just remove the code that displays that particular specialist in the screen. Before I attempt that, I'd like to do it the 'right' way though.

                          -Jamison

                          Comment


                          • #14
                            Also, I've got an interface worked into the city screen. Let me know what you think and what looks out of place or cluttered.

                            Changes made were:
                            • Shorten the 'Trade Routes' table slightly
                            • Add in the 'Caravan Routes' table with Incoming and Outgoing
                            • Move the 'Buildings' table down and shorten it
                            • Very slightly shrink the bottom-center UI background
                            • Add a second panel above the bottom-center UI
                            • Relocate the Culture and Nationality bars to the new panel
                            • Add 'Populace:' label to Nationality to make it more informative
                            • Move unit face icons and the 'End Turn' text up just slightly to make room
                            • Added a title label to fill up the bar when not in the city screen.


                            -Jamison
                            Attached Files

                            Comment


                            • #15
                              Another shot, if anyone wondered what the title bar looks like with the city screen closed:
                              Attached Files

                              Comment

                              Working...
                              X