#include "stdafx.h"
#include "Global_variables_extern.h"
#include "Basics_functions.h"
#include "DB_Cost.h"
#include "Vampirism_fire.h"

bool fGetResoursesResearch(ParamPlayer *pParamPlayer, integer vNResearch, integer *vId, integer *vGoldUnit, integer *vWoodUnit)
{
	if (pParamPlayer == NULL) return FALSE;
	if (vNResearch < 0 || vNResearch >= pParamPlayer->MAX_RESEARCH) return FALSE;
	if (pParamPlayer->vResearch[vNResearch] == TRUE) return FALSE;
	switch(vNResearch)
	{
	case N_RESEARCH_LES1:
		*vGoldUnit = 0;
		*vWoodUnit = 250;
		*vId = ID_RESEARCH_LES;
		break;
	case N_RESEARCH_LES2:
		*vGoldUnit = 0;
		*vWoodUnit = 500;
		*vId = ID_RESEARCH_LES;
		break;
	case N_RESEARCH_LES3:
		*vGoldUnit = 0;
		*vWoodUnit = 750;
		*vId = ID_RESEARCH_LES;
		break;
	case N_RESEARCH_GEM1:
		*vGoldUnit = 0;
		*vWoodUnit = 500;
		*vId = ID_RESEARCH_GEM;
		break;
	case N_RESEARCH_LES_SPEED1:
		*vGoldUnit = 0;
		*vWoodUnit = 1000;
		*vId = ID_RESEARCH_LES_SPEED;
		break;
	case N_RESEARCH_GEM2:
		*vGoldUnit = 0;
		*vWoodUnit = 1000;
		*vId = ID_RESEARCH_GEM;
		break;
	case N_RESEARCH_GEM3:
		*vGoldUnit = 0;
		*vWoodUnit = 1500;
		*vId = ID_RESEARCH_GEM;
		break;
	case N_RESEARCH_RIFLES:
		*vGoldUnit = 0;
		*vWoodUnit = 1000;
		*vId = ID_RESEARCH_RIFLES;
		break;
	case N_RESEARCH_HP_WORKERS:
		*vGoldUnit = 0;
		*vWoodUnit = 2000;
		*vId = ID_RESEARCH_HP_WORKERS;
		break;
	case N_RESEARCH_MANA_REG:
		*vGoldUnit = 0;
		*vWoodUnit = 2000;
		*vId = ID_RESEARCH_MANA_REG;
		break;
	case N_RESEARCH_SLAYER_UPGRADE1:
		*vGoldUnit = 0;
		*vWoodUnit = 1000;
		*vId = ID_RESEARCH_SLAYER_UPGRADE;
		break;
	case N_RESEARCH_SLAYER_ARMOR1:
		*vGoldUnit = 0;
		*vWoodUnit = 500;
		*vId = ID_RESEARCH_SLAYER_ARMOR;
		break;
	case N_RESEARCH_SLAYER_UPGRADE2:
		*vGoldUnit = 0;
		*vWoodUnit = 2500;
		*vId = ID_RESEARCH_SLAYER_UPGRADE;
		break;
	case N_RESEARCH_SLAYER_ARMOR2:
		*vGoldUnit = 0;
		*vWoodUnit = 1000;
		*vId = ID_RESEARCH_SLAYER_ARMOR;
		break;
	case N_RESEARCH_SLAYER_UPGRADE3:
		*vGoldUnit = 0;
		*vWoodUnit = 4000;
		*vId = ID_RESEARCH_SLAYER_UPGRADE;
		break;
	case N_RESEARCH_SLAYER_ARMOR3:
		*vGoldUnit = 0;
		*vWoodUnit = 1500;
		*vId = ID_RESEARCH_SLAYER_ARMOR;
		break;
	case N_RESEARCH_SKILL_POINT:
		*vGoldUnit = 25;
		*vWoodUnit = 0;
		*vId = ID_RESEARCH_SKILL_POINT;
		break;
	case N_RESEARCH_SKILL_STRENGTH:
		*vGoldUnit = 250;
		*vWoodUnit = 0;
		*vId = ID_RESEARCH_STRENGTH;
		break;
	case N_RESEARCH_SKILL_AGILITY:
		*vGoldUnit = 300;
		*vWoodUnit = 0;
		*vId = ID_RESEARCH_AGILITY;
		break;
	case N_RESEARCH_SKILL_INTELEKT:
		*vGoldUnit = 90;
		*vWoodUnit = 0;
		*vId = ID_RESEARCH_INTELEKT;
		break;
	case N_RESEARCH_SKILL_DAMAGE:
		*vGoldUnit = 50;
		*vWoodUnit = 0;
		*vId = ID_RESEARCH_DAMAGE;
		break;
	case N_RESEARCH_SKILL_ALL_STATS_300:
		*vGoldUnit = 500;
		*vWoodUnit = 0;
		*vId = ID_RESEARCH_ALL_STATS_300;
		break;
	case N_RESEARCH_SKILL_UNDERWORLD:
		*vGoldUnit = 2000;
		*vWoodUnit = 0;
		*vId = ID_RESEARCH_UNDERWORLD;
		break;
	case N_RESEARCH_INVISIBILITY_INFERNAL:
		*vGoldUnit = 10;
		*vWoodUnit = 0;
		*vId = ID_RESEARCH_INVISIBILITY_INFERNAL;
		break;
	case N_RESEARCH_FIRE_INFERNAL:
		*vGoldUnit = 10;
		*vWoodUnit = 0;
		*vId = ID_RESEARCH_FIRE_INFERNAL;
		break;
	default:
		return FALSE;
	}
	return TRUE;
}

bool fGetResoursesUnit(integer vId, integer *vGoldUnit, integer *vWoodUnit)
{
	if (vId == NULL) return FALSE;
	switch(vId)
	{
	case ID_UNIT_WORKER:
		*vGoldUnit = 0;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_BUILD_DOM:
		*vGoldUnit = 0;
		*vWoodUnit = 10;
		break;
	case ID_UNIT_BUILD_TENT:
		*vGoldUnit = 0;
		*vWoodUnit = 20;
		break;
	case ID_UNIT_BUILD_GRADE_TENT:
		*vGoldUnit = 0;
		*vWoodUnit = 20;
		break;
	case ID_UNIT_BUILD_KUZNYA:
		*vGoldUnit = 0;
		*vWoodUnit = 150;
		break;
	case ID_UNIT_BUILD_TOWER_WHITE:
		*vGoldUnit = 0;
		*vWoodUnit = 50;
		break;
	case ID_UNIT_BUILD_SLAYER_TAVERN:
		*vGoldUnit = 0;
		*vWoodUnit = 400;
		break;
	case ID_UNIT_BUILD_WALL_BROWN:
		*vGoldUnit = 0;
		*vWoodUnit = 50;
		break;
	case ID_UNIT_BUILD_TOWER_HEAL_LVL1:
		*vGoldUnit = 0;
		*vWoodUnit = 2000;
		break;
	case ID_UNIT_BUILD_WALL_YELLOW:
		*vGoldUnit = 0;
		*vWoodUnit = 250;
		break;
	case ID_UNIT_BUILD_WALL_VIOLET:
		*vGoldUnit = 0;
		*vWoodUnit = 1000;
		break;
	case ID_UNIT_SLAYER1:
	case ID_UNIT_SLAYER2:
		*vGoldUnit = 0;
		*vWoodUnit = 400;
		break;
	case ID_UNIT_BUILD_HRAM:
		*vGoldUnit = 1;
		*vWoodUnit = 150;
		break;
	case ID_UNIT_BUILD_TOWER_GOLD:
		*vGoldUnit = 0;
		*vWoodUnit = 150;
		break;
	case ID_UNIT_BUILD_TOWER_KONUS:
		*vGoldUnit = 0;
		*vWoodUnit = 800;
		break;
	case ID_UNIT_BUILD_TOWER_MANA_LVL1:
		*vGoldUnit = 0;
		*vWoodUnit = 2000;
		break;
	case ID_UNIT_BUILD_WALL_BLUE:
		*vGoldUnit = 0;
		*vWoodUnit = 5000;
		break;
	case ID_UNIT_BUILD_LESOPILKA1:
		*vGoldUnit = 1;
		*vWoodUnit = 3000;
		break;
	case ID_UNIT_URSA:
		*vGoldUnit = 1;
		*vWoodUnit = 1000;
		break;
	case ID_UNIT_ORK:
		*vGoldUnit = 0;
		*vWoodUnit = 1000;
		break;
	case ID_UNIT_BUILD_GOLD_MINE_WHITE:
		*vGoldUnit = 0;
		*vWoodUnit = 20000;
		break;
	case ID_UNIT_BUILD_TOWER_FIRE_LVL1:
		*vGoldUnit = 0;
		*vWoodUnit = 4000;
		break;
	case ID_UNIT_BUILD_LESOPILKA2:
		*vGoldUnit = 1;
		*vWoodUnit = 10000;
		break;
	case ID_UNIT_BUILD_WALL_GREEN:
		*vGoldUnit = 0;
		*vWoodUnit = 10000;
		break;
	case ID_UNIT_BUILD_MAGAZ_HUMAN:
		*vGoldUnit = 3;
		*vWoodUnit = 1000;
		break;
	case ID_UNIT_BUILD_TOWER_EARTH_LVL1:
		*vGoldUnit = 0;
		*vWoodUnit = 2000;
		break;
	case ID_UNIT_BUILD_BOX_LVL1:
		*vGoldUnit = 0;
		*vWoodUnit = 50;
		break;
	case ID_UNIT_BUILD_TOWER_FROST:
		*vGoldUnit = 0;
		*vWoodUnit = 15000;
		break;
	case ID_UNIT_BUILD_ULTRA_RESRARCH_CENTER:
		*vGoldUnit = 10;
		*vWoodUnit = 5000;
		break;
	case ID_UNIT_BUILD_TOWER_FIRE_LVL2:
		*vGoldUnit = 0;
		*vWoodUnit = 10000;
		break;
	case ID_UNIT_SHADOW:
		*vGoldUnit = 5;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_INFERNAL:
		*vGoldUnit = 20;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_METEOR:
		*vGoldUnit = 70;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_FIRE_INFERNAL:
		*vGoldUnit = 10;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_ACIDIC_INFERNAL:
		*vGoldUnit = 20;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_FROST_INFERNAL:
		*vGoldUnit = 40;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_SHAMAN:
		*vGoldUnit = 75;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_DOGGIE:
		*vGoldUnit = 45;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_TINI:
		*vGoldUnit = 5;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_TACHKA:
		*vGoldUnit = 60;
		*vWoodUnit = 0;
		break;
	case ID_UNIT_BUILD_TOWER_ANTI_INVIZ:
		*vGoldUnit = 1;
		*vWoodUnit = 5000;
		break;
	case ID_UNIT_BUILD_TOWER_DIAMOND_LVL1:
		*vGoldUnit = 0;
		*vWoodUnit = 4000;
		break;
	case ID_UNIT_BUILD_TOWER_BLOOD_LVL1:
		*vGoldUnit = 1;
		*vWoodUnit = 15000;
		break;
	case ID_UNIT_BUILD_TOWER_OUTPOST_LVL1:
		*vGoldUnit = 0;
		*vWoodUnit = 3500;
		break;
	default:
		//vGoldUnit = 0;
		//vWoodUnit = 0;
		return FALSE;
	}
	return TRUE;
}

bool fGetResoursesItem(integer vId, integer *vGoldUnit, integer *vWoodUnit)
{
	if (vId == NULL) return FALSE;
	switch(vId)
	{
	case ID_ITEM_BOOT:
		*vGoldUnit = 100;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_DOOM:
		*vGoldUnit = 800;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_IMMORTALITY:
		*vGoldUnit = 40;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_RING:
		*vGoldUnit = 300;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_HELMET:
		*vGoldUnit = 210;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_STAFF:
		*vGoldUnit = 175;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_MANA_SHILD:
		*vGoldUnit = 70;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_URN:
		*vGoldUnit = 200;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_TELEPORT:
		*vGoldUnit = 100;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_DEMONIC_REMEINS:
		*vGoldUnit = 850;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_4000_WOOD_1_GOLD:
		*vGoldUnit = 0;
		*vWoodUnit = 4000;
		break;
	case ID_ITEM_GEM_FOR_RICO:
		*vGoldUnit = 290;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_GRIVE:
		*vGoldUnit = 30;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_CLOAK:
		*vGoldUnit = 325;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_INFERNO:
		*vGoldUnit = 150;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_INVISIBILITY:
		*vGoldUnit = 30;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_BOOST:
		*vGoldUnit = 125;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_SILENT:
		*vGoldUnit = 50;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_REFRECH_POINT:
		*vGoldUnit = 275;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_FIREFLIES:
		*vGoldUnit = 10;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_BREEZE:
		*vGoldUnit = 2;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_WARDS:
		*vGoldUnit = 15;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_BEAST_SCROLL:
		*vGoldUnit = 2;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_PLUS_20_DAMAGE:
		*vGoldUnit = 2;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_REGENERATION_RING:
		*vGoldUnit = 15;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_FLASK:
		*vGoldUnit = 2;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_ITEM_ARMOR:
		*vGoldUnit = 2;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_RECIPE_RICO:
		*vGoldUnit = 200;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_GLOVE:
		*vGoldUnit = 2000;
		*vWoodUnit = 0;
		break;
	case ID_ITEM_HELLFIRE:
		*vGoldUnit = 1800;
		*vWoodUnit = 0;
		break;
	default:
		//vGoldUnit = 0;
		//vWoodUnit = 0;
		return FALSE;
	}
	return TRUE;
}

bool fGetManaItem(integer vId, real *vMana)
{
	if (vId == NULL) return FALSE;
	switch(vId)
	{
	case ID_ITEM_BOOT:
		*vMana = 100;
		break;
	case ID_ITEM_DOOM:
		*vMana = 1000;
		break;
	case ID_ITEM_STAFF:
		*vMana = 500;
		break;
	case ID_ITEM_URN:
		*vMana = 300;
		break;
	case ID_ITEM_GEM_FOR_RICO:
		*vMana = 500;
		break;
	case ID_ITEM_INFERNO:
		*vMana = 1000;
		break;
	case ID_ITEM_BOOST:
		*vMana = 1000;
		break;
	case ID_ITEM_SILENT:
		*vMana = 1000;
		break;
	case ID_ITEM_RICO:
		*vMana = 750;
		break;
	default:
		*vMana = 0;
		break;
	}
	return TRUE;
}

integer fSetParamUnit(DataUnit *pDataUnit)
{
	if (!pDataUnit) return 0;
	if (!pDataUnit->vId) return 0;
	if (!pDataUnit->WhichUnit) return 0;
	pDataUnit->Atakovan = FALSE;
	pDataUnit->Fly = FALSE;
	pDataUnit->Zdanie = FALSE;
	pDataUnit->Dead = FALSE;
	pDataUnit->LastCoordinates.X = GetUnitX(pDataUnit->WhichUnit);
	pDataUnit->LastCoordinates.Y = GetUnitY(pDataUnit->WhichUnit);
	pDataUnit->vActionFinish = 1;
	pDataUnit->Blinked = FALSE;
	pDataUnit->Permission = FALSE;
	pDataUnit->PermissionMove = TRUE;
	pDataUnit->Lvl = TRUE;
	pDataUnit->Steals = FALSE;
	pDataUnit->vHead = NULL;
	pDataUnit->Upgrade = FALSE;
	if (pDataUnit->vNPlayer >= 0 && pDataUnit->vNPlayer <= 9)
		pDataUnit->vStorona = HUMANS;
	if (pDataUnit->vNPlayer >= 10 && pDataUnit->vNPlayer <= 11)
		pDataUnit->vStorona = VAMPIRES;
	if (pDataUnit->vNPlayer == NPLAYER_PASSIVE)
		pDataUnit->vStorona = PASSIVE;
	pDataUnit->vRadius_Unit = fRadius_Unit(pDataUnit->vId);
    pDataUnit->vDiff = fRadiusToDiff(pDataUnit->vRadius_Unit);
	pDataUnit->vPosHarvesting = 0;
	pDataUnit->Harvest = FALSE;
	switch (pDataUnit->vId)
	{
		case ID_UNIT_EMPTY1:
		case ID_UNIT_EMPTY2:
		case ID_UNIT_EMPTY3:
		case ID_UNIT_EMPTY4:
		case ID_UNIT_EMPTY5:
			return 0;
		case ID_UNIT_MAIN_HUMAN1:
		case ID_UNIT_MAIN_HUMAN2:
		case ID_UNIT_SLAYER1:
		case ID_UNIT_SLAYER2:
		case ID_UNIT_SHAMAN:
			pDataUnit->Blinked = TRUE;
		case ID_UNIT_VAMPIRE1:
		case ID_UNIT_VAMPIRE2:
		case ID_UNIT_VAMPIRE3:
		case ID_UNIT_TINI:
		case ID_UNIT_INFERNAL:
		case ID_UNIT_FIRE_INFERNAL:
		case ID_UNIT_TRACKER:
			pDataUnit->vTimeForSpeed = 0.5;
			break;
		case ID_UNIT_URSA:
			pDataUnit->Blinked = TRUE;
		case ID_UNIT_WORKER:
			pDataUnit->vRect1.vX1 = fConverterX(pDataUnit->LastCoordinates.X-pDataUnit->vRadius_Unit+(float)DOOD_MAP_SUBDIV/4);
			pDataUnit->vRect1.vY1 = fConverterY(pDataUnit->LastCoordinates.Y+pDataUnit->vRadius_Unit-(float)DOOD_MAP_SUBDIV/4);
			pDataUnit->vPosHarvesting = fConvertXYToI(pDataUnit->vRect1.vX1,pDataUnit->vRect1.vY1);
			pDataUnit->vTimeForSpeed = 0.5;
			pDataUnit->Harvest = TRUE;
			fHarvestingNearestTree(pDataUnit);
			break;
		case ID_UNIT_PASSIVE_NIZHNIY_MAGAZIN:
		case ID_UNIT_PASSIVE_VERHNIY_MAGAZIN:
		case ID_UNIT_PASSIVE_GATE:
		case ID_UNIT_PASSIVE_SVEN:
		case ID_UNIT_PASSIVE_BANSHA:
		case ID_UNIT_PASSIVE_MANA_KOLODEC:
		case ID_UNIT_PASSIVE_KOLODEC_ZHIZNI:
		case ID_UNIT_PASSIVE_BAZA_UNITOV:
		case ID_UNIT_PASSIVE_PIT_1:
		case ID_UNIT_PASSIVE_PIT_2:
		case ID_UNIT_PASSIVE_CREDITS:
		case ID_UNIT_PASSIVE_BLOOD:
		case ID_UNIT_BUILD_DOM:
		case ID_UNIT_BUILD_TENT:
		case ID_UNIT_BUILD_GRADE_TENT:
		case ID_UNIT_BUILD_KUZNYA:
		case ID_UNIT_BUILD_SLAYER_TAVERN:
		case ID_UNIT_BUILD_HRAM:
		case ID_UNIT_BUILD_WALL_BROWN:
		case ID_UNIT_BUILD_WALL_YELLOW:
		case ID_UNIT_BUILD_WALL_VIOLET:
		case ID_UNIT_BUILD_WALL_BLUE:
		case ID_UNIT_BUILD_WALL_GREEN:
		case ID_UNIT_BUILD_WALL_EMIRALD:
		case ID_UNIT_BUILD_WALL_DARKGREEN:
		case ID_UNIT_BUILD_WALL_DARKRED:
		case ID_UNIT_BUILD_WALL_RUBY:
		case ID_UNIT_BUILD_WALL_DIAMIND:
		case ID_UNIT_BUILD_CITADEL:
		case ID_UNIT_BUILD_MAGAZ_HUMAN:
		case ID_UNIT_BUILD_ULTRA_RESRARCH_CENTER:
		case ID_UNIT_BUILD_LESOPILKA1:
		case ID_UNIT_BUILD_LESOPILKA2:
		case ID_UNIT_BUILD_ZAMOK:
		case ID_UNIT_BUILD_TOVERN:
		case ID_UNIT_BUILD_GOLD_MINE_WHITE:
		case ID_UNIT_BUILD_GOLD_MINE_GREEN:
		case ID_UNIT_BUILD_GOLD_MINE_RED:
		case ID_UNIT_BUILD_GOLD_MINE_GOLD:
		case ID_UNIT_BUILD_TOWER_WHITE:
		case ID_UNIT_BUILD_TOWER_GOLD:
		case ID_UNIT_BUILD_TOWER_KONUS:
		case ID_UNIT_BUILD_TOWER_MANA_LVL1:
		case ID_UNIT_BUILD_TOWER_MANA_LVL2:
		case ID_UNIT_BUILD_TOWER_HEAL_LVL1:
		case ID_UNIT_BUILD_TOWER_HEAL_LVL2:
		case ID_UNIT_BUILD_TOWER_FIRE_LVL1:
		case ID_UNIT_BUILD_TOWER_FIRE_LVL2:
		case ID_UNIT_BUILD_TOWER_FIRE_LVL3:
		case ID_UNIT_BUILD_TOWER_DIAMOND_LVL1:
		case ID_UNIT_BUILD_TOWER_DIAMOND_LVL2:
		case ID_UNIT_BUILD_TOWER_FROST:
		case ID_UNIT_BUILD_TOWER_COMET_LVL1:
		case ID_UNIT_BUILD_TOWER_COMET_LVL2:
		case ID_UNIT_BUILD_TOWER_YAD_LVL1:
		case ID_UNIT_BUILD_TOWER_YAD_LVL2:
			//pDataUnit->vActionFinish = 0;
			pDataUnit->Zdanie = TRUE;
			if (pDataUnit->vStorona != PASSIVE)
			{
				pDataUnit->vRect1.vX1 = fConverterX(pDataUnit->LastCoordinates.X-pDataUnit->vRadius_Unit+(float)DOOD_MAP_SUBDIV/4);
				pDataUnit->vRect1.vY1 = fConverterY(pDataUnit->LastCoordinates.Y+pDataUnit->vRadius_Unit-(float)DOOD_MAP_SUBDIV/4);
				pDataUnit->vHead = vMapBases.fFillBuild(fConvertXYToI(pDataUnit->vRect1.vX1,pDataUnit->vRect1.vY1),pDataUnit->vDiff/2,pDataUnit->vDiff/2,pDataUnit->vIdDataUnit);
			}
			break;
		case ID_UNIT_VAMPIRIC_RC:
			//pDataUnit->vActionFinish = 0;
			pDataUnit->Zdanie = TRUE;
			pDataUnit->Steals = TRUE;
			break;
		case ID_UNIT_GRIVE:
			pDataUnit->Zdanie = TRUE;
			break;
		case ID_UNIT_METEOR:
			pDataUnit->Fly = TRUE;
			pDataUnit->vTimeForSpeed = 1;
			break;
		default:
			return 0;
	}
	if (pDataUnit->Zdanie == TRUE)
	{
		fGetTimeCompliteBuild(pDataUnit->vId,&pDataUnit->vTimeCompliteBuild);
		pDataUnit->vTimeStartBuild = TimerGetElapsed(vTimerGame);
		pDataUnit->vTimeEndBuild = pDataUnit->vTimeStartBuild + pDataUnit->vTimeCompliteBuild;
	}
	pDataUnit->Postroeno = FALSE;
	pDataUnit->Move = FALSE;
	pDataUnit->vTimerMove = NULL;
	pDataUnit->vAction = ACTION_WAITING;
	pDataUnit->vActionN = 0;
	pDataUnit->vCountActions = 0;
	pDataUnit->Atakuet = FALSE;
	pDataUnit->Researching = FALSE;
	pDataUnit->Researched = FALSE;

	sprintf(pDataUnit->vKeyUnit,"%d\0",pDataUnit->WhichUnit);
	sprintf(pDataUnit->vName,"%s\0",GetUnitName(pDataUnit->WhichUnit));
	//fLog(12,pDataUnit->vName);
	
	pDataUnit->vSync = FALSE;
	/*if (pDataUnit->vGoTo == TRUE)
	{
		pDataUnit->vSyncCache = InitGameCache(pDataUnit->vKeyUnit);
		//sprintf(pDataUnit->vKeyLocalPlayer,"%d\0",GetPlayerColor(GetLocalPlayer()));
	}*/
	pDataUnit->vSyncClean = FALSE;
	pDataUnit->vAI = TRUE;
	for (int vvi = 0; vvi < vCountPlayersUser; vvi++)
	{
		if (pDataUnit->vNPlayer == pPlayerUser[vvi].vNPlayer)
		{
			pDataUnit->vAI = FALSE;
			pDataUnit->Permission = TRUE;
		}
		/*if (pDataUnit->vGoTo == TRUE)
		{
			StoreInteger(pDataUnit->vSyncCache,pDataUnit->vKeyUnit,pPlayerUser[vvi].vKeyPlayer,0);
		}*/
	}
	pDataUnit->vGoToGlobal = FALSE;
	pDataUnit->EnemyAdd = FALSE;
	pDataUnit->LastCoordinatesForEnemy.X = 0;
	pDataUnit->LastCoordinatesForEnemy.Y = 0;
	pDataUnit->CoordinatesForGoToGlobal.X = 0;
	pDataUnit->CoordinatesForGoToGlobal.Y = 0;
	pDataUnit->vPickupItem = FALSE;
	pDataUnit->TargetUnit = 0;
	pDataUnit->vRaisingClifLevel = FALSE;
	pDataUnit->vTimerRaisingClifLevel = 0;
	pDataUnit->vTimeGo = 0;
	pDataUnit->vHelping = FALSE;
	pDataUnit->vStageHelp = 0;
	pDataUnit->vTimeSignalToHelp = 0;
	pDataUnit->vInt3 = 0;
	pDataUnit->vPosRepair = 0;
	pDataUnit->vTimeSync = 0;
	pDataUnit->vBoolTimeGoBuild = FALSE;
	pDataUnit->vFlagBuild = FALSE;
	//pDataUnit->vBlockNewBlink = FALSE;
	return 1;
}

bool fGetXYBuild(integer vId, unsigned short *vXBuild, unsigned short *vYBuild)
{
	if (vId == NULL) return FALSE;
	real vRadius_Unit = fRadius_Unit(vId);
    unsigned short vDiff = fRadiusToDiff(vRadius_Unit);
	if (vDiff >= 2)
	{
		*vXBuild = vDiff/2;
		*vYBuild = vDiff/2;
		return TRUE;
	}
	return FALSE;
}

real fRadius_Unit (integer vID_UNIT)
{
	switch (vID_UNIT)
	{
		case ID_UNIT_WORKER:
		case ID_UNIT_SHADOW:
			return (float)(DOOD_MAP_SUBDIV/4);
		case ID_UNIT_MAIN_HUMAN1:
		case ID_UNIT_MAIN_HUMAN2:
		case ID_UNIT_TINI:
		case ID_UNIT_TRACKER:
		case ID_UNIT_URSA:
		case ID_UNIT_SHAMAN:
			return (float)(DOOD_MAP_SUBDIV/2);
		case ID_UNIT_VAMPIRE1:
		case ID_UNIT_VAMPIRE2:
		case ID_UNIT_VAMPIRE3:
		case ID_UNIT_SLAYER1:
		case ID_UNIT_SLAYER2:
		case ID_UNIT_PASSIVE_NIZHNIY_MAGAZIN:
		case ID_UNIT_PASSIVE_VERHNIY_MAGAZIN:
		case ID_UNIT_PASSIVE_SVEN:
		case ID_UNIT_PASSIVE_BANSHA:
		case ID_UNIT_PASSIVE_CREDITS:
		case ID_UNIT_BUILD_DOM:
		case ID_UNIT_BUILD_WALL_BROWN:
		case ID_UNIT_BUILD_WALL_YELLOW:
		case ID_UNIT_BUILD_WALL_VIOLET:
		case ID_UNIT_BUILD_WALL_BLUE:
		case ID_UNIT_BUILD_WALL_GREEN:
		case ID_UNIT_BUILD_TOWER_WHITE:
		case ID_UNIT_BUILD_TOWER_GOLD:
		case ID_UNIT_BUILD_TOWER_KONUS:
		case ID_UNIT_BUILD_TOWER_MANA_LVL1:
		case ID_UNIT_BUILD_TOWER_MANA_LVL2:
		case ID_UNIT_BUILD_TOWER_HEAL_LVL1:
		case ID_UNIT_BUILD_TOWER_HEAL_LVL2:
		case ID_UNIT_BUILD_TOWER_FIRE_LVL1:
		case ID_UNIT_BUILD_TOWER_FIRE_LVL2:
		case ID_UNIT_BUILD_TOWER_FIRE_LVL3:
		case ID_UNIT_BUILD_TOWER_EARTH_LVL1:
		case ID_UNIT_BUILD_TOWER_EARTH_LVL2:
		case ID_UNIT_BUILD_TOWER_DIAMOND_LVL1:
		case ID_UNIT_BUILD_TOWER_DIAMOND_LVL2:
		case ID_UNIT_BUILD_TOWER_FROST:
		case ID_UNIT_BUILD_TOWER_COMET_LVL1:
		case ID_UNIT_BUILD_TOWER_COMET_LVL2:
		case ID_UNIT_BUILD_TOWER_YAD_LVL1:
		case ID_UNIT_BUILD_TOWER_YAD_LVL2:
		case ID_UNIT_BUILD_LESOPILKA1:
		case ID_UNIT_BUILD_LESOPILKA2:
		case ID_UNIT_INFERNAL:
		case ID_UNIT_FIRE_INFERNAL:
		case ID_UNIT_PASSIVE_BLOOD:
		case ID_UNIT_BUILD_GOLD_MINE_WHITE:
			return (float)(DOOD_MAP_SUBDIV);
		case ID_UNIT_PASSIVE_KOLODEC_ZHIZNI:
		case ID_UNIT_PASSIVE_MANA_KOLODEC:
		case ID_UNIT_PASSIVE_BAZA_UNITOV:
		case ID_UNIT_PASSIVE_PIT_1:
		case ID_UNIT_PASSIVE_PIT_2:
		case ID_UNIT_BUILD_KUZNYA:
		case ID_UNIT_VAMPIRIC_RC:
		case ID_UNIT_BUILD_SLAYER_TAVERN:
		case ID_UNIT_BUILD_HRAM:
			return (float)(DOOD_MAP_SUBDIV*2);
		case ID_UNIT_BUILD_TENT:
		case ID_UNIT_BUILD_GRADE_TENT:
		case ID_UNIT_GRIVE:
			return (float)(DOOD_MAP_SUBDIV*1.5);
		case ID_UNIT_PASSIVE_GATE:
			return (float)(DOOD_MAP_SUBDIV*3.75);
	}
    return -1;
}

bool fGetManaSpell(integer vId, integer vLvl, real *vMana)
{
	if (vId == NULL) return FALSE;
	switch(vId)
	{
	case ID_ORDER_MANABURN:
		*vMana = 3;
		break;
	case ID_ORDER_FARSIGHT:
		*vMana = 200;
		break;
	case ID_ORDER_HEALINGWAVE:
		switch(vLvl)
		{
		case 1:
			*vMana = 175;
			break;
		case 2:
			*vMana = 200;
			break;
		case 3:
			*vMana = 225;
			break;
		case 4:
			*vMana = 500;
			break;
		case 5:
			*vMana = 750;
			break;
		case 6:
			*vMana = 2000;
			break;
		case 7:
			*vMana = 3500;
			break;
		case 8:
			*vMana = 5250;
			break;
		case 9:
			*vMana = 7000;
			break;
		case 10:
			*vMana = 7500;
			break;
		}
		break;
	case ID_ORDER_STEALS:
		*vMana = 0;
		break;
	case ID_ORDER_CHAINLIGHTNING:
		*vMana = 250;
		break;
	default:
		*vMana = CONST_UNKNOWN;
		break;
	}
	return TRUE;
}

bool fGetCoolDown(integer vId, integer vLvl, real *vCoolDown)
{
	if (vId == NULL) return FALSE;
	switch(vId)
	{
	case ID_ORDER_MANABURN:
		*vCoolDown = 5;
		break;
	case ID_ORDER_FARSIGHT:
		switch(vLvl)
		{
		case 1:
			*vCoolDown = 30;
			break;
		case 2:
			*vCoolDown = 20;
			break;
		}
		break;
	case ID_ORDER_HEALINGWAVE:
	case ID_ORDER_CHAINLIGHTNING:
		*vCoolDown = 10;
		break;
	case ID_ORDER_STEALS:
		switch(vLvl)
		{
		case 1:
			*vCoolDown = 150;
			break;
		case 2:
			*vCoolDown = 100;
			break;
		case 3:
			*vCoolDown = 50;
			break;
		}
		break;
	default:
		*vCoolDown = CONST_UNKNOWN;
		break;
	}
	return TRUE;
}

bool fGetCoolDamage(integer vId, integer vLvl, real *vDamage)
{
	if (vId == NULL) return FALSE;
	switch(vId)
	{
	case ID_ORDER_MANABURN:
		*vDamage = 500;
		break;
	case ID_ORDER_HEALINGWAVE:
		switch(vLvl)
		{
		case 1:
			*vDamage = 1000;
			break;
		case 2:
			*vDamage = 1500;
			break;
		case 3:
			*vDamage = 2000;
			break;
		case 4:
			*vDamage = 3000;
			break;
		case 5:
			*vDamage = 4500;
			break;
		case 6:
			*vDamage = 6000;
			break;
		case 7:
			*vDamage = 7500;
			break;
		case 8:
			*vDamage = 9000;
			break;
		case 9:
			*vDamage = 11500;
			break;
		case 10:
			*vDamage = 15000;
			break;
		}
		break;
	case ID_ORDER_CHAINLIGHTNING:
		switch(vLvl)
		{
		case 1:
			*vDamage = 125;
			break;
		case 2:
			*vDamage = 150;
			break;
		case 3:
			*vDamage = 175;
			break;
		case 4:
			*vDamage = 200;
			break;
		case 5:
			*vDamage = 225;
			break;
		case 6:
			*vDamage = 250;
			break;
		case 7:
			*vDamage = 275;
			break;
		case 8:
			*vDamage = 300;
			break;
		case 9:
			*vDamage = 325;
			break;
		case 10:
			*vDamage = 350;
			break;
		case 11:
			*vDamage = 375;
			break;
		case 12:
			*vDamage = 400;
			break;
		case 13:
			*vDamage = 425;
			break;
		case 14:
			*vDamage = 450;
			break;
		case 15:
			*vDamage = 475;
			break;
		}
		break;
	default:
		*vDamage = CONST_UNKNOWN;
		break;
	}
	return TRUE;
}

bool fGetCoolRadius(integer vId, integer vLvl, real *vRadius)
{
	if (vId == NULL) return FALSE;
	switch(vId)
	{
	case ID_ORDER_HEALINGWAVE:
	case ID_ORDER_CHAINLIGHTNING:
		*vRadius = 128*16;
		break;
	case ID_ORDER_MANABURN:
		*vRadius = 128*2.5;
		break;
	default:
		*vRadius = CONST_UNKNOWN;
		break;
	}
	return TRUE;
}

bool fGetAttackRadius(integer vId, real *vRadius)
{
	if (vId == NULL) return FALSE;
	switch(vId)
	{
	case ID_UNIT_BUILD_TOWER_WHITE:
		*vRadius = 128*8;
		break;
	case ID_UNIT_BUILD_TOWER_GOLD:
		*vRadius = 128*8;
		break;
	case ID_UNIT_BUILD_TOWER_KONUS:
		*vRadius = 128*8;
		break;
	case ID_UNIT_BUILD_TOWER_FIRE_LVL1:
		*vRadius = 128*10;
		break;
	default:
		*vRadius = CONST_UNKNOWN;
		break;
	}
	return TRUE;
}

bool fGetId(unsigned short vComment, unsigned short vStage, integer *vId)
{
	if (vComment < 0) return FALSE;
	switch(vComment)
	{
	case COMMENT_MAIN_HUMAN:
		*vId = ID_UNIT_MAIN_HUMAN1;
		break;
	case COMMENT_FIRST_DOM:
		if (vStage >= 100 && vStage <= 1000)
		{
			*vId = ID_UNIT_BUILD_LESOPILKA1;
			break;
		}
	case COMMENT_SECOND_DOM:
	case COMMENT_THIRD_DOM:
	case COMMENT_FOURTH_DOM:
	case COMMENT_FIFTH_DOM:
	case COMMENT_SIXTH_DOM:
		*vId = ID_UNIT_BUILD_DOM;
		break;
	case COMMENT_FIRST_TENT:
	case COMMENT_SECOND_TENT:
	case COMMENT_THIRD_TENT:
	case COMMENT_FOURTH_TENT:
		if (vStage >= 60 && vStage <= 1000)
		{
			*vId = ID_UNIT_BUILD_GRADE_TENT;
			break;
		}
		*vId = ID_UNIT_BUILD_TENT;
		break;
	case COMMENT_FIRST_KUZNYA:
		*vId = ID_UNIT_BUILD_KUZNYA;
		break;
	case COMMENT_MAIN_WALL:
		if (vStage >= 80 && vStage <= 98)
		{
			*vId = ID_UNIT_BUILD_WALL_VIOLET;
			break;
		}
		if (vStage >= 99 && vStage <= 1000)
		{
			*vId = ID_UNIT_BUILD_WALL_BLUE;
			break;
		}
		*vId = ID_UNIT_BUILD_WALL_BROWN;
		break;
	case COMMENT_SLAYER:
		*vId = ID_UNIT_SLAYER1;
		break;
	case COMMENT_TAVERN_SLAYER:
		*vId = ID_UNIT_BUILD_SLAYER_TAVERN;
		break;
	case COMMENT_TEMPLE:
		*vId = ID_UNIT_BUILD_HRAM;
		break;
	case COMMENT_FIRE_1:
	case COMMENT_FIRE_2:
		*vId = ID_UNIT_BUILD_TOWER_FIRE_LVL1;
		break;
	default:
		*vId = COMMENT_NO_UNIT;
		break;
	}
	return TRUE;
}

bool fGetTimeCompliteBuild(integer vId, float *vTime)
{
	if (vId <= 0) return FALSE;
	switch(vId)
	{
	case ID_UNIT_BUILD_DOM:
		*vTime = 2.0;//1.3;
		break;
	case ID_UNIT_BUILD_TOWER_WHITE:
	case ID_UNIT_BUILD_TENT:
		*vTime = 2.3;
		break;
	case ID_UNIT_VAMPIRIC_RC:
	case ID_UNIT_BUILD_HRAM:
		*vTime = 3.0;//2.3;
		break;
	case ID_UNIT_BUILD_WALL_BROWN:
		*vTime = 3.0;//1.3;
		break;
	case ID_UNIT_BUILD_TOWER_HEAL_LVL1:
		*vTime = 5;
		break;
	case ID_UNIT_BUILD_KUZNYA:
	case ID_UNIT_BUILD_SLAYER_TAVERN:
		*vTime = 3.0;//2.3;
		break;
	default:
		*vTime = 100;
		break;
	}
	return TRUE;
}

bool fGetTimeCompliteResearch(integer vNResearch, float *vTime)
{
	if (vNResearch <= 0) return FALSE;
	switch(vNResearch)
	{
	case N_RESEARCH_LES1:
	case N_RESEARCH_LES2:
	case N_RESEARCH_LES3:
		*vTime = 35.3;
		break;
	case N_RESEARCH_GEM1:
	case N_RESEARCH_GEM2:
	case N_RESEARCH_GEM3:
	case N_RESEARCH_LES_SPEED1:
		*vTime = 40.3;
		break;
	case N_RESEARCH_RIFLES:
		*vTime = 60;
		break;
	case N_RESEARCH_HP_WORKERS:
		*vTime = 60;
		break;
	case N_RESEARCH_MANA_REG:
		*vTime = 30.3;
		break;
	case N_RESEARCH_SLAYER_UPGRADE1:
		*vTime = 60;
		break;
	case N_RESEARCH_SLAYER_UPGRADE2:
		*vTime = 60;
		break;
	case N_RESEARCH_SLAYER_UPGRADE3:
		*vTime = 60;
		break;
	case N_RESEARCH_SLAYER_ARMOR1:
		*vTime = 60;
		break;
	case N_RESEARCH_SLAYER_ARMOR2:
		*vTime = 60;
		break;
	case N_RESEARCH_SLAYER_ARMOR3:
		*vTime = 60;
		break;
	case N_RESEARCH_SKILL_POINT:
		*vTime = 60;
		break;
	case N_RESEARCH_SKILL_STRENGTH:
		*vTime = 60;
		break;
	case N_RESEARCH_SKILL_AGILITY:
		*vTime = 60;
		break;
	case N_RESEARCH_SKILL_INTELEKT:
		*vTime = 60;
		break;
	case N_RESEARCH_SKILL_DAMAGE:
		*vTime = 60;
		break;
	case N_RESEARCH_SKILL_ALL_STATS_300:
		*vTime = 60;
		break;
	case N_RESEARCH_SKILL_UNDERWORLD:
		*vTime = 60;
		break;
	case N_RESEARCH_INVISIBILITY_INFERNAL:
		*vTime = 60;
		break;
	case N_RESEARCH_FIRE_INFERNAL:
		*vTime = 10;
		break;
	default:
		*vTime = 100;
		break;
	}
	return TRUE;
}

bool fGetTimeCompliteTrain(integer vId, float *vTime)
{
	if (vId <= 0) return FALSE;
	switch(vId)
	{
	case ID_UNIT_BUILD_WALL_YELLOW:
		*vTime = 5.3;
		break;
	case ID_UNIT_BUILD_WALL_VIOLET:
		*vTime = 10.3;
		break;
	case ID_UNIT_BUILD_TOWER_GOLD:
	case ID_UNIT_BUILD_TOWER_KONUS:
	case ID_UNIT_BUILD_TOWER_FIRE_LVL1:
		*vTime = 5.3;
		break;
	case ID_UNIT_BUILD_GRADE_TENT:
		*vTime = 2.0;//1.3;
		break;
	case ID_UNIT_SLAYER1:
	case ID_UNIT_SLAYER2:
		*vTime = 60.3;
		break;
	case ID_UNIT_BUILD_WALL_BLUE:
		*vTime = 20.3;
		break;
	default:
		*vTime = 100;
		break;
	}
	return TRUE;
}