Otclient 1.0  14/8/2020
outfit.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #include "outfit.h"
24 
26 {
27  m_category = ThingCategoryCreature;
28  m_id = 128;
29  m_auxId = 0;
30  resetClothes();
31 }
32 
34 {
35  if(color >= HSI_H_STEPS * HSI_SI_VALUES)
36  color = 0;
37 
38  float loc1 = 0, loc2 = 0, loc3 = 0;
39  if(color % HSI_H_STEPS != 0) {
40  loc1 = color % HSI_H_STEPS * 1.0 / 18.0;
41  loc2 = 1;
42  loc3 = 1;
43 
44  switch(static_cast<int>(color / HSI_H_STEPS)) {
45  case 0:
46  loc2 = 0.25;
47  loc3 = 1.00;
48  break;
49  case 1:
50  loc2 = 0.25;
51  loc3 = 0.75;
52  break;
53  case 2:
54  loc2 = 0.50;
55  loc3 = 0.75;
56  break;
57  case 3:
58  loc2 = 0.667;
59  loc3 = 0.75;
60  break;
61  case 4:
62  loc2 = 1.00;
63  loc3 = 1.00;
64  break;
65  case 5:
66  loc2 = 1.00;
67  loc3 = 0.75;
68  break;
69  case 6:
70  loc2 = 1.00;
71  loc3 = 0.50;
72  break;
73  }
74  } else {
75  loc1 = 0;
76  loc2 = 0;
77  loc3 = 1 - static_cast<float>(color) / HSI_H_STEPS / static_cast<float>(HSI_SI_VALUES);
78  }
79 
80  if(loc3 == 0)
81  return Color(0, 0, 0);
82 
83  if(loc2 == 0) {
84  const int loc7 = static_cast<int>(loc3 * 255);
85  return Color(loc7, loc7, loc7);
86  }
87 
88  float red = 0, green = 0, blue = 0;
89 
90  if(loc1 < 1.0 / 6.0) {
91  red = loc3;
92  blue = loc3 * (1 - loc2);
93  green = blue + (loc3 - blue) * 6 * loc1;
94  } else if(loc1 < 2.0 / 6.0) {
95  green = loc3;
96  blue = loc3 * (1 - loc2);
97  red = green - (loc3 - blue) * (6 * loc1 - 1);
98  } else if(loc1 < 3.0 / 6.0) {
99  green = loc3;
100  red = loc3 * (1 - loc2);
101  blue = red + (loc3 - red) * (6 * loc1 - 2);
102  } else if(loc1 < 4.0 / 6.0) {
103  blue = loc3;
104  red = loc3 * (1 - loc2);
105  green = blue - (loc3 - red) * (6 * loc1 - 3);
106  } else if(loc1 < 5.0 / 6.0) {
107  blue = loc3;
108  green = loc3 * (1 - loc2);
109  red = green + (loc3 - green) * (6 * loc1 - 4);
110  } else {
111  red = loc3;
112  green = loc3 * (1 - loc2);
113  blue = red - (loc3 - green) * (6 * loc1 - 5);
114  }
115  return Color(static_cast<int>(red * 255), static_cast<int>(green * 255), static_cast<int>(blue * 255));
116 }
117 
119 {
120  setHead(0);
121  setBody(0);
122  setLegs(0);
123  setFeet(0);
124  setMount(0);
125 }
Outfit::getColor
static Color getColor(int color)
Definition: outfit.cpp:33
Outfit::Outfit
Outfit()
Definition: outfit.cpp:25
Outfit::setBody
void setBody(int body)
Definition: outfit.h:44
Color
Definition: color.h:32
Outfit::setFeet
void setFeet(int feet)
Definition: outfit.h:46
ThingCategoryCreature
@ ThingCategoryCreature
Definition: thingtype.h:47
Outfit::setHead
void setHead(int head)
Definition: outfit.h:43
Outfit::setMount
void setMount(int mount)
Definition: outfit.h:48
outfit.h
Outfit::resetClothes
void resetClothes()
Definition: outfit.cpp:118
Outfit::setLegs
void setLegs(int legs)
Definition: outfit.h:45