2 Copyright (C) 2004 Parallel Realities
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.
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.
13 See the GNU General Public License for more details.
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.
23 void checkSwitchContact(Entity *ent)
25 Switch *swt = (Switch*)map.switchList.getHead();
26 bool okayToActivate = false;
30 while (swt->next != NULL)
32 swt = (Switch*)swt->next;
34 if (swt->type == SWT_USED)
37 if (swt->type == SWT_NORMAL)
39 if ((ent != &player) && (!(ent->flags & ENT_BULLET)))
42 if ((ent->flags & ENT_BULLET) && (ent->id != WP_GRENADES))
46 if ((swt->type == SWT_RESET) && (ent != &player))
49 if ((swt->type == SWT_WATERLEVEL) && (ent != &player))
52 if (Collision::collision(ent, swt))
54 okayToActivate = false;
56 if (strcmp(swt->requiredObjectName, "@none@") == 0)
58 okayToActivate = true;
60 else if (ent == &player)
62 if (carryingItem(swt->requiredObjectName))
64 okayToActivate = true;
66 if (swt->type == SWT_PRESSURE)
68 strncpy(swt->requiredObjectName, "@none@", sizeof swt->requiredObjectName);
71 checkObjectives(swt->name, true);
72 strncpy(swt->name, "Switch", sizeof swt->name);
76 snprintf(message, sizeof message, "%s required", swt->requiredObjectName);
77 engine.setInfoMessage(message, 1, INFO_HINT);
85 if ((swt->type == SWT_NORMAL) || (swt->type == SWT_WATERLEVEL))
87 audio.playSound(SND_SWITCH1, CH_TOUCH);
88 swt->activated = !swt->activated;
89 activateTrigger(swt->linkName, swt->activateMessage, swt->activated);
93 else if (swt->type == SWT_TOGGLE)
95 audio.playSound(SND_SWITCH1, CH_TOUCH);
96 activateTrigger(swt->linkName, swt->activateMessage, !swt->activated);
97 swt->activated = !swt->activated;
99 else if (swt->type == SWT_PRESSURE)
101 audio.playSound(SND_SWITCH1, CH_TOUCH);
102 swt->activated = true;
103 activateTrigger(swt->linkName, swt->activateMessage, true);
106 else if ((swt->type == SWT_TIMED) || (swt->type == SWT_RESET))
108 audio.playSound(SND_SWITCH1, CH_TOUCH);
109 activateTrigger(swt->linkName, swt->activateMessage, true);
110 swt->activated = !swt->activated;
115 if ((swt->type == SWT_TOGGLE) || (swt->type == SWT_PRESSURE))
124 Switch *swt = (Switch*)map.switchList.getHead();
126 int x, y, absX, absY;
128 while (swt->next != NULL)
130 swt = (Switch*)swt->next;
132 x = (int)(swt->x - engine.playerPosX);
133 y = (int)(swt->y - engine.playerPosY);
138 if ((absX < 800) && (absY < 600))
141 graphics.blit(graphics.getSprite("SwitchOff", true)->getCurrentFrame(), x, y, graphics.screen, false);
143 graphics.blit(graphics.getSprite("SwitchOn", true)->getCurrentFrame(), x, y, graphics.screen, false);
146 if ((swt->type != SWT_NORMAL) && (swt->type != SWT_WATERLEVEL) && (swt->type != SWT_USED))
151 if (swt->health == 0)
153 if (swt->type != SWT_TOGGLE)
155 swt->activated = false;
156 activateTrigger(swt->linkName, swt->activateMessage, false);