-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsub2.d
82 lines (70 loc) · 1.69 KB
/
sub2.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Empire, the Wargame of the Century (tm)
* Copyright (C) 1978-2004 by Walter Bright
* All Rights Reserved
*
* You may use this source for personal use only. To use it commercially
* or to distribute source or binaries of Empire, please contact
* www.digitalmars.com.
*
* Written by Walter Bright.
* This source is written in the D Programming Language.
* See www.digitalmars.com/d/ for the D specification and compiler.
*
* Use entirely at your own risk. There is no warranty, expressed or implied.
*/
module sub2;
import std.string;
import empire;
import var;
/*********************************
* Return city number given city location.
*/
City *fndcit(loc_t loc)
in
{
assert(chkloc(loc));
}
body
{ int i;
for (i = CITMAX; i--;)
if (city[i].loc == loc)
return &city[i]; // we found the city
assert(0);
return null;
}
/*******************************
* Create a new unit, given it's loc and type.
* Output:
* unitop = max(unitop, uninum + 1)
* Returns:
* true if successful
* false if overpopulation
*/
int newuni(Unit **pu,loc_t loc,uint ty,uint pn)
in
{
assert(chkloc(loc));
assert(ty < TYPMAX);
assert(pn <= PLYMAX);
}
body
{ int i;
Unit *u;
for (i = 0; i < UNIMAX; i++)
{ u = &unit[i];
if (!unit[i].loc) // if unit doesn't exist
{ if (i >= unitop)
unitop = i + 1; // set unitop to 1 past max uninum
memset(u,0,Unit.sizeof);
u.loc = loc;
u.own = pn;
u.typ = ty;
u.hit = typx[ty].hittab;
u.dir = (i & 1) ? 1 : -1;
*pu = u; // return unit # created
return true; // successful
}
}
return false; // overpopulation
}