MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AbstractElement_ForkBomb.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  AbstractElement_ForkBomb.h Light cone painting element
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
27 #ifndef ABSTRACTELEMENT_FORKBOMB_H
28 #define ABSTRACTELEMENT_FORKBOMB_H
29 
30 #include "Element.h"
31 #include "EventWindow.h"
32 #include "ElementTable.h"
33 #include "itype.h"
34 
35 namespace MFM
36 {
37 
38 #define FORKBOMBBASE_VERSION 1
39 
40  template <class CC>
41  class AbstractElement_ForkBomb : public Element<CC>
42  {
43  // Extract short names for parameter types
44  typedef typename CC::ATOM_TYPE T;
45  typedef typename CC::PARAM_CONFIG P;
46  enum { R = P::EVENT_WINDOW_RADIUS };
47 
48  private:
49 
50  public:
51 
55  virtual u32 GetBombRange() const = 0;
56 
57  virtual u32 LocalPhysicsColor(const T& atom, u32 selector) const = 0;
58 
59  AbstractElement_ForkBomb(const UUID & uuid) : Element<CC>(uuid)
60  {
61  }
62 
63  virtual u32 PercentMovable(const T& you,
64  const T& me, const SPoint& offset) const
65  {
66  return 100;
67  }
68 
69  virtual u32 DefaultPhysicsColor() const
70  {
71  T temp;
72  return LocalPhysicsColor(temp, 0);
73  }
74 
75  virtual void Behavior(EventWindow<CC>& window) const
76  {
77  const MDist<R> & md = MDist<R>::get();
78  u32 range = GetBombRange();
79  if (range > R)
80  range = R;
81  for (u32 idx = md.GetFirstIndex(1); idx <= md.GetLastIndex(range); ++idx)
82  {
83  const SPoint rel = md.GetPoint(idx);
84  window.SetRelativeAtom(rel, window.GetCenterAtom());
85  }
86  }
87  };
88 }
89 
90 #endif /* ABSTRACTELEMENT_FORKBOMB_H */
u32 GetFirstIndex(const u32 radius) const
Definition: MDist.h:112
virtual u32 DefaultPhysicsColor() const
Definition: AbstractElement_ForkBomb.h:69
Definition: AbstractElement_ForkBomb.h:41
u32 GetLastIndex(const u32 radius) const
Definition: MDist.h:129
virtual u32 LocalPhysicsColor(const T &atom, u32 selector) const =0
virtual void Behavior(EventWindow< CC > &window) const
Definition: AbstractElement_ForkBomb.h:75
const T & GetCenterAtom() const
Definition: EventWindow.h:209
virtual u32 GetBombRange() const =0
Definition: MDist.h:69
static MDist< R > & get()
Definition: MDist.tcc:193
Definition: ElementTable.h:43
Definition: UUID.h:44
virtual u32 PercentMovable(const T &you, const T &me, const SPoint &offset) const
Definition: AbstractElement_ForkBomb.h:63
bool SetRelativeAtom(const SPoint &offset, const T &atom)
Definition: EventWindow.tcc:15
Definition: Atom.h:43