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

Function restorexmap

source/src/worldio.cpp:1534–1608  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1532} );
1533
1534void restorexmap(char **args, int numargs) // read an xmap from a cubescript file
1535{
1536 const char *cmdnames[] = { "version", "names", "sizes", "header", "world", "headerextra", "ent", "delent", "config", "todoent", "position", "" };
1537 const char cmdnumarg[] = { 3, 2, 3, 0, 0, 1, 11, 11, 1, 2, 5 };
1538
1539 if(!xmjigsaw || numargs < 1) return; // { conoutf("restorexmap out of context"); return; }
1540 bool abort = false;
1541 int cmd = getlistindex(args[0], cmdnames, false, -1);
1542 if(cmd < 0 || numargs != cmdnumarg[cmd] + 1) { conoutf("restorexmap error"); return; }
1543 switch(cmd)
1544 {
1545 case 0: // version
1546 if(ATOI(args[1]) != XMAPVERSION || ATOI(args[2]) != (isbigendian() ? 1 : 0) || ATOI(args[3]) != int(sizeof(world)))
1547 {
1548 conoutf("restorexmap: file is from different game version");
1549 abort = true;
1550 }
1551 break;
1552 case 1: // names
1553 copystring(xmjigsaw->name, args[1]);
1554 copystring(xmjigsaw->mcfname, args[2]);
1555 break;
1556 case 2: // sizes
1557 xmjigsaw->ssize = ATOI(args[1]);
1558 xmjigsaw->cubicsize = ATOI(args[2]);
1559 xmjigsaw->numundo = ATOI(args[3]);
1560 break;
1561 case 3: // header
1562 if(hexbin.length() == sizeof(header)) memcpy(&xmjigsaw->hdr, hexbin.getbuf(), sizeof(header));
1563 else abort = true;
1564 break;
1565 case 4: // world
1566 {
1567 int rawworldsize = xmjigsaw->cubicsize * sizeof(sqr);
1568 xmjigsaw->world = new sqr[rawworldsize];
1569 uLongf rawsize = rawworldsize;
1570 if(uncompress((uchar *)xmjigsaw->world, &rawsize, hexbin.getbuf(), hexbin.length()) != Z_OK || rawsize - rawworldsize != 0) abort = true;
1571 break;
1572 }
1573 case 5: // headerextra
1574 xmjigsaw->headerextras.add(new headerextra(hexbin.length(), ATOI(args[1]), hexbin.getbuf()));
1575 break;
1576 case 6: // ent
1577 case 7: // delent
1578 {
1579 persistent_entity &e = cmd == 6 ? xmjigsaw->ents.add() : xmjigsaw->delents.add();
1580 int a[11];
1581 loopi(11) a[i] = ATOI(args[i + 1]);
1582 e.type = a[0]; e.x = a[1]; e.y = a[2]; e.z = a[3]; e.attr1 = a[4]; e.attr2 = a[5]; e.attr3 = a[6]; e.attr4 = a[7]; e.attr5 = a[8]; e.attr6 = a[9]; e.attr7 = a[10];
1583 break;
1584 }
1585 case 8: // config
1586 cvecprintf(xmjigsaw->mapconfig, "%s\n", args[1]);
1587 break;
1588 case 9: // todoent
1589 xmjigsaw->todoents.add(ATOI(args[1]));
1590 xmjigsaw->todoentdescs.add(newstring(args[2]));
1591 break;

Callers

nothing calls this directly

Calls 14

getlistindexFunction · 0.85
isbigendianFunction · 0.85
copystringFunction · 0.85
cvecprintfFunction · 0.85
newstringFunction · 0.85
getxmapbynickFunction · 0.85
xmapdeleteFunction · 0.85
setsizeMethod · 0.80
conoutfFunction · 0.70
loopiFunction · 0.70
lengthMethod · 0.45
getbufMethod · 0.45

Tested by

no test coverage detected