[MODCOMP] AIAutoPlay

jdog5000

Revolutionary
Joined
Nov 25, 2003
Messages
2,601
Location
California
AIAutoPlay Description
Version: 2.0
For BTS 3.19 (some older versions available below)
Multiplayer: Yes*
Langauges: English, French, German

Updates for version 2.0

AIAutoPlay is now multiplayer compatible (thanks Jeckel!) with one asterisk: it will apply to all players, not just the one who activates it. It is technically also savegame compatible with plain BTS if you can figure out how to disarm the check for "This save requires ___, do you want to load it?".

How to use

This component is a tool, you decide when you want to activate it and for how long. Press Ctrl-Shift-X to open the AIAutoPlay Chooser window, select a number of turns to auto play and select Full Automation from the drop down menu (or no automation). There is a new feature to have the AI only move your units. At the start of your turn, change whatever you want or move a couple units, then press Ctrl-Shift-M to have the AI do the rest of that turn. You can also cancel automation by pressing Ctrl-Shift-X again, but only when there are no popups open. To help with that, there is a config option to block some standard game popups.

In addition, there is a config option that will fortify all units fortified by the AI at the end of automation. Without this all units start active, although refortified units will not lose their defense percentage.

Potential uses

Great for debugging or watching the behavior of the AI, as it shows you only what the AI can see. Also, if you want to skip certain sections of the game, or you're so close to winning but not quite there, let the AI play it for you! With many civs in the late game, auto play will still take a while but you won't have to do anything ... it will basically take (# of turns)*(in between turn lag + a little bit) to go through the turns. As of version 2.0, AIAutoPlay will automatically stop the game at the end so you can see all the end of game screens.

Notes on this version

AIAutoPlay was originally developed to ease testing in my Revolution Mod. Version 2.0 will be the last stand-alone version as it is feature complete. It has been setup to ease issues with merging with other mods to enable modders to test out their creations.

How to merge

Check out the updated merge guide in the download.

Download link

AIAutoPlay for BTS 3.19 by Tholish


AIAutoPlay for BTS 3.17


AIAutoPlay for Warlords 2.08
AIAutoPlay for Vanilla 1.61
 
For the Warlords version: Firaxis exposed a lot of the functionality to Python, so the only SDK changes are to allow autoplay to work without killing off your civ (!). Basically, the lines that kill you civ are commented out, and a bit is set that causes CvPlayer.isHuman() to return false during automation.

For the Vanilla version: This version uses the SDK changes from my Revolution Modpack. See that thread for the SDK files. There are changes other than those that enable the autoplay features, but they will not have any gameplay effects unless you call the new functions. So, if you have a python mod and just add this AIAutoPlay to test things out, there will not be any other effects on your game.

In the future, I will try to get the AIAutoPlay functions added to the community SDK project, and then use that dll here.
 
Thank you very much for this mod! I think it will help me a lot in testing my modpack.

Great job! :goodjob: And why doesn't Firaxis think of these things? :crazyeye:
 
Amra said:
Thank you very much for this mod! I think it will help me a lot in testing my modpack.

Great job! :goodjob: And why doesn't Firaxis think of these things? :crazyeye:
That's what I'm using this mod for, too. I extracted it from jdog5000's Revolution mod.
 
Amra said:
Thank you very much for this mod! I think it will help me a lot in testing my modpack.

Great job! :goodjob: And why doesn't Firaxis think of these things? :crazyeye:
You're welcome :) Most of the SDK functionality was already written by Firaxis, presumably for their own testing ... what is by default exposed to Python versus not seems in some places quite arbitrary to me, but I guess we should instead thank Firaxis for making the game so open and moddable.
 
I'm not python literate, so bear with me.

As per instructions, the core dll has been placed in custom assets, and AIAutoPlay.py in python folder, in the mod folder I'm trying to institute the component in. That was no problem.

In the python section, there are now two files, CVEventManager (originally there) and AIAutoPlay (added). I then copied DrElemer's files into the mod folder... this included CVCustomEventManager and a couple of other files that came with it, into the python folder, and copied a subfolder, Entry Points. I then editted the CVCustomEventManager by adding AIAutoPlay to this section:

# --> INSERT EVENT HANDLER INITIALIZATION HERE <--
AIAutoPlay.AIAutoPlay(self)
Civ4lerts.Civ4lerts(self)

It didn't work when I started up my mod.

A couple of things could have gone wrong.

First, did I modifiy the right python file... should I have changed the CVEventManager that was originally with the mod? Rather than the one that came with DR.Giggles.

Did I insert AIAutoPlay in the right part of the CVCustomEventsManager?

Please give some advice... I know nothing about python, but just want to add the one line of code to the proper file in the proper place.

Sorry for the inconvenience.
 
Craig_Sutter said:
Did I insert AIAutoPlay in the right part of the CVCustomEventsManager?
Yes, I think the issue may be you also need to import the AIAutoPlay module ... basically, you have to declare up at the top of your Python file what other modules you'll be using before you can use them. So, right under the line:

import CvEventManager

you should add:

import AIAutoPlay

Let me know if that solves it. The other issue is I'm not sure if you've placed the dll in the right place. The dll needs to be placed in (your mod name)\Assets\, which is the folder your Python folder is in. It may work to place the dll in My Games\Sid's Civ4\Custom Assets\, but I haven't tried it and I believe it would then use this dll all the time (probably not your intention). Hopefully these will resolve your issues.

Craig_Sutter said:
Sorry for the inconvenience.
No problem at all ... good luck! :)

(Edited first post to include this info)
 
Thanks for the advice.

I checked that all the files were where they ought to be, and added the import AIAutoPlay as instructed. It still didn't work.

However, instead of all the above, I copied the contents of AIAutoPlay folder to my mod folder. Since I didn't have CVCustomEventManager in the first place, the one that came with AIAutoPlay served its function. Because the mod I used is fairly basic, merging this way was relatively easy.

Anyhow, it works.

Thanks for the help, again.
 
Craig_Sutter said:
Thanks for the advice.

I checked that all the files were where they ought to be, and added the import AIAutoPlay as instructed. It still didn't work.

However, instead of all the above, I copied the contents of AIAutoPlay folder to my mod folder. Since I didn't have CVCustomEventManager in the first place, the one that came with AIAutoPlay served its function. Because the mod I used is fairly basic, merging this way was relatively easy.

Anyhow, it works.

Thanks for the help, again.
Great, glad it's working for you.
 
I like it! Alot better than the way I was doing it before. Have you considered making an option to stop popups from opening (city naming and suchlike)?
 
Isn't there an option in civilization4.ini to enable autoplay in vanilla Civ4?
 
MooManof_ said:
Isn't there an option in civilization4.ini to enable autoplay in vanilla Civ4?
There is an Autorun option in the civilization4.ini, but I believe the mechanics behind it are tied up in the exe part of the program. There does not seem to be a way to set autorun from the SDK code they've opened up and the turn limit setting in the ini wasn't working for me.

AIAutoPlay builds off another piece of machinery Firaxis wrote ... in Vanilla civ with the chipotle cheat code on, you can set AIAutoPlay (do a forum search for chipotle). This wasn't very convienent and also killed off your civ when activated. This implementation uses that machinery, but doesn't expose the whole globe or kill off your civ (!), so I think its much more useful for debugging.

These two Firaxis elements, Autorun and AIAutoPlay, are used in exactly the same places in the SDK code ...

Anyway, I find this component far more useful than those, as you can easily set it for a while, then check the results, set it again, etc without anyone having to die :p
 
The Great Apple said:
I like it! Alot better than the way I was doing it before. Have you considered making an option to stop popups from opening (city naming and suchlike)?
Yeah, I've found those pretty annoying too ... I'll look into it for the next version. Good idea.
 
Just want to let you know how useful a tool this is. Excellent work. Well done:goodjob: .

Also, is it hard to implement the console commands in a mod. For example, I'd like a python script that runs map.generateBonuses before a scenario is started, so that random resources are generated each time a scenario is played. AIAutoplay uses a console command from WBuilder... is this easy to do. In you Autoplay file, for instance, could I just add the console command for map.generateBonuses somewhere similar to where you call AIAutoPlay?

Good mod component, anyhow.
 
Is anyone having lockups with this mod? Granted, I'm running it like 200 turns at a time, which was cautioned against in the readme. I set it to run adn then come back and it has locked up. It doesn't seem to happen when I only run for 20-50 turns at a time.

Roger Bacon
 
RogerBacon said:
Is anyone having lockups with this mod? Granted, I'm running it like 200 turns at a time, which was cautioned against in the readme. I set it to run adn then come back and it has locked up. It doesn't seem to happen when I only run for 20-50 turns at a time.

Roger Bacon
When you say locked up, do you mean completely locked and nothing responds? Does it reach the end turn it should or get stuck part way through?

I've never had it lock up completely ... occasionally, as cautioned in the readme, after 200 turns when control is returned to me no unit is selected and I can't find a way to select a unit, but I can save, quit and reload and things return to normal. I don't know why this happens, I thought it might be that the unit you had selected when you entered autoplay died, but that doesn't seem to be the case.

The only other thing I've seen, is that if some other piece of my Python code produces an error or 50 during automation, strange things can happen. Like being unable to scroll on the map (but you can navigate with the minimap) ... again save, quit and reload resets things (can't really fault AIAutoPlay for these issues :p )

Are you experiencing something different?
 
Craig_Sutter said:
Just want to let you know how useful a tool this is. Excellent work. Well done:goodjob: .

Also, is it hard to implement the console commands in a mod. For example, I'd like a python script that runs map.generateBonuses before a scenario is started, so that random resources are generated each time a scenario is played. AIAutoplay uses a console command from WBuilder... is this easy to do. In you Autoplay file, for instance, could I just add the console command for map.generateBonuses somewhere similar to where you call AIAutoPlay?

Good mod component, anyhow.
I'm not sure I understand the terminology you're using, specifically "AIAutoplay uses a console command from WBuilder" ... AIAutoPlay runs using keyboard commands, then using a Popup. There's nothing particularly tied into the WorldBuilder ... :confused:

Yes, it would be easy to add another keyboard command ... I'd recommend doing it in your own Python file and onKbdEvent function. Basically, you'd just add another if() statement with a different key combo, then call your map function or whatever. However, if you want something to run at the beginning of the game only, you would want to hook into the 'GameStart' event ... check out my BarbarianCiv mod code for one example of how to do that (see sig). With this, you could have a function called at the beginning of the game to redistribute things on the map and not have to press any keys. Just a thought ...

Glad you like it! :cool:
 
Top Bottom