blob: 094f4dae46ac3ad48048f8697d9e3ba19d54e769 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
import os
import sequtils
import parsetoml
import tables
type
Plant = object
icon: char
seedspacing: int
rowspacing: int
rownum: int
let sneedconfig = parsetoml.parseFile(paramStr(1))
let plotMaxSizeX = sneedconfig["X"].getInt()
let plotMaxSizeY = sneedconfig["Y"].getInt()
var plot = newSeqWith( plotMaxSizeX, newSeq[char](plotMaxSizeY))
var plants: seq[Plant]
var soilicon: char
var gapicon: char
var gapsize: int
var farmableEdge: bool
for key, val in sneedconfig["plants"].getTable.pairs():
if key == "soilicon":
soilicon = sneedconfig["plants"]["soilicon"].getStr()[0]
elif key == "gapicon":
gapicon = sneedconfig["plants"]["gapicon"].getStr()[0]
elif key == "gapsize":
gapsize = sneedconfig["plants"]["gapsize"].getInt()
elif key == "farmableEdge":
farmableEdge = sneedconfig["plants"]["farmableEdge"].getBool()
else:
let rawPlant = sneedconfig["plants"][key]
plants.add ( Plant(
icon: rawPlant["icon"].getStr[0],
seedspacing: rawPlant["seedspacing"].getInt(),
rowspacing: rawPlant["rowspacing"].getInt(),
rownum: rawPlant["rownum"].getInt(1)
) )
var rowstart = 0
var rowend: int
var gapstart: int
var gapend: int
var seedSpaceCounter = 0
# If the edge is farmable, then the edge plants should have their row size reduced.
if farmableEdge:
plants[0].rowspacing = toInt(plants[0].rowspacing/2)
plants[plants.len()-1].rowspacing = toInt(plants[plants.len()-1].rowspacing/2)
# Find the demarcation point of the the row's end point.
for plant in plants:
rowend = (rowstart + plant.rowspacing)
# If the rowend go over the maximum, terminate the loop
if rowend >= (plotMaxSizeY-1):
echo "Warning: " & $plant & " has gone over the allowed farm size! It has been dropped from the farm!"
break
# fill the entire row with the soil icon, and the gap area with the gap icon
# put seeds in the center of the rows with seedspacing number of units of free space between the edge
for x in rowstart..rowend:
for y in 0..(plotMaxSizeY-1):
plot[y][x] = soilicon
seedSpaceCounter = seedSpaceCounter + 1
if x == (toInt(plant.rowspacing/2)+rowstart) and (seedSpaceCounter mod (plant.seedspacing+1)) == 0:
plot[y][x] = plant.icon
# Find the start and end of the gap given the gap size and add it unless this is the final plant.
gapstart = rowend + 1
gapend = gapstart + gapsize
# If the gaps go over the maximum, terminate the loop
if gapend >= (plotMaxSizeY-1):
break
if plant != plants[plants.len()-1]:
for x in gapstart..gapend:
for y in 0..(plotMaxSizeY-1):
plot[y][x] = gapicon
else:
for x in gapstart..gapend:
for y in 0..(plotMaxSizeY-1):
plot[y][x] = '!'
let extraGap = (plotMaxSizeY - gapstart)
if extraGap > 0:
echo "Warning! You have " & $(extraGap) & " Y units of unused space!"
# Note the start of the next row (end of the previous row + gap size), reset the seed space counter, and then move onto the next plant.
rowstart = gapend + 1
seedSpaceCounter = 0
for y in plot:
for x in y:
stdout.write x
stdout.write "\n"
|