Announcement

Collapse
No announcement yet.

In-Game Change of leader heads?

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

  • In-Game Change of leader heads?

    Hello!

    I'd like start to create Civ4-scenarios (like in the good old days of Civ2). Taking the examples provided by the "GreekWorld" mod I already created some custom 'static' leaderheads, but something I would really like to do is change the AI leader heads during the game. For example this could be used to simulate different culture levels or change of rulers or the like.

    Does anyone know how that can be acomplished?

    I'm already quite sure that it is possible to make that work (given the enormous possibilities of Python), but perhaps there exists an especially elegant way to do it ...

    Thanks a lot!
    Cheers!

  • #2
    All rights, appears as if there is no elegant way known ...

    But I have found a very simple and extremely unelegant way, perhaps someone can give me advice how to implement that.
    All one needs to do is exchange the "leaderhead.dds" file one defined for the respective leader (should probably work with .nif or .kf files as well, but since I don't even know these formats I only tried "static" heads up to now).

    So what one has to create is a Python script which, when certain conditions are met (diplomatic relation, tech researched ...) copies a "Leaderhead_B.dds" to "Leadhead.dds" and if the conditions are not met it does the same for "Leaderhead_A.dds".
    Can Python give direct commands to Windows (say a command line "copy x y")?
    Or execute a batch file?
    Or do I have to write an executable which does what I want (I have found some references to how to start executables, but did not try it yet).

    Please be patient if these are dumb noobie-questions, i'm new to the Python-trade.

    Cheers!

    Comment


    • #3
      Originally posted by Grishnach

      Can Python give direct commands to Windows (say a command line "copy x y")?
      Or execute a batch file?
      Or do I have to write an executable which does what I want (I have found some references to how to start executables, but did not try it yet).

      Please be patient if these are dumb noobie-questions, i'm new to the Python-trade.
      Don't know python, but I know how to Google!

      Running shell commands from Python - Programming in Python and Ruby - Programming in the Python and Ruby languages ; forum discussion

      Check out my Atlas Map Generator

      Generate, preview and play Civ IV maps of any size with the alternative Map Generator

      Comment


      • #4
        Ok, should have put that otherwise:

        Does Civ support the Python libraries which enable external file access and the like?

        I tried to import shutils and use the 'shutils.copy(src, dest)' command, but there is always an error with that.
        Did anyone try something like that already and made it work?

        Cheers!


        EDIT:
        Ok, found a small error and a different command I tried now actually works!

        ###########
        import os

        def onLoadGame(self, argsList):
        cmd=r'copy c:\Misc.txt c:\Misc2.txt'
        os.system(cmd)
        ############

        copies c:\Misc.txt to c:\Misc2.txt when a game is loaded.
        Only problem is that civ minimizes, when this command is executed ...
        Hope to find a solution to that.
        Last edited by Grishnach; December 15, 2005, 13:36.

        Comment


        • #5
          Allright, final update:

          shutils.copy works, I made some mistakes with the string definitions.

          ################
          import shutils

          --- arbitrary function (or whatever that is called in Python)---
          file1=r'''filename1'''
          file2=r'''filename2'''
          shutil.copy(file1,file2)

          ################

          This command also works quietly in the background without bothersome minimizing. The triple quotes are necessary if a ' should appear in your string (like in "\Sid Meier's Civilization 4\").
          The only problem is, that blanks are appearently not allowed within the filename. Means that I will have to reinstall Civ unless there is a way around that.

          Comment


          • #6
            There's probably an escape character for a space?

            Check out my Atlas Map Generator

            Generate, preview and play Civ IV maps of any size with the alternative Map Generator

            Comment


            • #7
              edit: nvm

              Comment


              • #8
                Originally posted by Grishnach
                So what one has to create is a Python script which, when certain conditions are met (diplomatic relation, tech researched ...) copies a "Leaderhead_B.dds" to "Leadhead.dds" and if the conditions are not met it does the same for "Leaderhead_A.dds".
                Uh. Not sure if that will work - Civ4 possibly reads the file and stores the information in memory, not re-reading the file later. I'm at least 80% sure that's the case, because disk I/O is slow and reading the file during gameplay would have a negative impact on performance.

                You should try it out ASAP. If/when it turns out that the file isn't re-read, try finding out if the game exposes the information to the scripting engine somehow...
                -=- 4ntifa -=-

                Comment

                Working...
                X