]> git.pond.sub.org Git - empserver/blob - src/lib/subs/plane.c
Rewrite the broken code to move cargo with its carrier
[empserver] / src / lib / subs / plane.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  plane.c: Plane post-read and pre-write data massage
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1989
32  *     Steve McClure, 1996
33  */
34
35 #include <config.h>
36
37 #include "file.h"
38 #include "lost.h"
39 #include "misc.h"
40 #include "optlist.h"
41 #include "plane.h"
42 #include "player.h"
43 #include "prototypes.h"
44 #include "unit.h"
45
46 void
47 pln_postread(int n, void *ptr)
48 {
49     struct plnstr *pp = ptr;
50
51     if (pp->pln_uid != n) {
52         logerror("pln_postread: Error - %d != %d, zeroing.\n",
53                  pp->pln_uid, n);
54         memset(pp, 0, sizeof(struct plnstr));
55     }
56     player->owner = (player->god || pp->pln_own == player->cnum);
57     if (opt_MOB_ACCESS)
58         pln_do_upd_mob(pp);
59 }
60
61 void
62 pln_prewrite(int n, void *old, void *new)
63 {
64     struct plnstr *oldpp = old;
65     struct plnstr *pp = new;
66     natid own = pp->pln_own;
67
68     if (pp->pln_effic < PLANE_MINEFF) {
69         own = 0;
70         pp->pln_effic = 0;
71         pp->pln_ship = pp->pln_land = -1;
72     }
73
74     if (CANT_HAPPEN(pp->pln_ship >= 0 && pp->pln_land >= 0))
75         pp->pln_land = -1;
76     if (oldpp->pln_ship != pp->pln_ship)
77         pln_carrier_change(pp, EF_SHIP, oldpp->pln_ship, pp->pln_ship);
78     if (oldpp->pln_land != pp->pln_land)
79         pln_carrier_change(pp, EF_LAND, oldpp->pln_land, pp->pln_land);
80
81     /* We've avoided assigning to pp->pln_own, in case oldsp == sp */
82     if (oldpp->pln_own != own)
83         lost_and_found(EF_PLANE, oldpp->pln_own, own,
84                        pp->pln_uid, pp->pln_x, pp->pln_y);
85
86     pp->pln_own = own;
87     if (!own || pp->pln_x != oldpp->pln_x || pp->pln_y != oldpp->pln_y)
88         unit_update_cargo((struct empobj *)pp);
89 }
90
91 void
92 pln_oninit(void *ptr)
93 {
94     struct plnstr *pp = ptr;
95
96     pp->pln_ship = pp->pln_land = -1;
97 }
98
99 char *
100 prplane(struct plnstr *pp)
101 {
102     return prbuf("%s #%d", plchr[(int)pp->pln_type].pl_name, pp->pln_uid);
103 }