I seem to have broken ANLEra Terraforming Code

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
Cen7
Posts: 15
Joined: February 2nd, 2020, 11:16 pm

I seem to have broken ANLEra Terraforming Code

Post by Cen7 »

Consternation, people! I have broken something again. :oops:

I have been using "A New Land Era" as a basis for my own modification that includes the ability for 0-level units to terraform the tile they are on. As a preliminary step to adding new options, I've been trying to simplify the existing code: whoever created the SP version for ANLEra created a modification in the SP folder so that any 0-level units would receive the terraforming options. (The original ANLEra code instead contains specific lists of units.) I incorporated that SP code, changing macro names as appropriate, and got a version that successfully loads and correctly displays the original options.

The only thing that is broken is that if an option costs gold, it will not execute. For example, a 0-level unit standing on a ford is given the option to landfill the ford for a cost of 1 (converting it to grassland) or destroy the code for a cost of 0 (converting to shallow water). Although you can click on the landfill, choice, it will not execute, and the program behaves as if you didn't have the money for it. Testing this by changing the cost for landfill from 1 to 0, it will then execute correctly. So, I think the problem is with checking the available gold, yet the code I'm using in this regard is the original ANLEra code. The only change I made to it was to remove a comment. (I even tried restoring that comment: that didn't fix the problem.) :hmm:

Here is all of the code that gets referenced on the change-ford-to-landfill issue:

Code: Select all

#define MODIFY_TERRAIN_OVERLAY TERRAIN X_SPAN Y_SPAN
    # Changes the terrain at a given list of coordinates
    # For example, we could make 14,15 and 14,16 grassland:
    #! {MODIFY_TERRAIN Gg (14,14) (15,16)}
    [terrain]
        terrain={TERRAIN}
        layer=overlay
        x={X_SPAN}
        y={Y_SPAN}
    [/terrain]
#enddef

#define SIF_TERRAFORM IMAGE LABEL COST SOUND SHOW_IF THEN
    [option]
        label="<span color='green'>" + {LABEL} + "</span>" # wmllint: ignore
        image={IMAGE}
        #textdomain wesnoth-sif
        description="<span size='small'>" + _ "Cost:" + " " + {COST} + _ "g" + "</span>"
        #textdomain wesnoth-sif
        {SHOW_IF}
        [command]
            [if]
                [variable]
                    name=gold
                    greater_than_equal_to={COST}
                [/variable]

                [then]
                    {COMPLETE_ACTION -{COST}}
                    [sound]
                        name={SOUND}
                    [/sound]

                    # In case of destroyed village or castle
                    [remove_item]
                        x,y=$x1,$y1
                    [/remove_item]

                    {THEN}

                    [break][/break]
                [/then]
            [/if]
        [/command]
    [/option]
#enddef

# Note -- the following macro came from the SP folder
#define SIF_SHOW_IF_LEVEL_0 TERRAINLIST
    [show_if]
        [have_unit]
            side=$side_number
            x,y=$x1,$y1
            [filter]
                level=0
                side=$side_number
            [/filter]
            [not]
                [filter_wml]
                    [status]
                        worked_this_turn=yes
                    [/status]
                [/filter_wml]
            [/not]
            [filter_location]
                terrain={TERRAINLIST}
            [/filter_location]
        [/have_unit]
    [/show_if]
#enddef

#define WORKER_OPTIONS
    [set_menu_item]
        id=sif_get_to_work
        description= _ "Get to Work!"
		[show_if]
            [have_unit]
                side=$side_number
                x,y=$x1,$y1
                level=0
            [/have_unit]
        [/show_if]
        [command]
            [store_side]
                side=$side_number
                variable=worker
            [/store_side]

            [store_unit]
                [filter]
                    x=$x1
                    y=$y1
                [/filter]
                variable=unit
            [/store_unit]

            [set_variable]
                name=finished
                value=no
            [/set_variable]
            [while]
                [variable]
                    name=finished
                    equals=no
                [/variable]

                [do]
# wmlindent: start ignoring
            [message]
                speaker=unit
# wmllint: display on
                message= _ "What shall I do, my liege?"
# wmllint: display off

[option]
message= _ "Nothing"
    [command]
        [set_variable]
            name=finished
            value=yes
        [/set_variable]
    [/command]
[/option]
# ----------------------------------------------
# FORD

# Destroy the Ford
# FIXME ANL_TERRAFORM_FREE
{SIF_TERRAFORM "terrain/water/coast-tile.png" _"Destroy Ford" 0 () (
	{SIF_SHOW_IF_LEVEL_0 "Wwf"}
) (
	[delay]
		time=200
	[/delay]
	{MODIFY_TERRAIN "Ww" $x1 $y1}
	[sound]
		name=pincers.ogg
	[/sound]
	[delay]
		time=200
	[/delay]
	[sound]
		name=water-blast.wav
	[/sound]
)}

# Landfill (on a Ford, cheaper than elsewhere)
{SIF_TERRAFORM "terrain/grass/green6.png" _"Landfill" 1 () (
	{SIF_SHOW_IF_LEVEL_0 "Wwf"}
) (
	[delay]
		time=200
	[/delay]
	{MODIFY_TERRAIN "Gg" $x1 $y1}
	[sound]
		name=claws.ogg
	[/sound]
)}

[/message]
[/do]
[/while]

[/command]
[/set_menu_item]
#enddef

# Those familiar with the code will recognize I left out the portions relating to other changes to other terrains.
Any ideas on what my problem is?

Cen7
Posts: 15
Joined: February 2nd, 2020, 11:16 pm

Re: I seem to have broken ANLEra Terraforming Code

Post by Cen7 »

Edit: Whoops! Nevermind, people, I think I found the problem. The original #define WORKER_OPTIONS code includes this, which my current version lacks:

Code: Select all

            [store_gold]
                side=$side_number
                variable=gold
            [/store_gold]
Yeah, notwithstanding my ignorance of coding, I suspect herein lay my problem. :lol:
I'll let you know if it doesn't. Thanks for looking, those who looked.

EDIT: Yep, that did it. A fix so simple, even I could do it.

Post Reply