// ---------------------------------------------------------------------------------------------------------
//  Autor: Monsada (SMM) 27.11.2009
//		(smirall@hotmail.com)
//		http://www.simulacion-esp.com/
//		Comunidad Hispana de Simulacin
// ---------------------------------------------------------------------------------------------------------
Para ms informacin y descarga de las ltimas versiones o si quieres aportarme alguna idea, visita la pgina de la
comunidad hispana de simulacin:


http://www.simulacion-esp.com/v3/topic/18360-urban-patrol-script-version-monsada/



//-------------------------------------------------------------------------------------------------------------
Historial de modificaciones:
// ---------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//Version: 5.0.6
// -----------------------------------------------------------------------------
//   	Added:
//		Parameter "RESPAWN" for alowing respawn UPSMON squads when all are dead
//		"aware","combat","stealth" and "careless" added as a parameter so you can define default behaviour of squad
//		Added AI stuff for water
//		AI aware if find dead bodies
//		Added fixed positions for reinforcement squads, those squads that have a reinforcement ID can be set reinforcement position by seting KRON_UPS_reinforcement"x"_pos = position; sample
//		reinforcement: http://dev-heaven.net/projects/upsmon/wiki/Reinforcement
//		Added Artillery module:  http://dev-heaven.net/projects/upsmon/wiki/Artillery_module
//		Added spawn module: http://dev-heaven.net/projects/upsmon/wiki/MON_spawn
// 	Modified:
//		Solved bug in SPAWNED that not refreshed correctly army counters
//		If in walk mode and safe will land hely.
//		When Hely in squad column formation can not be used, last member assigned as driver
//		Detected bug with VEE formation, some times AI don't change vehaviour, changed to wedge
//		Folder estructure modified to gather upsmon scripts this will no affect already missions.
//		Improved AI response under Supress fire in combat situation
//		Avoid hurt soldiers than can not stand to get in vehicles and buildings
//		Avoid to patrol in damaged buildings
//		avoid bugged clases such as "BIS_alice_emptydoor";
//		AI try to get in combat vehicles
//		Performance optimization.
//		Realistic reaction of squads depending on distance to target
// -----------------------------------------------------------------------------
//Version: 5.0.5
// -----------------------------------------------------------------------------
//   	Added
//		Parameter "AMBUSH:",3000 you can set max time to wait for ambush
// 	Modified:
//		Ambush squads exits if called for reinforcement so you can force exit creating a especific reinforcement group for this ex: setting "reinforcement:",100
//			you can force exit ambush setting KRON_UPS_reinforcement100 = true
//			you can put 0 seconds for putting mines and go away if combined with "move" for example
//		Solved bug that sets reinforcement to false on init of scritp
//		Improved getout and landheli algoritm
//		Improved target debug console A=all units C=current alive units T=targets knonw by this side
//		Improved movement with vehicles, now they go in safe until near known enemies
//   		adjusted flanking algorithm
// -----------------------------------------------------------------------------
//Version: 5.0.4
//   	Added
//   		Implemented: It also would be great if they use smoke-grenades when ai is under fire by targets they dont see well. One example: I lay on a moutain with my squad and shoot with sniperrifles from the hill down at the ai in a village. The ai should throw smoke and try to get cover. That would be great.
//             Feature #9559: parameter "spawned" = use only with squads created in runtime, this feature will add squad to UPSMON correctly.
//		Feature #9558 parameter "nowp" = No waypoints will be created for this squad, so this squad will comunicate enemies but will not be moved, so you can do what you want with them using waypoints.
//		Feature #9503 parameter "ambush"	= Ambush squad will not move until in combat, will wait for incoming enemies stealth and ambush when near or discovered.
//		Parameter "RFLOCK", if especified when reinforcement is called, target position is locked until reached reinforcement point
//		Added surrended client control so now is no necesary create any trigger in mission to launch surrended.sqf
//		Added stuck control to avoid that helis stopping flying
//		New target sistem control based in last known positions instead of real position of targets
// 	Modified:
//		Bug #9666 fixed:AI Cheats with UPSMON - Groups always Flank Real Position instead of last known
//		Bug #9662 fixed: Reinforcement Group returning home, does not get out of Vehicles (if used)
//		Bug #9639 fixed: Reinforcement Group can get stuck if Transportvehicle back to Patrolmarker gets destroyed//		
//		Set DIAMOND formation when exiting vehicle
//		bug with NOSLOW solved.
//		solved other bugs such as no patrol without enemies.
// ---------------------------------------------------------------------------------------------------------
//Version: 5.0.3
//   	Added
//		KRON_UPS_searchVehicledist = 800
//		KRON_UPS_EAST_SURRENDER, KRON_UPS_WEST_SURRENDER,KRON_UPS_GUER_SURRENDER
//		Set percentaje of forces for surrender.
//		Main control for all squads, doing comon proceses and saving performance.
//		sample followme.sqf script for enabling AI surrended to join your squad, must
//			be executed in each client when KRON_UPS_EAST_SURRENDED or KRON_UPS_WEST_SURRENDED
//			or KRON_UPS_GUER_SURRENDED
// 	Modified:
//		Fixed Bug with resistance forces detected as enemies when not parametriced as enemy
//		Fixed bug check if dead leader before moving.
//		Fixed bug, "alive" not always returns someone is dead instanctly so controlled with canmove.
//		Fixed bug, error _vehicle object expected.
//		Controled  not doing paradroop  on water.
//-------------------------------------------------------------------------------------------------------------
//Version: 5.0.2
//   	Added
//		KRON_UPS_useStatics, enables AI to use Static weapons.
//		KRON_UPS_useMines, enables AI to put mines when enemy armored vehicles near
//		Now vehicles can be used for patrol, not only with target.
// 	Modified:
//		Fixed Bug that do not sent reinforcement if parameter "reinforcement"
//		Fixed bug with random 1 ocasiolly has been returned more than 1.
//		Fixed bug that eventually do not change dead leader		
//-------------------------------------------------------------------------------------------------------------
//Version: 5.0.1
//   	Added
//		Mulitiple reinforcement reinforcement:x, now you can put an id of reinforcement for calling only this groups later:
//		nul=[this,"town", "move","reinforcement:",1, "delete:",600] execVM "scripts\upsmon.sqf";
//		nul=[this,"town", "move","reinforcement:",2, "delete:",600] execVM "scripts\upsmon.sqf";
// 	Modified:
//		Fixed fortify squads don't get defence positions until known enemys
//		Fortify squads leave fortify status when called for reinforcement
// ---------------------------------------------------------------------------------------------------------
//Version: 5.0.0
//   	Added
//		KRON_UPS_flyInHeight: Height that heli will fly this input will be randomiced in a 10%
//		KRON_UPS_paradropdist: Max distance to target for doing paradrop, will be randomiced between 0 and 100% of this value. 
//		parameter "fortify" makes leader order to take positions on nearly buildings at distance 100 meters near leader, 
//				squads with fortify  will ignore "MOVE" rol.
// 	Modified:
//		Fixed bug that eventually stoped hely when paradrops done.
// ---------------------------------------------------------------------------------------------------------
//Version: 4.2.6
//   	Added
//
// 	Modified:
//		Fixed bug that leaves a soldier in front of vehicle afte geting out.
//		Fixed bug that allowed AI to disenbark from heli before arriving objective.
//-------------------------------------------------------------------------------------------------------------
//Version: 4.2.5
//    	Added
//		Air transport 
//		Paratroop air transported units
//		Improved comunications
// 	Modificaciones:
//		Updated for an action radio of 1000 meters or avove.
//		Added some translations to english
//-------------------------------------------------------------------------------------------------------------
//Version: 4.2.2
//    	Added
//		Se ha aadido ataque frontal
//		Formaciones de combate en funcin de la situacin
//		La IA puede entrar en los edificios a tomar posiciones de defensa y en ataque puede patrullarlos en busca de enemigos o posiciones de fuego.
// 	Modificaciones:
//		Mejorado el sistema para localizar, asignar y entrar en vehiculos,.
//		Optimizado el rendimiento. Se ha mejorado para que se pueda ejecutar cada 20s.
//		Modificada la parametrizacin, sharedist incrementado, react reducido, cycle aumentado.
//		Modificada la actitud e la IA en combate, se ha dado ms especializacin en funcin de la situacin.
//		Corregido bug que al enviar refuerzos haca que dejaran de patrullar si no tenian ningn target
//		Posiciones de flanqueo ms dinmicas.
//		Las escuadras con rol "NOMOVE" tienden a asegurar la posicin y a hacer mayor uso de los edificios del entorno.
//-------------------------------------------------------------------------------------------------------------
//Version: 4.1.3
//		
// 	Modificaciones:
//		corregidos los problemas al entrar en vehiculos, que haca que casi siempre alguno se quedara fuera
//		Optimizado el rendimiento.
//		Modificada la actitud e la IA en combate, se ha dado ms especializacin en funcin de la situacin.
//		
//-------------------------------------------------------------------------------------------------------------
//Version: 4.1.2
//		
// 	Modificaciones:
//		KRON_UPS_Maxwaiting pasa a ser una variable excluvia para patrullas, indica el tiempo mximo a esperar
//		para llegar al destino y buscar otro
//-------------------------------------------------------------------------------------------------------------
//Version: 4.1.0
//    	Added
//             Habilitado bsqueda y uso de vehculos de transporte, cuando la IA est lejos del objetivo busca vehiculos con capacidad cerca, ahora ya puedes definir tu base con vehiculos, que si la IA los necesita los coge.
//		
// 	Modificaciones:
//		Adaptadas ciertas partes de cdigo para ser usadas en modo multihilo, mejorando los resultados y el rendimiento en general.
//-------------------------------------------------------------------------------------------------------------
//Version: 4.0.0
// 	Added
// 		Control de movimiento de la IA, ahora gestionan mejor los tiempos, hacen coverturas de movimiento, avanzan con ms precaucin cuando estn cerca del enemigo.
// 		Aadidas algunas animaciones para darle pinceladas de dramatismo a los movimientos de la IA
// 
// 	Modificaciones:
// 		Modificacin control de deteccin de movimientos de otros grupos ahora no requiere la lectura de objetos, con lo que mejora el rendimiento.
// 		Adaptado sistema de scripts para poder controlar los grupos de IA y aadir mejoras que requieran la interaccin de los grupos.
//-------------------------------------------------------------------------------
//Version: 3.0.8
// 	Modificaciones:
//		Corregido el bug de los buildings, se ha vuelto a implementar el uso de edificios
//		Mejorada la velocidad de iniciacin del script.
//-------------------------------------------------------------------------------------------------------------
//Version: 3.0.7
//    	Added
//             
// 	Modificaciones:
//		Corregido bud que en dedicado fijaba el objetivo siempre en lugar de los flancos		
//-------------------------------------------------------------------------------------------------------------
//Version: 3.0.6
//    	Added
//             
// 	Modificaciones
//		Corregidos bugs varios, entre ellos uno que ralentizaba la accin de los grupos
//		Set de parmetros modificados para un comportamiento ms ptimo y realista
//		deshabilitado KRON_UPS_intowndist por comportamientos extraos con algunos objetos builiding
//		Ahora la IA selecciona los caminos con ms cobertura, a ser posible
//-------------------------------------------------------------------------------------------------------------
//Version: 3.0.5
//    	Added
//             
// 	Modificaciones
//		Corregido bug que evitaba enviar los refuerzos
//		La distancia de comunicacin de objetivos aumenta en funcin del rol, los nomove * 1.5
//	
//-------------------------------------------------------------------------------------------------------------
//Version: 3.0.4
//    	Added
//   		Aadidos parmetros para asignar enemigos y aliados a la resistencia
//             Aadido control anti snipers, si la IA se ve atacada y no sabe de donde se mueve de sitio
// 	Modificaciones
//		Se ajusta el ngulo de flanqueo en funcin de la distancia al objetivo
//	
//-------------------------------------------------------------------------------------------------------------
//
//  Modified: Monsada (SMM) 03.11.2009
//Version: 3.0.3
//    	Added
//   		Multiple targets, now IA can have multiple open targets
//		La IA ahora usa tamien los edificios para buscar enemigos, protegerse dentro o atacar desde all.
// 	Modificaciones
//		La IA pierde el objetivo si lo pierde de vista y est a ms de la distancia KRON_UPS_sharedist
//
//-------------------------------------------------------------------------------------------------------------
//Version: 3.0.2
//    	Added
//		Se ha aadido la opcin de Refuerzos, ahora se pueden definir unas unidades de refuerzos alejados de la zona que se enviarn al detectar enemigos enemigos 
//		si KRON_UPS_reinforcement es true, se puede usar un marcador a modo de alarma para alimentar esta variable cuando se desee.
//		Las unidades tendrn una predisposicin a mantener la posicin si tienen el rol NOMOVE
// 	Modificaciones
//		Se ha corregido la formula par definir los puntos de flanqueo tx = sin x * dist * (signo cos x).
//		Las unidades con rol NOMOVE tienden a mantener la posicin cuanto ms alejados estn del enemigo
//		Se ha mejorado el rendimiento.
//
//-------------------------------------------------------------------------------------------------------------
//Version: 3.0.1
//    	Added
//		Sistema de combate urbano.  La Ia ajusta el flanjeo y sus movimientos al tipo de superficie.
//	Modificaciones
//		Ahora los pelotones verifican la presencia de aliados para determinar otras rutas de flanqueo.
//		Se ha substituido el algoritmo de determinacin de posiciones de flanqueo por un bug con las funciones cos y sin 
//		que retornan aleatoriamente valores positivos o negativos con el mismo ngulo.
//
//-------------------------------------------------------------------------------------------------------------
// Version: 3.0.0
// 	Added:
// 		Improved IA flanking possitions
// 		Improved IA movements in combat
// 		Now IA can be supressed by fire
// 		IA may use smoke grenades when in fire
// 		Improved performance (this script now runs every 15s and do not need to stress to 1 second)
// 		Implemented comunications simulating radio to know enemy position
//Errores corregidos y modificaciones
//	Corregida la funcin KRON_distancePosSqr que no devolvia la distancia correcta entre dos puntos
//	Corregido bug que no alimentaba correctamente el objetivocompartido cuando este fallecia
//	Corregido control de la distancia al objetivo que hacia que la IA no flanquera
//    Algoritmo de control de accin y movimiento modificado
// =========================================================================================================