forked from jjsimpso/AberMUD
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DarkLight.c
100 lines (90 loc) · 2.03 KB
/
DarkLight.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/****************************************************************************\
* *
* C R E A T O R O F L E G E N D S *
* (AberMud Version 5) *
* *
* The Creator Of Legends System is (C) Copyright 1989 Alan Cox, All Rights *
* Reserved. *
* *
\****************************************************************************/
/*
* Dark/Light model
*
* 1.00 Original Version
* 1.01 ANSIfied
*/
#include "System.h"
Module "DarkLight";
Author "Alan Cox";
Version "1.01";
/*
* Decide if item 'i' is in the dark.
*/
int IsDarkFor(ITEM *i)
{
ITEM *p;
short rct=5;
if((p=O_PARENT(i))==NULL)
{
/*
* A question for the philosophers - is nothingness dark or not.....
* For game purposes we say it isn't, and the player gets 'The void' etc
*/
return(1);
}
/*
* We go up the tree first looking for higher lights
*/
reup: if(O_PARENT(p))
{
if(ContainerOf(p))
{
if((ContainerOf(p)->co_Flags&CO_SEETHRU)||
((ContainerOf(p)->co_Flags&CO_CLOSES)&&(!O_STATE(p))))
{
p=O_PARENT(p);
if(--rct) /* MAX 5 Levels of upping */
goto reup;
}
return(RecCheckDark(p,(short)0));
}
else
{
p=O_PARENT(p);
if(--rct)
goto reup;
}
}
return(RecCheckDark(p,(short)0));
}
/*
* Scan recursively downwards looking for light sources
*/
int RecCheckDark(ITEM *item, short depth)
{
ROOM *r;
OBJECT *o;
ITEM *x;
CONTAINER *c;
if(depth>31) /* Recursion Limit of 32 */
return(1);
r=RoomOf(item);
if((r)&&((r->rm_Flags&RM_DARK)==0))
return(0); /* lit by room - easy case */
o=ObjectOf(item);
if((o)&&(IsLit(item)))
return(0); /* Do we light it up ?*/
x=O_CHILDREN(item);
while(x) /* See if the contents do */
{
c=ContainerOf(x);
if((c)&&(c->co_Flags&CO_CLOSES)&&(O_STATE(x)==0))
goto l2; /* Open so can see in */
if((c)&&((c->co_Flags&CO_SEETHRU)==0))
goto nx; /* Opaque item */
l2: if(RecCheckDark(x,(short)(depth+1))==0)
return(0); /* Light found */
nx: x=O_NEXT(x);
}
return(1); /* REALLY DARK */
}