mapeditscripts.cfg 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. // opt/mapeditscripts
  2. // fringe mapediting scripts
  3. echo "\f0Extra map editing scripts:"
  4. // list entity-sparklies with identical positions
  5. echo "\fs\f2doublesparklies [enttype]\fr\t\tlist entity-sparklies with identical positions"
  6. tempalias doublesparklies [
  7. if $editing [
  8. push eee $arg1
  9. if (! (strlen $eee)) [ eee = (listoptions ents) ]
  10. echo list entity sparklies with identical x, y and z coordinates "(" $eee ")"
  11. looplist $eee ot [
  12. looplist (enumentities $ot) oi [
  13. push oee (editentity $oi)
  14. push oex (at $oee 1)
  15. looplist $eee it [
  16. looplist (enumentities $it) ii [
  17. if (&& (< $ii $oi) (= $oex (at (editentity $ii) 1))) [
  18. push iee (editentity $ii)
  19. if (&& (= (at $iee 2) (at $oee 2)) (= (at $iee 3) (at $oee 3))) [
  20. echo $ii : $iee --- $oi : $oee
  21. ]
  22. pop iee
  23. ]
  24. ]
  25. ]
  26. pop oee oex
  27. ]
  28. ]
  29. pop eee
  30. ][
  31. echo edit mode required
  32. ]
  33. ]
  34. // list identical models on the same position
  35. echo "\fs\f2doublemodels\fr\t\tlist identical models on the same position"
  36. tempalias doublemodels [
  37. if $editing [
  38. push res 0
  39. echo "list doubled mapmodels (same position, model and elevation)"
  40. looplist (enumentities mapmodel) oi [
  41. push oee (editentity $oi)
  42. push oex (at $oee 1)
  43. looplist (enumentities mapmodel) ii [
  44. if (&& (< $ii $oi) (= $oex (at (editentity $ii) 1))) [
  45. push iee (editentity $ii)
  46. if (&& (= (at $iee 2) (at $oee 2)) (&& (strcmp (mapmodelslotname (at $iee 5)) (mapmodelslotname (at $oee 5))) (= (at $iee 6) (at $oee 6)))) [
  47. echo $ii : $iee --- $oi : $oee
  48. addtodoentity $oi (concat double model $ii : $iee --- $oi : $oee)
  49. += res 1
  50. ]
  51. pop iee
  52. ]
  53. ]
  54. pop oee oex
  55. ]
  56. if $res [ showmenu "TODO entities" ]
  57. result (pop res)
  58. ][
  59. echo edit mode required
  60. ]
  61. ]
  62. // get cube info of a certain cube
  63. // getcubedata x y attr
  64. // (loses current selection)
  65. tempalias getcubedata [
  66. select $arg1 $arg2 1 1
  67. push res (concatword sw_ $arg3)
  68. selectionwalk [res = $$res]
  69. resetselections
  70. result (pop res)
  71. ]
  72. // adjust mapmodel sparklie positions to a fixed offset over ground + mapmodel elevation + modelslot elevation
  73. // mm_z slot z-offset
  74. echo "\fs\f2mm_z slot z-offset\fr\tadjust mapmodel sparklie positions to a fixed offset over ground + mapmodel elevation + modelslot elevation"
  75. tempalias mm_z [
  76. if $editing_sp [
  77. push es (editmapmodelslot $arg1)
  78. echo set z-coordinate of the entity sparklies of all mapmodels of slot # (escape $arg1) to floor + elevation + (at $es 2) + (escape $arg2)
  79. if (strlen $arg1) [
  80. looplist (enumentities mapmodel) i [
  81. push ee (editentity $i)
  82. if (= $arg1 (at $ee 5)) [
  83. push nh (+ (getcubedata (at $ee 1) (at $ee 2) floor) (at $ee 6) $arg2 (at $es 2))
  84. if (strlen $arg2) [editentity $i "" "" $nh]
  85. echo $ee -> (pop nh) -> (editentity $i)
  86. ]
  87. pop ee
  88. ]
  89. ][
  90. echo usage: mm_z mmslotnumber heightoffset
  91. ]
  92. pop es
  93. ][
  94. echo offline edit mode required
  95. ]
  96. ]
  97. // adjust clipent sparklie positions to the middle of the clip
  98. // clip_z
  99. echo "\fs\f2clip_z\fr\t\t\tadjust clipent sparklie positions to the middle of the clip"
  100. tempalias clip_z [
  101. if $editing_sp [
  102. echo set z-coordinate of the entity sparklies of all clip and plclip to the middle of the clips
  103. looplist (concat (enumentities clip) (enumentities plclip)) i [
  104. push ee (editentity $i)
  105. push nh (+ (getcubedata (at $ee 1) (at $ee 2) floor) (at $ee 4) (div (at $ee 7) 2))
  106. editentity $i "" "" $nh
  107. echo clip_z: $ee -> (pop nh) -> (editentity $i)
  108. pop ee
  109. ]
  110. ][
  111. echo offline edit mode required
  112. ]
  113. ]
  114. // duplicate all clipped model slots with an unclipped version - then sort the slots
  115. // (after running this, reducing the slot number of any clipped mapmodel by one will remove the clip)
  116. // doubleclippedslots
  117. echo "\fs\f2duplicateclippedslots\fr\t\tduplicate all clipped model slots with an unclipped version, then sort the slots"
  118. tempalias duplicateclippedslots [
  119. if $editing_sp [
  120. echo double all clipped model slots with an unclipped version, then sort the slots
  121. loop i 256 [
  122. push info (editmapmodelslot $i)
  123. if (|| (at $info 0) (at $info 1)) [
  124. mapmodel 0 0 (at $info 2) (at $info 3) (at $info 4)
  125. ]
  126. pop info
  127. ]
  128. sortmapmodelslots
  129. echo "\f4When done, use duplicateclippedslots_cleanup."
  130. ][
  131. echo offline edit mode required
  132. ]
  133. ]
  134. // clean up after using doubleclippedslots: sort&merge mapmodel slots, then delete all unused mapmodel slots
  135. // doubleclippedslots_cleanup
  136. echo "\fs\f2duplicateclippedslots_cleanup\fr\tremove all unnecessary mapmodel slots"
  137. tempalias duplicateclippedslots_cleanup [
  138. if $editing_sp [
  139. sortmapmodelslots mergeused
  140. loop ii 256 [ push i (- 255 $ii) ; if (&& (strlen (mapmodelslotname $i)) (strcmp "" (mapmodelslotusage $i))) [deletemapmodelslot $i] ; pop i]
  141. echo all unnecessary mapmodel slots removed
  142. ][
  143. echo offline edit mode required
  144. ]
  145. ]
  146. tempalias dryrun 0
  147. // un-clip models that are fully in tagclipped areas
  148. // uncliptagclippedmodels
  149. echo "\fs\f2uncliptagclippedmodels\fr\tun-clip models that are fully in tagclipped areas"
  150. tempalias uncliptagclippedmodels [
  151. if $editing_sp [
  152. push res 0
  153. looplist (enumentities mapmodel) i [
  154. push entinfo (editentity $i)
  155. push slotinfo (editmapmodelslot (at $entinfo 5))
  156. if (|| (at $slotinfo 0) (at $slotinfo 1)) [
  157. push radius (at $slotinfo 0)
  158. if (= $radius 0) [ radius = 1 ] // FIXME
  159. select (- (at $entinfo 1) $radius) (- (at $entinfo 2) $radius) (* $radius 2) (* $radius 2)
  160. push unclipped 0
  161. selectionwalk [ if (&& (! (&b 0x40 $sw_tag)) $sw_type) [ += unclipped 1 ] ]
  162. if (&& (! (at $slotinfo 0)) (< $unclipped 4)) [ unclipped = 0 ] // radius 0 is fine, if there is at least 1 tagclip
  163. if (! $unclipped) [
  164. if $dryrun [
  165. addtodoentity $i (concat $slotinfo can be unclipped by uncliptagclippedmodels)
  166. ][
  167. push uinfo (concat 0 0 (at $slotinfo 2) (at $slotinfo 3) (escape (at $slotinfo 4)))
  168. loop j 256 [
  169. if (strcmp (editmapmodelslot $j) $uinfo) [
  170. addtodoentity $i (concatword "changed from mapmodel slot #" (at $entinfo 5) " to slot #" $j)
  171. editentity $i "" "" "" "" $j
  172. unclipped = -1
  173. break
  174. ]
  175. ]
  176. if (! $unclipped) [
  177. editentity $i "" "" "" "" (mapmodel 0 0 (at $slotinfo 2) (at $slotinfo 3) (at $slotinfo 4))
  178. addtodoentity $i (concatword "changed from mapmodel slot #" (at $entinfo 5) " to newly created slot #" (at (editentity $i) 5))
  179. ]
  180. pop uinfo
  181. ]
  182. += res 1
  183. ]
  184. pop unclipped radius
  185. ]
  186. pop entinfo slotinfo
  187. ]
  188. resetselections
  189. echo un-clipped $res mapmodel entities
  190. pop res
  191. ][
  192. echo offline edit mode required
  193. ]
  194. ]
  195. // un-clip models that are fully clipped by a clip entity
  196. // unclipentclippedmodels
  197. echo "\fs\f2unclipentclippedmodels\fr\tun-clip models that are fully clipped by a clip entity"
  198. tempalias unclipentclippedmodels [
  199. if $editing_sp [
  200. push res 0
  201. looplist (enumentities mapmodel) i [
  202. push entinfo (editentity $i)
  203. push slotinfo (editmapmodelslot (at $entinfo 5))
  204. if (|| (at $slotinfo 0) (at $slotinfo 1)) [
  205. push radius (at $slotinfo 0) // model clip radius
  206. push bot (+f (getcubedata (at $entinfo 1) (at $entinfo 2) floor) (at $entinfo 6) (at $slotinfo 2)) // model clip bottom, float
  207. push h (at $slotinfo 1) // model clip height
  208. looplist (enumentities clip) ci [
  209. push clipinfo (editentity $ci)
  210. if (&& (! (at $clipinfo 10)) (at $clipinfo 7)) [ // skip non-zero shapes
  211. push cibot (+f (getcubedata (at $clipinfo 1) (at $clipinfo 2) floor) (at $clipinfo 4)) // clip bottom, float
  212. push cih (at $clipinfo 7) // clip height, float
  213. push clipped (&& (<=f $cibot $bot) (>= (+f $cibot $cih) (+f $bot $h))) // check height range
  214. *= clipped (&& (<= (- (at $clipinfo 1) (at $clipinfo 5)) (- (at $entinfo 1) $radius)) (>= (+ (at $clipinfo 1) (at $clipinfo 5)) (+ (at $entinfo 1) $radius))) // check x range
  215. *= clipped (&& (<= (- (at $clipinfo 2) (at $clipinfo 6)) (- (at $entinfo 2) $radius)) (>= (+ (at $clipinfo 2) (at $clipinfo 6)) (+ (at $entinfo 2) $radius))) // check y range
  216. if $clipped [
  217. if $dryrun [
  218. addtodoentity $i (concat $slotinfo can be unclipped by unclipentclippedmodels)
  219. ][
  220. push uinfo (concat 0 0 (at $slotinfo 2) (at $slotinfo 3) (escape (at $slotinfo 4)))
  221. loop j 256 [
  222. if (strcmp (editmapmodelslot $j) $uinfo) [
  223. addtodoentity $i (concatword "changed from mapmodel slot #" (at $entinfo 5) " to slot #" $j)
  224. editentity $i "" "" "" "" $j
  225. clipped = 0
  226. break
  227. ]
  228. ]
  229. if $clipped [
  230. editentity $i "" "" "" "" (mapmodel 0 0 (at $slotinfo 2) (at $slotinfo 3) (at $slotinfo 4))
  231. addtodoentity $i (concatword "changed from mapmodel slot #" (at $entinfo 5) " to newly created slot #" (at (editentity $i) 5))
  232. ]
  233. pop uinfo
  234. ]
  235. += res 1
  236. h = 0 // exit clipent loop
  237. ]
  238. pop clipped cih cibot
  239. ]
  240. pop clipinfo
  241. if (! $h) break
  242. ]
  243. pop h bot radius
  244. ]
  245. pop entinfo slotinfo
  246. ]
  247. resetselections
  248. echo un-clipped $res mapmodel entities
  249. pop res
  250. ][
  251. echo offline edit mode required
  252. ]
  253. ]
  254. // find middle cube in selection
  255. // selectmiddle
  256. echo "\fs\f2selectmiddle\fr\tfind middle cube in selection"
  257. tempalias selectmiddle [
  258. if $editing [
  259. push res resetselections
  260. selectionwalk [] [
  261. looplist $sw_cursel [x y xs ys] [
  262. res = (concat $res ";" addselection (+ $x (div $xs 2)) (+ $y (div $ys 2)) 1 1)
  263. ]
  264. ]
  265. echo reduced (listlen (selx)) selections to the middle cube
  266. res
  267. pop res
  268. ][
  269. echo edit mode required
  270. ]
  271. ]