🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

WC3 Trigger Style System

Started by
6 comments, last by Shaarigan 5 years, 5 months ago

If I wanted to a create a WC 3 trigger style event queue inside my ECS-style game engine, how would I go about doing that?

Advertisement

To get better answers, you should explain what "WC3 trigger style" means. I can only guess that WC3 is Warcraft 3, and that your question has something to do with the way it did triggers in its world editor, but that still doesn't mean anything to someone who didn't use the WC3 world editor.

WC3 Triggers assuming you mean the good old days of tinkering arround with custom maps in Warcraft, are just a shiny user friendly style of underlaying JASS code. Those triggers are functions that are called under certain circumstances, for example they hook to the AI event dispatch list and rund whatever is places inside it.

You could see this behavior when converting a normal generated trigger into a custom code trigger. The other way round isn't possible because JASS can't be made into a UI-Friendly Trigger anymore so this is a one way process. More about JASS can be found here.

What you could do in C# to mimic this behavior is to flagg a set of functions you want to use in your UI with certain attributes and build reflection code to get other informations you need.


[Category(Utility)]
static class UtilityFunctions
{
   [Action("Random", Description = "Random Integer from range %min% to %max%")]
   [Parameter("min", Description = "Lower bounds of the range")]
   [Parameter("max", Description = "Upper bounds of the range")]
   Int32 Random(Int32 min, Int32 max)
   { }
  
   [Converter("ToInteger", Description = "Converts %value% into an Integer")]
   Int32 ToInteger(float value)
   { }
}

This will build a category and add depending on your current section (Condition, Action, Event) those methods to the categroy. You can then select Utility as category and Random as action from the dropdown lists. Descriptions are placed inside the attributes and obtained using reflection as same as doing some type checks like the return type or parameter for example. I added %parameterName% in here so you could parse the description and add those blue labels in there that could be set for the values you wish to set. A trigger could so look like this:


[Actions]
Set X to ( Random Integer from range '10' to ( Converts '25.0' into an Integer ) )

At the end you translate all those into IL code and create a DynmaicMethod from them to obtain your trigger function

Yeah but how do I do the events and conditions?

Simply register the DynamicMethod object you obtain at the event delegate instance or have a list with callback functions you add it to. You can convert DynamicMethod into a Action<> or Func<> object.

Conditions could simply be cast to their own IL generated DynamicMethod and just linked as an if clause

Any easier way to do it which is serializable?

There dosen't exist a "ready-to-use" open source solution you could simply embedd into your code unless you make one.

Function pointers aren't serializable anyways. Look at the JASS tutorial I posted above, WC3 Triggers are compiled into JASS Scripts so you have to serialize them by your own in whatever way you choose your data format will be.

The only option you have except IL is an expression tree but this requires significant more managing of your UI structure to be translated into expression tokens thata re linked together and then executed one by one at runtime

This topic is closed to new replies.

Advertisement