]> git.localhorst.tv Git - l2e.git/blob - src/battle/PartyLayout.cpp
added Sort function to Inventory
[l2e.git] / src / battle / PartyLayout.cpp
1 /*
2  * PartyLayout.cpp
3  *
4  *  Created on: Aug 5, 2012
5  *      Author: holy
6  */
7
8 #include "PartyLayout.h"
9
10 #include "../loader/Interpreter.h"
11 #include "../loader/TypeDescription.h"
12
13 using geometry::Vector;
14 using loader::FieldDescription;
15 using loader::Interpreter;
16 using loader::TypeDescription;
17 using std::vector;
18
19 namespace battle {
20
21 Vector<int> PartyLayout::CalculatePosition(int index, int width, int height) const {
22         assert(index >= 0 && index < numPositions);
23         return Vector<int>(
24                         positions[index].X() * width / 255,
25                         positions[index].Y() * height / 223
26                         );
27 }
28
29 void PartyLayout::CalculatePositions(int width, int height, vector<Vector<int> > &dest) const {
30         dest.clear();
31         dest.reserve(numPositions);
32         for (int i(0); i < numPositions; ++i) {
33                 dest.push_back(Vector<int>(
34                                 positions[i].X() * width / 255,
35                                 positions[i].Y() * height / 223
36                                 ));
37         }
38 }
39
40
41 void PartyLayout::CreateTypeDescription() {
42         PartyLayout p;
43
44         TypeDescription &td(TypeDescription::Create(TYPE_ID, "PartyLayout"));
45         td.SetDescription("Positions of party members");
46         td.SetConstructor(&Construct);
47         td.SetSize(sizeof(PartyLayout));
48
49         td.AddField("positions", FieldDescription(((char *)&p.positions) - ((char *)&p), Interpreter::VECTOR_ID).SetReferenced().SetAggregate().SetDescription("the members' positions"));
50 }
51
52 void PartyLayout::Construct(void *data) {
53         new (data) PartyLayout;
54 }
55
56 }