templeos-info/public/Wb/Demo/Games/BattleLines.HC.HTML

414 lines
32 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.c20{color:#000000;background-color:#00aa00;}
.c2A{color:#55ff55;background-color:#00aa00;}
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF2>//Uses </span><a href="/Wb/Demo/Lectures/FixedPoint.HC.HTML#l1"><span class=cF4>fixed-point</span></a><span class=cF2>.</span><span class=cF0>
<a name="l2"></a>
<a name="l3"></a></span><span class=c20>
<a name="l4"></a></span><span class=c2A>
<a name="l5"></a>&lt;1&gt;/* Graphics Not Rendered in HTML */</span><span class=c20>
<a name="l6"></a>
<a name="l7"></a>
<a name="l8"></a></span><span class=c2A>
<a name="l9"></a>&lt;2&gt;/* Graphics Not Rendered in HTML */</span><span class=c20>
<a name="l10"></a>
<a name="l11"></a>
<a name="l12"></a></span><span class=c2A>
<a name="l13"></a>&lt;3&gt;/* Graphics Not Rendered in HTML */</span><span class=c20>
<a name="l14"></a>
<a name="l15"></a>
<a name="l16"></a></span><span class=c2A>
<a name="l17"></a>&lt;4&gt;/* Graphics Not Rendered in HTML */</span><span class=c20>
<a name="l18"></a>
<a name="l19"></a>
<a name="l20"></a></span><span class=c2A>
<a name="l21"></a>&lt;5&gt;/* Graphics Not Rendered in HTML */</span><span class=c20>
<a name="l22"></a>
<a name="l23"></a>
<a name="l24"></a></span><span class=cF0>#</span><span class=cF1>define</span><span class=cF0> FRAMES 6
<a name="l25"></a>
<a name="l26"></a></span><span class=cF1>U8</span><span class=cF0> *imgs[FRAMES]={</span><span class=cFA>
<a name="l27"></a>&lt;1&gt;</span><span class=cF0>,</span><span class=cFA>&lt;2&gt;</span><span class=cF0>,</span><span class=cFA>&lt;3&gt;</span><span class=cF0>,</span><span class=cFA>&lt;4&gt;</span><span class=cF0>,</span><span class=cFA>&lt;3&gt;</span><span class=cF0>,</span><span class=cFA>&lt;2&gt;</span><span class=cF0>};
<a name="l28"></a>
<a name="l29"></a></span><span class=cF1>F64</span><span class=cF0> fire_end_time;
<a name="l30"></a>
<a name="l31"></a></span><span class=cF1>class</span><span class=cF0> Trooper
<a name="l32"></a>{
<a name="l33"></a> </span><span class=cF9>I64</span><span class=cF0> x,y,dx,dy,att,def,rng,player;
<a name="l34"></a> </span><span class=cF1>F64</span><span class=cF0> animate_time_base,fire_end_time;
<a name="l35"></a> Trooper *target;
<a name="l36"></a>};
<a name="l37"></a>
<a name="l38"></a>#</span><span class=cF1>define</span><span class=cF0> TROOPERS_NUM 100
<a name="l39"></a>Trooper tr[2][TROOPERS_NUM];
<a name="l40"></a>
<a name="l41"></a></span><span class=cF1>Bool</span><span class=cF0> time_lapse=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l42"></a>
<a name="l43"></a>#</span><span class=cF1>define</span><span class=cF0> TAP_MODE_RADIUS 50
<a name="l44"></a></span><span class=cF1>Bool</span><span class=cF0> tap_mode;
<a name="l45"></a>
<a name="l46"></a>#</span><span class=cF1>define</span><span class=cF0> AI_NOTHING 0
<a name="l47"></a>#</span><span class=cF1>define</span><span class=cF0> AI_TARGET 1
<a name="l48"></a>#</span><span class=cF1>define</span><span class=cF0> AI_RANDOM 2
<a name="l49"></a>#</span><span class=cF1>define</span><span class=cF0> AI_AI_NUM 3
<a name="l50"></a></span><span class=cF9>I64</span><span class=cF0> ai_mode;
<a name="l51"></a>
<a name="l52"></a></span><span class=cF9>I64</span><span class=cF0> ai_targets[10];
<a name="l53"></a>
<a name="l54"></a></span><span class=cF1>U0</span><span class=cF0> DrawTrooper(</span><span class=cF9>CTask</span><span class=cF0> *,</span><span class=cF9>CDC</span><span class=cF0> *dc,Trooper *tmpt)
<a name="l55"></a>{
<a name="l56"></a> </span><span class=cF1>U8</span><span class=cF0> *tmps;
<a name="l57"></a> </span><span class=cF9>I64</span><span class=cF0> x,y,gx,gy;
<a name="l58"></a> </span><span class=cF1>F64</span><span class=cF0> speed,tt;
<a name="l59"></a>
<a name="l60"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt-&gt;def&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l61"></a> x=tmpt-&gt;dx&gt;&gt;28;
<a name="l62"></a> y=tmpt-&gt;dy&gt;&gt;28;
<a name="l63"></a> speed=0.5*</span><span class=cF5>Sqrt</span><span class=cF0>(x*x+y*y);
<a name="l64"></a>
<a name="l65"></a> tt=tmpt-&gt;animate_time_base+</span><span class=cF5>tS</span><span class=cF0>*speed;
<a name="l66"></a> </span><span class=cF1>if</span><span class=cF0> (time_lapse) {
<a name="l67"></a> x=(tmpt-&gt;x+500*tmpt-&gt;dx)&gt;&gt;32;
<a name="l68"></a> y=(tmpt-&gt;y+500*tmpt-&gt;dy)&gt;&gt;32;
<a name="l69"></a> } </span><span class=cF1>else</span><span class=cF0> {
<a name="l70"></a> x=tmpt-&gt;x.i32[1];
<a name="l71"></a> y=tmpt-&gt;y.i32[1];
<a name="l72"></a> }
<a name="l73"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt-&gt;target) {
<a name="l74"></a> gx=x;gy=y;
<a name="l75"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt-&gt;dx&lt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l76"></a> dc-&gt;flags|=</span><span class=cF3>DCF_SYMMETRY</span><span class=cF0>|</span><span class=cF3>DCF_JUST_MIRROR</span><span class=cF0>;
<a name="l77"></a> </span><span class=cF5>DCSymmetrySet</span><span class=cF0>(dc,x,y,x,y+1);
<a name="l78"></a> gx-=13;
<a name="l79"></a> gy-=7;
<a name="l80"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l81"></a> dc-&gt;flags&amp;=~</span><span class=cF3>DCF_SYMMETRY</span><span class=cF0>|</span><span class=cF3>DCF_JUST_MIRROR</span><span class=cF0>;
<a name="l82"></a> gx+=13;
<a name="l83"></a> gy-=7;
<a name="l84"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l85"></a>
<a name="l86"></a> dc-&gt;color=</span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l87"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x+1,y,0,</span><span class=cFA>&lt;5&gt;</span><span class=cF0>);
<a name="l88"></a>
<a name="l89"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpt-&gt;player)
<a name="l90"></a> dc-&gt;color=</span><span class=cF3>LTCYAN</span><span class=cF0>;
<a name="l91"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l92"></a> dc-&gt;color=</span><span class=cF3>LTPURPLE</span><span class=cF0>;
<a name="l93"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x,y,0,</span><span class=cFA>&lt;5&gt;</span><span class=cF0>);
<a name="l94"></a>
<a name="l95"></a> dc-&gt;flags&amp;=~(</span><span class=cF3>DCF_SYMMETRY</span><span class=cF0>|</span><span class=cF3>DCF_JUST_MIRROR</span><span class=cF0>);
<a name="l96"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpt-&gt;player)
<a name="l97"></a> dc-&gt;color=</span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l98"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l99"></a> dc-&gt;color=</span><span class=cF3>LTBLUE</span><span class=cF0>;
<a name="l100"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc,gx,gy,0,tmpt-&gt;target-&gt;x.i32[1],tmpt-&gt;target-&gt;y.i32[1],0);
<a name="l101"></a> } </span><span class=cF1>else</span><span class=cF0> {
<a name="l102"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt-&gt;dx&lt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l103"></a> dc-&gt;flags|=</span><span class=cF3>DCF_SYMMETRY</span><span class=cF0>|</span><span class=cF3>DCF_JUST_MIRROR</span><span class=cF0>;
<a name="l104"></a> </span><span class=cF5>DCSymmetrySet</span><span class=cF0>(dc,x,y,x,y+1);
<a name="l105"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l106"></a> dc-&gt;flags&amp;=~</span><span class=cF3>DCF_SYMMETRY</span><span class=cF0>|</span><span class=cF3>DCF_JUST_MIRROR</span><span class=cF0>;
<a name="l107"></a> tmps=</span><span class=cF5>SpriteInterpolate</span><span class=cF0>(tt%1.0,imgs[tt%FRAMES],imgs[</span><span class=cF7>(</span><span class=cF0>tt+1.0</span><span class=cF7>)</span><span class=cF0>%FRAMES]);
<a name="l108"></a>
<a name="l109"></a> dc-&gt;color=</span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l110"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x+1,y,0,tmps);
<a name="l111"></a>
<a name="l112"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpt-&gt;player)
<a name="l113"></a> dc-&gt;color=</span><span class=cF3>LTCYAN</span><span class=cF0>;
<a name="l114"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l115"></a> dc-&gt;color=</span><span class=cF3>LTPURPLE</span><span class=cF0>;
<a name="l116"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,x,y,0,tmps);
<a name="l117"></a>
<a name="l118"></a> </span><span class=cF5>Free</span><span class=cF0>(tmps);
<a name="l119"></a> dc-&gt;flags&amp;=~(</span><span class=cF3>DCF_SYMMETRY</span><span class=cF0>|</span><span class=cF3>DCF_JUST_MIRROR</span><span class=cF0>);
<a name="l120"></a> }
<a name="l121"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l122"></a>}
<a name="l123"></a>
<a name="l124"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DrawIt</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task,</span><span class=cF9>CDC</span><span class=cF0> *dc)
<a name="l125"></a>{
<a name="l126"></a> Trooper *tmpt=tr;
<a name="l127"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,cnt[2],
<a name="l128"></a> x=</span><span class=cFB>ms</span><span class=cF0>.pos.x-task-&gt;pix_left-task-&gt;scroll_x,
<a name="l129"></a> y=</span><span class=cFB>ms</span><span class=cF0>.pos.y-task-&gt;pix_top-task-&gt;scroll_y;
<a name="l130"></a> </span><span class=cF1>Bool</span><span class=cF0> repulsive=</span><span class=cFB>ms</span><span class=cF0>.pos.z&gt;0 ^^ </span><span class=cFB>ms</span><span class=cF0>.rb,
<a name="l131"></a> active=!</span><span class=cFB>winmgr</span><span class=cF0>.grab_scroll &amp;&amp; (</span><span class=cFB>ms</span><span class=cF0>.lb||</span><span class=cFB>ms</span><span class=cF0>.rb);
<a name="l132"></a>
<a name="l133"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j&lt;2;j++) </span><span class=cF7>{</span><span class=cF0>
<a name="l134"></a> cnt[j]=0;
<a name="l135"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;TROOPERS_NUM;i++,tmpt++) {
<a name="l136"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt-&gt;def&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l137"></a> DrawTrooper(task,dc,tmpt);
<a name="l138"></a> cnt[j]++;
<a name="l139"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l140"></a> }
<a name="l141"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l142"></a> </span><span class=cF1>if</span><span class=cF0> (tap_mode) </span><span class=cF7>{</span><span class=cF0>
<a name="l143"></a> dc-&gt;color=</span><span class=cF3>YELLOW</span><span class=cF0>;
<a name="l144"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc,x,y,TAP_MODE_RADIUS);
<a name="l145"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l146"></a> </span><span class=cF1>if</span><span class=cF0> (repulsive) {
<a name="l147"></a> </span><span class=cF1>if</span><span class=cF0> (active)
<a name="l148"></a> dc-&gt;color=</span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l149"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l150"></a> dc-&gt;color=</span><span class=cF3>RED</span><span class=cF0>;
<a name="l151"></a> } </span><span class=cF1>else</span><span class=cF0> {
<a name="l152"></a> </span><span class=cF1>if</span><span class=cF0> (active)
<a name="l153"></a> dc-&gt;color=</span><span class=cF3>LTBLUE</span><span class=cF0>;
<a name="l154"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l155"></a> dc-&gt;color=</span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l156"></a> }
<a name="l157"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc,x,y,</span><span class=cF5>AbsI64</span><span class=cF7>(</span><span class=cFB>ms</span><span class=cF0>.pos.z</span><span class=cF7>)</span><span class=cF0>);
<a name="l158"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l159"></a> dc-&gt;color=</span><span class=cF3>LTCYAN</span><span class=cF0>;
<a name="l160"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,</span><span class=cF7>(</span><span class=cF0>task-&gt;win_right-8</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF3>FONT_WIDTH</span><span class=cF0>,0,</span><span class=cF6>&quot;%03d&quot;</span><span class=cF0>,cnt[0]);
<a name="l161"></a> dc-&gt;color=</span><span class=cF3>LTPURPLE</span><span class=cF0>;
<a name="l162"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,</span><span class=cF7>(</span><span class=cF0>task-&gt;win_right-4</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF3>FONT_WIDTH</span><span class=cF0>,0,</span><span class=cF6>&quot;%03d&quot;</span><span class=cF0>,cnt[1]);
<a name="l163"></a>}
<a name="l164"></a>
<a name="l165"></a></span><span class=cF1>U0</span><span class=cF0> DoAiTarget()
<a name="l166"></a>{
<a name="l167"></a> </span><span class=cF9>I64</span><span class=cF0> i,j;
<a name="l168"></a> Trooper *tmpt1,*tmpt0;
<a name="l169"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;10;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l170"></a> tmpt0=&amp;tr[0][ai_targets[i]];
<a name="l171"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j&lt;10;j++) {
<a name="l172"></a> tmpt1=&amp;tr[1][i*10+j];
<a name="l173"></a> tmpt1-&gt;dx=(tmpt0-&gt;x-tmpt1-&gt;x)&gt;&gt;11;
<a name="l174"></a> tmpt1-&gt;dy=(tmpt0-&gt;y-tmpt1-&gt;y)&gt;&gt;11;
<a name="l175"></a> }
<a name="l176"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l177"></a>}
<a name="l178"></a>
<a name="l179"></a></span><span class=cF1>U0</span><span class=cF0> UpdatePos()
<a name="l180"></a>{
<a name="l181"></a> </span><span class=cF9>I64</span><span class=cF0> i,j;
<a name="l182"></a> Trooper *tmpt=tr;
<a name="l183"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j&lt;2;j++)
<a name="l184"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;TROOPERS_NUM;i++,tmpt++) </span><span class=cF7>{</span><span class=cF0>
<a name="l185"></a> tmpt-&gt;x+=tmpt-&gt;dx;
<a name="l186"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt-&gt;x&gt;=</span><span class=cF3>GR_WIDTH</span><span class=cF0>&lt;&lt;32) tmpt-&gt;x-=</span><span class=cF3>GR_WIDTH</span><span class=cF0>&lt;&lt;32;
<a name="l187"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt-&gt;x&lt;0) tmpt-&gt;x+=</span><span class=cF3>GR_WIDTH</span><span class=cF0>&lt;&lt;32;
<a name="l188"></a> tmpt-&gt;y+=tmpt-&gt;dy;
<a name="l189"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt-&gt;y&gt;=</span><span class=cF3>GR_HEIGHT</span><span class=cF0>&lt;&lt;32) tmpt-&gt;y-=</span><span class=cF3>GR_HEIGHT</span><span class=cF0>&lt;&lt;32;
<a name="l190"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt-&gt;y&lt;0) tmpt-&gt;y+=</span><span class=cF3>GR_HEIGHT</span><span class=cF0>&lt;&lt;32;
<a name="l191"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l192"></a>}
<a name="l193"></a>
<a name="l194"></a></span><span class=cF1>U0</span><span class=cF0> ResolveFiring()
<a name="l195"></a>{
<a name="l196"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,dd,dx,dy;
<a name="l197"></a> Trooper *tmpt=tr,*tmpt0,*tmpt1;
<a name="l198"></a>
<a name="l199"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j&lt;2;j++)
<a name="l200"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;TROOPERS_NUM;i++,tmpt++) </span><span class=cF7>{</span><span class=cF0>
<a name="l201"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt-&gt;target &amp;&amp; tmpt-&gt;fire_end_time&lt;</span><span class=cF5>tS</span><span class=cF0>) {
<a name="l202"></a> tmpt-&gt;target-&gt;def-=tmpt-&gt;att;
<a name="l203"></a> tmpt-&gt;fire_end_time=0;
<a name="l204"></a> tmpt-&gt;target=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l205"></a> }
<a name="l206"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l207"></a>
<a name="l208"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;TROOPERS_NUM;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l209"></a> tmpt0=&amp;tr[0][i];
<a name="l210"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j&lt;TROOPERS_NUM;j++) {
<a name="l211"></a> tmpt1=&amp;tr[1][j];
<a name="l212"></a> </span><span class=cF1>if</span><span class=cF0> (tmpt0-&gt;def&gt;0 &amp;&amp; tmpt1-&gt;def&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l213"></a> dx=(tmpt0-&gt;x-tmpt1-&gt;x)&gt;&gt;32;
<a name="l214"></a> dy=(tmpt0-&gt;y-tmpt1-&gt;y)&gt;&gt;32;
<a name="l215"></a> dd=dx*dx+dy*dy;
<a name="l216"></a> </span><span class=cF1>if</span><span class=cF0> (dd&lt;tmpt0-&gt;rng &amp;&amp; !tmpt0-&gt;target) {
<a name="l217"></a> fire_end_time=tmpt0-&gt;fire_end_time=</span><span class=cF5>tS</span><span class=cF0>+0.125;
<a name="l218"></a> </span><span class=cF5>Snd</span><span class=cF0>(86);
<a name="l219"></a> tmpt0-&gt;target=tmpt1;
<a name="l220"></a> }
<a name="l221"></a> </span><span class=cF1>if</span><span class=cF0> (dd&lt;tmpt1-&gt;rng &amp;&amp; !tmpt1-&gt;target) {
<a name="l222"></a> fire_end_time=tmpt1-&gt;fire_end_time=</span><span class=cF5>tS</span><span class=cF0>+0.125;
<a name="l223"></a> </span><span class=cF5>Snd</span><span class=cF0>(86);
<a name="l224"></a> tmpt1-&gt;target=tmpt0;
<a name="l225"></a> }
<a name="l226"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l227"></a> }
<a name="l228"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l229"></a>
<a name="l230"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>tS</span><span class=cF0>&gt;=fire_end_time)
<a name="l231"></a> </span><span class=cF5>Snd</span><span class=cF0>;
<a name="l232"></a>}
<a name="l233"></a>
<a name="l234"></a></span><span class=cF1>U0</span><span class=cF0> UpdateHumanVelocities()
<a name="l235"></a>{
<a name="l236"></a> </span><span class=cF1>F64</span><span class=cF0> intensity;
<a name="l237"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,dx,dy,d,
<a name="l238"></a> x=</span><span class=cFB>ms</span><span class=cF0>.pos.x-</span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_left-</span><span class=cF5>Fs</span><span class=cF0>-&gt;scroll_x,
<a name="l239"></a> y=</span><span class=cFB>ms</span><span class=cF0>.pos.y-</span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_top-</span><span class=cF5>Fs</span><span class=cF0>-&gt;scroll_y;
<a name="l240"></a> </span><span class=cF1>Bool</span><span class=cF0> active=!</span><span class=cFB>winmgr</span><span class=cF0>.grab_scroll&amp;&amp;(</span><span class=cFB>ms</span><span class=cF0>.lb||</span><span class=cFB>ms</span><span class=cF0>.rb);
<a name="l241"></a> Trooper *tmpt=&amp;tr[0][0];
<a name="l242"></a> </span><span class=cF1>if</span><span class=cF0> (tap_mode) </span><span class=cF7>{</span><span class=cF0>
<a name="l243"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;TROOPERS_NUM;i++,tmpt++) {
<a name="l244"></a> dx=x- tmpt-&gt;x.i32[1];
<a name="l245"></a> dy=y- tmpt-&gt;y.i32[1];
<a name="l246"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>d=dx*dx+dy*dy</span><span class=cF7>)</span><span class=cF0> &amp;&amp; d&lt;TAP_MODE_RADIUS*TAP_MODE_RADIUS) </span><span class=cF7>{</span><span class=cF0>
<a name="l247"></a> intensity=</span><span class=cF5>SqrI64</span><span class=cF0>(</span><span class=cF5>SqrI64</span><span class=cF7>(</span><span class=cF5>SqrI64</span><span class=cF0>(TAP_MODE_RADIUS)-d</span><span class=cF7>)</span><span class=cF0>);
<a name="l248"></a> dx=intensity*dx/d;
<a name="l249"></a> dy=intensity*dy/d;
<a name="l250"></a> tmpt-&gt;dx=tmpt-&gt;dx-dx;
<a name="l251"></a> tmpt-&gt;dy=tmpt-&gt;dy-dy;
<a name="l252"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l253"></a> tmpt-&gt;dx-=0.2*tmpt-&gt;dx;
<a name="l254"></a> tmpt-&gt;dy-=0.2*tmpt-&gt;dy;
<a name="l255"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l256"></a> }
<a name="l257"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (active) </span><span class=cF7>{</span><span class=cF0>
<a name="l258"></a> j=400000000*</span><span class=cFB>ms</span><span class=cF0>.pos.z;
<a name="l259"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>ms</span><span class=cF0>.rb)
<a name="l260"></a> j=-j;
<a name="l261"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;TROOPERS_NUM;i++,tmpt++) {
<a name="l262"></a> dx=x- tmpt-&gt;x.i32[1];
<a name="l263"></a> dy=y- tmpt-&gt;y.i32[1];
<a name="l264"></a> </span><span class=cF1>if</span><span class=cF0> (d=dx*dx+dy*dy) </span><span class=cF7>{</span><span class=cF0>
<a name="l265"></a> dx=j*dx/d;
<a name="l266"></a> dy=j*dy/d;
<a name="l267"></a> tmpt-&gt;dx=tmpt-&gt;dx-dx;
<a name="l268"></a> tmpt-&gt;dy=tmpt-&gt;dy-dy;
<a name="l269"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l270"></a> }
<a name="l271"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l272"></a>}
<a name="l273"></a>
<a name="l274"></a></span><span class=cF1>U0</span><span class=cF0> Init()
<a name="l275"></a>{
<a name="l276"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,dx,dy;
<a name="l277"></a> Trooper *tmpt;
<a name="l278"></a> </span><span class=cF5>MsSet</span><span class=cF0>(,,25);
<a name="l279"></a> tap_mode=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l280"></a> time_lapse=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l281"></a> fire_end_time=0;
<a name="l282"></a> </span><span class=cF5>MemSet</span><span class=cF0>(tr,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>tr</span><span class=cF7>)</span><span class=cF0>);
<a name="l283"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;10;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l284"></a> ai_targets[i]=</span><span class=cF5>RandU16</span><span class=cF0>%TROOPERS_NUM;
<a name="l285"></a> dx=</span><span class=cF5>RandI32</span><span class=cF0>;
<a name="l286"></a> dy=</span><span class=cF5>RandI32</span><span class=cF0>;
<a name="l287"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j&lt;10;j++) {
<a name="l288"></a> tmpt=&amp;tr[0][i*10+j];
<a name="l289"></a> tmpt-&gt;x=(</span><span class=cF3>GR_WIDTH</span><span class=cF0>-100-i*10)&lt;&lt;32;
<a name="l290"></a> tmpt-&gt;y=(</span><span class=cF3>GR_HEIGHT</span><span class=cF0>&gt;&gt;1-50+j*10)&lt;&lt;32;
<a name="l291"></a> tmpt-&gt;att=3;
<a name="l292"></a> tmpt-&gt;def=10;
<a name="l293"></a> tmpt-&gt;rng=50*50;
<a name="l294"></a> tmpt-&gt;animate_time_base=10*</span><span class=cF5>Rand</span><span class=cF0>;
<a name="l295"></a> tmpt-&gt;player=0;
<a name="l296"></a>
<a name="l297"></a> tmpt=&amp;tr[1][i*10+j];
<a name="l298"></a> tmpt-&gt;x=(100+i*10)&lt;&lt;32;
<a name="l299"></a> tmpt-&gt;y=(</span><span class=cF3>GR_HEIGHT</span><span class=cF0>&gt;&gt;1-50+j*10)&lt;&lt;32;
<a name="l300"></a> </span><span class=cF1>if</span><span class=cF0> (ai_mode==AI_RANDOM) </span><span class=cF7>{</span><span class=cF0>
<a name="l301"></a> tmpt-&gt;dx=dx;
<a name="l302"></a> tmpt-&gt;dy=dy;
<a name="l303"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l304"></a> tmpt-&gt;att=3;
<a name="l305"></a> tmpt-&gt;def=10;
<a name="l306"></a> tmpt-&gt;rng=50*50;
<a name="l307"></a> tmpt-&gt;animate_time_base=10*</span><span class=cF5>Rand</span><span class=cF0>;
<a name="l308"></a> tmpt-&gt;player=1;
<a name="l309"></a> }
<a name="l310"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l311"></a> ai_mode=</span><span class=cF5>RandU16</span><span class=cF0>%AI_AI_NUM;
<a name="l312"></a>}
<a name="l313"></a>
<a name="l314"></a></span><span class=cF1>U0</span><span class=cF0> BattleLines()
<a name="l315"></a>{
<a name="l316"></a> </span><span class=cF9>CMenuEntry</span><span class=cF0> *tmpse;
<a name="l317"></a>
<a name="l318"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
<a name="l319"></a> </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l320"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l321"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l322"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l323"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l324"></a> </span><span class=cF6>&quot; Restart(,'\n');&quot;</span><span class=cF0>
<a name="l325"></a> </span><span class=cF6>&quot; TimeLapse(,'1');&quot;</span><span class=cF0>
<a name="l326"></a> </span><span class=cF6>&quot; TapMode(,'2');&quot;</span><span class=cF0>
<a name="l327"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l328"></a> );
<a name="l329"></a>
<a name="l330"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="/Wb/Adam/TaskSettings.HC.HTML#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l331"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;text_attr=</span><span class=cF3>GREEN</span><span class=cF0>&lt;&lt;4+</span><span class=cF3>WHITE</span><span class=cF0>;
<a name="l332"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l333"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l334"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l335"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l336"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l337"></a> Init;
<a name="l338"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;draw_it=&amp;</span><span class=cF5>DrawIt</span><span class=cF0>;
<a name="l339"></a> </span><span class=cF5>PopUpOk</span><span class=cF0>(</span><span class=cF6>&quot;The mouse wheel controls\n&quot;</span><span class=cF0>
<a name="l340"></a> </span><span class=cF6>&quot;the command force.\n&quot;</span><span class=cF0>
<a name="l341"></a> </span><span class=cF6>&quot;Attract or repel with\n&quot;</span><span class=cF0>
<a name="l342"></a> </span><span class=cF6>&quot;left or right bttn.\n\n&quot;</span><span class=cF0>);
<a name="l343"></a>
<a name="l344"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;win_inhibit=</span><span class=cF3>WIG_TASK_DFT</span><span class=cF0>-</span><span class=cF3>WIF_SELF_FOCUS</span><span class=cF0>
<a name="l345"></a> -</span><span class=cF3>WIF_SELF_BORDER</span><span class=cF0>-</span><span class=cF3>WIF_FOCUS_TASK_MENU</span><span class=cF0>;
<a name="l346"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l347"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
<a name="l348"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>ScanChar</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l349"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'1'</span><span class=cF0>:
<a name="l350"></a> time_lapse=!time_lapse;
<a name="l351"></a> tmpse=</span><span class=cF5>MenuEntryFind</span><span class=cF0>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_menu,</span><span class=cF6>&quot;Play/TimeLapse&quot;</span><span class=cF0>);
<a name="l352"></a> tmpse-&gt;checked=time_lapse;
<a name="l353"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l354"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'2'</span><span class=cF0>:
<a name="l355"></a> tap_mode=!tap_mode;
<a name="l356"></a> tmpse=</span><span class=cF5>MenuEntryFind</span><span class=cF0>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_menu,</span><span class=cF6>&quot;Play/TapMode&quot;</span><span class=cF0>);
<a name="l357"></a> tmpse-&gt;checked=tap_mode;
<a name="l358"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l359"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
<a name="l360"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
<a name="l361"></a> </span><span class=cF1>goto</span><span class=cF0> wg_done;
<a name="l362"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
<a name="l363"></a> Init;
<a name="l364"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l365"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l366"></a> </span><span class=cF5>Sleep</span><span class=cF0>(40);
<a name="l367"></a> </span><span class=cF1>if</span><span class=cF0> (ai_mode==AI_TARGET)
<a name="l368"></a> DoAiTarget;
<a name="l369"></a> UpdateHumanVelocities;
<a name="l370"></a> UpdatePos;
<a name="l371"></a> ResolveFiring;
<a name="l372"></a> }
<a name="l373"></a>wg_done:
<a name="l374"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l375"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l376"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l377"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l378"></a>}
<a name="l379"></a>
<a name="l380"></a>BattleLines;
</span></pre></body>
</html>