mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-30 17:26:31 +00:00
174 lines
15 KiB
HTML
Executable file
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 V0.15">
|
|
<style type="text/css">
|
|
body {background-color:#fef1f0;}
|
|
.cF0{color:#000000;background-color:#fef1f0;}
|
|
.cF1{color:#0148a4;background-color:#fef1f0;}
|
|
.cF2{color:#3b7901;background-color:#fef1f0;}
|
|
.cF3{color:#057c7e;background-color:#fef1f0;}
|
|
.cF4{color:#bb2020;background-color:#fef1f0;}
|
|
.cF5{color:#9e42ae;background-color:#fef1f0;}
|
|
.cF6{color:#b57901;background-color:#fef1f0;}
|
|
.cF7{color:#b2b6af;background-color:#fef1f0;}
|
|
.cF8{color:#555753;background-color:#fef1f0;}
|
|
.cF9{color:#678fbb;background-color:#fef1f0;}
|
|
.cFA{color:#82bc49;background-color:#fef1f0;}
|
|
.cFB{color:#0097a2;background-color:#fef1f0;}
|
|
.cFC{color:#e26a6a;background-color:#fef1f0;}
|
|
.cFD{color:#c671bc;background-color:#fef1f0;}
|
|
.cFE{color:#c7ab00;background-color:#fef1f0;}
|
|
.cFF{color:#fef1f0;background-color:#fef1f0;}
|
|
</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 & </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 & </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 & </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&</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 >= </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 = &hex_centers[row][col];
|
|
<a name="l56"></a> *_x = c->x;
|
|
<a name="l57"></a> *_y = c->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 & </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 >>= </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 < </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 < UNITS_NUM; i++)
|
|
<a name="l78"></a> </span><span class=cF1>if</span><span class=cF0> ( units[j][i].life > </span><span class=cFE>0</span><span class=cF0> &&
|
|
<a name="l79"></a> units[j][i].row == row &&
|
|
<a name="l80"></a> units[j][i].col == col)
|
|
<a name="l81"></a> </span><span class=cF1>return</span><span class=cF0> &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> <= x + task->scroll_x < task->pix_width &&
|
|
<a name="l88"></a> </span><span class=cFE>0</span><span class=cF0> <= y + task->scroll_y < task->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(&cursor_row, &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(&row, &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->r1 || col != l->c1</span><span class=cF7>)</span><span class=cF0> &&
|
|
<a name="l111"></a> </span><span class=cF7>(</span><span class=cF0>row != l->r2 || col != l->c2</span><span class=cF7>)</span><span class=cF0> &&
|
|
<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->r1][l->c1] == MOUNTAINS)
|
|
<a name="l115"></a> {
|
|
<a name="l116"></a> </span><span class=cF1>if</span><span class=cF0> (terrain[row][col] == MOUNTAINS || z>l->distance >> </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->r2][l->c2] == MOUNTAINS)
|
|
<a name="l120"></a> {
|
|
<a name="l121"></a> </span><span class=cF1>if</span><span class=cF0> (terrain[row][col] == MOUNTAINS || z <= l->distance >> </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(&x1, &y1, r1, c1);
|
|
<a name="l137"></a> RowCol2XY(&x2, &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>(&l, x1, y1, </span><span class=cFE>0</span><span class=cF0>, x2, y2, l.distance, &LOSPlot);
|
|
<a name="l145"></a>}
|
|
</span></pre></body>
|
|
</html>
|