// ################################
// ##  Tridy pevnosti (ne tridy  ##
// ##  cpp, ale ve smyslu typy)  ##
// ################################

#pragma once
#ifndef FORTRESS_CLASSES_H
#define FORTRESS_CLASSES_H

#include "common.h"
#include "common_routines.h"

#include "cache_list.h"

using namespace std;

// ################################
// ################################

class fortressClass;
class hangarClass;

// ################################
// ################################

enum fortressesTypes
{
	FT_BASE = 1,
	FT_SHIP = 2
};

// ################################
// ################################

#define SHIPS_REPAIRABILITY_FOR_ALL_CLASSES        1
#define SHIPS_CONSTRUCTION_TO_REPAIRABILITY_RATIO  256

// ################################
// ################################

class fortressClassClass : public dataListObjectClass
{
private:
	string             className_;
	fortressesTypes    classType_;
	unsigned long long minWeight_;
	unsigned long long maxWeight_;
	unsigned long long minTotalStructuralIntegrity_;
	unsigned long long maxTotalStructuralIntegrity_;
	double             maxLength_;
	double             maxWidth_;
	double             maxHeight_;
	unsigned long      maxDroneMissileLaunchers_;
	unsigned long      maxLaserGuns_;
	unsigned long      maxWeaponsTotal_;
	unsigned long      accomodationPointsTotal_;
	double             qualityRating_; // od 0 do 1; 0 je shitka, 1 nejlepsi lod
	double             massRating_;    // od 0 do 1; 0 je lehka, 1 hrozne tezka lod
public:
	fortressClass * deriveNewFortress(hangarClass * hangar, unsigned long long &titaniumForConstruction, bool divineBuilding);

    /* konstruktor pro databazi */
    fortressClassClass() {};
	fortressClassClass(string             className,
		               fortressesTypes    classType,
					   unsigned long long minWeight,
					   unsigned long long maxWeight,
					   unsigned long long minTotalStructuralIntegrity,
					   unsigned long long maxTotalStructuralIntegrity,
					   double             maxLength,
					   double             maxWidth,
					   double             maxHeight,
					   unsigned long      maxDroneMissileLaunchers,
					   unsigned long      maxLaserGuns,
					   unsigned long      maxWeaponsTotal,
					   unsigned long      accomodationPointsTotal,
					   double             qualityRating,
					   double             massRating):
					   className_(className),
					   classType_(classType),
					   minWeight_(minWeight),
					   maxWeight_(maxWeight),
					   minTotalStructuralIntegrity_(minTotalStructuralIntegrity),
					   maxTotalStructuralIntegrity_(maxTotalStructuralIntegrity),
					   maxLength_(maxLength),
					   maxWidth_(maxWidth),
					   maxHeight_(maxHeight),
					   maxDroneMissileLaunchers_(maxDroneMissileLaunchers),
					   maxLaserGuns_(maxLaserGuns),
					   maxWeaponsTotal_(maxWeaponsTotal),
					   accomodationPointsTotal_(accomodationPointsTotal),
					   qualityRating_(qualityRating),
					   massRating_(massRating)
	                   {
						   if ((maxWeight                   < minWeight                  ) ||
							   (maxTotalStructuralIntegrity < minTotalStructuralIntegrity))
						   {							   
							   minWeight_                   = min(minWeight                  , maxWeight                  );
							   maxWeight_                   = max(minWeight                  , maxWeight                  );
							   minTotalStructuralIntegrity_ = min(minTotalStructuralIntegrity, maxTotalStructuralIntegrity);
							   maxTotalStructuralIntegrity_ = max(minTotalStructuralIntegrity, maxTotalStructuralIntegrity);
                               errLogicalError("invalid range: %u", (unsigned long long)this->getID());
						   }
					   };
	
	string             getClassName()                                                             { return className_;                                                                                          };
	fortressesTypes    getClassType()                                                             { return classType_;                                                                                          };
	unsigned long long getMinWeight()                                                             { return minWeight_;                                                                                          };
	unsigned long long getMaxWeight()                                                             { return maxWeight_;                                                                                          };
	unsigned long long checkWeight(unsigned long long weight)                                     { return ullCheckRange(minWeight_, maxWeight_, weight);                                                       };
	unsigned long long getMinTotalStructuralIntegrity()                                           { return minTotalStructuralIntegrity_;                                                                        };
	unsigned long long getMaxTotalStructuralIntegrity()                                           { return maxTotalStructuralIntegrity_;                                                                        };
	unsigned long long checkTotalStructuralIntegrity(unsigned long long totalStructuralIntegrity) { return ullCheckRange(minTotalStructuralIntegrity_, maxTotalStructuralIntegrity_, totalStructuralIntegrity); };
	double             getMaxLength()                                                             { return maxLength_;                                                                                          };
	double             getMaxWidth()                                                              { return maxWidth_;                                                                                           };
	double             getMaxHeight()                                                             { return maxHeight_;                                                                                          };
	unsigned long      getMaxDroneMissileLaunchers()                                              { return maxDroneMissileLaunchers_;                                                                           };
	unsigned long      getMaxLaserGuns()                                                          { return maxLaserGuns_;                                                                                       };
	unsigned long      getMaxWeapons()                                                            { return maxWeaponsTotal_;                                                                                    };
	unsigned long      getAccomodationPointsTotal()                                               { return accomodationPointsTotal_;                                                                            };
	double             getQualityRating()                                                         { return qualityRating_;                                                                                      };
	double             getMassRating()                                                            { return massRating_;                                                                                         };
//	unsigned long      checkDroneMissileLaunchers(unsigned long count)                            { return min(maxDroneMissileLaunchers_, count);                                                               };
//	unsigned long      checkLaserGuns(unsigned long count)                                        { return min(maxLaserGuns_, count);                                                                           };
//	unsigned long      checkWeapons(unsigned long count)                                          { return min(maxWeaponsTotal_, count);                                                                        };

			 bool      fitShipIntoWeightAndHangar(itemDimensionsClass * shipDimensions);
	         bool      getDimensionsByWeight(unsigned long long &buildingTitanium, double &length, double &width, double &height);
			 bool      getDimensionsByWeight(itemDimensionsClass * fortressDimensions);
	         bool      shipFitsIntoHangar(hangarClass * hangar, unsigned long long buildingTitanium);
    virtual ~fortressClassClass() {};


	virtual void          DB_Load       (  unsigned long ID                );
	virtual void          DB_Save       (  unsigned long ID                );
	virtual void          DB_Insert     (  unsigned long ID                );
};

// ################################
// ################################

#endif