Little Big COB improvements
Posted: 08 Feb 2007, 14:12
As far as I'm aware it is impossible/unfeasible to alter Scriptor's compiler to accept new commands.
Function 1: Callback on unit creation
Whenever a unit is created, other units will have their UnitCreated(id) function called. A unit that wants to receive this call has to set UNIT_CREATE_CALLBACK to 1 to avoid loads of unnecessary script calls (best handled internally by making this add a unit to a linked list that gets waded through on every unit creation).
Purpose: This would enable units to react to the existence of other units, e.g. turrets to a fire control system, without having to regularly check ALL units for the existence of a specific unit among them. It basically reduces the script load a lot and allows even basic ressource structures to watch for things like that.
Function 2: UnitType constant
Each unit will have a UnitType tag. This tag defaults to 0 and can be used in any way the modder chooses, it's constant and can be gotten through get UNIT_TYPE(unitId).
Purpose: This would allow easier identification of units in script, this tag can be used either as a sequential ID to know the exact type or a flagarray to mark certain attributes (by using bit operations), depending on how the modder wants to use it.
Function 3: Public unit variables
These variables would be accessed through get/set UNIT_VAR(unitId) and would be used to communicate values from one unit to another. The last time I proposed this it was deemed unfeasible because get only has one parameter in addition to the constant, a solution would be to encode the number of the variable into the constant (e.g. set 256 would access the first, set 257 the second, ...). I don't know if set takes any parameters at all so these might need to be read-only for units other than the owner but even that's a big improvement over the current situation. Similar variables could exist per-player and globally.
Additionally a tag could be added that can make some of these variables displayed in the GUI.
Purpose: This would be used for inter-unit communication, e.g. having the refinery retrieve the amount of "ressources" stored in the harvester and generating ressources while decreasing that count to unload the harvester.
Function 4: List of nearby units
This would add the set-only variable UNITS_IN_RADIUS and the get-only variable GET_NEXT_UIR. Setting the first to a value would make the engine compile a list of all units in a radius equal to the value set (the value isn't actually stored, it's just a wrapper for a command). Getting the second would return one unitID at a time from that list (could be a stack for this purpose, actually), -1 (or something) when the list is emptied. In essence it iterates through the IDs of all units that were nearby during the set UNITS_IN_RADIUS command.
Optionally a set UNIT_FILTER and set UNIT_TYPE_ONLY could be added that would only return units whose UnitType matches one bit (for the former, if & returns !=0)/ matches the whole number (for the latter) set.
If necessary the list could be valid only in the frame it was created in though of course allowing it to persist for longer would be beneficial.
Purpose: This would allow units to react to the proximity of others while being able to use the engine's faster code for determining what's in range. E.g. for mobile cloak generators all units that can be cloaked by it would have to check regularly if a generator is nearby, obviously this would create a lot of load if we had to iterate through the whole unit list and compare distances all the time.
I believe all of the above would need only small amounts of code and could be done before the next version easily while greatly increasing the power of the script and allowing a large number of new gameplay mechanics.
Function 1: Callback on unit creation
Whenever a unit is created, other units will have their UnitCreated(id) function called. A unit that wants to receive this call has to set UNIT_CREATE_CALLBACK to 1 to avoid loads of unnecessary script calls (best handled internally by making this add a unit to a linked list that gets waded through on every unit creation).
Purpose: This would enable units to react to the existence of other units, e.g. turrets to a fire control system, without having to regularly check ALL units for the existence of a specific unit among them. It basically reduces the script load a lot and allows even basic ressource structures to watch for things like that.
Function 2: UnitType constant
Each unit will have a UnitType tag. This tag defaults to 0 and can be used in any way the modder chooses, it's constant and can be gotten through get UNIT_TYPE(unitId).
Purpose: This would allow easier identification of units in script, this tag can be used either as a sequential ID to know the exact type or a flagarray to mark certain attributes (by using bit operations), depending on how the modder wants to use it.
Function 3: Public unit variables
These variables would be accessed through get/set UNIT_VAR(unitId) and would be used to communicate values from one unit to another. The last time I proposed this it was deemed unfeasible because get only has one parameter in addition to the constant, a solution would be to encode the number of the variable into the constant (e.g. set 256 would access the first, set 257 the second, ...). I don't know if set takes any parameters at all so these might need to be read-only for units other than the owner but even that's a big improvement over the current situation. Similar variables could exist per-player and globally.
Additionally a tag could be added that can make some of these variables displayed in the GUI.
Purpose: This would be used for inter-unit communication, e.g. having the refinery retrieve the amount of "ressources" stored in the harvester and generating ressources while decreasing that count to unload the harvester.
Function 4: List of nearby units
This would add the set-only variable UNITS_IN_RADIUS and the get-only variable GET_NEXT_UIR. Setting the first to a value would make the engine compile a list of all units in a radius equal to the value set (the value isn't actually stored, it's just a wrapper for a command). Getting the second would return one unitID at a time from that list (could be a stack for this purpose, actually), -1 (or something) when the list is emptied. In essence it iterates through the IDs of all units that were nearby during the set UNITS_IN_RADIUS command.
Optionally a set UNIT_FILTER and set UNIT_TYPE_ONLY could be added that would only return units whose UnitType matches one bit (for the former, if & returns !=0)/ matches the whole number (for the latter) set.
If necessary the list could be valid only in the frame it was created in though of course allowing it to persist for longer would be beneficial.
Purpose: This would allow units to react to the proximity of others while being able to use the engine's faster code for determining what's in range. E.g. for mobile cloak generators all units that can be cloaked by it would have to check regularly if a generator is nearby, obviously this would create a lot of load if we had to iterate through the whole unit list and compare distances all the time.
I believe all of the above would need only small amounts of code and could be done before the next version easily while greatly increasing the power of the script and allowing a large number of new gameplay mechanics.