<?xml version="1.0" encoding="UTF-8"?>
<otrunk id="22d3fb4f-123a-425f-9d60-d84e145c0678">
  <imports>
    <import class="org.concord.otrunk.OTIncludeRootObject" />
    <import class="org.concord.otrunk.OTInclude" />
    <import class="org.concord.otrunk.OTSystem" />
    <import class="org.concord.otrunk.biologica.OTOrganismPlacement" />
    <import class="org.concord.otrunk.biologica.OTEnvironment" />
    <import class="org.concord.otrunk.biologica.OTOrganism" />
    <import class="org.concord.otrunk.biologica.OTWorld" />
    <import class="org.concord.otrunk.biologica.agent.OTAgentSpecies" />
    <import class="org.concord.otrunk.biologica.agent.OTAgentTrait" />
    <import class="org.concord.otrunk.biologica.agent.OTAgentPropertyImageMap" />
    <import class="org.concord.otrunk.biologica.environment.OTAddAgentButton" />
    <import class="org.concord.otrunk.biologica.environment.OTEnvironmentHolder" />
    <import class="org.concord.otrunk.biologica.rules.OTRule" />
    <import class="org.concord.otrunk.biologica.rules.OTRuleCondition" />
    <import class="org.concord.otrunk.biologica.rules.OTRuleConsequence" />
    <import class="org.concord.otrunk.ui.OTCurriculumUnit" />
    <import class="org.concord.otrunk.ui.OTPlacement" />
    <import class="org.concord.otrunk.ui.snapshot.OTSnapshot" />
    <import class="org.concord.otrunk.ui.snapshot.OTSnapshotButton" />
    <import class="org.concord.otrunk.ui.snapshot.OTSnapshotAlbum" />
    <import class="org.concord.otrunk.ui.snapshot.OTSnapshotChooser" />
    <import class="org.concord.otrunk.view.OTViewEntry" />
    <import class="org.concord.otrunk.view.OTViewBundle" />
    <import class="org.concord.otrunk.view.OTViewMode" />
    <import class="org.concord.otrunk.view.document.OTCompoundDoc" />
    <import class="org.concord.otrunk.script.ui.OTScriptObject" />
    <import class="org.concord.otrunk.script.js.OTJavascript" />
    <import class="org.concord.otrunk.script.OTScriptEngineBundle" />
    <import class="org.concord.otrunk.script.OTScriptEngineEntry" />
    <import class="org.concord.otrunk.script.ui.OTScriptVariable" />
    <import class="org.concord.otrunk.script.ui.OTScriptVariableComponent" />
    <import class="org.concord.otrunk.script.ui.OTScriptVariableRealObject" />
    <import class="org.concord.otrunk.script.ui.OTScriptVariableView" />
    <import class="org.concord.otrunk.script.ui.OTScriptButton" />
    <import class="org.concord.framework.otrunk.view.OTFrame" />
  </imports>
  <objects>
    <OTSystem>
      <bundles>
        <object refid="8d880970-c22a-11dc-95ff-0800200c9a66" />
        <OTScriptEngineBundle>
          <engines>
            <OTScriptEngineEntry objectClass="org.concord.otrunk.script.js.OTJavascript" engineClass="org.concord.otrunk.script.js.OTJavascriptEngine" />
          </engines>
        </OTScriptEngineBundle>
      </bundles>
      <includes>
        <OTInclude href="../global-imports/er-view-bundle.otml" />
        <OTInclude href="species/annual-varied-plants.otml" />
      </includes>
      <root>
        <OTEnvironmentHolder local_id="env-holder" width="590" height="460" toolbar="run,reset">
          <environment>
            <OTEnvironment local_id="environment" environmentWidth="15" environmentHeight="15" showRunButton="false" winterLength="-1" summerLength="50" orgSizeMultiplier="3.0" backgroundImageSrc="jres:/org/concord/er/resources/images/envs/sun5levels.jpg">
              <world>
                <OTWorld local_id="peasimple_world" speciesPath="org/concord/biologica/worlds/peasimple.xml" />
              </world>
              <barriers>
                <OTPlacement x="0" y="0" width="25" height="155" />
                <OTPlacement x="139" y="0" width="16" height="150" />
                <OTPlacement x="25" y="0" width="114" height="17" />
                <OTPlacement x="25" y="32" width="114" height="12" />
                <OTPlacement x="25" y="59" width="114" height="12" />
                <OTPlacement x="25" y="86" width="114" height="11" />
                <OTPlacement x="26" y="113" width="112" height="11" />
                <OTPlacement x="70" y="129" width="0" height="0" />
                <OTPlacement x="25" y="137" width="114" height="12" />
              </barriers>
              <rules>
                <OTRule description="Health depends on leaves and sunlight">
                  <conditions>
                    <OTRuleCondition always="true" />
                  </conditions>
                  <consequences>
                    <OTRuleConsequence property="Health" ruleScript="var diff = Math.abs((11 - size_of_leaves) - (sunlight*10)); return 1 - (diff /  20)">
                      <propertyVariables>
                        <string>size of leaves</string>
                        <string>sunlight</string>
                      </propertyVariables>
                    </OTRuleConsequence>
                  </consequences>
                </OTRule>
                <OTRule description="Immortality rule">
                  <conditions>
                    <OTRuleCondition property="Health" minValue="0.87" maxValue="1.0" />
                  </conditions>
                  <consequences>
                    <OTRuleConsequence property="is immortal" newValueBoolean="true" />
                    <OTRuleConsequence property="Days to seed" newValueFloat="-1.0" />
                  </consequences>
                </OTRule>
                <OTRule description="Flower rule">
                  <conditions>
                    <OTRuleCondition property="Health" maxValue="0.95" />
                  </conditions>
                  <consequences>
                    <OTRuleConsequence property="Chance of flowering" newValueFloat="0.0" />
                  </consequences>
                </OTRule>
                <OTRule description="Flower health is 1">
                  <conditions>
                    <OTRuleCondition property="Has flower" equals="true" />
                  </conditions>
                  <consequences>
                    <OTRuleConsequence property="Health" newValueFloat="1.0" />
                  </consequences>
                </OTRule>
              </rules>
            </OTEnvironment>
          </environment>
          <traitsToShow>
            <string>size of leaves</string>
          </traitsToShow>
          <addAgentsButtons>
            <OTAddAgentButton text="Add Plant A" limit="20">
              <species>
                <object refid="f5732706-c9c2-4e29-8c99-4c668dda89b0" />
              </species>
              <agentTraits>
                <OTAgentTrait property="size of leaves">
                  <defaultValues>
                    <int>5</int>
                  </defaultValues>
                </OTAgentTrait>
              </agentTraits>
            </OTAddAgentButton>
            <OTAddAgentButton text="Add Plant B" limit="20">
              <species>
                <object refid="f5732706-c9c2-4e29-8c99-4c668dda89b0" />
              </species>
              <agentTraits>
                <OTAgentTrait property="size of leaves">
                  <defaultValues>
                    <int>1</int>
                  </defaultValues>
                </OTAgentTrait>
              </agentTraits>
            </OTAddAgentButton>
            <OTAddAgentButton text="Add Plant C" limit="20">
              <species>
                <object refid="f5732706-c9c2-4e29-8c99-4c668dda89b0" />
              </species>
              <agentTraits>
                <OTAgentTrait property="size of leaves">
                  <defaultValues>
                    <int>9</int>
                  </defaultValues>
                </OTAgentTrait>
              </agentTraits>
            </OTAddAgentButton>
          </addAgentsButtons>
          <scripts>
            <OTScriptObject local_id="setup-script" name="Setup script">
              <script>
                <OTJavascript src="scripts/gradated-sunlight-five-blocks/setup.js">
                  <script>importPackage(Packages.java.lang);
importPackage(Packages.java.awt);
importPackage(Packages.org.concord.biologica.environment);
  			
function init() {
                        env.removeAllAgents()
                       env.setStepCount(0)
                       envHolder.pauseAction()
	var world = env.getWorld()
	env.setColumns(15)
	env.setRows(15)
	env.setWrapNorthSouth(false)
	env.setWrapEastWest(false)
	for (var i = 0; i &lt; 15; i++) {
	        for (var j = 0; j &lt; 15; j++) {
	        	var envUnit = new EnvironmentUnit(env, null, i, j)
	        	env.setEnvironmentUnit(envUnit, i, j)
	        	if (j &lt; 4)
	        		percentSunlight = 1.0
	        	else if (j &lt; 6)
	        		percentSunlight = 0.8
	        	else if (j &lt; 9)
	        		percentSunlight = 0.6
	        	else if (j &lt; 12)
	        		percentSunlight = 0.4
	        	else if (j &lt; 15)
	        		percentSunlight = 0.2
	        		
	        	envUnit.setProperty("sunlight", new Float(percentSunlight))
	        	
	        	var r =  (percentSunlight) * 0.5
	        	var g = r * 0.5
	        	var b = g * 0.2
	        	var color = new Color(r+0.3, g+0.2, b+0.1)
	        	var terrain = new Terrain(world, "terrain", color)
	        	envUnit.setTerrain(terrain)
            }
        }
    holder.repaint();
	return true;
}

function save() {
	return true;
}</script>
                </OTJavascript>
              </script>
              <variables>
                <OTScriptVariableRealObject name="env">
                  <reference>
                    <object refid="${environment}" />
                  </reference>
                </OTScriptVariableRealObject>
                <OTScriptVariableRealObject name="envHolder">
                  <reference>
                    <object refid="${env-holder}" />
                  </reference>
                </OTScriptVariableRealObject>
                <OTScriptVariableRealObject name="holder">
                  <reference>
                    <object refid="${env-holder}" />
                  </reference>
                </OTScriptVariableRealObject>
              </variables>
              <scriptState />
            </OTScriptObject>
          </scripts>
          <logAddedAgentProperties>
            <string>size of leaves</string>
          </logAddedAgentProperties>
        </OTEnvironmentHolder>
      </root>
    </OTSystem>
  </objects>
</otrunk>

