<URL: http://bugs.freeciv.org/Ticket/Display.html?id=17191 >

> [wsimpson - Tir. 10. Jul. 2007 22:00:55]:
> 
> To be consistent with other naming conventions, that should be:
> 
> has_unit_type_name(unit, rule_name)
> 
> because its argument is a unit, not a utype.
> 
> ===
> 
> Likewise,
> 
> function has_tile_terrain_name(tile, rule_name)
> 

Absolutely. If it was my scenario, convenience function names could be
sloppy. This one could be frequently copied and edited though so it is
right.

Also, it's sad that the == operator doesn't work on Unit_Types and the
like, it seems to go after reference (actual instance) equality, and the
id comparison is all I've got to reliably work.

Also, I managed to attach v1 and not v2 last time, that's the reason for
 the unneeded print call.

Attached v3 with your suggested changes

Index: data/scenario/tutorial.sav
===================================================================
--- data/scenario/tutorial.sav	(revision 13088)
+++ data/scenario/tutorial.sav	(arbetskopia)
@@ -5,6 +5,13 @@
 
 [script]
 code=$
+function has_unit_type_name(unit, utype_name) 
+  return (unit.utype.id == find.unit_type(utype_name).id)
+end
+function has_tile_type_name(tile, terrain_name)
+  return (tile.terrain.id == find.terrain(terrain_name).id)
+end
+
 function turn_callback(turn, year)
   if turn == 0 then
     notify.event(nil, nil, E.TUTORIAL,
@@ -20,9 +27,9 @@
 function unit_moved_callback(unit, src_tile, dst_tile)
   if unit.owner:is_human() then
     if citiesbuilt == 0
-      and unit.type.name == 'Settlers'
-      and (dst_tile.terrain.name == 'Grassland'
-           or dst_tile.terrain.name == 'Plains') then  
+      and has_unit_type_name(unit, 'Settlers')
+      and (has_tile_type_name(dst_tile, 'Grassland')
+           or has_tile_type_name(dst_tile, 'Plains')) then  
       notify.event(unit.owner, dst_tile, E.TUTORIAL,
 _("This looks like a good place to build a city.  The next time this\n\
 unit gets a chance to move, press (b) to found a city.\n\
@@ -195,7 +202,7 @@
   if not unit.owner:is_human() then
     return
   end
-  if unit.type.name == 'Settlers' then
+  if has_unit_type_name(unit, 'Settlers') then
     if settlersbuilt == 0 then
       notify.event(unit.owner, unit.tile, E.TUTORIAL,
 _("You have built a settler unit.  Settlers are best used to build \n\
@@ -233,7 +240,7 @@
   if not city.owner:is_human() then
     return
   end
-  if building.name == 'Barracks' and not barracksmsg then
+  if building.id == find.building_type('Barracks').id and not barracksmsg then
     notify.event(city.owner, city.tile, E.TUTORIAL,
 _("You have built a Barracks.  This building will make any military\n\
 units you build start out as veterans.  Veteran units are stronger\n\
@@ -255,7 +262,7 @@
   if not city.owner:is_human() then
     return
   end
-  if unittype.name == 'Settlers' and not nosettlermsg then
+  if unittype.id == find.unit_type('Settlers').id and not nosettlermsg then
     notify.event(city.owner, city.tile, E.TUTORIAL,
 _("Your city cannot build a settler.  Settlers take one unit of\n\
 population to build, so a city of size one cannot build one without\n\
Index: data/scenario/tutorial.sav
===================================================================
--- data/scenario/tutorial.sav	(revision 13088)
+++ data/scenario/tutorial.sav	(arbetskopia)
@@ -5,6 +5,13 @@
 
 [script]
 code=$
+function has_unit_type_name(unit, utype_name) 
+  return (unit.utype.id == find.unit_type(utype_name).id)
+end
+function has_tile_type_name(tile, terrain_name)
+  return (tile.terrain.id == find.terrain(terrain_name).id)
+end
+
 function turn_callback(turn, year)
   if turn == 0 then
     notify.event(nil, nil, E.TUTORIAL,
@@ -20,9 +27,9 @@
 function unit_moved_callback(unit, src_tile, dst_tile)
   if unit.owner:is_human() then
     if citiesbuilt == 0
-      and unit:type().name == 'Settlers'
-      and (dst_tile:terrain().name == 'Grassland'
-           or dst_tile:terrain().name == 'Plains') then  
+      and has_unit_type_name(unit, 'Settlers')
+      and (has_tile_type_name(dst_tile, 'Grassland')
+           or has_tile_type_name(dst_tile, 'Plains')) then  
       notify.event(unit.owner, dst_tile, E.TUTORIAL,
 _("This looks like a good place to build a city.  The next time this\n\
 unit gets a chance to move, press (b) to found a city.\n\
@@ -195,7 +202,7 @@
   if not unit.owner:is_human() then
     return
   end
-  if unit:type().name == 'Settlers' then
+  if has_unit_type_name(unit, 'Settlers') then
     if settlersbuilt == 0 then
       notify.event(unit.owner, unit.tile, E.TUTORIAL,
 _("You have built a settler unit.  Settlers are best used to build \n\
@@ -233,7 +240,7 @@
   if not city.owner:is_human() then
     return
   end
-  if building.name == 'Barracks' and not barracksmsg then
+  if building.id == find.building_type('Barracks').id and not barracksmsg then
     notify.event(city.owner, city.tile, E.TUTORIAL,
 _("You have built a Barracks.  This building will make any military\n\
 units you build start out as veterans.  Veteran units are stronger\n\
@@ -255,7 +262,7 @@
   if not city.owner:is_human() then
     return
   end
-  if unittype.name == 'Settlers' and not nosettlermsg then
+  if unittype.id == find.unit_type('Settlers').id and not nosettlermsg then
     notify.event(city.owner, city.tile, E.TUTORIAL,
 _("Your city cannot build a settler.  Settlers take one unit of\n\
 population to build, so a city of size one cannot build one without\n\
@@ -272,7 +279,7 @@
 _("You have built your first military unit!  Military units have two\n\
 basic purposes: attack and defense.  Each unit has an attack strength\n\
 and a defense strength.  While a Warriors is a measly 1/1, a Phalanx\n\
-is a must stronger defender with 2 defense (1/2).  A Catapult is a good\n\
+is a much stronger defender with 2 defense (1/2).  A Catapult is a good\n\
 attacking unit because it has 6 attack (6/1).\n\
 \n\
 Usually it is a good idea to keep one or two defenders in each city.\n\
@@ -356,7 +363,7 @@
   if not hutmsg then
     notify.event(unit.owner, unit.tile, E.TUTORIAL,
 _("Your unit has found a Hut.  These are small villages scattered across\n\
-the landscape.  When a unit enters one several things may happen.  The\n\
+the landscape.  When a unit enters one, several things may happen.  The\n\
 most likely outcome is that you will find resources worth a small\n\
 amount of gold.  However it is also possible to find technologies or\n\
 mercenary units inside a hut.  Some huts contain native settlers\n\
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to