[Freeciv-Dev] (PR#12997) [PATCH] UnitFlag requirement
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] (PR#12997) [PATCH] UnitFlag requirement |
From: |
"Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx> |
Date: |
Fri, 6 May 2005 16:12:10 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12997 >
This patch implements the UnitFlag requirement.
It will be commited ASAP.
Index: common/requirements.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.c,v
retrieving revision 1.20
diff -u -u -r1.20 requirements.c
--- common/requirements.c 6 May 2005 16:01:42 -0000 1.20
+++ common/requirements.c 6 May 2005 23:09:47 -0000
@@ -37,6 +37,7 @@
"Terrain",
"Nation",
"UnitType",
+ "UnitFlag",
"MinSize"
};
@@ -143,6 +144,12 @@
return source;
}
break;
+ case REQ_UNITFLAG:
+ source.value.unitflag = unit_flag_from_str(value);
+ if (source.value.unitflag != F_LAST) {
+ return source;
+ }
+ break;
case REQ_MINSIZE:
source.value.minsize = atoi(value);
if (source.value.minsize > 0) {
@@ -192,6 +199,9 @@
case REQ_UNITTYPE:
source.value.unittype = value;
return source;
+ case REQ_UNITFLAG:
+ source.value.unitflag = value;
+ return source;
case REQ_MINSIZE:
source.value.minsize = value;
return source;
@@ -238,6 +248,9 @@
case REQ_UNITTYPE:
*value = source->value.unittype;
return;
+ case REQ_UNITFLAG:
+ *value = source->value.unitflag;
+ return;
case REQ_MINSIZE:
*value = source->value.minsize;
return;
@@ -277,6 +290,7 @@
case REQ_SPECIAL:
case REQ_TERRAIN:
case REQ_UNITTYPE:
+ case REQ_UNITFLAG:
req.range = REQ_RANGE_LOCAL;
break;
case REQ_MINSIZE:
@@ -320,6 +334,7 @@
&& req.range != REQ_RANGE_WORLD);
break;
case REQ_UNITTYPE:
+ case REQ_UNITFLAG:
invalid = (req.range != REQ_RANGE_LOCAL);
break;
case REQ_NONE:
@@ -659,6 +674,18 @@
}
/****************************************************************************
+ Is there a unit with the given flag within range of the target?
+****************************************************************************/
+static bool is_unitflag_in_range(const struct unit *target_unit,
+ enum req_range range, bool survives,
+ enum unit_flag_id unitflag)
+{
+ return (range == REQ_RANGE_LOCAL
+ && target_unit
+ && unit_flag(target_unit, unitflag));
+}
+
+/****************************************************************************
Checks the requirement to see if it is active on the given target.
target gives the type of the target
@@ -714,6 +741,10 @@
return is_unittype_in_range(target_unit,
req->range, req->survives,
req->source.value.unittype);
+ case REQ_UNITFLAG:
+ return is_unitflag_in_range(target_unit,
+ req->range, req->survives,
+ req->source.value.unitflag);
case REQ_MINSIZE:
return target_city && target_city->size >= req->source.value.minsize;
case REQ_LAST:
@@ -781,6 +812,7 @@
case REQ_BUILDING:
case REQ_MINSIZE:
case REQ_UNITTYPE: /* Not sure about this one */
+ case REQ_UNITFLAG: /* Not sure about this one */
return FALSE;
case REQ_SPECIAL:
case REQ_TERRAIN:
@@ -823,6 +855,8 @@
return psource1->value.nation == psource2->value.nation;
case REQ_UNITTYPE:
return psource1->value.unittype == psource2->value.unittype;
+ case REQ_UNITFLAG:
+ return psource1->value.unitflag == psource2->value.unitflag;
case REQ_MINSIZE:
return psource1->value.minsize == psource2->value.minsize;
case REQ_LAST:
@@ -865,8 +899,13 @@
case REQ_UNITTYPE:
mystrlcat(buf, unit_name(psource->value.unittype), bufsz);
break;
+ case REQ_UNITFLAG:
+ cat_snprintf(buf, bufsz, _("%s units"),
+ get_unit_flag_name(psource->value.unitflag));
+ break;
case REQ_MINSIZE:
- cat_snprintf(buf, bufsz, "Size %d", psource->value.minsize);
+ cat_snprintf(buf, bufsz, _("Size %d"),
+ psource->value.minsize);
break;
case REQ_LAST:
assert(0);
Index: common/requirements.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.h,v
retrieving revision 1.14
diff -u -u -r1.14 requirements.h
--- common/requirements.h 6 May 2005 16:01:42 -0000 1.14
+++ common/requirements.h 6 May 2005 23:09:48 -0000
@@ -16,6 +16,7 @@
#include "fc_types.h"
#include "tech.h"
+#include "unittype.h"
/* The type of a requirement source. This must correspond to req_type_names[]
* in requirements.c. */
@@ -28,6 +29,7 @@
REQ_TERRAIN,
REQ_NATION,
REQ_UNITTYPE,
+ REQ_UNITFLAG,
REQ_MINSIZE, /* Minimum size: at city range means city size */
REQ_LAST
};
@@ -56,6 +58,7 @@
Terrain_type_id terrain; /* source terrain type */
Nation_type_id nation; /* source nation type */
Unit_type_id unittype; /* source unittype */
+ enum unit_flag_id unitflag; /* source unit flag */
int minsize; /* source minsize type */
} value; /* source value */
};
Index: common/unittype.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.c,v
retrieving revision 1.57
diff -u -u -r1.57 unittype.c
--- common/unittype.c 5 May 2005 18:32:52 -0000 1.57
+++ common/unittype.c 6 May 2005 23:09:48 -0000
@@ -187,6 +187,7 @@
{
return unit_types[id].name_orig;
}
+
/**************************************************************************
...
**************************************************************************/
@@ -372,6 +373,14 @@
}
/**************************************************************************
+ Return the original (untranslated) name of the unit flag.
+**************************************************************************/
+const char *get_unit_flag_name(enum unit_flag_id id)
+{
+ return flag_names[id];
+}
+
+/**************************************************************************
Convert role names to enum; case insensitive;
returns L_LAST if can't match.
**************************************************************************/
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.48
diff -u -u -r1.48 unittype.h
--- common/unittype.h 5 May 2005 18:32:52 -0000 1.48
+++ common/unittype.h 6 May 2005 23:09:48 -0000
@@ -253,6 +253,8 @@
enum unit_flag_id unit_flag_from_str(const char *s);
enum unit_role_id unit_role_from_str(const char *s);
+const char *get_unit_flag_name(enum unit_flag_id id);
+
bool can_player_build_unit_direct(const struct player *p, Unit_type_id id);
bool can_player_build_unit(const struct player *p, Unit_type_id id);
bool can_player_eventually_build_unit(const struct player *p,
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.311
diff -u -u -r1.311 cityturn.c
--- server/cityturn.c 6 May 2005 16:01:43 -0000 1.311
+++ server/cityturn.c 6 May 2005 23:09:49 -0000
@@ -749,6 +749,7 @@
get_nation_name(req->source.value.nation));
break;
case REQ_UNITTYPE:
+ case REQ_UNITFLAG:
/* Will only happen with a bogus ruleset. */
break;
case REQ_MINSIZE:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12997) [PATCH] UnitFlag requirement,
Vasco Alexandre da Silva Costa <=
|
|