Jump to content
  • Advertisement

Recommended Posts


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.

Share this post

Link to post
Share on other sites

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.

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:

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

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

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

Edited by Shaarigan

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!