| 1330 | COMMAND(selectionflip, "s"); |
| 1331 | |
| 1332 | void selectionwalk(char *action, char *beginsel, char *endsel) |
| 1333 | { |
| 1334 | EDITSEL("selectionwalk"); |
| 1335 | bool mp = multiplayer(NULL); |
| 1336 | const char *localvars[] = { "sw_cursel", "sw_abs_x", "sw_abs_y", "sw_rel_x", "sw_rel_y", "sw_type", "sw_floor", "sw_ceil", "sw_wtex", "sw_ftex", "sw_ctex", "sw_utex", "sw_vdelta", "sw_tag", "sw_r", "sw_g", "sw_b", "" }; |
| 1337 | for(int i = 0; *localvars[i]; i++) push(localvars[i], ""); |
| 1338 | int maxsels = sels.length(); |
| 1339 | loopv(sels) |
| 1340 | { |
| 1341 | if(i >= maxsels) break; // don't allow the script to add selections |
| 1342 | block sel = sels[i]; // (copy, not reference) |
| 1343 | defformatstring(tmp)("%d %d %d %d", sel.x, sel.y, sel.xs, sel.ys); |
| 1344 | alias("sw_cursel", tmp); |
| 1345 | if(*beginsel) execute(beginsel); |
| 1346 | bool haveundo = false, isro = mp && sel.xs * sel.ys > MAXNETBLOCKSQR, didwarn = false; |
| 1347 | loop(x, sel.xs) loop(y, sel.ys) |
| 1348 | { |
| 1349 | sqr *s = S(sel.x + x, sel.y + y), so = *s; |
| 1350 | formatstring(tmp)("%d", sel.x + x); alias("sw_abs_x", tmp); |
| 1351 | formatstring(tmp)("%d", sel.y + y); alias("sw_abs_y", tmp); |
| 1352 | formatstring(tmp)("%d", x); alias("sw_rel_x", tmp); |
| 1353 | formatstring(tmp)("%d", y); alias("sw_rel_y", tmp); |
| 1354 | #define AATTR(x) formatstring(tmp)("%d", s->x); alias("sw_"#x, tmp) |
| 1355 | AATTR(type); AATTR(floor); AATTR(ceil); AATTR(wtex); AATTR(ftex); AATTR(ctex); AATTR(utex); AATTR(vdelta); AATTR(tag); AATTR(r); AATTR(g); AATTR(b); |
| 1356 | #undef AATTR |
| 1357 | if(*action) execute(action); |
| 1358 | so.type = getlistindex(getalias("sw_type"), cubetypenames, true, int(SPACE)); |
| 1359 | #define GETA(x) so.x = ATOI(getalias("sw_"#x)) |
| 1360 | GETA(floor); GETA(ceil); GETA(wtex); GETA(ftex); GETA(ctex); GETA(utex); GETA(vdelta); GETA(tag); GETA(r); GETA(g); GETA(b); |
| 1361 | #undef GETA |
| 1362 | if(memcmp(s, &so, sizeof(sqr))) |
| 1363 | { |
| 1364 | if(isro) |
| 1365 | { |
| 1366 | if(!didwarn) conoutf("\f3selectionwalk: selected area %dx%d too big for multiplayer editing, changes ignored!", sel.xs, sel.ys); |
| 1367 | didwarn = true; |
| 1368 | } |
| 1369 | else |
| 1370 | { |
| 1371 | if(!haveundo) makeundo(sel); |
| 1372 | haveundo = true; |
| 1373 | *s = so; |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | if(haveundo) |
| 1378 | { |
| 1379 | if(mp) |
| 1380 | { |
| 1381 | block *b = blockcopy(sel); |
| 1382 | netblockpaste(*b, sel.x, sel.y, true); |
| 1383 | freeblockp(b); |
| 1384 | } |
| 1385 | remipgenerous(sel); |
| 1386 | } |
| 1387 | if(*endsel) execute(endsel); |
| 1388 | } |
| 1389 | for(int i = 0; *localvars[i]; i++) pop(localvars[i]); |
nothing calls this directly
no test coverage detected