tibia-client/src/otclient/outfit.cpp

130 lines
3.4 KiB
C++
Raw Normal View History

2011-11-13 09:46:19 +01:00
/*
2012-01-02 17:58:37 +01:00
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
2011-11-13 09:46:19 +01:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "outfit.h"
2011-12-02 03:29:05 +01:00
Outfit::Outfit()
{
2012-06-21 19:54:20 +02:00
m_category = DatCreatureCategory;
m_id = 0;
2012-01-09 22:16:50 +01:00
resetClothes();
2011-12-02 03:29:05 +01:00
}
Color Outfit::getColor(int color)
2011-11-13 09:46:19 +01:00
{
if(color >= HSI_H_STEPS * HSI_SI_VALUES)
color = 0;
float loc1 = 0, loc2 = 0, loc3 = 0;
if(color % HSI_H_STEPS != 0) {
loc1 = color % HSI_H_STEPS * 1.0/18.0;
loc2 = 1;
loc3 = 1;
switch(int(color / HSI_H_STEPS)) {
case 0:
loc2 = 0.25;
loc3 = 1.00;
break;
case 1:
loc2 = 0.25;
loc3 = 0.75;
break;
case 2:
loc2 = 0.50;
loc3 = 0.75;
break;
case 3:
loc2 = 0.667;
loc3 = 0.75;
break;
case 4:
loc2 = 1.00;
loc3 = 1.00;
break;
case 5:
loc2 = 1.00;
loc3 = 0.75;
break;
case 6:
loc2 = 1.00;
loc3 = 0.50;
break;
}
}
else {
loc1 = 0;
loc2 = 0;
loc3 = 1 - (float)color / HSI_H_STEPS / (float)HSI_SI_VALUES;
}
if(loc3 == 0)
return Color(0, 0, 0);
2012-07-14 19:29:42 +02:00
if(loc2 == 0) {
2011-11-13 09:46:19 +01:00
int loc7 = int(loc3 * 255);
return Color(loc7, loc7, loc7);
}
2011-12-02 03:29:05 +01:00
float red = 0, green = 0, blue = 0;
2011-11-13 09:46:19 +01:00
if(loc1 < 1.0/6.0) {
2011-12-02 03:29:05 +01:00
red = loc3;
blue = loc3 * (1 - loc2);
green = blue + (loc3 - blue) * 6 * loc1;
2011-11-13 09:46:19 +01:00
}
2012-07-14 19:29:42 +02:00
else if(loc1 < 2.0/6.0) {
2011-12-02 03:29:05 +01:00
green = loc3;
blue = loc3 * (1 - loc2);
red = green - (loc3 - blue) * (6 * loc1 - 1);
2011-11-13 09:46:19 +01:00
}
else if(loc1 < 3.0/6.0) {
2011-12-02 03:29:05 +01:00
green = loc3;
red = loc3 * (1 - loc2);
blue = red + (loc3 - red) * (6 * loc1 - 2);
2011-11-13 09:46:19 +01:00
}
2012-07-14 19:29:42 +02:00
else if(loc1 < 4.0/6.0) {
2011-12-02 03:29:05 +01:00
blue = loc3;
red = loc3 * (1 - loc2);
green = blue - (loc3 - red) * (6 * loc1 - 3);
2011-11-13 09:46:19 +01:00
}
2012-07-14 19:29:42 +02:00
else if(loc1 < 5.0/6.0) {
2011-12-02 03:29:05 +01:00
blue = loc3;
green = loc3 * (1 - loc2);
red = green + (loc3 - green) * (6 * loc1 - 4);
2011-11-13 09:46:19 +01:00
}
else {
2011-12-02 03:29:05 +01:00
red = loc3;
green = loc3 * (1 - loc2);
blue = red - (loc3 - green) * (6 * loc1 - 5);
2011-11-13 09:46:19 +01:00
}
2011-12-02 03:29:05 +01:00
return Color(int(red * 255), int(green * 255), int(blue * 255));
2011-11-13 09:46:19 +01:00
}
2011-12-29 20:36:43 +01:00
void Outfit::resetClothes()
{
setHead(0);
setBody(0);
setLegs(0);
setFeet(0);
}