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

Function empty_world

source/src/world.cpp:695–780  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

693}
694
695bool empty_world(int factor, bool force) // main empty world creation routine, if passed factor -1 will enlarge old world by 1, factor -2 will shrink old world by 1
696{
697 if(!force && noteditmode("empty world")) return false;
698 if(factor < -2) return false;
699 if(factor == -1 && multiplayer() && sfactor > 9) return false;
700 if(factor == -2 && !worldbordercheck(ssize/4 + MINBORD, ssize/4 + MINBORD, ssize/4 + MINBORD, ssize/4 + MINBORD, 0, 0)) { conoutf("map does not fit into smaller world"); return false; }
701 block *ow = NULL, be = { 0, 0, ssize, ssize }, bs = { ssize/4, ssize/4, ssize/2, ssize/2 };
702 int oldfactor = sfactor;
703 bool copy = false;
704 if(world && factor<0) { factor = sfactor + (factor == -2 ? -1 : 1); copy = true; }
705 if(factor<SMALLEST_FACTOR) factor = SMALLEST_FACTOR;
706 if(factor>LARGEST_FACTOR) factor = LARGEST_FACTOR;
707 if(copy && oldfactor == factor) return false;
708 bool shrink = factor < oldfactor;
709 bool clearmap = !copy && world;
710 if(clearmap && unsavededits) { xmapbackup("newmap", ""); unsavededits = 0; }
711 if(copy) ow = blockcopy(shrink ? bs : be);
712
713 DELETEA(world);
714
715 setupworld(factor);
716 loop(x,ssize) loop(y,ssize)
717 {
718 sqrdefault(S(x,y));
719 }
720
721 checkselections(); // assert no selection became invalid
722
723 if(copy)
724 {
725 ow->x = ow->y = shrink ? 0 : ssize/4;
726 blockpaste(*ow);
727 int moveents = shrink ? -ssize/2 : ssize/4;
728 loopv(ents)
729 {
730 ents[i].x += moveents;
731 ents[i].y += moveents;
732 if(OUTBORD(ents[i].x, ents[i].y)) ents[i].type = NOTUSED;
733 }
734 player1->o.x += moveents;
735 player1->o.y += moveents;
736 entinmap(player1);
737 }
738 else
739 { // all-new map
740 int oldunsavededits = unsavededits;
741 memset(&hdr, 0, sizeof(header));
742 mapconfigdata.clear();
743 formatstring(hdr.maptitle)("Untitled Map by %s", player1->name);
744 setfvar("waterlevel", -10000);
745 hdr.waterlevel = waterlevel * WATERLEVELSCALING;
746 setwatercolor();
747 loopk(3) loopi(256) hdr.texlists[k][i] = i;
748 ents.shrink(0);
749 block b = { 8, 8, ssize-16, ssize - 16};
750 edittypexy(SPACE, b);
751 clearheaderextras();
752 unsavededits = oldunsavededits;

Callers 6

mapenlargeFunction · 0.85
mapshrinkFunction · 0.85
newmapFunction · 0.85
changemapservFunction · 0.85
parsemessagesFunction · 0.85
main.cppFile · 0.85

Calls 15

noteditmodeFunction · 0.85
multiplayerFunction · 0.85
worldbordercheckFunction · 0.85
xmapbackupFunction · 0.85
blockcopyFunction · 0.85
setupworldFunction · 0.85
checkselectionsFunction · 0.85
blockpasteFunction · 0.85
entinmapFunction · 0.85
setfvarFunction · 0.85
setwatercolorFunction · 0.85
edittypexyFunction · 0.85

Tested by

no test coverage detected