Results 1 to 4 of 4

Thread: How to use static dictionary (in code since 4.56) to communication among submissions

  1. #1
    Ace
    Join Date
    May 2015
    Location
    Kansas City, Missouri area
    Posts
    515
    Post Thanks / Like
    Total Downloaded
    130.02 MB

    How to use static dictionary (in code since 4.56) to communication among submissions

    I know a static dictionary was added to the Mission object in CloD 4.56, to allow various submission .cs files to communicate & share data and such-like.

    However, I've never looked up the details. Does anyone know them, or have a bit of sample code?

    One second of looking, looks like AMission.DataDictionary

    public static System.Collections.Generic.Dictionary<string, object> DataDictionary
    Member of maddox.game.AMission
    Some of us can probably figure it out from there, but others might get a lot of mileage out of a leg up.

    (Paging ATAG_Oskar?)
    Last edited by TWC_Flug; Jun-16-2021 at 01:19.
    System: Microsoft Windows 10 Pro 64 bit, 10.0.18362 N/A Build 18362, 20,437 MB |
    ASUS GeForce GTX 1060 3GB | Intel Core i5-2500 Quad-Core Processor 3.3 GHz 6 MB Cache LGA 1155 | Intel DB65AL motherboard | ARCTIC Freezer i11 CPU Cooler | SVGA 500 watt power supply | Microsoft Sidewinder 2 Force Feedback joystick

  2. Likes TWC_Fatal_Error liked this post
  3. #2
    Team Fusion Artist's Avatar
    Join Date
    Mar 2010
    Posts
    2,866
    Post Thanks / Like
    Total Downloaded
    319.97 MB

    Re: How to use static dictionary (in code since 4.56) to communication among submissi

    There's another method since 5.0 to allow communication between the base and it's sub-missions

    Code:
    /// SUB-MISSION
    public override void Inited()
    {
        base.Inited();
        AMission BaseMission = Battle.GetBaseMission();
        BaseMission.OnIntraMissionsMessage("sub-mission xyz to base mission: here I am", new object[] { this });
    }
    
    /// BASE MISSION
    public override object[] OnIntraMissionsMessage(string sMsg, object[] args = null)
    {
        if(sMsg.Equals("sub-mission xyz to base mission: here I am")
        {
            m_SubMissions.Add("xyz", (args[0] as AMission));
        }
        return null;
    Once the base missions has access to the sub-missions you can start setting up any kind of communication and shared data.

    The SampleMission 1.0.7 has a working example (with the CServerStats as a sub mission).
    Last edited by Artist; Jun-16-2021 at 04:56.

  4. Likes TWC_Fatal_Error liked this post
  5. #3
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: How to use static dictionary (in code since 4.56) to communication among submissi

    That Dictionary can be used to send messages between missions but that is the most basic use case. The real value is how easily you can modularize the code.

    Picture a situation where you have a base mission that loads a second mission which has code that simulates radar. That code would build and maintain information (course, speed, altitude) for each side of all spotted enemy air groups. Maybe even for a few minutes after they fly out of view. A reference to that information can be put in the Dictionary under the key "RADAR".

    Then you have another mission that looks at the radar and launches interceptors if the enemy is heading for a valuable target, or just entering the airspace. These would take off on a calculated course but if the enemy changed course the interceptors would be re-vectored. And if it became impossible to intercept the aircraft would turn back and land. All the activities, air assets and ground facilities for each side are put in the Dictionary keyed as "AIR_INTERCEPT".

    Another mission controls ships. Say a cargo ship is nearing the port of Tobruk where it will park and unload for a few hours then head home. Checking the radar the ship could weight anchor and leave the area early if enemy aircraft are approaching. Some cruising warships have radar on board and contribute to the radar picture. Added to the Dictionary as "NAVAL".

    Yet another mission has depots and trucks. As air units are refueled and rearmed this code sends out supply columns with fuel, bombs and ammo without which the aircraft could not fly. This info is in the Dictionary as "LOGISTICS".

    And then there is a mission that controls the daily bombing and strafing schedule. Bomber groups can be assigned a daily target which they will attack at a designated time. Once airborne the bomber group could be redirected to a secondary target if the primary has enemy fighters. And ground units might call for air support from another mission. All this is in the Dictionary as "AIR_ATTACK".

    The missions I described above do not have to done all at once. You can start with very simple radar logic and add to it later with more sophisticated behavior. The air intercept and air attack code could be done without logistics details and that could be added later. Testing is much easier if you are only running one or two modules. And you can plug in different versions to simulate different conditions.

    All this makes a huge difference in the effort required to build a mission, especially as the mission gets complicated.

    Now you might say that you don't need separate missions, you could just write one big mission with all the code. This is a bad approach though because you end up with a big brittle hunk of code that becomes progressively harder to modify. And especially to test.

  6. Likes TWC_Fatal_Error liked this post
  7. #4
    Ace
    Join Date
    May 2015
    Location
    Kansas City, Missouri area
    Posts
    515
    Post Thanks / Like
    Total Downloaded
    130.02 MB

    Re: How to use static dictionary (in code since 4.56) to communication among submissi

    Thanks! That is all super helpful! (It is also helpful to be reminded that those sample missions exist & we can look at them for examples of how to do certain things.)

    Here is a really simple example I put together.

    The first submission sets a certain key in the dictionary, and then the second submission checks to see if that key exists, and if it is then it can do the specific things it needs to in that case.

    Code:
     string gsl_dictname = "generalstaff_discovered_red";
                if (army==2) gsl_dictname = "generalstaff_discovered_blue";
                Mission.DataDictionary[gsl_dictname] = new object { }; //just setting this value lets other submissions know that the general staff has been discovered for that army
    Code:
      if (retMO.AttackingArmy == 1 && Mission.DataDictionary.ContainsKey("generalstaff_discovered_blue")) sendArmy = -1; //If blue has found the GeneralStaff, **do something**
                            if (retMO.AttackingArmy == 2 && Mission.DataDictionary.ContainsKey("generalstaff_discovered_red")) sendArmy = -1; //If red has found the GeneralStaff, **do something**
    System: Microsoft Windows 10 Pro 64 bit, 10.0.18362 N/A Build 18362, 20,437 MB |
    ASUS GeForce GTX 1060 3GB | Intel Core i5-2500 Quad-Core Processor 3.3 GHz 6 MB Cache LGA 1155 | Intel DB65AL motherboard | ARCTIC Freezer i11 CPU Cooler | SVGA 500 watt power supply | Microsoft Sidewinder 2 Force Feedback joystick

  8. Likes TWC_Fatal_Error liked this post

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •