Otclient  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(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  }
75  else {
76  loc1 = 0;
77  loc2 = 0;
78  loc3 = 1 - (float)color / HSI_H_STEPS / (float)HSI_SI_VALUES;
79  }
80 
81  if(loc3 == 0)
82  return Color(0, 0, 0);
83 
84  if(loc2 == 0) {
85  int loc7 = int(loc3 * 255);
86  return Color(loc7, loc7, loc7);
87  }
88 
89  float red = 0, green = 0, blue = 0;
90 
91  if(loc1 < 1.0/6.0) {
92  red = loc3;
93  blue = loc3 * (1 - loc2);
94  green = blue + (loc3 - blue) * 6 * loc1;
95  }
96  else if(loc1 < 2.0/6.0) {
97  green = loc3;
98  blue = loc3 * (1 - loc2);
99  red = green - (loc3 - blue) * (6 * loc1 - 1);
100  }
101  else if(loc1 < 3.0/6.0) {
102  green = loc3;
103  red = loc3 * (1 - loc2);
104  blue = red + (loc3 - red) * (6 * loc1 - 2);
105  }
106  else if(loc1 < 4.0/6.0) {
107  blue = loc3;
108  red = loc3 * (1 - loc2);
109  green = blue - (loc3 - red) * (6 * loc1 - 3);
110  }
111  else if(loc1 < 5.0/6.0) {
112  blue = loc3;
113  green = loc3 * (1 - loc2);
114  red = green + (loc3 - green) * (6 * loc1 - 4);
115  }
116  else {
117  red = loc3;
118  green = loc3 * (1 - loc2);
119  blue = red - (loc3 - green) * (6 * loc1 - 5);
120  }
121  return Color(int(red * 255), int(green * 255), int(blue * 255));
122 }
123 
125 {
126  setHead(0);
127  setBody(0);
128  setLegs(0);
129  setFeet(0);
130  setMount(0);
131 }
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:44
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:124
Outfit::setLegs
void setLegs(int legs)
Definition: outfit.h:45