From 17bbc58c6c3bdf5cda88e5b90cb9b6826dd09b8c Mon Sep 17 00:00:00 2001 From: Cordoncharge83 <146195205+Cordoncharge83@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:13:12 +0100 Subject: [PATCH 01/37] Test Commot W --- TestPush | 1 + 1 file changed, 1 insertion(+) create mode 100644 TestPush diff --git a/TestPush b/TestPush new file mode 100644 index 0000000..6579086 --- /dev/null +++ b/TestPush @@ -0,0 +1 @@ +ijfjverzhjbtrkubt:lhbtr \ No newline at end of file From 7bd9b5b636bdbe5fe5a60e265dbc92f05aac1147 Mon Sep 17 00:00:00 2001 From: yahia Date: Tue, 28 Nov 2023 15:24:29 +0100 Subject: [PATCH 02/37] Yahiewi med amine --- TestYahia | 1 + 1 file changed, 1 insertion(+) create mode 100644 TestYahia diff --git a/TestYahia b/TestYahia new file mode 100644 index 0000000..7c3ad18 --- /dev/null +++ b/TestYahia @@ -0,0 +1 @@ +TEjsfsidfjzuifnhnhjdfs \ No newline at end of file From 62f261ea2beec22101a7aed0b1cf08007a96e960 Mon Sep 17 00:00:00 2001 From: i22smai Date: Tue, 28 Nov 2023 15:28:21 +0100 Subject: [PATCH 03/37] hello --- IhebTesting | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 IhebTesting diff --git a/IhebTesting b/IhebTesting new file mode 100644 index 0000000..e69de29 From de6e56b6944262f9c9ecc4cd224f7772cdd3a9f8 Mon Sep 17 00:00:00 2001 From: Jihene556 <144704955+Jihene556@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:28:25 +0100 Subject: [PATCH 04/37] Create testjiji --- testjiji | 1 + 1 file changed, 1 insertion(+) create mode 100644 testjiji diff --git a/testjiji b/testjiji new file mode 100644 index 0000000..4f49e5f --- /dev/null +++ b/testjiji @@ -0,0 +1 @@ +jsgdhsjfjhiezuyruiz From c79dd69378e3025e2d527bfda9f6fa13cdf8f09a Mon Sep 17 00:00:00 2001 From: Oussama1928 <150257499+Oussama1928@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:41:20 +0100 Subject: [PATCH 05/37] Create TestOussama --- TestOussama | 1 + 1 file changed, 1 insertion(+) create mode 100644 TestOussama diff --git a/TestOussama b/TestOussama new file mode 100644 index 0000000..3597aed --- /dev/null +++ b/TestOussama @@ -0,0 +1 @@ +Sah sah sah From 45c291a25ac103dfc0a5bdcd5e600ef9421b54fc Mon Sep 17 00:00:00 2001 From: Oussama1928 <150257499+Oussama1928@users.noreply.github.com> Date: Tue, 28 Nov 2023 16:06:13 +0100 Subject: [PATCH 06/37] Delete TestOussama --- TestOussama | 1 - 1 file changed, 1 deletion(-) delete mode 100644 TestOussama diff --git a/TestOussama b/TestOussama deleted file mode 100644 index 3597aed..0000000 --- a/TestOussama +++ /dev/null @@ -1 +0,0 @@ -Sah sah sah From e4b9c9f60c7a0ae0109e8bd238b9d57433ecc6c9 Mon Sep 17 00:00:00 2001 From: oussama Date: Tue, 28 Nov 2023 16:21:38 +0100 Subject: [PATCH 07/37] haya aad --- TestOussama | 1 + 1 file changed, 1 insertion(+) create mode 100644 TestOussama diff --git a/TestOussama b/TestOussama new file mode 100644 index 0000000..58ad6ee --- /dev/null +++ b/TestOussama @@ -0,0 +1 @@ +sah sah sah \ No newline at end of file From 70666170067ca740547df8ae745efaa227a226ff Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Fri, 8 Dec 2023 12:04:40 +0100 Subject: [PATCH 08/37] currentWeatherMethod to determine rain/hail/snow depending on the temperature and humidity --- .../weather/DownfallCondition.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/terasology/weatherManager/weather/DownfallCondition.java b/src/main/java/org/terasology/weatherManager/weather/DownfallCondition.java index 82efc2e..fc79ba4 100644 --- a/src/main/java/org/terasology/weatherManager/weather/DownfallCondition.java +++ b/src/main/java/org/terasology/weatherManager/weather/DownfallCondition.java @@ -1,7 +1,7 @@ // Copyright 2021 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.weatherManager.weather; - +import java.util.Random; import com.google.common.base.Objects; import com.google.common.base.Preconditions; @@ -78,6 +78,27 @@ public static DownfallCondition get(final Severity amount, final DownfallType ty return INSTANCES.computeIfAbsent(values, (DownfallValues v) -> new DownfallCondition(v) ); */ } + public static DownfallCondition currentDownfall(float temperature, Severity humidity){ + Random rand = new Random(); + boolean withThunder = rand.nextInt(2)==0?false:true ; + // if the severity is none, there is no downfall regardless of the temparature. Also, there is no thunder + // because it would be an illegal combination as stated in the get method of this class + if(humidity.toString().equals("none")){ + return DownfallCondition.get(humidity,DownfallCondition.DownfallType.NONE,false); + } + // it is raining with a severity non equal to none if the temperature is greater than 0 + else if(temperature>0){ + return DownfallCondition.get(humidity,DownfallCondition.DownfallType.RAIN,withThunder); + } + // it is hailing with a severity non equal to none if the temperature greater than -2 and less than 0 + else if(temperature>-2){ + return DownfallCondition.get(humidity,DownfallCondition.DownfallType.HAIL,withThunder); + } + // it is snowing if there is no match with the precedent cases + else { + return DownfallCondition.get(humidity,DownfallCondition.DownfallType.SNOW,withThunder); + } + } public DownfallValues getDownfallValues() { return downfallValues; From a26364f599d7b77046f325a492363845294e82ac Mon Sep 17 00:00:00 2001 From: Ewwweee Date: Sat, 16 Dec 2023 15:07:09 +0100 Subject: [PATCH 09/37] added beginning of temp --- module.txt | 3 +- .../events/TemperatureIncreaseEvent.java | 12 ++ .../systems/WeatherManagerSystem.java | 103 +++++++++++++++++- src/test/resources/logback-test.xml | 39 +++++++ 4 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/terasology/weatherManager/events/TemperatureIncreaseEvent.java create mode 100644 src/test/resources/logback-test.xml diff --git a/module.txt b/module.txt index a47f3bd..0c8aa40 100644 --- a/module.txt +++ b/module.txt @@ -7,7 +7,8 @@ "dependencies": [ { "id": "MarkovChains", "minVersion": "1.5.0" }, { "id": "CoreAssets", "minVersion": "2.1.0" }, - { "id": "FlowingLiquids", "minVersion": "1.2.0" } + { "id": "FlowingLiquids", "minVersion": "1.2.0" }, + { "id": "ClimateConditions", "minVersion": "1.0.0"} ], "isAugmentation": true } diff --git a/src/main/java/org/terasology/weatherManager/events/TemperatureIncreaseEvent.java b/src/main/java/org/terasology/weatherManager/events/TemperatureIncreaseEvent.java new file mode 100644 index 0000000..d525fec --- /dev/null +++ b/src/main/java/org/terasology/weatherManager/events/TemperatureIncreaseEvent.java @@ -0,0 +1,12 @@ +// Copyright 2021 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 + +package org.terasology.weatherManager.events; + +import org.terasology.gestalt.entitysystem.event.Event; + +/** + * Event which is called when the weather changes to hail (frozen raindrop fall) + */ +public class TemperatureIncreaseEvent implements Event { +} diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index e03ce46..60746df 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -4,16 +4,28 @@ package org.terasology.weatherManager.systems; import com.google.common.math.DoubleMath; +import com.google.common.base.Function; import org.joml.Vector2f; +import org.joml.Vector3f; +import org.joml.Vector3fc; +import org.joml.Vector3i; +import org.joml.Vector3ic; +import java.util.List; +import java.util.ArrayList; import org.slf4j.LoggerFactory; +import org.terasology.engine.context.Context; +import org.terasology.engine.network.NetworkSystem; import org.terasology.engine.entitySystem.entity.EntityManager; import org.terasology.engine.entitySystem.entity.EntityRef; +import org.terasology.engine.logic.delay.PeriodicActionTriggeredEvent; import org.terasology.engine.entitySystem.systems.BaseComponentSystem; import org.terasology.engine.entitySystem.systems.RegisterMode; import org.terasology.engine.entitySystem.systems.RegisterSystem; import org.terasology.engine.logic.console.commandSystem.annotations.Command; import org.terasology.engine.logic.console.commandSystem.annotations.CommandParam; import org.terasology.engine.logic.delay.DelayManager; +import org.terasology.engine.network.Client; +import org.terasology.engine.logic.location.LocationComponent; import org.terasology.engine.logic.delay.DelayedActionTriggeredEvent; import org.terasology.engine.logic.players.event.LocalPlayerInitializedEvent; import org.terasology.engine.registry.In; @@ -25,6 +37,7 @@ import org.terasology.weatherManager.events.StartRainEvent; import org.terasology.weatherManager.events.StartSnowEvent; import org.terasology.weatherManager.events.StartSunEvent; +import org.terasology.weatherManager.events.TemperatureIncreaseEvent; import org.terasology.weatherManager.weather.ConditionAndDuration; import org.terasology.weatherManager.weather.DownfallCondition; import org.terasology.weatherManager.weather.Severity; @@ -34,6 +47,10 @@ import java.util.Iterator; import java.util.Random; +import org.terasology.climateConditions.ClimateConditionsSystem; +import org.terasology.climateConditions.ClimateConditionsSystem; + + @RegisterSystem(RegisterMode.AUTHORITY) @Share(WeatherManagerSystem.class) public class WeatherManagerSystem extends BaseComponentSystem { @@ -42,6 +59,7 @@ public class WeatherManagerSystem extends BaseComponentSystem { public static final String MELT_SNOW = "meltSnow"; public static final String EVAPORATE_WATER = "evaporateWater"; public static final String PLACE_WATER = "placeWater"; + public static final String TEMPERATURE_INCREASE = "temperatureIncrease"; private static final org.slf4j.Logger logger = LoggerFactory.getLogger(WeatherManagerSystem.class); @@ -51,6 +69,7 @@ public class WeatherManagerSystem extends BaseComponentSystem { private DownfallCondition.DownfallType currentWeather; private WeatherConditionProvider weatherConditionProvider; + private float currentTemperature; private ConditionAndDuration current; private EntityRef weatherEntity; @@ -64,6 +83,20 @@ public class WeatherManagerSystem extends BaseComponentSystem { @In private WorldTime worldTime; + @In + private ClimateConditionsSystem climateConditionsSystem; + + @In + private Context context; + private int countTempAug = 0; + private NetworkSystem networkSystem; + + + @Command(shortDescription = "Print Massage", helpText = "Equivalent to a println but in the chat") + public String printMessage(@CommandParam(value = "text") String text){ + return this.countTempAug+""; + } + @Command(shortDescription = "Make it rain", helpText = "Changes the weather to raining for some time") public String makeRain(@CommandParam(value = "time") int time) { float windX = randomWindSpeed(); @@ -85,14 +118,15 @@ public String makeSnow(@CommandParam(value = "time") int time) { WeatherCondition weatherCondition = new WeatherCondition(Severity.MODERATE, condition, new Vector2f(windX, windY)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); changeWeather(conditionAndDuration); - return "It is now snowing."; + this.changeTemperaturePlayers(); + delayManager.addPeriodicAction(weatherEntity, TEMPERATURE_INCREASE, 10, 100); + return "It is now snowing." + this.currentTemperature; } @Command(shortDescription = "Make it hail", helpText = "Changes the weather to hailing for some time") public String makeHail(@CommandParam(value = "time") int time) { float windX = randomWindSpeed(); float windY = randomWindSpeed(); - DownfallCondition condition = DownfallCondition.get(Severity.MODERATE, DownfallCondition.DownfallType.HAIL, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.MODERATE, condition, new Vector2f(windX, windY)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); @@ -116,8 +150,39 @@ public void onLocalPlayerReady(LocalPlayerInitializedEvent event, EntityRef enti changeWeather(current); } + @ReceiveEvent + public void changeTemperatureEvent(PeriodicActionTriggeredEvent event, EntityRef worldEntity) { + if (event.getActionId().equals(TEMPERATURE_INCREASE)) { + //we create a temperature event to set the temperature of the environment and we set the temperature + new TemperatureIncreaseEvent(); + this.changeTemperaturePlayers(); + } + } + + @ReceiveEvent + public void reduceTemperature(StartSnowEvent event, EntityRef worldEntity) { +// Function function = (Float number) -> { +// return (float) (number - 0.5 * Math.random()); +// }; +// this.climateConditionsSystem.configureTemperature(0, 100, 0, function, +// -10, 30); + } + + @ReceiveEvent + public void increaseTemperature(StartSnowEvent event, EntityRef worldEntity) { + float temperature = this.currentTemperature +0.1f; + Function function = (Float number) -> { + return (float) (temperature); + }; + this.climateConditionsSystem.configureTemperature(0, 200, 0, function, + -10, 30); + this.changeTemperaturePlayers(); + + } + @Override public void postBegin() { + networkSystem = context.get(NetworkSystem.class); float avglength = WorldTime.DAY_LENGTH / 480.0f; // / 48.0f; // worldTime.getTimeRate(); -- not available for modules weatherConditionProvider = new MarkovChainWeatherGenerator(12354, avglength); current = weatherConditionProvider.getNext(); @@ -131,7 +196,6 @@ public void postBegin() { weatherEntity = entityManager.create(); weatherEntity.addComponent(new WeatherBase()); } - changeWeather(current); } @@ -154,6 +218,7 @@ private void changeWeather(ConditionAndDuration conditionAndDuration) { triggerEvents(); } + @ReceiveEvent public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity) { if (event.getActionId().equals("RandomWeather")) { @@ -166,11 +231,13 @@ public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity } } + /** * Adds/removes periodic actions and sends events based on the type of weather it currently is. */ private void triggerEvents() { if (delayManager != null && weatherEntity != null) { + if (delayManager.hasPeriodicAction(weatherEntity, MELT_SNOW)) { delayManager.cancelPeriodicAction(weatherEntity, MELT_SNOW); } @@ -186,11 +253,12 @@ private void triggerEvents() { if (currentWeather.equals(DownfallCondition.DownfallType.SNOW)) { delayManager.addPeriodicAction(weatherEntity, PLACE_SNOW, 200, 400); + this.changeTemperaturePlayers(); } if (currentWeather.equals(DownfallCondition.DownfallType.NONE)) { - delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 150, 300); - delayManager.addPeriodicAction(weatherEntity, EVAPORATE_WATER, 150, 300); + delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 10, 10); + delayManager.addPeriodicAction(weatherEntity, EVAPORATE_WATER, 10, 10); } if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { @@ -255,8 +323,31 @@ public Severity getCurrentSeverity() { return severity; } + public void changeTemperaturePlayers() { + this.countTempAug=100; + List playerPos = this.getPlayersPosition(); + float currentTemp = 0; + for(Vector3fc players : playerPos){ + currentTemp += this.climateConditionsSystem.getTemperature(players.x(), players.y(), players.z()); + } + this.currentTemperature = currentTemp/playerPos.size(); + } + public float randomWindSpeed() { Random rand = new Random(); return (float) Math.random() / (rand.nextInt(21) - 10); } -} + + public List getPlayersPosition() { + final Vector3f position = new Vector3f(); + final Vector3f playerPos = new Vector3f(); + List listPlayerPos = new ArrayList(); + + for (Client currentPlayer : networkSystem.getPlayers()) { + LocationComponent locComp = currentPlayer.getEntity().getComponent(LocationComponent.class); + playerPos.set(locComp.getWorldPosition(position)); + listPlayerPos.add(playerPos); + } + return listPlayerPos; + } +} \ No newline at end of file diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 0000000..a687f07 --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,39 @@ + + + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + From 87d45e77d09ad3d60bde71785025788bb001dd79 Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sat, 16 Dec 2023 18:20:05 +0100 Subject: [PATCH 10/37] I add a method that looks like triggerEvents() but with this new method, we send the current weather condition depending on the humidity and the temperature --- .../systems/WeatherManagerSystem.java | 91 ++++++++++++++++++- .../weather/DownfallCondition.java | 21 ----- 2 files changed, 90 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 60746df..3c542d1 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 package org.terasology.weatherManager.systems; - import com.google.common.math.DoubleMath; import com.google.common.base.Function; import org.joml.Vector2f; @@ -350,4 +349,94 @@ public List getPlayersPosition() { } return listPlayerPos; } + public triggerWeather(int time){ + float currentHumidityDegree = this.climateConditionsSystem.getHumidity(this.getPlayersPosition()) / this.climateConditionsSystem.humidityMaximum ; + Random rand = new Random(); + boolean withThunder = rand.nextInt(2)==0?false:true ; + Severity severity = withThunder==false?Severity.MODERATE: Severity.HEAVY; + if (delayManager != null && weatherEntity != null) { + + if (delayManager.hasPeriodicAction(weatherEntity, MELT_SNOW)) { + delayManager.cancelPeriodicAction(weatherEntity, MELT_SNOW); + } + if (delayManager.hasPeriodicAction(weatherEntity, EVAPORATE_WATER)) { + delayManager.cancelPeriodicAction(weatherEntity, EVAPORATE_WATER); + } + if (delayManager.hasPeriodicAction(weatherEntity, PLACE_SNOW)) { + delayManager.cancelPeriodicAction(weatherEntity, PLACE_SNOW); + } + if (delayManager.hasPeriodicAction(weatherEntity, PLACE_WATER)) { + delayManager.cancelPeriodicAction(weatherEntity, PLACE_WATER); + } + + if (currentWeather.equals(DownfallCondition.DownfallType.SNOW)) { + delayManager.addPeriodicAction(weatherEntity, PLACE_SNOW, 200, 400); + this.changeTemperaturePlayers(); + } + + if (currentWeather.equals(DownfallCondition.DownfallType.NONE)) { + delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 10, 10); + delayManager.addPeriodicAction(weatherEntity, EVAPORATE_WATER, 10, 10); + } + + if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { + delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 150, 300); + delayManager.addPeriodicAction(weatherEntity, PLACE_WATER, 1000, 10000); + } + } + if(currentHumidityDegree>0.7){ + if(this.currentTemperature>0){ + DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.RAIN, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); + ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); + this.current = conditionAndDuration ; + weatherEntity.send(new StartRainEvent()); + } + else if(this.currentTemperature>-10 && this.currentTemperature<=0){ + DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.SNOW, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); + ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); + this.current = conditionAndDuration ; + weatherEntity.send(new StartSnowEvent()); + } + else{ + DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.HAIL, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); + ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); + this.current = conditionAndDuration ; + weatherEntity.send(new StartHailEvent()); + } + } + if(currentHumidityDegree<=0.7 && currentHumidityDegree>0.5 ){ + if(this.currentTemperature>0){ + DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.RAIN, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); + ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); + this.current = conditionAndDuration ; + weatherEntity.send(new StartRainEvent()); + } + else if(this.currentTemperature>-10 && this.currentTemperature<=0){ + DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.SNOW, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); + ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); + this.current = conditionAndDuration ; + weatherEntity.send(new StartSnowEvent()); + } + else{ + DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.HAIL, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); + ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); + this.current = conditionAndDuration ; + weatherEntity.send(new StartHailEvent()); + } + } + if(currentHumidityDegree<=0.5){ + DownfallCondition condition = DownfallCondition.get(Severity.NONE, DownfallCondition.DownfallType.NONE, false); + WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(windX, windY)); + ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); + this.current = conditionAndDuration ; + weatherEntity.send(new StartSunEvent()); + } + + } } \ No newline at end of file diff --git a/src/main/java/org/terasology/weatherManager/weather/DownfallCondition.java b/src/main/java/org/terasology/weatherManager/weather/DownfallCondition.java index fc79ba4..3fd9b39 100644 --- a/src/main/java/org/terasology/weatherManager/weather/DownfallCondition.java +++ b/src/main/java/org/terasology/weatherManager/weather/DownfallCondition.java @@ -78,27 +78,6 @@ public static DownfallCondition get(final Severity amount, final DownfallType ty return INSTANCES.computeIfAbsent(values, (DownfallValues v) -> new DownfallCondition(v) ); */ } - public static DownfallCondition currentDownfall(float temperature, Severity humidity){ - Random rand = new Random(); - boolean withThunder = rand.nextInt(2)==0?false:true ; - // if the severity is none, there is no downfall regardless of the temparature. Also, there is no thunder - // because it would be an illegal combination as stated in the get method of this class - if(humidity.toString().equals("none")){ - return DownfallCondition.get(humidity,DownfallCondition.DownfallType.NONE,false); - } - // it is raining with a severity non equal to none if the temperature is greater than 0 - else if(temperature>0){ - return DownfallCondition.get(humidity,DownfallCondition.DownfallType.RAIN,withThunder); - } - // it is hailing with a severity non equal to none if the temperature greater than -2 and less than 0 - else if(temperature>-2){ - return DownfallCondition.get(humidity,DownfallCondition.DownfallType.HAIL,withThunder); - } - // it is snowing if there is no match with the precedent cases - else { - return DownfallCondition.get(humidity,DownfallCondition.DownfallType.SNOW,withThunder); - } - } public DownfallValues getDownfallValues() { return downfallValues; From 8c55d693dab86c74811b93a20da88f777a0d7fea Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sat, 16 Dec 2023 18:38:12 +0100 Subject: [PATCH 11/37] some correction on the currentWeather method --- .../systems/WeatherManagerSystem.java | 39 +------------------ 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 3c542d1..287dbdc 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -349,62 +349,31 @@ public List getPlayersPosition() { } return listPlayerPos; } - public triggerWeather(int time){ + public void currentWeather(int time){ float currentHumidityDegree = this.climateConditionsSystem.getHumidity(this.getPlayersPosition()) / this.climateConditionsSystem.humidityMaximum ; Random rand = new Random(); boolean withThunder = rand.nextInt(2)==0?false:true ; Severity severity = withThunder==false?Severity.MODERATE: Severity.HEAVY; - if (delayManager != null && weatherEntity != null) { - - if (delayManager.hasPeriodicAction(weatherEntity, MELT_SNOW)) { - delayManager.cancelPeriodicAction(weatherEntity, MELT_SNOW); - } - if (delayManager.hasPeriodicAction(weatherEntity, EVAPORATE_WATER)) { - delayManager.cancelPeriodicAction(weatherEntity, EVAPORATE_WATER); - } - if (delayManager.hasPeriodicAction(weatherEntity, PLACE_SNOW)) { - delayManager.cancelPeriodicAction(weatherEntity, PLACE_SNOW); - } - if (delayManager.hasPeriodicAction(weatherEntity, PLACE_WATER)) { - delayManager.cancelPeriodicAction(weatherEntity, PLACE_WATER); - } - if (currentWeather.equals(DownfallCondition.DownfallType.SNOW)) { - delayManager.addPeriodicAction(weatherEntity, PLACE_SNOW, 200, 400); - this.changeTemperaturePlayers(); - } - - if (currentWeather.equals(DownfallCondition.DownfallType.NONE)) { - delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 10, 10); - delayManager.addPeriodicAction(weatherEntity, EVAPORATE_WATER, 10, 10); - } - - if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { - delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 150, 300); - delayManager.addPeriodicAction(weatherEntity, PLACE_WATER, 1000, 10000); - } - } if(currentHumidityDegree>0.7){ if(this.currentTemperature>0){ DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.RAIN, withThunder); WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); this.current = conditionAndDuration ; - weatherEntity.send(new StartRainEvent()); } else if(this.currentTemperature>-10 && this.currentTemperature<=0){ DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.SNOW, withThunder); WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); this.current = conditionAndDuration ; - weatherEntity.send(new StartSnowEvent()); + } else{ DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.HAIL, withThunder); WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); this.current = conditionAndDuration ; - weatherEntity.send(new StartHailEvent()); } } if(currentHumidityDegree<=0.7 && currentHumidityDegree>0.5 ){ @@ -413,21 +382,18 @@ else if(this.currentTemperature>-10 && this.currentTemperature<=0){ WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); this.current = conditionAndDuration ; - weatherEntity.send(new StartRainEvent()); } else if(this.currentTemperature>-10 && this.currentTemperature<=0){ DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.SNOW, withThunder); WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); this.current = conditionAndDuration ; - weatherEntity.send(new StartSnowEvent()); } else{ DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.HAIL, withThunder); WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); this.current = conditionAndDuration ; - weatherEntity.send(new StartHailEvent()); } } if(currentHumidityDegree<=0.5){ @@ -435,7 +401,6 @@ else if(this.currentTemperature>-10 && this.currentTemperature<=0){ WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(windX, windY)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); this.current = conditionAndDuration ; - weatherEntity.send(new StartSunEvent()); } } From 159931db2eb2926743f0e7280cdabd66ebafe005 Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sat, 16 Dec 2023 18:50:31 +0100 Subject: [PATCH 12/37] some correction on the currentWeather method --- .../systems/WeatherManagerSystem.java | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 287dbdc..2f489e7 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -349,7 +349,7 @@ public List getPlayersPosition() { } return listPlayerPos; } - public void currentWeather(int time){ + public void currentWeather(){ float currentHumidityDegree = this.climateConditionsSystem.getHumidity(this.getPlayersPosition()) / this.climateConditionsSystem.humidityMaximum ; Random rand = new Random(); boolean withThunder = rand.nextInt(2)==0?false:true ; @@ -359,48 +359,41 @@ public void currentWeather(int time){ if(this.currentTemperature>0){ DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.RAIN, withThunder); WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); - this.current = conditionAndDuration ; + this.current.condition = weatherCondition ; } else if(this.currentTemperature>-10 && this.currentTemperature<=0){ DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.SNOW, withThunder); WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); - this.current = conditionAndDuration ; + this.current.condition = weatherCondition ; } else{ DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.HAIL, withThunder); WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); - this.current = conditionAndDuration ; + this.current.condition = weatherCondition ; } } if(currentHumidityDegree<=0.7 && currentHumidityDegree>0.5 ){ if(this.currentTemperature>0){ - DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.RAIN, withThunder); + DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.RAIN, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); - this.current = conditionAndDuration ; + this.current.condition = weatherCondition ; } else if(this.currentTemperature>-10 && this.currentTemperature<=0){ - DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.SNOW, withThunder); + DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.SNOW, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); - this.current = conditionAndDuration ; + this.current.condition = weatherCondition ; } else{ - DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.HAIL, withThunder); + DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.HAIL, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); - this.current = conditionAndDuration ; + this.current.condition = weatherCondition ; } } if(currentHumidityDegree<=0.5){ DownfallCondition condition = DownfallCondition.get(Severity.NONE, DownfallCondition.DownfallType.NONE, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(windX, windY)); - ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); - this.current = conditionAndDuration ; + this.current.condition = weatherCondition ; } } From 79716eb0f2d5db80990eaa96b99963b0cc5ca2bf Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sat, 16 Dec 2023 19:06:17 +0100 Subject: [PATCH 13/37] last version of currentWeather methode, i hope ;) --- .../systems/WeatherManagerSystem.java | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 2f489e7..94f2397 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -350,51 +350,51 @@ public List getPlayersPosition() { return listPlayerPos; } public void currentWeather(){ - float currentHumidityDegree = this.climateConditionsSystem.getHumidity(this.getPlayersPosition()) / this.climateConditionsSystem.humidityMaximum ; Random rand = new Random(); boolean withThunder = rand.nextInt(2)==0?false:true ; Severity severity = withThunder==false?Severity.MODERATE: Severity.HEAVY; - - if(currentHumidityDegree>0.7){ - if(this.currentTemperature>0){ - DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.RAIN, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; + for(Vector3fc position : this.getPlayersPosition()){ + float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / this.climateConditionsSystem.humidityMaximum ; + if(currentHumidityDegree>0.7){ + if(this.currentTemperature>0){ + DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.RAIN, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition ; + } + else if(this.currentTemperature>-10 && this.currentTemperature<=0){ + DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.SNOW, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition ; + + } + else{ + DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.HAIL, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition ; + } } - else if(this.currentTemperature>-10 && this.currentTemperature<=0){ - DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.SNOW, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - + if(currentHumidityDegree<=0.7 && currentHumidityDegree>0.5 ){ + if(this.currentTemperature>0){ + DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.RAIN, false); + WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition ; + } + else if(this.currentTemperature>-10 && this.currentTemperature<=0){ + DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.SNOW, false); + WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition ; + } + else{ + DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.HAIL, false); + WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition ; + } } - else{ - DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.HAIL, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); + if(currentHumidityDegree<=0.5){ + DownfallCondition condition = DownfallCondition.get(Severity.NONE, DownfallCondition.DownfallType.NONE, false); + WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(windX, windY)); this.current.condition = weatherCondition ; } } - if(currentHumidityDegree<=0.7 && currentHumidityDegree>0.5 ){ - if(this.currentTemperature>0){ - DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.RAIN, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - } - else if(this.currentTemperature>-10 && this.currentTemperature<=0){ - DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.SNOW, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - } - else{ - DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.HAIL, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - } - } - if(currentHumidityDegree<=0.5){ - DownfallCondition condition = DownfallCondition.get(Severity.NONE, DownfallCondition.DownfallType.NONE, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - } - } } \ No newline at end of file From aaf8af02688e1eea9f6693990bf77028072aca0e Mon Sep 17 00:00:00 2001 From: Ewwweee Date: Sat, 16 Dec 2023 19:27:41 +0100 Subject: [PATCH 14/37] Added temperature variations --- .../events/TemperatureDecreaseEvent.java | 12 ++ .../events/TemperatureStagnateEvent.java | 12 ++ .../systems/BlockPlacingWeatherSystem.java | 1 + .../systems/WeatherManagerSystem.java | 197 +++++++++++++----- 4 files changed, 170 insertions(+), 52 deletions(-) create mode 100644 src/main/java/org/terasology/weatherManager/events/TemperatureDecreaseEvent.java create mode 100644 src/main/java/org/terasology/weatherManager/events/TemperatureStagnateEvent.java diff --git a/src/main/java/org/terasology/weatherManager/events/TemperatureDecreaseEvent.java b/src/main/java/org/terasology/weatherManager/events/TemperatureDecreaseEvent.java new file mode 100644 index 0000000..2517fa9 --- /dev/null +++ b/src/main/java/org/terasology/weatherManager/events/TemperatureDecreaseEvent.java @@ -0,0 +1,12 @@ +// Copyright 2021 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 + +package org.terasology.weatherManager.events; + +import org.terasology.gestalt.entitysystem.event.Event; + +/** + * Event which is called when the weather changes to hail (frozen raindrop fall) + */ +public class TemperatureDecreaseEvent implements Event { +} diff --git a/src/main/java/org/terasology/weatherManager/events/TemperatureStagnateEvent.java b/src/main/java/org/terasology/weatherManager/events/TemperatureStagnateEvent.java new file mode 100644 index 0000000..ae540be --- /dev/null +++ b/src/main/java/org/terasology/weatherManager/events/TemperatureStagnateEvent.java @@ -0,0 +1,12 @@ +// Copyright 2021 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 + +package org.terasology.weatherManager.events; + +import org.terasology.gestalt.entitysystem.event.Event; + +/** + * Event which is called when the weather changes to hail (frozen raindrop fall) + */ +public class TemperatureStagnateEvent implements Event { +} diff --git a/src/main/java/org/terasology/weatherManager/systems/BlockPlacingWeatherSystem.java b/src/main/java/org/terasology/weatherManager/systems/BlockPlacingWeatherSystem.java index 2bf0613..b2c802d 100644 --- a/src/main/java/org/terasology/weatherManager/systems/BlockPlacingWeatherSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/BlockPlacingWeatherSystem.java @@ -175,3 +175,4 @@ private int getValueToPlaceBlock(int initial) { return initial + rand.nextInt(SNOW_BLOCK_RANGE * 2) - SNOW_BLOCK_RANGE; } } + diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 60746df..3afab00 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -38,6 +38,8 @@ import org.terasology.weatherManager.events.StartSnowEvent; import org.terasology.weatherManager.events.StartSunEvent; import org.terasology.weatherManager.events.TemperatureIncreaseEvent; +import org.terasology.weatherManager.events.TemperatureDecreaseEvent; +import org.terasology.weatherManager.events.TemperatureStagnateEvent; import org.terasology.weatherManager.weather.ConditionAndDuration; import org.terasology.weatherManager.weather.DownfallCondition; import org.terasology.weatherManager.weather.Severity; @@ -60,7 +62,11 @@ public class WeatherManagerSystem extends BaseComponentSystem { public static final String EVAPORATE_WATER = "evaporateWater"; public static final String PLACE_WATER = "placeWater"; public static final String TEMPERATURE_INCREASE = "temperatureIncrease"; - + public static final String TEMPERATURE_DECREASE = "temperatureDecrease"; + public static final String TEMPERATURE_STAGNATE = "temperatureStagnate"; + public static final String DELAYED_TEMPERATURE_CHOICE = "delayTemp"; + public static final float TMAX = 50f; + public static final float TMIN = -10; private static final org.slf4j.Logger logger = LoggerFactory.getLogger(WeatherManagerSystem.class); private Vector2f currentWind = new Vector2f(); @@ -88,15 +94,10 @@ public class WeatherManagerSystem extends BaseComponentSystem { @In private Context context; - private int countTempAug = 0; + private double countTempAug = 0; private NetworkSystem networkSystem; - @Command(shortDescription = "Print Massage", helpText = "Equivalent to a println but in the chat") - public String printMessage(@CommandParam(value = "text") String text){ - return this.countTempAug+""; - } - @Command(shortDescription = "Make it rain", helpText = "Changes the weather to raining for some time") public String makeRain(@CommandParam(value = "time") int time) { float windX = randomWindSpeed(); @@ -118,9 +119,7 @@ public String makeSnow(@CommandParam(value = "time") int time) { WeatherCondition weatherCondition = new WeatherCondition(Severity.MODERATE, condition, new Vector2f(windX, windY)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); changeWeather(conditionAndDuration); - this.changeTemperaturePlayers(); - delayManager.addPeriodicAction(weatherEntity, TEMPERATURE_INCREASE, 10, 100); - return "It is now snowing." + this.currentTemperature; + return "It is now snowing."; } @Command(shortDescription = "Make it hail", helpText = "Changes the weather to hailing for some time") @@ -140,6 +139,7 @@ public String makeSunny(@CommandParam(value = "time") int time) { WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); changeWeather(conditionAndDuration); + delayManager.addDelayedAction(weatherEntity,DELAYED_TEMPERATURE_CHOICE, 100); return "It is now sunny."; } @@ -150,43 +150,12 @@ public void onLocalPlayerReady(LocalPlayerInitializedEvent event, EntityRef enti changeWeather(current); } - @ReceiveEvent - public void changeTemperatureEvent(PeriodicActionTriggeredEvent event, EntityRef worldEntity) { - if (event.getActionId().equals(TEMPERATURE_INCREASE)) { - //we create a temperature event to set the temperature of the environment and we set the temperature - new TemperatureIncreaseEvent(); - this.changeTemperaturePlayers(); - } - } - - @ReceiveEvent - public void reduceTemperature(StartSnowEvent event, EntityRef worldEntity) { -// Function function = (Float number) -> { -// return (float) (number - 0.5 * Math.random()); -// }; -// this.climateConditionsSystem.configureTemperature(0, 100, 0, function, -// -10, 30); - } - - @ReceiveEvent - public void increaseTemperature(StartSnowEvent event, EntityRef worldEntity) { - float temperature = this.currentTemperature +0.1f; - Function function = (Float number) -> { - return (float) (temperature); - }; - this.climateConditionsSystem.configureTemperature(0, 200, 0, function, - -10, 30); - this.changeTemperaturePlayers(); - - } - @Override public void postBegin() { networkSystem = context.get(NetworkSystem.class); float avglength = WorldTime.DAY_LENGTH / 480.0f; // / 48.0f; // worldTime.getTimeRate(); -- not available for modules weatherConditionProvider = new MarkovChainWeatherGenerator(12354, avglength); current = weatherConditionProvider.getNext(); - boolean weatherEntityFound = false; Iterator weatherEntityIter = entityManager.getEntitiesWith(WeatherBase.class).iterator(); @@ -221,6 +190,7 @@ private void changeWeather(ConditionAndDuration conditionAndDuration) { @ReceiveEvent public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity) { + //Each time a delayedActionTriggeredEvent is trigger, we change the way the temperature change if (event.getActionId().equals("RandomWeather")) { current = weatherConditionProvider.getNext(); currentWeather = current.condition.downfallCondition.getDownfallValues().type; @@ -231,13 +201,11 @@ public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity } } - /** * Adds/removes periodic actions and sends events based on the type of weather it currently is. */ private void triggerEvents() { if (delayManager != null && weatherEntity != null) { - if (delayManager.hasPeriodicAction(weatherEntity, MELT_SNOW)) { delayManager.cancelPeriodicAction(weatherEntity, MELT_SNOW); } @@ -253,12 +221,11 @@ private void triggerEvents() { if (currentWeather.equals(DownfallCondition.DownfallType.SNOW)) { delayManager.addPeriodicAction(weatherEntity, PLACE_SNOW, 200, 400); - this.changeTemperaturePlayers(); } if (currentWeather.equals(DownfallCondition.DownfallType.NONE)) { - delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 10, 10); - delayManager.addPeriodicAction(weatherEntity, EVAPORATE_WATER, 10, 10); + delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 100, 100); + delayManager.addPeriodicAction(weatherEntity, EVAPORATE_WATER, 100, 100); } if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { @@ -323,21 +290,29 @@ public Severity getCurrentSeverity() { return severity; } + public float randomWindSpeed() { + Random rand = new Random(); + return (float) Math.random() / (rand.nextInt(21) - 10); + } + + /** + * The temperature is equal of the average temperature between the players + */ public void changeTemperaturePlayers() { - this.countTempAug=100; List playerPos = this.getPlayersPosition(); float currentTemp = 0; + for(Vector3fc players : playerPos){ currentTemp += this.climateConditionsSystem.getTemperature(players.x(), players.y(), players.z()); + } this.currentTemperature = currentTemp/playerPos.size(); } - public float randomWindSpeed() { - Random rand = new Random(); - return (float) Math.random() / (rand.nextInt(21) - 10); - } - + /** + * Get a list of the position of all the players + * @return List listPlayers + */ public List getPlayersPosition() { final Vector3f position = new Vector3f(); final Vector3f playerPos = new Vector3f(); @@ -350,4 +325,122 @@ public List getPlayersPosition() { } return listPlayerPos; } + + @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") + public String printMessage(@CommandParam(value = "text") String text){ + return "this.currentTemperature = " + this.currentTemperature+"\n" + "Nombre de fois triggerEvent called : " + this.countTempAug + + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity,"Weather"); + } + + + /** + * Don't change the current Temperature + * @param event + * @param worldEntity + */ + @ReceiveEvent + public void stagnateTemperature(TemperatureStagnateEvent event, EntityRef worldEntity){ + float temperature = this.currentTemperature; + //T = (TMAX - TMIN)value + TMIN => value = (T - TMIN)/(TMAX -TMIN) + float value = (temperature -TMIN)/(TMAX - TMIN); + Function function = (Float number) -> { + return (float) (value) ; + }; + //I fixed the seaLevel = maxLevel to be sure that the value given if temperatureBase ==> The variation + //Of temperature can be negligee + this.climateConditionsSystem.configureTemperature(200, 200, 0, function, + TMIN, TMAX); + this.changeTemperaturePlayers(); + } + + /** + * Decrease the current Temperature by a number between 0 and 0.01 + * @param event + * @param worldEntity + */ + @ReceiveEvent + public void reduceTemperature(TemperatureDecreaseEvent event, EntityRef worldEntity) { + float temperature = this.currentTemperature; + //T = (TMAX - TMIN)value + TMIN => value = (T - TMIN)/(TMAX -TMIN) + float randNbr = (float)(Math.random()*0.01); + float value = (temperature -TMIN - randNbr)/(TMAX - TMIN); + Function function = (Float number) -> { + return (float) (value) ; + }; + //I fixed the seaLevel = maxLevel to be sure that the value given if temperatureBase ==> The variation + //Of temperature due the height can be negligee + this.climateConditionsSystem.configureTemperature(200, 200, 0, function, + TMIN, TMAX); + this.changeTemperaturePlayers(); + } + + /** + * Increase the current Temperature by a number between 0 and 0.01 + * @param event + * @param worldEntity + */ + @ReceiveEvent + public void increaseTemperature(TemperatureIncreaseEvent event, EntityRef worldEntity) { + float temperature = this.currentTemperature; + //T = (TMAX - TMIN)value + TMIN => value = (T - TMIN)/(TMAX -TMIN) + float randNbr = (float)(Math.random()*0.01); + float value = (temperature -TMIN + randNbr)/(TMAX - TMIN); + Function function = (Float number) -> { + return (float) (value) ; + }; + //I fixed the seaLevel = maxLevel to be sure that the value given if temperatureBase ==> The variation + //Of temperature can be negligee + this.climateConditionsSystem.configureTemperature(200, 200, 0, function, + TMIN, TMAX); + this.changeTemperaturePlayers(); + + } + + /** + * This function create a Temperature Event each period. + * @param event + * @param weatherEntity + */ + @ReceiveEvent + public void chooseTemperatureVariable(PeriodicActionTriggeredEvent event , EntityRef weatherEntity){ + switch(event.getActionId()){ + case TEMPERATURE_INCREASE: + weatherEntity.send(new TemperatureIncreaseEvent()); + break; + case TEMPERATURE_DECREASE: + weatherEntity.send(new TemperatureDecreaseEvent()); + break; + case TEMPERATURE_STAGNATE: + weatherEntity.send(new TemperatureStagnateEvent()); + break; + } + } + + /** + * This class will create a periodicAction which will either increase, decrease the temperature or + * make it stagnate + * @param event + * @param weatherEntity + */ + @ReceiveEvent + public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weatherEntity) { + if(event.getActionId().equals(DELAYED_TEMPERATURE_CHOICE)){ + //We cancel all periodic action + if(delayManager.hasPeriodicAction(weatherEntity,TEMPERATURE_INCREASE)){ + delayManager.cancelPeriodicAction(weatherEntity,TEMPERATURE_INCREASE); + } + if(delayManager.hasPeriodicAction(weatherEntity,TEMPERATURE_DECREASE)){ + delayManager.cancelPeriodicAction(weatherEntity,TEMPERATURE_DECREASE); + } + if(delayManager.hasPeriodicAction(weatherEntity,TEMPERATURE_STAGNATE)){ + delayManager.cancelPeriodicAction(weatherEntity,TEMPERATURE_STAGNATE); + } + this.countTempAug++; + String[] tempChoices = {TEMPERATURE_STAGNATE,TEMPERATURE_INCREASE,TEMPERATURE_DECREASE}; + int indexChoice = (int)(Math.random()*3); + delayManager.addPeriodicAction(weatherEntity, tempChoices[indexChoice], 0, 100); + //We add another delayed action to do this action again, over and over + delayManager.addDelayedAction(weatherEntity,DELAYED_TEMPERATURE_CHOICE, 100000); + } + } } \ No newline at end of file From 4442083a7049622ad1809f8a44b7a2c7b6cc2b87 Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sat, 16 Dec 2023 20:11:49 +0100 Subject: [PATCH 15/37] ras --- .../terasology/weatherManager/systems/WeatherManagerSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 94f2397..4191655 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -349,7 +349,7 @@ public List getPlayersPosition() { } return listPlayerPos; } - public void currentWeather(){ + public void curWeather(){ Random rand = new Random(); boolean withThunder = rand.nextInt(2)==0?false:true ; Severity severity = withThunder==false?Severity.MODERATE: Severity.HEAVY; From 3869517a9a0bca60bf824bb023beb8c0f73d37f1 Mon Sep 17 00:00:00 2001 From: Ewwweee Date: Sat, 16 Dec 2023 22:22:03 +0100 Subject: [PATCH 16/37] pb commit --- .../weatherManager/systems/WeatherManagerSystem.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 3afab00..e90ba23 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -66,7 +66,9 @@ public class WeatherManagerSystem extends BaseComponentSystem { public static final String TEMPERATURE_STAGNATE = "temperatureStagnate"; public static final String DELAYED_TEMPERATURE_CHOICE = "delayTemp"; public static final float TMAX = 50f; - public static final float TMIN = -10; + public static final float TMIN = -10f; + public static final float TFREEZE = 0f; + public static final float TEBULLITION = 20f; private static final org.slf4j.Logger logger = LoggerFactory.getLogger(WeatherManagerSystem.class); private Vector2f currentWind = new Vector2f(); From a25dfbccfc55f67d69e25c6ef3a1f3fb03929b61 Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sun, 17 Dec 2023 10:28:27 +0100 Subject: [PATCH 17/37] correction --- .../systems/WeatherManagerSystem.java | 77 +++++++++---------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 4191655..a6b5bd3 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -349,52 +349,51 @@ public List getPlayersPosition() { } return listPlayerPos; } - public void curWeather(){ + public void curWeather() { Random rand = new Random(); - boolean withThunder = rand.nextInt(2)==0?false:true ; - Severity severity = withThunder==false?Severity.MODERATE: Severity.HEAVY; - for(Vector3fc position : this.getPlayersPosition()){ - float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / this.climateConditionsSystem.humidityMaximum ; - if(currentHumidityDegree>0.7){ - if(this.currentTemperature>0){ - DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.RAIN, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - } - else if(this.currentTemperature>-10 && this.currentTemperature<=0){ - DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.SNOW, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - - } - else{ - DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.HAIL, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; + boolean withThunder = rand.nextInt(2) == 0 ? false : true; + this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; + for (Vector3fc position : this.getPlayersPosition()) { + float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / this.climateConditionsSystem.humidityMaximum; + if (currentHumidityDegree > 0.7) { + if (this.currentTemperature > 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition; + } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition; + + } else { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition; } } - if(currentHumidityDegree<=0.7 && currentHumidityDegree>0.5 ){ - if(this.currentTemperature>0){ - DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.RAIN, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - } - else if(this.currentTemperature>-10 && this.currentTemperature<=0){ - DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.SNOW, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - } - else{ - DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.HAIL, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; + if (currentHumidityDegree <= 0.7 && currentHumidityDegree > 0.5) { + this.severity = Severity.LIGHT + if (this.currentTemperature > 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, false); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition; + } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, false); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition; + } else { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.current.condition = weatherCondition; } } - if(currentHumidityDegree<=0.5){ - DownfallCondition condition = DownfallCondition.get(Severity.NONE, DownfallCondition.DownfallType.NONE, false); + if (currentHumidityDegree <= 0.5) { + this.severity = Severity.NONE + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.NONE, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; + this.current.condition = weatherCondition; } } } + } \ No newline at end of file From 6d76292b8a401caaaa46f3402ecd6913af96fc2a Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sun, 17 Dec 2023 11:10:20 +0100 Subject: [PATCH 18/37] correction --- .../systems/WeatherManagerSystem.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index a6b5bd3..0feaad0 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -235,6 +235,7 @@ public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity * Adds/removes periodic actions and sends events based on the type of weather it currently is. */ private void triggerEvents() { + curWeather(); if (delayManager != null && weatherEntity != null) { if (delayManager.hasPeriodicAction(weatherEntity, MELT_SNOW)) { @@ -351,47 +352,56 @@ public List getPlayersPosition() { } public void curWeather() { Random rand = new Random(); + float windX = randomWindSpeed(); + float windY = randomWindSpeed(); boolean withThunder = rand.nextInt(2) == 0 ? false : true; this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; for (Vector3fc position : this.getPlayersPosition()) { - float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / this.climateConditionsSystem.humidityMaximum; + float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / 100 ; if (currentHumidityDegree > 0.7) { if (this.currentTemperature > 0) { DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, withThunder); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); } else { DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); } } if (currentHumidityDegree <= 0.7 && currentHumidityDegree > 0.5) { - this.severity = Severity.LIGHT + this.severity = Severity.LIGHT ; if (this.currentTemperature > 0) { DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, false); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, false); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); } else { DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); } } if (currentHumidityDegree <= 0.5) { - this.severity = Severity.NONE + this.severity = Severity.NONE ; DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.NONE, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition; + WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); } } } From 9df40b6247dacc865aa44f6f64dc43cef104e89a Mon Sep 17 00:00:00 2001 From: oussama Date: Sun, 17 Dec 2023 11:26:08 +0100 Subject: [PATCH 19/37] oussama --- .../systems/WeatherManagerSystem.java | 122 ++++++++++++++---- 1 file changed, 94 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 3afab00..8fc1227 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -44,6 +44,10 @@ import org.terasology.weatherManager.weather.DownfallCondition; import org.terasology.weatherManager.weather.Severity; import org.terasology.weatherManager.weather.WeatherCondition; +import org.terasology.engine.network.Client; +import org.terasology.engine.logic.location.LocationComponent; + + import java.math.RoundingMode; import java.util.Iterator; @@ -97,6 +101,8 @@ public class WeatherManagerSystem extends BaseComponentSystem { private double countTempAug = 0; private NetworkSystem networkSystem; + @In + private WorldProvider worldProvider; @Command(shortDescription = "Make it rain", helpText = "Changes the weather to raining for some time") public String makeRain(@CommandParam(value = "time") int time) { @@ -139,7 +145,7 @@ public String makeSunny(@CommandParam(value = "time") int time) { WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); changeWeather(conditionAndDuration); - delayManager.addDelayedAction(weatherEntity,DELAYED_TEMPERATURE_CHOICE, 100); + delayManager.addDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE, 100); return "It is now sunny."; } @@ -302,15 +308,16 @@ public void changeTemperaturePlayers() { List playerPos = this.getPlayersPosition(); float currentTemp = 0; - for(Vector3fc players : playerPos){ + for (Vector3fc players : playerPos) { currentTemp += this.climateConditionsSystem.getTemperature(players.x(), players.y(), players.z()); } - this.currentTemperature = currentTemp/playerPos.size(); + this.currentTemperature = currentTemp / playerPos.size(); } /** * Get a list of the position of all the players + * * @return List listPlayers */ public List getPlayersPosition() { @@ -327,24 +334,25 @@ public List getPlayersPosition() { } @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") - public String printMessage(@CommandParam(value = "text") String text){ - return "this.currentTemperature = " + this.currentTemperature+"\n" + "Nombre de fois triggerEvent called : " + this.countTempAug - + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity,"Weather"); + public String printMessage(@CommandParam(value = "text") String text) { + return "this.currentTemperature = " + this.currentTemperature + "\n" + "Nombre de fois triggerEvent called : " + this.countTempAug + + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity, "Weather"); } /** * Don't change the current Temperature + * * @param event * @param worldEntity */ @ReceiveEvent - public void stagnateTemperature(TemperatureStagnateEvent event, EntityRef worldEntity){ + public void stagnateTemperature(TemperatureStagnateEvent event, EntityRef worldEntity) { float temperature = this.currentTemperature; //T = (TMAX - TMIN)value + TMIN => value = (T - TMIN)/(TMAX -TMIN) - float value = (temperature -TMIN)/(TMAX - TMIN); + float value = (temperature - TMIN) / (TMAX - TMIN); Function function = (Float number) -> { - return (float) (value) ; + return (float) (value); }; //I fixed the seaLevel = maxLevel to be sure that the value given if temperatureBase ==> The variation //Of temperature can be negligee @@ -355,6 +363,7 @@ public void stagnateTemperature(TemperatureStagnateEvent event, EntityRef world /** * Decrease the current Temperature by a number between 0 and 0.01 + * * @param event * @param worldEntity */ @@ -362,10 +371,10 @@ public void stagnateTemperature(TemperatureStagnateEvent event, EntityRef world public void reduceTemperature(TemperatureDecreaseEvent event, EntityRef worldEntity) { float temperature = this.currentTemperature; //T = (TMAX - TMIN)value + TMIN => value = (T - TMIN)/(TMAX -TMIN) - float randNbr = (float)(Math.random()*0.01); - float value = (temperature -TMIN - randNbr)/(TMAX - TMIN); + float randNbr = (float) (Math.random() * 0.01); + float value = (temperature - TMIN - randNbr) / (TMAX - TMIN); Function function = (Float number) -> { - return (float) (value) ; + return (float) (value); }; //I fixed the seaLevel = maxLevel to be sure that the value given if temperatureBase ==> The variation //Of temperature due the height can be negligee @@ -376,6 +385,7 @@ public void reduceTemperature(TemperatureDecreaseEvent event, EntityRef worldEnt /** * Increase the current Temperature by a number between 0 and 0.01 + * * @param event * @param worldEntity */ @@ -383,10 +393,10 @@ public void reduceTemperature(TemperatureDecreaseEvent event, EntityRef worldEnt public void increaseTemperature(TemperatureIncreaseEvent event, EntityRef worldEntity) { float temperature = this.currentTemperature; //T = (TMAX - TMIN)value + TMIN => value = (T - TMIN)/(TMAX -TMIN) - float randNbr = (float)(Math.random()*0.01); - float value = (temperature -TMIN + randNbr)/(TMAX - TMIN); + float randNbr = (float) (Math.random() * 0.01); + float value = (temperature - TMIN + randNbr) / (TMAX - TMIN); Function function = (Float number) -> { - return (float) (value) ; + return (float) (value); }; //I fixed the seaLevel = maxLevel to be sure that the value given if temperatureBase ==> The variation //Of temperature can be negligee @@ -398,12 +408,13 @@ public void increaseTemperature(TemperatureIncreaseEvent event, EntityRef worldE /** * This function create a Temperature Event each period. + * * @param event * @param weatherEntity */ @ReceiveEvent - public void chooseTemperatureVariable(PeriodicActionTriggeredEvent event , EntityRef weatherEntity){ - switch(event.getActionId()){ + public void chooseTemperatureVariable(PeriodicActionTriggeredEvent event, EntityRef weatherEntity) { + switch (event.getActionId()) { case TEMPERATURE_INCREASE: weatherEntity.send(new TemperatureIncreaseEvent()); break; @@ -419,28 +430,83 @@ public void chooseTemperatureVariable(PeriodicActionTriggeredEvent event , Entit /** * This class will create a periodicAction which will either increase, decrease the temperature or * make it stagnate + * * @param event * @param weatherEntity */ @ReceiveEvent public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weatherEntity) { - if(event.getActionId().equals(DELAYED_TEMPERATURE_CHOICE)){ + if (event.getActionId().equals(DELAYED_TEMPERATURE_CHOICE)) { //We cancel all periodic action - if(delayManager.hasPeriodicAction(weatherEntity,TEMPERATURE_INCREASE)){ - delayManager.cancelPeriodicAction(weatherEntity,TEMPERATURE_INCREASE); + if (delayManager.hasPeriodicAction(weatherEntity, TEMPERATURE_INCREASE)) { + delayManager.cancelPeriodicAction(weatherEntity, TEMPERATURE_INCREASE); } - if(delayManager.hasPeriodicAction(weatherEntity,TEMPERATURE_DECREASE)){ - delayManager.cancelPeriodicAction(weatherEntity,TEMPERATURE_DECREASE); + if (delayManager.hasPeriodicAction(weatherEntity, TEMPERATURE_DECREASE)) { + delayManager.cancelPeriodicAction(weatherEntity, TEMPERATURE_DECREASE); } - if(delayManager.hasPeriodicAction(weatherEntity,TEMPERATURE_STAGNATE)){ - delayManager.cancelPeriodicAction(weatherEntity,TEMPERATURE_STAGNATE); + if (delayManager.hasPeriodicAction(weatherEntity, TEMPERATURE_STAGNATE)) { + delayManager.cancelPeriodicAction(weatherEntity, TEMPERATURE_STAGNATE); } this.countTempAug++; - String[] tempChoices = {TEMPERATURE_STAGNATE,TEMPERATURE_INCREASE,TEMPERATURE_DECREASE}; - int indexChoice = (int)(Math.random()*3); + String[] tempChoices = {TEMPERATURE_STAGNATE, TEMPERATURE_INCREASE, TEMPERATURE_DECREASE}; + int indexChoice = (int) (Math.random() * 3); delayManager.addPeriodicAction(weatherEntity, tempChoices[indexChoice], 0, 100); //We add another delayed action to do this action again, over and over - delayManager.addDelayedAction(weatherEntity,DELAYED_TEMPERATURE_CHOICE, 100000); + delayManager.addDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE, 100000); + } + } + + /** + * Having the snow melt when the temperature reaches 0 degree + */ + public void startMelting(EntityRef weatherEntity) { + if (this.currentTemperature >= 0.0) { + delayManager.cancelPeriodicAction(weatherEntity, MELT_SNOW); + delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 100, 100); + } + for (Client currentPlayer : networkSystem.getPlayers()) { + Vector3i playerPos = new Vector3i(); + LocationComponent locComp = currentPlayer.getEntity().getComponent(LocationComponent.class); + playerPos.set(locComp.getWorldPosition(position), RoundingMode.FLOOR); + meltSnow(playerPos); + } + } + + private Vector3i findSpot(Block toCheck, int x, int z, int initialY) { + int currentY = initialY + SNOW_BLOCK_RANGE; + int iter = 0; + while (iter < SNOW_BLOCK_RANGE * 2 && worldProvider.getBlock(x, currentY, z).equals(air)) { + iter++; + currentY--; + } + while (iter < SNOW_BLOCK_RANGE * 2 && !worldProvider.getBlock(x, currentY, z).equals(air)) { + iter++; + currentY++; + } + if (iter >= SNOW_BLOCK_RANGE * 2) { + return null; + } + + if (worldProvider.getSunlight(x, currentY, z) != Chunks.MAX_SUNLIGHT) { + // The block isn't actually exposed to the weather. + return null; + } + Block ground = worldProvider.getBlock(x, currentY - 1, z); + if (ground.equals(toCheck)) { + return new Vector3i(x, currentY - 1, z); + } else if (toCheck.equals(air) && !ground.isPenetrable() && ground.isAttachmentAllowed()) { + return new Vector3i(x, currentY, z); + } else { + return null; + } + } + private void meltSnow(Vector3ic playerPos) { + int x = getValueToPlaceBlock(playerPos.x()); + int z = getValueToPlaceBlock(playerPos.z()); + Vector3i spotToPlace = findSpot(snow, x, z, playerPos.y()); + if (spotToPlace != null) { + worldProvider.setBlock(spotToPlace, water); } } -} \ No newline at end of file +} + From dcb12cab38c73b17910270f612e6ef2f7a100cbc Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sun, 17 Dec 2023 11:39:11 +0100 Subject: [PATCH 20/37] correction --- .../terasology/weatherManager/systems/WeatherManagerSystem.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 0feaad0..3c4b91c 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -235,7 +235,6 @@ public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity * Adds/removes periodic actions and sends events based on the type of weather it currently is. */ private void triggerEvents() { - curWeather(); if (delayManager != null && weatherEntity != null) { if (delayManager.hasPeriodicAction(weatherEntity, MELT_SNOW)) { From 834bb9d0fb271525679337de239c42150d5770ea Mon Sep 17 00:00:00 2001 From: Ewwweee Date: Sun, 17 Dec 2023 11:43:10 +0100 Subject: [PATCH 21/37] Meaa --- .../systems/WeatherManagerSystem.java | 115 +++++++++--------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index b22697f..f1c1e6c 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -140,7 +140,7 @@ public String makeSunny(@CommandParam(value = "time") int time) { WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); changeWeather(conditionAndDuration); - delayManager.addDelayedAction(weatherEntity,DELAYED_TEMPERATURE_CHOICE, 100); + delayManager.addDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE, 100); return "It is now sunny."; } @@ -303,15 +303,16 @@ public void changeTemperaturePlayers() { List playerPos = this.getPlayersPosition(); float currentTemp = 0; - for(Vector3fc players : playerPos){ + for (Vector3fc players : playerPos) { currentTemp += this.climateConditionsSystem.getTemperature(players.x(), players.y(), players.z()); } - this.currentTemperature = currentTemp/playerPos.size(); + this.currentTemperature = currentTemp / playerPos.size(); } /** * Get a list of the position of all the players + * * @return List listPlayers */ public List getPlayersPosition() { @@ -326,74 +327,72 @@ public List getPlayersPosition() { } return listPlayerPos; } - - public void currentWeather(){ + + public void currentWeather() { Random rand = new Random(); - boolean withThunder = rand.nextInt(2)==0?false:true ; - Severity severity = withThunder==false?Severity.MODERATE: Severity.HEAVY; - for(Vector3fc position : this.getPlayersPosition()){ - float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / this.climateConditionsSystem.humidityMaximum ; - if(currentHumidityDegree>0.7){ - if(this.currentTemperature>0){ + boolean withThunder = rand.nextInt(2) == 0 ? false : true; + Severity severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; + for (Vector3fc position : this.getPlayersPosition()) { + float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / this.climateConditionsSystem.humidityMaximum; + if (currentHumidityDegree > 0.7) { + if (this.currentTemperature > 0) { DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.RAIN, withThunder); WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - } - else if(this.currentTemperature>-10 && this.currentTemperature<=0){ + this.current.condition = weatherCondition; + } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.SNOW, withThunder); WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; + this.current.condition = weatherCondition; - } - else{ + } else { DownfallCondition condition = DownfallCondition.get(severity, DownfallCondition.DownfallType.HAIL, withThunder); WeatherCondition weatherCondition = new WeatherCondition(severity, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; + this.current.condition = weatherCondition; } } - if(currentHumidityDegree<=0.7 && currentHumidityDegree>0.5 ){ - if(this.currentTemperature>0){ + if (currentHumidityDegree <= 0.7 && currentHumidityDegree > 0.5) { + if (this.currentTemperature > 0) { DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.RAIN, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - } - else if(this.currentTemperature>-10 && this.currentTemperature<=0){ + this.current.condition = weatherCondition; + } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.SNOW, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; - } - else{ + this.current.condition = weatherCondition; + } else { DownfallCondition condition = DownfallCondition.get(Severity.LIGHT, DownfallCondition.DownfallType.HAIL, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.LIGHT, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; + this.current.condition = weatherCondition; } } - if(currentHumidityDegree<=0.5){ + if (currentHumidityDegree <= 0.5) { DownfallCondition condition = DownfallCondition.get(Severity.NONE, DownfallCondition.DownfallType.NONE, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(windX, windY)); - this.current.condition = weatherCondition ; + this.current.condition = weatherCondition; } } + } @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") - public String printMessage(@CommandParam(value = "text") String text){ - return "this.currentTemperature = " + this.currentTemperature+"\n" + "Nombre de fois triggerEvent called : " + this.countTempAug - + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity,"Weather"); + public String printMessage(@CommandParam(value = "text") String text) { + return "this.currentTemperature = " + this.currentTemperature + "\n" + "Nombre de fois triggerEvent called : " + this.countTempAug + + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity, "Weather"); } /** * Don't change the current Temperature + * * @param event * @param worldEntity */ @ReceiveEvent - public void stagnateTemperature(TemperatureStagnateEvent event, EntityRef worldEntity){ + public void stagnateTemperature(TemperatureStagnateEvent event, EntityRef worldEntity) { float temperature = this.currentTemperature; //T = (TMAX - TMIN)value + TMIN => value = (T - TMIN)/(TMAX -TMIN) - float value = (temperature -TMIN)/(TMAX - TMIN); + float value = (temperature - TMIN) / (TMAX - TMIN); Function function = (Float number) -> { - return (float) (value) ; + return (float) (value); }; //I fixed the seaLevel = maxLevel to be sure that the value given if temperatureBase ==> The variation //Of temperature can be negligee @@ -404,6 +403,7 @@ public void stagnateTemperature(TemperatureStagnateEvent event, EntityRef world /** * Decrease the current Temperature by a number between 0 and 0.01 + * * @param event * @param worldEntity */ @@ -411,10 +411,10 @@ public void stagnateTemperature(TemperatureStagnateEvent event, EntityRef world public void reduceTemperature(TemperatureDecreaseEvent event, EntityRef worldEntity) { float temperature = this.currentTemperature; //T = (TMAX - TMIN)value + TMIN => value = (T - TMIN)/(TMAX -TMIN) - float randNbr = (float)(Math.random()*0.01); - float value = (temperature -TMIN - randNbr)/(TMAX - TMIN); + float randNbr = (float) (Math.random() * 0.01); + float value = (temperature - TMIN - randNbr) / (TMAX - TMIN); Function function = (Float number) -> { - return (float) (value) ; + return (float) (value); }; //I fixed the seaLevel = maxLevel to be sure that the value given if temperatureBase ==> The variation //Of temperature due the height can be negligee @@ -425,6 +425,7 @@ public void reduceTemperature(TemperatureDecreaseEvent event, EntityRef worldEnt /** * Increase the current Temperature by a number between 0 and 0.01 + * * @param event * @param worldEntity */ @@ -432,10 +433,10 @@ public void reduceTemperature(TemperatureDecreaseEvent event, EntityRef worldEnt public void increaseTemperature(TemperatureIncreaseEvent event, EntityRef worldEntity) { float temperature = this.currentTemperature; //T = (TMAX - TMIN)value + TMIN => value = (T - TMIN)/(TMAX -TMIN) - float randNbr = (float)(Math.random()*0.01); - float value = (temperature -TMIN + randNbr)/(TMAX - TMIN); + float randNbr = (float) (Math.random() * 0.01); + float value = (temperature - TMIN + randNbr) / (TMAX - TMIN); Function function = (Float number) -> { - return (float) (value) ; + return (float) (value); }; //I fixed the seaLevel = maxLevel to be sure that the value given if temperatureBase ==> The variation //Of temperature can be negligee @@ -447,12 +448,13 @@ public void increaseTemperature(TemperatureIncreaseEvent event, EntityRef worldE /** * This function create a Temperature Event each period. + * * @param event * @param weatherEntity */ @ReceiveEvent - public void chooseTemperatureVariable(PeriodicActionTriggeredEvent event , EntityRef weatherEntity){ - switch(event.getActionId()){ + public void chooseTemperatureVariable(PeriodicActionTriggeredEvent event, EntityRef weatherEntity) { + switch (event.getActionId()) { case TEMPERATURE_INCREASE: weatherEntity.send(new TemperatureIncreaseEvent()); break; @@ -466,30 +468,31 @@ public void chooseTemperatureVariable(PeriodicActionTriggeredEvent event , Entit } /** - * This class will create a periodicAction which will either increase, decrease the temperature or - * make it stagnate + * This class will create a periodicAction which will either increase, decrease the temperature or make it stagnate + * * @param event * @param weatherEntity */ @ReceiveEvent public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weatherEntity) { - if(event.getActionId().equals(DELAYED_TEMPERATURE_CHOICE)){ + if (event.getActionId().equals(DELAYED_TEMPERATURE_CHOICE)) { //We cancel all periodic action - if(delayManager.hasPeriodicAction(weatherEntity,TEMPERATURE_INCREASE)){ - delayManager.cancelPeriodicAction(weatherEntity,TEMPERATURE_INCREASE); + if (delayManager.hasPeriodicAction(weatherEntity, TEMPERATURE_INCREASE)) { + delayManager.cancelPeriodicAction(weatherEntity, TEMPERATURE_INCREASE); } - if(delayManager.hasPeriodicAction(weatherEntity,TEMPERATURE_DECREASE)){ - delayManager.cancelPeriodicAction(weatherEntity,TEMPERATURE_DECREASE); + if (delayManager.hasPeriodicAction(weatherEntity, TEMPERATURE_DECREASE)) { + delayManager.cancelPeriodicAction(weatherEntity, TEMPERATURE_DECREASE); } - if(delayManager.hasPeriodicAction(weatherEntity,TEMPERATURE_STAGNATE)){ - delayManager.cancelPeriodicAction(weatherEntity,TEMPERATURE_STAGNATE); + if (delayManager.hasPeriodicAction(weatherEntity, TEMPERATURE_STAGNATE)) { + delayManager.cancelPeriodicAction(weatherEntity, TEMPERATURE_STAGNATE); } this.countTempAug++; - String[] tempChoices = {TEMPERATURE_STAGNATE,TEMPERATURE_INCREASE,TEMPERATURE_DECREASE}; - int indexChoice = (int)(Math.random()*3); + String[] tempChoices = {TEMPERATURE_STAGNATE, TEMPERATURE_INCREASE, TEMPERATURE_DECREASE}; + int indexChoice = (int) (Math.random() * 3); delayManager.addPeriodicAction(weatherEntity, tempChoices[indexChoice], 0, 100); //We add another delayed action to do this action again, over and over - delayManager.addDelayedAction(weatherEntity,DELAYED_TEMPERATURE_CHOICE, 100000); + delayManager.addDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE, 100000); } - + + } } \ No newline at end of file From 0693ba45109ed604828a341d7b03d73b21210121 Mon Sep 17 00:00:00 2001 From: Ihebsmai <146442711+Ihebsmai@users.noreply.github.com> Date: Sun, 17 Dec 2023 12:16:01 +0100 Subject: [PATCH 22/37] Update increaseHumidity --- .../systems/WeatherManagerSystem.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index c774002..13c1504 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -68,6 +68,9 @@ public class WeatherManagerSystem extends BaseComponentSystem { public static final String TEMPERATURE_DECREASE = "temperatureDecrease"; public static final String TEMPERATURE_STAGNATE = "temperatureStagnate"; public static final String DELAYED_TEMPERATURE_CHOICE = "delayTemp"; + + public static final String HUMIDITY_INCREASE = "HumidityIncrease"; + public static final float TMAX = 50f; public static final float TMIN = -10f; public static final float TFREEZE = 0f; @@ -81,6 +84,7 @@ public class WeatherManagerSystem extends BaseComponentSystem { private WeatherConditionProvider weatherConditionProvider; private float currentTemperature; + private float currentHumidity; private ConditionAndDuration current; private EntityRef weatherEntity; @@ -238,6 +242,7 @@ private void triggerEvents() { if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 150, 300); delayManager.addPeriodicAction(weatherEntity, PLACE_WATER, 1000, 10000); + increaseHumidity(); } } @@ -570,5 +575,18 @@ private void meltSnow(Vector3ic playerPos) { worldProvider.setBlock(spotToPlace, water); } } + public void increaseHumidity() { + float humidity = this.currentHumidity; + float humidityMin = climateConditionsSystem.getHumidityMinimum(); + float humidityMax = climateConditionsSystem.getHumidityMaximum(); + float randNbr = (float) (Math.random() * 0.01); + float value = (humidity - humidityMin + randNbr) / (humidityMax - humidityMin); + Function function = (Float number) -> { + return (float) (value); + }; + + this.climateConditionsSystem.configureHumidity(200, 200, 0, function, + humidityMin, humidityMax); + } } From e188d31e8c7e489d7b81a2906285c297dfb1215d Mon Sep 17 00:00:00 2001 From: Ewwweee Date: Sun, 17 Dec 2023 12:40:19 +0100 Subject: [PATCH 23/37] melt, freeze, evaporate --- .../systems/BlockPlacingWeatherSystem.java | 17 ++++ .../systems/WeatherManagerSystem.java | 97 ++++++------------- 2 files changed, 47 insertions(+), 67 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/BlockPlacingWeatherSystem.java b/src/main/java/org/terasology/weatherManager/systems/BlockPlacingWeatherSystem.java index b2c802d..1c0ba56 100644 --- a/src/main/java/org/terasology/weatherManager/systems/BlockPlacingWeatherSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/BlockPlacingWeatherSystem.java @@ -28,6 +28,7 @@ import static org.terasology.weatherManager.systems.WeatherManagerSystem.MELT_SNOW; import static org.terasology.weatherManager.systems.WeatherManagerSystem.PLACE_SNOW; import static org.terasology.weatherManager.systems.WeatherManagerSystem.PLACE_WATER; +import static org.terasology.weatherManager.systems.WeatherManagerSystem.FREEZE_WATER; @RegisterSystem(RegisterMode.AUTHORITY) public class BlockPlacingWeatherSystem extends BaseComponentSystem { @@ -96,6 +97,13 @@ public void onPlaceEvent(PeriodicActionTriggeredEvent event, EntityRef worldEnti evaporateWater(playerPos); } break; + case FREEZE_WATER: + for (Client currentPlayer : networkSystem.getPlayers()) { + LocationComponent locComp = currentPlayer.getEntity().getComponent(LocationComponent.class); + playerPos.set(locComp.getWorldPosition(position), RoundingMode.FLOOR); + freezeWater(playerPos); + } + break; } } @@ -144,6 +152,15 @@ private void placeSnow(Vector3ic playerPos) { } } + private void freezeWater(Vector3ic playerPos) { + int x = getValueToPlaceBlock(playerPos.x()); + int z = getValueToPlaceBlock(playerPos.z()); + Vector3i spotToPlace = findSpot(water, x, z, playerPos.y()); + if (spotToPlace != null) { + worldProvider.setBlock(spotToPlace, snow); + } + } + private void meltSnow(Vector3ic playerPos) { int x = getValueToPlaceBlock(playerPos.x()); int z = getValueToPlaceBlock(playerPos.z()); diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index c774002..af528d2 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -62,6 +62,7 @@ public class WeatherManagerSystem extends BaseComponentSystem { public static final String PLACE_SNOW = "placeSnow"; public static final String MELT_SNOW = "meltSnow"; + public static final String FREEZE_WATER = "freezeWater"; public static final String EVAPORATE_WATER = "evaporateWater"; public static final String PLACE_WATER = "placeWater"; public static final String TEMPERATURE_INCREASE = "temperatureIncrease"; @@ -102,8 +103,6 @@ public class WeatherManagerSystem extends BaseComponentSystem { private double countTempAug = 0; private NetworkSystem networkSystem; - @In - private WorldProvider worldProvider; @Command(shortDescription = "Make it rain", helpText = "Changes the weather to raining for some time") public String makeRain(@CommandParam(value = "time") int time) { @@ -212,6 +211,9 @@ public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity * Adds/removes periodic actions and sends events based on the type of weather it currently is. */ private void triggerEvents() { + if(!delayManager.hasDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE)) { + delayManager.addDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE, 100000); + } if (delayManager != null && weatherEntity != null) { if (delayManager.hasPeriodicAction(weatherEntity, MELT_SNOW)) { delayManager.cancelPeriodicAction(weatherEntity, MELT_SNOW); @@ -225,20 +227,26 @@ private void triggerEvents() { if (delayManager.hasPeriodicAction(weatherEntity, PLACE_WATER)) { delayManager.cancelPeriodicAction(weatherEntity, PLACE_WATER); } + if (delayManager.hasPeriodicAction(weatherEntity, FREEZE_WATER)) { + delayManager.cancelPeriodicAction(weatherEntity, FREEZE_WATER); + } if (currentWeather.equals(DownfallCondition.DownfallType.SNOW)) { delayManager.addPeriodicAction(weatherEntity, PLACE_SNOW, 200, 400); } - - if (currentWeather.equals(DownfallCondition.DownfallType.NONE)) { + if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { + delayManager.addPeriodicAction(weatherEntity, PLACE_WATER, 1000, 1000); + } + if (this.currentTemperature > 0) { delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 100, 100); + } + if (this.currentTemperature > 20) { delayManager.addPeriodicAction(weatherEntity, EVAPORATE_WATER, 100, 100); } - - if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { - delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 150, 300); - delayManager.addPeriodicAction(weatherEntity, PLACE_WATER, 1000, 10000); + if (this.currentTemperature < 0) { + delayManager.addPeriodicAction(weatherEntity, FREEZE_WATER, 10, 100); } + } if (currentWeather.equals(DownfallCondition.DownfallType.SNOW)) { @@ -396,6 +404,13 @@ public String printMessage(@CommandParam(value = "text") String text) { + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity, "Weather"); } + @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") + public String setTemperature(@CommandParam(value = "text") int temp) { + this.currentTemperature = temp; + return "this.currentTemperature = " + this.currentTemperature + "\n" + "Nombre de fois triggerEvent called : " + this.countTempAug + + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity, "Weather"); + } + /** * Don't change the current Temperature @@ -474,20 +489,22 @@ public void chooseTemperatureVariable(PeriodicActionTriggeredEvent event, Entity switch (event.getActionId()) { case TEMPERATURE_INCREASE: weatherEntity.send(new TemperatureIncreaseEvent()); + this.triggerEvents(); break; case TEMPERATURE_DECREASE: weatherEntity.send(new TemperatureDecreaseEvent()); + this.triggerEvents(); break; case TEMPERATURE_STAGNATE: weatherEntity.send(new TemperatureStagnateEvent()); + this.triggerEvents(); break; } } /** - * This class will create a periodicAction which will either increase, decrease the temperature or make it stagnate - * This class will create a periodicAction which will either increase, decrease the temperature or - * make it stagnate + * This class will create a periodicAction which will either increase, decrease the temperature or make it stagnate This class will + * create a periodicAction which will either increase, decrease the temperature or make it stagnate * * @param event * @param weatherEntity @@ -508,67 +525,13 @@ public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weath this.countTempAug++; String[] tempChoices = {TEMPERATURE_STAGNATE, TEMPERATURE_INCREASE, TEMPERATURE_DECREASE}; int indexChoice = (int) (Math.random() * 3); - delayManager.addPeriodicAction(weatherEntity, tempChoices[indexChoice], 0, 100); + delayManager.addPeriodicAction(weatherEntity, tempChoices[indexChoice], 0, 1000); //We add another delayed action to do this action again, over and over delayManager.addDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE, 100000); } - - - } - - /** - * Having the snow melt when the temperature reaches 0 degree - */ - public void startMelting(EntityRef weatherEntity) { - if (this.currentTemperature >= 0.0) { - delayManager.cancelPeriodicAction(weatherEntity, MELT_SNOW); - delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 100, 100); - } - for (Client currentPlayer : networkSystem.getPlayers()) { - Vector3i playerPos = new Vector3i(); - LocationComponent locComp = currentPlayer.getEntity().getComponent(LocationComponent.class); - playerPos.set(locComp.getWorldPosition(position), RoundingMode.FLOOR); - meltSnow(playerPos); - } - } - - private Vector3i findSpot(Block toCheck, int x, int z, int initialY) { - int currentY = initialY + SNOW_BLOCK_RANGE; - int iter = 0; - while (iter < SNOW_BLOCK_RANGE * 2 && worldProvider.getBlock(x, currentY, z).equals(air)) { - iter++; - currentY--; - } - while (iter < SNOW_BLOCK_RANGE * 2 && !worldProvider.getBlock(x, currentY, z).equals(air)) { - iter++; - currentY++; - } - if (iter >= SNOW_BLOCK_RANGE * 2) { - return null; - } - - if (worldProvider.getSunlight(x, currentY, z) != Chunks.MAX_SUNLIGHT) { - // The block isn't actually exposed to the weather. - return null; - } - Block ground = worldProvider.getBlock(x, currentY - 1, z); - if (ground.equals(toCheck)) { - return new Vector3i(x, currentY - 1, z); - } else if (toCheck.equals(air) && !ground.isPenetrable() && ground.isAttachmentAllowed()) { - return new Vector3i(x, currentY, z); - } else { - return null; - } - } - private void meltSnow(Vector3ic playerPos) { - int x = getValueToPlaceBlock(playerPos.x()); - int z = getValueToPlaceBlock(playerPos.z()); - Vector3i spotToPlace = findSpot(snow, x, z, playerPos.y()); - if (spotToPlace != null) { - worldProvider.setBlock(spotToPlace, water); - } } } + From bd26bbb750e987a173d695f9b7e0e2a3a220c41d Mon Sep 17 00:00:00 2001 From: Ewwweee Date: Sun, 17 Dec 2023 13:34:14 +0100 Subject: [PATCH 24/37] final add temp and change block according to the temp --- .../systems/WeatherManagerSystem.java | 120 +++++++++--------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index af528d2..4c9079d 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -145,7 +145,6 @@ public String makeSunny(@CommandParam(value = "time") int time) { WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); ConditionAndDuration conditionAndDuration = new ConditionAndDuration(weatherCondition, time); changeWeather(conditionAndDuration); - delayManager.addDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE, 100); return "It is now sunny."; } @@ -196,7 +195,7 @@ private void changeWeather(ConditionAndDuration conditionAndDuration) { @ReceiveEvent public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity) { - //Each time a delayedActionTriggeredEvent is trigger, we change the way the temperature change + //Each time a delayedActionTriggeredEvent is trigger, we change the way the weather if (event.getActionId().equals("RandomWeather")) { current = weatherConditionProvider.getNext(); currentWeather = current.condition.downfallCondition.getDownfallValues().type; @@ -207,6 +206,62 @@ public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity } } + public void curWeather() { + Random rand = new Random(); + float windX = randomWindSpeed(); + float windY = randomWindSpeed(); + boolean withThunder = rand.nextInt(2) == 0 ? false : true; + this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; + for (Vector3fc position : this.getPlayersPosition()) { + float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / 100 ; + if (currentHumidityDegree > 0.7) { + if (this.currentTemperature > 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + + } else { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + } + } + if (currentHumidityDegree <= 0.7 && currentHumidityDegree > 0.5) { + this.severity = Severity.LIGHT ; + if (this.currentTemperature > 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, false); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, false); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + } else { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + } + } + if (currentHumidityDegree <= 0.5) { + this.severity = Severity.NONE ; + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.NONE, false); + WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + } + } + } + /** * Adds/removes periodic actions and sends events based on the type of weather it currently is. */ @@ -238,13 +293,13 @@ private void triggerEvents() { delayManager.addPeriodicAction(weatherEntity, PLACE_WATER, 1000, 1000); } if (this.currentTemperature > 0) { - delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 100, 100); + delayManager.addPeriodicAction(weatherEntity, MELT_SNOW, 100, 400); } if (this.currentTemperature > 20) { - delayManager.addPeriodicAction(weatherEntity, EVAPORATE_WATER, 100, 100); + delayManager.addPeriodicAction(weatherEntity, EVAPORATE_WATER, 100, 400); } if (this.currentTemperature < 0) { - delayManager.addPeriodicAction(weatherEntity, FREEZE_WATER, 10, 100); + delayManager.addPeriodicAction(weatherEntity, FREEZE_WATER, 100, 400); } } @@ -342,61 +397,6 @@ public List getPlayersPosition() { return listPlayerPos; } - public void curWeather() { - Random rand = new Random(); - float windX = randomWindSpeed(); - float windY = randomWindSpeed(); - boolean withThunder = rand.nextInt(2) == 0 ? false : true; - this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; - for (Vector3fc position : this.getPlayersPosition()) { - float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / 100 ; - if (currentHumidityDegree > 0.7) { - if (this.currentTemperature > 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - - } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } - } - if (currentHumidityDegree <= 0.7 && currentHumidityDegree > 0.5) { - this.severity = Severity.LIGHT ; - if (this.currentTemperature > 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } - } - if (currentHumidityDegree <= 0.5) { - this.severity = Severity.NONE ; - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.NONE, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } - } - } @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") public String printMessage(@CommandParam(value = "text") String text) { From c7fb87eac491ffe2ca8b9b7d7dd029f5f96e5189 Mon Sep 17 00:00:00 2001 From: Ihebsmai <146442711+Ihebsmai@users.noreply.github.com> Date: Sun, 17 Dec 2023 13:48:43 +0100 Subject: [PATCH 25/37] Update increaseHumidity --- .../weatherManager/systems/WeatherManagerSystem.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 2e3fe07..b5aa10b 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -539,8 +539,8 @@ public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weath } public void increaseHumidity() { float humidity = this.currentHumidity; - float humidityMin = climateConditionsSystem.getHumidityMinimum(); - float humidityMax = climateConditionsSystem.getHumidityMaximum(); + float humidityMin = 0f; + float humidityMax = 100f; float randNbr = (float) (Math.random() * 0.01); float value = (humidity - humidityMin + randNbr) / (humidityMax - humidityMin); Function function = (Float number) -> { From 14b03445959fcb25ba2bd95facac445169995434 Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sun, 17 Dec 2023 14:45:05 +0100 Subject: [PATCH 26/37] some correction on curWeather and a new command chWeather that changes the weather depending on the temperature and the humidity --- .../systems/WeatherManagerSystem.java | 113 ++++++++++-------- 1 file changed, 64 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 2e3fe07..e0a386b 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -202,10 +202,9 @@ private void changeWeather(ConditionAndDuration conditionAndDuration) { public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity) { //Each time a delayedActionTriggeredEvent is trigger, we change the way the temperature change if (event.getActionId().equals("RandomWeather")) { - current = weatherConditionProvider.getNext(); - currentWeather = current.condition.downfallCondition.getDownfallValues().type; - severity = current.condition.downfallCondition.getDownfallValues().amount; - currentWind.set(current.condition.wind); + for(Vector3fc position : this.getPlayersPosition()){ + curWeather(position); + } triggerEvents(); logger.debug("WEATHER CHANGED: " + current.condition + "(" + current.duration + ")"); } @@ -347,60 +346,66 @@ public List getPlayersPosition() { return listPlayerPos; } - public void curWeather() { + public void curWeather(Vector3fc position) { Random rand = new Random(); float windX = randomWindSpeed(); float windY = randomWindSpeed(); boolean withThunder = rand.nextInt(2) == 0 ? false : true; this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; - for (Vector3fc position : this.getPlayersPosition()) { - float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / 100 ; - if (currentHumidityDegree > 0.7) { - if (this.currentTemperature > 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - - } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } - } - if (currentHumidityDegree <= 0.7 && currentHumidityDegree > 0.5) { - this.severity = Severity.LIGHT ; - if (this.currentTemperature > 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } + float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / 100 ; + if (currentHumidityDegree > 0.7) { + if (this.currentTemperature > 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.currentWeather = DownfallCondition.DownfallType.RAIN ; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.currentWeather = DownfallCondition.DownfallType.SNOW ; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + + } else { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.currentWeather = DownfallCondition.DownfallType.HAIL ; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); } - if (currentHumidityDegree <= 0.5) { - this.severity = Severity.NONE ; - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.NONE, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); + } + if (currentHumidityDegree <= 0.7 && currentHumidityDegree > 0.5) { + this.severity = Severity.LIGHT ; + if (this.currentTemperature > 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, false); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.currentWeather = DownfallCondition.DownfallType.RAIN ; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, false); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.currentWeather = DownfallCondition.DownfallType.SNOW ; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + } else { + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.currentWeather = DownfallCondition.DownfallType.HAIL ; float time = this.current.duration ; this.current = new ConditionAndDuration(weatherCondition,time); } } + if (currentHumidityDegree <= 0.5) { + this.severity = Severity.NONE ; + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.NONE, false); + WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); + this.currentWeather = DownfallCondition.DownfallType.NONE ; + float time = this.current.duration ; + this.current = new ConditionAndDuration(weatherCondition,time); + } + } @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") @@ -537,7 +542,7 @@ public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weath } - public void increaseHumidity() { + /**public void increaseHumidity() { float humidity = this.currentHumidity; float humidityMin = climateConditionsSystem.getHumidityMinimum(); float humidityMax = climateConditionsSystem.getHumidityMaximum(); @@ -550,6 +555,16 @@ public void increaseHumidity() { this.climateConditionsSystem.configureHumidity(200, 200, 0, function, humidityMin, humidityMax); } + */ + @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") + public String chWeather(){ + for(Vector3fc position : this.getPlayersPosition()){ + curWeather(position); + } + triggerEvents(); + return "WEATHER CHANGED: " + current.condition + "(" + current.duration + ")" ; + } + } From 40cc2e245b8f70ccf63b4cae0888efd154cab78e Mon Sep 17 00:00:00 2001 From: Ihebsmai <146442711+Ihebsmai@users.noreply.github.com> Date: Sun, 17 Dec 2023 15:14:25 +0100 Subject: [PATCH 27/37] Update IncreasedHumidity.2 --- .../systems/WeatherManagerSystem.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 4a88aa3..7ed777d 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -263,6 +263,9 @@ private void triggerEvents() { if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { weatherEntity.send(new StartRainEvent()); + for(Vector3fc position : this.getPlayersPosition()){ + increaseHumidity(position); + } } if (currentWeather.equals(DownfallCondition.DownfallType.HAIL)) { @@ -542,20 +545,27 @@ public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weath } - /**public void increaseHumidity() { - float humidity = this.currentHumidity; - float humidityMin = 0f; - float humidityMax = 100f; - float randNbr = (float) (Math.random() * 0.01); - float value = (humidity - humidityMin + randNbr) / (humidityMax - humidityMin); - Function function = (Float number) -> { - return (float) (value); - }; + + public void increaseHumidity(Vector3fc position) { + currentHumidity = this.climateConditionsSystem.getHumidity(position) / 100 ; + float humidity = this.currentHumidity; + float humidityMin = 0f; + float humidityMax = 100f; + + // Add a small random value to the current humidity + float randNbr = (float) (Math.random() * 0.01); + humidity += randNbr; + + // Ensure the humidity stays within the valid range + humidity = Math.min(Math.max(humidity, humidityMin), humidityMax); + + // Configure the climate conditions system with the updated humidity value + Function function = (Float number) -> humidity; + + this.climateConditionsSystem.configureHumidity(200, 200, 0, function, humidityMin, humidityMax); +} - this.climateConditionsSystem.configureHumidity(200, 200, 0, function, - humidityMin, humidityMax); - } - */ + @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") public String chWeather(){ for(Vector3fc position : this.getPlayersPosition()){ From 347cba898d35de6fa136ca171e80b7a968defcd6 Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sun, 17 Dec 2023 15:17:29 +0100 Subject: [PATCH 28/37] it is working --- .../weatherManager/systems/WeatherManagerSystem.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 4a88aa3..b738cda 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -214,6 +214,9 @@ public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity * Adds/removes periodic actions and sends events based on the type of weather it currently is. */ private void triggerEvents() { + for(Vector3fc position : this.getPlayersPosition()){ + curWeather(position); + } if(!delayManager.hasDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE)) { delayManager.addDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE, 100000); } From b7d5c35c6cbc766862253396749edf3af8fcf576 Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sun, 17 Dec 2023 16:29:07 +0100 Subject: [PATCH 29/37] minor correction --- .../terasology/weatherManager/systems/WeatherManagerSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index f26804a..5aff114 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -569,7 +569,7 @@ public void increaseHumidity(Vector3fc position) { } - @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") + @Command(shortDescription = "changes the weather", helpText = "changes the weather depending on the temperature and the humidity") public String chWeather(){ for(Vector3fc position : this.getPlayersPosition()){ curWeather(position); From a1d412d3122808ec6e5aefd37da1ab22a2414b48 Mon Sep 17 00:00:00 2001 From: Ihebsmai <146442711+Ihebsmai@users.noreply.github.com> Date: Sun, 17 Dec 2023 18:03:13 +0100 Subject: [PATCH 30/37] Update HumidityEvent --- .../systems/WeatherManagerSystem.java | 63 ++++++++++++++++--- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 5aff114..b30818c 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -266,8 +266,10 @@ private void triggerEvents() { if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { weatherEntity.send(new StartRainEvent()); + for(Vector3fc position : this.getPlayersPosition()){ increaseHumidity(position); + } } @@ -548,8 +550,20 @@ public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weath } - - public void increaseHumidity(Vector3fc position) { + + + + @Command(shortDescription = "changes the weather", helpText = "changes the weather depending on the temperature and the humidity") + public String chWeather(){ + for(Vector3fc position : this.getPlayersPosition()){ + curWeather(position); + } + triggerEvents(); + return "WEATHER CHANGED: " + current.condition + "(" + current.duration + ")" ; + } + + +public void increaseHumidity(Vector3fc position /* HumidityIncreaseEvent event, EntityRef worldEntity */) { currentHumidity = this.climateConditionsSystem.getHumidity(position) / 100 ; float humidity = this.currentHumidity; float humidityMin = 0f; @@ -567,16 +581,47 @@ public void increaseHumidity(Vector3fc position) { this.climateConditionsSystem.configureHumidity(200, 200, 0, function, humidityMin, humidityMax); } +/* Dealing with Humidity periodically + @ReceiveEvent + public void chooseHumidity(DelayedActionTriggeredEvent event, EntityRef weatherEntity) { + if (event.getActionId().equals(DELAYED_HUMIDITY_CHOICE)) { + // We cancel all periodic action + if (delayManager.hasPeriodicAction(weatherEntity, HUMIDITY_INCREASE)) { + delayManager.cancelPeriodicAction(weatherEntity, HUMIDITY_INCREASE); + } - - @Command(shortDescription = "changes the weather", helpText = "changes the weather depending on the temperature and the humidity") - public String chWeather(){ - for(Vector3fc position : this.getPlayersPosition()){ - curWeather(position); + this.countHumAug++; + // Add a new periodic action to increase humidity + delayManager.addPeriodicAction(weatherEntity, HUMIDITY_INCREASE, 0, 1000); + + // Add another delayed action to trigger the humidity choice periodically + delayManager.addDelayedAction(weatherEntity, DELAYED_HUMIDITY_CHOICE, 100000); } - triggerEvents(); - return "WEATHER CHANGED: " + current.condition + "(" + current.duration + ")" ; + + } + +@ReceiveEvent + public void chooseHumidityVariable(PeriodicActionTriggeredEvent event, EntityRef weatherEntity) { + switch (event.getActionId()) { + case HUMIDITY_INCREASE: + weatherEntity.send(new HumidityIncreaseEvent()); + this.triggerEvents(); + break; + // Add other humidity-related cases if needed in the future + } + } + +public void changeHumidityPlayers() { + List playerPos = this.getPlayersPosition(); + float currentHumid = 0; + + for (Vector3fc players : playerPos) { + currentHumid += this.climateConditionsSystem.getHumidity(players.x(), players.y(), players.z()); + + } + this.currentHumidity = currentHumid / playerPos.size(); } +*/ } From 425e318ba858e2ecd8430743e27cbbef2e29636e Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sun, 17 Dec 2023 18:28:51 +0100 Subject: [PATCH 31/37] final correction --- .../weatherManager/systems/WeatherManagerSystem.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 5aff114..5b30722 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -202,9 +202,6 @@ private void changeWeather(ConditionAndDuration conditionAndDuration) { public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity) { //Each time a delayedActionTriggeredEvent is trigger, we change the way the temperature change if (event.getActionId().equals("RandomWeather")) { - for(Vector3fc position : this.getPlayersPosition()){ - curWeather(position); - } triggerEvents(); logger.debug("WEATHER CHANGED: " + current.condition + "(" + current.duration + ")"); } From c0bc2d705505530d9be814db2b3e0603de30d7a6 Mon Sep 17 00:00:00 2001 From: Ewwweee Date: Sun, 17 Dec 2023 19:29:13 +0100 Subject: [PATCH 32/37] me --- .../events/HumidityIncreaseEvent.java | 12 +++++ .../systems/WeatherManagerSystem.java | 54 +++++++++---------- 2 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 src/main/java/org/terasology/weatherManager/events/HumidityIncreaseEvent.java diff --git a/src/main/java/org/terasology/weatherManager/events/HumidityIncreaseEvent.java b/src/main/java/org/terasology/weatherManager/events/HumidityIncreaseEvent.java new file mode 100644 index 0000000..9f739cf --- /dev/null +++ b/src/main/java/org/terasology/weatherManager/events/HumidityIncreaseEvent.java @@ -0,0 +1,12 @@ +// Copyright 2021 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 + +package org.terasology.weatherManager.events; + +import org.terasology.gestalt.entitysystem.event.Event; + +/** + * Event which is called when the weather changes to hail (frozen raindrop fall) + */ +public class HumidityIncreaseEvent implements Event { +} diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 5fb55e3..c0623b0 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -37,6 +37,7 @@ import org.terasology.weatherManager.events.StartSnowEvent; import org.terasology.weatherManager.events.StartSunEvent; import org.terasology.weatherManager.events.TemperatureIncreaseEvent; +import org.terasology.weatherManager.events.HumidityIncreaseEvent; import org.terasology.weatherManager.events.TemperatureDecreaseEvent; import org.terasology.weatherManager.events.TemperatureStagnateEvent; import org.terasology.weatherManager.weather.ConditionAndDuration; @@ -69,7 +70,7 @@ public class WeatherManagerSystem extends BaseComponentSystem { public static final String TEMPERATURE_DECREASE = "temperatureDecrease"; public static final String TEMPERATURE_STAGNATE = "temperatureStagnate"; public static final String DELAYED_TEMPERATURE_CHOICE = "delayTemp"; - + public static final String DELAYED_HUMIDITY_CHOICE = "delayHum"; public static final String HUMIDITY_INCREASE = "HumidityIncrease"; public static final float TMAX = 50f; @@ -212,6 +213,9 @@ public void curWeather() { float windY = randomWindSpeed(); boolean withThunder = rand.nextInt(2) == 0 ? false : true; this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; + if(this.severity ==Severity.NONE){ + withThunder =false; + } for (Vector3fc position : this.getPlayersPosition()) { float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / 100 ; if (currentHumidityDegree > 0.7) { @@ -302,12 +306,7 @@ private void triggerEvents() { delayManager.addPeriodicAction(weatherEntity, EVAPORATE_WATER, 100, 400); } if (this.currentTemperature < 0) { -<<<<<<< HEAD delayManager.addPeriodicAction(weatherEntity, FREEZE_WATER, 100, 400); -======= - delayManager.addPeriodicAction(weatherEntity, FREEZE_WATER, 10, 100); - ->>>>>>> 94540f62a1f4d6cc7b263e55ec422f78a2b3a207 } } @@ -322,11 +321,7 @@ private void triggerEvents() { if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { weatherEntity.send(new StartRainEvent()); - - for(Vector3fc position : this.getPlayersPosition()){ - increaseHumidity(position); - - } + } if (currentWeather.equals(DownfallCondition.DownfallType.HAIL)) { @@ -410,15 +405,13 @@ public List getPlayersPosition() { return listPlayerPos; } -<<<<<<< HEAD -======= public void curWeather(Vector3fc position) { Random rand = new Random(); float windX = randomWindSpeed(); float windY = randomWindSpeed(); boolean withThunder = rand.nextInt(2) == 0 ? false : true; this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; - float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / 100 ; + float currentHumidityDegree = this.currentHumidity / 100 ; if (currentHumidityDegree > 0.7) { if (this.currentTemperature > 0) { DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); @@ -465,6 +458,9 @@ public void curWeather(Vector3fc position) { } if (currentHumidityDegree <= 0.5) { this.severity = Severity.NONE ; + if(withThunder == true){ + withThunder = false; + } DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.NONE, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); this.currentWeather = DownfallCondition.DownfallType.NONE ; @@ -473,7 +469,6 @@ public void curWeather(Vector3fc position) { } } ->>>>>>> 94540f62a1f4d6cc7b263e55ec422f78a2b3a207 @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") public String printMessage(@CommandParam(value = "text") String text) { @@ -482,9 +477,9 @@ public String printMessage(@CommandParam(value = "text") String text) { } @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") - public String setTemperature(@CommandParam(value = "text") int temp) { - this.currentTemperature = temp; - return "this.currentTemperature = " + this.currentTemperature + "\n" + "Nombre de fois triggerEvent called : " + this.countTempAug + public String setHumidity(@CommandParam(value = "text") int temp) { + this.currentHumidity = (float)temp; + return "this.currentHumidity = " + this.currentHumidity + "\n" + "Nombre de fois triggerEvent called : " + this.countTempAug + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity, "Weather"); } @@ -622,8 +617,7 @@ public String chWeather(){ } -public void increaseHumidity(Vector3fc position /* HumidityIncreaseEvent event, EntityRef worldEntity */) { - currentHumidity = this.climateConditionsSystem.getHumidity(position) / 100 ; +public void increaseHumidity(HumidityIncreaseEvent event, EntityRef worldEntity ) { float humidity = this.currentHumidity; float humidityMin = 0f; float humidityMax = 100f; @@ -634,14 +628,16 @@ public void increaseHumidity(Vector3fc position /* HumidityIncreaseEvent event, // Ensure the humidity stays within the valid range humidity = Math.min(Math.max(humidity, humidityMin), humidityMax); - + float value = humidity; // Configure the climate conditions system with the updated humidity value - Function function = (Float number) -> humidity; - + Function function = (Float number) -> { + return (float) (value); + }; this.climateConditionsSystem.configureHumidity(200, 200, 0, function, humidityMin, humidityMax); + this.changeHumidityPlayers(); } -/* Dealing with Humidity periodically - @ReceiveEvent + + @ReceiveEvent public void chooseHumidity(DelayedActionTriggeredEvent event, EntityRef weatherEntity) { if (event.getActionId().equals(DELAYED_HUMIDITY_CHOICE)) { // We cancel all periodic action @@ -649,7 +645,6 @@ public void chooseHumidity(DelayedActionTriggeredEvent event, EntityRef weatherE delayManager.cancelPeriodicAction(weatherEntity, HUMIDITY_INCREASE); } - this.countHumAug++; // Add a new periodic action to increase humidity delayManager.addPeriodicAction(weatherEntity, HUMIDITY_INCREASE, 0, 1000); @@ -659,18 +654,17 @@ public void chooseHumidity(DelayedActionTriggeredEvent event, EntityRef weatherE } -@ReceiveEvent + @ReceiveEvent public void chooseHumidityVariable(PeriodicActionTriggeredEvent event, EntityRef weatherEntity) { switch (event.getActionId()) { case HUMIDITY_INCREASE: weatherEntity.send(new HumidityIncreaseEvent()); - this.triggerEvents(); break; // Add other humidity-related cases if needed in the future } } -public void changeHumidityPlayers() { + public void changeHumidityPlayers() { List playerPos = this.getPlayersPosition(); float currentHumid = 0; @@ -680,7 +674,7 @@ public void changeHumidityPlayers() { } this.currentHumidity = currentHumid / playerPos.size(); } -*/ + } From 307ee222ca1f60a99f2787329cce4cb59df7be99 Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sun, 17 Dec 2023 19:55:40 +0100 Subject: [PATCH 33/37] final correction --- .../systems/WeatherManagerSystem.java | 67 ++----------------- 1 file changed, 4 insertions(+), 63 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index c0623b0..c1215eb 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -207,72 +207,13 @@ public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity } } - public void curWeather() { - Random rand = new Random(); - float windX = randomWindSpeed(); - float windY = randomWindSpeed(); - boolean withThunder = rand.nextInt(2) == 0 ? false : true; - this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; - if(this.severity ==Severity.NONE){ - withThunder =false; - } - for (Vector3fc position : this.getPlayersPosition()) { - float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / 100 ; - if (currentHumidityDegree > 0.7) { - if (this.currentTemperature > 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - - } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } - } - if (currentHumidityDegree <= 0.7 && currentHumidityDegree > 0.5) { - this.severity = Severity.LIGHT ; - if (this.currentTemperature > 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } - } - if (currentHumidityDegree <= 0.5) { - this.severity = Severity.NONE ; - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.NONE, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } - } - } + /** * Adds/removes periodic actions and sends events based on the type of weather it currently is. */ private void triggerEvents() { - for(Vector3fc position : this.getPlayersPosition()){ - curWeather(position); - } + curWeather(); if(!delayManager.hasDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE)) { delayManager.addDelayedAction(weatherEntity, DELAYED_TEMPERATURE_CHOICE, 100000); } @@ -405,7 +346,7 @@ public List getPlayersPosition() { return listPlayerPos; } - public void curWeather(Vector3fc position) { + public void curWeather() { Random rand = new Random(); float windX = randomWindSpeed(); float windY = randomWindSpeed(); @@ -610,7 +551,7 @@ public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weath @Command(shortDescription = "changes the weather", helpText = "changes the weather depending on the temperature and the humidity") public String chWeather(){ for(Vector3fc position : this.getPlayersPosition()){ - curWeather(position); + curWeather(); } triggerEvents(); return "WEATHER CHANGED: " + current.condition + "(" + current.duration + ")" ; From d95e996fe6e15529d3c301a8bba45f333ebb694a Mon Sep 17 00:00:00 2001 From: Mouhamed Sow Date: Sun, 17 Dec 2023 20:33:45 +0100 Subject: [PATCH 34/37] last --- .../systems/WeatherManagerSystem.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index c1215eb..53cd0c8 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -350,25 +350,24 @@ public void curWeather() { Random rand = new Random(); float windX = randomWindSpeed(); float windY = randomWindSpeed(); - boolean withThunder = rand.nextInt(2) == 0 ? false : true; - this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; float currentHumidityDegree = this.currentHumidity / 100 ; if (currentHumidityDegree > 0.7) { + this.severity =Severity.HEAVY; if (this.currentTemperature > 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, false); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); this.currentWeather = DownfallCondition.DownfallType.RAIN ; float time = this.current.duration ; this.current = new ConditionAndDuration(weatherCondition,time); } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, withThunder); + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, false); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); this.currentWeather = DownfallCondition.DownfallType.SNOW ; float time = this.current.duration ; this.current = new ConditionAndDuration(weatherCondition,time); } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); this.currentWeather = DownfallCondition.DownfallType.HAIL ; float time = this.current.duration ; @@ -399,9 +398,6 @@ public void curWeather() { } if (currentHumidityDegree <= 0.5) { this.severity = Severity.NONE ; - if(withThunder == true){ - withThunder = false; - } DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.NONE, false); WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); this.currentWeather = DownfallCondition.DownfallType.NONE ; @@ -423,6 +419,12 @@ public String setHumidity(@CommandParam(value = "text") int temp) { return "this.currentHumidity = " + this.currentHumidity + "\n" + "Nombre de fois triggerEvent called : " + this.countTempAug + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity, "Weather"); } + @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") + public String setTemperature(@CommandParam(value = "text") int temp) { + this.currentTemperature = (float) temp; + return "this.currentTemperature = " + this.currentTemperature + "\n" + "Nombre de fois triggerEvent called : " + this.countTempAug + + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity, "Weather"); + } /** @@ -550,9 +552,6 @@ public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weath @Command(shortDescription = "changes the weather", helpText = "changes the weather depending on the temperature and the humidity") public String chWeather(){ - for(Vector3fc position : this.getPlayersPosition()){ - curWeather(); - } triggerEvents(); return "WEATHER CHANGED: " + current.condition + "(" + current.duration + ")" ; } From 1c9b8f0bc8cd5d0401cb624ef73bb3aadd740908 Mon Sep 17 00:00:00 2001 From: Ewwweee Date: Sun, 17 Dec 2023 22:32:47 +0100 Subject: [PATCH 35/37] Final --- .../events/HumidityDecreaseEvent.java | 12 + .../systems/WeatherManagerSystem.java | 221 +++++++----------- 2 files changed, 101 insertions(+), 132 deletions(-) create mode 100644 src/main/java/org/terasology/weatherManager/events/HumidityDecreaseEvent.java diff --git a/src/main/java/org/terasology/weatherManager/events/HumidityDecreaseEvent.java b/src/main/java/org/terasology/weatherManager/events/HumidityDecreaseEvent.java new file mode 100644 index 0000000..234ec3c --- /dev/null +++ b/src/main/java/org/terasology/weatherManager/events/HumidityDecreaseEvent.java @@ -0,0 +1,12 @@ +// Copyright 2021 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 + +package org.terasology.weatherManager.events; + +import org.terasology.gestalt.entitysystem.event.Event; + +/** + * Event which is called when the weather changes to hail (frozen raindrop fall) + */ +public class HumidityDecreaseEvent implements Event { +} diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index c0623b0..b8a2d84 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -38,6 +38,7 @@ import org.terasology.weatherManager.events.StartSunEvent; import org.terasology.weatherManager.events.TemperatureIncreaseEvent; import org.terasology.weatherManager.events.HumidityIncreaseEvent; +import org.terasology.weatherManager.events.HumidityDecreaseEvent; import org.terasology.weatherManager.events.TemperatureDecreaseEvent; import org.terasology.weatherManager.events.TemperatureStagnateEvent; import org.terasology.weatherManager.weather.ConditionAndDuration; @@ -70,8 +71,6 @@ public class WeatherManagerSystem extends BaseComponentSystem { public static final String TEMPERATURE_DECREASE = "temperatureDecrease"; public static final String TEMPERATURE_STAGNATE = "temperatureStagnate"; public static final String DELAYED_TEMPERATURE_CHOICE = "delayTemp"; - public static final String DELAYED_HUMIDITY_CHOICE = "delayHum"; - public static final String HUMIDITY_INCREASE = "HumidityIncrease"; public static final float TMAX = 50f; public static final float TMIN = -10f; @@ -107,6 +106,7 @@ public class WeatherManagerSystem extends BaseComponentSystem { private Context context; private double countTempAug = 0; private NetworkSystem networkSystem; + private boolean changeWeatherTrue = false; @Command(shortDescription = "Make it rain", helpText = "Changes the weather to raining for some time") @@ -207,65 +207,6 @@ public void onTimeEvent(DelayedActionTriggeredEvent event, EntityRef worldEntity } } - public void curWeather() { - Random rand = new Random(); - float windX = randomWindSpeed(); - float windY = randomWindSpeed(); - boolean withThunder = rand.nextInt(2) == 0 ? false : true; - this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; - if(this.severity ==Severity.NONE){ - withThunder =false; - } - for (Vector3fc position : this.getPlayersPosition()) { - float currentHumidityDegree = this.climateConditionsSystem.getHumidity(position) / 100 ; - if (currentHumidityDegree > 0.7) { - if (this.currentTemperature > 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - - } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } - } - if (currentHumidityDegree <= 0.7 && currentHumidityDegree > 0.5) { - this.severity = Severity.LIGHT ; - if (this.currentTemperature > 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } - } - if (currentHumidityDegree <= 0.5) { - this.severity = Severity.NONE ; - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.NONE, false); - WeatherCondition weatherCondition = new WeatherCondition(Severity.NONE, condition, new Vector2f(0, 0)); - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); - } - } - } - /** * Adds/removes periodic actions and sends events based on the type of weather it currently is. */ @@ -311,20 +252,24 @@ private void triggerEvents() { } - if (currentWeather.equals(DownfallCondition.DownfallType.SNOW)) { + if (currentWeather.equals(DownfallCondition.DownfallType.SNOW) && this.changeWeatherTrue == true) { + this.changeWeatherTrue = false; weatherEntity.send(new StartSnowEvent()); } - if (currentWeather.equals(DownfallCondition.DownfallType.NONE)) { + if (currentWeather.equals(DownfallCondition.DownfallType.NONE)&& this.changeWeatherTrue == true) { + this.changeWeatherTrue = false; weatherEntity.send(new StartSunEvent()); } - if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { + if (currentWeather.equals(DownfallCondition.DownfallType.RAIN)&& this.changeWeatherTrue == true) { + this.changeWeatherTrue = false; weatherEntity.send(new StartRainEvent()); } - if (currentWeather.equals(DownfallCondition.DownfallType.HAIL)) { + if (currentWeather.equals(DownfallCondition.DownfallType.HAIL)&& this.changeWeatherTrue == true) { + this.changeWeatherTrue = false; weatherEntity.send(new StartHailEvent()); } } @@ -413,13 +358,16 @@ public void curWeather(Vector3fc position) { this.severity = withThunder == false ? Severity.MODERATE : Severity.HEAVY; float currentHumidityDegree = this.currentHumidity / 100 ; if (currentHumidityDegree > 0.7) { - if (this.currentTemperature > 0) { + if (this.currentTemperature > 0 && !currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { + //we changed the weather + this.changeWeatherTrue = true; DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, withThunder); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); this.currentWeather = DownfallCondition.DownfallType.RAIN ; float time = this.current.duration ; this.current = new ConditionAndDuration(weatherCondition,time); - } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { + } else if (this.currentTemperature > -5 && this.currentTemperature <= 0 && !currentWeather.equals(DownfallCondition.DownfallType.SNOW)) { + this.changeWeatherTrue = true; DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, withThunder); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); this.currentWeather = DownfallCondition.DownfallType.SNOW ; @@ -427,36 +375,45 @@ public void curWeather(Vector3fc position) { this.current = new ConditionAndDuration(weatherCondition,time); } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - this.currentWeather = DownfallCondition.DownfallType.HAIL ; - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); + if(!currentWeather.equals(DownfallCondition.DownfallType.HAIL) && this.currentTemperature < -5) { + this.changeWeatherTrue = true; + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, withThunder); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.currentWeather = DownfallCondition.DownfallType.HAIL; + float time = this.current.duration; + this.current = new ConditionAndDuration(weatherCondition, time); + } } } if (currentHumidityDegree <= 0.7 && currentHumidityDegree > 0.5) { this.severity = Severity.LIGHT ; - if (this.currentTemperature > 0) { + if (this.currentTemperature > 0 &&!currentWeather.equals(DownfallCondition.DownfallType.RAIN)) { + this.changeWeatherTrue = true; DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.RAIN, false); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); this.currentWeather = DownfallCondition.DownfallType.RAIN ; float time = this.current.duration ; this.current = new ConditionAndDuration(weatherCondition,time); - } else if (this.currentTemperature > -10 && this.currentTemperature <= 0) { + } else if (this.currentTemperature > -5 && this.currentTemperature <= 0 && !currentWeather.equals(DownfallCondition.DownfallType.SNOW)) { + this.changeWeatherTrue = true; DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.SNOW, false); WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); this.currentWeather = DownfallCondition.DownfallType.SNOW ; float time = this.current.duration ; this.current = new ConditionAndDuration(weatherCondition,time); } else { - DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); - WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); - this.currentWeather = DownfallCondition.DownfallType.HAIL ; - float time = this.current.duration ; - this.current = new ConditionAndDuration(weatherCondition,time); + if(!currentWeather.equals(DownfallCondition.DownfallType.HAIL) && this.currentTemperature < -5) { + this.changeWeatherTrue = true; + DownfallCondition condition = DownfallCondition.get(this.severity, DownfallCondition.DownfallType.HAIL, false); + WeatherCondition weatherCondition = new WeatherCondition(this.severity, condition, new Vector2f(windX, windY)); + this.currentWeather = DownfallCondition.DownfallType.HAIL; + float time = this.current.duration; + this.current = new ConditionAndDuration(weatherCondition, time); + } } } - if (currentHumidityDegree <= 0.5) { + if (currentHumidityDegree <= 0.5 && !currentWeather.equals(DownfallCondition.DownfallType.NONE)) { + this.changeWeatherTrue = true; this.severity = Severity.NONE ; if(withThunder == true){ withThunder = false; @@ -472,15 +429,19 @@ public void curWeather(Vector3fc position) { @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") public String printMessage(@CommandParam(value = "text") String text) { - return "this.currentTemperature = " + this.currentTemperature + "\n" + "Nombre de fois triggerEvent called : " + this.countTempAug - + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity, "Weather"); + return "this.currentTemperature = " + this.currentTemperature +"\n" + "this.currentHumidity = " + this.currentHumidity + +"\n" + "this.countAug = " + this.countTempAug; } @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") public String setHumidity(@CommandParam(value = "text") int temp) { - this.currentHumidity = (float)temp; - return "this.currentHumidity = " + this.currentHumidity + "\n" + "Nombre de fois triggerEvent called : " + this.countTempAug - + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity, "Weather"); + if (temp < 100) { + this.currentHumidity = (float) temp; + } + else { + this.currentHumidity = 100f; + } + return "this.currentHumidity = " + this.currentHumidity ; } @@ -534,7 +495,7 @@ public void reduceTemperature(TemperatureDecreaseEvent event, EntityRef worldEnt * @param worldEntity */ @ReceiveEvent - public void increaseTemperature(TemperatureIncreaseEvent event, EntityRef worldEntity) { + public void increaseTemperature(TemperatureIncreaseEvent event, EntityRef weatherEntity) { float temperature = this.currentTemperature; //T = (TMAX - TMIN)value + TMIN => value = (T - TMIN)/(TMAX -TMIN) float randNbr = (float) (Math.random() * 0.01); @@ -560,11 +521,14 @@ public void increaseTemperature(TemperatureIncreaseEvent event, EntityRef worldE public void chooseTemperatureVariable(PeriodicActionTriggeredEvent event, EntityRef weatherEntity) { switch (event.getActionId()) { case TEMPERATURE_INCREASE: + //When the temperature increase, the humidity decrease weatherEntity.send(new TemperatureIncreaseEvent()); + weatherEntity.send(new HumidityDecreaseEvent()); this.triggerEvents(); break; case TEMPERATURE_DECREASE: weatherEntity.send(new TemperatureDecreaseEvent()); + weatherEntity.send(new HumidityIncreaseEvent()); this.triggerEvents(); break; case TEMPERATURE_STAGNATE: @@ -594,7 +558,6 @@ public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weath if (delayManager.hasPeriodicAction(weatherEntity, TEMPERATURE_STAGNATE)) { delayManager.cancelPeriodicAction(weatherEntity, TEMPERATURE_STAGNATE); } - this.countTempAug++; String[] tempChoices = {TEMPERATURE_STAGNATE, TEMPERATURE_INCREASE, TEMPERATURE_DECREASE}; int indexChoice = (int) (Math.random() * 3); delayManager.addPeriodicAction(weatherEntity, tempChoices[indexChoice], 0, 1000); @@ -606,7 +569,7 @@ public void chooseTemperature(DelayedActionTriggeredEvent event, EntityRef weath } - + @Command(shortDescription = "changes the weather", helpText = "changes the weather depending on the temperature and the humidity") public String chWeather(){ for(Vector3fc position : this.getPlayersPosition()){ @@ -616,19 +579,51 @@ public String chWeather(){ return "WEATHER CHANGED: " + current.condition + "(" + current.duration + ")" ; } + @ReceiveEvent + public void decreaseHumidity(HumidityDecreaseEvent event, EntityRef weatherEnity ) { + + float humidity = this.currentHumidity; + float humidityMin = 0f; + float humidityMax = 100f; + + // Add a small random value to the current humidity + float randNbr = (float) (Math.random() * 0.1); + humidity = (humidity - humidityMin - randNbr)/(humidityMax - humidityMin); + + + float value = humidity; + // Configure the climate conditions system with the updated humidity value + Function function = (Float number) -> { + return (float) (value); + }; + this.climateConditionsSystem.configureHumidity(200, 200, 0, function, humidityMin, humidityMax); + this.changeHumidityPlayers(); + } -public void increaseHumidity(HumidityIncreaseEvent event, EntityRef worldEntity ) { + + public void changeHumidityPlayers() { + List playerPos = this.getPlayersPosition(); + float currentHumid = 0; + + for (Vector3fc players : playerPos) { + currentHumid += this.climateConditionsSystem.getHumidity(players.x(), players.y(), players.z()); + + } + this.currentHumidity = currentHumid / playerPos.size(); + } + +@ReceiveEvent +public void increaseHumidity(HumidityIncreaseEvent event, EntityRef weatherEntity ) { float humidity = this.currentHumidity; float humidityMin = 0f; float humidityMax = 100f; - + // Add a small random value to the current humidity - float randNbr = (float) (Math.random() * 0.01); - humidity += randNbr; + float randNbr = (float) (Math.random() * 0.1); + humidity = (humidity - humidityMin + randNbr)/(humidityMax - humidityMin); - // Ensure the humidity stays within the valid range - humidity = Math.min(Math.max(humidity, humidityMin), humidityMax); float value = humidity; + // Configure the climate conditions system with the updated humidity value Function function = (Float number) -> { return (float) (value); @@ -637,44 +632,6 @@ public void increaseHumidity(HumidityIncreaseEvent event, EntityRef worldEntity this.changeHumidityPlayers(); } - @ReceiveEvent - public void chooseHumidity(DelayedActionTriggeredEvent event, EntityRef weatherEntity) { - if (event.getActionId().equals(DELAYED_HUMIDITY_CHOICE)) { - // We cancel all periodic action - if (delayManager.hasPeriodicAction(weatherEntity, HUMIDITY_INCREASE)) { - delayManager.cancelPeriodicAction(weatherEntity, HUMIDITY_INCREASE); - } - - // Add a new periodic action to increase humidity - delayManager.addPeriodicAction(weatherEntity, HUMIDITY_INCREASE, 0, 1000); - - // Add another delayed action to trigger the humidity choice periodically - delayManager.addDelayedAction(weatherEntity, DELAYED_HUMIDITY_CHOICE, 100000); - } - - } - - @ReceiveEvent - public void chooseHumidityVariable(PeriodicActionTriggeredEvent event, EntityRef weatherEntity) { - switch (event.getActionId()) { - case HUMIDITY_INCREASE: - weatherEntity.send(new HumidityIncreaseEvent()); - break; - // Add other humidity-related cases if needed in the future - } - } - - public void changeHumidityPlayers() { - List playerPos = this.getPlayersPosition(); - float currentHumid = 0; - - for (Vector3fc players : playerPos) { - currentHumid += this.climateConditionsSystem.getHumidity(players.x(), players.y(), players.z()); - - } - this.currentHumidity = currentHumid / playerPos.size(); - } - } From 082b8b24ce21e48f1b842dc116195137ed4b08a1 Mon Sep 17 00:00:00 2001 From: Ewwweee Date: Sun, 17 Dec 2023 22:35:55 +0100 Subject: [PATCH 36/37] me --- .../weatherManager/systems/WeatherManagerSystem.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index b8a2d84..76739f1 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -104,7 +104,6 @@ public class WeatherManagerSystem extends BaseComponentSystem { @In private Context context; - private double countTempAug = 0; private NetworkSystem networkSystem; private boolean changeWeatherTrue = false; @@ -429,8 +428,7 @@ public void curWeather(Vector3fc position) { @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") public String printMessage(@CommandParam(value = "text") String text) { - return "this.currentTemperature = " + this.currentTemperature +"\n" + "this.currentHumidity = " + this.currentHumidity - +"\n" + "this.countAug = " + this.countTempAug; + return "this.currentTemperature = " + this.currentTemperature +"\n" + "this.currentHumidity = " + this.currentHumidity; } @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") From 2a5cff6b5a096b1f176990846e385673a548f963 Mon Sep 17 00:00:00 2001 From: Ewwweee Date: Sun, 17 Dec 2023 22:49:40 +0100 Subject: [PATCH 37/37] Final --- .../weatherManager/systems/WeatherManagerSystem.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java index 7b4bc46..86b8981 100644 --- a/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java +++ b/src/main/java/org/terasology/weatherManager/systems/WeatherManagerSystem.java @@ -352,6 +352,11 @@ public void curWeather() { Random rand = new Random(); float windX = randomWindSpeed(); float windY = randomWindSpeed(); + boolean[] tab = {true, false}; + boolean withThunder = tab[(int)(Math.random()*2)]; + if(this.severity == Severity.NONE) { + withThunder = false; + } float currentHumidityDegree = this.currentHumidity / 100 ; if (currentHumidityDegree > 0.7) { @@ -441,8 +446,7 @@ public String setHumidity(@CommandParam(value = "text") int temp) { @Command(shortDescription = "Print Message", helpText = "Equivalent to a println but in the chat") public String setTemperature(@CommandParam(value = "text") int temp) { this.currentTemperature = (float) temp; - return "this.currentTemperature = " + this.currentTemperature + "\n" + "Nombre de fois triggerEvent called : " + this.countTempAug - + "\n" + "HasDelayedAction ? " + delayManager.hasDelayedAction(weatherEntity, "Weather"); + return "this.currentTemperature = " + this.currentTemperature + "\n" +"this.currentHumidity" + this.currentHumidity; } @@ -585,7 +589,7 @@ public void decreaseHumidity(HumidityDecreaseEvent event, EntityRef weatherEnity float humidityMax = 100f; // Add a small random value to the current humidity - float randNbr = (float) (Math.random() * 0.1); + float randNbr = (float) (Math.random() * 0.5); humidity = (humidity - humidityMin - randNbr)/(humidityMax - humidityMin); @@ -617,7 +621,7 @@ public void increaseHumidity(HumidityIncreaseEvent event, EntityRef weatherEntit float humidityMax = 100f; // Add a small random value to the current humidity - float randNbr = (float) (Math.random() * 0.1); + float randNbr = (float) (Math.random() * 0.5); humidity = (humidity - humidityMin + randNbr)/(humidityMax - humidityMin); float value = humidity;