place item on map instead of in code

The place to post your WML questions and answers.

Moderator: Forum Moderators

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
denispir
Posts: 184
Joined: March 14th, 2013, 12:26 am

place item on map instead of in code

Post by denispir »

Hello all,

[I ask this question here because there does not seem to be any forum dedicated to maps, else tell me where it should belong and/or move the thread.]

Is it possible to have an item on the map directly (if only by modifying its text file) instead of placing it in WML code? I think at having it be an overlay as for mixed terrains (with the '^' sign in text).

Thank you,
Diniz
User avatar
Ravana
Forum Moderator
Posts: 2995
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: place item on map instead of in code

Post by Ravana »

Usually not, though it is possible to use WML to create new terrain types that look like items.
User avatar
doofus-01
Art Director
Posts: 4128
Joined: January 6th, 2008, 9:27 pm
Location: USA

Re: place item on map instead of in code

Post by doofus-01 »

Take a look at the brazier "embellishment' terrains (^Eb, ^Ebn) as examples, I think they do what you want. You'll still need to define what the terrain code does, but then you can add it as an overlay with the "^" on a map.
BfW 1.12 supported, but active development only for BfW 1.13/1.14: Bad Moon Rising | Trinity | Archaic Era |
| Abandoned: Tales of the Setting Sun
GitHub link for these projects
User avatar
TrashMan
Posts: 601
Joined: April 30th, 2008, 8:04 pm
Contact:

Re: place item on map instead of in code

Post by TrashMan »

Do you mean something as externally referenced item so you only need to call in the scenario file?

Since that is possible. Something like this in the macros:

Code: Select all

#define PICK_UP _IMG _X _Y _VERBOSE_MSG _OBJECT_CODE_AND_ACTIONS
    [event]
        name=victory
        [clear_variable]
            name=pickups.generic_flag_{_X}_{_Y}
        [/clear_variable]
    [/event]
    [item]
        image={_IMG}
        x={_X}
        y={_Y}
    [/item]
    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            x={_X}
            y={_Y}
        [/filter]
        {REDRAW}
        [if]
            [variable]
                boolean_equals=no
                name=pickups.generic_flag_{_X}_{_Y}
            [/variable]
            [then]
                [message]
                    speaker=unit
                    message={_VERBOSE_MSG}
                [/message]
                [message]
                    speaker=narrator
                    image=wesnoth-icon.png
                    message= _ "Do you want this unit to pick up this item?"
                    [option]
                        message= _ "Yes"
                        [command]
                            {_OBJECT_CODE_AND_ACTIONS}
                            [+object]
                                [+then]
                                    # Mark object as picked-up; won't happen if the object's filter
                                    # doesn't match primary_unit
                                    [set_variable]
                                        name=pickups.generic_flag_{_X}_{_Y}
                                        value="yes"
                                    [/set_variable]
                                [/then]
                            [/object]
                        [/command]
                    [/option]
                    [option]
                        message= _ "No"
                        [command]
                            [allow_undo]
                            [/allow_undo]
                        [/command]
                    [/option]
                [/message]
            [/then]
        [/if]
    [/event]
#enddef

#define RING_DEFENSE X Y
    {PICK_UP (items/ring-gold.png) ({X}) ({Y})
    ( _ "A gold ring, and there is a inscription on it. 'May enemy attacks shatter upon you like water upon a might rock.'")
    (
        [object]
            image=items/ring-gold.png
            duration=forever

            name= _ "Ring of Impregnable Defense"
            description= _ "+10% defense on all terrains."
            [filter]
                x={X}
                y={Y}
            [/filter]
            [then]
                [remove_item]
                    x,y={X},{Y}
                [/remove_item]
            [/then]
            [effect]
				apply_to=defense
				replace=no
				[defense]
					deep_water=-10%
					shallow_water=-10%
					flat=-10%
					forest=-10%
					frozen=-10%
					desert=-10%
					hills=-10%
					mountains=-10%
					village=-10%
					castle=-10%
					cave=-10%
					fungus=-10%
				[/defense]
            [/effect]
			[effect]
				apply_to=overlay
				add="overlays/armor-icon.png"
			[/effect]				
        [/object]
    )}
#enddef
And then in the scenario file you place it with {RING_DEFENSE 33 70}
Light travels much faster than sound, that's why some people seem bright until you hear them speak.

>>> MY LITTLE LAB! <<<
User avatar
octalot
General Code Maintainer
Posts: 786
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: place item on map instead of in code

Post by octalot »

Do you mean, although there's some WML involved, the location is chosen in the map editor instead of putting the coordinates in to the WML?
map_editor_bloodmoon.png
map_editor_bloodmoon.png (153.99 KiB) Viewed 2335 times
This works in 1.14, in the map editor the labels are placed with the "player start" tool (click "Add", and then type a name that doesn't start with a number). Units then can be placed using "location_id=" instead of "x,y=".

The WML on the back of picture above is:

Code: Select all

  # The dwarvish treasury is accessible via a guarded rope-bridge, which will be cut
  # if a non-flying unit moves on to it.
  #
  # For now let's just cut it when a unit gets close (when it's on the hex
  # before the bridge).  If the trap gets more complex, the player's unit
  # should stop there anyway, and warn that there's a dwarf waiting to cut the
  # bridge.
  [event]
    name=enter hex
    # It will only modify terrain for non-flying heroes, and it makes sense to
    # have the dwarf laugh again every time someone steps on this hex.
    first_time_only=no
    [filter]
      [filter_location]
        location_id=laugh_trigger
      [/filter_location]
      [filter_side]
        team_name=Heroes
      [/filter_side]
    [/filter]
    [if]
      {SXC_CMP unit.movement_costs.unwalkable not_equals 1}
      [have_unit]
        [filter_location]
          location_id=laughing_dwarf
        [/filter_location]
        role=guard
      [/have_unit]
      [then]
        [cancel_action][/cancel_action]
        [terrain]
          terrain="Qxu"
          location_id=trap_bridge
        [/terrain]
        {SXC_REDRAW_TERRAIN}
        [sound]
          name=dwarf-laugh.wav
        [/sound]
        [animate_unit]
          [filter]
            location_id=laughing_dwarf
          [/filter]
          [facing]
            x,y=$x,$y
          [/facing]
          flag=defend
          hits=no
        [/animate_unit]
      [/then]
      [else]
        [allow_undo][/allow_undo]
      [/else]
    [/if]
  [/event]
Post Reply