MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Element_ForkBomb3.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  Element_ForkBomb3.h Randomized 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 ELEMENT_FORKBOMB3_H
28 #define ELEMENT_FORKBOMB3_H
29 
30 #include "Element.h"
31 #include "EventWindow.h"
32 #include "ElementTable.h"
34 #include "itype.h"
35 
36 namespace MFM
37 {
38 
39 #define FORKBOMB3_VERSION 1
40 
41  template <class CC>
43  {
44  // Extract short names for parameter types
45  typedef typename CC::ATOM_TYPE T;
46  typedef typename CC::PARAM_CONFIG P;
47  enum { R = P::EVENT_WINDOW_RADIUS };
48 
49  private:
50 
51  ElementParameterS32<CC> m_bombCount;
52 
53  public:
54 
55  static Element_ForkBomb3 THE_INSTANCE;
56 
57  virtual u32 GetBombRange() const
58  {
59  return (u32) m_bombCount.GetValue(); // Um, not really
60  }
61 
63  AbstractElement_ForkBomb<CC>(MFM_UUID_FOR("BombYellow", FORKBOMB3_VERSION)),
64  m_bombCount(this, "count", "Bomb Count",
65  "Number of bombs randomly dropped each bomb event",
66  0, 10, 30/*, 1*/)
67 
68  {
70  Element<CC>::SetName("Yellow Fork Bomb");
71  }
72 
73  virtual u32 LocalPhysicsColor(const T& atom, u32 selector) const
74  {
75  return 0xffcccc00;
76  }
77 
78  virtual void Behavior(EventWindow<CC>& window) const
79  {
80  Random & random = window.GetRandom();
81  const MDist<R> & md = MDist<R>::get();
82  const u32 loIdx = md.GetFirstIndex(1);
83  const u32 hiIdx = md.GetLastIndex(R);
84  for (u32 i = 0; i < (u32) m_bombCount.GetValue(); ++i)
85  {
86  u32 idx = random.Between(loIdx,hiIdx);
87  window.SetRelativeAtom(md.GetPoint(idx), window.GetCenterAtom());
88  }
89  }
90 
91  };
92 
93  template <class CC>
94  Element_ForkBomb3<CC> Element_ForkBomb3<CC>::THE_INSTANCE;
95 
96 }
97 
98 #endif /* ELEMENT_FORKBOMB3_H */
u32 GetFirstIndex(const u32 radius) const
Definition: MDist.h:112
Definition: AbstractElement_ForkBomb.h:41
Definition: Random.h:45
u32 GetLastIndex(const u32 radius) const
Definition: MDist.h:129
virtual u32 GetBombRange() const
Definition: Element_ForkBomb3.h:57
void SetName(const char *name)
Definition: Element.h:209
void SetAtomicSymbol(const char *symbol)
Definition: Element.h:193
Random & GetRandom()
Definition: EventWindow.h:122
Definition: Parameter.h:593
const T & GetCenterAtom() const
Definition: EventWindow.h:209
virtual void Behavior(EventWindow< CC > &window) const
Definition: Element_ForkBomb3.h:78
Definition: MDist.h:69
static MDist< R > & get()
Definition: MDist.tcc:193
s32 Between(s32 min, s32 max)
Definition: Random.h:188
Definition: ElementTable.h:43
virtual u32 LocalPhysicsColor(const T &atom, u32 selector) const
Definition: Element_ForkBomb3.h:73
bool SetRelativeAtom(const SPoint &offset, const T &atom)
Definition: EventWindow.tcc:15
Definition: Element_ForkBomb3.h:42