diff --git a/gama.core/src/gama/core/common/interfaces/IKeyword.java b/gama.core/src/gama/core/common/interfaces/IKeyword.java index 634281e406..951a766614 100644 --- a/gama.core/src/gama/core/common/interfaces/IKeyword.java +++ b/gama.core/src/gama/core/common/interfaces/IKeyword.java @@ -222,6 +222,9 @@ public interface IKeyword { /** The current state. */ String CURRENT_STATE = "currentState"; + /** The Constant CYCLE. */ + String CYCLE = "cycle"; + /** The cycle length. */ String CYCLE_LENGTH = "cycle_length"; diff --git a/gama.core/src/gama/core/kernel/experiment/ExperimentAgent.java b/gama.core/src/gama/core/kernel/experiment/ExperimentAgent.java index 869b3146e3..3494731cff 100644 --- a/gama.core/src/gama/core/kernel/experiment/ExperimentAgent.java +++ b/gama.core/src/gama/core/kernel/experiment/ExperimentAgent.java @@ -108,6 +108,10 @@ name = IKeyword.RNG, type = IType.STRING, doc = @doc (RandomUtils.DOC)), + @variable ( + name = IKeyword.CYCLE, + type = IType.INT, + doc = @doc ("Returns the current cycle of the simulation")), @variable ( name = SimulationAgent.USAGE, type = IType.INT, @@ -738,6 +742,20 @@ public GamaMap getParameters(final IScope scope) { @getter (PROJECT_PATH) public String getProjectPath() { return getModel().getProjectPath() + "/"; } + + /** + * Gets the cycle. + * + * @param scope + * the scope + * @return the cycle + */ + @getter (IKeyword.CYCLE) + public Integer getCycle(final IScope scope) { + if (ownClock != null) return ownClock.getCycle(); + return 0; + } + /** * Update displays. * @@ -1197,7 +1215,7 @@ public Iterable getAllSimulationOutputs() { if (pop != null) return Iterables.filter(Iterables.concat(Iterables.transform(pop, SimulationAgent::getOutputManager), Collections.singletonList(getOutputManager())), each -> each != null); - return Collections.EMPTY_LIST; + return Collections.emptyList(); } /** diff --git a/gama.core/src/gama/core/kernel/simulation/SimulationAgent.java b/gama.core/src/gama/core/kernel/simulation/SimulationAgent.java index add777be45..13e6f3c482 100644 --- a/gama.core/src/gama/core/kernel/simulation/SimulationAgent.java +++ b/gama.core/src/gama/core/kernel/simulation/SimulationAgent.java @@ -122,7 +122,7 @@ value = "Represents the total time passed, in model time, since the beginning of the simulation", comment = "Equal to cycle * step if the user does not arbitrarily initialize it.")), @variable ( - name = SimulationAgent.CYCLE, + name = IKeyword.CYCLE, type = IType.INT, doc = @doc ("Returns the current cycle of the simulation")), @variable ( @@ -173,9 +173,6 @@ public class SimulationAgent extends GamlAgent implements ITopLevelAgent { /** The Constant AVERAGE_DURATION. */ public static final String AVERAGE_DURATION = "average_duration"; - /** The Constant CYCLE. */ - public static final String CYCLE = "cycle"; - /** The Constant TIME. */ public static final String TIME = "time"; @@ -534,7 +531,7 @@ public IPopulation getPopulationFor(final String speciesName) * the scope * @return the cycle */ - @getter (CYCLE) + @getter (IKeyword.CYCLE) public Integer getCycle(final IScope scope) { final SimulationClock clock = getClock(); if (clock != null) return clock.getCycle(); @@ -1010,7 +1007,7 @@ public void updateWith(final IScope scope, final ISerialisedAgent sa) { setUsage(usageValue); // Update Clock - final Object cycle = sa.getAttributeValue(CYCLE); + final Object cycle = sa.getAttributeValue(IKeyword.CYCLE); ownClock.setCycleNoCheck((Integer) cycle); final Map savedAgentInnerPop = sa.innerPopulations(); diff --git a/gama.core/src/gama/core/metamodel/agent/SerialisedAgent.java b/gama.core/src/gama/core/metamodel/agent/SerialisedAgent.java index f577f3e48e..fd03fa7d94 100644 --- a/gama.core/src/gama/core/metamodel/agent/SerialisedAgent.java +++ b/gama.core/src/gama/core/metamodel/agent/SerialisedAgent.java @@ -162,7 +162,7 @@ public static Map filterAttributes(final IAgent agent, final boo map.put(IKeyword.SEED, sim.getSeed()); map.put(IKeyword.RNG, sim.getRng()); map.put(SimulationAgent.USAGE, sim.getUsage()); - map.put(SimulationAgent.CYCLE, sim.getClock().getCycle()); + map.put(IKeyword.CYCLE, sim.getClock().getCycle()); } if (!isGrid) { map.put(IKeyword.SHAPE, agent.getGeometry()); } map.put(IKeyword.NAME, agent.getName()); @@ -232,7 +232,7 @@ public void restoreAs(final IScope scope, final IAgent agent) { sim.setRandomGenerator(new RandomUtils(seedValue, rngValue)); sim.setUsage(usageValue); // Update Clock - final Integer cycle = (Integer) sim.getAttribute(SimulationAgent.CYCLE); + final Integer cycle = (Integer) sim.getAttribute(IKeyword.CYCLE); sim.getClock().setCycleNoCheck(cycle); }