Skip to content

Commit 22452bb

Browse files
committed
Added 3 save slots and map optimizations
1 parent dd8d62c commit 22452bb

File tree

9 files changed

+247
-49
lines changed

9 files changed

+247
-49
lines changed

AM2R Server.project.gmx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<sprite>sprites\sLoad</sprite>
4848
<sprite>sprites\sSave</sprite>
4949
<sprite>sprites\sClients</sprite>
50+
<sprite>sprites\sSlot</sprite>
5051
</sprites>
5152
<backgrounds name="background"/>
5253
<paths name="paths"/>
@@ -70,6 +71,7 @@
7071
<object>objects\oLoad</object>
7172
<object>objects\oReset</object>
7273
<object>objects\oClients</object>
74+
<object>objects\oSlot</object>
7375
</objects>
7476
<rooms name="rooms">
7577
<room>rooms\room0</room>

objects/oLoad.object.gmx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<string>draw_self();
7777
if(alarm[0] &gt; 0){
7878
draw_set_halign(fa_right);
79-
draw_text(x - 12, y + 12, "Stats loaded!");
79+
draw_text(x - 12, y + 12, "Loaded slot " + string(global.slot) + "!");
8080
draw_set_halign(fa_left);
8181
}
8282
</string>

objects/oReset.object.gmx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,54 @@
88
<parentName>&lt;undefined&gt;</parentName>
99
<maskName>&lt;undefined&gt;</maskName>
1010
<events>
11+
<event eventtype="0" enumb="0">
12+
<action>
13+
<libid>1</libid>
14+
<id>603</id>
15+
<kind>7</kind>
16+
<userelative>0</userelative>
17+
<isquestion>0</isquestion>
18+
<useapplyto>-1</useapplyto>
19+
<exetype>2</exetype>
20+
<functionname></functionname>
21+
<codestring></codestring>
22+
<whoName>self</whoName>
23+
<relative>0</relative>
24+
<isnot>0</isnot>
25+
<arguments>
26+
<argument>
27+
<kind>1</kind>
28+
<string>alarm[10] = -1;
29+
</string>
30+
</argument>
31+
</arguments>
32+
</action>
33+
</event>
34+
<event eventtype="2" enumb="10">
35+
<action>
36+
<libid>1</libid>
37+
<id>603</id>
38+
<kind>7</kind>
39+
<userelative>0</userelative>
40+
<isquestion>0</isquestion>
41+
<useapplyto>-1</useapplyto>
42+
<exetype>2</exetype>
43+
<functionname></functionname>
44+
<codestring></codestring>
45+
<whoName>self</whoName>
46+
<relative>0</relative>
47+
<isnot>0</isnot>
48+
<arguments>
49+
<argument>
50+
<kind>1</kind>
51+
<string>if(instance_exists(oServer)){
52+
with(oServer) event_user(0);
53+
}
54+
</string>
55+
</argument>
56+
</arguments>
57+
</action>
58+
</event>
1159
<event eventtype="2" enumb="0">
1260
<action>
1361
<libid>1</libid>
@@ -79,6 +127,12 @@ if(alarm[0] &gt; 0){
79127
draw_text(x - 12, y + 12, "Stats reset!");
80128
draw_set_halign(fa_left);
81129
}
130+
131+
if(alarm[10] &gt; 0){
132+
draw_set_halign(fa_right);
133+
draw_text(1008, 416, "Server resetting in " + string(floor(alarm[10] / 60)));
134+
draw_set_halign(fa_left);
135+
}
82136
</string>
83137
</argument>
84138
</arguments>

objects/oSave.object.gmx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<string>draw_self();
7777
if(alarm[0] &gt; 0){
7878
draw_set_halign(fa_right);
79-
draw_text(x - 12, y + 12, "Stats saved!");
79+
draw_text(x - 12, y + 12, "Saved slot " + string(global.slot) + "!");
8080
draw_set_halign(fa_left);
8181
}
8282
</string>

objects/oServer.object.gmx

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ alarm[1] = 90;
7878
alarm[2] = 300;
7979
alarm[5] = 3600;
8080
alarm[9] = 60;
81-
alarm[10] = 3600;
8281

8382
reset_globals();
8483

85-
sendSize = 300;
84+
global.slot = 1;
85+
86+
var slotStr = string(global.slot);
87+
88+
global.saveString = "\save" + slotStr + ".txt";
8689
</string>
8790
</argument>
8891
</arguments>
@@ -749,6 +752,10 @@ switch(type_event){
749752
}
750753
}
751754
ds_list_delete(playerList, findsocket);
755+
756+
if(ds_list_size(playerList) == 0){
757+
with(oReset) alarm[10] = 1800;
758+
}
752759
}
753760
break;
754761
case network_type_data:
@@ -1091,6 +1098,9 @@ switch(type_event){
10911098
var findsocket = ds_list_find_index(playerList, socket);
10921099
if(findsocket &lt; 0){
10931100
ds_list_add(playerList, socket);
1101+
if(ds_list_size(playerList) &gt; 0 &amp;&amp; oReset.alarm[10] &gt; 0){
1102+
oReset.alarm[10] = -1;
1103+
}
10941104
}
10951105
if(ds_list_size(idList) &gt; 0){
10961106
for(var i=0; i&lt;ds_list_size(idList); i++){
@@ -1330,51 +1340,48 @@ switch(type_event){
13301340
ds_list_destroy(event);
13311341
break;
13321342
case 9:
1333-
var dmap = ds_list_create();
1334-
ds_list_read(dmap, strict_decompress(buffer_read(_buffer, buffer_string)));
1335-
var clientID = buffer_read(_buffer, buffer_u8);
1336-
var sockets = ds_list_size(playerList);
1337-
var dmapArr = dmap[| 0];
1338-
if(is_array(dmapArr)){
1339-
for(var i=0; i&lt;array_height_2d(global.dmap); i++){
1340-
for(var f=0; f&lt;array_length_2d(global.dmap, i); f++){
1341-
for(var v=0; v&lt;array_height_2d(dmapArr); v++){
1342-
if(i == dmapArr[v, 1] &amp;&amp; f == dmapArr[v, 2]){
1343-
if(dmapArr[v, 0] &gt; global.dmap[i, f]){
1344-
global.dmap[i, f] = dmapArr[v, 0];
1345-
} else if(dmapArr[v, 0] &lt; global.dmap[i, f]){
1346-
if(global.dmap[i, f] == 10 &amp;&amp; dmapArr[v, 0] == 1){
1347-
global.dmap[i, f] = dmapArr[v, 0];
1348-
}
1349-
}
1350-
}
1343+
var tileCount = buffer_read(_buffer, buffer_u16);
1344+
if(tileCount &gt; 0){
1345+
buffer_delete(buffer);
1346+
var size, type, alignment;
1347+
size = 1024;
1348+
type = buffer_grow;
1349+
alignment = 1;
1350+
buffer = buffer_create(size, type, alignment);
1351+
buffer_seek(buffer, buffer_seek_start, 0);
1352+
buffer_write(buffer, buffer_s32, bufferSizePacket);
1353+
buffer_write(buffer, buffer_u8, 10);
1354+
buffer_write(buffer, buffer_u16, tileCount);
1355+
1356+
for(var i=0; i&lt;tileCount; i++){
1357+
var tileX = buffer_read(_buffer, buffer_u8);
1358+
var tileY = buffer_read(_buffer, buffer_u8);
1359+
var tileData = buffer_read(_buffer, buffer_u8);
1360+
buffer_write(buffer, buffer_u8, tileX);
1361+
buffer_write(buffer, buffer_u8, tileY);
1362+
buffer_write(buffer, buffer_u8, tileData);
1363+
if(tileData &gt; global.dmap[tileX, tileY]){
1364+
global.dmap[tileX, tileY] = tileData;
1365+
} else if(tileData &lt; global.dmap[tileX, tileY]){
1366+
if(global.dmap[tileX, tileY] == 10 &amp;&amp; tileData == 1){
1367+
global.dmap[tileX, tileY] = tileData;
13511368
}
13521369
}
13531370
}
1371+
1372+
var clientID = buffer_read(_buffer, buffer_u8);
1373+
1374+
buffer_write(buffer, buffer_u8, clientID);
1375+
1376+
var sockets = ds_list_size(playerList);
1377+
1378+
for(var i=0; i&lt;sockets; i++){
1379+
network_send_packet(playerList[| i], buffer, buffer_tell(buffer));
1380+
}
13541381
}
1355-
buffer_delete(buffer);
1356-
var size, type, alignment;
1357-
size = 1024;
1358-
type = buffer_grow;
1359-
alignment = 1;
1360-
buffer = buffer_create(size, type, alignment);
1361-
buffer_seek(buffer, buffer_seek_start, 0);
1362-
buffer_write(buffer, buffer_u8, 10);
1363-
buffer_write(buffer, buffer_string, strict_compress(ds_list_write(dmap)));
1364-
buffer_write(buffer, buffer_u8, clientID);
1365-
var bufferSize = buffer_tell(buffer);
1366-
buffer_seek(buffer, buffer_seek_start, 0);
1367-
buffer_write(buffer, buffer_s32, bufferSize);
1368-
buffer_write(buffer, buffer_u8, 10);
1369-
buffer_write(buffer, buffer_string, strict_compress(ds_list_write(dmap)));
1370-
buffer_write(buffer, buffer_u8, clientID);
1371-
for(var i=0; i&lt;sockets; i++){
1372-
network_send_packet(playerList[| i], buffer, buffer_tell(buffer));
1373-
}
1374-
ds_list_destroy(dmap);
13751382

1376-
if(alarm[5] &lt; 360 &amp;&amp; alarm[5] &gt; 1){
1377-
alarm[5] += 360;
1383+
if(alarm[5] &lt; 300 &amp;&amp; alarm[5] &gt; 1){
1384+
alarm[5] += 120;
13781385
show_debug_message("dmap alarm incremented");
13791386
}
13801387
break;
@@ -1691,9 +1698,9 @@ switch(type_event){
16911698
<arguments>
16921699
<argument>
16931700
<kind>1</kind>
1694-
<string>if(file_exists(working_directory + "\save.txt")){
1701+
<string>if(file_exists(working_directory + global.saveString)){
16951702
var list = ds_list_create();
1696-
file = file_text_open_read(working_directory + "\save.txt");
1703+
file = file_text_open_read(working_directory + global.saveString);
16971704
ds_list_read(list, file_text_read_string(file));
16981705
file_text_close(file);
16991706
global.metdead = list[| 0];
@@ -1734,10 +1741,10 @@ list[| 1] = global.event;
17341741
list[| 2] = global.item;
17351742
list[| 3] = global.dmap;
17361743
list[| 4] = global.monstersleft;
1737-
if(file_exists(working_directory + "\save.txt")){
1738-
file_delete(working_directory + "\save.txt");
1744+
if(file_exists(working_directory + global.saveString)){
1745+
file_delete(working_directory + global.saveString);
17391746
}
1740-
file = file_text_open_write(working_directory + "\save.txt");
1747+
file = file_text_open_write(working_directory + global.saveString);
17411748
file_text_write_string(file, ds_list_write(list));
17421749
file_text_close(file);
17431750
ds_list_destroy(list);

objects/oSlot.object.gmx

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<!--This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!-->
2+
<object>
3+
<spriteName>sSlot</spriteName>
4+
<solid>0</solid>
5+
<visible>-1</visible>
6+
<depth>0</depth>
7+
<persistent>0</persistent>
8+
<parentName>&lt;undefined&gt;</parentName>
9+
<maskName>&lt;undefined&gt;</maskName>
10+
<events>
11+
<event eventtype="0" enumb="0">
12+
<action>
13+
<libid>1</libid>
14+
<id>603</id>
15+
<kind>7</kind>
16+
<userelative>0</userelative>
17+
<isquestion>0</isquestion>
18+
<useapplyto>-1</useapplyto>
19+
<exetype>2</exetype>
20+
<functionname></functionname>
21+
<codestring></codestring>
22+
<whoName>self</whoName>
23+
<relative>0</relative>
24+
<isnot>0</isnot>
25+
<arguments>
26+
<argument>
27+
<kind>1</kind>
28+
<string>global.slot = 1;
29+
</string>
30+
</argument>
31+
</arguments>
32+
</action>
33+
</event>
34+
<event eventtype="6" enumb="4">
35+
<action>
36+
<libid>1</libid>
37+
<id>603</id>
38+
<kind>7</kind>
39+
<userelative>0</userelative>
40+
<isquestion>0</isquestion>
41+
<useapplyto>-1</useapplyto>
42+
<exetype>2</exetype>
43+
<functionname></functionname>
44+
<codestring></codestring>
45+
<whoName>self</whoName>
46+
<relative>0</relative>
47+
<isnot>0</isnot>
48+
<arguments>
49+
<argument>
50+
<kind>1</kind>
51+
<string>if(oLoad.alarm[0] &lt; 0 &amp;&amp; oSave.alarm[0] &lt; 0){
52+
global.slot++;
53+
54+
if(global.slot &gt; 3){
55+
global.slot = 1;
56+
}
57+
58+
var slotStr = string(global.slot);
59+
60+
global.saveString = "\save" + slotStr + ".txt";
61+
}
62+
</string>
63+
</argument>
64+
</arguments>
65+
</action>
66+
</event>
67+
<event eventtype="8" enumb="0">
68+
<action>
69+
<libid>1</libid>
70+
<id>603</id>
71+
<kind>7</kind>
72+
<userelative>0</userelative>
73+
<isquestion>0</isquestion>
74+
<useapplyto>-1</useapplyto>
75+
<exetype>2</exetype>
76+
<functionname></functionname>
77+
<codestring></codestring>
78+
<whoName>self</whoName>
79+
<relative>0</relative>
80+
<isnot>0</isnot>
81+
<arguments>
82+
<argument>
83+
<kind>1</kind>
84+
<string>draw_self();
85+
86+
draw_set_halign(fa_center);
87+
draw_text(x + 1, y - 18, string(global.slot));
88+
draw_set_halign(fa_right);
89+
draw_text(x - 24, y - 18, "Save Slot: ");
90+
draw_set_halign(fa_left);
91+
</string>
92+
</argument>
93+
</arguments>
94+
</action>
95+
</event>
96+
</events>
97+
<PhysicsObject>0</PhysicsObject>
98+
<PhysicsObjectSensor>0</PhysicsObjectSensor>
99+
<PhysicsObjectShape>0</PhysicsObjectShape>
100+
<PhysicsObjectDensity>0.5</PhysicsObjectDensity>
101+
<PhysicsObjectRestitution>0.100000001490116</PhysicsObjectRestitution>
102+
<PhysicsObjectGroup>0</PhysicsObjectGroup>
103+
<PhysicsObjectLinearDamping>0.100000001490116</PhysicsObjectLinearDamping>
104+
<PhysicsObjectAngularDamping>0.100000001490116</PhysicsObjectAngularDamping>
105+
<PhysicsObjectFriction>0.200000002980232</PhysicsObjectFriction>
106+
<PhysicsObjectAwake>-1</PhysicsObjectAwake>
107+
<PhysicsObjectKinematic>0</PhysicsObjectKinematic>
108+
<PhysicsShapePoints/>
109+
</object>

rooms/room0.room.gmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ for(var i = 0; i &lt; p_num; i += 1){
6666
<instance objName="oSave" x="864" y="224" name="inst_09F9BCBB" locked="0" code="" scaleX="1" scaleY="1" colour="4294967295" rotation="0"/>
6767
<instance objName="oLoad" x="864" y="288" name="inst_32B28128" locked="0" code="" scaleX="1" scaleY="1" colour="4294967295" rotation="0"/>
6868
<instance objName="oClients" x="864" y="96" name="inst_F4D6DEE6" locked="0" code="" scaleX="1" scaleY="1" colour="4294967295" rotation="0"/>
69+
<instance objName="oSlot" x="988" y="368" name="inst_D80C554D" locked="0" code="" scaleX="1" scaleY="1" colour="4294967295" rotation="0"/>
6970
</instances>
7071
<tiles/>
7172
<PhysicsWorld>0</PhysicsWorld>

sprites/images/sSlot_0.png

106 Bytes
Loading

sprites/sSlot.sprite.gmx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!-->
2+
<sprite>
3+
<type>0</type>
4+
<xorig>16</xorig>
5+
<yorigin>16</yorigin>
6+
<colkind>1</colkind>
7+
<coltolerance>0</coltolerance>
8+
<sepmasks>0</sepmasks>
9+
<bboxmode>0</bboxmode>
10+
<bbox_left>0</bbox_left>
11+
<bbox_right>31</bbox_right>
12+
<bbox_top>0</bbox_top>
13+
<bbox_bottom>31</bbox_bottom>
14+
<HTile>0</HTile>
15+
<VTile>0</VTile>
16+
<TextureGroups>
17+
<TextureGroup0>0</TextureGroup0>
18+
</TextureGroups>
19+
<For3D>0</For3D>
20+
<width>32</width>
21+
<height>32</height>
22+
<frames>
23+
<frame index="0">images\sSlot_0.png</frame>
24+
</frames>
25+
</sprite>

0 commit comments

Comments
 (0)