00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00065 if (pp->pln_mission) {
00066
00067
00068
00069
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
00087 if (pp->pln_mission) {
00088
00089
00090
00091
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 }