2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * sect.c: Sector pre-write and post-read data massage
30 * Known contributors to this file:
45 #include "prototypes.h"
48 static int checksect(struct sctstr *);
49 static void give_back_cap(struct sctstr *sp);
53 sct_postread(int id, s_char *ptr)
55 struct sctstr *sp = (struct sctstr *)ptr;
58 player->owner = (player->god || sp->sct_own == player->cnum);
66 sct_prewrite(int id, s_char *ptr)
68 struct sctstr *sp = (struct sctstr *)ptr;
71 time(&sp->sct_timestamp);
74 getsect(sp->sct_x, sp->sct_y, §);
79 checksect(struct sctstr *sp)
81 int mil, civs, loyalcivs;
83 /* shouldn't happen, but... */
84 if (sp->sct_mobil > 127)
87 mil = sp->sct_item[I_MILIT];
88 civs = sp->sct_item[I_CIVIL];
89 if (sp->sct_own == sp->sct_oldown)
94 if (sp->sct_effic < SCT_MINEFF) {
95 if (sp->sct_type == SCT_BSPAN)
97 else if (sp->sct_type == SCT_BTOWER) {
102 if (sp->sct_own != 0 && !civs) {
104 sp->sct_oldown = sp->sct_own;
106 /* If they have a military unit there, they still own it */
107 if (sp->sct_own && !loyalcivs && !(sp->sct_flags & MOVE_IN_PROGRESS)) {
108 if (!mil && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) {
110 if (sp->sct_type == SCT_CAPIT || sp->sct_type == SCT_MOUNT)
111 caploss(sp, sp->sct_own, "");
113 if (sp->sct_oldown == sp->sct_own) {
114 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
118 /* if oldown gets his cap back make agri */
119 if (sp->sct_oldown &&
120 player->cnum == sp->sct_own &&
121 sp->sct_type == SCT_CAPIT &&
122 sp->sct_newtype == SCT_CAPIT)
124 takeover(sp, sp->sct_oldown);
129 if (!opt_DEFENSE_INFRA)
130 sp->sct_defense = sp->sct_effic;
135 issector(s_char *arg)
139 while (0 != (c = *arg++))
140 if (!isdigit(c) && !isspace(c) && (c != '/'))
147 give_back_cap(struct sctstr *sp)
149 struct natstr *natp = getnatp(sp->sct_oldown);
151 if (xrel(natp, natp->nat_xcap) == xrel(natp, sp->sct_x) &&
152 yrel(natp, natp->nat_ycap) == yrel(natp, sp->sct_y)) {
153 sp->sct_newtype = SCT_AGRI;
158 sct_init(coord x, coord y, s_char *ptr)
160 struct sctstr *sp = (struct sctstr *)ptr;
162 sp->ef_type = EF_SECTOR;