2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 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.
28 * sect.c: Sector pre-write and post-read data massage
30 * Known contributors to this file:
46 #include "prototypes.h"
49 static int checksect(struct sctstr *);
52 sct_postread(int id, void *ptr)
54 struct sctstr *sp = ptr;
57 player->owner = (player->god || sp->sct_own == player->cnum);
64 sct_prewrite(int id, void *ptr)
66 struct sctstr *sp = ptr;
69 time(&sp->sct_timestamp);
72 getsect(sp->sct_x, sp->sct_y, §);
77 item_prewrite(short *item)
81 for (i = I_NONE + 1; i <= I_MAX; ++i) {
82 if (CANT_HAPPEN(item[i] < 0))
84 else if (CANT_HAPPEN(item[i] > ITEM_MAX))
90 checksect(struct sctstr *sp)
92 int mil, civs, loyalcivs;
94 item_prewrite(sp->sct_item);
96 /* shouldn't happen, but... */
97 if (sp->sct_mobil > 127)
100 mil = sp->sct_item[I_MILIT];
101 civs = sp->sct_item[I_CIVIL];
102 if (sp->sct_own == sp->sct_oldown)
107 if (sp->sct_effic < SCT_MINEFF) {
108 if (sp->sct_type == SCT_BSPAN)
110 else if (sp->sct_type == SCT_BTOWER) {
115 if (sp->sct_own != 0 && !civs) {
117 sp->sct_oldown = sp->sct_own;
119 /* If they have a military unit there, they still own it */
120 if (sp->sct_own && !loyalcivs && !(sp->sct_flags & MOVE_IN_PROGRESS)) {
121 if (!mil && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) {
123 if (sp->sct_type == SCT_CAPIT || sp->sct_type == SCT_MOUNT)
124 caploss(sp, sp->sct_own, "");
126 if (sp->sct_oldown == sp->sct_own) {
127 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
131 takeover(sp, sp->sct_oldown);
135 if (!opt_DEFENSE_INFRA)
136 sp->sct_defense = sp->sct_effic;
141 issector(s_char *arg)
145 while (0 != (c = *arg++))
146 if (!isdigit(c) && !isspace(c) && (c != '/'))