function readint:integer; var b:integer; begin b:=b or (read_uns_byte<<24); b:=b or (read_uns_byte<<16); b:=b or (read_uns_byte<<8); b:=b or (read_uns_byte); readint:=b; end; procedure writeint(intt:integer); begin write_byte((intt>>24) and $FF); write_byte((intt>>16) and $FF); write_byte((intt>>8) and $FF); write_byte((intt) and $FF); end; procedure writebool(bo:boolean); begin if bo=true then write_byte(1); else write_byte(0); end; function readbool:boolean; begin if read_byte>0 then readbool:=true; else readbool:=false; end; procedure savegame; var ix,iy:integer; begin if file_exists('/'+sd+'/world.sav')<>1 then file_create('/'+sd+'/world.sav'); if open_file('/'+sd+'/world.sav')=1 then begin //Head write_byte(version_map); write_byte(gamemode); write_byte(seed); //Player writeint(x); writeint(y); write_byte(velx); write_byte(vely); write_byte(min_vely); write_byte(invslot); write_byte(posi); write_byte(r_ani); write_byte(n_ani); write_byte(hp); write_byte(acc); writebool(jmp); writebool(fall); writebool(an_pr); for ix:=0 to 35 do begin write_byte(inv[ix].item_i); write_byte(inv[ix].sum_i); end; //Matrix for ix:=0 to 255 do for iy:=0 to 127 do begin write_byte(map[ix,iy]); write_byte(i_map[ix,iy]); write_byte(l_map[ix,iy]); end; //Background and biomes for ix:=0 to 255 do begin write_byte(back_map[ix]); write_byte(biom_map[ix]); end; //Chests for ix:=0 to 31 do for iy:=0 to 26 do begin write_byte(chest[ix,iy].item_i); write_byte(chest[ix,iy].sum_i); end; //Mobs for ix:=0 to 31 do begin write_byte(mob[ix].m_type); writeint(mob[ix].m_x); writeint(mob[ix].m_y); write_byte(mob[ix].m_posi); write_byte(mob[ix].m_velx); write_byte(mob[ix].m_vely); write_byte(mob[ix].m_ani); write_byte(mob[ix].m_min_vely); writeint(mob[ix].m_hp); write_byte(mob[ix].m_del); writebool(mob[ix].m_fall); writebool(mob[ix].m_jmp); end; write_byte(zomb_anim_del); //Drop for ix:=0 to 255 do begin write_byte(drop[ix].item_d); writeint(drop[ix].x_d); writeint(drop[ix].y_d); write_byte(drop[ix].vel_d); end; //Particles for ix:=0 to 255 do begin write_byte(particles[ix].typ_p); write_byte(particles[ix].ani_p); writeint(particles[ix].x_p); writeint(particles[ix].y_p); end; write_byte(gb_up_pa); //Other write_byte(updx); write_byte(updy); writebool(osadki); write_byte(osadki_ani); /////////////////////// flush; if close_file('/'+sd+'/world.sav')=1 then debug('OK'); end; end; procedure loadgame; var ix,iy:integer; begin if file_exists('/'+sd+'/world.sav')=1 then if open_file('/'+sd+'/world.sav')=1 then begin //Head if read_byte<>version_map then halt; gamemode:=read_byte; seed:=read_byte; //Player x:=readint; y:=readint; velx:=read_byte; vely:=read_byte; min_vely:=read_byte; invslot:=read_byte; posi:=read_byte; r_ani:=read_byte; n_ani:=read_byte; hp:=read_byte; acc:=read_byte; jmp:=readbool; fall:=readbool; an_pr:=readbool; for ix:=0 to 35 do begin inv[ix].item_i:=read_byte; inv[ix].sum_i:=read_byte; end; //Matrix for ix:=0 to 255 do for iy:=0 to 127 do begin map[ix,iy]:=read_byte; i_map[ix,iy]:=read_byte; l_map[ix,iy]:=read_byte; end; //Background and biomes for ix:=0 to 255 do begin back_map[ix]:=read_byte; biom_map[ix]:=read_byte; end; //Chests for ix:=0 to 31 do for iy:=0 to 26 do begin chest[ix,iy].item_i:=read_byte; chest[ix,iy].sum_i:=read_byte; end; //Mobs for ix:=0 to 31 do begin mob[ix].m_type:=read_byte; mob[ix].m_x:=readint; mob[ix].m_y:=readint; mob[ix].m_posi:=read_byte; mob[ix].m_velx:=read_byte; mob[ix].m_vely:=read_byte; mob[ix].m_ani:=read_byte; mob[ix].m_min_vely:=read_byte; mob[ix].m_hp:=readint; mob[ix].m_del:=read_byte; mob[ix].m_fall:=readbool; mob[ix].m_jmp:=readbool; end; zomb_anim_del:=read_byte; //Drop for ix:=0 to 255 do begin drop[ix].item_d:=read_byte; drop[ix].x_d:=readint; drop[ix].y_d:=readint; drop[ix].vel_d:=read_byte; end; //Particles for ix:=0 to 255 do begin particles[ix].typ_p:=read_byte; particles[ix].ani_p:=read_byte; particles[ix].x_p:=readint; particles[ix].y_p:=readint; end; gb_up_pa:=read_byte; //Other updx:=read_byte; updy:=read_byte; osadki:=readbool; osadki_ani:=read_byte; /////////////////////// if close_file('/'+sd+'/world.sav')=1 then debug('OK'); end; end;