[Avida-SVN] r2750 - development/source/actions
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Fri Aug 15 06:45:50 PDT 2008
Author: beckma24
Date: 2008-08-15 09:45:49 -0400 (Fri, 15 Aug 2008)
New Revision: 2750
Modified:
development/source/actions/EnvironmentActions.cc
Log:
Added seasonal resource setting action
Modified: development/source/actions/EnvironmentActions.cc
===================================================================
--- development/source/actions/EnvironmentActions.cc 2008-08-08 14:37:04 UTC (rev 2749)
+++ development/source/actions/EnvironmentActions.cc 2008-08-15 13:45:49 UTC (rev 2750)
@@ -536,6 +536,35 @@
};
/**
+ Sets resource availiblity to seasonal
+ */
+class cActionSetSeasonalResource : public cAction
+ {
+ private:
+ cString m_res_name;
+ double yearLength;
+
+ public:
+ cActionSetSeasonalResource(cWorld* world, const cString& args): cAction(world, args), m_res_name(""), yearLength(0.0)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_res_name = largs.PopWord();
+ if (largs.GetSize()) yearLength = largs.PopWord().AsDouble();
+ }
+
+ static const cString GetDescription() { return "Arguments: <string reaction_name> <double yearlenght> <string pi/frequence> <phaseShift*pi> <string initial_Y>"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ int time = m_world->GetStats().GetUpdate();
+ double m_res_count = -1*(0.4*tanh((time-182500)/50000)+0.5)*(0.5*sin(time/58.091)+0.5)+1;
+ cResource* res = m_world->GetEnvironment().GetResourceLib().GetResource(m_res_name);
+ if (res != NULL) m_world->GetPopulation().SetResource(res->GetID(), m_res_count);
+
+ }
+ };
+
+/**
Sets resource availiblity to periodic
*/
class cActionSetPeriodicResource : public cAction
@@ -850,6 +879,7 @@
action_lib->Register<cActionSetEnvironmentInputs>("SetEnvironmentInputs");
action_lib->Register<cActionSetEnvironmentRandomMask>("SetEnvironmentRandomMask");
+ action_lib->Register<cActionSetPeriodicResource>("cActionSetSeasonalResource");
action_lib->Register<cActionSetPeriodicResource>("SetPeriodicResource");
action_lib->Register<cActionSetNumInstBefore0Energy>("SetNumInstBefore0Energy");
More information about the Avida-cvs
mailing list