src/lib/subs/plane.c

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  plane.c: Plane post-read and pre-write data massage
00029  * 
00030  *  Known contributors to this file:
00031  *     Dave Pare, 1989
00032  *     Steve McClure, 1996
00033  */
00034 
00035 #include <config.h>
00036 
00037 #include "file.h"
00038 #include "land.h"
00039 #include "lost.h"
00040 #include "misc.h"
00041 #include "nuke.h"
00042 #include "optlist.h"
00043 #include "plane.h"
00044 #include "player.h"
00045 #include "prototypes.h"
00046 #include "ship.h"
00047 
00048 int
00049 pln_postread(int n, void *ptr)
00050 {
00051     struct plnstr *pp = ptr;
00052     struct shpstr theship;
00053     struct lndstr theland;
00054 
00055     if (pp->pln_uid != n) {
00056         logerror("pln_postread: Error - %d != %d, zeroing.\n",
00057                  pp->pln_uid, n);
00058         memset(pp, 0, sizeof(struct plnstr));
00059     }
00060 
00061     if (pp->pln_ship >= 0 && pp->pln_own && pp->pln_effic >= PLANE_MINEFF) {
00062         if (getship(pp->pln_ship, &theship) &&
00063             (theship.shp_effic >= SHIP_MINEFF)) {
00064             /* wooof!  Carriers are a pain */
00065             if (pp->pln_mission) {
00066                 /*
00067                  *  If the plane is on a mission centered
00068                  *  on it's loc, the op-area travels with
00069                  *  the plane.
00070                  */
00071                 if ((pp->pln_opx == pp->pln_x) &&
00072                     (pp->pln_opy == pp->pln_y)) {
00073                     pp->pln_opx = theship.shp_x;
00074                     pp->pln_opy = theship.shp_y;
00075                 }
00076             }
00077             if (pp->pln_x != theship.shp_x || pp->pln_y != theship.shp_y)
00078                 time(&pp->pln_timestamp);
00079             pp->pln_x = theship.shp_x;
00080             pp->pln_y = theship.shp_y;
00081         }
00082     }
00083     if (pp->pln_land >= 0 && pp->pln_own && pp->pln_effic >= PLANE_MINEFF) {
00084         if (getland(pp->pln_land, &theland) &&
00085             (theland.lnd_effic >= LAND_MINEFF)) {
00086             /* wooof!  Units are a pain, too */
00087             if (pp->pln_mission) {
00088                 /*
00089                  *  If the plane is on a mission centered
00090                  *  on it's loc, the op-area travels with
00091                  *  the plane.
00092                  */
00093                 if ((pp->pln_opx == pp->pln_x) &&
00094                     (pp->pln_opy == pp->pln_y)) {
00095                     pp->pln_opx = theland.lnd_x;
00096                     pp->pln_opy = theland.lnd_y;
00097                 }
00098             }
00099             if (pp->pln_x != theland.lnd_x || pp->pln_y != theland.lnd_y)
00100                 time(&pp->pln_timestamp);
00101             pp->pln_x = theland.lnd_x;
00102             pp->pln_y = theland.lnd_y;
00103         }
00104     }
00105     player->owner = (player->god || pp->pln_own == player->cnum);
00106     if (opt_MOB_ACCESS)
00107         pln_do_upd_mob(pp);
00108     return 1;
00109 }
00110 
00111 int
00112 pln_prewrite(int n, void *ptr)
00113 {
00114     struct plnstr *pp = ptr;
00115     struct plnstr plane;
00116     struct nukstr *np;
00117     int i;
00118 
00119     if (pp->pln_effic < PLANE_MINEFF) {
00120         if (pp->pln_own)
00121             makelost(EF_PLANE, pp->pln_own, pp->pln_uid,
00122                      pp->pln_x, pp->pln_y);
00123         pp->pln_own = 0;
00124         pp->pln_effic = 0;
00125         for (i = 0; NULL != (np = getnukep(i)); i++) {
00126             if (np->nuk_own && np->nuk_plane == n) {
00127                 mpr(np->nuk_own, "%s lost!\n", prnuke(np));
00128                 np->nuk_effic = 0;
00129                 np->nuk_plane = -1;
00130                 putnuke(np->nuk_uid, np);
00131             }
00132         }
00133     }
00134     pp->ef_type = EF_PLANE;
00135     pp->pln_uid = n;
00136 
00137     time(&pp->pln_timestamp);
00138 
00139     getplane(n, &plane);
00140 
00141     return 1;
00142 }
00143 
00144 void
00145 pln_init(int n, void *ptr)
00146 {
00147     struct plnstr *pp = ptr;
00148 
00149     pp->ef_type = EF_PLANE;
00150     pp->pln_uid = n;
00151     pp->pln_own = 0;
00152 }
00153 
00154 char *
00155 prplane(struct plnstr *pp)
00156 {
00157     return prbuf("%s #%d", plchr[(int)pp->pln_type].pl_name, pp->pln_uid);
00158 }

Generated on Fri Mar 28 11:01:14 2008 for empserver by  doxygen 1.5.2