templeos-info/public/Wb/Apps/ToTheFront/TTFMove.HC.HTML

161 lines
12 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">
.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=cF1>U8</span><span class=cF0> movement_costs[16];
<a name="l2"></a>movement_costs[PLAINS]=2;
<a name="l3"></a>movement_costs[TREES]=6;
<a name="l4"></a>movement_costs[MOUNTAINS]=10;
<a name="l5"></a>
<a name="l6"></a></span><span class=cF9>I64</span><span class=cF0> HexMoveOneCost(Unit *tmpu,</span><span class=cF9>I64</span><span class=cF0> r,</span><span class=cF9>I64</span><span class=cF0> c,</span><span class=cF9>I64</span><span class=cF0> facing)
<a name="l7"></a>{
<a name="l8"></a> </span><span class=cF9>I64</span><span class=cF0> res;
<a name="l9"></a> </span><span class=cF1>if</span><span class=cF0> (tmpu-&gt;infantry)
<a name="l10"></a> res=0;
<a name="l11"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l12"></a> res=FacingChg(facing,tmpu-&gt;facing);
<a name="l13"></a> </span><span class=cF1>if</span><span class=cF0> (res&gt;0) res--;
<a name="l14"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l15"></a> </span><span class=cF1>if</span><span class=cF0> (roads[r][c] &amp;&amp; roads[tmpu-&gt;row][tmpu-&gt;col])
<a name="l16"></a> res+=1;
<a name="l17"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l18"></a> </span><span class=cF1>if</span><span class=cF0> (tmpu-&gt;infantry)
<a name="l19"></a> res+=2;
<a name="l20"></a> </span><span class=cF1>else</span><span class=cF0> {
<a name="l21"></a> res+=movement_costs[terrain[r][c]];
<a name="l22"></a> </span><span class=cF1>if</span><span class=cF0> (rivers[r][c])
<a name="l23"></a> res=tmpu-&gt;movement;
<a name="l24"></a> }
<a name="l25"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l26"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l27"></a>}
<a name="l28"></a>
<a name="l29"></a></span><span class=cF9>I64</span><span class=cF0> HexMoveOne(</span><span class=cF9>I64</span><span class=cF0> *_row,</span><span class=cF9>I64</span><span class=cF0> *_col,</span><span class=cF1>F64</span><span class=cF0> x,</span><span class=cF1>F64</span><span class=cF0> y)
<a name="l30"></a>{
<a name="l31"></a> </span><span class=cF9>I64</span><span class=cF0> direction,best_direction=-1,r,c;
<a name="l32"></a> </span><span class=cF1>F64</span><span class=cF0> dd,best_dd,x1,y1;
<a name="l33"></a> RowCol2XY(&amp;x1,&amp;y1,*_row,*_col);
<a name="l34"></a> best_dd=</span><span class=cF5>Sqr</span><span class=cF0>(x1-x)+</span><span class=cF5>Sqr</span><span class=cF0>(y1-y);
<a name="l35"></a> </span><span class=cF1>for</span><span class=cF0> (direction=0;direction&lt;6;direction++) </span><span class=cF7>{</span><span class=cF0>
<a name="l36"></a> r=*_row; c=*_col;
<a name="l37"></a> Toward(&amp;r,&amp;c,direction);
<a name="l38"></a> RowCol2XY(&amp;x1,&amp;y1,r,c);
<a name="l39"></a> dd=</span><span class=cF5>Sqr</span><span class=cF0>(x1-x)+</span><span class=cF5>Sqr</span><span class=cF0>(y1-y);
<a name="l40"></a> </span><span class=cF1>if</span><span class=cF0> (0&lt;=r&lt;map_rows &amp;&amp; 0&lt;=c&lt;map_cols &amp;&amp; dd&lt;best_dd) {
<a name="l41"></a> best_dd=dd;
<a name="l42"></a> best_direction=direction;
<a name="l43"></a> }
<a name="l44"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l45"></a> </span><span class=cF1>if</span><span class=cF0> (best_direction&gt;=0) </span><span class=cF7>{</span><span class=cF0>
<a name="l46"></a> Toward(_row,_col,best_direction);
<a name="l47"></a> </span><span class=cF1>return</span><span class=cF0> best_direction;
<a name="l48"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l49"></a> </span><span class=cF1>return</span><span class=cF0> -1;
<a name="l50"></a>}
<a name="l51"></a>
<a name="l52"></a></span><span class=cF1>Bool</span><span class=cF0> UnitMovePlot(</span><span class=cF1>U0</span><span class=cF0>,</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y,</span><span class=cF9>I64</span><span class=cF0>)
<a name="l53"></a>{
<a name="l54"></a> move_x=x; move_y=y;
<a name="l55"></a> </span><span class=cF5>Sleep</span><span class=cF0>(5*animation_delay);
<a name="l56"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l57"></a>}
<a name="l58"></a>
<a name="l59"></a></span><span class=cF1>U0</span><span class=cF0> UnitMoveAnimation(Unit *tmpu,</span><span class=cF9>I64</span><span class=cF0> r,</span><span class=cF9>I64</span><span class=cF0> c,</span><span class=cF9>I64</span><span class=cF0> facing)
<a name="l60"></a>{
<a name="l61"></a> </span><span class=cF1>F64</span><span class=cF0> x1,y1,x2,y2,f=facing*60.0*</span><span class=cF3>pi</span><span class=cF0>/180.0;
<a name="l62"></a> moving_unit=tmpu;
<a name="l63"></a> RowCol2XY(&amp;x1,&amp;y1,tmpu-&gt;row,tmpu-&gt;col);
<a name="l64"></a> move_x=x1; move_y=y1;
<a name="l65"></a> moving=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l66"></a> </span><span class=cF1>if</span><span class=cF0> (tmpu-&gt;infantry)
<a name="l67"></a> </span><span class=cF5>Snd</span><span class=cF0>(53);
<a name="l68"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l69"></a> move_facing=tmpu-&gt;facing*60.0*</span><span class=cF3>pi</span><span class=cF0>/180.0;
<a name="l70"></a> </span><span class=cF5>Snd</span><span class=cF0>(41);
<a name="l71"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>Wrap</span><span class=cF7>(</span><span class=cF0>f-move_facing,-</span><span class=cF3>pi</span><span class=cF7>)</span><span class=cF0>&lt;=0) {
<a name="l72"></a> move_facing-=0.03;
<a name="l73"></a> </span><span class=cF5>Sleep</span><span class=cF0>(5*animation_delay);
<a name="l74"></a> }
<a name="l75"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>Wrap</span><span class=cF7>(</span><span class=cF0>f-move_facing,-</span><span class=cF3>pi</span><span class=cF7>)</span><span class=cF0>&gt;0) {
<a name="l76"></a> move_facing+=0.03;
<a name="l77"></a> </span><span class=cF5>Sleep</span><span class=cF0>(5*animation_delay);
<a name="l78"></a> }
<a name="l79"></a> </span><span class=cF5>Snd</span><span class=cF0>(34);
<a name="l80"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l81"></a> move_facing=f;
<a name="l82"></a> RowCol2XY(&amp;x2,&amp;y2,r,c);
<a name="l83"></a> </span><span class=cF5>Line</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>,x1,y1,0,x2,y2,0,&amp;UnitMovePlot);
<a name="l84"></a> </span><span class=cF5>Snd</span><span class=cF0>;
<a name="l85"></a> moving_unit=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l86"></a> moving=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l87"></a>}
<a name="l88"></a>
<a name="l89"></a></span><span class=cF1>Bool</span><span class=cF0> UnitMove(Unit *tmpu,</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y)
<a name="l90"></a>{
<a name="l91"></a> Unit *target;
<a name="l92"></a> </span><span class=cF9>I64</span><span class=cF0> r,c,r0=tmpu-&gt;row,c0=tmpu-&gt;col,i,facing;
<a name="l93"></a> </span><span class=cF1>while</span><span class=cF0> (tmpu-&gt;remaining_movement&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l94"></a> r=tmpu-&gt;row;
<a name="l95"></a> c=tmpu-&gt;col;
<a name="l96"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>facing=HexMoveOne(&amp;r,&amp;c,x,y)</span><span class=cF7>)</span><span class=cF0>&lt;0)
<a name="l97"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l98"></a> </span><span class=cF1>else</span><span class=cF0> {
<a name="l99"></a> i=HexMoveOneCost(tmpu,r,c,facing);
<a name="l100"></a> </span><span class=cF1>if</span><span class=cF0> (i&gt;tmpu-&gt;movement)
<a name="l101"></a> i=tmpu-&gt;movement;
<a name="l102"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpu-&gt;fired &amp;&amp; tmpu-&gt;remaining_movement&gt;=i &amp;&amp;
<a name="l103"></a> tmpu-&gt;remaining_movement&gt;=tmpu-&gt;movement&gt;&gt;1 &amp;&amp;
<a name="l104"></a> </span><span class=cF7>(</span><span class=cF0>target=UnitFind(r,c)</span><span class=cF7>)</span><span class=cF0> &amp;&amp; target-&gt;player!=tmpu-&gt;player &amp;&amp;
<a name="l105"></a> tmpu-&gt;infantry!=target-&gt;infantry) </span><span class=cF7>{</span><span class=cF0>
<a name="l106"></a> </span><span class=cF1>if</span><span class=cF0> (!HexOccupy</span><span class=cF7>(</span><span class=cF5>ToBool</span><span class=cF0>(target-&gt;infantry),tmpu,target</span><span class=cF7>)</span><span class=cF0>) {
<a name="l107"></a> tmpu=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l108"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l109"></a> }
<a name="l110"></a> i=tmpu-&gt;remaining_movement;
<a name="l111"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l112"></a> </span><span class=cF1>if</span><span class=cF0> (tmpu-&gt;remaining_movement&gt;=i &amp;&amp; !UnitFind</span><span class=cF7>(</span><span class=cF0>r,c</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l113"></a> UnitMoveAnimation(tmpu,r,c,facing);
<a name="l114"></a> tmpu-&gt;facing=facing;
<a name="l115"></a> tmpu-&gt;remaining_movement-=i;
<a name="l116"></a> tmpu-&gt;row=r;
<a name="l117"></a> tmpu-&gt;col=c;
<a name="l118"></a> VisRecalc(VR_UPDATE_FRIENDLY_UNIT,tmpu);
<a name="l119"></a> </span><span class=cF5>LBEqu</span><span class=cF0>(&amp;tmpu-&gt;vis[enemy_player],0,
<a name="l120"></a> VisRecalc</span><span class=cF7>(</span><span class=cF0>VR_ONE_ENEMY_UNIT,tmpu</span><span class=cF7>)</span><span class=cF0>);
<a name="l121"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l122"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l123"></a> }
<a name="l124"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l125"></a> </span><span class=cF1>if</span><span class=cF0> (!tmpu || tmpu-&gt;row!=r0 || tmpu-&gt;col!=c0)
<a name="l126"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l127"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l128"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l129"></a>}
</span></pre></body>
</html>