Caesar IV Scenario Scripting

Discussion and help with using the in-game editor
Brian Ferullo
Posts: 12
Joined: Wed Apr 05, 2006 2:54 am
Location: Cambridge, Massachusetts

Caesar IV Scenario Scripting

Postby Brian Ferullo » Mon Oct 16, 2006 4:08 pm

Those of you familiar with building custom scenarios for CotN may have been a bit bewildered by the move to XML and C# scripting for some of the behind-the-scenes aspects of Caesar IV's maps. To help make this transition a little friendlier, I've annotated an example scenario script which covers many of the basic features and functionality of the scripting system. I hope you can use it as a jumping-off point for creating some awesome custom scenarios!

We look forward to playing them :)

Note:
As with a scenario's XML and terrain texture files, the script (.cs) file must share the filename prefix of the scenario itself -- for example, Colonia Agrippina.cs, Colonia Agrippina.xml, and Colonia Agrippina.mp3 all belong to Colonia Agrippina.scn.

(For info about other aspects of scenario creation in C4, check out Kuplo's editor guide thread and couchpotato's editor website!)
You do not have the required permissions to view the files attached to this post.
Last edited by Brian Ferullo on Mon Oct 16, 2006 4:18 pm, edited 1 time in total.

Brian Ferullo
Posts: 12
Joined: Wed Apr 05, 2006 2:54 am
Location: Cambridge, Massachusetts

Postby Brian Ferullo » Mon Oct 16, 2006 4:34 pm

One thing I realize I did not cover in the example script was military request setup. Here's a quick example, taken from the Roma scenario:

Code: Select all

//
// MILITARY REQUEST SETUP
//
sMilitaryRequestInfo requestInfo = new sMilitaryRequestInfo();
MilitaryRequest request;

// Germanian Encroachment
requestInfo.mRequestID = 1; // zero-based index into list of all requests for scenario
requestInfo.mReward = 10; // favor reward for successful completion
requestInfo.mPenalty = 0; // favor penalty for failure
requestInfo.mStartWeek = 156; // week the request fires
requestInfo.mVariance = 8; // +/- starting week
requestInfo.mRecursionWeek = 120; // how often the request repeats
requestInfo.mDeadline = 60; // how many weeks to fulfill
requestInfo.mFirstWarning = 30; // first reminder warning
requestInfo.mSecondWarning = 56; // second reminder warning
requestInfo.mTravelTime = 4; // weeks it takes for player cohorts to reach their destination enemy site
requestInfo.mWorldSiteIndex = 28; // index into the list of world sites on the Empire Level map for the enemy site

request = new MilitaryRequest();
// the cohorts below are the cohorts the player will face at the
// enemy site and determine the player's potential for victory
request.AddCohort(sCohortDbIDs.kGerm_Cav, 2);
request.AddCohort(sCohortDbIDs.kGerm_Hvy, 1);
request.AddMilitaryRequest(requestInfo, game);


This creates a single military request with a 10 Favor reward for completion. This code snippet should go in the same place as the invasion setup (in the OnBeginScenario() function).

Notes:
  • The mRequestID value is a zero-based index in the list of all requests of all types for a given scenario, and controls which message from the XML file is displayed to the player -- for example, if mRequestID=2, the game will show REQUEST_2_* messages when that request fires. So, if you have a scenario with, say, a request for grain and a request for cohorts, the grain request (defined in the Editor) will automatically become request ID 0 and you should set up your military request in scripting to have an ID of 1. A bit confusing, I know.
  • Feel free to check out other scenario scripts for examples and ideas. Argos implements invasions, requests, disasters, and wage changes.
Last edited by Brian Ferullo on Mon Oct 16, 2006 4:48 pm, edited 1 time in total.

Agamemnus
Posts: 2081
Joined: Mon Feb 20, 2006 4:21 am

Postby Agamemnus » Mon Oct 16, 2006 7:04 pm

Where can we find a list of all the possible XML variables/functions?

Will Jennings
Posts: 216
Joined: Fri Apr 07, 2006 9:47 pm
Contact:

Postby Will Jennings » Mon Oct 16, 2006 8:59 pm

Agamemnus wrote:Where can we find a list of all the possible XML variables/functions?


The scenario XML files hold three things:
- The text used in the scenario
- The scenario goals
- For tutorial scenarios, the tutorial messages

Have a look at one of the non-tutorial XMLs for a list of standard strings and their use. That should get you cooking for the moment. The most important strings are:

POPULATION, FAVOR, CULTURE, PROSPERITY, SECURITY: The scenario goals
REQUEST_[n]_TITLE: Corresponds to the Name of an order/request, set in the scenario editor
INVASION_[n]_YEAR, THREE_MONTH, etc: The messages that give advance warning of an invasion


The tutorial XML and .cs files are significantly more complicated, since all of the tutorial messaging is done in scripting.

Kuplo
Posts: 1041
Joined: Wed Sep 01, 2004 10:45 pm
Location: CityBuilderGames.com
Contact:

Postby Kuplo » Tue Oct 17, 2006 1:54 am

Thanks for that. Im quite certain that I wont be able to use it though Im sure there are others that will figure it out with your annotations.

I have one question if you have time to answer it.

In the xml files there is the fields:

Aftermath
History
TIPS

I notice in your example that there is not a </string> after any of those three. Does that mean that they are not usable by user making their own scenarios? Also, what would go in the aftermath area, if it is usable in the xml file.

Thanks

Brian Ferullo
Posts: 12
Joined: Wed Apr 05, 2006 2:54 am
Location: Cambridge, Massachusetts

Postby Brian Ferullo » Tue Oct 17, 2006 1:22 pm

HISTORY, HINTS, and AFTERMATH are indeed legacy strings. Anything you put there will not show up in-game.

Pi-Xerxes
Posts: 158
Joined: Fri Nov 12, 2004 3:48 am
Location: Iowa, USA

Postby Pi-Xerxes » Wed Oct 18, 2006 12:49 am

Thanks for the XML information.

Can anyone tell me if it is possible to rotate the map view from within the editor? To see what it looks like from other angles.

I know how to rotate an object once it is placed down by holding and 'spin' the object before letting go of the left mouse button.

I was making hills and such, but I cannot see the backside without a way to rotate the editor camera view.

Thanks again for any help! :)

Brian Ferullo
Posts: 12
Joined: Wed Apr 05, 2006 2:54 am
Location: Cambridge, Massachusetts

Postby Brian Ferullo » Wed Oct 18, 2006 1:15 pm

Hold the '`' (tilde/backtick) key to rotate the camera with the mouse. It works in-game, as well.

Kuplo
Posts: 1041
Joined: Wed Sep 01, 2004 10:45 pm
Location: CityBuilderGames.com
Contact:

Postby Kuplo » Wed Oct 18, 2006 4:19 pm

Thanks ever so much. That was pretty much driving me almost insane, I thought I had tried every possible key combination on my keyboard to swivel the map around, never thinking it would be a key and mouse combination.

Agamemnus
Posts: 2081
Joined: Mon Feb 20, 2006 4:21 am

Postby Agamemnus » Tue Oct 24, 2006 3:29 am

So,

Upon further inspection, I found the script file "Tools.cs". Verry interesting stuff, BUT not enough... I want to create mercenary forts or something like that...

Must now try to troll through romescriptinterfaces.dll for more info... :eek:

wodinoneeye
Posts: 1442
Joined: Tue Aug 10, 2004 12:10 pm

Postby wodinoneeye » Tue Oct 24, 2006 6:19 am

Agamemnus wrote:So,

Upon further inspection, I found the script file "Tools.cs". Verry interesting stuff, BUT not enough... I want to create mercenary forts or something like that...

Must now try to troll through romescriptinterfaces.dll for more info... :eek:




Those may or may not be the same procedure name/parameters that the script language uses. Kind of half-assed having to try to reverse engineer the functions/attributes/parameters. WHERE are the internal docs that TM used for all the functions???? (They MUST have had some for their scripters, unless they gired ones who also had to be psychics/mindreaders) A few days of someones time (or less) to clean up the incriminating bits and make it available to the editor users.... It doesnt have to be pretty -- it would be 1000X more effcient than working in the dark. D-

Agamemnus
Posts: 2081
Joined: Mon Feb 20, 2006 4:21 am

Postby Agamemnus » Tue Oct 24, 2006 4:03 pm

It is all the same. When I enter an invalid command in the script and the game tries to read it, it comes out as a compiler error. The Microsoft Visual (C#? I forgot...) compiler spits out an error, but before that line you can see the compiler command which links romescriptinterfaces.dll.

Will Jennings
Posts: 216
Joined: Fri Apr 07, 2006 9:47 pm
Contact:

Postby Will Jennings » Tue Oct 24, 2006 4:37 pm

Agamemnus wrote:So,

Upon further inspection, I found the script file "Tools.cs". Verry interesting stuff, BUT not enough... I want to create mercenary forts or something like that...

Must now try to troll through romescriptinterfaces.dll for more info... :eek:


It's probably not possible to do everything you can imagine doing with the scripting system -- for instance, you probably can't use it to introduce an additional UI element to the game, or add a new building type, or an additional mechanic of some sort.

I say "probably" because it's quite likely that very clever people will be able to get the scripting system to do things it wasn't built to do... but all we have done with it are the tasks Brian outlined in his post here, plus triggering tutorial messages. There's no documentation on how to do anything more complicated, because we didn't use the system for anything more complicated.

Best of luck, and I can't wait to play what you come up with!

couchpotato
Posts: 34
Joined: Sat Oct 07, 2006 9:32 pm

Postby couchpotato » Tue Oct 24, 2006 6:02 pm

Tilted Mill Staff: I'm hoping you can help with the Empire setup.

I've found two ways to enter a trading city... neither of them work alone. If I enter New Scenario (city name, location coordinates, etc.) and choose add, the editor will enter that city. But when I choose Activation Screen and enter all the information plus import/export information, it adds a new city with the same name. Neither of these will work alone and both crash the game. What am I doing wrong?

Anaxamenes
Posts: 288
Joined: Sun Oct 22, 2006 4:55 pm
Location: Austin, TX

Postby Anaxamenes » Sat Nov 25, 2006 3:13 am

I've been fiddling with the scripting for a couple weeks and have been able to find many cool and neat commands but there are a few that I have not found in any of the scenario scripts and I was wondering if you could help:

1. To call a Gaulish Lt Inf unit I use 'sInvasionFactions.kGaul' and 'sCohortDbIDs.kGaul_Lt' but I would like to be able to script a Roman civil war scenario and can't find a variable that holds that info like 'sInvasionFactions.kRome' or something, how could I do that? Also, what number corresponds to which direction when spawning a cohort on the map?

2. How would you call 'Jupiter's wrath' (that cool lightning strike)? Is there a command similar to natural event commands, like for earthquakes, I could use (besides thunderstorms that is)? How about benevolences?

3. How do you call the culture, security, favor, and prosperity ratings values? I was also wondering if there was a way to 'force' a rating with code? Ex: If a player bribes a certain enemy invasion force instead of fighting them I could force his favor rating down to zero and have Caesar send his cohorts. Also, is there a boolean value that indicates whether the player bribed the enemy? If not, is there a way to call the value of the player's treasury and personal funds?

4. A question about the editor: When I was modifying the Carthago scenario I changed the location of one of the existing trade routes. How do I modify the path line that goes from the trade city to the players city?

5. Is there a way to delete roads in the editor once they have been placed?

6. Is there a way to force an epidemic outbreak in the city even if the player has perfect health coverage?

Any help you could give would be greatly appreciated.
Last edited by Anaxamenes on Sat Nov 25, 2006 6:09 am, edited 1 time in total.

Hieronymus
Posts: 537
Joined: Fri Dec 08, 2006 9:10 am
Location: Londinium, with the insane parakeets

Postby Hieronymus » Thu Mar 29, 2007 9:01 pm

Here's an updated version of the 'Example Scenario' script which I hope will be useful. I've added a few more notes and other things including:
    the example military request
    the basic code needed to ensure build button controls are set OK on scenario start or load from a saved game
    a function for setting the current game time, current ratings and population on each tick (for use in triggers)


EDIT: Sorry - example file was missing some crucial lines in OnBeginScenario and OnScenarioLoad :o
You do not have the required permissions to view the files attached to this post.
Last edited by Hieronymus on Fri Mar 30, 2007 4:54 pm, edited 1 time in total.
Reason: Changed file version

goonsquad
Posts: 539
Joined: Fri Aug 19, 2005 11:01 am

Postby goonsquad » Fri Mar 30, 2007 10:15 am

Since I design competitive contest scenarios, much of what interests me is associated with closing loopholes in the scripting.

Does anyone know if it is possible for the value of a variable to be displayed inside a message string?

For example the Djedu Revisited scenario has patrician housing enabled when certain ratings goals are met. A variation of this is used in my forthcoming Pink Lake contest. Is it possible to have these ratings (eg You have reached 30 favor and 50 security and now Patrician housing is enabled) appear as part of the message string, but with the numbers being the actual ratings (ie variable) and not just part of a text string.

I'm also looking for a way to detect if a game has been played with alterations to scripting of invasions, particularly making them smalller or altering the buy-off amount. I can tell if an invasion is edited out, or if it is given a buy-off amount where it was designed without one, but I cannot tell if an invasion or buy-off has been reduced in size, from the message log.
Last edited by goonsquad on Fri Mar 30, 2007 10:24 am, edited 1 time in total.

Hieronymus
Posts: 537
Joined: Fri Dec 08, 2006 9:10 am
Location: Londinium, with the insane parakeets

Postby Hieronymus » Fri Mar 30, 2007 12:19 pm

I wish I could give you a positive answer to both, but I can't. :( The only available methods I know of for sending messages involve referencing the message string IDs in the XML file.

And as for invasions... Given that a lot of the code controlling invasions is available in tools.cs, there doesn't seem to be much you can do about this one. For example, I've been able to produce a script to override enemy cohort orders, making them flee from the city soon after they arrive.

In between testing my latest scenario, I'm trying to put together a guide to the available code functions, so if I come across anything useful, I'll let you know.

goonsquad
Posts: 539
Joined: Fri Aug 19, 2005 11:01 am

Postby goonsquad » Sat Mar 31, 2007 8:38 am

The only real workaround for invasions that I can think of is to have several of them timed to start at the same time, and each of the minimum size (one cohort) so it cannot be made any smaller. If it is scripted out altogether this can be detected. This may make military invasions viable for contests.

We're probably going to have to live with the fact that buying off of invasions is open to abuse and just always set the buy off to 0.

Hieronymus
Posts: 537
Joined: Fri Dec 08, 2006 9:10 am
Location: Londinium, with the insane parakeets

Postby Hieronymus » Sat Mar 31, 2007 10:16 am

Just a thought... could you make it a condition of entry that a saved game has to be provided on any invasion arrival? That way you could check both the composition of the invading army and the bribe level.

Incidentally, I tried out the invasion script "cheat" i.e. causing the invaders to flee. I think this should also be detectable as you get an "enemies have left the city" message in the log.


Return to “Editing”

Who is online

Users browsing this forum: No registered users and 1 guest