[Freeciv-Dev] Re: (PR#6941) Mission Orders
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] Re: (PR#6941) Mission Orders |
From: |
"Arnstein Lindgard" <a-l@xxxxxxx> |
Date: |
Wed, 28 Jan 2004 13:07:20 -0800 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=6941 >
On Wed, 28 Jan 2004 10:42:25 -0800 Jason Short wrote:
> struct unit_order {
> enum orders_type type;
> union {
> enum unit_orders order;
> enum unit_activity activity;
> enum unit_actions action;
> enum diplomat_actions diplomat;
> } order;
> enum direction8 dir;
> }
>
> Is this also illegal? It does have a name now.
It seems legal, but I need to reference the order (union) in places
where the "struct unit_order" isn't relevant, so why not declare the
union outside, when you have a name for it already.
> How do you know whether a 0 is the first
> order or the first activity?
I did this:
enum unit_activity {
ACTIVITY_IDLE,
...
ACTIVITY_LAST /* leave this one last */
};
enum unit_actions {
ACTION_AUTO_ATTACK = (ACTIVITY_LAST + 1),
...
ACTION_LAST /* leave this one last */
};
enum diplomat_actions {
DIPLOMAT_BRIBE = (ACTION_LAST + 1),
...
DIPLOMAT_ANY_ACTION /* leave this one last */
};
enum unit_orders {
ORDER_MOVE = (DIPLOMAT_ANY_ACTION + 1),
...
};
> If the type doesn't need to be associated with the union, how do you
> tell which type the union is?
I simply use order.action when I know I'm dealing with an action,
and order.activity when I know I have an activity. That's only for
cosmetic reasons, as is the entire union in the first place.
I think the most straightforward implementation would be:
struct unit_order {
int order;
enum direction8 dir;
};
and reference "order" by any name, whether ACTIVITY_*, ACTION_* or ORDER_*,
because enums ARE integers in C, as far as I can see. I sort of thought it
was fancy to see if I could find a use for that strange union thing.. or
maybe I thought someone would protest against putting enums in integers
without cast because that's not allowed in C++ and thus avoid another
pointless monster debate.
In the patch I do:
union composite_orders {
enum unit_orders order;
enum unit_activity activity;
enum unit_actions action;
};
struct unit_order {
union composite_orders composite;
enum direction8 dir;
};
switch (order.composite.order) {
case ORDER.MOVE:
...
case ACTIVITY_SENTRY:
...
case ACTION_UNLOAD:
...
}
But of course, to make it pedantic we could have:
switch (order.composite.order) {
case ORDER.MOVE:
...
default:
switch (order.composite.activity) {
case ACTIVITY_SENTRY:
...
default:
switch (order.composite.action) {
case ACTION_UNLOAD:
...
}
}
}
..and then the assembler could laugh at us for handling a simple
integer in the most complex fashion possible :-)
Anyway, I like having separate enums for ACTIVITY_* and ORDER_* etc.
Arnstein
- [Freeciv-Dev] Re: (PR#6941) Mission Orders, Arnstein Lindgard, 2004/01/07
- [Freeciv-Dev] Re: (PR#6941) Mission Orders, Arnstein Lindgard, 2004/01/09
- [Freeciv-Dev] (PR#6941) Mission Orders 5, Arnstein Lindgard, 2004/01/28
- [Freeciv-Dev] (PR#6941) Mission Orders, Jason Short, 2004/01/28
- [Freeciv-Dev] Re: (PR#6941) Mission Orders, Arnstein Lindgard, 2004/01/28
- [Freeciv-Dev] Re: (PR#6941) Mission Orders, Jason Short, 2004/01/28
- [Freeciv-Dev] Re: (PR#6941) Mission Orders,
Arnstein Lindgard <=
- [Freeciv-Dev] (PR#6941) Mission Orders, Guest, 2004/01/28
- [Freeciv-Dev] Re: (PR#6941) Mission Orders, Arnstein Lindgard, 2004/01/28
- [Freeciv-Dev] Re: (PR#6941) Mission Orders, Jason Short, 2004/01/28
- [Freeciv-Dev] Re: (PR#6941) Mission Orders, Raimar Falke, 2004/01/29
|
|