153 lines
12 KiB
Plaintext
153 lines
12 KiB
Plaintext
|
<!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>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) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l4"></a> </span><span class=cF1>case</span><span class=cF0> 0:
|
||
|
<a name="l5"></a> *_row-=2;
|
||
|
<a name="l6"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l7"></a> </span><span class=cF1>case</span><span class=cF0> 1:
|
||
|
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (*_row&1) *_col+=1;
|
||
|
<a name="l9"></a> *_row-=1;
|
||
|
<a name="l10"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l11"></a> </span><span class=cF1>case</span><span class=cF0> 2:
|
||
|
<a name="l12"></a> </span><span class=cF1>if</span><span class=cF0> (*_row&1) *_col+=1;
|
||
|
<a name="l13"></a> *_row+=1;
|
||
|
<a name="l14"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l15"></a> </span><span class=cF1>case</span><span class=cF0> 3:
|
||
|
<a name="l16"></a> *_row+=2;
|
||
|
<a name="l17"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l18"></a> </span><span class=cF1>case</span><span class=cF0> 4:
|
||
|
<a name="l19"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>*_row&1</span><span class=cF7>)</span><span class=cF0>) *_col-=1;
|
||
|
<a name="l20"></a> *_row+=1;
|
||
|
<a name="l21"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l22"></a> </span><span class=cF1>case</span><span class=cF0> 5:
|
||
|
<a name="l23"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>*_row&1</span><span class=cF7>)</span><span class=cF0>) *_col-=1;
|
||
|
<a name="l24"></a> *_row-=1;
|
||
|
<a name="l25"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l26"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l27"></a>}
|
||
|
<a name="l28"></a>
|
||
|
<a name="l29"></a></span><span class=cF9>I64</span><span class=cF0> FacingChg(</span><span class=cF9>I64</span><span class=cF0> f1,</span><span class=cF9>I64</span><span class=cF0> f2)
|
||
|
<a name="l30"></a>{
|
||
|
<a name="l31"></a> </span><span class=cF9>I64</span><span class=cF0> res=(f1+6-f2)%6;
|
||
|
<a name="l32"></a> </span><span class=cF1>if</span><span class=cF0> (res>=3)
|
||
|
<a name="l33"></a> </span><span class=cF1>return</span><span class=cF0> 6-res;
|
||
|
<a name="l34"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l35"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
||
|
<a name="l36"></a>}
|
||
|
<a name="l37"></a>
|
||
|
<a name="l38"></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="l39"></a>{
|
||
|
<a name="l40"></a> Pt *c;
|
||
|
<a name="l41"></a> row=</span><span class=cF5>ClampI64</span><span class=cF0>(row,0,map_rows);
|
||
|
<a name="l42"></a> col=</span><span class=cF5>ClampI64</span><span class=cF0>(col,0,map_cols);
|
||
|
<a name="l43"></a> c=&hex_centers[row][col];
|
||
|
<a name="l44"></a> *_x=c->x;
|
||
|
<a name="l45"></a> *_y=c->y;
|
||
|
<a name="l46"></a>}
|
||
|
<a name="l47"></a>
|
||
|
<a name="l48"></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="l49"></a>{
|
||
|
<a name="l50"></a> *_col=(x-DCOS/2)/(HEX_SIDE+DCOS);
|
||
|
<a name="l51"></a> </span><span class=cF1>if</span><span class=cF0> (*_col&1)
|
||
|
<a name="l52"></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=cF0>2*DSIN</span><span class=cF7>)</span><span class=cF0>)*2+1;
|
||
|
<a name="l53"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l54"></a> *_row=</span><span class=cF5>ToI64</span><span class=cF0>(y/</span><span class=cF7>(</span><span class=cF0>2*DSIN</span><span class=cF7>)</span><span class=cF0>)*2;
|
||
|
<a name="l55"></a> *_col>>=1;
|
||
|
<a name="l56"></a> *_row=</span><span class=cF5>ClampI64</span><span class=cF0>(*_row,0,map_rows-1);
|
||
|
<a name="l57"></a> *_col=</span><span class=cF5>ClampI64</span><span class=cF0>(*_col,0,map_cols-1);
|
||
|
<a name="l58"></a>}
|
||
|
<a name="l59"></a>
|
||
|
<a name="l60"></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="l61"></a>{</span><span class=cF2>//Finds unit in a hexagon.</span><span class=cF0>
|
||
|
<a name="l62"></a> </span><span class=cF9>I64</span><span class=cF0> i,j;
|
||
|
<a name="l63"></a> </span><span class=cF1>for</span><span class=cF0> (j=0;j<2;j++)
|
||
|
<a name="l64"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<UNITS_NUM;i++)
|
||
|
<a name="l65"></a> </span><span class=cF1>if</span><span class=cF0> (units[j][i].life>0 &&
|
||
|
<a name="l66"></a> units[j][i].row==row &&
|
||
|
<a name="l67"></a> units[j][i].col==col)
|
||
|
<a name="l68"></a> </span><span class=cF1>return</span><span class=cF0> &units[j][i];
|
||
|
<a name="l69"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
|
||
|
<a name="l70"></a>}
|
||
|
<a name="l71"></a>
|
||
|
<a name="l72"></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="l73"></a>{
|
||
|
<a name="l74"></a> </span><span class=cF1>if</span><span class=cF0> (0<=x+task->scroll_x<task->pix_width &&
|
||
|
<a name="l75"></a> 0<=y+task->scroll_y<task->pix_height)
|
||
|
<a name="l76"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l77"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l78"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l79"></a>}
|
||
|
<a name="l80"></a>
|
||
|
<a name="l81"></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="l82"></a>{
|
||
|
<a name="l83"></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="l84"></a> XY2RowCol(&cursor_row,&cursor_col,x,y);
|
||
|
<a name="l85"></a>}
|
||
|
<a name="l86"></a>
|
||
|
<a name="l87"></a></span><span class=cF1>class</span><span class=cF0> LOSCtrl
|
||
|
<a name="l88"></a>{
|
||
|
<a name="l89"></a> </span><span class=cF9>I64</span><span class=cF0> r1,c1,r2,c2,distance;
|
||
|
<a name="l90"></a>};
|
||
|
<a name="l91"></a>
|
||
|
<a name="l92"></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="l93"></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="l94"></a> </span><span class=cF9>I64</span><span class=cF0> row,col;
|
||
|
<a name="l95"></a> XY2RowCol(&row,&col,x,y);
|
||
|
<a name="l96"></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="l97"></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="l98"></a> terrain[row][col]!=PLAINS) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l99"></a> </span><span class=cF1>if</span><span class=cF0> (terrain[l->r1][l->c1]==MOUNTAINS) {
|
||
|
<a name="l100"></a> </span><span class=cF1>if</span><span class=cF0> (terrain[row][col]==MOUNTAINS || z>l->distance>>1)
|
||
|
<a name="l101"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l102"></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="l103"></a> </span><span class=cF1>if</span><span class=cF0> (terrain[row][col]==MOUNTAINS || z<=l->distance>>1)
|
||
|
<a name="l104"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l105"></a> } </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l106"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l107"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l108"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l109"></a>}
|
||
|
<a name="l110"></a>
|
||
|
<a name="l111"></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="l112"></a>{
|
||
|
<a name="l113"></a> </span><span class=cF1>F64</span><span class=cF0> x1,y1,x2,y2;
|
||
|
<a name="l114"></a> LOSCtrl l;
|
||
|
<a name="l115"></a> RowCol2XY(&x1,&y1,r1,c1);
|
||
|
<a name="l116"></a> RowCol2XY(&x2,&y2,r2,c2);
|
||
|
<a name="l117"></a> l.r1=r1; l.c1=c1;
|
||
|
<a name="l118"></a> l.r2=r2; l.c2=c2;
|
||
|
<a name="l119"></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="l120"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>Line</span><span class=cF0>(&l,x1,y1,0,x2,y2,l.distance,&LOSPlot);
|
||
|
<a name="l121"></a>}
|
||
|
</span></pre></body>
|
||
|
</html>
|