2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Checks against various objects (Train, SpawnPoint, Teleporter, Trap)
26 * to see if they should be activated. If the
27 * object name matches the link name, it's active status is changed.
28 * @param linkName The name of the link to check against
29 * @param activateMessage The message to display on successful trigger
30 * @param active The new status of the object
32 void activateTrigger(const char *linkName, const char *activateMessage, bool active)
34 if (strcmp(linkName, "@none@") == 0)
37 if (strcmp(linkName, "WATERLEVEL") == 0)
39 int newLevel = atoi(activateMessage);
41 // only if the new level is less than our current level
42 // (ie - raising water up!)
43 if (newLevel < map.waterLevel)
45 map.requiredWaterLevel = atoi(activateMessage);
46 engine.setInfoMessage("Water level is rising", 1, INFO_ACTIVATE);
51 if (strcmp(linkName, "OBSTACLERESET") == 0)
56 Entity *obstacle = (Entity*)map.obstacleList.getHead();
58 while (obstacle->next != NULL)
60 obstacle = (Entity*)obstacle->next;
62 if (strcmp(obstacle->name, activateMessage) == 0)
64 addTeleportParticles(obstacle->x + (obstacle->width / 2), obstacle->y + (obstacle->height / 2), 50, SND_TELEPORT2);
65 obstacle->place(obstacle->tx, obstacle->ty);
66 Math::removeBit(&obstacle->flags, ENT_TELEPORTING);
67 obstacle->dx = obstacle->dy = 0;
68 obstacle->environment = ENV_AIR;
69 addTeleportParticles(obstacle->x + (obstacle->width / 2), obstacle->y + (obstacle->height / 2), 50, SND_TELEPORT2);
73 engine.setInfoMessage("Obstacles Reset", 0, INFO_ACTIVATE);
78 bool linkOkay = false;
80 Train *train = (Train*)map.trainList.getHead();
81 SpawnPoint *sp = (SpawnPoint*)map.spawnList.getHead();
82 Teleporter *tele = (Teleporter*)map.teleportList.getHead();
83 Trap *trap = (Trap*)map.trapList.getHead();
85 while (train->next != NULL)
87 train = (Train*)train->next;
89 if (strcmp(linkName, train->name) == 0)
91 train->active = active;
92 if ((train->active) && (strcmp(activateMessage, "@none@")))
93 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
95 if (train->type != TR_TRAIN)
96 audio.playSound(SND_OPENDOOR, CH_TOUCH, train->x);
102 while (sp->next != NULL)
104 sp = (SpawnPoint*)sp->next;
106 if (strcmp(linkName, sp->name) == 0)
108 sp->active = !sp->active;
109 if ((sp->active) && (strcmp(activateMessage, "@none@")))
110 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
116 while (tele->next != NULL)
118 tele = (Teleporter*)tele->next;
120 if (strcmp(linkName, tele->name) == 0)
122 tele->active = active;
123 if ((tele->active) && (strcmp(activateMessage, "@none@")))
124 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
130 while (trap->next != NULL)
132 trap = (Trap*)trap->next;
134 if (strcmp(linkName, trap->name) == 0)
137 if (strcmp(activateMessage, "@none@"))
138 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
145 showMessageLineDef(linkName, active);
149 debug(("WARNING : No such object '%s'!\n", linkName));