-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathimportactbusy.cpp
More file actions
185 lines (152 loc) · 7.27 KB
/
importactbusy.cpp
File metadata and controls
185 lines (152 loc) · 7.27 KB
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
183
184
185
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "importkeyvaluebase.h"
#include "dmserializers.h"
#include "datamodel/idatamodel.h"
#include "datamodel/dmelement.h"
#include "datamodel/dmattributevar.h"
#include "tier1/KeyValues.h"
#include "tier1/UtlBuffer.h"
#include "datamodel/dmattribute.h"
//-----------------------------------------------------------------------------
// Serialization class for Key Values
//-----------------------------------------------------------------------------
class CImportActBusy : public CImportKeyValueBase
{
public:
virtual const char *GetName() const { return "actbusy"; }
virtual const char *GetDescription() const { return "ActBusy Script File"; }
virtual int GetCurrentVersion() const { return 0; } // doesn't store a version
virtual const char *GetImportedFormat() const { return "actbusy"; }
virtual int GetImportedVersion() const { return 1; }
bool Serialize( CUtlBuffer &outBuf, CDmElement *pRoot );
CDmElement* UnserializeFromKeyValues( KeyValues *pKeyValues );
private:
// Reads a single element
bool UnserializeActBusyKey( CDmAttribute *pChildren, KeyValues *pKeyValues );
// Writes out the actbusy header
void SerializeHeader( CUtlBuffer &buf );
};
//-----------------------------------------------------------------------------
// Singleton instance
//-----------------------------------------------------------------------------
static CImportActBusy s_ImportActBusy;
void InstallActBusyImporter( IDataModel *pFactory )
{
pFactory->AddSerializer( &s_ImportActBusy );
}
//-----------------------------------------------------------------------------
// Writes out the actbusy header
//-----------------------------------------------------------------------------
void CImportActBusy::SerializeHeader( CUtlBuffer &buf )
{
buf.Printf( "// \"act busy name\"\t\tThis is the name that a mapmaker must specify in the hint node.\n" );
buf.Printf( "// {\n" );
buf.Printf( "// \t\"busy_anim\"\t\t\t\"Activity Name\".\n" );
buf.Printf( "// \t\"entry_anim\"\t\t\"Activity Name\"\n" );
buf.Printf( "// \t\"exit_anim\"\t\t\t\"Activity Name\"\n" );
buf.Printf( "// \t\"busy_sequence\"\t\t\"Sequence Name\". If specified, this is used over the activity name. Specify it in the hint node.\n" );
buf.Printf( "// \t\"entry_sequence\"\t\"Sequence Name\". If specified, this is used over the entry anim.\n" );
buf.Printf( "// \t\"exit_sequence\"\t\t\"Sequence Name\". If specified, this is used over the exit anim.\n" );
buf.Printf( "// \t\"min_time\"\t\t\t\"Minimum time to spend in this busy anim\"\n" );
buf.Printf( "// \t\"max_time\"\t\t\t\"Maximum time to spend in this busy anim\" 0 = only stop when interrupted by external event\n" );
buf.Printf( "// \t\"interrupts\"\t\tOne of:\n" );
buf.Printf( "// \t\t\t\t\t\t\"BA_INT_NONE\"\t\tbreak out only when time runs out. No external influence will break me out.\n" );
buf.Printf( "// \t\t\t\t\t\t\"BA_INT_DANGER\"\t\tbreak out of this anim only if threatened\n" );
buf.Printf( "// \t\t\t\t\t\t\"BA_INT_PLAYER\"\t\tbreak out of this anim if I can see the player, or I'm threatened\n" );
buf.Printf( "// \t\t\t\t\t\t\"BA_INT_AMBUSH\"\t\tsomeone please define this - I have no idea what it does\n" );
buf.Printf( "// \t\t\t\t\t\t\"BA_INT_COMBAT\"\t\tbreak out of this anim if combat occurs in my line of sight (bullet hits, grenades, etc), -OR- the max time is reached\n" );
buf.Printf( "// }\n" );
buf.Printf( "//\n" );
}
//-----------------------------------------------------------------------------
// Writes out a new actbusy file
//-----------------------------------------------------------------------------
bool CImportActBusy::Serialize( CUtlBuffer &buf, CDmElement *pRoot )
{
SerializeHeader( buf );
buf.Printf( "\"ActBusy.txt\"\n" );
buf.Printf( "{\n" );
CDmAttribute *pChildren = pRoot->GetAttribute( "children" );
if ( !pChildren || pChildren->GetType() != AT_ELEMENT_ARRAY )
return NULL;
CDmrElementArray<> children( pChildren );
int nCount = children.Count();
buf.PushTab();
for ( int i = 0; i < nCount; ++i )
{
CDmElement *pChild = children[i];
buf.Printf( "\"%s\"\n", pChild->GetName() );
buf.Printf( "{\n" );
buf.PushTab();
PrintStringAttribute( pChild, buf, "busy_anim", true );
PrintStringAttribute( pChild, buf, "entry_anim", true );
PrintStringAttribute( pChild, buf, "exit_anim", true );
PrintStringAttribute( pChild, buf, "busy_sequence", true );
PrintStringAttribute( pChild, buf, "entry_sequence", true );
PrintStringAttribute( pChild, buf, "exit_sequence", true );
PrintFloatAttribute( pChild, buf, "min_time" );
PrintFloatAttribute( pChild, buf, "max_time" );
PrintStringAttribute( pChild, buf, "interrupts" );
buf.PopTab();
buf.Printf( "}\n" );
}
buf.PopTab();
buf.Printf( "}\n" );
return true;
}
//-----------------------------------------------------------------------------
// Reads a single element
//-----------------------------------------------------------------------------
bool CImportActBusy::UnserializeActBusyKey( CDmAttribute *pChildren, KeyValues *pKeyValues )
{
CDmElement *pActBusy = CreateDmElement( "DmElement", pKeyValues->GetName(), NULL );
if ( !pActBusy )
return false;
// Each act busy needs to have an editortype associated with it so it displays nicely in editors
pActBusy->SetValue( "editorType", "actBusy" );
float flZero = 0.0f;
AddStringAttribute( pActBusy, pKeyValues, "busy_anim", "" );
AddStringAttribute( pActBusy, pKeyValues, "entry_anim", "" );
AddStringAttribute( pActBusy, pKeyValues, "exit_anim", "" );
AddStringAttribute( pActBusy, pKeyValues, "busy_sequence", "" );
AddStringAttribute( pActBusy, pKeyValues, "entry_sequence", "" );
AddStringAttribute( pActBusy, pKeyValues, "exit_sequence", "" );
AddFloatAttribute( pActBusy, pKeyValues, "min_time", &flZero );
AddFloatAttribute( pActBusy, pKeyValues, "max_time", &flZero );
AddStringAttribute( pActBusy, pKeyValues, "interrupts", "BA_INT_NONE" );
CDmrElementArray<> children( pChildren );
children.AddToTail( pActBusy );
return true;
}
//-----------------------------------------------------------------------------
// Main entry point for the unserialization
//-----------------------------------------------------------------------------
CDmElement* CImportActBusy::UnserializeFromKeyValues( KeyValues *pKeyValues )
{
// Create the main element
CDmElement *pElement = CreateDmElement( "DmElement", "ActBusyList", NULL );
if ( !pElement )
return NULL;
// Each act busy list needs to have an editortype associated with it so it displays nicely in editors
pElement->SetValue( "editorType", "actBusyList" );
// All actbusy keys are elements of a single element array attribute 'children'
CDmAttribute *pChildren = pElement->AddAttribute( "children", AT_ELEMENT_ARRAY );
if ( !pChildren )
return NULL;
// Under the root are all the actbusy keys
for ( KeyValues *pActBusyKey = pKeyValues->GetFirstTrueSubKey(); pActBusyKey != NULL; pActBusyKey = pActBusyKey->GetNextTrueSubKey() )
{
if ( !UnserializeActBusyKey( pChildren, pActBusyKey ) )
{
Warning( "Error importing actbusy element %s\n", pActBusyKey->GetName() );
return NULL;
}
}
// Resolve all element references recursively
RecursivelyResolveElement( pElement );
return pElement;
}