more changes to gwars
Thomas Charles CONWAY
conway at cs.mu.oz.au
Wed Feb 19 09:21:32 AEDT 1997
For whosoever cares:
[coming next: support for both b&w and colour displays]
gwars/radar.m:
(Re)implement a line that sweeps round the radar window in the
"usual" radar way.
gwars/*.m:
various minor changes to support the radar sweep.
cvs diff: Diffing .
Index: control.m
===================================================================
RCS file: /home/staff/zs/imp/gwars/control.m,v
retrieving revision 1.3
diff -u -r1.3 control.m
--- control.m 1997/02/18 04:41:42 1.3
+++ control.m 1997/02/18 22:13:01
@@ -479,9 +479,10 @@
get_global("PlayerInfo", PlayerInfo),
{ type_playerinfo(PlayerInfo) },
{ map__keys(PlayerInfo, Players) },
- { Lambda = lambda([P::in, IO0::di, IO::uo] is det,
- playfield:draw_missile(Interp, P, X, Y, IO0, IO)
- ) },
+ { Lambda = lambda([P::in, IO0::di, IO::uo] is det, (
+ playfield:draw_missile(Interp, P, X, Y, IO0, IO1),
+ draw_radar_sweep(Interp, P, IO1, IO)
+ )) },
list__foldl(Lambda, Players),
(
{ N mod 16 = 0 }
@@ -500,10 +501,6 @@
:- func dt = float.
dt = 0.1.
-:- func pi = float.
-pi = 3.1415926535897932385.
-
-
%------------------------------------------------------------------------------%
:- pred basename(string::in, string::out) is det.
@@ -580,11 +577,6 @@
:- pred init_playerhighlights(map(player, string)::out) is det.
init_playerhighlights(Map) :-
- map__init(Map).
-
-:- pred init_radarinfo(map(player, maybe(string))::out) is det.
-
-init_radarinfo(Map) :-
map__init(Map).
%------------------------------------------------------------------------------%
Index: objects.m
===================================================================
RCS file: /home/staff/zs/imp/gwars/objects.m,v
retrieving revision 1.2
diff -u -r1.2 objects.m
--- objects.m 1997/02/18 04:41:47 1.2
+++ objects.m 1997/02/18 22:05:28
@@ -58,6 +58,8 @@
:- func sin(float) = float.
+:- func pi = float.
+
:- implementation.
:- import_module globals.
@@ -275,7 +277,6 @@
:- func dt = float.
dt = 0.1.
-:- func pi = float.
pi = 3.1415926535897932385.
remap(X0, Y0, playfield(Xmin, Xmax, Ymin, Ymax),
Index: radar.m
===================================================================
RCS file: /home/staff/zs/imp/gwars/radar.m,v
retrieving revision 1.2
diff -u -r1.2 radar.m
--- radar.m 1997/02/18 04:41:48 1.2
+++ radar.m 1997/02/18 22:20:42
@@ -2,7 +2,11 @@
:- interface.
-:- import_module io, mtk, objects.
+:- import_module io, mtk, objects, map.
+
+:- type radar.
+
+:- pred init_radarinfo(map(player, radar)::out) is det.
:- pred create_radar(tcl_interp, player, io__state, io__state).
:- mode create_radar(in, in, di, uo) is det.
@@ -25,16 +29,27 @@
:- pred draw_missile(tcl_interp, player, float, float, io__state, io__state).
:- mode draw_missile(in, in, in, in, di, uo) is det.
+:- pred reset_radar_sweep(tcl_interp, player, io__state, io__state).
+:- mode reset_radar_sweep(in, in, di, uo) is det.
+
+:- pred draw_radar_sweep(tcl_interp, player, io__state, io__state).
+:- mode draw_radar_sweep(in, in, di, uo) is det.
+
%------------------------------------------------------------------------------%
:- implementation.
-:- import_module string, map, require, globals, int, float, list, std_util.
+:- import_module string, require, globals, int, float, list, std_util.
+
+:- type radar ---> radar(maybe(string), float, maybe(string)).
+
+init_radarinfo(Map) :-
+ map__init(Map).
create_radar(Interp, Player) -->
get_global("RadarInfo", RadarInfo0),
{ semidet_succeed -> RI = no ; RI = yes("-1") },
- { map__set(RadarInfo0, Player, RI, RadarInfo) },
+ { map__set(RadarInfo0, Player, radar(RI, 0.0, RI), RadarInfo) },
set_global("RadarInfo", RadarInfo),
get_global("PlayerInfo", PlayerInfo),
{ map__lookup(PlayerInfo, Player, playerinfo(Name, Display, _)) },
@@ -136,7 +151,6 @@
{ string__to_lower(Name, WName) },
get_global("RadarInfo", RadarInfo0),
{ remap(X0, Y0, PlayField, DisplayField, X1, Y1) },
- { DisplayField = playfield(Xmin, Xmax, Ymin, Ymax) },
{ string__format(
".%s.radar.canvas create oval %d %d %d %d \
-fill gray -outline gray \n",
@@ -144,7 +158,10 @@
i(int(X1)), i(int(Y1))], CmdStr1) },
eval(Interp, CmdStr1, Res1, ResStr1),
{ Res1 = tcl_ok -> true ; error(ResStr1) },
- { map__set(RadarInfo0, Player, yes(ResStr1), RadarInfo) },
+ { map__lookup(RadarInfo0, Player, Radar0) },
+ { Radar0 = radar(_, Theta, Sweep) },
+ { Radar = radar(yes(ResStr1), Theta, Sweep) },
+ { map__set(RadarInfo0, Player, Radar, RadarInfo) },
set_global("RadarInfo", RadarInfo).
:- pred remove_blob(tcl_interp, player, io__state, io__state).
@@ -155,7 +172,58 @@
{ map__lookup(PlayerInfo, Player, playerinfo(Name, _, _)) },
{ string__to_lower(Name, WName) },
get_global("RadarInfo", RadarInfo0),
- { map__lookup(RadarInfo0, Player, MRI) },
+ { map__lookup(RadarInfo0, Player, radar(MRI, _Theta, _Sweep)) },
+ (
+ { MRI = no }
+ ;
+ { MRI = yes(Id0) },
+ { string__format(".%s.radar.canvas delete %s",
+ [s(WName), s(Id0)], DelStr) },
+ eval(Interp, DelStr, _, _)
+ ).
+
+%------------------------------------------------------------------------------%
+
+reset_radar_sweep(Interp, Player) -->
+ remove_sweep_blob(Interp, Player),
+ get_global("RadarInfo", RadarInfo0),
+ { map__lookup(RadarInfo0, Player, Radar0) },
+ { Radar0 = radar(Missile, _, Sweep) },
+ { Radar = radar(Missile, 0.0, Sweep) },
+ { map__set(RadarInfo0, Player, Radar, RadarInfo) },
+ set_global("RadarInfo", RadarInfo).
+
+%------------------------------------------------------------------------------%
+
+draw_radar_sweep(Interp, Player) -->
+ remove_sweep_blob(Interp, Player),
+ get_global("PlayerInfo", PlayerInfo),
+ { map__lookup(PlayerInfo, Player, playerinfo(Name, _, _)) },
+ { string__to_lower(Name, WName) },
+ get_global("RadarInfo", RadarInfo0),
+ { map__lookup(RadarInfo0, Player, Radar0) },
+ { Radar0 = radar(Missile, Theta, _) },
+ { X0 = 120.0*cos(Theta) + 128.0 },
+ { Y0 = 120.0*sin(Theta) + 128.0 },
+ { string__format(
+ ".%s.radar.canvas create line 128 128 %d %d \
+ -fill gray \n",
+ [s(WName), i(int(X0)), i(int(Y0))], CmdStr1) },
+ eval(Interp, CmdStr1, Res1, ResStr1),
+ { Res1 = tcl_ok -> true ; error(ResStr1) },
+ { Radar = radar(Missile, Theta-pi/256.0, yes(ResStr1)) },
+ { map__set(RadarInfo0, Player, Radar, RadarInfo) },
+ set_global("RadarInfo", RadarInfo).
+
+:- pred remove_sweep_blob(tcl_interp, player, io__state, io__state).
+:- mode remove_sweep_blob(in, in, di, uo) is det.
+
+remove_sweep_blob(Interp, Player) -->
+ get_global("PlayerInfo", PlayerInfo),
+ { map__lookup(PlayerInfo, Player, playerinfo(Name, _, _)) },
+ { string__to_lower(Name, WName) },
+ get_global("RadarInfo", RadarInfo0),
+ { map__lookup(RadarInfo0, Player, radar(_, _, MRI)) },
(
{ MRI = no }
;
--
Thomas Conway conway at cs.mu.oz.au
AD DEUM ET VINUM Every sword has two edges.
More information about the developers
mailing list