-
Notifications
You must be signed in to change notification settings - Fork 1
/
Players.CB
377 lines (294 loc) · 11.3 KB
/
Players.CB
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
//Pelaajien hallinta
//Pelaajan muistipalan offsettejä
Const MAIN_PLAYER_NAME = 0 //Viittaa merkkijonoon, joka sisältää pelaajan nimen
Const MAIN_PLAYER_CONTROLS = 4 //Viittaa muistipalaan, joka sisältää pelaajan näppäimet
Const MAIN_PLAYER_COLOR = 8 //Sisältää pelaajan tunnusvärin
Const MAIN_PLAYER_SKIN = 12 //Sisältää pelaajan ihonvärin
Const MAIN_PLAYER_HEADGEAR = 16 //Sisältää tiedot pelaajan osista
Const MAIN_PLAYER_HEAD = 17 //Sisältää tiedot pelaajan osista
Const MAIN_PLAYER_BODY = 18 //Sisältää tiedot pelaajan osista
Const MAIN_PLAYER_TEAM = 20 //Sisältää pelaajan joukkueen numeron
Const MAIN_PLAYER_NPC = 24 //Onko ihmispelaaja (0) vai tekoäly (taitavuus 1, 2 tai 3)
Const MAIN_PLAYER_POINTS = 28 //Sisältää pelaajan pisteet (Int)
Const MAIN_PLAYER_DYNAMIC = 32 //Viittaa muistipalaan, joka on tarkoitettu minipelikohtaista tiedontallennusta varten
//Pelaajan muistipalan koko
Const MAIN_PLAYER_STATIC_SIZE = 36
//Pelaajien maksimimäärä 8, tietokoneelle harvoin pystyy sen enempää pelaamaan (loppuu näppäimet ja kapulat :D )
Const MAIN_MAX_PLAYERS = 8
//Sisältää viittaukset pelaajien muistipaloihin
Dim MAIN_PlayerData(MAIN_MAX_PLAYERS) As integer
//Sisältää todellisen tiedon pelaajien määrästä (minipelille saatetaan ilmoittaa eri määrä)
Global MAIN_PlayerAmount
MAIN_PlayerAmount = 0
Type MAIN_CommonString
Field txt$
EndType
//Lisää pelaajan ja värin, palauttaa pelaajan numeron
Function MAIN_AddPlayer(name$, r = -1, g = -1, b = -1)
number = -1
//Luodaan pelaaja seuraavalle vapaalle indeksille jos on olemassa (muutoin palautetaan -1)
For i = 0 To MAIN_MAX_PLAYERS - 1
If (MAIN_PlayerData(i) = 0) Then number = i : Exit
Next i
If (number <> -1) Then
MAIN_PlayerAmount = MAIN_PlayerAmount + 1
player = MakeMEMBlock(MAIN_PLAYER_STATIC_SIZE)
iS. MAIN_CommonString = New(MAIN_CommonString)
iS\txt$ = name$
id = ConvertToInteger(iS)
PokeInt player, MAIN_PLAYER_NAME, id
PokeInt player, MAIN_PLAYER_CONTROLS, MakeMEMBlock(API_ACTIONS + 1)
PokeInt player, MAIN_PLAYER_POINTS, 0
PokeInt player, MAIN_PLAYER_DYNAMIC, MakeMEMBlock(4)
MAIN_PlayerData(number) = player
API_PlayerColor(number,r,g,b)
EndIf
Return number
EndFunction
// Palauttaa pelaajan nimen tai tyhjän merkkijonon jos pelaajaa ei löydy
Function API_PlayerName(number)
If (number >= 0 And number < MAIN_MAX_PLAYERS) Then
player = MAIN_PlayerData(number)
return MAIN_MemString(player,MAIN_PLAYER_NAME)
EndIf
Return ""
EndFunction
// Asettaa ja palauttaa pelaajan tekoälyarvon
Function API_PlayerNPC(number, npc = -1)
If (number >= 0 And number < MAIN_MAX_PLAYERS) Then
player = MAIN_PlayerData(number)
If (npc >= 0) Then
PokeInt player, MAIN_PLAYER_NPC, npc
Return npc
Else
Return PeekInt(player, MAIN_PLAYER_NPC)
EndIf
EndIf
Return 0
EndFunction
// Asettaa ja palauttaa pelaajan joukkuenumeron
Function API_PlayerTeam(number, team = -1)
If (number >= 0 And number < MAIN_MAX_PLAYERS) Then
player = MAIN_PlayerData(number)
If (team >= 0) Then
PokeInt player, MAIN_PLAYER_NPC, team
Return team
Else
Return PeekInt(player, MAIN_PLAYER_NPC)
EndIf
EndIf
Return 0
EndFunction
// Asettaa ja palauttaa pelaajan pisteet
Function API_PlayerPoints(number, points = -1)
If (number >= 0 And number < MAIN_MAX_PLAYERS) Then
player = MAIN_PlayerData(number)
If (points >= 0) Then
PokeInt player, MAIN_PLAYER_POINTS, points
Return points
Else
Return PeekInt(player, MAIN_PLAYER_POINTS)
EndIf
EndIf
Return 0
EndFunction
//Asettaa tai palauttaa pelaajan värikomponentit tai pikselin
Function API_PlayerColor(number, r = -1, g = -1, b = -1)
If (number >= 0 And number < MAIN_MAX_PLAYERS) Then
player = MAIN_PlayerData(number)
If r = -1 Then
c = Rand(1, 6)
c = c Shl 29
PokeByte player, MAIN_PLAYER_COLOR + 3 - RED, 127 + 127 * (c Shr 31)
c = c Shl 1
PokeByte player, MAIN_PLAYER_COLOR + 3 - GREEN, 127 + 127 * (c Shr 31)
c = c Shl 1
PokeByte player, MAIN_PLAYER_COLOR + 3 - BLUE, 127 + 127 * (c Shr 31)
Else
If g = -1 Or b = -1 And (r => 0 And r < 4)
If r = 0 Then
Return PeekInt(player, MAIN_PLAYER_COLOR)
Else
Return PeekByte(player, MAIN_PLAYER_COLOR + 3 - r)
EndIf
Else
PokeByte player, MAIN_PLAYER_COLOR + 3 - RED, r Mod 256
PokeByte player, MAIN_PLAYER_COLOR + 3 - GREEN, g Mod 256
PokeByte player, MAIN_PLAYER_COLOR + 3 - BLUE, b Mod 256
PokeByte player, MAIN_PLAYER_COLOR + 4, 255
EndIf
EndIf
EndIf
EndFunction
//Palauttaa minipelin käyttämän muistipalan
Function API_PlayerDataBlock(number)
Return PeekInt(MAIN_PlayerData(number), MAIN_PLAYER_DYNAMIC)
EndFunction
//Tyhjentää pelaajien muistipalat
Function MAIN_ResetPlayersDataBlocks()
For p = 0 To MAIN_PlayerAmount - 1
player = MAIN_PlayerData(p)
If player <> 0 Then
dynamic = PeekInt(player, MAIN_PLAYER_DYNAMIC)
If dynamic <> 0 Then
For i = 0 To MEMBlockSize(dynamic) - 1
PokeByte dynamic, i, 0
Next i
EndIf
EndIf
Next p
EndFunction
//Asettaa tai palauttaa kokonaisluvun
Function API_PlayerInt(number, dataField, value$ = "NAN")
player = MAIN_PlayerData(number)
dynamic = PeekInt(player,MAIN_PLAYER_DYNAMIC)
iValue = MAIN_MemInt(dynamic, dataField, value$)
PokeInt player,MAIN_PLAYER_DYNAMIC,MAIN_MemChangedAddress
Return iValue
EndFunction
//Asettaa tai palauttaa liukuluvun
Function API_PlayerFloat(number, dataField, value$ = "NAN")
player = MAIN_PlayerData(number)
dynamic = PeekInt(player,MAIN_PLAYER_DYNAMIC)
fValue# = MAIN_MemFloat(dynamic, dataField, value$)
PokeInt player, MAIN_PLAYER_DYNAMIC, MAIN_MemChangedAddress
Return fValue#
EndFunction
//Asettaa tai palauttaa merkkijonon
Function API_PlayerString(number, dataField, value$ = "TOIVOTAANettäEItuleTÖRMÄYKSIÄtämänMERKKIJONONkanssa!!")
player = MAIN_PlayerData(number)
dynamic = PeekInt(player,MAIN_PLAYER_DYNAMIC)
sValue$ = MAIN_MemString(dynamic, dataField, value$)
PokeInt player, MAIN_PLAYER_DYNAMIC, MAIN_MemChangedAddress
Return sValue$
EndFunction
//Kopioi staatisen ja/tai dynaamisen muistipalan
//pelaajalle jos annettu pala on erisuuri kuin nolla
Function MAIN_CopyPlayerData(number, static = 0, dynamic = 0)
If (number >= 0 And number < MAIN_MAX_PLAYERS) Then
player = MAIN_PlayerData(number)
If (static <> 0 And MEMBlockSize(static) = MAIN_PLAYER_STATIC_SIZE) Then
MemCopy static, 0, player, 0, MAIN_PLAYER_STATIC_SIZE
EndIf
p_dynamic = PeekInt(player, MAIN_PLAYER_DYNAMIC)
If (dynamic <> 0) Then
size = MEMBlockSize(dynamic)
ResizeMEMBlock p_dynamic, size
MemCopy dynamic, 0, p_dynamic, 0, size
PokeInt player, MAIN_PLAYER_DYNAMIC, p_dynamic
EndIf
EndIf
EndFunction
//Lataa näppäinasetukset
Function MAIN_LoadKeys()
MAIN_ParseSettings("Saved Data/keyconfig.ini")
For i = 1 To MAIN_PlayerAmount
If (MAIN_PlayerData(i-1) <> 0) Then
player = MAIN_PlayerData(i-1)
ctrl = PeekInt(player, MAIN_PLAYER_CONTROLS)
PokeByte ctrl, API_UP, MAIN_GetSetting("PLAYER"+i+"_UP")
PokeByte ctrl, API_DOWN, MAIN_GetSetting("PLAYER"+i+"_DOWN")
PokeByte ctrl, API_LEFT, MAIN_GetSetting("PLAYER"+i+"_LEFT")
PokeByte ctrl, API_RIGHT, MAIN_GetSetting("PLAYER"+i+"_RIGHT")
PokeByte ctrl, API_ACTION1, MAIN_GetSetting("PLAYER"+i+"_ACTION1")
PokeByte ctrl, API_ACTION2, MAIN_GetSetting("PLAYER"+i+"_ACTION2")
PokeByte ctrl, API_CONTROL_SOURCE, API_KEYBOARD
EndIf
Next i
End Function
//Asettaa tai palauttaa pelaajan hahmon päähineen
Function API_PlayerHeadgear(number, partNo = -1)
If (number >= 0 And number < MAIN_MAX_PLAYERS) Then
player = MAIN_PlayerData(number)
If partNo < 0 Then
Return PeekByte(player, MAIN_PLAYER_HEADGEAR)
Else
PokeByte player, MAIN_PLAYER_HEADGEAR, partNo
EndIf
EndIf
EndFunction
//Asettaa tai palauttaa pelaajan hahmon pään
Function API_PlayerHead(number, partNo = -1)
If (number >= 0 And number < MAIN_MAX_PLAYERS) Then
player = MAIN_PlayerData(number)
If partNo < 0 Then
Return PeekByte(player, MAIN_PLAYER_HEAD)
Else
PokeByte player, MAIN_PLAYER_HEAD, partNo
EndIf
EndIf
EndFunction
//Asettaa tai palauttaa pelaajan hahmon ruumiin
Function API_PlayerBody(number, partNo = -1)
If (number >= 0 And number < MAIN_MAX_PLAYERS) Then
player = MAIN_PlayerData(number)
If partNo < 0 Then
Return PeekByte(player, MAIN_PLAYER_BODY)
Else
PokeByte player, MAIN_PLAYER_BODY, partNo
EndIf
EndIf
EndFunction
//Kokoaa hahmon osista
Function MAIN_CompileCharacter(number, style$ = "side")
Headgear$ = Replace(RSet(Str(API_PlayerHeadgear(number)), 3), " ", "0")
Head$ = Replace(RSet(Str(API_PlayerHead(number)), 3), " ", "0")
Body$ = Replace(RSet(Str(API_PlayerBody(number)), 3), " ", "0")
dir$ = "GlobalMedia/Character" + style + "Parts/"
//Ladataan ensin ruumiin ihonvärillä värjättävä kuva
If FileExists(dir + "Body_SC_" + Body + ".png") Then
BodySC = LoadImage(dir + "Body_SC_" + Body + ".png")
'API_Recolor(number, BodySC, 10)
EndIf
//Sitten tunnusvärillä
If FileExists(dir + "Body_PC_" + Body + ".png") Then
Character = LoadImage(dir + "Body_PC_" + Body + ".png")
//Etsitään pään sijainnin merkitsevää magentaa pistettä
Lock Image(Character)
hx = -1 : hy = -1
For y = 0 To ImageHeight(Character) - 1
For x = 0 To ImageWidth(Character) - 1
If GetPixel2(x, y, Image(Character)) = -65281 Then hx = x : hy = y : Exit //Magenta 255, 0, 255
Next x
If hx = x Then Exit
Next y
Unlock Image(Character)
API_Recolor(number, Character, 10, BodySC) //Jos BodySC ei ole ladattu, niin se on nolla => jätetään huomiotta
If BodySC <> 0 Then DeleteImage BodySC
Else
API_MakeError("Hahmon ruumista ei ole olemassa")
EndIf
//Päästä todennäköisesti löytyy aina ihonvärikuva, joten ladataan ensin tunnusväreillä
If FileExists(dir + "Head_PC_" + Head + ".png") Then
HeadPC = LoadImage(dir + "Head_PC_" + Head + ".png")
API_Recolor(number, HeadPC, 10)
EndIf
If FileExists(dir + "Head_SC_" + Head + ".png") Then
HeadSC = LoadImage(dir + "Head_SC_" + Head + ".png")
'API_Recolor(number, HeadSC, 10, HeadPC)
If HeadPC <> 0 Then DeleteImage HeadPC
//Sitten liitetään koko pää ruumiiseen
HotSpot HeadSC
DrawToImage Character
DrawImage HeadSC, hx, hy
DrawToScreen
DeleteImage HeadSC
EndIf
//Päähineestä todennäköisesti löytyy aina tunnusvärikuva, joten ladataan ensin ihonvärillä
If FileExists(dir + "Headgear_SC_" + Headgear + ".png") Then
HeadgearSC = LoadImage(dir + "Headgear_SC_" + Headgear + ".png")
'API_Recolor(number, HeadGearPC)
EndIf
If FileExists(dir + "Headgear_PC_" + Headgear + ".png") Then
HeadgearPC = LoadImage(dir + "Headgear_PC_" + Headgear + ".png")
API_Recolor(number, HeadGearPC, 10, HeadGearSC)
If HeadGearSC <> 0 Then DeleteImage HeadGearSC
//Sitten liitetään koko päähine ruumiiseen
HotSpot HeadGearPC
DrawToImage Character
DrawImage HeadGearPC, hx, hy
DrawToScreen
DeleteImage HeadGearPC
EndIf
Return Character
EndFunction