~ubuntu-branches/ubuntu/oneiric/blobandconquer/oneiric

« back to all changes in this revision

Viewing changes to src/cplusplus/CTrigger.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Guus Sliepen
  • Date: 2008-06-15 12:04:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080615120429-5ss7cbb4z9mpywj5
Tags: 0.95-1
New upstream release. Closes: #486310

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2006 Parallel Realities
 
3
 
 
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.
 
8
 
 
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.
 
12
 
 
13
See the GNU General Public License for more details.
 
14
 
 
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.
 
18
 
 
19
*/
 
20
#include "../headers.h"
 
21
 
 
22
Trigger::Trigger()
 
23
{
 
24
        active = false;
 
25
        
 
26
        type = 0;
 
27
 
 
28
        action = 0;
 
29
        
 
30
        objectiveId = -1;
 
31
        
 
32
        timeLimit = 0;
 
33
        
 
34
        targetValue = 1;
 
35
        
 
36
        specialAction = NULL;
 
37
}
 
38
 
 
39
Trigger::~Trigger()
 
40
{
 
41
}
 
42
 
 
43
void Trigger::addLocationBox(const char *name, Vector position, Vector v)
 
44
{
 
45
        TriggerBoxEntry *entry = new TriggerBoxEntry();
 
46
        
 
47
        entry->name = name;
 
48
        entry->position = position;
 
49
        entry->boundingBox.mins -= v;
 
50
        entry->boundingBox.maxs += v;
 
51
        
 
52
        boundingBoxList.add(entry);
 
53
        
 
54
        debug(("addLocationBox() - Added '%s'\n", name));
 
55
}
 
56
 
 
57
void Trigger::clearLocationBoxes()
 
58
{
 
59
        boundingBoxList.clear();
 
60
}
 
61
 
 
62
void Trigger::assignTriggerLocation()
 
63
{
 
64
        for (TriggerBoxEntry *entry = (TriggerBoxEntry*)boundingBoxList.getFirstElement() ; entry != NULL ; entry = (TriggerBoxEntry*)entry->next)
 
65
        {
 
66
                if (entry->name == name.getText())
 
67
                {
 
68
                        debug(("Trigger::assignTriggerLocation - Assigning box to trigger '%s'\n", name.getText()));
 
69
                        
 
70
                        boundingBox = entry->boundingBox;
 
71
                        position = entry->position;
 
72
                }
 
73
        }
 
74
}
 
75
 
 
76
void Trigger::load(Properties *props)
 
77
{
 
78
        name = props->getString("name", name.getText());
 
79
        targetName = props->getString("targetName", targetName.getText());
 
80
 
 
81
        active = props->getInt("active", active);
 
82
        
 
83
        targetValue = props->getInt("targetValue", targetValue);
 
84
        
 
85
        timeLimit = props->getInt("timeLimit", timeLimit);
 
86
        
 
87
        objectiveId = props->getInt("objectiveId", objectiveId);
 
88
 
 
89
        position = props->getVector("position", position);
 
90
        boundingBox.mins = props->getVector("bbMins", boundingBox.mins);
 
91
        boundingBox.maxs = props->getVector("bbMaxs", boundingBox.maxs);
 
92
}
 
93
 
 
94
void Trigger::save(FILE *fp)
 
95
{
 
96
        Properties props;
 
97
        
 
98
        props.setName("Trigger");
 
99
        
 
100
        props.setProperty("name", name.getText());
 
101
        props.setProperty("targetName", targetName.getText());
 
102
        
 
103
        props.setProperty("active", active);
 
104
        props.setProperty("type", type);
 
105
        
 
106
        props.setProperty("targetValue", targetValue);
 
107
        
 
108
        props.setProperty("timeLimit", timeLimit);
 
109
        
 
110
        props.setProperty("action", action);
 
111
        
 
112
        props.setProperty("objectiveId", objectiveId);
 
113
        
 
114
        props.setProperty("position", position);
 
115
        props.setProperty("bbMins", boundingBox.mins);
 
116
        props.setProperty("bbMaxs", boundingBox.maxs);
 
117
        
 
118
        props.save(fp);
 
119
}
 
120
 
 
121
List Trigger::boundingBoxList;