[Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Raimar --
I'll fix the bugs, but I agree that the code duplication is rather unpleasant,
and I'd like to see it fixed first, so I don't introduce bugs in two places :-)
What do you think of the following patch? I preserved the current behavior of
can_unit_add_to_city to protect callers who need a simple boolean, and added
the enum and the more nuanced function.
Arien
--- Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
> As a side note: (as a seperate patch) what do you think about
> something like this:
>
> enum add_to_city_error
> {
> OK, NO_UNIT_WITH_POP, CITY_TO_BIG, NO_AQUEDUCT,...;
> };
>
> enum add_to_city_error can_unit_add_to_city(struct unit *punit);
>
> And than remove this duplicated code in handle_unit_build_city.
>
> Raimar
>
> --
> email: rf13@xxxxxxxxxxxxxxxxx
> "SIGDANGER - The System is likely to crash soon"
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/ Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.125
diff -u -r1.125 unit.c
--- common/unit.c 2001/08/13 12:25:26 1.125
+++ common/unit.c 2001/08/21 23:29:13
@@ -413,7 +413,7 @@
/**************************************************************************
...
**************************************************************************/
-int can_unit_add_to_city(struct unit *punit)
+enum add_to_city_status unit_add_to_city_status (struct unit *punit)
{
struct city *pcity;
@@ -442,6 +442,13 @@
return 0;
return 1;
+}
+/**************************************************************************
+...
+**************************************************************************/
+int can_unit_add_to_city(struct unit *punit)
+{
+ return (unit_add_to_city_status (unit) == ADD_OK);
}
/**************************************************************************
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.72
diff -u -r1.72 unit.h
--- common/unit.h 2001/08/13 12:25:27 1.72
+++ common/unit.h 2001/08/21 23:29:13
@@ -66,6 +66,19 @@
MR_OTHER, MR_INVALID_TYPE_FOR_CITY_TAKE_OVER, MR_NO_WAR, MR_ZOC
};
+enum add_to_city_status {
+ ADD_OK, /* Unit OK to add to city */
+ ADD_NO_MOVES, /* Unit does not have moves left */
+ ADD_NOT_AT_CITY, /* Unit is not at a city */
+ ADD_NOT_OWNER, /* Owner of unit is not owner of city */
+ ADD_NOT_ADDABLE_UNIT, /* Unit is not one that can be added to cities */
+ ADD_TOO_BIG, /* City is too big to be added to */
+ ADD_NO_AQUEDUCT, /* Adding takes city past limit for aquaduct but
+ city has no aquaduct */
+ ADD_NO_SEWER /* Adding takes city past limit for sewer but city
+ has no sewer */
+};
+
struct unit_ai {
int control; /* 0: not automated 1: automated */
enum ai_unit_task ai_role;
@@ -186,6 +199,7 @@
int is_heli_unit(struct unit *punit);
int is_ground_unit(struct unit *punit);
int can_unit_build_city(struct unit *punit);
+enum add_to_city_status unit_add_to_city_status (struct unit *punit);
int can_unit_add_to_city(struct unit *punit);
int kills_citizen_after_attack(struct unit *punit);
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), (continued)
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Trent Piepho, 2001/08/19
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Raimar Falke, 2001/08/19
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Trent Piepho, 2001/08/19
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Raimar Falke, 2001/08/19
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Arien Malec, 2001/08/20
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Raimar Falke, 2001/08/20
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Arien Malec, 2001/08/20
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Trent Piepho, 2001/08/20
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Arien Malec, 2001/08/21
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Raimar Falke, 2001/08/21
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897),
Arien Malec <=
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Arien Malec, 2001/08/21
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Raimar Falke, 2001/08/22
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Erik Sigra, 2001/08/22
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Raimar Falke, 2001/08/22
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Arien Malec, 2001/08/22
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Raimar Falke, 2001/08/22
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Arien Malec, 2001/08/22
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Raimar Falke, 2001/08/22
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Arien Malec, 2001/08/22
- [Freeciv-Dev] Re: Pop cost patch (resending via bug system) (PR#897), Raimar Falke, 2001/08/23
|
|