YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
MapEvent.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Game/World/Map/MapEvent.hpp
"
2
#include "
YAPOG/Game/World/Map/Physics/BoundingBox.hpp
"
3
#include "
YAPOG/Game/World/Map/IMapEventCondition.hpp
"
4
#include "
YAPOG/Game/World/Map/IMapEventAction.hpp
"
5
#include "
YAPOG/Game/World/Map/Physics/EventBoundingBoxCollection.hpp
"
6
#include "
YAPOG/Game/World/Map/DynamicWorldObject.hpp
"
7
#include "
YAPOG/Game/World/Map/MapEventArgs.hpp
"
8
9
namespace
yap
10
{
11
MapEvent::MapEvent
()
12
: boundingBoxes_ ()
13
, conditions_ ()
14
, actions_ ()
15
{
16
}
17
18
MapEvent::~MapEvent
()
19
{
20
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
21
delete
boundingBox;
22
23
for
(
IMapEventCondition
* condition :
conditions_
)
24
delete
condition;
25
26
for
(
IMapEventAction
* action :
actions_
)
27
delete
action;
28
}
29
30
MapEvent::MapEvent
(
const
MapEvent
& copy)
31
: boundingBoxes_ ()
32
, conditions_ ()
33
, actions_ ()
34
{
35
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
36
AddBoundingBox
(
new
BoundingBox
(*boundingBox));
37
38
for
(
IMapEventCondition
* condition :
conditions_
)
39
AddCondition
(condition->Clone ());
40
41
for
(
IMapEventAction
* action :
actions_
)
42
AddAction
(action->Clone ());
43
}
44
45
MapEvent
*
MapEvent::Clone
()
const
46
{
47
return
new
MapEvent
(*
this
);
48
}
49
50
bool
MapEvent::Call
(
MapEventActionType
actionType,
MapEventArgs
& args)
51
{
52
for
(
IMapEventCondition
* condition :
conditions_
)
53
if
(!condition->IsValid (args))
54
return
false
;
55
56
return
HandleCall
(actionType, args);
57
}
58
59
void
MapEvent::AddBoundingBox
(
BoundingBox
* boundingBox)
60
{
61
boundingBoxes_
.
Add
(boundingBox);
62
}
63
64
void
MapEvent::RemoveBoundingBox
(
BoundingBox
* boundingBox)
65
{
66
boundingBoxes_
.
Remove
(boundingBox);
67
68
delete
boundingBox;
69
}
70
71
void
MapEvent::AddCondition
(
IMapEventCondition
* condition)
72
{
73
conditions_
.
Add
(condition);
74
}
75
76
void
MapEvent::RemoveCondition
(
IMapEventCondition
* condition)
77
{
78
conditions_
.
Remove
(condition);
79
80
delete
condition;
81
}
82
83
void
MapEvent::AddAction
(
IMapEventAction
* action)
84
{
85
actions_
.
Add
(action);
86
}
87
88
void
MapEvent::RemoveAction
(
IMapEventAction
* action)
89
{
90
actions_
.
Remove
(action);
91
92
delete
action;
93
}
94
95
void
MapEvent::AddToEventBoundingBoxCollection
(
96
EventBoundingBoxCollection
& eventBoundingBoxCollection,
97
const
DynamicWorldObject
& parent)
98
{
99
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
100
{
101
parent.
AdjustCollidablePosition
(*boundingBox);
102
eventBoundingBoxCollection.
AddEventBoundingBox
(boundingBox,
this
);
103
}
104
}
105
106
void
MapEvent::RemoveFromEventBoundingBoxCollection
(
107
EventBoundingBoxCollection
& eventBoundingBoxCollection)
108
{
109
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
110
eventBoundingBoxCollection.
RemoveEventBoundingBox
(boundingBox);
111
}
112
113
bool
MapEvent::CollidesWith
(
const
ICollidable
& collidable)
const
114
{
115
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
116
if
(boundingBox->CollidesWith (collidable))
117
return
true
;
118
119
return
false
;
120
}
121
122
bool
MapEvent::HandleCall
(
MapEventActionType
actionType,
MapEventArgs
& args)
123
{
124
bool
successful =
true
;
125
126
for
(
IMapEventAction
* action :
actions_
)
127
{
128
if
(!action->Execute (actionType, args.
GetTrigger
(), args))
129
successful =
false
;
130
}
131
132
return
successful;
133
}
134
}
// namespace yap
YAPOG
src
YAPOG
Game
World
Map
MapEvent.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1