| 1026 | COMMAND(textureslotusage, "i"); |
| 1027 | |
| 1028 | void deletetextureslot(int *n, char *opt, char *_replace) // delete texture slot - only if unused or "purge" is specified |
| 1029 | { |
| 1030 | EDITMP("deletetextureslot"); |
| 1031 | if(!slots.inrange(*n)) return; |
| 1032 | bool purgeall = !strcmp(opt, "purge"); |
| 1033 | bool mmused = false; |
| 1034 | loopv(ents) if(ents[i].type == MAPMODEL && ents[i].attr4 == *n) mmused = true; |
| 1035 | if(!purgeall && *n <= DEFAULT_CEIL) { conoutf("texture slots below #%d should usually not be deleted", DEFAULT_CEIL + 1); return; } |
| 1036 | if(!purgeall && (mmused || testworldtexusage(*n))) { conoutf("texture slot #%d is in use: can't delete", *n); return; } |
| 1037 | int deld = 0, replace = 256; |
| 1038 | if(purgeall && isdigit(*_replace)) replace = strtol(_replace, NULL, 0) & 255; |
| 1039 | if(replace > *n) replace--; |
| 1040 | sqr *s = world; |
| 1041 | loopirev(cubicsize) |
| 1042 | { // check, if cubes use the texture |
| 1043 | if(s->wtex == *n) { s->wtex = replace; deld++; } |
| 1044 | else if(s->wtex > *n) s->wtex--; |
| 1045 | if(s->ctex == *n) { s->ctex = replace; deld++; } |
| 1046 | else if(s->ctex > *n) s->ctex--; |
| 1047 | if(s->ftex == *n) { s->ftex = replace; deld++; } |
| 1048 | else if(s->ftex > *n) s->ftex--; |
| 1049 | if(s->utex == *n) { s->utex = replace; deld++; } |
| 1050 | else if(s->utex > *n) s->utex--; |
| 1051 | s++; |
| 1052 | } |
| 1053 | block bb = { clmapdims.x1 - 1, clmapdims.y1 - 1, clmapdims.xspan + 2, clmapdims.yspan + 2 }; |
| 1054 | remip(bb); |
| 1055 | loopv(ents) if(ents[i].type == MAPMODEL) |
| 1056 | { // check, if mapmodels use the texture |
| 1057 | entity &e = ents[i]; |
| 1058 | if(e.attr4 == *n) |
| 1059 | { // use default model texture instead |
| 1060 | e.attr4 = 0; |
| 1061 | deld++; |
| 1062 | } |
| 1063 | else if(e.attr4 > *n) e.attr4--; // adjust models in higher slots |
| 1064 | } |
| 1065 | loopk(3) // adjust texlists |
| 1066 | { |
| 1067 | int j = 255; |
| 1068 | loopi(256) |
| 1069 | { |
| 1070 | if(hdr.texlists[k][i] == *n) j = i; |
| 1071 | if(hdr.texlists[k][i] > *n) hdr.texlists[k][i]--; |
| 1072 | } |
| 1073 | if(j < 255) memmove(&hdr.texlists[k][j], &hdr.texlists[k][j + 1], 255 - j); |
| 1074 | hdr.texlists[k][255] = 255; |
| 1075 | } |
| 1076 | slots.remove(*n); |
| 1077 | defformatstring(m)(" (%d uses removed)", deld); |
| 1078 | if(replace != 255) formatstring(m)(" (%d uses changed to use slot #%d)", deld, replace); |
| 1079 | conoutf("texture slot #%d deleted%s", *n, deld ? m : ""); |
| 1080 | unsavededits++; |
| 1081 | hdr.flags |= MHF_AUTOMAPCONFIG; // requires automapcfg |
| 1082 | } |
| 1083 | COMMAND(deletetextureslot, "iss"); |
| 1084 | |
| 1085 | void edittextureslot(int *n, char *scale, char *name) // edit slot parameters != "" |