Update of /cvsroot/netrek/client/netrekxp/src
In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv6411/src
Modified Files:
input.c util.c
Log Message:
Add support for plasma to gettarget.
Add sanity and range checks to autophaser.
Add plasma check to autophaser.
Index: input.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/input.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- input.c 23 May 2009 13:23:39 -0000 1.51
+++ input.c 23 May 2009 15:21:20 -0000 1.52
@@ -1921,6 +1921,7 @@
{
unsigned char course;
int x, y;
+ int distance;
register struct player *j;
struct obtype *gettarget (W_Window ww,
int x,
@@ -1928,27 +1929,57 @@
int targtype),
*target;
- if (F_auto_weapons && autoPhaser) {
- target = gettarget (data->Window, data->x, data->y, TARG_ENEMY | TARG_CLOAK);
- if (target->o_num == -1) {
+ if (F_auto_weapons && autoPhaser)
+ {
+ target = gettarget (data->Window, data->x, data->y, TARG_ENEMY | TARG_CLOAK | TARG_PLASMA);
+ if (target->o_type == PLAYERTYPE && target->o_num == me->p_no)
+ {
/* failed to find a target */
course = (unsigned char) (getcourse (data->Window, data->x, data->y));
sendPhaserReq (course);
return;
}
- j = &players[target->o_num];
- if (data->Window == mapw)
+ if (target->o_type == PLAYERTYPE)
{
- x = j->p_x * GWINSIDE / GWIDTH;
- y = j->p_y * GWINSIDE / GWIDTH;
+ j = &players[target->o_num];
+ if (data->Window == mapw)
+ {
+ x = j->p_x * GWINSIDE / GWIDTH;
+ y = j->p_y * GWINSIDE / GWIDTH;
+ }
+ else if (data->Window == w)
+ {
+ x = (j->p_x - me->p_x) / scaleFactor + TWINSIDE / 2;
+ y = (j->p_y - me->p_y) / scaleFactor + TWINSIDE / 2;
+ }
}
- else
+ else if (target->o_type == PLASMATYPE)
{
- x = (j->p_x - me->p_x) / scaleFactor + TWINSIDE / 2;
- y = (j->p_y - me->p_y) / scaleFactor + TWINSIDE / 2;
+ x = target->o_dist_x;
+ y = target->o_dist_y;
}
- /* Sanity check on x, y? Use ship max phaser range? */
- /* How about phasering plasma? */
+
+ /* Sanity check on distance. Negative x or y indicates phaser is in local
+ window but target is outside viewable range. */
+ if (x < 0 || y < 0)
+ {
+ course = (unsigned char) (getcourse (data->Window, data->x, data->y));
+ sendPhaserReq (course);
+ return;
+ }
+ /* Check ship max phaser range for local window phasers. Sometimes phasers
+ are fired to "point". Not checking galaxy map phasers. */
+ if (data->Window == w)
+ {
+ distance = (int) sqrt((x- TWINSIDE / 2)*(x - TWINSIDE / 2) + (y - TWINSIDE / 2)*(y - TWINSIDE /2));
+ if (distance > (PHASEDIST * j->p_ship.s_phaserdamage / 100 / scaleFactor))
+ {
+ course = (unsigned char) (getcourse (data->Window, data->x, data->y));
+ sendPhaserReq (course);
+ return;
+ }
+ }
+ /* Everything checks out */
course = (unsigned char) (getcourse (data->Window, x, y));
}
else
Index: util.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/util.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- util.c 16 Apr 2008 00:08:23 -0000 1.8
+++ util.c 23 May 2009 15:21:20 -0000 1.9
@@ -64,6 +64,8 @@
g_y = (y - 4) / W_Textheight;
_targ.o_type = PLAYERTYPE;
_targ.o_num = GetPlayerFromPlist (g_x, g_y);
+ _targ.o_dist_x = -1;
+ _targ.o_dist_y = -1;
targ = &_targ;
return (targ);
}
@@ -75,6 +77,8 @@
g_y = (y - 4) / W_Textheight - 2; // Two header lines
_targ.o_type = PLANETTYPE;
_targ.o_num = GetPlanetFromPlist (g_x, g_y);
+ _targ.o_dist_x = -1;
+ _targ.o_dist_y = -1;
targ = &_targ;
return (targ);
}
@@ -105,6 +109,7 @@
register int i;
register struct player *j;
register struct planet *k;
+ register struct plasmatorp *pt;
double dist, closedist;
int friendly;
@@ -118,6 +123,8 @@
{
_target.o_type = PLANETTYPE;
_target.o_num = i;
+ _target.o_dist_x = -1;
+ _target.o_dist_y = -1;
closedist = dist;
}
@@ -145,6 +152,28 @@
{
_target.o_type = PLAYERTYPE;
_target.o_num = i;
+ _target.o_dist_x = -1;
+ _target.o_dist_y = -1;
+ closedist = dist;
+ }
+ }
+ }
+ if (targtype & TARG_PLASMA)
+ {
+ for (pt = plasmatorps + (nplasmas * nplayers) - 1; pt >= plasmatorps; --pt)
+ {
+ if (!pt->pt_status)
+ continue;
+ if (pt->pt_status == PTEXPLODE || pt->pt_status == PTFREE)
+ continue;
+
+ dist = hypot ((double) (x - pt->pt_x), (double) (y - pt->pt_y));
+ if (dist < closedist)
+ {
+ _target.o_type = PLASMATYPE;
+ _target.o_num = -1;
+ _target.o_dist_x = (int) ((x - pt->pt_x) / scaleFactor + TWINSIDE / 2);
+ _target.o_dist_y = (int) ((y - pt->pt_y) / scaleFactor + TWINSIDE / 2);
closedist = dist;
}
}
@@ -155,6 +184,8 @@
_target.o_type = PLAYERTYPE;
_target.o_num = me->p_no; /* Return myself. Oh
* well... */
+ _target.o_dist_x = -1;
+ _target.o_dist_y = -1;
return (&_target);
}
else