YAPOG  0.0.1
Yet Another Pokemon Online Game
MapEvent.cpp
Go to the documentation of this file.
8 
9 namespace yap
10 {
12  : boundingBoxes_ ()
13  , conditions_ ()
14  , actions_ ()
15  {
16  }
17 
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 
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 
46  {
47  return new MapEvent (*this);
48  }
49 
51  {
52  for (IMapEventCondition* condition : conditions_)
53  if (!condition->IsValid (args))
54  return false;
55 
56  return HandleCall (actionType, args);
57  }
58 
60  {
61  boundingBoxes_.Add (boundingBox);
62  }
63 
65  {
66  boundingBoxes_.Remove (boundingBox);
67 
68  delete boundingBox;
69  }
70 
72  {
73  conditions_.Add (condition);
74  }
75 
77  {
78  conditions_.Remove (condition);
79 
80  delete condition;
81  }
82 
84  {
85  actions_.Add (action);
86  }
87 
89  {
90  actions_.Remove (action);
91 
92  delete action;
93  }
94 
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 
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 
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