Package com.csse3200.game.areas.terrain
Class CropTileComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.areas.terrain.CropTileComponent
- All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable
Component which stores information about plots of land on which crops and
plants can grow.
Listens to a variety of trigger-able events to update state of the tile,
including its water
content and whether it is fertilised.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new crop tile with default valuesCropTileComponent
(float initialWaterContent, float soilQuality) Creates a new crop tile component, with a specified initial water content, and an initial soil quality (higher values indicate higher soil quality, meaning better growth rate). -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Adds player-triggered events listeners to the entity.double
Gets the growth rate of the tile, assuming a water content value of 1 yields the maximum growth rate.double
getGrowthRate
(float idealWaterAmount) Gets the growth rate of the tile, specifying the water content of the tile which yields the maximum growth rate.getPlant()
float
boolean
Returns whether the tile is fertilised.void
read
(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue jsonMap) void
Only to be used for loading as it can go around the achievement stuffvoid
Sets the tile to be unoccupied.void
update()
Decreases water content in the tile by a constant amount.void
write
(com.badlogic.gdx.utils.Json json) Writes in json summary of croptile state.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
Constructor Details
-
CropTileComponent
public CropTileComponent()Creates a new crop tile with default values -
CropTileComponent
public CropTileComponent(float initialWaterContent, float soilQuality) Creates a new crop tile component, with a specified initial water content, and an initial soil quality (higher values indicate higher soil quality, meaning better growth rate).- Parameters:
initialWaterContent
- The initial amount of water in the crop tile. Value should be between 0 and 2 inclusive - 0 indicates tile is completely dry, and 2 indicates tile is flooded, water content of 1 leads to ideal growth rate for most plantssoilQuality
- The initial soil quality of the crop tile. Higher soil quality increases the calculated growth rate. Should be greater than 0.
-
-
Method Details
-
create
public void create()Adds player-triggered events listeners to the entity. -
update
public void update()Decreases water content in the tile by a constant amount. -
isFertilised
public boolean isFertilised()Returns whether the tile is fertilised.- Returns:
- True if the tile is fertilised, false otherwise.
-
getGrowthRate
public double getGrowthRate()Gets the growth rate of the tile, assuming a water content value of 1 yields the maximum growth rate. The calculated growth rate is dependent on the water content and soil quality of this tile, and whether it is fertilised.- Returns:
- The calculated growth rate of the tile with an ideal water content value of 1, which is dependent on water content, soil quality, and whether the tile has been fertilised.
-
getGrowthRate
public double getGrowthRate(float idealWaterAmount) Gets the growth rate of the tile, specifying the water content of the tile which yields the maximum growth rate. The calculated growth rate is dependent on the water content and soil quality of this tile, and whether it is fertilised.- Parameters:
idealWaterAmount
- The amount which yields the maximum growth rate.- Returns:
- The calculated growth rate of the tile, dependent on water content, soil quality, and whether the tile has been fertilised.
-
getWaterContent
public float getWaterContent() -
setUnoccupied
public void setUnoccupied()Sets the tile to be unoccupied. -
getPlant
-
setPlant
Only to be used for loading as it can go around the achievement stuff- Parameters:
plant
- - the plant to set here
-
write
public void write(com.badlogic.gdx.utils.Json json) Writes in json summary of croptile state. Writes to json the waterContent, soilQuality, isFertilised and plant to the json -
read
public void read(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue jsonMap)
-