2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2018, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * sect.c: Sector pre-write and post-read data massage
29 * Known contributors to this file:
32 * Markus Armbruster, 2004-2016
44 #include "prototypes.h"
50 sct_postread(int id, void *ptr)
52 struct sctstr *sp = ptr;
54 player->owner = (player->god || sp->sct_own == player->cnum);
56 if (opt_MOB_ACCESS && sp->sct_own && sp->sct_type != SCT_SANCT
58 mob_inc_sect(sp, game_tick_to_now(&sp->sct_access));
62 sct_prewrite(int id, void *old, void *new)
64 struct sctstr *oldsp = old;
65 struct sctstr *sp = new;
70 sctoff2xy(&x, &y, sp->sct_uid);
71 if (CANT_HAPPEN(sp->sct_x != x || sp->sct_y != y)) {
77 item_prewrite(sp->sct_item);
79 mil = sp->sct_item[I_MILIT];
80 civs = sp->sct_item[I_CIVIL];
82 prev_own = oldsp->sct_own;
91 * Without civilians, military and land units, revert to deity.
92 * Note: would_abandon() must match this condition.
94 if (own && !civs && !mil && !has_units(sp->sct_x, sp->sct_y, own)
95 && !(sp->sct_flags & MOVE_IN_PROGRESS)) {
96 own = sp->sct_own = 0;
99 if (sp->sct_type == SCT_CAPIT || sp->sct_type == SCT_MOUNT)
100 caploss(sp, prev_own, "");
104 lost_and_found(EF_SECTOR, prev_own, own, 0, sp->sct_x, sp->sct_y);
108 item_prewrite(short *item)
112 for (i = I_NONE + 1; i <= I_MAX; ++i) {
113 if (CANT_HAPPEN(item[i] < 0))
115 else if (CANT_HAPPEN(item[i] > ITEM_MAX))
125 while (0 != (c = *arg++))
126 if (!isdigit(c) && !isspace(c) && (c != '/'))