]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/triggers.cpp
Add doc/samples which more accurately tracks samples origin
[quix0rs-blobwars.git] / src / triggers.cpp
1 /*
2 Copyright (C) 2004-2010 Parallel Realities
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "triggers.h"
22
23 /**
24 * Checks against various objects (Train, SpawnPoint, Teleporter, Trap)
25 * to see if they should be activated. If the
26 * object name matches the link name, it's active status is changed.
27 * @param linkName The name of the link to check against
28 * @param activateMessage The message to display on successful trigger
29 * @param active The new status of the object
30 */
31 void activateTrigger(const char *linkName, const char *activateMessage, bool active)
32 {
33         if (strcmp(linkName, "@none@") == 0)
34                 return;
35                 
36         if (strcmp(linkName, "WATERLEVEL") == 0)
37         {
38                 int newLevel = atoi(activateMessage);
39                 
40                 // only if the new level is less than our current level
41                 // (ie - raising water up!)
42                 if (newLevel < map.waterLevel)
43                 {
44                         map.requiredWaterLevel = atoi(activateMessage);
45                         engine.setInfoMessage("Water level is rising", 1, INFO_ACTIVATE);
46                 }
47                 return;
48         }
49
50         if (strcmp(linkName, "OBSTACLERESET") == 0)
51         {
52                 if (!active)
53                         return;
54
55                 Entity *obstacle = (Entity*)map.obstacleList.getHead();
56
57                 while (obstacle->next != NULL)
58                 {
59                         obstacle = (Entity*)obstacle->next;
60
61                         if (strcmp(obstacle->name, activateMessage) == 0)
62                         {
63                                 addTeleportParticles(obstacle->x + (obstacle->width / 2), obstacle->y + (obstacle->height / 2), 50, SND_TELEPORT2);
64                                 obstacle->place(obstacle->tx, obstacle->ty);
65                                 Math::removeBit(&obstacle->flags, ENT_TELEPORTING);
66                                 obstacle->dx = obstacle->dy = 0;
67                                 obstacle->environment = ENV_AIR;
68                                 addTeleportParticles(obstacle->x + (obstacle->width / 2), obstacle->y + (obstacle->height / 2), 50, SND_TELEPORT2);
69                         }
70                 }
71
72                 engine.setInfoMessage("Obstacles Reset", 0, INFO_ACTIVATE);
73
74                 return;
75         }
76
77         bool linkOkay = false;
78
79         Train *train = (Train*)map.trainList.getHead();
80         SpawnPoint *sp = (SpawnPoint*)map.spawnList.getHead();
81         Teleporter *tele = (Teleporter*)map.teleportList.getHead();
82         Trap *trap = (Trap*)map.trapList.getHead();
83
84         while (train->next != NULL)
85         {
86                 train = (Train*)train->next;
87
88                 if (strcmp(linkName, train->name) == 0)
89                 {
90                         train->active = active;
91                         if ((train->active) && (strcmp(activateMessage, "@none@")))
92                                 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
93
94                         if (train->type != TR_TRAIN)
95                                 audio.playSound(SND_OPENDOOR, CH_TOUCH);
96
97                         linkOkay = true;
98                 }
99         }
100
101         while (sp->next != NULL)
102         {
103                 sp = (SpawnPoint*)sp->next;
104
105                 if (strcmp(linkName, sp->name) == 0)
106                 {
107                         sp->active = !sp->active;
108                         if ((sp->active) && (strcmp(activateMessage, "@none@")))
109                                 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
110
111                         linkOkay = true;
112                 }
113         }
114
115         while (tele->next != NULL)
116         {
117                 tele = (Teleporter*)tele->next;
118
119                 if (strcmp(linkName, tele->name) == 0)
120                 {
121                         tele->active = active;
122                         if ((tele->active) && (strcmp(activateMessage, "@none@")))
123                                 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
124
125                         linkOkay = true;
126                 }
127         }
128
129         while (trap->next != NULL)
130         {
131                 trap = (Trap*)trap->next;
132
133                 if (strcmp(linkName, trap->name) == 0)
134                 {
135                         toggleTrap(trap);
136                         if (strcmp(activateMessage, "@none@"))
137                                 engine.setInfoMessage(activateMessage, 1, INFO_ACTIVATE);
138                         linkOkay = true;
139                 }
140         }
141
142         if (linkOkay)
143         {
144                 showMessageLineDef(linkName, active);
145         }
146         else
147         {
148                 debug(("WARNING : No such object '%s'!\n", linkName));
149         }
150 }