1 /*
2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
4
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.
9
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.
13
14 See the GNU General Public License for more details.
15
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.
19
20 */
21
22 #include "triggers.h"
23
24 /**
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
31 */
activateTrigger(const char * linkName,const char * activateMessage,bool active)32 void activateTrigger(const char *linkName, const char *activateMessage, bool active)
33 {
34 if (strcmp(linkName, "@none@") == 0)
35 return;
36
37 if (strcmp(linkName, "WATERLEVEL") == 0)
38 {
39 int newLevel = atoi(activateMessage);
40
41 // only if the new level is less than our current level
42 // (ie - raising water up!)
43 if (newLevel < map.waterLevel)
44 {
45 map.requiredWaterLevel = atoi(activateMessage);
46 engine.setInfoMessage("Water level is rising", 1, INFO_ACTIVATE);
47 }
48 return;
49 }
50
51 if (strcmp(linkName, "OBSTACLERESET") == 0)
52 {
53 if (!active)
54 return;
55
56 Entity *obstacle = (Entity*)map.obstacleList.getHead();
57
58 while (obstacle->next != NULL)
59 {
60 obstacle = (Entity*)obstacle->next;
61
62 if (strcmp(obstacle->name, activateMessage) == 0)
63 {
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);
70 }
71 }
72
73 engine.setInfoMessage("Obstacles Reset", 0, INFO_ACTIVATE);
74
75 return;
76 }
77
78 bool linkOkay = false;
79
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();
84
85 while (train->next != NULL)
86 {
87 train = (Train*)train->next;
88
89 if (strcmp(linkName, train->name) == 0)
90 {
91 train->active = active;
92 if ((train->active) && (strcmp(activateMessage, "@none@")))
93 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
94
95 if (train->type != TR_TRAIN)
96 audio.playSound(SND_OPENDOOR, CH_TOUCH, train->x);
97
98 linkOkay = true;
99 }
100 }
101
102 while (sp->next != NULL)
103 {
104 sp = (SpawnPoint*)sp->next;
105
106 if (strcmp(linkName, sp->name) == 0)
107 {
108 sp->active = !sp->active;
109 if ((sp->active) && (strcmp(activateMessage, "@none@")))
110 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
111
112 linkOkay = true;
113 }
114 }
115
116 while (tele->next != NULL)
117 {
118 tele = (Teleporter*)tele->next;
119
120 if (strcmp(linkName, tele->name) == 0)
121 {
122 tele->active = active;
123 if ((tele->active) && (strcmp(activateMessage, "@none@")))
124 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
125
126 linkOkay = true;
127 }
128 }
129
130 while (trap->next != NULL)
131 {
132 trap = (Trap*)trap->next;
133
134 if (strcmp(linkName, trap->name) == 0)
135 {
136 toggleTrap(trap);
137 if (strcmp(activateMessage, "@none@"))
138 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
139 linkOkay = true;
140 }
141 }
142
143 if (linkOkay)
144 {
145 showMessageLineDef(linkName, active);
146 }
147 else
148 {
149 debug(("WARNING : No such object '%s'!\n", linkName));
150 }
151 }
152