URL: http://bugs.freeciv.org/Ticket/Display.html?id=40442
Attached patch improves the unit tool under erase
mode to erase only units of the selected unit type
(value erase) belonging to the current 'applied
player' a number of times equal to the value of
the 'count' parameter.
---
昨晩、私の押入れをきれいにした。
diff --git a/client/editor.c b/client/editor.c
index cbbd3b6..8f16676 100644
--- a/client/editor.c
+++ b/client/editor.c
@@ -118,8 +118,8 @@ void editor_init(void)
SET_TOOL(ETT_MILITARY_BASE, _(Military Base),
ETF_HAS_VALUE | ETF_HAS_SIZE | ETF_HAS_VALUE_ERASE,
_(Create a military base.));
- SET_TOOL(ETT_UNIT, _(Unit),
- ETF_HAS_VALUE | ETF_HAS_COUNT | ETF_HAS_APPLIED_PLAYER,
+ SET_TOOL(ETT_UNIT, _(Unit), ETF_HAS_VALUE | ETF_HAS_COUNT
+ | ETF_HAS_APPLIED_PLAYER | ETF_HAS_VALUE_ERASE,
_(Create unit.));
SET_TOOL(ETT_CITY, _(City), ETF_HAS_SIZE | ETF_HAS_APPLIED_PLAYER,
_(Create city.));
@@ -753,13 +753,8 @@ void editor_apply_tool(const struct tile *ptile,
case ETT_UNIT:
if (erase) {
- unit_list_iterate(ptile-units, punit) {
-if (apno != player_number(punit-owner)) {
- continue;
-}
-dsend_packet_edit_unit_remove(client.conn, punit-id);
-break;
- } unit_list_iterate_end;
+ dsend_packet_edit_unit_remove(client.conn, apno,
+ptile-x, ptile-y, value, count);
} else {
dsend_packet_edit_unit_create(client.conn, apno,
ptile-x, ptile-y, value, count);
diff --git a/common/packets.def b/common/packets.def
index 84a8965..451ac90 100644
--- a/common/packets.def
+++ b/common/packets.def
@@ -1496,7 +1496,10 @@ PACKET_EDIT_UNIT_CREATE=162;cs,handle-per-conn,dsend
end
PACKET_EDIT_UNIT_REMOVE=163;cs,handle-per-conn,dsend
- UNIT id;
+ PLAYER owner;
+ COORD x,y;
+ UNIT_TYPE type;
+ UINT8 count;
end
PACKET_EDIT_UNIT=164;cs,handle-per-conn,handle-via-packet
diff --git a/server/edithand.c b/server/edithand.c
index 6cae087..63824d9 100644
--- a/server/edithand.c
+++ b/server/edithand.c
@@ -388,7 +388,7 @@ void handle_edit_unit_create(struct connection *pc, int owner,
ptile = map_pos_to_tile(x, y);
if (!ptile) {
notify_conn(pc-self, NULL, E_BAD_COMMAND,
-_(Cannot edit the tile (%d, %d) because
+_(Cannot create units at tile (%d, %d) because
it is not on the map!), x, y);
return;
}
@@ -445,11 +445,16 @@ void handle_edit_unit_create(struct connection *pc, int owner,
}
/
- Remove a unit with the given id.
+ Remove 'count' units of type 'utid' owned by player number 'owner' at
+ tile (x, y).
/
-void handle_edit_unit_remove(struct connection *pc, int id)
+void handle_edit_unit_remove(struct connection *pc, int owner,
+ int x, int y, Unit_type_id utid, int count)
{
- struct unit *punit;
+ struct tile *ptile;
+ struct unit_type *punittype;
+ struct player *pplayer;
+ int i;
if (!can_conn_edit(pc)) {
notify_conn(pc-self, NULL, E_BAD_COMMAND,
@@ -457,14 +462,44 @@ void handle_edit_unit_remove(struct connection *pc, int id)
return;
}
- punit = game_find_unit_by_number(id);
- if (!punit) {
+ ptile = map_pos_to_tile(x, y);
+ if (!ptile) {
notify_conn(pc-self, NULL, E_BAD_COMMAND,
-_(Cannot remove unit with unknown id %d.), id);
+_(Cannot remove units at tile (%d, %d) because
+ it is not on the map!), x, y);
+return;
+ }
+
+ punittype = utype_by_number(utid);
+ if (!punittype) {
+notify_conn(pc-self, ptile, E_BAD_COMMAND,
+_(Cannot remove a unit at (%d, %d) because the
+ given unit type id %d is invalid.), x, y, utid);
return;
}
- wipe_unit(punit);
+ pplayer = valid_player_by_number(owner);
+ if (!pplayer) {
+notify_conn(pc-self, ptile, E_BAD_COMMAND,
+_(Cannot remove a unit of type %s at (%d, %d)
+ because the given owner's player id %d is
+ invalid.), utype_name_translation(punittype),
+x, y, owner);
+return;
+ }
+
+ i = 0;
+ unit_list_iterate_safe(ptile-units, punit) {
+if (i = count) {
+ break;
+}
+if (unit_type(punit) != punittype
+|| unit_owner(punit) != pplayer) {
+ continue;
+}
+wipe_unit(punit);
+i++;
+ } unit_list_iterate_safe_end;
}
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev