<URL: http://bugs.freeciv.org/Ticket/Display.html?id=17191 >
New fixes for the tutorial; to fix that .name is no longer available and use find.unit_type and similar. Introduces convenience functions since the test for unit type is not so straightforward (Might also be a good example for those who read the tutorial to learn how to write scripts) One patch for the 2.1 branch and one for trunk, revision 13075. The patches are different in details but they make tutorial.sav identical in both versions.
Index: data/scenario/tutorial.sav =================================================================== --- data/scenario/tutorial.sav (revision 13075) +++ data/scenario/tutorial.sav (arbetskopia) @@ -5,6 +5,14 @@ [script] code=$ +function has_utype(unit, utype_name) + print(utype_name) + return (unit.utype.id == find.unit_type(utype_name).id) +end +function has_terrain(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 +28,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_utype(unit, 'Settlers') + and (has_terrain(dst_tile, 'Grassland') + or has_terrain(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 +203,7 @@ if not unit.owner:is_human() then return end - if unit:type().name == 'Settlers' then + if has_utype(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 +241,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 +263,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 +280,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 +364,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\
Index: data/scenario/tutorial.sav =================================================================== --- data/scenario/tutorial.sav (revision 13086) +++ data/scenario/tutorial.sav (arbetskopia) @@ -5,6 +5,14 @@ [script] code=$ +function has_utype(unit, utype_name) + print(utype_name) + return (unit.utype.id == find.unit_type(utype_name).id) +end +function has_terrain(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 +28,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_utype(unit, 'Settlers') + and (has_terrain(dst_tile, 'Grassland') + or has_terrain(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 +203,7 @@ if not unit.owner:is_human() then return end - if unit.type.name == 'Settlers' then + if has_utype(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 +241,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 +263,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\
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev