// * AdmiralMOD by Matthias Lorenz, http://www.cod2mod.com *



StartCamperMonitor() {

	level endon("am_end_map");
    level endon("round_ended");
	
	self endon("killed_player");
	self endon("disconnect");
     


	// * Bei S&D und Spawn im Rundenende, dann kein Camping *
	if(isDefined(level.roundended) && level.roundended) return;

    
    // * Wenn spectator, dann nicht *
    if(!isDefined(self.pers["team"]) || self.pers["team"] == "spectator") return;
       
      
    // * Wenn schon markiert... dann nicht nochmal *
    if(isDefined(self.pers["camper"])) return;
    
	
	if(game["am_error_logfile"] == 1) logPrint("StartCamperMonitor\n");



    self.pers["camper"] = true;
    
    
    
 
    // * Wenn Objekt schon auf Kompass, dann löschen *
    if(isDefined(self.objnum)) {
    
        objective_delete(self.objnum);
        self.objnum = undefined;
    }

   
    // * eine freie Objektnummer holen *
    self.objnum = GetFreeObjective();
    

	kompass_bild = "";

	if(self.pers["team"] == "allies") { 

		kompass_bild    = "objective_" + game["allies"];  		
	}
	else {          
	
		kompass_bild    = "objective_" + game["axis"];
	}
    
    level.objective_activ[self.objnum]  = true;   
    
    
    time 	= 0;
    blink 	= 0;
    
    while(isPlayer(self) && isAlive(self) && isDefined(self.pers["camper"]) && isDefined(self.pers["team"]) && self.pers["team"] != "spectator") {
        
        blink += 0.2;
              

		// * Blinken * 
		if(blink == 0.2) {
			
			objective_add(self.objnum, "current", (0,0,0), kompass_bild);
			objective_onEntity(self.objnum, self);
			objective_team(self.objnum, "none");
		}

		if(blink == 1) {			
		
			objective_delete(self.objnum);                        
		}

		if(blink == 1.8) blink = 0;                        



		time = time + 0.2; 
		if(time >= game["am_indicate_end_after_sec"]) {

			self DeleteCamping();
			self thread maps\mp\gametypes\_admiral_mod_player::CheckCamping();	
			break;
		}
		
		wait 0.2;

    }        
}


DeleteCampingAllPlayers() {
		
	if(game["am_error_logfile"] == 1) logPrint("DeleteCampingAllPlayers\n");


	players = getentarray("player", "classname");
	
	for(i = 0; i < players.size; i++) {             

		player = players[i];
	
		if(isPlayer(player) && isDefined(player.pers["camper"]) && isDefined(player.objnum)) {
	
	 		player DeleteCamping();
	    }
	}
}

DeleteCamping() {

 	self endon("killed_player");
	self endon("disconnect");


	if(game["am_error_logfile"] == 1) logPrint("DeleteCamping\n");


	if(isDefined(self.pers["camper"]) && isDefined(self.objnum)) {

 		objective_delete(self.objnum);
 		
 		level.objective_activ[self.objnum]  = undefined;
 		
    	self.objnum 						= undefined;    
     	self.pers["camper"] 				= undefined;
		
		if( isPlayer(self) != isAlive(self) ){
		
			self iprintlnbold( &"CUSTOM_CAMP4");
			self iprintlnbold( &"CUSTOM_CAMP5");
			
			iprintln( &"CUSTOM_CAMP6" );
			iprintln( self.name , &"CUSTOM_CAMP7");
			}

		if( isPlayer(self) && isAlive(self) ){
		
			self iprintlnbold( &"CUSTOM_CAMP8");
			self iprintlnbold( &"CUSTOM_CAMP9");
			
			iprintln( &"CUSTOM_CAMP6" );
			iprintln( self.name , &"CUSTOM_CAMP10");
			}
    }
    
}

GetFreeObjective() {

	if(game["am_error_logfile"] == 1) logPrint("GetFreeObjective\n");


	if(!isDefined(level.objectives)) level.objectives = 11;
	
	level.objectives++;
	
	if(level.objectives > 15) level.objectives = 12;
	
	return level.objectives;
}


NextFreeObjectiveInactiv() {

	if(game["am_error_logfile"] == 1) logPrint("NextFreeObjectiveInactiv\n");


	if(!isDefined(level.objectives)) nr = 11;
	else							 nr = level.objectives;
	
	nr++;
	
	if(nr > 15) nr = 12;
	
	
	if(!isDefined(level.objective_activ) || !isDefined(level.objective_activ[nr])) return true; 
	
	return false;
}



AddSpyPoint(origin,kompassteam,time) {

	if(game["am_error_logfile"] == 1) logPrint("AddSpyPoint\n");


	free_obj_nr = GetFreeObjectiveSpyPoint();

    objective_add(free_obj_nr, "current", origin, "gfx/custom/compass_spy_point.tga");
    objective_team(free_obj_nr, kompassteam);

	wait time;
		
    objective_delete(free_obj_nr);
}



GetFreeObjectiveSpyPoint() {

	if(game["am_error_logfile"] == 1) logPrint("GetFreeObjectiveSpyPoint\n");


	if(isDefined(level.do_get_free_obj_spy_point)) wait 0.5;
	level.do_get_free_obj_spy_point = true;


	if(!isDefined(level.objectives_spy)) level.objectives_spy = 8;
	
	level.objectives_spy++;
	
	if(level.objectives_spy > 11) level.objectives_spy = 9;


	level.do_get_free_obj_spy_point = undefined;

	
	return level.objectives_spy;

}



ShowMedic(kompassteam) {

	level endon("am_end_map");
    level endon("round_ended");

	if(game["am_error_logfile"] == 1) logPrint("ShowMedic\n");


	// * Bei Gametype Deathmatch Medic sinnlos *
	if(game["am_gametype"] == "dm") return;
	


	if(game["am_use_player_class_system"] == 0) return;
	if(!isDefined(kompassteam)) return;



	if(kompassteam == "allies") free_obj_nr = 5;
	else 						free_obj_nr = 6;
	
	obj = "am_compass_medic";


 
 	while(1) {
       
       	       
        medic_count = 0;
       	medics = undefined;
       
		players = getentarray("player", "classname");
		
		for(i=0;i<players.size;i++) {

			if(isDefined(players[i].sessionstate) && players[i].sessionstate == "playing" && isDefined(players[i].pers["player_class"]) && players[i].pers["player_class"] == 4 && players[i].pers["team"] == kompassteam) {			

				medics[medic_count] = players[i].clientid;
				medic_count++;
			}
		}	
									



		if(isDefined(medics)) {
		
		
			for(m=0;m<medics.size;m++) {
			
						
				players = getentarray("player", "classname");
				for(i = 0; i < players.size; i++) {             
					
					if(players[i].sessionstate == "playing" && players[i].clientid == medics[m]) {
						
						objective_add(free_obj_nr, "current", players[i].origin, obj);
						objective_team(free_obj_nr, players[i].pers["team"]);
						objective_onEntity(free_obj_nr, players[i]);

						wait 2;

						objective_delete(free_obj_nr);	

						break;				
					}
				}			
			}
		}
		
		
		wait 2;		
	}	
}







ShowCrate(kompassteam,origin) {


	level endon("am_end_map");
    level endon("round_ended");

	if(game["am_error_logfile"] == 1) logPrint("ShowMedic\n");


	if(game["am_use_player_class_system"] == 0) return;
	if(!isDefined(kompassteam)) return;



	if(kompassteam == "allies") free_obj_nr = 7;
	else 						free_obj_nr = 8;
	
	
	obj = "am_crate";

	objective_delete(free_obj_nr);
	
 	objective_add(free_obj_nr, "current", origin, obj);
	objective_team(free_obj_nr, kompassteam);
	
}


