diff --git a/.idea/.idea.Petite Post/.idea/.gitignore b/.idea/.idea.Petite Post/.idea/.gitignore new file mode 100644 index 0000000..9c9e160 --- /dev/null +++ b/.idea/.idea.Petite Post/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/.idea.Petite Post.iml +/contentModel.xml +/projectSettingsUpdater.xml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.Petite Post/.idea/encodings.xml b/.idea/.idea.Petite Post/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.Petite Post/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.Petite Post/.idea/indexLayout.xml b/.idea/.idea.Petite Post/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.Petite Post/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Petite Post/.idea/vcs.xml b/.idea/.idea.Petite Post/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/.idea.Petite Post/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 9421266..74ddffb 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -202,7 +202,112 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1447796513 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1447796515} + - component: {fileID: 1447796514} + m_Layer: 0 + m_Name: House 01 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1447796514 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1447796513} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ef9f1f87684e67e6da7888d486a6bcea, type: 3} + m_Name: + m_EditorClassIdentifier: + mailCycleTime: 1 + mailChance: 0.5 + maxMail: 10 + mailAmountAdjustment: 0.10000000149011612 + mailAdjustment: 1 + address: 0 + manager: {fileID: 1967804166} + maxMailLifetime: 5 + currentMail: 0 + cycleTime: 0 + lastRandomMail: 0 + lastRandomCutoff: 0 + lastMailAmountAdjustment: 0 + lastMailAmountAdjustedBy: 0 +--- !u!4 &1447796515 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1447796513} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1967804165 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1967804167} + - component: {fileID: 1967804166} + m_Layer: 0 + m_Name: BuildingManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1967804166 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1967804165} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 32aa227b448de9c55a47a29b4d0ac546, type: 3} + m_Name: + m_EditorClassIdentifier: + gameOver: 0 + gameOverAddress: -1 +--- !u!4 &1967804167 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1967804165} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts.meta b/Assets/Scripts.meta new file mode 100644 index 0000000..56043e4 --- /dev/null +++ b/Assets/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8a7f71fd8aaf32134b5ff17d8e44a131 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/BuildingManager.cs b/Assets/Scripts/BuildingManager.cs new file mode 100644 index 0000000..52bba53 --- /dev/null +++ b/Assets/Scripts/BuildingManager.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using Random = System.Random; + +public class BuildingManager : MonoBehaviour { + [SerializeField] private bool gameOver = false; + [SerializeField] private int gameOverAddress = -1; + + private Dictionary _mailGenerators; + + // Start is called before the first frame update + private void Start() { + _mailGenerators = new Dictionary(); + } + + // Update is called once per frame + private void Update() { } + + public void RegisterMailGenerator(int atAddress, MailGenerator generator) { + _mailGenerators[atAddress] = generator; + } + + public void GameOver(int byAddress) { + gameOver = true; + gameOverAddress = byAddress; + } + + public int RandomMailGenerator() { + return new Random().Next(0, _mailGenerators.Count); + } + + public int RandomMailGeneratorNot(int address) { + var generator = 0; + do { + generator = RandomMailGenerator(); + } while (generator != address); + + return generator; + } + + public MailGenerator GetMailGenerator(int address) { + return _mailGenerators[address]; + } +} \ No newline at end of file diff --git a/Assets/Scripts/BuildingManager.cs.meta b/Assets/Scripts/BuildingManager.cs.meta new file mode 100644 index 0000000..b06ff77 --- /dev/null +++ b/Assets/Scripts/BuildingManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 32aa227b448de9c55a47a29b4d0ac546 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/MailGenerator.cs b/Assets/Scripts/MailGenerator.cs new file mode 100644 index 0000000..416d074 --- /dev/null +++ b/Assets/Scripts/MailGenerator.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using Unity.Collections; +using UnityEngine; +using UnityEngine.Serialization; +using Random = System.Random; + +public class Mail { + public int FromAddress; + public int ToAddress; + public double TimeExisted; +} + +public class MailGenerator : MonoBehaviour { + [FormerlySerializedAs("MailCycleTime")] [SerializeField] private int mailCycleTime = 5; + [FormerlySerializedAs("MailChance")] [SerializeField, Range(0, 1)] private double mailChance = 0.2; + [FormerlySerializedAs("MaxMail")] [SerializeField] private int maxMail = 10; + [SerializeField, Range(0, 1)] private double mailAmountAdjustment = 0.3; + [SerializeField] private bool mailAdjustment = true; + [SerializeField] private int address; + [SerializeField] private BuildingManager manager; + [SerializeField] private double maxMailLifetime = 30; + + [FormerlySerializedAs("CurrentMail")] [SerializeField, ReadOnly] private int currentMail = 0; + [FormerlySerializedAs("CycleTime")] [SerializeField, ReadOnly] private double cycleTime = 0.0; + [FormerlySerializedAs("LastRandomMail")] [SerializeField, ReadOnly] private double lastRandomMail = 0.0; + [FormerlySerializedAs("LastRandomCutoff")] [SerializeField, ReadOnly] private double lastRandomCutoff = 0.0; + [SerializeField, ReadOnly] private double lastMailAmountAdjustment = 0.0; + [SerializeField, ReadOnly] private double lastMailAmountAdjustedBy = 0.0; + + private Random _rng; + private Dictionary _mail; + + // Start is called before the first frame update + private void Start() { + _rng = new Random(); + _mail = new Dictionary(); + + manager.RegisterMailGenerator(address, this); + } + + // Update is called once per frame + private void Update() { + cycleTime += Time.deltaTime; + + foreach (var mail in _mail) { + mail.Value.TimeExisted += Time.deltaTime; + + if (mail.Value.TimeExisted > maxMailLifetime) { + manager.GameOver(mail.Value.ToAddress); + } + } + + if (cycleTime > mailCycleTime) { + cycleTime = 0; + + lastRandomMail = _rng.NextDouble(); + lastRandomCutoff = 1 - mailChance; + + if (currentMail < maxMail && lastRandomMail > lastRandomCutoff) { + currentMail++; + var newMail = new Mail { + FromAddress = address, + ToAddress = manager.RandomMailGeneratorNot(address), + TimeExisted = 0.0 + }; + _mail[currentMail] = newMail; + } + + if (mailAdjustment) { + lastMailAmountAdjustment = _rng.NextDouble() - 0.5; + lastMailAmountAdjustedBy = lastMailAmountAdjustment * mailAmountAdjustment; + mailChance += lastMailAmountAdjustedBy; + } + + if (mailChance > 1) mailChance = 1; + if (mailChance < 0) mailChance = 0; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/MailGenerator.cs.meta b/Assets/Scripts/MailGenerator.cs.meta new file mode 100644 index 0000000..0512237 --- /dev/null +++ b/Assets/Scripts/MailGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ef9f1f87684e67e6da7888d486a6bcea +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/SceneTemplateSettings.json b/ProjectSettings/SceneTemplateSettings.json new file mode 100644 index 0000000..6f3e60f --- /dev/null +++ b/ProjectSettings/SceneTemplateSettings.json @@ -0,0 +1,167 @@ +{ + "templatePinStates": [], + "dependencyTypeInfos": [ + { + "userAdded": false, + "type": "UnityEngine.AnimationClip", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEditor.Animations.AnimatorController", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.AnimatorOverrideController", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEditor.Audio.AudioMixerController", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.ComputeShader", + "ignore": true, + "defaultInstantiationMode": 1, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.Cubemap", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.GameObject", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEditor.LightingDataAsset", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": false + }, + { + "userAdded": false, + "type": "UnityEngine.LightingSettings", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.Material", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEditor.MonoScript", + "ignore": true, + "defaultInstantiationMode": 1, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.PhysicMaterial", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.PhysicsMaterial2D", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.Rendering.PostProcessing.PostProcessProfile", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.Rendering.PostProcessing.PostProcessResources", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.Rendering.VolumeProfile", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEditor.SceneAsset", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": false + }, + { + "userAdded": false, + "type": "UnityEngine.Shader", + "ignore": true, + "defaultInstantiationMode": 1, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.ShaderVariantCollection", + "ignore": true, + "defaultInstantiationMode": 1, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.Texture", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.Texture2D", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + }, + { + "userAdded": false, + "type": "UnityEngine.Timeline.TimelineAsset", + "ignore": false, + "defaultInstantiationMode": 0, + "supportsModification": true + } + ], + "defaultDependencyTypeInfo": { + "userAdded": false, + "type": "", + "ignore": false, + "defaultInstantiationMode": 1, + "supportsModification": true + }, + "newSceneOverride": 0 +} \ No newline at end of file