-
Notifications
You must be signed in to change notification settings - Fork 109
/
Save.bb
2538 lines (2116 loc) · 58.6 KB
/
Save.bb
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Function SaveGame(file$)
CatchErrors("Uncaught (SaveGame)")
If Not Playable Then Return ;don't save if the player can't move at all
If DropSpeed#>0.02*FPSfactor Or DropSpeed#<-0.02*FPSfactor Then Return
If KillTimer < 0 Then Return
GameSaved = True
Local x%, y%, i%, temp%
Local n.NPCs, r.Rooms, do.Doors
CreateDir(file)
Local f% = WriteFile(file + "save.txt")
WriteString f, CurrentTime()
WriteString f, CurrentDate()
WriteInt f, PlayTime
WriteFloat f, EntityX(Collider)
WriteFloat f, EntityY(Collider)
WriteFloat f, EntityZ(Collider)
WriteFloat f, EntityX(Head)
WriteFloat f, EntityY(Head)
WriteFloat f, EntityZ(Head)
WriteString f, Str(AccessCode)
WriteFloat f, EntityPitch(Collider)
WriteFloat f, EntityYaw(Collider)
;WriteString f, VersionNumber
WriteString f, CompatibleNumber
WriteFloat f, BlinkTimer
WriteFloat f, BlinkEffect
WriteFloat f, BlinkEffectTimer
WriteInt f, DeathTimer
WriteInt f, BlurTimer
WriteFloat f, HealTimer
WriteByte f, Crouch
WriteFloat f, Stamina
WriteFloat f, StaminaEffect
WriteFloat f, StaminaEffectTimer
WriteFloat f, EyeStuck
WriteFloat f, EyeIrritation
WriteFloat f, Injuries
WriteFloat f, Bloodloss
WriteFloat f,PrevInjuries
WriteFloat f,PrevBloodloss
WriteString f, DeathMSG
For i = 0 To 5
WriteFloat f, SCP1025state[i]
Next
WriteFloat f, VomitTimer
WriteByte f, Vomit
WriteFloat f, CameraShakeTimer
WriteFloat f, Infect
For i = 0 To CUSTOM
If (SelectedDifficulty = difficulties(i)) Then
WriteByte f, i
If (i = CUSTOM) Then
WriteByte f,SelectedDifficulty\aggressiveNPCs
WriteByte f,SelectedDifficulty\permaDeath
WriteByte f,SelectedDifficulty\saveType
WriteByte f,SelectedDifficulty\otherFactors
EndIf
EndIf
Next
WriteFloat f, MonitorTimer
WriteFloat f, Sanity
WriteByte f, WearingGasMask
WriteByte f, WearingVest
WriteByte f, WearingHazmat
WriteByte f, WearingNightVision
WriteByte f, Wearing1499
WriteFloat f,NTF_1499PrevX#
WriteFloat f,NTF_1499PrevY#
WriteFloat f,NTF_1499PrevZ#
WriteFloat f,NTF_1499X#
WriteFloat f,NTF_1499Y#
WriteFloat f,NTF_1499Z#
If NTF_1499PrevRoom <> Null
WriteFloat f,NTF_1499PrevRoom\x
WriteFloat f,NTF_1499PrevRoom\z
Else
WriteFloat f,0.0
WriteFloat f,0.0
EndIf
WriteByte f, SuperMan
WriteFloat f, SuperManTimer
WriteByte f, LightsOn
WriteString f, RandomSeed
WriteFloat f, SecondaryLightOn
WriteFloat f, PrevSecondaryLightOn
WriteByte f, RemoteDoorOn
WriteByte f, SoundTransmission
WriteByte f, Contained106
For i = 0 To MAXACHIEVEMENTS-1
WriteByte f, Achievements(i)
Next
WriteInt f, RefinedItems
WriteInt f, MapWidth
WriteInt f, MapHeight
For lvl = 0 To 0
For x = 0 To MapWidth
For y = 0 To MapHeight
WriteInt f, MapTemp(x, y)
WriteByte f, MapFound(x, y)
Next
Next
Next
WriteInt f, 113
temp = 0
For n.NPCs = Each NPCs
temp = temp +1
Next
WriteInt f, temp
For n.NPCs = Each NPCs
DebugLog("Saving NPC " +n\NVName+ " (ID "+n\ID+")")
WriteByte f, n\NPCtype
WriteFloat f, EntityX(n\Collider,True)
WriteFloat f, EntityY(n\Collider,True)
WriteFloat f, EntityZ(n\Collider,True)
WriteFloat f, EntityPitch(n\Collider)
WriteFloat f, EntityYaw(n\Collider)
WriteFloat f, EntityRoll(n\Collider)
WriteFloat f, n\State
WriteFloat f, n\State2
WriteFloat f, n\State3
WriteInt f, n\PrevState
WriteByte f, n\Idle
WriteFloat f, n\LastDist
WriteInt f, n\LastSeen
WriteInt f, n\CurrSpeed
WriteFloat f, n\Angle
WriteFloat f, n\Reload
WriteInt f, n\ID
If n\Target <> Null Then
WriteInt f, n\Target\ID
Else
WriteInt f, 0
EndIf
WriteFloat f, n\EnemyX
WriteFloat f, n\EnemyY
WriteFloat f, n\EnemyZ
WriteString f, n\texture
WriteFloat f, AnimTime(n\obj)
WriteInt f, n\IsDead
WriteFloat f, n\PathX
WriteFloat f, n\PathZ
WriteInt f, n\HP
WriteString f, n\Model
WriteFloat f, n\ModelScaleX#
WriteFloat f, n\ModelScaleY#
WriteFloat f, n\ModelScaleZ#
WriteInt f, n\TextureID
Next
WriteFloat f, MTFtimer
For i = 0 To 6
If MTFrooms[0]<>Null Then
WriteString f, MTFrooms[0]\RoomTemplate\Name
Else
WriteString f, "a"
EndIf
WriteInt f, MTFroomState[i]
Next
WriteInt f, 632
WriteInt f, room2gw_brokendoor
WriteFloat f,room2gw_x
WriteFloat f,room2gw_z
WriteByte f, I_Zone\Transition[0]
WriteByte f, I_Zone\Transition[1]
WriteByte f, I_Zone\HasCustomForest
WriteByte f, I_Zone\HasCustomMT
temp = 0
For r.Rooms = Each Rooms
temp=temp+1
Next
WriteInt f, temp
For r.Rooms = Each Rooms
WriteInt f, r\RoomTemplate\id
WriteInt f, r\angle
WriteFloat f, r\x
WriteFloat f, r\y
WriteFloat f, r\z
WriteByte f, r\found
WriteInt f, r\zone
If PlayerRoom = r Then
WriteByte f, 1
Else
WriteByte f, 0
EndIf
For i = 0 To 11
If r\NPC[i]=Null Then
WriteInt f, 0
Else
WriteInt f, r\NPC[i]\ID
EndIf
Next
For i=0 To 10
If r\Levers[i]<>0 Then
If EntityPitch(r\Levers[i],True) > 0 Then ;p??????ll???
WriteByte(f,1)
Else
WriteByte(f,0)
EndIf
EndIf
Next
WriteByte(f,2)
If r\grid=Null Then ;this room doesn't have a grid
WriteByte(f,0)
Else ;this room has a grid
WriteByte(f,1)
For y=0 To gridsz-1
For x=0 To gridsz-1
WriteByte(f,r\grid\grid[x+(y*gridsz)])
WriteByte(f,r\grid\angles[x+(y*gridsz)])
Next
Next
EndIf
If r\fr=Null Then ;this room doesn't have a forest
WriteByte(f,0)
Else ;this room has a forest
If (Not I_Zone\HasCustomForest) Then
WriteByte(f,1)
Else
WriteByte(f,2)
EndIf
For y=0 To gridsize-1
For x=0 To gridsize-1
WriteByte(f,r\fr\grid[x+(y*gridsize)])
Next
Next
WriteFloat f,EntityX(r\fr\Forest_Pivot,True)
WriteFloat f,EntityY(r\fr\Forest_Pivot,True)
WriteFloat f,EntityZ(r\fr\Forest_Pivot,True)
EndIf
Next
WriteInt f, 954
temp = 0
For do.Doors = Each Doors
temp = temp+1
Next
WriteInt f, temp
For do.Doors = Each Doors
WriteFloat f, EntityX(do\frameobj,True)
WriteFloat f, EntityY(do\frameobj,True)
WriteFloat f, EntityZ(do\frameobj,True)
WriteByte f, do\open
WriteFloat f, do\openstate
WriteByte f, do\locked
WriteByte f, do\AutoClose
WriteFloat f, EntityX(do\obj, True)
WriteFloat f, EntityZ(do\obj, True)
If do\obj2 <> 0 Then
WriteFloat f, EntityX(do\obj2, True)
WriteFloat f, EntityZ(do\obj2, True)
Else
WriteFloat f, 0.0
WriteFloat f, 0.0
End If
WriteFloat f, do\timer
WriteFloat f, do\timerstate
WriteByte f, do\IsElevatorDoor
WriteByte f, do\MTFClose
Next
WriteInt f, 1845
DebugLog 1845
Local d.Decals
temp = 0
For d.Decals = Each Decals
temp = temp+1
Next
WriteInt f, temp
For d.Decals = Each Decals
WriteInt f, d\ID
WriteFloat f, EntityX(d\obj,True)
WriteFloat f, EntityY(d\obj,True)
WriteFloat f, EntityZ(d\obj,True)
WriteFloat f, EntityPitch(d\obj,True)
WriteFloat f, EntityYaw(d\obj,True)
WriteFloat f, EntityRoll(d\obj,True)
WriteByte f, d\blendmode
WriteInt f, d\fx
WriteFloat f, d\Size
WriteFloat f, d\Alpha
WriteFloat f, d\AlphaChange
WriteFloat f, d\Timer
WriteFloat f, d\lifetime
Next
Local e.Events
temp = 0
For e.Events = Each Events
temp=temp+1
Next
WriteInt f, temp
For e.Events = Each Events
WriteString f, e\EventName
WriteFloat f, e\EventState
WriteFloat f, e\EventState2
WriteFloat f, e\EventState3
WriteFloat f, EntityX(e\room\obj)
WriteFloat f, EntityZ(e\room\obj)
WriteString f, e\EventStr
Next
temp = 0
For it.items = Each Items
temp=temp+1
Next
WriteInt f, temp
For it.items = Each Items
WriteString f, it\itemtemplate\name
WriteString f, it\itemtemplate\tempName
WriteString f, it\name
WriteFloat f, EntityX(it\collider, True)
WriteFloat f, EntityY(it\collider, True)
WriteFloat f, EntityZ(it\collider, True)
WriteByte f, it\r
WriteByte f, it\g
WriteByte f, it\b
WriteFloat f, it\a
WriteFloat f, EntityPitch(it\collider)
WriteFloat f, EntityYaw(it\collider)
WriteFloat f, it\state
WriteByte f, it\Picked
If SelectedItem = it Then WriteByte f, 1 Else WriteByte f, 0
Local ItemFound% = False
For i = 0 To MaxItemAmount - 1
If Inventory(i) = it Then ItemFound = True : Exit
Next
If ItemFound Then WriteByte f, i Else WriteByte f, 66
If it\itemtemplate\isAnim<>0 Then
WriteFloat f, AnimTime(it\model)
EndIf
WriteByte f,it\invSlots
WriteInt f,it\ID
If it\itemtemplate\invimg=it\invimg Then WriteByte f,0 Else WriteByte f,1
Next
temp=0
For it.items = Each Items
If it\invSlots>0 Then temp=temp+1
Next
WriteInt f,temp
For it.items = Each Items
;OtherInv
If it\invSlots>0 Then
WriteInt f,it\ID
For i=0 To it\invSlots-1
If it\SecondInv[i] <> Null Then
WriteInt f, it\SecondInv[i]\ID
Else
WriteInt f, -1
EndIf
Next
EndIf
;OtherInv End
Next
For itt.itemtemplates = Each ItemTemplates
WriteByte f, itt\found
Next
If UsedConsole
WriteInt f, 100
DebugLog "Used Console"
Else
WriteInt f, 994
EndIf
WriteFloat f, CameraFogFar
WriteFloat f, StoredCameraFogFar
WriteByte f, I_427\Using
WriteFloat f, I_427\Timer
WriteByte f, Wearing714
CloseFile f
If Not MenuOpen Then
If SelectedDifficulty\saveType = SAVEONSCREENS Then
PlaySound_Strict(LoadTempSound("SFX\General\Save2.ogg"))
Else
PlaySound_Strict(LoadTempSound("SFX\General\Save1.ogg"))
EndIf
Msg = "Game progress saved."
MsgTimer = 70 * 4
;SetSaveMSG("Game progress saved.")
EndIf
CatchErrors("SaveGame")
End Function
Function LoadGame(file$)
Local version$ = ""
CatchErrors("Uncaught (LoadGame)")
DebugLog "---------------------------------------------------------------------------"
DropSpeed=0.0
DebugHUD = False
GameSaved = True
Local x#, y#, z#, i%, temp%, strtemp$, r.Rooms, id%, n.NPCs, do.Doors
Local f% = ReadFile(file + "save.txt")
strtemp = ReadString(f)
strtemp = ReadString(f)
PlayTime = ReadInt(f)
x = ReadFloat(f)
y = ReadFloat(f)
z = ReadFloat(f)
PositionEntity(Collider, x, y+0.05, z)
ResetEntity(Collider)
x = ReadFloat(f)
y = ReadFloat(f)
z = ReadFloat(f)
PositionEntity(Head, x, y+0.05, z)
ResetEntity(Head)
AccessCode = Int(ReadString(f))
x = ReadFloat(f)
y = ReadFloat(f)
RotateEntity(Collider, x, y, 0, 0)
strtemp = ReadString(f)
version = strtemp
BlinkTimer = ReadFloat(f)
BlinkEffect = ReadFloat(f)
BlinkEffectTimer = ReadFloat(f)
DeathTimer = ReadInt(f)
BlurTimer = ReadInt(f)
HealTimer = ReadFloat(f)
Crouch = ReadByte(f)
Stamina = ReadFloat(f)
StaminaEffect = ReadFloat(f)
StaminaEffectTimer = ReadFloat(f)
EyeStuck = ReadFloat(f)
EyeIrritation = ReadFloat(f)
Injuries = ReadFloat(f)
Bloodloss = ReadFloat(f)
PrevInjuries = ReadFloat(f)
PrevBloodloss = ReadFloat(f)
DeathMSG = ReadString(f)
For i = 0 To 5
SCP1025state[i]=ReadFloat(f)
Next
VomitTimer = ReadFloat(f)
Vomit = ReadByte(f)
CameraShakeTimer = ReadFloat(f)
Infect = ReadFloat(f)
Local difficultyIndex = ReadByte(f)
SelectedDifficulty = difficulties(difficultyIndex)
If (difficultyIndex = CUSTOM) Then
SelectedDifficulty\aggressiveNPCs = ReadByte(f)
SelectedDifficulty\permaDeath = ReadByte(f)
SelectedDifficulty\saveType = ReadByte(f)
SelectedDifficulty\otherFactors = ReadByte(f)
EndIf
MonitorTimer = ReadFloat(f)
Sanity = ReadFloat(f)
WearingGasMask = ReadByte(f)
WearingVest = ReadByte(f)
WearingHazmat = ReadByte(f)
WearingNightVision = ReadByte(f)
Wearing1499 = ReadByte(f)
NTF_1499PrevX# = ReadFloat(f)
NTF_1499PrevY# = ReadFloat(f)
NTF_1499PrevZ# = ReadFloat(f)
NTF_1499X# = ReadFloat(f)
NTF_1499Y# = ReadFloat(f)
NTF_1499Z# = ReadFloat(f)
Local r1499_x# = ReadFloat(f)
Local r1499_z# = ReadFloat(f)
SuperMan = ReadByte(f)
SuperManTimer = ReadFloat(f)
LightsOn = ReadByte(f)
RandomSeed = ReadString(f)
SecondaryLightOn = ReadFloat(f)
PrevSecondaryLightOn = ReadFloat(f)
RemoteDoorOn = ReadByte(f)
SoundTransmission = ReadByte(f)
Contained106 = ReadByte(f)
For i = 0 To MAXACHIEVEMENTS-1
Achievements(i)=ReadByte(f)
Next
RefinedItems = ReadInt(f)
MapWidth = ReadInt(f)
MapHeight = ReadInt(f)
For x = 0 To MapWidth
For y = 0 To MapHeight
MapTemp( x, y) = ReadInt(f)
MapFound(x, y) = ReadByte(f)
Next
Next
If ReadInt(f) <> 113 Then RuntimeError("Couldn't load the game, save file corrupted (error 2.5)")
temp = ReadInt(f)
For i = 1 To temp
Local NPCtype% = ReadByte(f)
x = ReadFloat(f)
y = ReadFloat(f)
z = ReadFloat(f)
n.NPCs = CreateNPC(NPCtype, x, y, z)
Select NPCtype
Case NPCtype173
Curr173 = n
Case NPCtypeOldMan
Curr106 = n
Case NPCtype096
Curr096 = n
Case NPCtype5131
Curr5131 = n
End Select
x = ReadFloat(f)
y = ReadFloat(f)
z = ReadFloat(f)
RotateEntity(n\Collider, x, y, z)
n\State = ReadFloat(f)
n\State2 = ReadFloat(f)
n\State3 = ReadFloat(f)
n\PrevState = ReadInt(f)
n\Idle = ReadByte(f)
n\LastDist = ReadFloat(f)
n\LastSeen = ReadInt(f)
n\CurrSpeed = ReadInt(f)
n\Angle = ReadFloat(f)
n\Reload = ReadFloat(f)
ForceSetNPCID(n, ReadInt(f))
n\TargetID = ReadInt(f)
DebugLog("Loading NPC " +n\NVName+ " (ID "+n\ID+")")
n\EnemyX = ReadFloat(f)
n\EnemyY = ReadFloat(f)
n\EnemyZ = ReadFloat(f)
n\texture = ReadString(f)
If n\texture <> "" Then
tex = LoadTexture_Strict (n\texture)
EntityTexture n\obj, tex
EndIf
Local frame# = ReadFloat(f)
Select NPCtype
Case NPCtypeOldMan, NPCtypeD, NPCtype096, NPCtypeMTF, NPCtypeGuard, NPCtype049, NPCtypeZombie, NPCtypeClerk
SetAnimTime(n\obj, frame)
End Select
n\Frame = frame
n\IsDead = ReadInt(f)
n\PathX = ReadFloat(f)
n\PathZ = ReadFloat(f)
n\HP = ReadInt(f)
n\Model = ReadString(f)
n\ModelScaleX# = ReadFloat(f)
n\ModelScaleY# = ReadFloat(f)
n\ModelScaleZ# = ReadFloat(f)
If n\Model <> ""
FreeEntity n\obj
n\obj = LoadAnimMesh_Strict(n\Model)
ScaleEntity n\obj,n\ModelScaleX,n\ModelScaleY,n\ModelScaleZ
SetAnimTime n\obj,frame
EndIf
n\TextureID = ReadInt(f)
If n\TextureID > 0
ChangeNPCTextureID(n.NPCs,n\TextureID-1)
SetAnimTime(n\obj,frame)
EndIf
Next
For n.NPCs = Each NPCs
If n\TargetID <> 0 Then
For n2.npcs = Each NPCs
If n2<>n Then
If n2\id = n\TargetID Then n\Target = n2
EndIf
Next
EndIf
Next
MTFtimer = ReadFloat(f)
For i = 0 To 6
strtemp = ReadString(f)
If strtemp <> "a" Then
For r.Rooms = Each Rooms
If r\RoomTemplate\Name = strtemp Then
MTFrooms[i]=r
EndIf
Next
EndIf
MTFroomState[i]=ReadInt(f)
Next
If ReadInt(f) <> 632 Then RuntimeError("Couldn't load the game, save file corrupted (error 1)")
room2gw_brokendoor = ReadInt(f)
room2gw_x = ReadFloat(f)
room2gw_z = ReadFloat(f)
If version = CompatibleNumber Then
I_Zone\Transition[0] = ReadByte(f)
I_Zone\Transition[1] = ReadByte(f)
I_Zone\HasCustomForest = ReadByte(f)
I_Zone\HasCustomMT = ReadByte(f)
EndIf
temp = ReadInt(f)
For i = 1 To temp
Local roomtemplateID% = ReadInt(f)
Local angle% = ReadInt(f)
x = ReadFloat(f)
y = ReadFloat(f)
z = ReadFloat(f)
found = ReadByte(f)
level = ReadInt(f)
temp2 = ReadByte(f)
; If angle >= 360
; angle = angle-360
; EndIf
angle=WrapAngle(angle)
For rt.roomtemplates = Each RoomTemplates
If rt\id = roomtemplateID Then
r.Rooms = CreateRoom(level, rt\shape, x, y, z, rt\name)
TurnEntity(r\obj, 0, angle, 0)
r\angle = angle
r\found = found
Exit
End If
Next
If temp2 = 1 Then PlayerRoom = r.Rooms
For x = 0 To 11
id = ReadInt(f)
If id > 0 Then
For n.NPCs = Each NPCs
If n\ID = id Then r\NPC[x]=n : Exit
Next
EndIf
Next
For x=0 To 11
id = ReadByte(f)
If id=2 Then
Exit
Else If id=1 Then
RotateEntity(r\Levers[x], 78, EntityYaw(r\Levers[x]), 0)
Else
RotateEntity(r\Levers[x], -78, EntityYaw(r\Levers[x]), 0)
EndIf
Next
If ReadByte(f)=1 Then ;this room has a grid
If r\grid<>Null Then ;remove the old grid content
For x=0 To gridsz-1
For y=0 To gridsz-1
If r\grid\Entities[x+(y*gridsz)]<>0 Then
FreeEntity r\grid\Entities[x+(y*gridsz)]
r\grid\Entities[x+(y*gridsz)]=0
EndIf
If r\grid\waypoints[x+(y*gridsz)]<>Null Then
RemoveWaypoint(r\grid\waypoints[x+(y*gridsz)])
r\grid\waypoints[x+(y*gridsz)]=Null
EndIf
Next
Next
For x=0 To 5
If r\grid\Meshes[x]<>0 Then
FreeEntity r\grid\Meshes[x]
r\grid\Meshes[x]=0
EndIf
Next
Delete r\grid
EndIf
r\grid=New Grids
For y=0 To gridsz-1
For x=0 To gridsz-1
r\grid\grid[x+(y*gridsz)]=ReadByte(f)
r\grid\angles[x+(y*gridsz)]=ReadByte(f)
;get only the necessary data, make the event handle the meshes and waypoints separately
Next
Next
EndIf
Local hasForest = ReadByte(f)
If hasForest>0 Then ;this room has a forest
If r\fr<>Null Then ;remove the old forest
DestroyForest(r\fr)
Else
r\fr=New Forest
EndIf
For y=0 To gridsize-1
Local sssss$ = ""
For x=0 To gridsize-1
r\fr\grid[x+(y*gridsize)]=ReadByte(f)
sssss=sssss+Str(r\fr\grid[x+(y*gridsize)])
Next
DebugLog sssss
Next
lx# = ReadFloat(f)
ly# = ReadFloat(f)
lz# = ReadFloat(f)
If hasForest=1 Then
PlaceForest(r\fr,lx,ly,lz,r)
Else
PlaceForest_MapCreator(r\fr,lx,ly,lz,r)
EndIf
ElseIf r\fr<>Null Then ;remove the old forest
DestroyForest(r\fr)
Delete r\fr
EndIf
Next
For r.Rooms = Each Rooms
If r\x = r1499_x# And r\z = r1499_z#
NTF_1499PrevRoom = r
Exit
EndIf
Next
If ReadInt(f) <> 954 Then RuntimeError("Couldn't load the game, save file may be corrupted (error 2)")
Local spacing# = 8.0
Local zone%,shouldSpawnDoor%
For y = MapHeight To 0 Step -1
If y<I_Zone\Transition[1]-(SelectedMap="") Then
zone=3
ElseIf y>=I_Zone\Transition[1]-(SelectedMap="") And y<I_Zone\Transition[0]-(SelectedMap="") Then
zone=2
Else
zone=1
EndIf
For x = MapWidth To 0 Step -1
If MapTemp(x,y) > 0 Then
If zone = 2 Then temp=2 Else temp=0
For r.Rooms = Each Rooms
r\angle = WrapAngle(r\angle)
If Int(r\x/8.0)=x And Int(r\z/8.0)=y Then
shouldSpawnDoor = False
Select r\RoomTemplate\Shape
Case ROOM1
If r\angle=90
shouldSpawnDoor = True
EndIf
Case ROOM2
If r\angle=90 Or r\angle=270
shouldSpawnDoor = True
EndIf
Case ROOM2C
If r\angle=0 Or r\angle=90
shouldSpawnDoor = True
EndIf
Case ROOM3
If r\angle=0 Or r\angle=180 Or r\angle=90
shouldSpawnDoor = True
EndIf
Default
shouldSpawnDoor = True
End Select
If shouldSpawnDoor
If (x+1)<(MapWidth+1)
If MapTemp(x + 1, y) > 0 Then
do.Doors = CreateDoor(r\zone, Float(x) * spacing + spacing / 2.0, 0, Float(y) * spacing, 90, r, Max(Rand(-3, 1), 0), temp)
r\AdjDoor[0] = do
EndIf
EndIf
EndIf
shouldSpawnDoor = False
Select r\RoomTemplate\Shape
Case ROOM1
If r\angle=180
shouldSpawnDoor = True
EndIf
Case ROOM2
If r\angle=0 Or r\angle=180
shouldSpawnDoor = True
EndIf
Case ROOM2C
If r\angle=180 Or r\angle=90
shouldSpawnDoor = True
EndIf
Case ROOM3
If r\angle=180 Or r\angle=90 Or r\angle=270
shouldSpawnDoor = True
EndIf
Default
shouldSpawnDoor = True
End Select
If shouldSpawnDoor
If (y+1)<(MapHeight+1)
If MapTemp(x, y + 1) > 0 Then
do.Doors = CreateDoor(r\zone, Float(x) * spacing, 0, Float(y) * spacing + spacing / 2.0, 0, r, Max(Rand(-3, 1), 0), temp)
r\AdjDoor[3] = do
EndIf
EndIf
EndIf
Exit
EndIf
Next
End If
Next
Next
temp = ReadInt (f)
For i = 1 To temp
x = ReadFloat(f)
y = ReadFloat(f)
z = ReadFloat(f)
Local open% = ReadByte(f)
Local openstate# = ReadFloat(f)
Local locked% = ReadByte(f)
Local autoclose% = ReadByte(f)
Local objX# = ReadFloat(f)
Local objZ# = ReadFloat(f)
Local obj2X# = ReadFloat(f)
Local obj2Z# = ReadFloat(f)
Local timer% = ReadFloat(f)
Local timerstate# = ReadFloat(f)
Local IsElevDoor = ReadByte(f)
Local MTFClose = ReadByte(f)
For do.Doors = Each Doors
If EntityX(do\frameobj,True) = x And EntityY(do\frameobj,True) = y And EntityZ(do\frameobj,True) = z Then
do\open = open
do\openstate = openstate
do\locked = locked
do\AutoClose = autoclose
do\timer = timer
do\timerstate = timerstate
do\IsElevatorDoor = IsElevDoor
do\MTFClose = MTFClose
PositionEntity(do\obj, objX, y, objZ, True)
If do\obj2 <> 0 Then PositionEntity(do\obj2, obj2X, y, obj2Z, True)
Exit
End If
Next
Next
InitWayPoints()
If ReadInt(f) <> 1845 Then RuntimeError("Couldn't load the game, save file corrupted (error 3)")
Local d.Decals
For d.Decals = Each Decals
FreeEntity d\obj
Delete d
Next
temp = ReadInt(f)
For i = 1 To temp
id% = ReadInt(f)
x = ReadFloat(f)
y = ReadFloat(f)
z = ReadFloat(f)
Local pitch# = ReadFloat(f)
Local yaw# = ReadFloat(f)
Local roll# = ReadFloat(f)
d.Decals = CreateDecal(id, x, y, z, pitch, yaw, roll)
d\blendmode = ReadByte (f)
d\fx = ReadInt(f)
d\Size = ReadFloat(f)
d\Alpha = ReadFloat(f)
d\AlphaChange = ReadFloat(f)
d\Timer = ReadFloat(f)
d\lifetime = ReadFloat(f)
ScaleSprite(d\obj, d\Size, d\Size)
EntityBlend d\obj, d\blendmode