Called to see if a trigger was tripped
| 184 | |
| 185 | // Called to see if a trigger was tripped |
| 186 | void CheckTrigger(int roomnum, int facenum, object *objp, int event_type) { |
| 187 | room *rp = &Rooms[roomnum]; |
| 188 | face *fp = &rp->faces[facenum]; |
| 189 | |
| 190 | ASSERT((event_type == TT_PASS_THROUGH) || (event_type == TT_COLLIDE)); |
| 191 | |
| 192 | if (fp->flags & FF_HAS_TRIGGER) { |
| 193 | trigger *tp; |
| 194 | int type; |
| 195 | |
| 196 | tp = FindTrigger(roomnum, facenum); |
| 197 | ASSERT(tp != NULL); |
| 198 | |
| 199 | if (tp == NULL) { |
| 200 | Int3(); // very bad! Get Matt. |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | // Check for dead or disabled trigger |
| 205 | if (tp->flags & (TF_DISABLED | TF_DEAD)) |
| 206 | return; |
| 207 | |
| 208 | // If portal trigger, make sure this is a pass-through event |
| 209 | if ((fp->portal_num != -1) && (event_type != TT_PASS_THROUGH)) |
| 210 | return; |
| 211 | |
| 212 | // Get the activator type for the object that hit the trigger |
| 213 | switch (objp->type) { |
| 214 | case OBJ_PLAYER: |
| 215 | type = AF_PLAYER; |
| 216 | break; |
| 217 | case OBJ_BUILDING: |
| 218 | case OBJ_ROBOT: |
| 219 | type = AF_ROBOT; |
| 220 | break; |
| 221 | case OBJ_CLUTTER: |
| 222 | type = AF_CLUTTER; |
| 223 | break; |
| 224 | case OBJ_WEAPON: { |
| 225 | object *parent = ObjGetUltimateParent(objp); |
| 226 | int parent_type = parent->type; |
| 227 | if (parent_type == OBJ_PLAYER) |
| 228 | type = AF_PLAYER_WEAPON; |
| 229 | else if (parent_type == OBJ_ROBOT || parent_type == OBJ_BUILDING) |
| 230 | type = AF_ROBOT_WEAPON; |
| 231 | else |
| 232 | return; // unknown parent for weapon |
| 233 | break; |
| 234 | } |
| 235 | default: |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | // Check if this object is a valid activator for this trigger |
| 240 | if (tp->activator & type) { |
| 241 | mprintf(0, "Hit trigger %d\n", tp - Triggers); |
| 242 | |
| 243 | // Execute this trigger's script |
no test coverage detected