Skip to content

Commit

Permalink
add map location rotate wml interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed May 19, 2014
1 parent aaff4bd commit ab29ba7
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
72 changes: 72 additions & 0 deletions data/test/scenarios/test_relative_dir.cfg
@@ -1,8 +1,41 @@
#define ROTATE_HEX_WITH_TERRAIN terrain
[store_rotate_map_location]
variable="ml"
[source]
x=$center.x
y=$center.y
[/source]
[destination]
x=$ml.x
y=$ml.y
[/destination]
[/store_rotate_map_location]
[terrain_mask]
x=$ml.x
y=$ml.y
mask={terrain}
[/terrain_mask]
#enddef

{GENERIC_UNIT_TEST "test_relative_dir" (
[event]
name=start
[modify_unit]
[filter]
side=1,2
[/filter]
max_moves=100
[/modify_unit]
[/event]

[event]
name=moveto
first_time_only=no

[replace_map]
map = "{test/maps/generic_unit_test.map}"
[/replace_map]

{VARIABLE mode $unit.side}
{VARIABLE_OP mode sub 1}

Expand Down Expand Up @@ -41,5 +74,44 @@
{VARIABLE_OP x add 1}
[/do]
[/while]

{VARIABLE ml.x 7}
{VARIABLE ml.y 5}

{VARIABLE center.x $x1}
{VARIABLE center.y $y1}

{ROTATE_HEX_WITH_TERRAIN "Hd"}
{ROTATE_HEX_WITH_TERRAIN "Hd"}
{ROTATE_HEX_WITH_TERRAIN "Hd"}
{ROTATE_HEX_WITH_TERRAIN "Hd"}
{ROTATE_HEX_WITH_TERRAIN "Hd"}
{ROTATE_HEX_WITH_TERRAIN "Hd"}
{ROTATE_HEX_WITH_TERRAIN "Hd"}

{VARIABLE ml.x 7}
{VARIABLE ml.y 5}

[terrain_mask]
x=$ml.x
y=$ml.y
mask="Hd^Fp"
[/terrain_mask]

{VARIABLE ml.x 11}
{VARIABLE ml.y 5}

{ROTATE_HEX_WITH_TERRAIN "Ai"}
{ROTATE_HEX_WITH_TERRAIN "Ai"}
{ROTATE_HEX_WITH_TERRAIN "Ai"}

{VARIABLE ml.x 11}
{VARIABLE ml.y 5}

[terrain_mask]
x=$ml.x
y=$ml.y
mask="Md"
[/terrain_mask]
[/event]
)}
31 changes: 31 additions & 0 deletions src/game_events/action_wml.cpp
Expand Up @@ -2328,6 +2328,37 @@ WML_HANDLER_FUNCTION(store_relative_dir, /*event_info*/, cfg)
store.as_scalar() = map_location::write_direction(src.get_relative_dir(dst,mode));
}

/// Store the rotation of one hex around another in a WML variable.
/// In increments of 60 degrees, clockwise.
/// This is mainly useful as a diagnostic tool, but could be useful
/// for some kind of scenario.
WML_HANDLER_FUNCTION(store_rotate_map_location, /*event_info*/, cfg)
{
if (!cfg.child("source")) {
WRN_NG << "No source in [store_relative_dir]" << std::endl;
return;
}
if (!cfg.child("destination")) {
WRN_NG << "No destination in [store_relative_dir]" << std::endl;
return;
}
if (!cfg.has_attribute("variable")) {
WRN_NG << "No variable in [store_relative_dir]" << std::endl;
return;
}

const map_location src = cfg_to_loc(cfg.child("source"));
const map_location dst = cfg_to_loc(cfg.child("destination"));

std::string variable = cfg["variable"];
int angle = cfg["angle"].to_int(1);

variable_info store(variable, true, variable_info::TYPE_CONTAINER );

dst.rotate_right_around_center(src,angle).write(store.as_container());
}


/// Store time of day config in a WML variable. This is useful for those who
/// are too lazy to calculate the corresponding time of day for a given turn,
/// or if the turn / time-of-day sequence mutates in a scenario.
Expand Down

0 comments on commit ab29ba7

Please sign in to comment.