ID:159518
 
The fact that client.mouse_pointer_icon does not take an icon_state as argument is kind of defeating my attempts of keeping the code object-oriented and yet not loosing out on performance.

Consider the idea of having several players, with several different units. Each player should have a unique colour for her "army".

Now while I could simply use icon_state = "[player.colour][unit.type]" to handle giving the unit an icon and thus could set the definition at a common node for all units, I can not do the same for icon = '[p.c][u.t].dmi'.

The only way I could think of would be to create a new icon on the fly, like var/icon/I = new('units.dmi',icon_state = "[p.c][u.t]"). The reference speaks of "quite a bit of overhead" here though.

Any ideas would be welcome!

Thank you in advance.
  1. Separate the states in your DMI into multiple DMI files.
  2. Give each unit a proc that takes a color and returns and icon.
  3. Use a switch statement inside the unit proc to return the correct one of those icons. Alternatively, you can use an index instead of text to represent color and then return the icon at that position in a list.
You'll have a few more files around your hard drive, but it's object-oriented and I doubt you'll notice any speed loss.
In response to ACWraith
ACWraith wrote:
Give each unit a proc that takes a color and returns and icon.

This is the very point I wanted to avoid by making use of inheritance.
With 20 units and 5 players, that would make more than 100 lines of code already, compared to a single line.
In response to Schnitzelnagler
You can use the same proc. Just refer to a different list of icons ordered by color.