MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Element_Rocket.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  Element_Rocket.h Demo high-speed payload-carrying device
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_ROCKET_H
28 #define ELEMENT_ROCKET_H
29 
30 #include "Element.h"
31 #include "EventWindow.h"
32 #include "ElementTable.h"
33 #include "itype.h"
34 #include "P3Atom.h"
35 
36 namespace MFM
37 {
38 
39  template <class CC>
40  class Element_Rocket : public Element<CC>
41  {
42  // Short names for params
43  typedef typename CC::ATOM_TYPE T;
44  typedef typename CC::PARAM_CONFIG P;
45  enum { R = P::EVENT_WINDOW_RADIUS };
46 
47  public:
48  enum {
49  ELT_VERSION = 1,
50 
52  // Element field sizes
53 
54  BITS_DIR = 3,
55  BITS_DIST = 5,
56 
57  STATE_BITS_START = P3Atom<P>::P3_STATE_BITS_POS
58  };
59 
61 
64 
65  static const u32 STATE_BITS_END = AFDist::END;
66  static const u32 STATE_BITS_COUNT = STATE_BITS_END - STATE_BITS_START + 1;
67  static Element_Rocket THE_INSTANCE;
68 
69  static const u32 TYPE()
70  {
71  return THE_INSTANCE.GetType();
72  }
73 
74  Element_Rocket() : Element<CC>(MFM_UUID_FOR("Rocket", ELT_VERSION))
75  {
77  Element<CC>::SetName("Rocket");
78  }
79 
80  virtual const T & GetDefaultAtom() const
81  {
82  static T defaultAtom(TYPE(),0,0,0);
83  return defaultAtom;
84  }
85 
86  virtual u32 DefaultPhysicsColor() const
87  {
88  return 0xff00ff00;
89  }
90 
91  virtual u32 DefaultLowlightColor() const
92  {
93  return 0xff00af00;
94  }
95 
96  virtual u32 Diffusability(EventWindow<CC> & ew, SPoint nowAt, SPoint maybeAt) const
97  {
98  return nowAt.Equals(maybeAt)?Element<CC>::COMPLETE_DIFFUSABILITY:0;
99  }
100 
101  virtual u32 PercentMovable(const T& you,
102  const T& me, const SPoint& offset) const
103  {
104  return 0;
105  }
106 
107  virtual void Behavior(EventWindow<CC>& window) const
108  {
109  // Phase 0: Self check
110  // Phase 1: See / Scan
111  // Scan goals:
112  // 1.0: Count all rocket pieces going my way
113  // Phase 2: Think
114  // 2.0: If I'm alone, decay
115  // Phase 3: Do
116  // 3.0: Do special event window scan -- in opposite of heading
117  // direction order -- so we'll find the first guys to move first
118  // 3.1: For each rocket piece going my way
119  // check in its heading direction for cases:
120  // 3.1.1: Heading direction is out of event window or not alive: do nothing
121  // 3.1.2: Empty in its heading direction: Move into it, decrement DIR
122  // 3.1.3: Second heading direction is out of event window or not alive: do nothing
123  // 3.1.4: Occupied in heading but empty in second heading: push occupant
124  // into second heading, move into first heading, decrement DIR
125  // 3.1.5: Do nothing
126  /*
127  . . . . . .
128  . e. e. . . .
129  . e. b. b. . .
130  . . b. p. . .
131  . . . . . .
132  . . . . . .
133  . . b. e. . .
134  . . p. b. e. .
135  . . b. e. . .
136  . . . . . .
137  . . . . . .
138 
139  . . . . . .
140  . e. . e. . .
141  . . b. . b. .
142  . e. . p. . .
143  . . b. . . .
144  . . . . . .
145  . . . . . .
146  . . b. e. . .
147  . . . . . .
148  . . p. . b. e.
149  . . . . . .
150  . . b. e. . .
151  . . . . . .
152  . . . . . .
153 
154 
155  .........
156  ...bbb...
157  ...bpb...
158  ...bbb...
159  .........
160 
161  */
162  FAIL(INCOMPLETE_CODE);
163  }
164  };
165 
166  template <class CC>
167  Element_Rocket<CC> Element_Rocket<CC>::THE_INSTANCE;
168 }
169 
170 #endif /* ELEMENT_ROCKET_H */
virtual u32 Diffusability(EventWindow< CC > &ew, SPoint nowAt, SPoint maybeAt) const
Definition: Element_Rocket.h:96
u32 GetType() const
Definition: Element.h:290
virtual const T & GetDefaultAtom() const
Definition: Element_Rocket.h:80
bool Equals(const Point< T > &rhs) const
Definition: Point.tcc:205
virtual u32 DefaultLowlightColor() const
Definition: Element_Rocket.h:91
Definition: Element_Rocket.h:40
void SetName(const char *name)
Definition: Element.h:209
void SetAtomicSymbol(const char *symbol)
Definition: Element.h:193
Definition: Atom.h:45
virtual void Behavior(EventWindow< CC > &window) const
Definition: Element_Rocket.h:107
Definition: ElementTable.h:43
Definition: BitVector.h:47
Definition: P3Atom.h:44
virtual u32 PercentMovable(const T &you, const T &me, const SPoint &offset) const
Definition: Element_Rocket.h:101
Definition: Atom.h:43
virtual u32 DefaultPhysicsColor() const
Definition: Element_Rocket.h:86