-
Notifications
You must be signed in to change notification settings - Fork 0
/
hshatch.cpp
182 lines (153 loc) · 4.57 KB
/
hshatch.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// -----------------------------------------------------------------------
//!
//! @$Id: hshatch.cpp,v 1.12 2006/04/25 16:52:01 mark Exp $
//!
//! @par Copyright (see hscopyright.h)
//! Copyright (c) 2005 by HSpace Development Team
//!
// -----------------------------------------------------------------------
#include "hscopyright.h"
#include "hshatch.h"
CHSHatch::CHSHatch() :
mObjectDbref(-1),
mTargetDbref(HSNOTHING),
mTargetHatchID(0),
mClamped(0),
mOwnerObject(NULL)
{
}
CHSHatch::~CHSHatch()
{
}
HS_BOOL8 CHSHatch::LoadFromObject(HS_DBREF obj)
{
if (hsInterface.ValidObject(obj) == false)
{
hs_log(
hsInterface.HSPrintf(
"ERROR: CHSHatch::LoadFromObject() called on invalid dbref #%d",
mObjectDbref));
return false;
}
mObjectDbref = obj;
hsInterface.SetToggle(mObjectDbref, EXIT_HSPACE_HATCH);
if (hsInterface.AtrGet(mObjectDbref, "HSDB_TARGETOBJ"))
mTargetDbref = strtodbref(hsInterface.m_buffer);
if (hsInterface.AtrGet(mObjectDbref, "HSDB_TARGETHATCH"))
mTargetHatchID = atoi(hsInterface.m_buffer);
if (hsInterface.AtrGet(mObjectDbref, "HSDB_CLAMPED"))
mClamped = atoi(hsInterface.m_buffer);
return true;
}
void CHSHatch::WriteTargetDbrefAttribute()
{
hsInterface.AtrAdd(mObjectDbref, "HSDB_TARGETOBJ",
hsInterface.HSPrintf("#%d", mTargetDbref),
hsInterface.GetGodDbref(), AF_MDARK | AF_WIZARD);
}
void CHSHatch::WriteTargetIdAttribute()
{
hsInterface.AtrAdd(mObjectDbref, "HSDB_TARGETHATCH",
hsInterface.HSPrintf("%d", mTargetHatchID),
hsInterface.GetGodDbref(), AF_MDARK | AF_WIZARD);
}
void CHSHatch::WriteClampedStatusAttribute()
{
hsInterface.AtrAdd(mObjectDbref, "HSDB_CLAMPED",
hsInterface.HSPrintf("%d", mClamped),
hsInterface.GetGodDbref(), AF_MDARK | AF_WIZARD);
}
void CHSHatch::ClearObjectAttrs()
{
hsInterface.AtrAdd(mObjectDbref, "HSDB_TARGETOBJ",
NULL, hsInterface.GetGodDbref());
hsInterface.AtrAdd(mObjectDbref, "HSDB_TARGETHATCH",
NULL, hsInterface.GetGodDbref());
hsInterface.AtrAdd(mObjectDbref, "HSDB_CLAMPED",
NULL, hsInterface.GetGodDbref());
hsInterface.AtrAdd(mObjectDbref, "HSDB_SHIP",
NULL, hsInterface.GetGodDbref());
}
void CHSHatch::InitObjectAttrs()
{
WriteTargetDbrefAttribute();
WriteTargetIdAttribute();
WriteClampedStatusAttribute();
}
// All not used yet.
HS_INT8 *CHSHatch::GetAttributeValue(const HS_INT8 * strName)
{
static char rval[32];
*rval = '\0';
if (!strcasecmp(strName, "TARGETOBJ"))
sprintf(rval, "#%d", mTargetDbref);
else if (!strcasecmp(strName, "TARGETHATCH"))
sprintf(rval, "%d", mTargetHatchID);
else if (!strcasecmp(strName, "CLAMPED"))
sprintf(rval, "%d", mClamped);
else
return NULL;
return rval;
}
// Unused currently, might be used in the future.
HS_BOOL8 CHSHatch::SetAttributeValue(const HS_INT8 * strName,
HS_INT8 * strValue)
{
// Match the name .. set the value
if (!strcasecmp(strName, "TARGETHATCH"))
{
mTargetHatchID = atoi(strValue);
WriteTargetIdAttribute();
return true;
}
if (!strcasecmp(strName, "CLAMPED"))
{
if (atoi(strValue) == 1 || atoi(strValue) == 0)
{
mClamped = atoi(strValue);
WriteClampedStatusAttribute();
return true;
}
else
return false;
}
else
return false;
}
// Handles a message, which for now is just giving it to the room the
// hatch is situated in.
void CHSHatch::HandleMessage(const char *lpstrMsg, int type)
{
hsInterface.NotifyContents(hsInterface.GetHome(mObjectDbref),
(char *) lpstrMsg);
}
// Sets the CHS3DObject that owns the landing location.
void CHSHatch::SetOwnerObject(CHS3DObject * cObj)
{
mOwnerObject = cObj;
}
// Remove the owner reference
void CHSHatch::ClearOwnerObject()
{
mOwnerObject = NULL;
}
// Returns the CHS3DObject that controls the landing location.
CHS3DObject *CHSHatch::GetOwnerObject()
{
return mOwnerObject;
}
void CHSHatch::TargetObject(HS_DBREF val)
{
mTargetDbref = val;
WriteTargetDbrefAttribute();
}
void CHSHatch::TargetHatch(HS_INT32 val)
{
mTargetHatchID = val;
WriteTargetIdAttribute();
}
void CHSHatch::Clamped(HS_INT32 val)
{
mClamped = val;
WriteClampedStatusAttribute();
}