MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Element_Dreg.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  Element_Dreg.h Basic dynamic regulating 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 
28 #ifndef ELEMENT_DREG_H
29 #define ELEMENT_DREG_H
30 
31 #include "Element.h"
32 #include "EventWindow.h"
33 #include "ElementTable.h"
34 #include "itype.h"
35 #include "P0Atom.h"
36 #include "P1Atom.h"
37 #include "P3Atom.h"
38 #include "Element_Res.h" /* For Element_Res::TYPE */
39 #include "Element_Wall.h" /* For Element_Wall::TYPE */
40 
41 namespace MFM
42 {
43 
44 #define DREG_VERSION 1
45 
46  template <class CC>
47  class Element_Dreg : public Element<CC>
48  {
49  // Extract short names for parameter types
50  typedef typename CC::ATOM_TYPE T;
51  typedef typename CC::PARAM_CONFIG P;
52  enum { R = P::EVENT_WINDOW_RADIUS };
53 
54  private:
55 
56  ElementParameterS32<CC> m_resOdds;
57  ElementParameterS32<CC> m_deleteOdds;
58  ElementParameterS32<CC> m_dregCreateOdds;
59  ElementParameterS32<CC> m_dregDeleteOdds;
60 
61  public:
62 
63  static Element_Dreg THE_INSTANCE;
64 
65  Element_Dreg()
66  : Element<CC>(MFM_UUID_FOR("Dreg", DREG_VERSION)),
67  m_resOdds(this, "res", "Res Spawn Odds", "Chance of filling an empty site with a Res", 1, 200, 1000/*, 10*/),
68  m_deleteOdds(this, "del", "Delete Odds", "Chance of deleting an adjacent non-empty non-Dreg", 1, 100, 1000/*, 10*/),
69  m_dregCreateOdds(this, "dreg", "Dreg Spawn Odds", "Chance of filling an empty site with a Dreg", 1, 500, 1000/*, 10*/),
70  m_dregDeleteOdds(this, "ddreg", "Delete Dreg Odds", "Chance of deleting an adjacent Dreg", 1, 50, 1000/*, 10*/)
71  {
73  Element<CC>::SetName("Dreg");
74  }
75 
76  virtual u32 PercentMovable(const T& you,
77  const T& me, const SPoint& offset) const
78  {
79  return 100;
80  }
81 
82  virtual u32 DefaultPhysicsColor() const
83  {
84  return 0xff505050;
85  }
86 
87  virtual u32 DefaultLowlightColor() const
88  {
89  return 0xff282828;
90  }
91 
92  virtual const char* GetDescription() const
93  {
94  return "Short for \"Dynamic Regulator\", This Atom controls the density of "
95  "nearby Atoms by creating RES atoms and deleting nearby atoms.";
96  }
97 
98  virtual void Behavior(EventWindow<CC>& window) const
99  {
100  Random & random = window.GetRandom();
101 
102  SPoint dir;
103  MDist<R>::get().FillRandomSingleDir(dir, random);
104 
105  if (window.IsLiveSite(dir))
106  {
107  T atom = window.GetRelativeAtom(dir);
108  u32 oldType = atom.GetType();
109 
111  {
112  if(random.OneIn(m_dregCreateOdds.GetValue()))
113  {
115  }
116  else if(random.OneIn(m_resOdds.GetValue()))
117  {
119  }
120  }
121  else if(oldType == Element_Dreg::THE_INSTANCE.GetType())
122  {
123  if(random.OneIn(m_dregDeleteOdds.GetValue()))
124  {
126  }
127  }
128  else if(oldType != Element_Wall<CC>::TYPE() && random.OneIn(m_dregDeleteOdds.GetValue()))
129  {
131  }
132 
133  if(atom.GetType() != oldType)
134  {
135  window.SetRelativeAtom(dir, atom);
136  }
137  }
138  this->Diffuse(window);
139  }
140  };
141 
142  template <class CC>
143  Element_Dreg<CC> Element_Dreg<CC>::THE_INSTANCE;
144 
145 }
146 
147 #endif /* ELEMENT_DREG_H */
void Diffuse(EventWindow< CC > &window) const
Definition: Element.tcc:73
u32 GetType() const
Definition: Element.h:290
Definition: Element_Empty.h:41
Definition: Random.h:45
virtual u32 PercentMovable(const T &you, const T &me, const SPoint &offset) const
Definition: Element_Dreg.h:76
void SetName(const char *name)
Definition: Element.h:209
void SetAtomicSymbol(const char *symbol)
Definition: Element.h:193
virtual u32 DefaultPhysicsColor() const
Definition: Element_Dreg.h:82
bool IsLiveSite(const SPoint &location) const
Definition: EventWindow.h:148
bool OneIn(u32 odds)
Definition: Random.h:96
Random & GetRandom()
Definition: EventWindow.h:122
const T & GetRelativeAtom(const SPoint &offset) const
Definition: EventWindow.tcc:26
Definition: Element_Dreg.h:47
Definition: Parameter.h:593
virtual const T & GetDefaultAtom() const
Definition: Element.h:382
bool IsType(u32 type) const
Definition: Element.h:345
static MDist< R > & get()
Definition: MDist.tcc:193
virtual u32 DefaultLowlightColor() const
Definition: Element_Dreg.h:87
Definition: Element_Res.h:48
virtual void Behavior(EventWindow< CC > &window) const
Definition: Element_Dreg.h:98
Definition: Element_Wall.h:42
Definition: ElementTable.h:43
bool SetRelativeAtom(const SPoint &offset, const T &atom)
Definition: EventWindow.tcc:15
virtual const char * GetDescription() const
Definition: Element_Dreg.h:92
Definition: Atom.h:43