/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2007 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Fabian 'x3n' Landau co-programmer: */ #include "util/loading/load_param.h" #include "util/loading/factory.h" #include "mover_trigger_approach.h" #include "debug.h" ObjectListDefinition(ApproachTrigger); CREATE_FACTORY(ApproachTrigger); ApproachTrigger::ApproachTrigger(const TiXmlElement* root) { PRINTF(0)("13_1 ApproachTrigger %p created\n", this); this->registerObject(this, ApproachTrigger::_objectList); this->toList(OM_ENVIRON); this->onlyHumans = false; this->onlyNPCs = false; this->radius = 0; this->distanceX = 0; this->distanceY = 0; this->distanceZ = 0; if (root != NULL) this->loadParams(root); this->init_post_params(); } void ApproachTrigger::loadParams(const TiXmlElement* root) { PRINTF(0)("13_2 ApproachTrigger loadParams\n", this); MoverTrigger::loadParams(root); LoadParam(root, "radius", this, ApproachTrigger, setRadius) .describe("The radius wherein the player releases the trigger.") .defaultValues(0); LoadParam(root, "distance", this, ApproachTrigger, setDistance) .describe("The distance of all axes wherein the player releases the trigger.") .defaultValues(0, 0, 0); LoadParam(root, "onlyHumans", this, ApproachTrigger, setOnlyHumans) .describe("Only human players can release the trigger.") .defaultValues(false); LoadParam(root, "onlyNPCs", this, ApproachTrigger, setOnlyNPCs) .describe("Only NPCs can release the trigger.") .defaultValues(false); } #include "playable.h" #include "../npcs/generic_npc.h" bool ApproachTrigger::checkIsTriggered() { WorldEntity* entity; float distance; // for all players if (!this->onlyNPCs) { for (ObjectList::const_iterator it = Playable::objectList().begin(); it != Playable::objectList().end(); ++it) { entity = (*it); distance = (this->getAbsCoor() - entity->getAbsCoor()).len(); if (distance <= this->radius || (fabs(this->getAbsCoor().x - entity->getAbsCoor().x) <= this->distanceX && fabs(this->getAbsCoor().y - entity->getAbsCoor().y) <= this->distanceY && fabs(this->getAbsCoor().z - entity->getAbsCoor().z) <= this->distanceZ)) return true; } } // for all npcs if (!this->onlyHumans) { for (ObjectList::const_iterator it = GenericNPC::objectList().begin(); it != GenericNPC::objectList().end(); ++it) { entity = (*it); distance = (this->getAbsCoor() - entity->getAbsCoor()).len(); if (distance <= this->radius || (fabs(this->getAbsCoor().x - entity->getAbsCoor().x) <= this->distanceX && fabs(this->getAbsCoor().y - entity->getAbsCoor().y) <= this->distanceY && fabs(this->getAbsCoor().z - entity->getAbsCoor().z) <= this->distanceZ)) return true; } } return false; }