TempleOSCDV4.11.ISO
This commit is contained in:
1 parent
9206246147
commit
93ca216483
662 files changed
+6431
-7369
No files matched your search
@@ -0,0 +1,79 @@
|
||||
Unit *FindNearestUnit(I64 row,I64 col,I64 player,Bool in_LOS,F64 range=-1)
|
||||
{
|
||||
I64 i;
|
||||
F64 dd,best_dd=MAX_F64,x1,y1,x2,y2;
|
||||
Unit *best=NULL;
|
||||
//$LK,"Sqrt",A="MN:Sqrt"$() is slow, so work with squared distances.
|
||||
if (range<0)
|
||||
range=MAX_F64;
|
||||
else
|
||||
range*=range;
|
||||
RowCol2XY(&x1,&y1,row,col);
|
||||
for (i=0;i<MAX_UNITS;i++)
|
||||
if (units[player][i].life>0) {
|
||||
if (!in_LOS || LOS(row,col,units[player][i].row,units[player][i].col)) {
|
||||
RowCol2XY(&x2,&y2,units[player][i].row,units[player][i].col);
|
||||
dd=Sqr(x2-x1)+Sqr(y2-y1);
|
||||
if (dd<=range && dd<best_dd) {
|
||||
best=&units[player][i];
|
||||
best_dd=dd;
|
||||
}
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
U0 TanksPlot()
|
||||
{
|
||||
Unit *target,*tempu;
|
||||
I64 i;
|
||||
for (i=0;i<MAX_UNITS;i++) {
|
||||
CheckUser;
|
||||
tempu=&units[cur_player][i];
|
||||
if (tempu->life>0 && tempu->indirect_fire &&
|
||||
(target=FindNearestUnit(tempu->row,tempu->col,enemy_player,TRUE,
|
||||
tempu->range*2*HEX_RADIUS)))
|
||||
PlotShot(tempu,target->row,target->col);
|
||||
}
|
||||
throw('PhaseOvr',TRUE);
|
||||
}
|
||||
|
||||
U0 TanksMove()
|
||||
{
|
||||
Unit *target,*tempu;
|
||||
I64 i;
|
||||
F64 x,y;
|
||||
for (i=0;i<MAX_UNITS;i++) {
|
||||
CheckUser;
|
||||
tempu=&units[cur_player][i];
|
||||
if (tempu->life>0) {
|
||||
//Cheats because it violates Line-of-Sight
|
||||
if (target=FindNearestUnit(tempu->row,tempu->col,enemy_player,FALSE)) {
|
||||
RowCol2XY(&x,&y,target->row,target->col);
|
||||
if (!MoveUnit(tempu,x,y)) {
|
||||
RowCol2XY(&x,&y,tempu->row,tempu->col);
|
||||
MoveUnit(tempu,x+RandI16,y+RandI16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw('PhaseOvr',TRUE);
|
||||
}
|
||||
|
||||
U0 TanksFire()
|
||||
{
|
||||
Unit *target,*tempu;
|
||||
I64 i;
|
||||
for (i=0;i<MAX_UNITS;i++) {
|
||||
CheckUser;
|
||||
tempu=&units[cur_player][i];
|
||||
if (tempu->life>0 && !tempu->indirect_fire &&
|
||||
(target=FindNearestUnit(tempu->row,tempu->col,enemy_player,TRUE,
|
||||
tempu->range*2*HEX_RADIUS))) {
|
||||
FireShot(tempu,target);
|
||||
Sleep(250*ANIMATION_DELAY);
|
||||
}
|
||||
}
|
||||
throw('PhaseOvr',TRUE);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user