home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
progmisc
/
euphor10.zip
/
WEAPONS.E
< prev
next >
Wrap
Text File
|
1993-06-08
|
6KB
|
265 lines
-- weapons.e
-- phasors, torpedos, (antimatter pods - coming soon)
global constant W_PHASOR = 1,
W_TORPEDO = 2,
W_POD = 3
type weapon_system(integer x)
return find(x, {W_PHASOR, W_TORPEDO, W_POD})
end type
extended_h_coord x0
extended_v_coord y0
atom xinc
atom yinc
function diftype(valid_f_row shooter, valid_f_row victim)
-- return TRUE if shooter and victim are on opposing sides
if f[shooter][F_TYPE] = G_BS then
return victim != ENTERPRISE
else
if find(f[shooter][F_TYPE], {G_SK, G_BK, G_JM}) and
find(f[victim][F_TYPE] , {G_SK, G_BK, G_JM}) then
-- both Klingons
return FALSE
else
return f[shooter][F_TYPE] != f[victim][F_TYPE]
end if
end if
end function
without warning
procedure pod_effect(h_coord rx,v_coord ry)
-- detonate an antimatter pod, all objects in the quadrant are
-- affected. It's like a 1500 unit tholian phasor blast against
-- everyone
end procedure
with warning
global procedure weapon(weapon_system w, positive_atom strength)
-- fire a phasor, torpedo or pod from shooter starting from (x0,y0) and
-- proceeding in steps of xinc, yinc until something is hit or the
-- edge of the screen is reached
extended_h_coord x
extended_v_coord y
h_coord rx
v_coord ry
extended_h_coord prev_rx
extended_v_coord prev_ry
boolean ahit
char c
positive_int freq
positive_atom units
sequence under
prev_rx = 0
prev_ry = 0
x = x0
y = y0
ahit = FALSE
under = {}
if w != W_PHASOR then
freq = 3500
sound(freq)
end if
while x >= .5 and x < HSIZE + 0.5 and
y >= .5 and y < VSIZE + 0.5 do
rx = floor(x + 0.5)
ry = floor(y + 0.5)
if rx != prev_rx or ry != prev_ry then
c = read_screen(rx, ry)
if c = ' ' or c = STAR or w = W_POD then
prev_rx = rx
prev_ry = ry
if w = W_PHASOR then
under = prepend(under, {rx, ry, c})
write_screen(rx, ry, '*')
delay(0.006)
else
if length(under) != 0 then
write_screen(under[1][1], under[1][2], under[1][3])
end if
under = {{rx, ry, c}}
if w = W_TORPEDO then
write_screen(rx, ry, '*')
else
write_screen(rx, ry, '@')
if get_key() = 13 then
exit
end if
end if
sound(freq)
if freq > 600 then
freq = freq - 50
end if
delay(0.008)
end if
else
ahit = TRUE
exit
end if
end if
x = x + xinc
y = y + yinc
end while
if w != W_PHASOR then
sound(0)
end if
if w = W_POD then
pod_effect(rx, ry)
else
if ahit then
victim = flook(rx, ry, FALSE)
if diftype(shooter, victim) then
if w = W_TORPEDO then
sounde(1, 85, 1)
torpedo_sound()
dodmg(strength, TRUE)
else
units = bcalc(strength)
phasor_sound(units)
dodmg(units, FALSE)
end if
end if
end if
end if
for i = length(under) to 1 by - 1 do
write_screen(under[i][1], under[i][2], under[i][3])
end for
end procedure
type object_height(integer x)
return x >= 1 and x <= 3
end type
global procedure tholian_phasor(positive_atom pen)
-- perform tholian phasor: no phasor drawn, can't miss
positive_atom blast
h_coord targx
v_coord targy
sequence c
positive_int len
object_type t
object_height height
victim = f[shooter][F_TARG]
targx = f[victim][F_X]
targy = f[victim][F_Y]
t = f[victim][F_TYPE]
if victim = ENTERPRISE then
len = length(esym)
height = 1
elsif t = G_BS then
len = length(BASE)
height = 2
elsif t = G_PL then
len = length(PLANET_MIDDLE)
height = 3
else
len = length(ship[f[victim][F_TYPE]][1])
height = 1
end if
blast = bcalc(pen)
for i = -2 to blast / 300 do
sound(500 + 500 * (integer(i / 2)))
write_screen(f[shooter][F_X]+1, f[shooter][F_Y], '-')
for j = 0 to height - 1 do
c = read_screen({targx, len}, targy + j)
write_screen(targx, targy + j, repeat(' ', len))
end for
delay(0.07)
write_screen(f[shooter][F_X]+1, f[shooter][F_Y], '+')
for j = 0 to height - 1 do
write_screen(targx, targy + j, c)
end for
delay(0.07)
end for
sound(0)
dodmg(blast, FALSE)
end procedure
global procedure setpt(valid_f_row r)
-- set up enemy (or base) phasor or torpedo
positive_atom dist
valid_f_row targ
h_coord targx
v_coord targy
object_type t
x0 = f[r][F_X]
y0 = f[r][F_Y]
targ = f[r][F_TARG]
targx = f[targ][F_X]
targy = f[targ][F_Y]
t = f[r][F_TYPE]
-- decide which side to shoot from
if t = G_BS then
if x0 < targx then
x0 = x0 + length(BASE)
else
x0 = x0 - 1
end if
if y0 < targy then
y0 = y0 + 2
else
y0 = y0 - 1
end if
else
if x0 < targx then
x0 = x0 + length(ship[t][1])
else
x0 = x0 - 1
end if
end if
-- add a bit of randomness so they might miss
xinc = targx - x0 + rand(5) - 3
yinc = targy - y0 + rand(3) - 2
if xinc = 0 and yinc = 0 then
xinc = 1 -- prevent infinite loop
end if
dist = sqrt(1 + xinc * xinc + yinc * yinc)
xinc = xinc/dist
yinc = yinc/dist
end procedure
global type direction(atom x)
return x >= 0 and x < 10
end type
constant PI = 3.14159265
type angle(atom x)
return x >= 0 and x < 2.25 * PI
end type
global procedure esetpt(direction dir)
-- set up for enterprise phasor/torpedo/pod firing
angle theta
shooter = ENTERPRISE
x0 = f[ENTERPRISE][F_X]
y0 = f[ENTERPRISE][F_Y]
theta = (dir - 1)/8.0 * 2 * PI
xinc = cos(theta)
yinc = -sin(theta) / ASPECT_RATIO
if xinc < -0.00001 then
write_screen(x0, y0, esyml)
elsif xinc > 0.00001 then
write_screen(x0, y0, esymr)
end if
if read_screen(x0, y0) = esyml[1] then
x0 = x0 - 1
else
x0 = x0 + length(esym)
end if
end procedure