xoreos  0.0.5
functions_2da.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/util.h"
26 
27 #include "src/aurora/2dafile.h"
28 #include "src/aurora/2dareg.h"
29 
31 
33 
34 namespace Engines {
35 
36 namespace Jade {
37 
39  const Aurora::TwoDAFile &scriptlist = TwoDAReg.get2DA("scriptlist");
40  int32 twodasNr = scriptlist.getRow(nr).getInt("2da");
41 
42  const Aurora::TwoDAFile &twodas = TwoDAReg.get2DA("2das");
43  const Common::UString twodaName = twodas.getRow(twodasNr).getString("file");
44 
45  return TwoDAReg.get2DA(twodaName);
46 }
47 
49  int32 tableNr = ctx.getParams()[0].getInt();
50 
51  const Aurora::TwoDAFile &table = findTable(tableNr);
52 
53  ctx.getReturn() = (int32) table.getRowCount();
54 }
55 
57  int32 tableNr = ctx.getParams()[0].getInt();
58 
59  const Aurora::TwoDAFile &table = findTable(tableNr);
60 
61  ctx.getReturn() = (int32) table.getColumnCount();
62 }
63 
65  int32 tableNr = ctx.getParams()[0].getInt();
66  int32 rowNr = ctx.getParams()[1].getInt();
67  Common::UString &columnName = ctx.getParams()[2].getString();
68 
69  const Aurora::TwoDAFile &table = findTable(tableNr);
70 
71  ctx.getReturn() = table.getRow(rowNr).getInt(columnName);
72 }
73 
75  int32 tableNr = ctx.getParams()[0].getInt();
76  int32 rowNr = ctx.getParams()[1].getInt();
77  Common::UString &columnName = ctx.getParams()[2].getString();
78 
79  const Aurora::TwoDAFile &table = findTable(tableNr);
80 
81  ctx.getReturn() = table.getRow(rowNr).getFloat(columnName);
82 }
83 
85  int32 tableNr = ctx.getParams()[0].getInt();
86  int32 rowNr = ctx.getParams()[1].getInt();
87  Common::UString &columnName = ctx.getParams()[2].getString();
88 
89  const Aurora::TwoDAFile &table = findTable(tableNr);
90 
91  ctx.getReturn() = table.getRow(rowNr).getString(columnName);
92 }
93 
95  int32 tableNr = ctx.getParams()[0].getInt();
96  int32 rowNr = ctx.getParams()[1].getInt();
97  int32 columnNr = ctx.getParams()[2].getInt();
98 
99  const Aurora::TwoDAFile &table = findTable(tableNr);
100 
101  ctx.getReturn() = table.getRow(rowNr).getInt(columnNr);
102 }
103 
105  int32 tableNr = ctx.getParams()[0].getInt();
106  int32 rowNr = ctx.getParams()[1].getInt();
107  int32 columnNr = ctx.getParams()[2].getInt();
108 
109  const Aurora::TwoDAFile &table = findTable(tableNr);
110 
111  ctx.getReturn() = table.getRow(rowNr).getFloat(columnNr);
112 }
113 
115  int32 tableNr = ctx.getParams()[0].getInt();
116  int32 rowNr = ctx.getParams()[1].getInt();
117  int32 columnNr = ctx.getParams()[2].getInt();
118 
119  const Aurora::TwoDAFile &table = findTable(tableNr);
120 
121  ctx.getReturn() = table.getRow(rowNr).getString(columnNr);
122 }
123 
124 } // End of namespace Jade
125 
126 } // End of namespace Engines
void get2DAEntryFloatByString(Aurora::NWScript::FunctionContext &ctx)
Class to hold the two-dimensional array of a 2DA file.
Definition: 2dafile.h:124
const Common::UString & getString(size_t column) const
Return the contents of a cell as a string.
Definition: 2dafile.cpp:59
void get2DAEntryIntByString(Aurora::NWScript::FunctionContext &ctx)
A class holding an UTF-8 string.
Definition: ustring.h:48
Context of an NWScript function.
Jade Empire engine functions.
const Aurora::TwoDAFile & findTable(int32 nr)
size_t getRowCount() const
Return the number of rows in the array.
Definition: 2dafile.cpp:400
size_t getColumnCount() const
Return the number of columns in the array.
Definition: 2dafile.cpp:404
void get2DAEntryStringByString(Aurora::NWScript::FunctionContext &ctx)
Utility templates and functions.
Handling BioWare&#39;s 2DAs (two-dimensional array).
void get2DAEntryString(Aurora::NWScript::FunctionContext &ctx)
void get2DANumColumn(Aurora::NWScript::FunctionContext &ctx)
#define TwoDAReg
Shortcut for accessing the 2da registry.
Definition: 2dareg.h:101
The global 2DA registry.
int32 getInt(size_t column) const
Return the contents of a cell as an int.
Definition: 2dafile.cpp:75
void get2DAEntryFloat(Aurora::NWScript::FunctionContext &ctx)
const TwoDARow & getRow(size_t row) const
Get a row.
Definition: 2dafile.cpp:421
void get2DAEntryInt(Aurora::NWScript::FunctionContext &ctx)
void get2DANumRows(Aurora::NWScript::FunctionContext &ctx)
float getFloat(size_t column) const
Return the contents of a cell as a float.
Definition: 2dafile.cpp:91
int32_t int32
Definition: types.h:203