]> git.pond.sub.org Git - empserver/blobdiff - include/plane.h
client: Unbreak standalone build
[empserver] / include / plane.h
index e7bdbc18b79e0ddddb5db6f2b074c5bd9ce88ea3..35a807b1b02e689fc1f89f0e2bf6f3c90ed2c859 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  plane.h: Definitions for planes and plane types
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
+ *     Markus Armbruster, 2004-2020
  */
 
-#ifndef _PLANE_H_
-#define _PLANE_H_
+#ifndef PLANE_H
+#define PLANE_H
 
+#include "file.h"
+#include "item.h"
 #include "queue.h"
-#include "sect.h"
+#include "types.h"
 
-#define        PLANE_MINEFF    10
+#define PLANE_MINEFF   10
 
-/*
- * some routines assume that from pln_x to pln_wing remains
- * exactly equivalent with shp_x to shp_fleet
- */
 struct plnstr {
-       short   ef_type;
-       natid   pln_own;        /* owning country */
-       short   pln_uid;        /* plane unit id */
-       coord   pln_x;          /* plane x-y */
-       coord   pln_y;
-       s_char  pln_type;       /* fighter, bomber, etc */
-       s_char  pln_effic;      /* actually "training" */
-       s_char  pln_mobil;      /* plane mobility */
-       short   pln_sell;       /* index into trade file */
-       short   pln_tech;       /* plane's tech level */
-       s_char  pln_wing;       /* like fleet */
-       coord   pln_opx;        /* Op sector coords */
-       coord   pln_opy;        /* Op sector coords */
-       short   pln_mission;    /* mission code */
-       short   pln_radius;     /* mission radius */
-       u_char  pln_range;      /* total distance, not radius */
-       u_char  pln_range_max;  /* max range for this plane */
-       short   pln_ship;       /* pointer to carrier */
-       short   pln_land;       /* pointer to carrier */
-       int     pln_att;        /* plane air-air attack/defense values */
-       int     pln_def;
-       int     pln_acc;
-       int     pln_load;
-       int     pln_fuel;
-       s_char  pln_harden;     /* for missiles */
-       s_char  pln_nuketype;   /* type of nuclear armament (if any) */
-       s_char  pln_flags;      /* State of the plane */
-       time_t  pln_access;     /* Last time mob was updated (MOB_ACCESS) */
-        time_t  pln_timestamp;  /* Last time this plane was touched */
-       float   pln_theta;      /* position in orbital sine wave */
+    /* initial part must match struct empobj */
+    signed ef_type: 8;
+    unsigned pln_seqno: 12;
+    unsigned pln_generation: 12;
+    int pln_uid;               /* unit ID (plane #) */
+    time_t pln_timestamp;      /* Last time this plane was touched */
+    natid pln_own;             /* owning country */
+    coord pln_x;               /* plane x-y */
+    coord pln_y;
+    signed char pln_type;      /* index in plchr[] */
+    signed char pln_effic;     /* actually "training" */
+    signed char pln_mobil;     /* plane mobility */
+    unsigned char pln_off;     /* repairs stopped? */
+    short pln_tech;            /* plane's tech level */
+    char pln_wing;             /* like fleet */
+    coord pln_opx;             /* Op sector coords */
+    coord pln_opy;             /* Op sector coords */
+    short pln_mission;         /* mission code */
+    short pln_radius;          /* mission radius */
+    /* end of part matching struct empobj */
+    unsigned char pln_range;   /* total distance, not radius */
+    signed char pln_harden;    /* for missiles */
+    int pln_ship;              /* UID of carrier, or -1 */
+    int pln_land;              /* UID of transporting land unit, or -1 */
+    int pln_flags;             /* State of the plane */
+    short pln_access;          /* Last tick mob was updated (MOB_ACCESS) */
+    float pln_theta;           /* position in orbital sine wave */
 };
 
-#define        PLN_LAUNCHED    bit(0)  /* A satellite that's in orbit */
-#define        PLN_SYNCHRONOUS bit(1)  /* A satellite in geo-synchronous orbit */
-#define        PLN_AIRBURST    bit(2)  /* Airburst the nuke we're armed with */
+#define PLN_LAUNCHED   bit(0)  /* Flying (satellite: in orbit) */
+#define PLN_SYNCHRONOUS        bit(1)  /* A satellite in geo-synchronous orbit */
+#define PLN_AIRBURST   bit(2)  /* Airburst the nuke we're armed with */
 
 struct plchrstr {
-       s_char  *pl_name;       /* plane vanilla unit name */
-        s_char  *pl_planename;  /* plane real name */
-       int     pl_lcm;         /* costs to build */
-       int     pl_hcm;
-       int     pl_cost;
-       int     pl_tech;        /* tech needed to build */
-       int     pl_acc;         /* bombing accuracy (higher the better) */
-       int     pl_load;        /* bomb load, also for carrying cargo */
-       int     pl_att;         /* air-air attack/defense strengths */
-       int     pl_def;
-       int     pl_range;       /* how many sectors it can fly */
-       int     pl_crew;        /* number of mil to crew it */
-       int     pl_fuel;        /* fuel consumption */
-       int     pl_stealth;     /* how stealthy is it? */
-       int     pl_flags;       /* description of capability */
+    char *pl_name;             /* full name of type of plane */
+    short pl_mat[I_MAX+1];     /* materials to build 100% */
+                               /* only I_LCM, I_HCM, I_MILIT non-zero */
+    int pl_bwork;              /* work to build 100% */
+    int pl_tech;               /* tech needed to build */
+    int pl_cost;               /* how much it costs to build */
+    int pl_acc;                        /* bombing accuracy (higher the better) */
+    int pl_load;               /* bomb load, also for carrying cargo */
+    int pl_att;                        /* air-air attack/defense strengths */
+    int pl_def;
+    int pl_range;              /* how many sectors it can fly */
+    int pl_fuel;               /* fuel consumption */
+    int pl_stealth;            /* how stealthy is it? */
+    int pl_flags;              /* description of capability */
+    signed char pl_type;       /* index in plchr[] */
 };
 
-#define P_B    bit(0)  /* bombing factor only for bombing */
-#define P_T    bit(1)  /* tactical bombing ability */
-#define P_F    bit(2)  /* interceptor/escort */
-#define P_C    bit(3)  /* bombing factor for transport only */
-#define P_V    bit(4)  /* vtol ability */
-#define P_M    bit(5)  /* missile, used only once, can't be intercepted */
-#define P_L    bit(6)  /* light plane, lands on carriers */
-#define P_S    bit(7)  /* Spy ability */
-#define P_I    bit(8)  /* Imaging ability (advanced spying) */
-#define P_O    bit(9)  /* Orbital ability (a satellite) */
-#define P_X    bit(10) /* Stealth ability */
-#define P_N    bit(11) /* Nuclear RV interceptor (abm) */
-#define        P_H     bit(12) /* Half stealthy */
-#define P_E    bit(13) /* extra light */
-#define P_K    bit(14) /* chopper */
-#define P_A    bit(15) /* ASW (Anti-Sub Warfare) */
-#define P_P    bit(16) /* paradropping */
-#define P_ESC  bit(17) /* escort */
-#define P_MINE bit(18) /* can lay mines */
-#define P_SWEEP        bit(19) /* can sweep mines */
-#define P_MAR  bit(20) /* missile can hit ships */
-
-#define PM_R   bit(0) /* Recon mission */
-#define PM_S   bit(1) /* Mine-sweeping mission */
-
-#define PLN_MAXDEF     50
+#define P_B    bit(0)          /* bombing factor only for bombing */
+#define P_T    bit(1)          /* tactical bombing ability */
+#define P_F    bit(2)          /* interceptor/escort */
+#define P_C    bit(3)          /* bombing factor for transport only */
+#define P_V    bit(4)          /* vtol ability */
+#define P_M    bit(5)          /* missile, used only once, can't be intercepted */
+#define P_L    bit(6)          /* light plane, lands on carriers */
+#define P_S    bit(7)          /* Spy ability */
+#define P_I    bit(8)          /* Imaging ability (advanced spying) */
+#define P_O    bit(9)          /* Orbital ability (a satellite) */
+/* unused      bit(10) */
+#define P_N    bit(11)         /* Nuclear RV interceptor (ABM) */
+/* unused      bit(12) */
+#define P_E    bit(13)         /* extra light */
+#define P_K    bit(14)         /* chopper */
+#define P_A    bit(15)         /* ASW (Anti-Sub Warfare) */
+#define P_P    bit(16)         /* paradropping */
+#define P_ESC  bit(17)         /* escort */
+#define P_MINE bit(18)         /* can lay mines */
+#define P_SWEEP        bit(19)         /* can sweep mines */
+#define P_MAR  bit(20)         /* missile can hit ships */
+
+#define PM_R   bit(0)          /* Recon mission */
+#define PM_S   bit(1)          /* Mine-sweeping mission */
 
        /* internal to "fly" module -- really shouldn't be here */
 
 struct plist {
-       struct emp_qelem queue; /* list of planes */
-       int state;              /* state of plane */
-       int bombs;              /* bombs carried for bombing mission */ 
-       int misc;               /* amount of random item being transported */
-       struct plchrstr *pcp;   /* pointer to desc of plane */
-       struct plnstr plane;    /* struct plane */
+    struct emp_qelem queue;    /* list of planes */
+    int load;                  /* number of bombs or items carried */
+    short pstage;              /* plague stage */
+    struct plchrstr *pcp;      /* pointer to desc of plane */
+    struct plnstr plane;       /* struct plane */
 };
 
-#define        P_OK            0
-#define P_FIRED                1
-#define P_DEL          2
-
-#define getplane(n, p) \
-       ef_read(EF_PLANE, n, (caddr_t)p)
-#define putplane(n, p) \
-       ef_write(EF_PLANE, n, (caddr_t)p)
-#define getplanep(n) \
-       (struct plnstr *) ef_ptr(EF_PLANE, n)
-
-extern  struct plchrstr plchr[];
-extern int pln_maxno;
+#define getplane(n, p) ef_read(EF_PLANE, (n), (p))
+#define putplane(n, p) ef_write(EF_PLANE, (n), (p))
+#define getplanep(n) ((struct plnstr *)ef_ptr(EF_PLANE, (n)))
 
-       struct  shiplook{
-               short           uid;
-               u_char          looked;
-               u_char          found;
-               struct shiplook *next;
-       };
+#define PLCHR_SZ 128
+extern struct plchrstr plchr[PLCHR_SZ];
 
-#define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20))))
-#define PLN_ACC(b, t) (b * (1.0 - (sqrt((double)t) / 50.)))
-#define PLN_RAN(b, t) (t ? (b + (logx((double)t, (double)2.0))) : b)
-#define PLN_LOAD(b, t) (t ? (b * (logx((double)t, (double)50.0) < 1.0 ? 1.0 : \
-                                 logx((double)t, (double)50.0))) : b)
-
-double sqrt();
-double logx();
-
-float  pln_damage_sect();
-
-void   count_planes();
-double  sqrt();
-s_char *prplane();
+struct shiplist {
+    int uid;
+    struct shiplist *next;
+};
 
+extern int pl_att(struct plchrstr *, int);
+extern int pl_def(struct plchrstr *, int);
+extern int pl_acc(struct plchrstr *, int);
+extern int pl_range(struct plchrstr *, int);
+extern int pl_load(struct plchrstr *, int);
+extern int pln_att(struct plnstr *);
+extern int pln_def(struct plnstr *);
+extern int pln_acc(struct plnstr *);
+extern int pln_range_max(struct plnstr *);
+extern int pln_load(struct plnstr *);
+
+/* src/lib/common/cargo.c */
+extern void pln_carrier_change(struct plnstr *, int, int, int);
+extern int pln_first_on_ship(struct shpstr *);
+extern int pln_first_on_land(struct lndstr *);
+extern int pln_next_on_unit(int);
 
 /* src/lib/subs/aircombat.c */
-extern void ac_planedamage(struct plist *  , natid  , int  , natid  , int  ,
-                          int  , s_char * );
-extern void ac_intercept(struct emp_qelem *  , struct emp_qelem *  ,
-                        struct emp_qelem *  , natid  , coord  , coord);
-extern void ac_combat_headers(natid  , natid );
-extern void ac_airtoair(struct emp_qelem *  , struct emp_qelem *  , natid );
-extern void ac_doflak(struct emp_qelem *  , struct sctstr * );
-extern void ac_shipflak(struct emp_qelem *  , coord  , coord );
-extern void ac_landflak(struct emp_qelem *  , coord  , coord );
-extern void ac_fireflak(struct emp_qelem *  , natid  , natid  , int );
-extern void ac_encounter(struct emp_qelem *  , struct emp_qelem *  , coord  ,
-                        coord  , s_char *  , int  , int ,
-                        struct emp_qelem *, struct emp_qelem *);
-extern int ac_isflying(struct plnstr *, struct emp_qelem *);
-extern int do_evade(struct emp_qelem *  , struct emp_qelem * );
-extern void sam_intercept(struct emp_qelem *  , struct emp_qelem *  ,
-                         natid  , natid  , coord  , coord  , int );
-extern int all_missiles(struct emp_qelem * );
-extern int can_fly(int );
+extern int ac_flak_dam(int, int, int);
+extern void ac_encounter(struct emp_qelem *, struct emp_qelem *, coord,
+                        coord, char *, int);
+extern int ac_damage_plane(struct plnstr *, natid, int, int, char *);
 
 /* src/lib/subs/aswplnsubs.c */
-extern int have_looked(u_char  , struct shiplook * );
-extern int have_found(u_char  , struct shiplook * );
-extern void set_have_looked(u_char  , struct shiplook * );
-extern void set_have_found(u_char  , struct shiplook * );
-extern int print_found(struct shiplook * );
+extern int on_shiplist(int, struct shiplist *);
+extern void add_shiplist(int, struct shiplist **);
+extern void free_shiplist(struct shiplist **);
 
-#endif /* _PLANE_H_ */
+#endif