[Avida-cvs] [avida-svn] r808 - in development/source: actions event

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Thu Jul 6 16:58:53 PDT 2006


Author: brysonda
Date: 2006-07-06 19:58:49 -0400 (Thu, 06 Jul 2006)
New Revision: 808

Modified:
   development/source/actions/PopulationActions.cc
   development/source/event/cEventManager.cc
Log:
Transition KillRectangle event into actions framework.

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2006-07-06 23:42:09 UTC (rev 807)
+++ development/source/actions/PopulationActions.cc	2006-07-06 23:58:49 UTC (rev 808)
@@ -425,7 +425,78 @@
 };
 
 
+/*
+ Kills all cell in a rectangle.
+ 
+ Parameters:
+   cell [X1][Y1][x2][Y2] (integer) default: 0
+     The start and stoping grid-points into which the organism should be killed.
+*/
+class cActionKillRectangle : public cAction
+{
+private:
+  int m_x1;
+  int m_y1;
+  int m_x2;
+  int m_y2;
+public:
+  cActionKillRectangle(cWorld* world, const cString& args) : cAction(world, args), m_x1(0), m_y1(0), m_x2(0), m_y2(0)
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_x1 = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_y1 = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_x2 = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_y2 = largs.PopWord().AsInt();
 
+    /* Be sure the user entered a valid range */
+    if (m_x1 < 0) {
+      m_x1 = 0;
+    } else if (m_x1 > m_world->GetPopulation().GetWorldX() - 1) {
+      m_x1 = m_world->GetPopulation().GetWorldX() - 1;
+    }
+    if (m_x2 < 0) {
+      m_x2 = 0;
+    } else if (m_x2 > m_world->GetPopulation().GetWorldX() - 1) {
+      m_x2 = m_world->GetPopulation().GetWorldX() - 1;
+    }
+    if (m_y1 < 0) {
+      m_y1 = 0;
+    } else if (m_y1 > m_world->GetPopulation().GetWorldY() - 1) {
+      m_y1 = m_world->GetPopulation().GetWorldY() - 1;
+    }
+    if (m_y2 < 0) {
+      m_y2 = 0;
+    } else if (m_y2 > m_world->GetPopulation().GetWorldY() - 1) {
+      m_y2 = m_world->GetPopulation().GetWorldY() - 1;
+    }
+
+    /* Account for a rectangle that crosses over the Zero X or Y cell */
+    if (m_x2 < m_x1) {
+      m_x2 = m_x2 + m_world->GetPopulation().GetWorldX();
+    }
+    if (m_y2 < m_y1) {
+      m_y2 = m_y2 + m_world->GetPopulation().GetWorldY();
+    }
+  }
+  
+  const cString GetDescription() { return "KillRectangle [int x1=0] [int y1=0] [int x2=0] [int y2=0]"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    cPopulation& pop = m_world->GetPopulation();
+    for (int i = m_y1; i <= m_y2; i++) {
+      for (int j = m_x1; j <= m_x2; j++) {
+        int loc = (i % pop.GetWorldY()) * pop.GetWorldX() + (j % pop.GetWorldX());
+        cPopulationCell& cell = pop.GetCell(loc);
+        if (cell.IsOccupied()) pop.KillOrganism(cell);
+      }
+    }
+    m_world->GetPopulation().SetSyncEvents(true);
+  }
+};
+
+
+
 void RegisterPopulationActions(cActionLibrary* action_lib)
 {
   action_lib->Register<cActionInject>("Inject");
@@ -438,6 +509,7 @@
   action_lib->Register<cActionInjectParasitePair>("InjectParasitePair");
 
   action_lib->Register<cActionApocalypse>("Apocalypse");
+  action_lib->Register<cActionKillRectangle>("KillRectangle");
 
 
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
@@ -448,4 +520,5 @@
   action_lib->Register<cActionInject>("inject_sequence");
 
   action_lib->Register<cActionApocalypse>("apocalypse");
+  action_lib->Register<cActionKillRectangle>("kill_rectangle");
 }

Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc	2006-07-06 23:42:09 UTC (rev 807)
+++ development/source/event/cEventManager.cc	2006-07-06 23:58:49 UTC (rev 808)
@@ -582,83 +582,7 @@
 };
 
 
-///// kill_rectangle /////
 
-/**
-* Kills all cell in a rectangle.
- *
- * Parameters:
- * cell [X1][Y1][x2][Y2] (integer) default: 0
-   *   The start and stoping grid-points into which the organism should
-   be killed.
-   **/
-
-
-class cEvent_kill_rectangle : public cEvent {
-private:
-  int cell_X1;
-  int cell_Y1;
-  int cell_X2;
-  int cell_Y2;
-public:
-    const cString GetName() const { return "kill_rectangle"; }
-  const cString GetDescription() const { return "kill_rectangle  [int cell_X1=0] [int cell_Y1=0] [int cell_X2=0] [int cell_Y2=0]"; }
-  
-  void Configure(cWorld* world, const cString& in_args)
-  {
-    m_world = world;
-    m_args = in_args;
-    cString args(in_args);
-    if (args == "") cell_X1=0; else cell_X1=args.PopWord().AsInt();
-    if (args == "") cell_Y1=0; else cell_Y1=args.PopWord().AsInt();
-    if (args == "") cell_X2=0; else cell_X2=args.PopWord().AsInt();
-    if (args == "") cell_Y2=0; else cell_Y2=args.PopWord().AsInt();
-  }
-  ///// kill_rectangle /////
-  void Process(){
-    int i, j, loc;
-    /* Be sure the user entered a valid range */
-    if (cell_X1 < 0) {
-      cell_X1 = 0;
-    } else if (cell_X1 > m_world->GetPopulation().GetWorldX() - 1) {
-      cell_X1 = m_world->GetPopulation().GetWorldX() - 1;
-    }
-    if (cell_X2 < 0) {
-      cell_X2 = 0;
-    } else if (cell_X2 > m_world->GetPopulation().GetWorldX() - 1) {
-      cell_X2 = m_world->GetPopulation().GetWorldX() - 1;
-    }
-    if (cell_Y1 < 0) {
-      cell_Y1 = 0;
-    } else if (cell_Y1 > m_world->GetPopulation().GetWorldY() - 1) {
-      cell_Y1 = m_world->GetPopulation().GetWorldY() - 1;
-    }
-    if (cell_Y2 < 0) {
-      cell_Y2 = 0;
-    } else if (cell_Y2 > m_world->GetPopulation().GetWorldY() - 1) {
-      cell_Y2 = m_world->GetPopulation().GetWorldY() - 1;
-    }
-    /* Account for a rectangle that crosses over the Zero X or Y cell */
-    if (cell_X2 < cell_X1) {
-      cell_X2 = cell_X2 + m_world->GetPopulation().GetWorldX();
-    }
-    if (cell_Y2 < cell_Y1) {
-      cell_Y2 = cell_Y2 + m_world->GetPopulation().GetWorldY();
-    }
-    for (i = cell_Y1; i <= cell_Y2; i++) {
-      for (j = cell_X1; j <= cell_X2; j++) {
-        loc = (i % m_world->GetPopulation().GetWorldY()) * m_world->GetPopulation().GetWorldX() +
-        (j % m_world->GetPopulation().GetWorldX());
-        cPopulationCell & cell = m_world->GetPopulation().GetCell(loc);
-        if (cell.IsOccupied() == true) {
-          m_world->GetPopulation().KillOrganism(cell);
-        }
-      }
-    }
-    m_world->GetPopulation().SetSyncEvents(true);
-  }
-};
-
 ///// rate_kill /////
 
 /**
@@ -1916,7 +1840,6 @@
   REGISTER(task_snapshot);
   REGISTER(print_viable_tasks_data);
   
-  REGISTER(kill_rectangle);
   REGISTER(rate_kill);
   REGISTER(serial_transfer);
   REGISTER(hillclimb);




More information about the Avida-cvs mailing list