Providing additional data to IGrouping

  • August 13, 2018 at 15:09 #23622
    andrew2110
    Participant

    I’m trying to write an RTS game, for a few cases it would be desirable to set an additional piece of data when a group of units have a path target set, for example if a worker is sent to chop a tree, it would be good to set the tree that the group has been sent to chop as an additional piece of data.

    So far, a group of units has been selected (these may or may not be “worker” type units), by right clicking on a tree, the worker units in this group will be routed towards the tree.

    I’ve tried iterating through the group / the IUnitFacade interfaces within the group and seeing if it has a component on the unit of type WorkerUnit so I can set the additional piece of data for what they should do when they arrive at their destination but haven’t found a good way to adapt this code yet to make that work.

    August 13, 2018 at 15:31 #23624
    Geminior
    Keymaster

    You have a number of options available.

    You can do what you are already doing, iterating over members and testing for the existence of a component should work just fine. You can’t use GetComponent directly on the interface reference of course, but call it from the transform property.

    You can also make a custom UnitFacade to expose extra data, see the examples project for an example (UnitFacadeExtended).

    Finally you can make your own IGroupingStrategy implementation to replace the DefaultUnitGroupingStrategy. The default simply puts all units into one group. You could instead put different unit types into separate groups.
    Again check the examples project for an example (AttributeBasedStrategy).

You must be logged in to reply to this topic.