ZealOS/docs/Demo/Games/TreeCheckers.CC.html
TomAwezome dbf8647d59 Fixed non-writable drive throw on F5 and Ctrl-S.
Added top & right borders to RawDr.
Improved spacing in some debug and compiler reporting.
Fixed RawPutChar and EdLite tab width.
Fixed Ui missing '0x' prefix syntax highlighter bug.
Added 32BitPaint demo.
2021-07-14 18:38:02 -04:00

463 lines
41 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.08">
<style type="text/css">
body {background-color:#000000;}
.cF0{color:#ffffff;background-color:#000000;}
.cF1{color:#3465a4;background-color:#000000;}
.cF2{color:#4e9a06;background-color:#000000;}
.cF3{color:#06989a;background-color:#000000;}
.cF4{color:#a24444;background-color:#000000;}
.cF5{color:#75507b;background-color:#000000;}
.cF6{color:#ce982f;background-color:#000000;}
.cF7{color:#bcc0b9;background-color:#000000;}
.cF8{color:#555753;background-color:#000000;}
.cF9{color:#729fcf;background-color:#000000;}
.cFA{color:#82bc49;background-color:#000000;}
.cFB{color:#34e2e2;background-color:#000000;}
.cFC{color:#ac3535;background-color:#000000;}
.cFD{color:#ad7fa8;background-color:#000000;}
.cFE{color:#fce94f;background-color:#000000;}
.cFF{color:#000000;background-color:#000000;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF1>U0</span><span class=cF0> InitDefines()
<a name="l2"></a>{
<a name="l3"></a> </span><span class=cF9>I64</span><span class=cF0> w = </span><span class=cF3>GR_WIDTH</span><span class=cF0>, h = </span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>, cols, rows, size = </span><span class=cF5>PopUpRangeI64</span><span class=cF0>(</span><span class=cFE>1</span><span class=cF0>,</span><span class=cFE>9</span><span class=cF0>,, </span><span class=cF6>&quot;Size\n&quot;</span><span class=cF0>), rad = </span><span class=cFE>16</span><span class=cF0> - size;
<a name="l4"></a>
<a name="l5"></a> </span><span class=cF1>if</span><span class=cF0> (size &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l6"></a> </span><span class=cF5>throw</span><span class=cF0>;
<a name="l7"></a> </span><span class=cF5>DefinePrint</span><span class=cF0>(</span><span class=cF6>&quot;UNITS_NUM&quot;</span><span class=cF0>, </span><span class=cF6>&quot;%d&quot;</span><span class=cF0>, </span><span class=cFE>4096</span><span class=cF0> / </span><span class=cF5>SqrI64</span><span class=cF7>(</span><span class=cF0>rad</span><span class=cF7>)</span><span class=cF0> &amp; ~</span><span class=cFE>1</span><span class=cF0>);
<a name="l8"></a> </span><span class=cF5>DefinePrint</span><span class=cF0>(</span><span class=cF6>&quot;CIRCLE_RAD&quot;</span><span class=cF0>, </span><span class=cF6>&quot;%d&quot;</span><span class=cF0>, rad);
<a name="l9"></a> </span><span class=cF5>DefinePrint</span><span class=cF0>(</span><span class=cF6>&quot;MOVE_CIRCLES&quot;</span><span class=cF0>, </span><span class=cF6>&quot;%d&quot;</span><span class=cF0>, </span><span class=cFE>65</span><span class=cF0> / rad);
<a name="l10"></a>
<a name="l11"></a> cols = (w - </span><span class=cFE>8</span><span class=cF0> - rad) / (</span><span class=cFE>2</span><span class=cF0> * rad) &amp; ~</span><span class=cFE>1</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>;
<a name="l12"></a> </span><span class=cF5>DefinePrint</span><span class=cF0>(</span><span class=cF6>&quot;BORDER_X&quot;</span><span class=cF0>, </span><span class=cF6>&quot;%d&quot;</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>w + rad - cols * </span><span class=cFE>2</span><span class=cF0> * rad</span><span class=cF7>)</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>);
<a name="l13"></a>
<a name="l14"></a> rows = (h - </span><span class=cFE>8</span><span class=cF0>) / (</span><span class=cFE>2</span><span class=cF0> * rad) &amp; ~</span><span class=cFE>1</span><span class=cF0>;
<a name="l15"></a> </span><span class=cF5>DefinePrint</span><span class=cF0>(</span><span class=cF6>&quot;BORDER_Y&quot;</span><span class=cF0>,</span><span class=cF6>&quot;%d&quot;</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>h - rows * </span><span class=cFE>2</span><span class=cF0> * rad</span><span class=cF7>)</span><span class=cF0> / </span><span class=cFE>2</span><span class=cF0>);
<a name="l16"></a>
<a name="l17"></a>} InitDefines;
<a name="l18"></a>
<a name="l19"></a></span><span class=cF1>class</span><span class=cF0> Unit
<a name="l20"></a>{
<a name="l21"></a> </span><span class=cF9>I64</span><span class=cF0> num, x, y, player, link, color;
<a name="l22"></a> </span><span class=cF1>Bool</span><span class=cF0> alive, king;
<a name="l23"></a>
<a name="l24"></a>} u[UNITS_NUM];
<a name="l25"></a>
<a name="l26"></a></span><span class=cF9>CDC</span><span class=cF0> *map_dc;
<a name="l27"></a></span><span class=cF9>I64</span><span class=cF0> cur_player, num_alive[</span><span class=cFE>2</span><span class=cF0>], start_x, start_y, end_x, end_y;
<a name="l28"></a></span><span class=cF1>Bool</span><span class=cF0> show_start;
<a name="l29"></a>
<a name="l30"></a></span><span class=cF1>U0</span><span class=cF0> S2Circle(</span><span class=cF9>I64</span><span class=cF0> *_x, </span><span class=cF9>I64</span><span class=cF0> *_y)
<a name="l31"></a>{
<a name="l32"></a> </span><span class=cF9>I64</span><span class=cF0> i, j;
<a name="l33"></a>
<a name="l34"></a> j = (*_y - BORDER_Y) / (CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>);
<a name="l35"></a> </span><span class=cF1>if</span><span class=cF0> (j &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l36"></a> i = (*_x - CIRCLE_RAD - BORDER_X) / (CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>);
<a name="l37"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l38"></a> i = (*_x - BORDER_X) / (CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>);
<a name="l39"></a> *_y = j;
<a name="l40"></a> *_x = i;
<a name="l41"></a>}
<a name="l42"></a>
<a name="l43"></a></span><span class=cF1>U0</span><span class=cF0> Circle2S(</span><span class=cF9>I64</span><span class=cF0> *_x, </span><span class=cF9>I64</span><span class=cF0> *_y)
<a name="l44"></a>{
<a name="l45"></a> </span><span class=cF9>I64</span><span class=cF0> j = *_y, i = *_x;
<a name="l46"></a>
<a name="l47"></a> *_y = j * CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0> + CIRCLE_RAD + BORDER_Y;
<a name="l48"></a> *_x = i * CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0> + CIRCLE_RAD + BORDER_X;
<a name="l49"></a> </span><span class=cF1>if</span><span class=cF0> (j &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l50"></a> *_x += CIRCLE_RAD;
<a name="l51"></a>}
<a name="l52"></a>
<a name="l53"></a></span><span class=cF1>U0</span><span class=cF0> S2W(</span><span class=cF9>I64</span><span class=cF0> *_x, </span><span class=cF9>I64</span><span class=cF0> *_y)
<a name="l54"></a>{
<a name="l55"></a> S2Circle(_x, _y);
<a name="l56"></a> Circle2S(_x, _y);
<a name="l57"></a>}
<a name="l58"></a>
<a name="l59"></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="l60"></a>{
<a name="l61"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l62"></a>
<a name="l63"></a> map_dc-&gt;flags |= </span><span class=cF3>DCF_NO_TRANSPARENTS</span><span class=cF0>;
<a name="l64"></a> </span><span class=cF5>GrBlot</span><span class=cF0>(dc, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, map_dc);
<a name="l65"></a>
<a name="l66"></a> </span><span class=cF1>if</span><span class=cF0> (cur_player == </span><span class=cFE>0</span><span class=cF0>)
<a name="l67"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l68"></a> dc-&gt;color = </span><span class=cF3>LTCYAN</span><span class=cF0>;
<a name="l69"></a> </span><span class=cF5>GrFloodFill</span><span class=cF0>(dc, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l70"></a> dc-&gt;color = </span><span class=cF3>CYAN</span><span class=cF0>;
<a name="l71"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l72"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l73"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l74"></a> dc-&gt;color = </span><span class=cF3>LTPURPLE</span><span class=cF0>;
<a name="l75"></a> </span><span class=cF5>GrFloodFill</span><span class=cF0>(dc, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l76"></a> dc-&gt;color = </span><span class=cF3>PURPLE</span><span class=cF0>;
<a name="l77"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l78"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cFE>2</span><span class=cF0>, </span><span class=cFE>2</span><span class=cF0>, </span><span class=cF6>&quot;Player %d&quot;</span><span class=cF0>, cur_player + </span><span class=cFE>1</span><span class=cF0>);
<a name="l79"></a>
<a name="l80"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; UNITS_NUM; i++)
<a name="l81"></a> </span><span class=cF1>if</span><span class=cF0> (u[i].alive)
<a name="l82"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l83"></a> dc-&gt;color = u[i].color;
<a name="l84"></a> </span><span class=cF5>GrFloodFill</span><span class=cF0>(dc, u[i].x, u[i].y);
<a name="l85"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l86"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; UNITS_NUM; i++)
<a name="l87"></a> </span><span class=cF1>if</span><span class=cF0> (u[i].alive &amp;&amp; !u[i].king)
<a name="l88"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l89"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l90"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, u[i].x, u[i].y, u[u[i].link].x, u[u[i].link].y);
<a name="l91"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Blink</span><span class=cF0>)
<a name="l92"></a> {
<a name="l93"></a> dc-&gt;color = </span><span class=cF3>BLUE</span><span class=cF0>;
<a name="l94"></a> dc-&gt;thick = </span><span class=cFE>6</span><span class=cF0>;
<a name="l95"></a> </span><span class=cF5>GrPlot3</span><span class=cF0>(dc, </span><span class=cF7>(</span><span class=cF0>u[i].x + u[u[i].link].x</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>1</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>u[i].y + u[u[i].link].y</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>1</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
<a name="l96"></a> }
<a name="l97"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l98"></a> </span><span class=cF1>if</span><span class=cF0> (show_start)
<a name="l99"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l100"></a> dc-&gt;color = </span><span class=cF3>LTRED</span><span class=cF0>;
<a name="l101"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, start_x - </span><span class=cFE>4</span><span class=cF0>, start_y - </span><span class=cFE>4</span><span class=cF0>, start_x + </span><span class=cFE>4</span><span class=cF0>, start_y + </span><span class=cFE>4</span><span class=cF0>);
<a name="l102"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, start_x - </span><span class=cFE>4</span><span class=cF0>, start_y + </span><span class=cFE>4</span><span class=cF0>, start_x + </span><span class=cFE>4</span><span class=cF0>, start_y - </span><span class=cFE>4</span><span class=cF0>);
<a name="l103"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, start_x, start_y, end_x, end_y);
<a name="l104"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l105"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>num_alive[</span><span class=cFE>0</span><span class=cF0>] == </span><span class=cFE>1</span><span class=cF0> || num_alive[</span><span class=cFE>1</span><span class=cF0>] == </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> &amp;&amp; </span><span class=cF5>Blink</span><span class=cF7>(</span><span class=cFE>4</span><span class=cF7>)</span><span class=cF0>)
<a name="l106"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l107"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l108"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cF7>(</span><span class=cF0>task-&gt;pix_width - </span><span class=cF3>FONT_WIDTH</span><span class=cF0> * </span><span class=cFE>9</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>1</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>task-&gt;pix_height - </span><span class=cF3>FONT_HEIGHT</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>1</span><span class=cF0>, </span><span class=cF6>&quot;Game Over&quot;</span><span class=cF0>);
<a name="l109"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l110"></a>}
<a name="l111"></a>
<a name="l112"></a>Unit *UnitFind(</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> player)
<a name="l113"></a>{
<a name="l114"></a> </span><span class=cF9>I64</span><span class=cF0> i, dd, best_dd = </span><span class=cF3>I64_MAX</span><span class=cF0>;
<a name="l115"></a> Unit *res = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l116"></a>
<a name="l117"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; UNITS_NUM; i++)
<a name="l118"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l119"></a> </span><span class=cF1>if</span><span class=cF0> (u[i].player == player &amp;&amp; u[i].alive)
<a name="l120"></a> {
<a name="l121"></a> dd = </span><span class=cF5>SqrI64</span><span class=cF0>(u[i].x - x) + </span><span class=cF5>SqrI64</span><span class=cF0>(u[i].y - y);
<a name="l122"></a> </span><span class=cF1>if</span><span class=cF0> (dd &lt; best_dd)
<a name="l123"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l124"></a> best_dd = dd;
<a name="l125"></a> res = &amp;u[i];
<a name="l126"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l127"></a> }
<a name="l128"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l129"></a>
<a name="l130"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l131"></a>}
<a name="l132"></a>
<a name="l133"></a></span><span class=cF1>U0</span><span class=cF0> KillsCheck(</span><span class=cF9>I64</span><span class=cF0> x1, </span><span class=cF9>I64</span><span class=cF0> y1, </span><span class=cF9>I64</span><span class=cF0> player)
<a name="l134"></a>{
<a name="l135"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, x2, y2, dd;
<a name="l136"></a> </span><span class=cF1>Bool</span><span class=cF0> found;
<a name="l137"></a>
<a name="l138"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; UNITS_NUM; i++)
<a name="l139"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l140"></a> </span><span class=cF1>if</span><span class=cF0> (u[i].player != player &amp;&amp; u[i].alive &amp;&amp; !u[i].king)
<a name="l141"></a> {
<a name="l142"></a> x2 = (u[i].x + u[u[i].link].x) &gt;&gt; </span><span class=cFE>1</span><span class=cF0>;
<a name="l143"></a> y2 = (u[i].y + u[u[i].link].y) &gt;&gt; </span><span class=cFE>1</span><span class=cF0>;
<a name="l144"></a> dd = </span><span class=cF5>SqrI64</span><span class=cF0>(x2 - x1) + </span><span class=cF5>SqrI64</span><span class=cF0>(y2 - y1);
<a name="l145"></a> </span><span class=cF1>if</span><span class=cF0> (dd &lt;= </span><span class=cF7>(</span><span class=cF0>CIRCLE_RAD + </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0> * </span><span class=cF7>(</span><span class=cF0>CIRCLE_RAD + </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0>)
<a name="l146"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l147"></a> u[i].alive = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l148"></a> </span><span class=cF5>Sound</span><span class=cF0>(</span><span class=cFE>62</span><span class=cF0>);
<a name="l149"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>100</span><span class=cF0>);
<a name="l150"></a> </span><span class=cF5>Sound</span><span class=cF0>;
<a name="l151"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>25</span><span class=cF0>);
<a name="l152"></a> num_alive[u[i].player]--;
<a name="l153"></a> </span><span class=cF1>do</span><span class=cF0>
<a name="l154"></a> {
<a name="l155"></a> found = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l156"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; UNITS_NUM; j++)
<a name="l157"></a> </span><span class=cF1>if</span><span class=cF0> (u[j].alive &amp;&amp; u[j].player != player &amp;&amp; !u[j].king &amp;&amp; !u[u[j].link].alive)
<a name="l158"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l159"></a> found = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l160"></a> u[j].alive = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l161"></a> </span><span class=cF5>Sound</span><span class=cF0>(</span><span class=cFE>62</span><span class=cF0>);
<a name="l162"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>100</span><span class=cF0>);
<a name="l163"></a> </span><span class=cF5>Sound</span><span class=cF0>;
<a name="l164"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>25</span><span class=cF0>);
<a name="l165"></a> num_alive[u[j].player]--;
<a name="l166"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l167"></a> }
<a name="l168"></a> </span><span class=cF1>while</span><span class=cF0> (found);
<a name="l169"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l170"></a> }
<a name="l171"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l172"></a>}
<a name="l173"></a>
<a name="l174"></a></span><span class=cF1>Bool</span><span class=cF0> UnitMove(Unit *tmpu, </span><span class=cF9>I64</span><span class=cF0> x2, </span><span class=cF9>I64</span><span class=cF0> y2)
<a name="l175"></a>{
<a name="l176"></a> </span><span class=cF9>I64</span><span class=cF0> i, r, c, r2, c2, x = start_x, y = start_y;
<a name="l177"></a>
<a name="l178"></a> S2W(&amp;x2, &amp;y2);
<a name="l179"></a> c2 = x2;
<a name="l180"></a> r2 = y2;
<a name="l181"></a> S2Circle(&amp;c2, &amp;r2);
<a name="l182"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; MOVE_CIRCLES + </span><span class=cFE>1</span><span class=cF0>; i++)
<a name="l183"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l184"></a> c = x;
<a name="l185"></a> r = y;
<a name="l186"></a> S2Circle(&amp;c, &amp;r);
<a name="l187"></a> </span><span class=cF1>if</span><span class=cF0> (c == c2 &amp;&amp; r == r2)
<a name="l188"></a> {
<a name="l189"></a> end_x = tmpu-&gt;x = x2;
<a name="l190"></a> end_y = tmpu-&gt;y = y2;
<a name="l191"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l192"></a> }
<a name="l193"></a> </span><span class=cF1>if</span><span class=cF0> (r2 != r)
<a name="l194"></a> {
<a name="l195"></a> </span><span class=cF1>if</span><span class=cF0> (r&amp;</span><span class=cFE>1</span><span class=cF0>)
<a name="l196"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l197"></a> </span><span class=cF1>if</span><span class=cF0> (c &lt; c2)
<a name="l198"></a> c++;
<a name="l199"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l200"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l201"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l202"></a> </span><span class=cF1>if</span><span class=cF0> (c &gt; c2)
<a name="l203"></a> c--;
<a name="l204"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l205"></a> }
<a name="l206"></a> </span><span class=cF1>if</span><span class=cF0> (r2 &gt; r)
<a name="l207"></a> {
<a name="l208"></a> x = c;
<a name="l209"></a> y = ++r;
<a name="l210"></a> Circle2S(&amp;x, &amp;y);
<a name="l211"></a> }
<a name="l212"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (r2 &lt; r)
<a name="l213"></a> {
<a name="l214"></a> x = c;
<a name="l215"></a> y = --r;
<a name="l216"></a> Circle2S(&amp;x, &amp;y);
<a name="l217"></a> }
<a name="l218"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (c2 &gt; c)
<a name="l219"></a> {
<a name="l220"></a> x = ++c;
<a name="l221"></a> y = r;
<a name="l222"></a> Circle2S(&amp;x, &amp;y);
<a name="l223"></a> }
<a name="l224"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (c2 &lt; c)
<a name="l225"></a> {
<a name="l226"></a> x = --c;
<a name="l227"></a> y = r;
<a name="l228"></a> Circle2S(&amp;x, &amp;y);
<a name="l229"></a> }
<a name="l230"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l231"></a>
<a name="l232"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l233"></a>}
<a name="l234"></a>
<a name="l235"></a></span><span class=cF9>CDC</span><span class=cF0> *DrawHexMap(</span><span class=cF9>I64</span><span class=cF0> *_w, </span><span class=cF9>I64</span><span class=cF0> *_h)
<a name="l236"></a>{
<a name="l237"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc = </span><span class=cF5>DCNew</span><span class=cF0>(*_w, *_h);
<a name="l238"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, x, y;
<a name="l239"></a>
<a name="l240"></a> *_w = (dc-&gt;width - BORDER_X * </span><span class=cFE>2</span><span class=cF0> - CIRCLE_RAD) / (CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>);
<a name="l241"></a> *_h = (dc-&gt;height - BORDER_Y * </span><span class=cFE>2</span><span class=cF0>) / (CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>);
<a name="l242"></a> </span><span class=cF5>DCFill</span><span class=cF0>(dc, </span><span class=cF3>WHITE</span><span class=cF0>);
<a name="l243"></a> dc-&gt;color =</span><span class=cF3>LTGRAY</span><span class=cF0>;
<a name="l244"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; *_h; j++)
<a name="l245"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l246"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; *_w; i++)
<a name="l247"></a> {
<a name="l248"></a> x = i * CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0> + BORDER_X + CIRCLE_RAD;
<a name="l249"></a> y = j * CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0> + BORDER_Y + CIRCLE_RAD;
<a name="l250"></a> </span><span class=cF1>if</span><span class=cF0> (j &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l251"></a> x += CIRCLE_RAD;
<a name="l252"></a> S2W(&amp;x, &amp;y);
<a name="l253"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc, x, y, CIRCLE_RAD);
<a name="l254"></a> }
<a name="l255"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l256"></a> *_w *= CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>;
<a name="l257"></a> *_h *= CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>;
<a name="l258"></a>
<a name="l259"></a> </span><span class=cF1>return</span><span class=cF0> dc;
<a name="l260"></a>}
<a name="l261"></a>
<a name="l262"></a></span><span class=cF1>U0</span><span class=cF0> Init()
<a name="l263"></a>{
<a name="l264"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, j1, j2, dd, best_dd, best, w = </span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_width, h = </span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_height;
<a name="l265"></a>
<a name="l266"></a> map_dc = DrawHexMap(&amp;w, &amp;h);
<a name="l267"></a> cur_player = </span><span class=cFE>0</span><span class=cF0>;
<a name="l268"></a>
<a name="l269"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>; i++)
<a name="l270"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l271"></a> u[i].num = i;
<a name="l272"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].num = i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>;
<a name="l273"></a>
<a name="l274"></a>ti_restart:
<a name="l275"></a> u[i].y = </span><span class=cF5>FloorI64</span><span class=cF0>(</span><span class=cF5>RandU32</span><span class=cF0> % h, CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>) + CIRCLE_RAD;
<a name="l276"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].y = h - </span><span class=cFE>1</span><span class=cF0> - u[i].y;
<a name="l277"></a> j1 = u[i].y / (CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>);
<a name="l278"></a> j2 = u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].y / (CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>);
<a name="l279"></a> u[i].y += BORDER_Y;
<a name="l280"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].y += BORDER_Y;
<a name="l281"></a>
<a name="l282"></a> </span><span class=cF1>if</span><span class=cF0> (!i)
<a name="l283"></a> {
<a name="l284"></a> u[i].x = CIRCLE_RAD;
<a name="l285"></a> </span><span class=cF1>if</span><span class=cF0> (j1 &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l286"></a> </span><span class=cF1>goto</span><span class=cF0> ti_restart;
<a name="l287"></a> }
<a name="l288"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l289"></a> u[i].x = </span><span class=cF5>FloorI64</span><span class=cF0>(</span><span class=cF5>RandU32</span><span class=cF0> % </span><span class=cF7>(</span><span class=cF0>(w - CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0> * </span><span class=cFE>2</span><span class=cF0>) / </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0>, CIRCLE_RAD * </span><span class=cFE>2</span><span class=cF0>) + CIRCLE_RAD;
<a name="l290"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].x = w - </span><span class=cFE>1</span><span class=cF0> - u[i].x;
<a name="l291"></a>
<a name="l292"></a> </span><span class=cF1>if</span><span class=cF0> (j1 &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l293"></a> u[i].x += CIRCLE_RAD;
<a name="l294"></a> </span><span class=cF1>if</span><span class=cF0> (j2 &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l295"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].x += CIRCLE_RAD;
<a name="l296"></a> u[i].x += BORDER_X;
<a name="l297"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].x += BORDER_X;
<a name="l298"></a>
<a name="l299"></a> S2W(&amp;u[i].x, &amp;u[i].y);
<a name="l300"></a> S2W(&amp;u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].x, &amp;u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].y);
<a name="l301"></a>
<a name="l302"></a> u[i].player = </span><span class=cFE>0</span><span class=cF0>;
<a name="l303"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].player = </span><span class=cFE>1</span><span class=cF0>;
<a name="l304"></a>
<a name="l305"></a> u[i].alive = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l306"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].alive = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l307"></a>
<a name="l308"></a> </span><span class=cF1>if</span><span class=cF0> (!i)
<a name="l309"></a> {
<a name="l310"></a> u[i].color = </span><span class=cF3>LTCYAN</span><span class=cF0>;
<a name="l311"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].color = </span><span class=cF3>LTPURPLE</span><span class=cF0>;
<a name="l312"></a> u[i].king = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l313"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].king = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l314"></a> }
<a name="l315"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l316"></a> {
<a name="l317"></a> u[i].color = </span><span class=cF3>CYAN</span><span class=cF0>;
<a name="l318"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].color = </span><span class=cF3>PURPLE</span><span class=cF0>;
<a name="l319"></a> u[i].king = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l320"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].king = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l321"></a> }
<a name="l322"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l323"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>; i++)
<a name="l324"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l325"></a> </span><span class=cF1>if</span><span class=cF0> (!u[i].king)
<a name="l326"></a> {
<a name="l327"></a> best_dd = </span><span class=cF3>I64_MAX</span><span class=cF0>;
<a name="l328"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>; j++)
<a name="l329"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l330"></a> </span><span class=cF1>if</span><span class=cF0> (i != j)
<a name="l331"></a> {
<a name="l332"></a> dd = </span><span class=cF5>SqrI64</span><span class=cF0>(u[i].x - u[j].x) + </span><span class=cF5>SqrI64</span><span class=cF0>(u[i].y - u[j].y);
<a name="l333"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>u[j].x &lt; u[i].x || u[j].king</span><span class=cF7>)</span><span class=cF0> &amp;&amp; dd &lt; best_dd )
<a name="l334"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l335"></a> best_dd = dd;
<a name="l336"></a> best = j;
<a name="l337"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l338"></a> }
<a name="l339"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l340"></a> u[i].link = best;
<a name="l341"></a> u[i + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>].link = best + UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>;
<a name="l342"></a> }
<a name="l343"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l344"></a> num_alive[</span><span class=cFE>0</span><span class=cF0>] = UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>;
<a name="l345"></a> num_alive[</span><span class=cFE>1</span><span class=cF0>] = UNITS_NUM / </span><span class=cFE>2</span><span class=cF0>;
<a name="l346"></a>}
<a name="l347"></a>
<a name="l348"></a></span><span class=cF1>U0</span><span class=cF0> CleanUp()
<a name="l349"></a>{
<a name="l350"></a> </span><span class=cF5>DCDel</span><span class=cF0>(map_dc);
<a name="l351"></a>}
<a name="l352"></a>
<a name="l353"></a></span><span class=cF1>U0</span><span class=cF0> TreeCheckers()
<a name="l354"></a>{
<a name="l355"></a> </span><span class=cF9>I64</span><span class=cF0> message_code, arg1, arg2, ch, sc;
<a name="l356"></a> Unit *tmpu;
<a name="l357"></a>
<a name="l358"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="https://tomawezome.github.io/ZealOS/System/TaskSettings.CC.html#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l359"></a> </span><span class=cF5>MenuPush</span><span class=cF0>( </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l360"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l361"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l362"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l363"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l364"></a> </span><span class=cF6>&quot; Restart(,'\n');&quot;</span><span class=cF0>
<a name="l365"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l366"></a> );
<a name="l367"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l368"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l369"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l370"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l371"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l372"></a> </span><span class=cF5>PopUpOk</span><span class=cF0>(</span><span class=cF6>&quot;Step on the link mid points.\n&quot;</span><span class=cF0>);
<a name="l373"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;win_inhibit = </span><span class=cF3>WIG_TASK_DEFAULT</span><span class=cF0> - </span><span class=cF3>WIF_SELF_FOCUS</span><span class=cF0> - </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="l374"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l375"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l376"></a>cn_start:
<a name="l377"></a> Init;
<a name="l378"></a> tmpu = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l379"></a> show_start = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l380"></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="l381"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l382"></a> {
<a name="l383"></a> message_code = </span><span class=cF5>MessageGet</span><span class=cF0>(&amp;arg1, &amp;arg2,
<a name="l384"></a> </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0> + </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_L_DOWN</span><span class=cF0> + </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_L_UP</span><span class=cF0> + </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_MOVE</span><span class=cF0>);
<a name="l385"></a> </span><span class=cF1>switch</span><span class=cF0> (message_code)
<a name="l386"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l387"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0>:
<a name="l388"></a> </span><span class=cF1>switch</span><span class=cF0> (arg1)
<a name="l389"></a> {
<a name="l390"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
<a name="l391"></a> CleanUp;
<a name="l392"></a> </span><span class=cF1>goto</span><span class=cF0> cn_start;
<a name="l393"></a>
<a name="l394"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
<a name="l395"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
<a name="l396"></a> </span><span class=cF1>goto</span><span class=cF0> cn_done;
<a name="l397"></a> }
<a name="l398"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l399"></a>
<a name="l400"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_MS_L_DOWN</span><span class=cF0>:
<a name="l401"></a> </span><span class=cF1>if</span><span class=cF0> (num_alive[</span><span class=cFE>0</span><span class=cF0>] &gt; </span><span class=cFE>1</span><span class=cF0> &amp;&amp; num_alive[</span><span class=cFE>1</span><span class=cF0>] &gt; </span><span class=cFE>1</span><span class=cF0>)
<a name="l402"></a> {
<a name="l403"></a> tmpu = UnitFind(arg1, arg2, cur_player);
<a name="l404"></a> end_x = start_x = tmpu-&gt;x;
<a name="l405"></a> end_y = start_y = tmpu-&gt;y;
<a name="l406"></a> show_start = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l407"></a> }
<a name="l408"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l409"></a>
<a name="l410"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_MS_MOVE</span><span class=cF0>:
<a name="l411"></a> </span><span class=cF1>if</span><span class=cF0> (tmpu)
<a name="l412"></a> UnitMove(tmpu, arg1, arg2);
<a name="l413"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l414"></a>
<a name="l415"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_MS_L_UP</span><span class=cF0>:
<a name="l416"></a> UnitMove(tmpu, arg1, arg2);
<a name="l417"></a> KillsCheck(tmpu-&gt;x, tmpu-&gt;y, cur_player);
<a name="l418"></a> show_start = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l419"></a> tmpu = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l420"></a> cur_player = </span><span class=cFE>1</span><span class=cF0> - cur_player;
<a name="l421"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l422"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l423"></a> }
<a name="l424"></a>cn_done:
<a name="l425"></a> </span><span class=cF5>MessageGet</span><span class=cF0>(,, </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_UP</span><span class=cF0>);
<a name="l426"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l427"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l428"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l429"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l430"></a> CleanUp;
<a name="l431"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l432"></a>}
<a name="l433"></a>
<a name="l434"></a>TreeCheckers;
</span></pre></body>
</html>