Ok i have a seeking missile verb, several version of it in fact. Heres version 4 that works:
fire_heat_seeker4()
new/obj/hsmissile(usr.loc)
var/T = 0
for(var/obj/hsmissile/H in usr.loc)
for(var/mob/M in orange(6))
if(M == usr)
del(H)
if(!M)
H.dir = usr.dir
walk(H,H.dir,2)
spawn(20)
del(H)
else
H.dir = usr.dir
walk(H,H.dir,2)
spawn(5)
seek
if(T<=10)//if it hasnt rescanned direction 6 times yet
var/D = get_dir(H,M)//this finds the direction it needs to go to get the M
if(D == NORTH) {if(H.dir == NORTH) ..();if(H.dir == NORTHEAST) H.dir = turn(H.dir, 45);if(H.dir == EAST) H.dir = turn(H.dir, 45);if(H.dir == SOUTHEAST) H.dir = turn(H.dir, 45);if(H.dir == SOUTH) H.dir = turn(H.dir, 45);if(H.dir == SOUTHWEST) H.dir = turn(H.dir, -45);if(H.dir == WEST) H.dir = turn(H.dir, -45);if(H.dir == NORTHWEST)H.dir = turn(H.dir, -45)}
if(D == NORTHEAST) {if(H.dir == NORTH) H.dir = turn(H.dir, -45);if(H.dir == NORTHEAST) ..();if(H.dir == EAST) H.dir = turn(H.dir, 45);if(H.dir == SOUTHEAST) H.dir = turn(H.dir, 45);if(H.dir == SOUTH) H.dir = turn(H.dir, 45);if(H.dir == SOUTHWEST) H.dir = turn(H.dir, 45);if(H.dir == WEST) H.dir = turn(H.dir, -45);if(H.dir == NORTHWEST)H.dir = turn(H.dir, -45)}
if(D == EAST) {if(H.dir == NORTH) H.dir = turn(H.dir, -45);if(H.dir == NORTHEAST) H.dir = turn(H.dir, -45);if(H.dir == EAST) ..();if(H.dir == SOUTHEAST) H.dir = turn(H.dir, 45);if(H.dir == SOUTH) H.dir = turn(H.dir, 45);if(H.dir == SOUTHWEST) H.dir = turn(H.dir, 45);if(H.dir == WEST) H.dir = turn(H.dir, 45);if(H.dir == NORTHWEST)H.dir = turn(H.dir, -45)}
if(D == SOUTHEAST) {if(H.dir == NORTH) H.dir = turn(H.dir, -45);if(H.dir == NORTHEAST) H.dir = turn(H.dir, -45);if(H.dir == EAST) H.dir = turn(H.dir, -45);if(H.dir == SOUTHEAST) ..();if(H.dir == SOUTH) H.dir = turn(H.dir, 45);if(H.dir == SOUTHWEST) H.dir = turn(H.dir, 45);if(H.dir == WEST) H.dir = turn(H.dir, 45);if(H.dir == NORTHWEST)H.dir = turn(H.dir, -45)}
if(D == SOUTH) {if(H.dir == NORTH) H.dir = turn(H.dir, -45);if(H.dir == NORTHEAST) H.dir = turn(H.dir, -45);if(H.dir == EAST) H.dir = turn(H.dir, -45);if(H.dir == SOUTHEAST) H.dir = turn(H.dir, -45);if(H.dir == SOUTH) ..();if(H.dir == SOUTHWEST) H.dir = turn(H.dir, 45);if(H.dir == WEST) H.dir = turn(H.dir, 45);if(H.dir == NORTHWEST)H.dir = turn(H.dir, 45)}
if(D == SOUTHWEST) {if(H.dir == NORTH) H.dir = turn(H.dir, 45);if(H.dir == NORTHEAST) H.dir = turn(H.dir, -45);if(H.dir == EAST) H.dir = turn(H.dir, -45);if(H.dir == SOUTHEAST) H.dir = turn(H.dir, -45);if(H.dir == SOUTH) H.dir = turn(H.dir, -45);if(H.dir == SOUTHWEST) ..();if(H.dir == WEST) H.dir = turn(H.dir, 45);if(H.dir == NORTHWEST)H.dir = turn(H.dir, 45)}
if(D == WEST) {if(H.dir == NORTH) H.dir = turn(H.dir, 45);if(H.dir == NORTHEAST) H.dir = turn(H.dir, 45);if(H.dir == EAST) H.dir = turn(H.dir, -45);if(H.dir == SOUTHEAST) H.dir = turn(H.dir, -45);if(H.dir == SOUTH) H.dir = turn(H.dir, -45);if(H.dir == SOUTHWEST) H.dir = turn(H.dir, -45);if(H.dir == WEST) ..();if(H.dir == NORTHWEST)H.dir = turn(H.dir, 45)}
if(D == NORTHWEST) {if(H.dir == NORTH) H.dir = turn(H.dir, 45);if(H.dir == NORTHEAST) H.dir = turn(H.dir, 45);if(H.dir == EAST) H.dir = turn(H.dir, 45);if(H.dir == SOUTHEAST) H.dir = turn(H.dir, -45);if(H.dir == SOUTH) H.dir = turn(H.dir, -45);if(H.dir == SOUTHWEST) H.dir = turn(H.dir, -45);if(H.dir == WEST) H.dir = turn(H.dir, -45);if(H.dir == NORTHWEST) ..()}
walk(H,H.dir,2)//this makes it go in the direction of D
spawn(5)//waits a half second
T++//adds 1 to T
goto seek//returns to the point 'seek'
else//if it has rescanned direction 6 times or more(for some reason)
del(H)//delete the missile
And heres version 5, I was playing around with variables, and it appears that it should work, but after the missile turns one time it just heads off straight:
fire_heat_seeker5()
new/obj/hsmissile(usr.loc)
var/T = 0
var/N=NORTH;var/NE=NORTHEAST;var/E=EAST;var/ SE=SOUTHEAST;var/S=SOUTH;var/SW=SOUTHWEST;var/W=WEST;var/ NW=NORTHWEST
for(var/obj/hsmissile/H in usr.loc)
for(var/mob/M in orange(6))
if(M == usr)
del(H)
if(!M)
H.dir = usr.dir
walk(H,H.dir,2)
spawn(20)
del(H)
else
H.dir = usr.dir
walk(H,H.dir,2)
var/P = turn(H.dir, 45);var/Q = turn(H.dir, -45)
spawn(5)
seek
if(T<=10)//if it hasnt rescanned direction 6 times yet
var/D = get_dir(H,M)//this finds the direction it needs to go to get the M
if(D==N){if(H.dir==NE)H.dir=P;if(H.dir==E)H.dir=P;if(H.dir== SE)H.dir=P;if(H.dir==S)H.dir=P;if(H.dir==SW)H.dir=Q;if(H.dir ==W)H.dir=Q;if(H.dir==NW)H.dir=Q;if(H.dir==N)..()}
if(D==NE){if(H.dir==N)H.dir=Q;if(H.dir==E)H.dir=P;if(H.dir== SE)H.dir=P;if(H.dir==S)H.dir=P;if(H.dir==SW)H.dir=P;if(H.dir ==W)H.dir=Q;if(H.dir==NW)H.dir=Q;if(H.dir==NE)..()}
if(D==E){if(H.dir==N)H.dir=Q;if(H.dir==NE)H.dir=Q;if(H.dir== SE)H.dir=P;if(H.dir==S)H.dir=P;if(H.dir==SW)H.dir=P;if(H.dir ==W)H.dir=P;if(H.dir==NW)H.dir=Q;if(H.dir==E)..()}
if(D==SE){if(H.dir==N)H.dir=Q;if(H.dir==NE)H.dir=Q;if(H.dir= =E)H.dir=Q;if(H.dir==S)H.dir=P;if(H.dir==SW)H.dir=P;if(H.dir= =W)H.dir=P;if(H.dir==NW)H.dir=Q;if(H.dir==SE)..()}
if(D==S){if(H.dir==N)H.dir=Q;if(H.dir==NE)H.dir=Q;if(H.dir== E)H.dir=Q;if(H.dir==SE)H.dir=Q;if(H.dir==SW)H.dir=P;if(H.dir ==W)H.dir=P;if(H.dir==NW)H.dir=P;if(H.dir==S)..()}
if(D==SW){if(H.dir==N)H.dir=P;if(H.dir==NE)H.dir=Q;if(H.dir= =E)H.dir=Q;if(H.dir==SE)H.dir=Q;if(H.dir==S)H.dir=Q;if(H.dir= =W)H.dir=P;if(H.dir==NW)H.dir=P;if(H.dir==SW)..()}
if(D==W){if(H.dir==N)H.dir=P;if(H.dir==NE)H.dir=P;if(H.dir== E)H.dir=Q;if(H.dir==SE)H.dir=Q;if(H.dir==S)H.dir=Q;if(H.dir= =SW)H.dir=Q;if(H.dir==NW)H.dir=P;if(H.dir==W)..()}
if(D==NW){if(H.dir==N)H.dir=P;if(H.dir==NE)H.dir=P;if(H.dir= =E)H.dir=P;if(H.dir==SE)H.dir=Q;if(H.dir==S)H.dir=Q;if(H.dir= =SW)H.dir=Q;if(H.dir==W)H.dir=Q;if(H.dir==NW)..()}
walk(H,H.dir,2)//this makes it go in the direction of D
spawn(5)//waits a half second
T++//adds 1 to T
goto seek//returns to the point 'seek'
else//if it has rescanned direction 6 times or more(for some reason)
del(H)//delete the missile
Anyone see a difference that would cuase the problem im having/see anything I should change with this?
ID:148562
![]() Dec 30 2002, 10:28 pm
|
|
Lummox JR wrote:
That directional scanning code is intensely freaky; there has to be a better way of doing it than what you're doing with all those ifs. Ive tried for awhile, and this was the only thing I could think of turn make sure it turned in the correct direction I was actually hoping someone would know a better way of doing this already because I agree with you, thats some freaky code. There's also this curious little bit: new/obj/hsmissile(usr.loc) I'll do this. var/obj/hmissile/H = new(usr.loc) Ill do this as well. This code has a few other heinous problems as well: Your use of goto for a simple loop, for example. A while() loop and a continue statement will do the trick, so use those. Never use goto when a regular loop construct will suffice just as well (or better); that's 99.9% of the cases. obj/hmissile Lummox JR Ill see what I can do about that as well. Thanks for the help. I was beginning to wonder if anyone was ever going to help me on this. |
Jotdaniel wrote:
Lummox JR wrote: Mathematically a good way to do it would be with dot products, but I don't consider that all that feasible; I've written up code on that before and it's a witch. Instead, fiddling with bit flags might be good. My understanding is that you basically want to turn right or left toward a target, and choose one direction or the other if the target is directly behind. var/d=get_dir(src,target) Now, take 4, 6, or 2--the directions to the right--and XOR them with 6 (90° right); the result is 2, 0, or 4, each of which has only 1 bit or 0 bits turned on. However, for 8, 9, and 1 (all to the left), the results are 14, 15, and 7, each of which has not two but three bits turned on. If the missile is facing in a cardinal direction, however, then it's easier. If you're facing north, then you turn right only if d is one of the eastward directions (d&EAST!=0), and so on; if d is behind the direction you're facing, then it's directly behind you (which isn't always true of the diagonals--hence the more complicated test) and you can simply pick a direction to turn at random. Lummox JR |
There's also this curious little bit:
This code has a few other heinous problems as well: Your use of goto for a simple loop, for example. A while() loop and a continue statement will do the trick, so use those. Never use goto when a regular loop construct will suffice just as well (or better); that's 99.9% of the cases.
Likewise, it makes no sense to me to put the seek code in the firing proc. Put it in the missile's own code instead:
Lummox JR