[Avida-cvs] [avida-svn] r807 - in development/source: actions event
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Jul 6 16:42:12 PDT 2006
Author: brysonda
Date: 2006-07-06 19:42:09 -0400 (Thu, 06 Jul 2006)
New Revision: 807
Modified:
development/source/actions/PopulationActions.cc
development/source/event/cEventManager.cc
Log:
Transition Apocalypse event into actions framework.
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2006-07-06 18:55:50 UTC (rev 806)
+++ development/source/actions/PopulationActions.cc 2006-07-06 23:42:09 UTC (rev 807)
@@ -16,6 +16,7 @@
#include "cHardwareManager.h"
#include "cInstUtil.h"
#include "cPopulation.h"
+#include "cPopulationCell.h"
#include "cWorld.h"
@@ -393,7 +394,38 @@
};
+/*
+ Randomly removes a certain proportion of the population.
+
+ Parameters:
+ removal probability (double) default: 0.9
+ The probability with which a single organism is removed.
+*/
+class cActionApocalypse : public cAction
+{
+private:
+ double m_killprob;
+public:
+ cActionApocalypse(cWorld* world, const cString& args) : cAction(world, args), m_killprob(0.9)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_killprob = largs.PopWord().AsDouble();
+ }
+
+ const cString GetDescription() { return "Apocalypse [double killprob=0.9]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ for (int i = 0; i < m_world->GetPopulation().GetSize(); i++) {
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(i);
+ if (cell.IsOccupied() == false) continue;
+ if (ctx.GetRandom().P(m_killprob)) m_world->GetPopulation().KillOrganism(cell);
+ }
+ }
+};
+
+
void RegisterPopulationActions(cActionLibrary* action_lib)
{
action_lib->Register<cActionInject>("Inject");
@@ -405,6 +437,7 @@
action_lib->Register<cActionInjectParasite>("InjectParasite");
action_lib->Register<cActionInjectParasitePair>("InjectParasitePair");
+ action_lib->Register<cActionApocalypse>("Apocalypse");
// @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
@@ -413,4 +446,6 @@
action_lib->Register<cActionInjectAll>("inject_all");
action_lib->Register<cActionInjectRange>("inject_range");
action_lib->Register<cActionInject>("inject_sequence");
+
+ action_lib->Register<cActionApocalypse>("apocalypse");
}
Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc 2006-07-06 18:55:50 UTC (rev 806)
+++ development/source/event/cEventManager.cc 2006-07-06 23:42:09 UTC (rev 807)
@@ -581,41 +581,7 @@
}
};
-///// apocalypse /////
-/**
-* Randomly removes a certain proportion of the population.
- *
- * Parameters:
- * removal probability (double) default: 0.9
- * The probability with which a single organism is removed.
- **/
-
-
-class cEvent_apocalypse : public cEvent {
-private:
- double kill_prob;
-public:
- const cString GetName() const { return "apocalypse"; }
- const cString GetDescription() const { return "apocalypse [double kill_prob=.9]"; }
-
- void Configure(cWorld* world, const cString& in_args)
- {
- m_world = world;
- m_args = in_args;
- cString args(in_args);
- if (args == "") kill_prob=.9; else kill_prob=args.PopWord().AsDouble();
- }
- ///// apocalypse /////
- void Process(){
- for (int i = 0; i < m_world->GetPopulation().GetSize(); i++) {
- cPopulationCell & cell = m_world->GetPopulation().GetCell(i);
- if (cell.IsOccupied() == false) continue;
- if (m_world->GetRandom().P(kill_prob)) m_world->GetPopulation().KillOrganism(cell);
- }
- }
-};
-
///// kill_rectangle /////
/**
@@ -1950,7 +1916,6 @@
REGISTER(task_snapshot);
REGISTER(print_viable_tasks_data);
- REGISTER(apocalypse);
REGISTER(kill_rectangle);
REGISTER(rate_kill);
REGISTER(serial_transfer);
More information about the Avida-cvs
mailing list