Skip to content

Commit 5f46790

Browse files
committed
EventManager: Add 'mapmod_toggle' property
Just like mapmod, but switches between 2 tiles. Great for switch puzzles!
1 parent 77edee7 commit 5f46790

File tree

7 files changed

+97
-10
lines changed

7 files changed

+97
-10
lines changed

RELEASE_NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Engine features:
5858
* Added 'class_tip' and 'show_class_tip' properties to new game menu config.
5959
* Added 'show_frame_background' property to configuration, new game, and load game menu configs.
6060
* Added 'ignore_resist' property to powers/effects.txt config.
61+
* Added 'mapmod_toggle' property to Events.
6162
* Support navigating "multi-page" books with left/right inputs when possible.
6263
* Android: Enabled use of external input devices (gamepads, keyboards, mice)
6364

docs/attribute-reference.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ <h4>EventManager</h4>
614614

615615
<p><strong>event.mapmod</strong> | <code>list(predefined_string, int, int, int) : Layer, X, Y, Tile ID</code> | Modify map tiles</p>
616616

617+
<p><strong>event.mapmod_toggle</strong> | <code>list(predefined_string, int, int, int, int) : Layer, X, Y, Tile ID A, Tile ID B</code> | Same as mapmod, except this will alternate between two tile IDs.</p>
618+
617619
<p><strong>event.soundfx</strong> | <code>filename, int, int, bool : Sound file, X, Y, loop</code> | Filename of a sound to play. Optionally, it can be played at a specific location and/or looped. Note: Sounds attached to 'on_load' events will loop by default.</p>
618620

619621
<p><strong>event.loot</strong> | <code>list(loot)</code> | Add loot to the event.</p>
@@ -2026,6 +2028,8 @@ <h4>PowerManager: Effects</h4>
20262028

20272029
<p><strong>effect.attack_speed_anim</strong> | <code>string</code> | If the type of Effect is attack_speed, this defines the attack animation that will have its speed changed.</p>
20282030

2031+
<p><strong>effect.ignore_resist</strong> | <code>bool</code> | If true, this effect will ignore the target's effect resistance stats (not to be confused with elemental/damage type resistances).</p>
2032+
20292033
<hr />
20302034

20312035
<h4>PowerManager: Powers</h4>

src/EventManager.cpp

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,33 @@ bool EventManager::loadEventComponentString(std::string &key, std::string &val,
287287
}
288288
}
289289
}
290+
else if (key == "mapmod_toggle") {
291+
// @ATTR event.mapmod_toggle|list(predefined_string, int, int, int, int) : Layer, X, Y, Tile ID A, Tile ID B|Same as mapmod, except this will alternate between two tile IDs.
292+
e->type = EventComponent::MAPMOD_TOGGLE;
293+
294+
e->s = Parse::popFirstString(val);
295+
e->data[0].Int = Parse::popFirstInt(val);
296+
e->data[1].Int = Parse::popFirstInt(val);
297+
e->data[2].Int = Parse::popFirstInt(val);
298+
e->data[3].Int = Parse::popFirstInt(val);
299+
300+
// add repeating mapmods
301+
if (evnt) {
302+
std::string repeat_val = Parse::popFirstString(val);
303+
while (repeat_val != "") {
304+
evnt->components.push_back(EventComponent());
305+
e = &evnt->components.back();
306+
e->type = EventComponent::MAPMOD_TOGGLE;
307+
e->s = repeat_val;
308+
e->data[0].Int = Parse::popFirstInt(val);
309+
e->data[1].Int = Parse::popFirstInt(val);
310+
e->data[2].Int = Parse::popFirstInt(val);
311+
e->data[3].Int = Parse::popFirstInt(val);
312+
313+
repeat_val = Parse::popFirstString(val);
314+
}
315+
}
316+
}
290317
else if (key == "soundfx") {
291318
// @ATTR event.soundfx|filename, int, int, bool : Sound file, X, Y, loop|Filename of a sound to play. Optionally, it can be played at a specific location and/or looped. Note: Sounds attached to 'on_load' events will loop by default.
292319
e->type = EventComponent::SOUNDFX;
@@ -994,24 +1021,70 @@ bool EventManager::executeEventInternal(Event &ev, bool skip_delay) {
9941021
mapr->teleport_destination.y = static_cast<float>(ec->data[1].Int) + 0.5f;
9951022
}
9961023
else if (ec->type == EventComponent::MAPMOD) {
1024+
int tile_x = ec->data[0].Int;
1025+
int tile_y = ec->data[1].Int;
1026+
unsigned short tile_id = static_cast<unsigned short>(ec->data[2].Int);
1027+
9971028
if (ec->s == "collision") {
998-
if (ec->data[0].Int >= 0 && ec->data[0].Int < mapr->w && ec->data[1].Int >= 0 && ec->data[1].Int < mapr->h) {
999-
mapr->collider.colmap[ec->data[0].Int][ec->data[1].Int] = static_cast<unsigned short>(ec->data[2].Int);
1029+
if (tile_x >= 0 && tile_x < mapr->w && tile_y >= 0 && tile_y < mapr->h) {
1030+
mapr->collider.colmap[tile_x][tile_y] = tile_id;
10001031
mapr->map_change = true;
10011032
}
10021033
else
1003-
Utils::logError("EventManager: Mapmod at position (%d, %d) is out of bounds 0-255.", ec->data[0].Int, ec->data[1].Int);
1034+
Utils::logError("EventManager: Mapmod at position (%d, %d) is out of bounds 0-255.", tile_x, tile_y);
10041035
}
10051036
else {
10061037
size_t index = static_cast<size_t>(distance(mapr->layernames.begin(), find(mapr->layernames.begin(), mapr->layernames.end(), ec->s)));
1007-
if (!mapr->isValidTile(ec->data[2].Int))
1008-
Utils::logError("EventManager: Mapmod at position (%d, %d) contains invalid tile id (%d).", ec->data[0].Int, ec->data[1].Int, ec->data[2].Int);
1038+
if (!mapr->isValidTile(tile_id))
1039+
Utils::logError("EventManager: Mapmod at position (%d, %d) contains invalid tile id (%d).", tile_x, tile_y, tile_id);
10091040
else if (index >= mapr->layers.size())
1010-
Utils::logError("EventManager: Mapmod at position (%d, %d) is on an invalid layer.", ec->data[0].Int, ec->data[1].Int);
1011-
else if (ec->data[0].Int >= 0 && ec->data[0].Int < mapr->w && ec->data[1].Int >= 0 && ec->data[1].Int < mapr->h)
1012-
mapr->layers[index][ec->data[0].Int][ec->data[1].Int] = static_cast<unsigned short>(ec->data[2].Int);
1041+
Utils::logError("EventManager: Mapmod at position (%d, %d) is on an invalid layer.", tile_x, tile_y);
1042+
else if (tile_x >= 0 && tile_x < mapr->w && tile_y >= 0 && tile_y < mapr->h)
1043+
mapr->layers[index][tile_x][tile_y] = tile_id;
1044+
else
1045+
Utils::logError("EventManager: Mapmod at position (%d, %d) is out of bounds 0-255.", tile_x, tile_y);
1046+
}
1047+
}
1048+
else if (ec->type == EventComponent::MAPMOD_TOGGLE) {
1049+
int tile_x = ec->data[0].Int;
1050+
int tile_y = ec->data[1].Int;
1051+
unsigned short tile_a = static_cast<unsigned short>(ec->data[2].Int);
1052+
unsigned short tile_b = static_cast<unsigned short>(ec->data[3].Int);
1053+
1054+
if (ec->s == "collision") {
1055+
if (tile_x >= 0 && tile_x < mapr->w && tile_y >= 0 && tile_y < mapr->h) {
1056+
unsigned short &map_tile = mapr->collider.colmap[tile_x][tile_y];
1057+
if (map_tile == tile_a) {
1058+
map_tile = tile_b;
1059+
mapr->map_change = true;
1060+
}
1061+
else if (map_tile == tile_b) {
1062+
map_tile = tile_a;
1063+
mapr->map_change = true;
1064+
}
1065+
}
1066+
else
1067+
Utils::logError("EventManager: Mapmod at position (%d, %d) is out of bounds 0-255.", tile_x, tile_y);
1068+
}
1069+
else {
1070+
size_t index = static_cast<size_t>(distance(mapr->layernames.begin(), find(mapr->layernames.begin(), mapr->layernames.end(), ec->s)));
1071+
if (!mapr->isValidTile(tile_a))
1072+
Utils::logError("EventManager: Mapmod at position (%d, %d) contains invalid tile id (%d).", tile_x, tile_y, tile_a);
1073+
else if (!mapr->isValidTile(tile_b))
1074+
Utils::logError("EventManager: Mapmod at position (%d, %d) contains invalid tile id (%d).", tile_x, tile_y, tile_b);
1075+
else if (index >= mapr->layers.size())
1076+
Utils::logError("EventManager: Mapmod at position (%d, %d) is on an invalid layer.", tile_x, tile_y);
1077+
else if (tile_x >= 0 && tile_x < mapr->w && tile_y >= 0 && tile_y < mapr->h) {
1078+
unsigned short &map_tile = mapr->layers[index][tile_x][tile_y];
1079+
if (map_tile == tile_a) {
1080+
map_tile = tile_b;
1081+
}
1082+
else if (map_tile == tile_b) {
1083+
map_tile = tile_a;
1084+
}
1085+
}
10131086
else
1014-
Utils::logError("EventManager: Mapmod at position (%d, %d) is out of bounds 0-255.", ec->data[0].Int, ec->data[1].Int);
1087+
Utils::logError("EventManager: Mapmod at position (%d, %d) is out of bounds 0-255.", tile_x, tile_y);
10151088
}
10161089
}
10171090
else if (ec->type == EventComponent::SOUNDFX) {

src/EventManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class EventComponent {
3737
INTERMAP_ID,
3838
INTRAMAP,
3939
MAPMOD,
40+
MAPMOD_TOGGLE,
4041
SOUNDFX,
4142
LOOT,
4243
LOOT_COUNT,

src/Map.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,10 @@ void Map::copyMapObjects(Map* src, Chunk* chunk, size_t src_x, size_t src_y, siz
15481548
ec->data[0].Int += static_cast<int>(x_offset);
15491549
ec->data[1].Int += static_cast<int>(y_offset);
15501550
}
1551+
else if (ec->type == EventComponent::MAPMOD_TOGGLE) {
1552+
ec->data[0].Int += static_cast<int>(x_offset);
1553+
ec->data[1].Int += static_cast<int>(y_offset);
1554+
}
15511555
else if (ec->type == EventComponent::SOUNDFX) {
15521556
// make sure we handle sounds that aren't positional
15531557
if (!(ec->data[0].Int == -1 && ec->data[1].Int == -1) && !(ec->data[0].Int == 0 && ec->data[1].Int == 0)) {

src/MapSaver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ MapSaver::MapSaver(Map *_map) : map(_map) {
3636
EVENT_COMPONENT_NAME[EventComponent::INTERMAP_ID] = "intermap_id";
3737
EVENT_COMPONENT_NAME[EventComponent::INTRAMAP] = "intramap";
3838
EVENT_COMPONENT_NAME[EventComponent::MAPMOD] = "mapmod";
39+
EVENT_COMPONENT_NAME[EventComponent::MAPMOD_TOGGLE] = "mapmod_toggle";
3940
EVENT_COMPONENT_NAME[EventComponent::SOUNDFX] = "soundfx";
4041
EVENT_COMPONENT_NAME[EventComponent::LOOT] = "loot"; // HALF-IMPLEMENTED
4142
EVENT_COMPONENT_NAME[EventComponent::LOOT_COUNT] = "loot_count";
@@ -517,6 +518,9 @@ void MapSaver::writeEventComponents(std::ofstream &map_file, int eventID) {
517518
else if (e.type == EventComponent::MAPMOD) {
518519
map_file << e.s << "," << e.data[0].Int << "," << e.data[1].Int << "," << e.data[2].Int << std::endl;
519520
}
521+
else if (e.type == EventComponent::MAPMOD_TOGGLE) {
522+
map_file << e.s << "," << e.data[0].Int << "," << e.data[1].Int << "," << e.data[2].Int << "," << e.data[3].Int << std::endl;
523+
}
520524
else if (e.type == EventComponent::SOUNDFX) {
521525
map_file << e.s;
522526
if (e.data[0].Int != -1 && e.data[1].Int != -1)

src/Version.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/
3030

3131
#include <SDL.h>
3232

33-
Version VersionInfo::ENGINE(1, 14, 253);
33+
Version VersionInfo::ENGINE(1, 14, 254);
3434
Version VersionInfo::MIN(0, 0, 0);
3535
Version VersionInfo::MAX(USHRT_MAX, USHRT_MAX, USHRT_MAX);
3636

0 commit comments

Comments
 (0)