diff --git a/SpriteFontPlus/src/obj/Debug/net45/SpriteFontPlus.FNA.assets.cache b/SpriteFontPlus/src/obj/Debug/net45/SpriteFontPlus.FNA.assets.cache index fa583116edf1dfeb60f3c50d140933201a36585a..7dcce0e548e46b90764d6354561e1e2dd771f572 GIT binary patch literal 137 zc$^FHc6a1rU|`6Y`Lft-vc#^t2G_eM*SatqnQarhm({N558oPxa1XnEtqg<#BM{5z ihZd(673(MFR2J*&<&~zVmgpBGCTAz6rxxqu(+mI~z8cH` diff --git a/SpriteFontPlus/src/obj/Debug/net45/SpriteFontPlus.FNA.csprojAssemblyReference.cache b/SpriteFontPlus/src/obj/Debug/net45/SpriteFontPlus.FNA.csprojAssemblyReference.cache index 32553b925989f81243733108b07d4924e7d32460..4509e352ad438a22ff3c12e2a43d27c53735ed8a GIT binary patch literal 20937 zc%1EA3v?9K8J@e@-Rx|T<>?6+X5)-t% z6qNK7#A=0}R%lC6+oH8TPPIOZo>O1vh+>PPrz%=hJoUjjRjAVYPi7`FxpNZ|CLB54 zHnK|A}Z-zG`J+(LNm$rH^xM>l8@MZ?T%e5e$D(4gVowUDTO19yb0ROgpmD9x#oO_hlCz!*#d(Qg zk{E|0#dVggZ#b0J?b9}00|4^XZ*b2^T6K?W5YGDC)OW0-nhh0rW=VyCZ6 z1gL^P|wH4q7kB!2px&0be6OY7%Fz>D9MS%+mT^tN5 zx$kJ)x5i>~0e6g?NkdJ@{*!$y#x5N)c2zu#z2KK*s2^actNL}FmOej}JvG#`(j#!8 z#R+Gy?;?u_QwbO2WZ-caxYa`7{v$pfpKVgVVbWKci*f5~2OlZJn7RaGOz!uL20vdq zU><3nyX>s8*HBI_muHQ|685o=3w269k#CPmK0%6x`55Ll4Np;R(}EGsS5{TzYZfBD z623X!0-xmmSDe+Xp;-iTU4gF^pL9qp(s1`VXXOw;nJ{3$46eHpH!m5w>AGy2h>>Ou z83_=s!U$CsjwQgn8e;}5#H7}*QBGyG!(Ibo5{Stlrhu3VA|1pu5MB^I5E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$i6$fSThTyuZHa?R*3*yS~ahRs(p zDOf7Bn}ANCL3@xH>(Nx`F$DBj8uUe`(BrAl7ZcEz(4em{bx4}>#^#xzzC%|k5b!H> zrw+mads64wQs36Q)R#AF(D!Ghe}1lOdw&1|e`G|v@#1DBxE6^K8?D{SwTOK^{;<_> zEdoC!V>@8KU{WHn5{acH)(yQI9c~tWt;2Q^X?2S}t!^gM>L%EToIGtIG+E+L>xY0%}S>twiPvzs{| zu8}HG-)p2wnyHISy;w{2Vjbbd#Wd(;rqB&k=oJKXBL&*iOa<{1AOQ-90|GmkT~e@M zoF9)_A;60@e2f!Yc)9wN;mX$YmrW1?I{_GZB!Wqd=BW<7r?zR^uLM9B4d5m-0JKiy jvVnlwNQ1gX54Bz8vV{P+l?Kpl27tDyT+nv)UCRFeVBd4~ diff --git a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs --- a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs +++ b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs @@ -1,6 +1,8 @@ using System; +using System.Linq; using System.Collections.Generic; using Encompass; +using JM.LinqFaster; using Microsoft.Xna.Framework; @@ -10,11 +12,12 @@ namespace isometricparkfna.Spawners { [Receives(typeof(SpawnContractMessage))] - [Reads(typeof(AreaComponent))] + [Reads(typeof(AreaComponent), typeof(ContractStatusComponent))] class ContractSpawner : Spawner { private Random random_generator; + public const int DEFAULT_MIN_SQUARES = 10; public const int DEFAULT_SQUARES = 25; public const int CONTRACT_MINIMUM = 50; public const int CONTRACT_MAXIMUM = 250; @@ -63,10 +66,11 @@ attempts += 1; } } - squares.AddRange(squares_to_add); + var remaining = max_size - squares.Count; + squares.AddRange(squares_to_add.Take(remaining)); squares_to_add.Clear(); - if (attempts >= maxAttempts) + if (attempts >= maxAttempts && squares.Count < max_size) { System.Console.WriteLine(string.Format("Failed to generate enough squares. {0} were requested, only {1} were found ({2} attempts)", max_size, squares.Count, attempts)); break; @@ -77,34 +81,44 @@ protected override void Spawn(in SpawnContractMessage message) { - var contract = CreateEntity(); - //for now: - var occupied = new List(); + //for now: + var occupied = new List(); - foreach(ref readonly var entity in ReadEntities()) - { - var entitySquares = GetComponent(entity).squares; - occupied.AddRange(entitySquares); - } + foreach (var (entity, status) in ReadEntities().SelectWhereF((e) => (e, GetComponent(e)), + (e) => (e.Item2.status != ContractStatus.Expired)) + ) + { + var entitySquares = GetComponent(entity).squares; + occupied.AddRange(entitySquares); + } - var start_x = random_generator.Next(0,50); - var start_y = random_generator.Next(0,50); + var start_x = random_generator.Next(0, 50); + var start_y = random_generator.Next(0, 50); + + int max_squares = (message.max_squares == 0) ? DEFAULT_SQUARES : message.max_squares; + int min_squares = (message.min_squares == null) ? DEFAULT_MIN_SQUARES : (int)message.min_squares; + Vector2[] squares = (message.squares == null) ? CreateArea(start_x, start_y, max_squares, new HashSet(occupied)) : message.squares; - int max_squares = (message.max_squares == 0) ? DEFAULT_SQUARES : message.max_squares; - Vector2[] squares = (message.squares == null) ? CreateArea(start_x, start_y, max_squares, new HashSet(occupied)) : message.squares; + if (squares.Length > min_squares) + { + var contract = CreateEntity(); - int contract_amount = random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM); + int contract_amount = random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM); - // AddComponent - AddComponent(contract, new AreaComponent { squares = squares }); - AddComponent(contract, new NameComponent { DisplayName = message.name }); - AddComponent(contract, new SelectedComponent { selected = false }); - AddComponent(contract, new ContractStatusComponent { status = ContractStatus.Proposed, date = this.simulation.DateTime }); - AddComponent(contract, new TreeDeltaComponent{ deltaTrees = -1}); - AddComponent(contract, new BudgetLineComponent { category = "Contracts", - //Round to the nearest $5 - amount = (decimal)((contract_amount/5)*5) }); + // AddComponent + AddComponent(contract, new AreaComponent { squares = squares }); + AddComponent(contract, new NameComponent { DisplayName = message.name }); + AddComponent(contract, new SelectedComponent { selected = false }); + AddComponent(contract, new ContractStatusComponent { status = ContractStatus.Proposed, date = this.simulation.DateTime }); + AddComponent(contract, new TreeDeltaComponent { deltaTrees = -1 }); + AddComponent(contract, new BudgetLineComponent + { + category = "Contracts", + //Round to the nearest $5 + amount = (decimal)((contract_amount / 5) * 5) + }); + } } } diff --git a/isometric-park-fna/Messages/SpawnContractMessage.cs b/isometric-park-fna/Messages/SpawnContractMessage.cs --- a/isometric-park-fna/Messages/SpawnContractMessage.cs +++ b/isometric-park-fna/Messages/SpawnContractMessage.cs @@ -7,6 +7,8 @@ { public Vector2[] squares; public string name; - public int max_squares; + public int max_squares; + + public int? min_squares; } } diff --git a/isometric-park-fna/isometric-park-fna.csproj b/isometric-park-fna/isometric-park-fna.csproj --- a/isometric-park-fna/isometric-park-fna.csproj +++ b/isometric-park-fna/isometric-park-fna.csproj @@ -194,6 +194,9 @@ + + ..\packages\JM.LinqFaster.1.1.2\lib\net461\JM.LinqFaster.dll + diff --git a/isometric-park-fna/packages.config b/isometric-park-fna/packages.config --- a/isometric-park-fna/packages.config +++ b/isometric-park-fna/packages.config @@ -2,8 +2,9 @@ - - + + + @@ -11,7 +12,7 @@ - + - + \ No newline at end of file