1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "ai_actions.h"
23 bool CAIActions::_init
;
24 CAIActions::IExecutor
*CAIActions::_executor
;
26 void CAIActions::openFile(const std::string
&fileName
)
28 nlassert(_init
==true);
29 _executor
->openFile(fileName
);
31 void CAIActions::closeFile(const std::string
&fileName
)
33 nlassert(_init
==true);
34 _executor
->closeFile(fileName
);
37 void CAIActions::begin(uint32 contextAlias
)
39 nlassert(_init
==true);
40 _executor
->begin(contextAlias
);
43 void CAIActions::end(uint32 contextAlias
)
45 nlassert(_init
==true);
46 _executor
->end(contextAlias
);
49 static uint64
stringToInt64(const char *str
)
53 for (i
=0;i
<8 && str
[i
]!=0;++i
)
54 ((char *)&id
)[i
]=str
[i
];
56 // the following assert ensures that we never try to cram >8 letters into an int64
65 static uint64
stringToInt64(const string
&str
)
67 return stringToInt64(str
.c_str());
70 void CAIActions::execute(const string
&action
,const std::vector
<CAIActions::CArg
> &args
)
72 H_AUTO(CAIActions_execute
);
73 nlassert(_init
==true);
75 _executor
->execute(stringToInt64(action
),args
);
78 void CAIActions::execute(const string
&action
,const std::vector
<std::string
> &stringArgs
)
80 H_AUTO(CAIActions_execute
);
81 nlassert(_init
==true);
83 // build an argument vector from the string vector
84 std::vector
<CAIActions::CArg
> args
;
85 for (uint j
=0;j
<stringArgs
.size();++j
)
86 args
.push_back(CAIActions::CArg(stringArgs
[j
]));
88 _executor
->execute(stringToInt64(action
),args
);
91 void CAIActions::execute(const string
&action
,const std::vector
<int> &rawArgs
)
93 H_AUTO(CAIActions_execute
);
94 nlassert(_init
==true);
96 // build an argument vector from the string vector
97 std::vector
<CAIActions::CArg
> args
;
98 for (uint j
=0;j
<rawArgs
.size();++j
)
99 args
.push_back(CAIActions::CArg(rawArgs
[j
]));
101 _executor
->execute(stringToInt64(action
),args
);
104 void CAIActions::execute(const string
&action
,const std::vector
<double> &rawArgs
)
106 H_AUTO(CAIActions_execute
);
107 nlassert(_init
==true);
109 // build an argument vector from the string vector
110 std::vector
<CAIActions::CArg
> args
;
111 for (uint j
=0;j
<rawArgs
.size();++j
)
112 args
.push_back(CAIActions::CArg(rawArgs
[j
]));
114 _executor
->execute(stringToInt64(action
),args
);
117 void CAIActions::execute(const string
&action
)
119 H_AUTO(CAIActions_execute
);
120 std::vector
<CAIActions::CArg
> emptyVector
;
121 execute(action
,emptyVector
);