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.
24 void checkSwitchContact(Entity *ent)
26 Switch *swt = (Switch*)map.switchList.getHead();
27 bool okayToActivate = false;
31 while (swt->next != NULL)
33 swt = (Switch*)swt->next;
35 if (swt->type == SWT_USED)
38 if (swt->type == SWT_NORMAL)
40 if ((ent != &player) && (!(ent->flags & ENT_BULLET)))
43 if ((ent->flags & ENT_BULLET) && (ent->id != WP_GRENADES))
47 if ((swt->type == SWT_RESET) && (ent != &player))
50 if ((swt->type == SWT_WATERLEVEL) && (ent != &player))
53 if (Collision::collision(ent, swt))
55 okayToActivate = false;
57 if (strcmp(swt->requiredObjectName, "@none@") == 0)
59 okayToActivate = true;
61 else if (ent == &player)
63 if (carryingItem(swt->requiredObjectName))
65 okayToActivate = true;
67 if (swt->type == SWT_PRESSURE)
69 strlcpy(swt->requiredObjectName, "@none@", sizeof swt->requiredObjectName);
72 checkObjectives(swt->name, true);
73 strlcpy(swt->name, "Switch", sizeof swt->name);
77 snprintf(message, sizeof message, "%s required", swt->requiredObjectName);
78 engine.setInfoMessage(message, 1, INFO_HINT);
86 if ((swt->type == SWT_NORMAL) || (swt->type == SWT_WATERLEVEL))
88 audio.playSound(SND_SWITCH1, CH_TOUCH, swt->x);
89 swt->activated = !swt->activated;
90 activateTrigger(swt->linkName, swt->activateMessage, swt->activated);
94 else if (swt->type == SWT_TOGGLE)
96 audio.playSound(SND_SWITCH1, CH_TOUCH, swt->x);
97 activateTrigger(swt->linkName, swt->activateMessage, !swt->activated);
98 swt->activated = !swt->activated;
100 else if (swt->type == SWT_PRESSURE)
102 audio.playSound(SND_SWITCH1, CH_TOUCH, swt->x);
103 swt->activated = true;
104 activateTrigger(swt->linkName, swt->activateMessage, true);
107 else if ((swt->type == SWT_TIMED) || (swt->type == SWT_RESET))
109 audio.playSound(SND_SWITCH1, CH_TOUCH, swt->x);
110 activateTrigger(swt->linkName, swt->activateMessage, true);
111 swt->activated = !swt->activated;
116 if ((swt->type == SWT_TOGGLE) || (swt->type == SWT_PRESSURE))
125 Switch *swt = (Switch*)map.switchList.getHead();
127 int x, y, absX, absY;
129 while (swt->next != NULL)
131 swt = (Switch*)swt->next;
133 x = (int)(swt->x - engine.playerPosX);
134 y = (int)(swt->y - engine.playerPosY);
139 if ((absX < 800) && (absY < 600))
142 graphics.blit(graphics.getSprite("SwitchOff", true)->getCurrentFrame(), x, y, graphics.screen, false);
144 graphics.blit(graphics.getSprite("SwitchOn", true)->getCurrentFrame(), x, y, graphics.screen, false);
147 if ((swt->type != SWT_NORMAL) && (swt->type != SWT_WATERLEVEL) && (swt->type != SWT_USED))
152 if (swt->health == 0)
154 if (swt->type != SWT_TOGGLE)
156 swt->activated = false;
157 activateTrigger(swt->linkName, swt->activateMessage, false);