[SDK/PY MODCMP] GerikSpells Framework

Gerikes

User of Run-on Sentences.
Joined
Jul 26, 2005
Messages
1,753
Location
Massachusetts
GerikSpells Framework
An Action-Creation Framework for Civ4

Current Status: Beta
Latest version: v0.54 August 23, 2006
Wiki: http://gerikspells.pbwiki.com
Known to work with Civilization 4 Vanilla version 1.61 (get the patch here)



News:

August 22, 2005: After merging with Civcraft, made a bunch of tweaks and fixes I found while using the code there.

Spoiler Old news :

August 18, 2005: Bunch of bug fixes, including problems with incorrectly calculating ranged plots in GerikSpellsUtils. Also changed GSImmediate to become GSImmediateNoTarget, along with creating a GSImmediatePlotTarget. This allows for GSImmediatePlotTarget to be used with GSMissionTargetCounter, since that policy expects to get a plot policy as it's target (and GSImmediate will only give a NoTarget policy). Finally, chaned how the stage list is made. Prior, it was created in the constructor, but this meant that creating different targetting stages based on the ctrl, shift and alt keys (as defined in GSHandler.start()) couldn't change anything. Now, create the stage by overriding the function createTargettingStageList(bAlt, bShift and bCtrl).

August 15, 2006: Beta, baby! I've decided to wait on the AI implementation for now while I view my options and pour more work into perhaps creating more targetting info policies and updating the documentation.

August 14, 2006: Fixed the patrol spell from crashing when moving to a place that the unit can't move to. Fixed the cyber terrorism missions to actually be affected by range. Whoops :P

August 13, 2006: Hurray for small updates! I finally put a stamp of approval on how I change interface modes and cursors, and now the multi-cursor feature is functioning. To see an example, check out the new and improved Patrol spell. It has a cursor that points one way to show the user that they are picking the first plot, and another feature that turns around to show that they are now picking the second plot. How deviously delightful!

Unfortunately, because I was testing the Patrol spell, I found that it has a bug in it when it comes to trying to move to plots it can't move to. It will cause crashes. I'll fix this in the next version, and also work on a better scheme for help texts. I can smell the AI just around the corner!

August 11, 2006: v0.41 released. Yup, I'm back to incrementing by a hundreth. I've implemented two new spells, using two new policies. I've renamed that long "GSPushMissionNoTarget" to just "GSMission", since basically the only other alternative (besides the base) is "GSMissionNoTarget". Knowing this, I've created two policies, GSMissionTargetCounter and GSMissionCasterCounter. These two policies allow for "counters" to be placed on either the target of the spell or the caster of the spell. These counters will then be incremented every turn, and when they reach a predefined amount, the user's function will be called.

For examples, I've put up two Cyber Terrorism spells (since as I am a self-defined supporter of the hacker culture, I'm hard pressed to allow the term "hacker" or "hack" be used in a negative way :P) that use these policies. Check them out below to see what they do.

August 8, 2006: v0.40 released. First off, I've implemented a version of "Plant Forest". Note that you need to have TECH_BIOLOGY to use it. I've also changed Sacrificial Oath to use a new graphics policy, GSPopup, as an alternative to GSPieMenu. I felt that people would probably want choices as to the target-selection process to use, since not everyone is going to be wild and crazy about my Pie-menu system. I also fixed a few bugs, and started working on implementing help text.

August 4, 2006: v0.35 released. The range system is finished. Included into every PlotInfo (whether it be single or square, or, in the future, other multi-target policies) there are callbacks and checks for range and visibility (fog of war-wise). The total range is created using a callback, but I have made two utility functions in GerikSpellsUtils that will help aid that function. Also fixed that annoying bug where pressing escape at the pie-menu will cause the main menu to appear. Finally, did some work finallizing a "Patrol" spell. I still don't like how it works, so I'm going to continue trying to come up with at least a better example for a spell that takes multiple turns.

July 31, 2006: v0.3 released today. I'm very happy with the changes made, and I don't believe I will be doing any more complete restructering anytime soon. The big change is how the "stages" of a targetting spell is done. Prior, there was specific, built-in policy for each "ordering" of target-retrieving. For example, the "PlotSelect" policy was just getting "Plot". The "PieMenu" select policy was getting "Plot, then PieMenu". This meant for every order a new policy would have to be created. The new policy, "GSTargetting", will replace all those. It can take any list and do the targetting. For example, I could make a "Plot" or "Plot->Pie Menu" like normal, or just as easily change it around and take "Plot->Plot->Pie Menu" or "PieMenu->Plot->PieMenu" or "Plot->Plot->Plot->Plot->Plot->Plot->Plot->PieMenu->Bacon, Eggs and Spam" (ok, not really the last one, but yes on many plots). Also, I've fooled around with the graphics, showing some easy ways to create neat effects and plot textures.

July 28, 2006: A completely reconstructured code base for GerikSpells is pretty much finished. It's not very well tested, but hey, that's what alpha's all about. I experimented a bit with plot coloring, but feel that do to the limited amount of plot textures you'd be able to have, that an unlimited amount of effects would be more scalable.Unfortunately, modifying effects is a bit tougher. Hopefully I can find someone on the forums that knows a thing or two. I'll still persue the plot graphics, however, for all it's worth. Finally, I've updated the screenies showing the unit info panel.

July 26, 2006: After losing tons of time trying to "fit in" code to the current structure, I've decided to go back to the drawing board for a few things. Basically, I'm completely changing how the Target and PieMenuGraphics policies work, and adding a third policy (Stages) to fill the gap. These are going to work COMPLETELY different, so I'd recommend anyone trying out this mod not to get too comfortable. Hey, I warned you it was alpha.

July 24, 2006: Today I released the alpha version of GerikSpells. I hope there isn't any other exciting events that might overshadow this... :mischief:



------------------------------------------------------------------------------------------------------------------------

The code is in it's VERY infant stages. The testing has been completely in single player mode. Asides from that, the AI, Civilopedia, and much of the popup info-pane implementation is not complete. I'm also going to add more pre-built policies. However, you should get a good idea using what's in this package of what you can do with GerikSpells.

What is the GerikSpells Framework?

The GerikSpells Framework is a tool that allows mod makers to create actions in a very quick and easy manner for the game Sid Meier's Civilization 4. The framework is built around a very customizable structure that allows for users to create very powerful actions, from simple "click and your done" to full-fledged unit targetting, while trying to make the modder go through as little code as possible by encapsulating most of the work into pre-defined class "Policies". This, all while allowing for the spells to be Multiplayer-ready, AI-moddable, and easy-to-use.

It's also good to note that although I refer to actions as "spells", that this does not mean that all actions created with this framework must be of the Fantasy-style spells. Indeed, the framework can be used to create actions for fantasy-style mods, sci-fi style mods, even simple Civ4 tweaks. However, as "spells" would be the obvious use of such a package, I decided to use that for a name. In fact, when finished, a modified version of this framework will be the backbone of the action system in Civcraft: SC, most likely controlling everything from special abilities of units to burrowing to even building buildings.

For more information on GerikSpells, check out the "About" page at the Official Wiki.


What can the Framework do?

I've whipped together a few "spells". I've given the end Python code into a spoiler to show you exactly what you would have to code to make similar spells (note that options such as AI and some more advanced plot highlighting is still to be made, but at least you get a fair idea of what's going on). The screenshots aren't very much graphically, mostly the code is the point of this presentation. Check them out in the next post, or download the mod and see them for yourself!


Thanks and shout outs:

Locutus: (Creator of the Python API I reference at least 20 times an hour.)
Stone-D (Creator of SdToolkit)
Teg Navanis (Modification to SdToolkit called SdToolkitAdvanced)
Kael (Writer of the tutorial "Adding new XML attributes" which got me addicted to the SDK)
jdog5000 (Writer of the "Exposing new functions to Python" tutorial, another necessity to get me started quickly in modding the SDK).
Rabbit, White and ArenaNet (For some of the Fantasy buttons used as part of the examples).
 
Example Spells/Actions

(Note: Just to make things easier on me, I've decided to just put links to the spells files in my SVN repository, just so I wouldn't have to copy and paste all the code but instead change the link)

"Haste" Spell:
The "Haste" ability is just an action that any unit can use so long as that unit has more than 1/3 of it's life remaining. At any time during a turn, a unit can use it's "haste" ability to fully rejuvenate it's movement points at a cost of losing 1/3 it's total HP.

Source



"Burn Land" Spell
The "Burn Land" spell selects one plot of land for a Warrior unit, and turns it into Desert.

Burn Land Targetting
Burn Land Results

Source



Sacrificial Oath
What would be a spell demo without the insta-death? I've changed it a bit, this time the unit that casts the spell dies as well. Also, some "explosions" in both the plots of the caster and target. Finally, this newest version shows off the new GSPopup graphics policy, which allows for "traditional" civ-style popups to replace the "non-traditional" pie-menu. Booooring.


Sacrifical Oath Plot Targetting
Sacrificial Oath Targetting (Pie-Menu)
Sacrificial Oath Targetting (Popup)
Sacrifical Oath Results

Source



Pie-Menu Improvements (aka Remote Improvements)

My personal favorite. Use a worker to select a plot, and the pie menu will show all the improvements that can be built there. Selecting one will cause the worker to move to the plot and start building.

Pie-Menu Improvements

Source

Earthquake

In an attempt to show how to do the plot targetting with graphics and the ability to trigger affects, I went through all the affects and tried to find a good one. This one worked well, so I made a spell based around it. It damages all units within a targetted 3x3 plot range for 20% damage. Maybe later I'll do something about having buildings a % to be destroyed.

Earthquake also shows off the abilities to allow the GerikSpells system to automatically calculate range and visibility for you. It creates a callback for creating the list of plots that are considered within "range". Because the most common would probably be step-distance and plot-distance, I've included those into the GerikSpellsUtils so that the function need only be a single line of code. This will also allow for user-created ranges, as well as allow for future algorithms (such as "walking distance" range) to be implemented very easily in the future.

Earthquake (Ranged Plot Targetting)
Earthquake (Results)

Source

Patrol

A spell where a user selects two plots. After selecting the two, the unit selected will travel to the first plot, then travel back and forth between the two plots in a typical RTS-style "Patrol" feature. This spell also features the ability to switch cursors. The user will have a different cursor for each plot. After selecting the first plot, it will change to another.

Source

Plant Forest
As well as showing off other ways to restrict your spell-casting (this one has a prerequired tech) and some in-progress textual improvements, Plant Forest shows off the new GSBuild policy, which allows for making new spells that work like builds with minimum fuss. Usefull for creating build-like abilities.

Plant Forest

Source


Cyber Terrorism
Cyber Terrorism is actually two seperate spells, but put in the same file.

The first is "Bank Breach", which will cause a unit to target a foreign city and, after five turns, steal money from that player. The spell works as a ranged spell. This shows an example of using the GSMissionCasterCounter, which puts a "counter" on the caster and once it reaches five will start the "transfer".

The second is "Sabotage Engineering Data". This uses the GSMissionTargetCounter, which means a counter will be put on the target city (actually, it's put on the target city's plot, but whatever). Once it reaches 15, then it loses a random amount of hammers. The main difference between this and the first is that multiple units can contribue to the process, so if three units all target the same city (even if the units are located at different plots), then it will only take 5 turns rather than the 15 it would take for one unit to do it.

Also note that Bank Breach returns "True" for it's continueSpellResultsOnTarget function. This means that once the unit finishes and the spell's effects are done, the unit will automatically repeat it's mission. In the Sabotage Data, returning "False" will make the unit end it's mission.

Bank Breach Results
Sabotage Engineering Data Results

Source (Both spells are included into one file).


Other Screenshots
Plot-targetting on multiple plots.
 
(For v0.44):
  1. Fix bug in Patrol spell.

(For v0.45):
  1. Fix Pie-menu targets being too transparent.

(For v0.45-v0.5)
  1. AI scheme.

(For v0.5):

  • Release Beta

---

(For v0.55):

  1. Animated pie-menu policy.

---

Far future:
POSSIBLE Warlords compatability.
Release as final : o)
 
I like the look of your targeting system (hell, the worker pie-thingy would even fit greatly into the vanilla game), but is there a way to get more info about the selectable units in the 'instagib'-like targeting system? A health bar and/or the promotions would be great to decide which of the spearmen to kill off :)

Some pages of the Wiki are still password-protected, namely the tutorials, the FAQ, the Introduction, and most of the references.
 
Teg_Navanis said:
I like the look of your targeting system (hell, the worker pie-thingy would even fit greatly into the vanilla game), but is there a way to get more info about the selectable units in the 'instagib'-like targeting system? A health bar and/or the promotions would be great to decide which of the spearmen to kill off :)

Adding healthbars is already implemented, I just didn't use it in any of the screenies. It would require the code that says "return []" in the getBars funciton to say "return [(pTarget.currHitPoints(), pTarget.maxHitPoints(), "COLOR_GREEN")]", or something to that effect.

Also, at this point it should be capable to place any information you want into the info pane when the target is being hovered over. I just put the name only because I was lazy. However, if someone wanted, they could write a moderately more complex info scheme just by modifying the string that is returned by the "getTargetInfo" function.

Some pages of the Wiki are still password-protected, namely the tutorials, the FAQ, the Introduction, and most of the references.

They're not password protected, I just haven't done them yet :lol:
 
Interesting stuff, the Pie selection system as you call it looks like it could be usefull but what happens when their are a dozen or more choices do they get all jumbled up? SimCutie has a button plug-in system in the CCP which might be usefull to you (I dont see how the Spells are "cast" right now, buttons are definatly the way to go and I belive the connection between button and spell should be easy to make.

As always I would like to see this in the CCP when its fully developed but I can see already this would be a major task as you have 20+ altered SDK files.
 
Impaler[WrG] said:
Interesting stuff, the Pie selection system as you call it looks like it could be usefull but what happens when their are a dozen or more choices do they get all jumbled up? SimCutie has a button plug-in system in the CCP which might be usefull to you (I dont see how the Spells are "cast" right now, buttons are definatly the way to go and I belive the connection between button and spell should be easy to make.

As always I would like to see this in the CCP when its fully developed but I can see already this would be a major task as you have 20+ altered SDK files.

None of the screens show it, but it uses a page system so that you can seperate the targets into multiple "pages" and flip through the pages using a button located in the center of the ring. Press the button and the next "page" of targets show on the screen, replacing the old page (currently the size if just enough for around 10 targets to fit peacefully, but you can always enlargen the distance from the center the buttons go, make the buttons smaller, or both to make it do exactly what you want).
 
What about actions like "plant forests" or "make water to land"?
Will this be possible?
 
Perhaps its just me but that sounds like it will be a bit hard to use not so much because its inherently complex of difficult (I remember playing Secret of Mana which had a nice muli-ring based organizing system) but because its so radicaly different then the games current UI style, why not simpley generate a popup list like that created when loading a transport that would provide ample information as well and be a bit more accessable.
 
@ Caesium: If the results of the spell can be done in python, then an appropriate spell should be able to be made. I see no reason why there can't be a "Plant forest", "Terraform", or "Civ3-style bombardment" when the package gets more stable.

@ Impaler: Probably because "radically different" has always been my style. :P

But because of the way that the classes are structured, it shouldn't be hard to be able to replace the pie-menu interface with a simple Popup interface like you say. I might even take the time to write a policy class that deals just with popup interfaces.

Definitely the biggest disadvantage of the Pie-menu is that the "facts" may not be directly in front of you, so for things that have lots of "stuff" to go with them, such as units, it may not be the best interface. However, I still think it's a reasonable alternative. One of my biggest pet peeves of the Civ4 UI is that sometimes you'll actually have to scroll in the window to pick the action button (if like me you have to play the game on the lowest resolution). I wouldn't memorize a bunch of different hotkeys, but I would memorize one so that all the improvements I could build are suddenly "surrounding" my mouse. Just like that you've got rid of a good 8 or so buttons on the bottom of the screen.

Or maybe I've just been playing too much Neverwinter Nights :P
 
ocedius said:
simply amazing. I am downloading these right now and will tweak them. Hopefully with some beta testing, can get this to work with warlords. :goodjob:

Edit: The patrol has 4 coordinates in it. Could this be changed to allow for a 6 or 8 so patrolling would be no longer be a linear function.

The main problem is this: in order any mission to work, you have to be able to store all the data needed in the missions into three integer variables (these are the iData1, iData2, iData3 variables you see everywhere). These variables are stored into a struct internally and are also sent over the wire in multiplayer games. Unfortunately, that severly limits some things. Since I want to make it multiplayer compatible, and also allow spells to be queued, it's important to find ways that you can fit the data into this three-integer data structure. For example, running a spell on a unit or one plot is easy, because each can be stored in two variables (X, Y for the plot or Owner/ID for the unit). Having a square of plots is also possible because each player on a multiplayer computer knows how big the square is, so it's only important to have the center square.

When you start talking about multiple targets like a system of 6 waypoints would be, then you run into problems. Currently, I have a function that will split the 22-bit iData3 integer variable into two 11-bit integer variables, allowing me to store both the X and Y of the second plot coordinate into that last iData3 variable. Although I could possibly do this for iData1 and iData2, it would just be delaying the inevitable.

Instead, I'm working on a solution where you would press patrol, then shift and right-click. Then, the patrol mission would be sent, then a few move missions, then another patrol mission to say you're done. On each computer in a multiplayer game, the group would suddenly have a group of missions, starting and ending with a patrol mission. It would go from top to bottom finding the coordinates of each mission, and load them into a data structure kept on the units that are going to be patrolling.

The other solution is to use the event system to pass the actual data structures (a list of coordinates). However, I'm not so sure about the timing between mission pushing messages and event messages in multiplayer, so I'd rather stick to mission pushing.

Edit: Oh, and BTW, I'm sure I can get it to work in Warlords... I just need to buy it and find where I need to put my changes. Luckily, I just had a birthday :gold: :banana: :gold:
 
ocedius said:
15 days with warlords and you still haven't completed the spells framework. Bah!

:p

Who said I even have Warlords? I just said that I have money :P

Besides, there hasn't been a big uprising for this to get done, so I'm concentrating my time on Civcraft, which should run on both Warlords and Vanilla anyway so I don't really have a reason to rush into the conversion.

Sooner or later I'll want a break of Civcraft and I'll get back to it. But right now, the version I have is doing exactly what I've been wanting it to do for Civcraft.

Sorry :blush:
 
Gerikes said:
Who said I even have Warlords? I just said that I have money :p

Besides, there hasn't been a big uprising for this to get done, so I'm concentrating my time on Civcraft, which should run on both Warlords and Vanilla anyway so I don't really have a reason to rush into the conversion.

Sooner or later I'll want a break of Civcraft and I'll get back to it. But right now, the version I have is doing exactly what I've been wanting it to do for Civcraft.

Sorry :blush:

So you ARE working on spells after all. :lol: Maybe I should have added more :p and the occasional :goodjob: to my post. I'll wait patiently. 'sides, I can always try and canabalize civcraft 0.32 :lol:
 
Back
Top Bottom