ZealOS/docs/Apps/ToTheFront/TTFLib.ZC.html
2021-12-11 06:10:58 -05:00

174 lines
15 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.07">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF1>U0</span><span class=cF0> Toward(</span><span class=cF9>I64</span><span class=cF0> *_row, </span><span class=cF9>I64</span><span class=cF0> *_col, </span><span class=cF9>I64</span><span class=cF0> direction)
<a name="l2"></a>{
<a name="l3"></a> </span><span class=cF1>switch</span><span class=cF0> (direction)
<a name="l4"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l5"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>:
<a name="l6"></a> *_row -= </span><span class=cFE>2</span><span class=cF0>;
<a name="l7"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l8"></a>
<a name="l9"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>1</span><span class=cF0>:
<a name="l10"></a> </span><span class=cF1>if</span><span class=cF0> (*_row &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l11"></a> *_col += </span><span class=cFE>1</span><span class=cF0>;
<a name="l12"></a> *_row -= </span><span class=cFE>1</span><span class=cF0>;
<a name="l13"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l14"></a>
<a name="l15"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>2</span><span class=cF0>:
<a name="l16"></a> </span><span class=cF1>if</span><span class=cF0> (*_row &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l17"></a> *_col += </span><span class=cFE>1</span><span class=cF0>;
<a name="l18"></a> *_row += </span><span class=cFE>1</span><span class=cF0>;
<a name="l19"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l20"></a>
<a name="l21"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>3</span><span class=cF0>:
<a name="l22"></a> *_row += </span><span class=cFE>2</span><span class=cF0>;
<a name="l23"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l24"></a>
<a name="l25"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>4</span><span class=cF0>:
<a name="l26"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>*_row &amp; </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>)
<a name="l27"></a> *_col -= </span><span class=cFE>1</span><span class=cF0>;
<a name="l28"></a> *_row += </span><span class=cFE>1</span><span class=cF0>;
<a name="l29"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l30"></a>
<a name="l31"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>5</span><span class=cF0>:
<a name="l32"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>*_row&amp;</span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>)
<a name="l33"></a> *_col -= </span><span class=cFE>1</span><span class=cF0>;
<a name="l34"></a> *_row -= </span><span class=cFE>1</span><span class=cF0>;
<a name="l35"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l36"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l37"></a>}
<a name="l38"></a>
<a name="l39"></a></span><span class=cF9>I64</span><span class=cF0> FacingChange(</span><span class=cF9>I64</span><span class=cF0> f1, </span><span class=cF9>I64</span><span class=cF0> f2)
<a name="l40"></a>{
<a name="l41"></a> </span><span class=cF9>I64</span><span class=cF0> res = (f1 + </span><span class=cFE>6</span><span class=cF0> - f2 ) %</span><span class=cFE>6</span><span class=cF0>;
<a name="l42"></a>
<a name="l43"></a> </span><span class=cF1>if</span><span class=cF0> (res &gt;= </span><span class=cFE>3</span><span class=cF0>)
<a name="l44"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>6</span><span class=cF0> - res;
<a name="l45"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l46"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l47"></a>}
<a name="l48"></a>
<a name="l49"></a></span><span class=cF1>U0</span><span class=cF0> RowCol2XY(</span><span class=cF1>F64</span><span class=cF0> *_x, </span><span class=cF1>F64</span><span class=cF0> *_y, </span><span class=cF9>I64</span><span class=cF0> row, </span><span class=cF9>I64</span><span class=cF0> col)
<a name="l50"></a>{
<a name="l51"></a> Pt *c;
<a name="l52"></a>
<a name="l53"></a> row = </span><span class=cF5>ClampI64</span><span class=cF0>(row, </span><span class=cFE>0</span><span class=cF0>, map_rows);
<a name="l54"></a> col = </span><span class=cF5>ClampI64</span><span class=cF0>(col, </span><span class=cFE>0</span><span class=cF0>, map_cols);
<a name="l55"></a> c = &amp;hex_centers[row][col];
<a name="l56"></a> *_x = c-&gt;x;
<a name="l57"></a> *_y = c-&gt;y;
<a name="l58"></a>}
<a name="l59"></a>
<a name="l60"></a></span><span class=cF1>U0</span><span class=cF0> XY2RowCol(</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="l61"></a>{
<a name="l62"></a> *_col = (x - DCOS / </span><span class=cFE>2</span><span class=cF0>) / (HEX_SIDE + DCOS);
<a name="l63"></a> </span><span class=cF1>if</span><span class=cF0> (*_col &amp; </span><span class=cFE>1</span><span class=cF0>)
<a name="l64"></a> *_row = </span><span class=cF5>ToI64</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>y - DSIN</span><span class=cF7>)</span><span class=cF0> / </span><span class=cF7>(</span><span class=cFE>2</span><span class=cF0> * DSIN</span><span class=cF7>)</span><span class=cF0>) * </span><span class=cFE>2</span><span class=cF0> + </span><span class=cFE>1</span><span class=cF0>;
<a name="l65"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l66"></a> *_row = </span><span class=cF5>ToI64</span><span class=cF0>(y / </span><span class=cF7>(</span><span class=cFE>2</span><span class=cF0> * DSIN</span><span class=cF7>)</span><span class=cF0>) * </span><span class=cFE>2</span><span class=cF0>;
<a name="l67"></a> *_col &gt;&gt;= </span><span class=cFE>1</span><span class=cF0>;
<a name="l68"></a> *_row = </span><span class=cF5>ClampI64</span><span class=cF0>(*_row, </span><span class=cFE>0</span><span class=cF0>, map_rows - </span><span class=cFE>1</span><span class=cF0>);
<a name="l69"></a> *_col = </span><span class=cF5>ClampI64</span><span class=cF0>(*_col, </span><span class=cFE>0</span><span class=cF0>, map_cols - </span><span class=cFE>1</span><span class=cF0>);
<a name="l70"></a>}
<a name="l71"></a>
<a name="l72"></a>Unit *UnitFind(</span><span class=cF9>I64</span><span class=cF0> row, </span><span class=cF9>I64</span><span class=cF0> col)
<a name="l73"></a>{</span><span class=cF2>//Finds unit in a hexagon.</span><span class=cF0>
<a name="l74"></a> </span><span class=cF9>I64</span><span class=cF0> i, j;
<a name="l75"></a>
<a name="l76"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; </span><span class=cFE>2</span><span class=cF0>; j++)
<a name="l77"></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="l78"></a> </span><span class=cF1>if</span><span class=cF0> ( units[j][i].life &gt; </span><span class=cFE>0</span><span class=cF0> &amp;&amp;
<a name="l79"></a> units[j][i].row == row &amp;&amp;
<a name="l80"></a> units[j][i].col == col)
<a name="l81"></a> </span><span class=cF1>return</span><span class=cF0> &amp;units[j][i];
<a name="l82"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l83"></a>}
<a name="l84"></a>
<a name="l85"></a></span><span class=cF1>Bool</span><span class=cF0> CursorInWin(</span><span class=cF9>CTask</span><span class=cF0> *task, </span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y)
<a name="l86"></a>{
<a name="l87"></a> </span><span class=cF1>if</span><span class=cF0> ( </span><span class=cFE>0</span><span class=cF0> &lt;= x + task-&gt;scroll_x &lt; task-&gt;pix_width &amp;&amp;
<a name="l88"></a> </span><span class=cFE>0</span><span class=cF0> &lt;= y + task-&gt;scroll_y &lt; task-&gt;pix_height)
<a name="l89"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l90"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l91"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l92"></a>}
<a name="l93"></a>
<a name="l94"></a></span><span class=cF1>U0</span><span class=cF0> CursorUpdate(</span><span class=cF9>CTask</span><span class=cF0> *task, </span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y)
<a name="l95"></a>{
<a name="l96"></a> </span><span class=cF1>if</span><span class=cF0> (CursorInWin</span><span class=cF7>(</span><span class=cF0>task, x, y</span><span class=cF7>)</span><span class=cF0>)
<a name="l97"></a> XY2RowCol(&amp;cursor_row, &amp;cursor_col, x, y);
<a name="l98"></a>}
<a name="l99"></a>
<a name="l100"></a></span><span class=cF1>class</span><span class=cF0> LOSCtrl
<a name="l101"></a>{
<a name="l102"></a> </span><span class=cF9>I64</span><span class=cF0> r1, c1, r2, c2, distance;
<a name="l103"></a>};
<a name="l104"></a>
<a name="l105"></a></span><span class=cF1>Bool</span><span class=cF0> LOSPlot(LOSCtrl *l, </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> z)
<a name="l106"></a>{</span><span class=cF2>//We got tricky and used z as the distance from the start of the line.</span><span class=cF0>
<a name="l107"></a> </span><span class=cF9>I64</span><span class=cF0> row, col;
<a name="l108"></a>
<a name="l109"></a> XY2RowCol(&amp;row, &amp;col, x, y);
<a name="l110"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>row != l-&gt;r1 || col != l-&gt;c1</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l111"></a> </span><span class=cF7>(</span><span class=cF0>row != l-&gt;r2 || col != l-&gt;c2</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l112"></a> terrain[row][col] != PLAINS)
<a name="l113"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l114"></a> </span><span class=cF1>if</span><span class=cF0> (terrain[l-&gt;r1][l-&gt;c1] == MOUNTAINS)
<a name="l115"></a> {
<a name="l116"></a> </span><span class=cF1>if</span><span class=cF0> (terrain[row][col] == MOUNTAINS || z&gt;l-&gt;distance &gt;&gt; </span><span class=cFE>1</span><span class=cF0>)
<a name="l117"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l118"></a> }
<a name="l119"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (terrain[l-&gt;r2][l-&gt;c2] == MOUNTAINS)
<a name="l120"></a> {
<a name="l121"></a> </span><span class=cF1>if</span><span class=cF0> (terrain[row][col] == MOUNTAINS || z &lt;= l-&gt;distance &gt;&gt; </span><span class=cFE>1</span><span class=cF0>)
<a name="l122"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l123"></a> }
<a name="l124"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l125"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l126"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l127"></a>
<a name="l128"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l129"></a>}
<a name="l130"></a>
<a name="l131"></a></span><span class=cF1>Bool</span><span class=cF0> LOS(</span><span class=cF9>I64</span><span class=cF0> r1, </span><span class=cF9>I64</span><span class=cF0> c1, </span><span class=cF9>I64</span><span class=cF0> r2, </span><span class=cF9>I64</span><span class=cF0> c2)
<a name="l132"></a>{
<a name="l133"></a> </span><span class=cF1>F64</span><span class=cF0> x1, y1, x2, y2;
<a name="l134"></a>
<a name="l135"></a> LOSCtrl l;
<a name="l136"></a> RowCol2XY(&amp;x1, &amp;y1, r1, c1);
<a name="l137"></a> RowCol2XY(&amp;x2, &amp;y2, r2, c2);
<a name="l138"></a> l.r1 = r1;
<a name="l139"></a> l.c1 = c1;
<a name="l140"></a> l.r2 = r2;
<a name="l141"></a> l.c2 = c2;
<a name="l142"></a> l.distance = </span><span class=cF5>Sqrt</span><span class=cF0>(</span><span class=cF5>SqrI64</span><span class=cF7>(</span><span class=cF0>x1 - x2</span><span class=cF7>)</span><span class=cF0> + </span><span class=cF5>SqrI64</span><span class=cF7>(</span><span class=cF0>y1 - y2</span><span class=cF7>)</span><span class=cF0>);
<a name="l143"></a>
<a name="l144"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>Line</span><span class=cF0>(&amp;l, x1, y1, </span><span class=cFE>0</span><span class=cF0>, x2, y2, l.distance, &amp;LOSPlot);
<a name="l145"></a>}
</span></pre></body>
</html>