[Freeciv-Dev] (PR#40567) [Patch] Some tile helper functions

2008-11-18 Thread Madeline Book

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40567 

Some tile helper functions that I needed to add for cleaner
virtual tile manipulation:

void tile_set_specials(struct tile *ptile, bv_special specials);
bv_bases tile_bases(const struct tile *ptile);
void tile_set_bases(struct tile *ptile, bv_bases bases);
bool tile_has_any_bases(const struct tile *ptile);


---
冬の夜に遠くのどこかで犬が吠えている。冷たいの?
diff --git a/common/tile.c b/common/tile.c
index cad4c4c..9fcba9d 100644
--- a/common/tile.c
+++ b/common/tile.c
@@ -119,6 +119,17 @@ bv_special tile_specials(const struct tile *ptile)
 }
 
 /
+  Sets the tile's specials to those present in the given bit vector.
+/
+void tile_set_specials(struct tile *ptile, bv_special specials)
+{
+  if (!ptile) {
+return;
+  }
+  ptile-special = specials;
+}
+
+/
   Returns TRUE iff the given tile has the given special.
 /
 bool tile_has_special(const struct tile *ptile,
@@ -136,6 +147,30 @@ bool tile_has_any_specials(const struct tile *ptile)
 }
 
 /
+  Returns a bit vector of the bases present at the tile.
+/
+bv_bases tile_bases(const struct tile *ptile)
+{
+  if (!ptile) {
+bv_bases empty;
+BV_CLR_ALL(empty);
+return empty;
+  }
+  return ptile-bases;
+}
+
+/
+  Set the bases on the tile to those present in the given bit vector.
+/
+void tile_set_bases(struct tile *ptile, bv_bases bases)
+{
+  if (!ptile) {
+return;
+  }
+  ptile-bases = bases;
+}
+
+/
   Adds base to tile.
   FIXME: Should remove conflicting old base and return bool indicating that.
 /
@@ -666,6 +701,17 @@ bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
 }
 
 /
+  Returns TRUE if the given tile has any bases on it.
+/
+bool tile_has_any_bases(const struct tile *ptile)
+{
+  if (!ptile) {
+return FALSE;
+  }
+  return BV_ISSET_ANY(ptile-bases);
+}
+
+/
   Returns a completely blank virtual tile (except for the unit list
   vtile-units, which is created for you). Be sure to call virtual_tile_free
   on it when it is no longer needed.
diff --git a/common/tile.h b/common/tile.h
index 93e7a5d..d3dc291 100644
--- a/common/tile.h
+++ b/common/tile.h
@@ -88,6 +88,7 @@ void tile_set_worked(struct tile *ptile, struct city *pcity);
 
 /* Specials are a bit different */
 bv_special tile_specials(const struct tile *ptile);
+void tile_set_specials(struct tile *ptile, bv_special specials);
 bool tile_has_special(const struct tile *ptile,
 		  enum tile_special_type to_test_for);
 bool tile_has_any_specials(const struct tile *ptile);
@@ -95,7 +96,10 @@ void tile_set_special(struct tile *ptile, enum tile_special_type spe);
 void tile_clear_special(struct tile *ptile, enum tile_special_type spe);
 void tile_clear_all_specials(struct tile *ptile);
 
+bv_bases tile_bases(const struct tile *ptile);
+void tile_set_bases(struct tile *ptile, bv_bases bases);
 bool tile_has_base(const struct tile *ptile, const struct base_type *pbase);
+bool tile_has_any_bases(const struct tile *ptile);
 void tile_add_base(struct tile *ptile, const struct base_type *pbase);
 void tile_remove_base(struct tile *ptile, const struct base_type *pbase);
 bool tile_has_base_flag(const struct tile *ptile, enum base_flag_id flag);
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#40568) [Editor] Copy and paste icons

2008-11-18 Thread Madeline Book

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40568 

I fashioned two icons representing copy and paste out of
one of pep's (!= pepeto) editor icons. Attached is the new
editor.png and a patch to make the icons usable in the code.

Also, I originally made a mistake in the spec file (off by 1
error ;)) which the patch fixes.


---
じゃあ、諸悪の根源は無知だという訳か。
diff --git a/client/tilespec.c b/client/tilespec.c
index 79631e0..927f37c 100644
--- a/client/tilespec.c
+++ b/client/tilespec.c
@@ -2306,6 +2306,8 @@ static void tileset_lookup_sprite_tags(struct tileset *t)
 #define SET_EDITOR_SPRITE(x) SET_SPRITE(editor.x, editor. #x)
   SET_EDITOR_SPRITE(erase);
   SET_EDITOR_SPRITE(brush);
+  SET_EDITOR_SPRITE(copy);
+  SET_EDITOR_SPRITE(paste);
   SET_EDITOR_SPRITE(startpos);
   SET_EDITOR_SPRITE(terrain);
   SET_EDITOR_SPRITE(terrain_resource);
diff --git a/client/tilespec.h b/client/tilespec.h
index e1d9fbd..a1123e3 100644
--- a/client/tilespec.h
+++ b/client/tilespec.h
@@ -225,6 +225,8 @@ struct editor_sprites {
   struct sprite
 *erase,
 *brush,
+*copy,
+*paste,
 *startpos,
 *terrain,
 *terrain_resource,
diff --git a/data/misc/editor.spec b/data/misc/editor.spec
index 113d62e..1693980 100644
--- a/data/misc/editor.spec
+++ b/data/misc/editor.spec
@@ -78,7 +78,7 @@ tiles = { row, column, tag
 [grid_extra]
 
 x_top_left = 1
-y_top_left = 143
+y_top_left = 142
 dx = 30
 dy = 30
 pixel_border = 1
@@ -89,4 +89,6 @@ tiles = { row, column, tag
   0,  2, editor.tiny_brush
   0,  3, editor.type_paint
   0,  4, editor.bitmap_to_map
+  0,  5, editor.copy
+  0,  6, editor.paste
 }
inline: editor_with_copy_paste.png___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#40570) [Patch] marine explorers try to violate peace treaties and thus are stoped

2008-11-18 Thread Thomas Kuehne

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40570 

Marine explorers stop if they try to travel to or trhough a marine 
tile who's owner is at peace with the unit's owner.

As a consequence the units are stoped and require player interaction 
even though there are still unexplored reacheable tiles.

The attached patch should fixe this issue in the vast majority of 
cases. Only if ai_manage_explorer's best_title isn't reacheable does 
the explorer stop, even if there are still other unexplored reachable 
tiles.

diff -ur freeciv-2.1.6/ai/aiexplorer.c freeciv-2.1.6-marine-explorer/ai/aiexplorer.c
--- freeciv-2.1.6/ai/aiexplorer.c	2008-08-10 14:56:15.0 +0200
+++ freeciv-2.1.6-marine-explorer/ai/aiexplorer.c	2008-11-18 14:30:08.0 +0100
@@ -107,6 +107,51 @@
   }
 }
 
+/*
+ * Explorers shouldn't try to break a peace treaty and thus cause
+ * player interaction.
+ */
+static bool ai_may_explore(const struct tile * ptile,
+const struct player * pplayer, const bv_flags unit_flags)
+{
+  if(! BV_ISSET(unit_flags, F_IGZOC)){
+// don't invade unless there are only allied troops on the tile
+if(players_non_invade(ptile-owner, pplayer)){
+  if(!is_allied_unit_tile(ptile, pplayer)){
+return FALSE;
+  }
+}
+  }
+
+  // don't attack
+  if(is_non_allied_unit_tile(ptile, pplayer)){
+return FALSE;
+  }
+  
+  return TRUE;
+}
+
+enum tile_behavior ai_explorer_tb(const struct tile *ptile, enum known_type k,
+struct pf_parameter * param)
+{
+  if(!ai_may_explore(ptile, param-owner, param-unit_flags)){
+return TB_IGNORE;
+  }
+  return TB_NORMAL;
+}
+
+static bool ai_explorer_goto(struct unit *punit, struct tile *ptile)
+{
+  struct pf_parameter parameter;
+  struct ai_risk_cost risk_cost;
+
+  ai_fill_unit_param(parameter, risk_cost, punit, ptile);
+  parameter.get_TB = ai_explorer_tb;
+  
+  UNIT_LOG(LOG_DEBUG, punit, ai_explorer_goto to %d,%d, ptile-x, ptile-y);
+  return ai_unit_goto_constrained(punit, ptile, parameter);
+}
+
 /**
 Return a value indicating how desirable it is to explore the given tile.
 In general, we want to discover unknown terrain of the opposite kind to
@@ -170,6 +215,11 @@
 return 0;
   }
 
+  /* Enforce diplomatic realtions. */
+  if(! ai_may_explore(ptile, punit-owner, unit_type(punit)-flags)){
+  return 0;
+  }
+
   /* What value we assign to the number of land and water tiles
* depends on if we're a land or water unit. */
   if (is_ground_unit(punit)) {
@@ -345,7 +395,7 @@
   if (best_tile != NULL) {
 /* TODO: read the path off the map we made.  Then we can make a path 
  * which goes beside the unknown, with a good EC callback... */
-if (!ai_unit_goto(punit, best_tile)) {
+if (!ai_explorer_goto(punit, best_tile)) {
   /* Died?  Strange... */
   return MR_DEATH;
 }
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev