Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/contentcreation/pps/FabianLandau/mover/environments/mover_trigger_approach.cc @ 4855

Last change on this file since 4855 was 4844, checked in by landauf, 17 years ago
File size: 3.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2007 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Fabian 'x3n' Landau
13   co-programmer:
14*/
15
16#include "util/loading/load_param.h"
17#include "util/loading/factory.h"
18#include "mover_trigger_approach.h"
19#include "debug.h"
20
21ObjectListDefinition(ApproachTrigger);
22CREATE_FACTORY(ApproachTrigger);
23
24
25ApproachTrigger::ApproachTrigger(const TiXmlElement* root)
26{
27    PRINTF(0)("13_1 ApproachTrigger %p created\n", this);
28    this->registerObject(this, ApproachTrigger::_objectList);
29    this->toList(OM_ENVIRON);
30
31    this->onlyHumans = false;
32    this->onlyNPCs =  false;
33    this->radius = 0;
34    this->distanceX = 0;
35    this->distanceY = 0;
36    this->distanceZ = 0;
37
38    if (root != NULL)
39        this->loadParams(root);
40
41    this->init_post_params();
42}
43
44void ApproachTrigger::loadParams(const TiXmlElement* root)
45{
46    PRINTF(0)("13_2 ApproachTrigger loadParams\n", this);
47    MoverTrigger::loadParams(root);
48
49    LoadParam(root, "radius", this, ApproachTrigger, setRadius)
50        .describe("The radius wherein the player releases the trigger.")
51        .defaultValues(0);
52    LoadParam(root, "distance", this, ApproachTrigger, setDistance)
53        .describe("The distance of all axes wherein the player releases the trigger.")
54        .defaultValues(0, 0, 0);
55    LoadParam(root, "onlyHumans", this, ApproachTrigger, setOnlyHumans)
56        .describe("Only human players can release the trigger.")
57        .defaultValues(false);
58    LoadParam(root, "onlyNPCs", this, ApproachTrigger, setOnlyNPCs)
59        .describe("Only NPCs can release the trigger.")
60        .defaultValues(false);
61}
62
63#include "playable.h"
64#include "../npcs/generic_npc.h"
65
66bool ApproachTrigger::checkIsTriggered()
67{
68    WorldEntity* entity;
69    float distance;
70
71    // for all players
72    if (!this->onlyNPCs)
73    {
74        for (ObjectList<Playable>::const_iterator it = Playable::objectList().begin();
75            it != Playable::objectList().end();
76            ++it)
77        {
78            entity = (*it);
79            distance = (this->getAbsCoor() - entity->getAbsCoor()).len();
80            if (distance <= this->radius
81                || (fabs(this->getAbsCoor().x - entity->getAbsCoor().x) <= this->distanceX
82                    && fabs(this->getAbsCoor().y - entity->getAbsCoor().y) <= this->distanceY
83                    && fabs(this->getAbsCoor().z - entity->getAbsCoor().z) <= this->distanceZ))
84                return true;
85        }
86    }
87
88    // for all npcs
89    if (!this->onlyHumans)
90    {
91        for (ObjectList<GenericNPC>::const_iterator it = GenericNPC::objectList().begin();
92            it != GenericNPC::objectList().end();
93            ++it)
94        {
95            entity = (*it);
96            distance = (this->getAbsCoor() - entity->getAbsCoor()).len();
97            if (distance <= this->radius
98                || (fabs(this->getAbsCoor().x - entity->getAbsCoor().x) <= this->distanceX
99                    && fabs(this->getAbsCoor().y - entity->getAbsCoor().y) <= this->distanceY
100                    && fabs(this->getAbsCoor().z - entity->getAbsCoor().z) <= this->distanceZ))
101                return true;
102        }
103    }
104   
105    return false;
106}
Note: See TracBrowser for help on using the repository browser.