-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComputer1.sprak
358 lines (322 loc) · 8.1 KB
/
Computer1.sprak
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
void SetUp()
ClearText()
PrintBanner('SetUp Defaults','-=+=-')
if (Input('restore default_location? (y/n)')=='y')
SaveMemory('default_location','Computer1')
end
if (Input('restore locations? (y/n)')=='y')
SaveArrayMemory('locations',[])
end
PrintBanner('Raw Functions','-=+=-')
if (Input('Unlock all doors? (y/n)')=='y')
UnlockAll()
end
if (HasFloppy())
if (Input('Save All Things? (y/n)')=='y')
SaveAllThings()
end
end
TestArrayMemories()
TestSplit()
end
string GetHardDriveName()
return 'Lodge_Room1_MediumSewerComputer_MediumSewerComputer_1'
end
string GetPoliceComputerName()
return 'PoliceOfficeInterior_MinistryOfficeWorkstationComputer_1'
end
array GetMemories()
DisconnectAll()
var dataserver=Connect(GetHardDriveName())
return dataserver.GetMemories()
end
void SaveMemory(var key,var val)
DisconnectAll()
var dataserver=Connect(GetHardDriveName())
dataserver.SaveMemory(key,val)
end
string LoadMemory(var key)
DisconnectAll()
var dataserver=Connect(GetHardDriveName())
return dataserver.LoadMemory(key)
end
void EraseMemory(var key)
DisconnectAll()
var dataserver=Connect(GetHardDriveName())
dataserver.EraseMemory(key)
end
bool HasMemory(var key)
DisconnectAll()
var dataserver=Connect(GetHardDriveName())
return dataserver.HasMemory(key)
end
string Tap(string name)
string default =LoadMemory('default_location')
DisconnectAll()
bool notfound = true
loop x in LoadArrayMemory('locations')
if x==name
notfound =false
end
end
if notfound
AppendArrayMemory('locations',name)
end
var remote =Connect(name)
remote.DisconnectAll()
remote.Connect(default)
remote.Slurp()
end
void EraseArrayMemory(string key)
string arraycount =key+'_len'
if HasMemory(arraycount)
number c = LoadMemory(arraycount)
loop x in Range(0,c+(-1))
EraseMemory(key+'_'+x)
end
EraseMemory(arraycount)
end
end
array LoadArrayMemory(string key)
array rval =[]
string arraycount =key+'_len'
if HasMemory(arraycount)
number c = LoadMemory(arraycount)
loop x in Range(0,c+(-1))
Append(rval,LoadMemory(key+'_'+x))
end
end
return rval
end
void RemoveArrayMemory(string key,number index)
array t = LoadArrayMemory(key)
Remove(t,index)
array rval=[]
loop x in t
Append(rval,x)
end
SaveArrayMemory(key,rval)
end
array PopArrayMemory(string key)
array rval =[]
string arraycount =key+'_len'
if HasMemory(arraycount)
number c = LoadMemory(arraycount)
c-=1
Append(rval,LoadMemory(key+'_'+c))
EraseMemory(key+'_'+c)
SaveMemory(arraycount,c)
end
return rval
end
void AppendArrayMemory(string key,var val)
string arraycount =key+'_len'
if HasMemory(arraycount)
number c = LoadMemory(arraycount)
SaveMemory(key+'_'+c,val)
c+=1
SaveMemory(arraycount,c)
end
end
void SaveArrayMemory(string key, array val)
string arraycount =key+'_len'
if HasMemory(arraycount)
EraseArrayMemory(key)
end
SaveMemory(arraycount,Count(val))
loop x in Range(0,Count(val)+(-1))
SaveMemory(key+'_'+x,val[x])
end
end
void PrintBanner(string s,string h)
number len = 30
Print('')
loop i in Range(0,Int(len/Count(h)))
PrintS(h)
end
Print('')
Print(s)
loop i in Range(0,Int(len/Count(h)))
PrintS(h)
end
Print('')
Print('')
end
void TestArrayMemories()
ClearText()
PrintBanner('TESTING MEMORYS','-=+=-')
array tst =[1,2,3,4]
Print('saving: ')
Print(tst)
SaveArrayMemory('tst',tst)
Print('Loading: ')
Print(LoadArrayMemory('tst'))
Print('All Memorys')
Print(GetMemories())
Print('Appending: 5 to:')
Print(tst)
AppendArrayMemory('tst',5)
Print('Loading: ')
Print(LoadArrayMemory('tst'))
Print('poppoing:')
Print(PopArrayMemory('tst'))
Print('Loading: ')
Print(LoadArrayMemory('tst'))
Print('removing at 1:')
RemoveArrayMemory('tst',1)
Print('Loading: ')
Print(LoadArrayMemory('tst'))
Print('Eraseing:')
EraseArrayMemory('tst')
Print('Remaining Memories')
Print(GetMemories())
string ban = 'TEST RESULT: '
ban+= !HasMemory('tst')
PrintBanner(ban,'~')
end
array GetAllRooms()
DisconnectAll()
var cops=Connect(GetPoliceComputerName())
return cops.GetAllRooms()
end
array GetThingsOfType(string type)
DisconnectAll()
var cops = Connect(GetPoliceComputerName())
return cops.GetThingsOfType(type)
end
var GetTypeOfThing(string thing)
DisconnectAll()
var cops = Connect(GetPoliceComputerName())
return cops.GetTypeOfThing(thing)
end
array GetThingsInRoom(string r)
DisconnectAll()
var cops=Connect(GetPoliceComputerName())
return cops.GetThingsInRoom(r)
end
array GetPeople()
DisconnectAll()
var cops=Connect(GetPoliceComputerName())
return cops.GetPeople()
end
var GetAction(string name)
DisconnectAll()
var cops =Connect(GetPoliceComputerName())
return cops.GetAction(name)
end
var GetPosition(string name)
DisconnectAll()
var cops =Connect(GetPoliceComputerName())
return cops.GetPosition(name)
end
void SetPosition(string name,string targetThing)
DisconnectAll()
var cops = Connect(GetPoliceComputerName())
cops.SetPosition(name,targetThing)
end
void InteractWith(string thing)
DisconnectAll()
var cops = Connect(GetPoliceComputerName())
cops.InteractWith(thing)
end
void UnlockAll()
var doors = GetThingsOfType('door')
loop t in doors
Unlock(t)
end
end
void SaveAllThings()
if HasFloppy()
ClearData()
number rcount=0
var rooms = GetAllRooms()
var maxrooms=Count(rooms)
loop r in rooms
rcount+=1
var things = GetThingsInRoom(r)
number max =Count(things)
number i=0
loop t in things
SaveData(GetTypeOfThing(t)+', '+r+', '+t)
i+=1
ClearText()
PrintS('Saving level ')
PrintS(Int(100*(rcount/maxrooms)))
Print("'/.")
PrintS('on room ')
PrintS(r)
PrintS(' @ ')
PrintS( Int(100*(i/max)))
Print("'/.")
end
end
PrintBanner('Done','~')
else
Print('no floppy to download to')
end
end
void TestSplit()
PrintBanner('TEST SPLIT','-=+=-')
PrintS('is d the second letter in dave? ')
Print(HasSubstringAt('dave',1,'d'))
PrintS('is a the second letter in dave? ')
Print(HasSubstringAt('dave',1,'a'))
PrintS('is av the second and third letter in dave? ')
Print(HasSubstringAt('dave',1,'av'))
PrintS('is ae the second and third letter in dave? ')
Print(HasSubstringAt('dave',1,'ae'))
Print('abc split on b is ["a","c"] >> ')
var o=Split('abc','b')
PrintS('len ')
PrintS(Count(o))
PrintS(' == 2: ')
Print(Count(o)==2)
array expected=['a','c']
loop x from 0 to Count(o)+(-1)
PrintS(o[x])
PrintS('==')
PrintS( expected[x])
PrintS(': ')
Print(o[x]==expected[x])
end
end
bool HasSubstringAt(string haystack, number haystackPos, string needle)
number size = Count(haystack)
number remainingSize = size - haystackPos
number needleSize = Count(needle)
if (remainingSize < needleSize)
return False
end
loop i from 0 to (needleSize - 1)
if (haystack[haystackPos + i] != needle[i])
return False
end
end
return True
end
array Split(string str, string delimiter)
number size = Count(str)
number delimiterSize = Count(delimiter)
if (size <= 0)
return []
end
array ret = []
string currentLine = ""
number i = 0
loop
if (HasSubstringAt(str, i, delimiter))
Append(ret, currentLine)
currentLine = ""
i += delimiterSize
else
currentLine += str[i]
i += 1
end
if (i >= size)
break
end
end
Append(ret, currentLine)
return ret
end
SetUp()