MCPcopy Create free account
hub / github.com/assaultcube/AC / load_world

Function load_world

source/src/worldio.cpp:927–1170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

925bool incompatiblemap = false;
926
927int load_world(char *mname) // still supports all map formats that have existed since the earliest cube betas!
928{
929 incompatiblemap = false;
930 const int sizeof_header = sizeof(header), sizeof_baseheader = sizeof_header - sizeof(int) * 16;
931 stopwatch watch;
932 watch.start();
933
934 advancemaprevision = 1;
935 setnames(mname);
936 maploaded = getfilesize(ocgzname);
937 if(maploaded > 0)
938 {
939 copystring(cgzname, ocgzname);
940 copystring(mcfname, omcfname);
941 }
942 else maploaded = getfilesize(cgzname);
943 if(!validmapname(mname))
944 {
945 conoutf("\f3Invalid map name. It must only contain letters, digits, '-', '_' and be less than %d characters long", MAXMAPNAMELEN);
946 return -1;
947 }
948 stream *f = opengzfile(cgzname, "rb");
949 if(!f) { conoutf("\f3could not read map %s", cgzname); return -2; }
950 if(unsavededits) xmapbackup("load_map_", mname);
951 unsavededits = 0;
952 DEBUG("reading map \"" << cgzname << "\"");
953 header tmp;
954 memset(&tmp, 0, sizeof_header);
955 if(f->read(&tmp, sizeof_baseheader) != sizeof_baseheader ||
956 (strncmp(tmp.head, "CUBE", 4)!=0 && strncmp(tmp.head, "ACMP",4)!=0)) { conoutf("\f3while reading map: header malformatted (1)"); delete f; return -3; }
957 lilswap(&tmp.version, 4); // version, headersize, sfactor, numents
958 if(tmp.version > MAPVERSION) { conoutf("\f3this map requires a newer version of AssaultCube"); delete f; return -4; }
959 if(tmp.sfactor<SMALLEST_FACTOR || tmp.sfactor>LARGEST_FACTOR || tmp.numents > MAXENTITIES) { conoutf("\f3illegal map size"); delete f; return -5; }
960 tmp.headersize = fixmapheadersize(tmp.version, tmp.headersize);
961 int restofhead = min(tmp.headersize, sizeof_header) - sizeof_baseheader;
962 if(f->read(&tmp.waterlevel, restofhead) != restofhead) { conoutf("\f3while reading map: header malformatted (2)"); delete f; return -6; }
963 DEBUG("version " << tmp.version << " headersize " << tmp.headersize << " headerextrasize " << tmp.headersize - int(sizeof(header)) << " entities " << tmp.numents << " factor " << tmp.sfactor << " revision " << tmp.maprevision);
964 clearheaderextras();
965 if(tmp.headersize > sizeof_header)
966 {
967 int extrasize = tmp.headersize - sizeof_header;
968 if(tmp.version < 9) extrasize = 0; // throw away mediareq...
969 else if(extrasize > MAXHEADEREXTRA) extrasize = MAXHEADEREXTRA;
970 if(extrasize)
971 { // map file actually has extra header data that we want too preserve
972 uchar *extrabuf = new uchar[extrasize];
973 if(f->read(extrabuf, extrasize) != extrasize) { conoutf("\f3while reading map: header malformatted (3)"); delete f; delete[] extrabuf; return -7; }
974 unpackheaderextra(extrabuf, extrasize);
975 delete[] extrabuf;
976 }
977 f->seek(tmp.headersize, SEEK_SET);
978 }
979 hdr = tmp;
980 mapconfigdata.clear();
981 rebuildtexlists();
982 loadingscreen("%s", hdr.maptitle);
983 resetmap();
984 int res = 0;

Callers 2

changemapservFunction · 0.85
worldio.cppFile · 0.85

Calls 15

setnamesFunction · 0.85
getfilesizeFunction · 0.85
copystringFunction · 0.85
validmapnameFunction · 0.85
opengzfileFunction · 0.85
xmapbackupFunction · 0.85
lilswapFunction · 0.85
fixmapheadersizeFunction · 0.85
minFunction · 0.85
clearheaderextrasFunction · 0.85
unpackheaderextraFunction · 0.85
rebuildtexlistsFunction · 0.85

Tested by

no test coverage detected