|
| 1 | +-- Activate with a cursor on screen and you will go there rapidly, attack something first to send them there. |
| 2 | +-- Based on propel.lua by Roses, molested by Rumrusher and I until this happened, sorry. |
| 3 | +--[[=begin |
| 4 | +
|
| 5 | +launch |
| 6 | +====== |
| 7 | +Activate with a cursor on screen and you will go there rapidly, attack |
| 8 | +something first to send them there. |
| 9 | +
|
| 10 | +=end]] |
| 11 | +function launch(unitSource,unitTarget) |
| 12 | + local curpos |
| 13 | + if df.global.ui_advmode.menu==1 then |
| 14 | + curpos=df.global.cursor |
| 15 | + else |
| 16 | + print ("No cursor located! You would have slammed into the ground and exploded.") --seriously, kasplut! |
| 17 | + return |
| 18 | + end |
| 19 | + |
| 20 | + |
| 21 | + local count=0 |
| 22 | + local l = df.global.world.proj_list |
| 23 | + local lastlist=l |
| 24 | + l=l.next |
| 25 | + while l do |
| 26 | + count=count+1 |
| 27 | + if l.next==nil then |
| 28 | + lastlist=l |
| 29 | + end |
| 30 | + l = l.next |
| 31 | + end |
| 32 | + |
| 33 | + resultx = curpos.x - unitSource.pos.x |
| 34 | + resulty = curpos.y - unitSource.pos.y |
| 35 | + resultz = curpos.z - unitSource.pos.z |
| 36 | + |
| 37 | + |
| 38 | + newlist = df.proj_list_link:new() |
| 39 | + lastlist.next=newlist |
| 40 | + newlist.prev=lastlist |
| 41 | + proj = df.proj_unitst:new() |
| 42 | + newlist.item=proj |
| 43 | + proj.link=newlist |
| 44 | + proj.id=df.global.proj_next_id |
| 45 | + df.global.proj_next_id=df.global.proj_next_id+1 |
| 46 | + proj.unit=unitSource |
| 47 | + proj.origin_pos.x=unitSource.pos.x |
| 48 | + proj.origin_pos.y=unitSource.pos.y |
| 49 | + proj.origin_pos.z=unitSource.pos.z |
| 50 | + proj.target_pos.x=curpos.x |
| 51 | + proj.target_pos.y=curpos.y |
| 52 | + proj.target_pos.z=curpos.z |
| 53 | + proj.prev_pos.x=unitSource.pos.x |
| 54 | + proj.prev_pos.y=unitSource.pos.y |
| 55 | + proj.prev_pos.z=unitSource.pos.z |
| 56 | + proj.cur_pos.x=unitSource.pos.x |
| 57 | + proj.cur_pos.y=unitSource.pos.y |
| 58 | + proj.cur_pos.z=unitSource.pos.z |
| 59 | + proj.flags.no_impact_destroy=true |
| 60 | + proj.flags.piercing=true |
| 61 | + proj.flags.high_flying=true --this probably doesn't do anything, let me know if you figure out what it is |
| 62 | + proj.flags.parabolic=true |
| 63 | + proj.flags.no_collide=true |
| 64 | + proj.flags.unk9=true |
| 65 | + proj.speed_x=resultx*10000 |
| 66 | + proj.speed_y=resulty*10000 |
| 67 | + proj.speed_z=resultz*12500 --higher z speed makes it easier to reach a target safely |
| 68 | + if df.global.world.units.active[0].job.hunt_target==nil then |
| 69 | + proj.flags[12]=true |
| 70 | + elseif df.global.world.units.active[0].job.hunt_target then |
| 71 | + proj.flags[12]=false |
| 72 | + end |
| 73 | + unitoccupancy = dfhack.maps.ensureTileBlock(unitSource.pos).occupancy[unitSource.pos.x%16][unitSource.pos.y%16] |
| 74 | + if not unitSource.flags1.on_ground then |
| 75 | + unitoccupancy.unit = false |
| 76 | + else |
| 77 | + unitoccupancy.unit_grounded = false |
| 78 | + end |
| 79 | + unitSource.flags1.projectile=true |
| 80 | + unitSource.flags1.on_ground=false |
| 81 | +end |
| 82 | + |
| 83 | +unitTarget = curpos |
| 84 | +if df.global.world.units.active[0].job.hunt_target==nil then |
| 85 | + unitSource = df.global.world.units.active[0] |
| 86 | +else |
| 87 | + unitSource = df.global.world.units.active[0].job.hunt_target --kudos Rumrusher for including this, allowing you to fling others around! |
| 88 | +end |
| 89 | + |
| 90 | +launch(unitSource,unitTarget) |
0 commit comments