1 #using scripts\codescripts\struct;
3 #using scripts\shared\array_shared;
4 #using scripts\shared\flag_shared;
5 #using scripts\shared\system_shared;
6 #using scripts\shared\trigger_shared;
7 #using scripts\shared\util_shared;
9 #insert scripts\shared\shared.gsh;
11 #using scripts\zm\gametypes\_zm_gametype;
12 #using scripts\zm\_util;
13 #using scripts\zm\_zm_utility;
15 #namespace zm_zonemgr;
52 level.zone_flags = [];
53 level.zone_scanning_active = 0;
54 level.str_zone_mgr_mode =
"occupied_and_adjacent";
67 if ( !IsDefined(level.zones) || !IsDefined(level.zones[ zone_name ]) || !level.zones[ zone_name ].is_enabled )
79 level waittill( zone_name );
103 scr_org =
spawn(
"script_origin", v_pos );
105 keys = GetArrayKeys( level.zones );
106 for( i=0; i<keys.size; i++ )
127 zone = level.zones[ zone_name ];
129 assert( IsDefined( zone_name ) );
131 return zone.magic_boxes;
141 zone = level.zones[ zone_name ];
143 assert( IsDefined( zone_name ) );
145 return zone.zbarriers;
161 zone = level.zones[ zone_name ];
165 players_in_zone = [];
166 players = GetPlayers();
167 for (i = 0; i < zone.volumes.size; i++)
169 for (j = 0; j < players.size; j++)
171 if ( players[j] IsTouching(zone.volumes[i]) )
174 players_in_zone[players_in_zone.size] = players[j];
178 if(isDefined(return_players))
180 return players_in_zone;
196 zone = level.zones[ zone_name ];
199 for (i = 0; i < zone.volumes.size; i++)
201 players = GetPlayers();
202 for (j = 0; j < players.size; j++)
204 if ( players[j] IsTouching(zone.volumes[i]) && !(players[j].sessionstate ==
"spectator"))
216 if ( IsPlayer(
self ) &&
self.sessionstate ==
"spectator" )
227 zone = level.zones[ zone_name ];
230 foreach( e_volume
in zone.volumes )
232 if (
self IsTouching( e_volume ) )
245 if ( IsPlayer(
self ) &&
self.sessionstate ==
"spectator" )
250 foreach( str_adj_zone
in level.active_zone_names )
270 for (i = 0; i < special_goals.size; i++)
272 if (IsDefined(special_goals[i].script_noteworthy))
274 special_goals[i].is_active =
false;
275 special_goals[i] TriggerEnable(
false );
288 if ( IsDefined( level.zones[ zone_name ] ) )
296 level.zones[ zone_name ] = SpawnStruct();
297 zone = level.zones[ zone_name ];
299 zone.is_enabled =
false;
301 zone.is_occupied =
false;
303 zone.is_active =
false;
305 zone.adjacent_zones = [];
307 zone.is_spawning_allowed =
false;
309 if( isDefined( zone_tag ) )
311 zone_name_tokens = StrTok( zone_name,
"_" );
313 zone.district = zone_name_tokens[1];
314 zone.area = zone_tag;
319 volumes = GetEntArray( zone_name,
"targetname" );
324 for ( i=0; i<volumes.size; i++ )
326 if ( volumes[i].classname ==
"info_volume" )
328 zone.volumes[ zone.volumes.size ] = volumes[i];
332 assert( IsDefined( zone.volumes[0] ),
"zone_init: No volumes found for zone: "+zone_name );
335 zone.total_spawn_count = 0;
336 zone.round_spawn_count = 0;
339 zone.a_loc_types = [];
340 zone.a_loc_types[
"zombie_location" ] = [];
343 zone.magic_boxes = [];
345 if ( IsDefined( zone.volumes[0].target ) )
352 foreach( spot
in spots )
354 spot.zone_name = zone_name;
357 spot.is_enabled =
true;
361 spot.is_enabled =
false;
365 tokens = StrTok( spot.script_noteworthy,
" " );
366 foreach ( token
in tokens )
371 case "spawn_location":
372 case "riser_location":
373 case "faller_location":
374 case "custom_spawner_entry":
375 ARRAY_ADD( zone.a_loc_types[
"zombie_location" ], spot );
378 if ( !isdefined( zone.a_loc_types[ token ] ) )
380 zone.a_loc_types[ token ] = [];
383 ARRAY_ADD( zone.a_loc_types[ token ], spot );
387 if(IsDefined(spot.script_string))
389 barricade_id = spot.script_string;
391 for (k = 0; k < barricades.size; k++)
393 if(IsDefined(barricades[k].script_string) && barricades[k].script_string == barricade_id)
395 nodes = GetNodeArray(barricades[k].target,
"targetname");
396 for (j = 0; j < nodes.size; j++)
398 if( IsDefined(nodes[j].type) && nodes[j].type ==
"Begin")
399 spot.target = nodes[j].targetname;
406 for( i = 0; i < barricades.size; i++ )
408 targets = GetEntArray( barricades[i].target,
"targetname" );
409 for( j = 0; j < targets.size; j++ )
411 if( targets[j] IsZBarrier() && IsDefined( targets[j].script_string ) && targets[j].script_string == zone_name )
418 for( i = 0; i < box_locs.size; i++ )
420 chest_ent = GetEnt(box_locs[i].script_noteworthy +
"_zbarrier",
"script_noteworthy");
433 zkeys = GetArrayKeys( level.zones );
434 for ( i = 0; i < level.zones.size; i++ )
436 zone = level.zones[ zkeys[i] ];
439 zone.a_loc_types = [];
440 zone.a_loc_types[
"zombie_location" ] = [];
442 if ( IsDefined( zone.volumes[0].target ) )
445 foreach ( n_index, spot
in spots )
447 spot.zone_name = zkeys[n_index];
450 spot.is_enabled =
true;
454 spot.is_enabled =
false;
458 tokens = StrTok( spot.script_noteworthy,
" " );
459 foreach ( token
in tokens )
464 case "spawn_location":
465 case "spawner_location":
466 case "riser_location":
467 case "faller_location":
468 case "custom_spawner_entry":
469 ARRAY_ADD( zone.a_loc_types[
"zombie_location" ], spot );
472 if ( !isdefined( zone.a_a_locs[ token ] ) )
474 zone.a_loc_types[ token ] = [];
477 ARRAY_ADD( zone.a_loc_types[ token ], spot );
490 assert( IsDefined(level.zones) && IsDefined(level.zones[zone_name]),
"enable_zone: zone has not been initialized" );
492 if ( level.zones[ zone_name ].is_enabled )
497 level.zones[ zone_name ].is_enabled =
true;
498 level.zones[ zone_name ].is_spawning_allowed =
true;
499 level notify( zone_name );
505 for( i = 0; i < spawn_points.size; i++ )
507 if ( spawn_points[i].script_noteworthy == zone_name )
509 spawn_points[i].locked =
false;
517 for(i=0;i<entry_points.size;i++)
519 entry_points[i].is_active =
true;
520 entry_points[i] TriggerEnable(
true );
533 main_zone = level.zones[ main_zone_name ];
536 if ( !IsDefined( main_zone.adjacent_zones[ adj_zone_name ] ) )
538 main_zone.adjacent_zones[ adj_zone_name ] = SpawnStruct();
539 adj_zone = main_zone.adjacent_zones[ adj_zone_name ];
540 adj_zone.is_connected =
false;
541 adj_zone.flags_do_or_check =
false;
543 if ( IsArray( flag_name ) )
545 adj_zone.flags = flag_name;
549 adj_zone.flags[0] = flag_name;
556 assert( !IsArray( flag_name ),
"make_zone_adjacent: can't mix single and arrays of flags" );
557 adj_zone = main_zone.adjacent_zones[ adj_zone_name ];
558 size = adj_zone.flags.size;
559 adj_zone.flags_do_or_check =
true;
560 adj_zone.flags[ size ] = flag_name;
572 if (!IsArray(add_flags) )
579 keys = GetArrayKeys( level.zone_flags );
580 for ( i=0; i<keys.size; i++ )
582 if ( keys[i] == wait_flag )
584 level.zone_flags[ keys[i] ] = ArrayCombine( level.zone_flags[ keys[i] ], add_flags,
true,
false );
588 level.zone_flags[ wait_flag ] = add_flags;
597 if ( !IsDefined( one_way ) )
603 if ( !IsDefined( level.flag[ flag_name ] ) )
630 zkeys = GetArrayKeys( level.zones );
631 for( z=0; z<level.zones.size; z++ )
633 zone = level.zones[ zkeys[z] ];
634 azkeys = GetArrayKeys( zone.adjacent_zones );
635 for ( az = 0; az<zone.adjacent_zones.size; az++ )
637 azone = zone.adjacent_zones[ azkeys[az] ];
638 for ( f = 0; f< azone.flags.size; f++ )
645 for( i=0; i<flags.size; i++ )
654 DEFAULT(level.zone_flags_updating,0);
655 while ( level.zone_flags_updating > 0 )
663 DEFAULT(level.zone_flag_wait_throttle,0);
664 level.zone_flag_wait_throttle++;
665 if ( level.zone_flag_wait_throttle > 3 )
667 level.zone_flag_wait_throttle=0;
677 if ( !IsDefined( level.flag[ flag_name ] ) )
683 DEFAULT(level.zone_flags_updating,0);
684 level.zone_flags_updating++;
687 for( z=0; z<level.zones.size; z++ )
689 zkeys = GetArrayKeys( level.zones );
690 zone = level.zones[ zkeys[z] ];
691 for ( az = 0; az<zone.adjacent_zones.size; az++ )
693 azkeys = GetArrayKeys( zone.adjacent_zones );
694 azone = zone.adjacent_zones[ azkeys[az] ];
695 if ( !azone.is_connected )
697 if ( azone.flags_do_or_check )
701 for ( f = 0; f< azone.flags.size; f++ )
714 for ( f = 0; f< azone.flags.size; f++ )
726 azone.is_connected =
true;
727 if ( !level.zones[ azkeys[az] ].is_enabled )
742 keys = GetArrayKeys( level.zone_flags );
743 for ( i=0; i<keys.size; i++ )
745 if ( keys[i] == flag_name )
747 check_flag = level.zone_flags[ keys[i] ];
748 for ( k=0; k<check_flag.size; k++ )
756 level.zone_flags_updating--;
766 self.is_connected =
false;
774 if ( !IsDefined( one_way ) )
788 if ( !IsDefined( level.zones[ zone_name_a ].adjacent_zones[ zone_name_b ] ) )
790 level.zones[ zone_name_a ].adjacent_zones[ zone_name_b ] = SpawnStruct();
791 level.zones[ zone_name_a ].adjacent_zones[ zone_name_b ].is_connected =
true;
797 if ( !IsDefined( level.zones[ zone_name_b ].adjacent_zones[ zone_name_a ] ) )
799 level.zones[ zone_name_b ].adjacent_zones[ zone_name_a ] = SpawnStruct();
800 level.zones[ zone_name_b ].adjacent_zones[ zone_name_a ].is_connected =
true;
812 assert( IsDefined( initial_zone ),
"You must specify an initial zone to manage" );
816 level.player_zone_found =
true;
824 for( i = 0; i < spawn_points.size; i++ )
826 assert( IsDefined( spawn_points[i].script_noteworthy ),
"player_respawn_point: You must specify a script noteworthy with the zone name" );
827 spawn_points[i].locked =
true;
831 if ( IsDefined( level.zone_manager_init_func ) )
833 [[ level.zone_manager_init_func ]]();
838 if ( IsArray( initial_zone ) )
841 for ( i = 0; i < initial_zone.size; i++ )
856 zkeys = GetArrayKeys( level.zones );
857 level.zone_keys = zkeys;
859 for( z=0; z<zkeys.size; z++ )
861 level.newzones[ zkeys[z] ] = spawnstruct();
871 while(GetDvarInt(
"noclip") == 0 ||GetDvarInt(
"notarget") != 0 )
876 for( z=0; z<zkeys.size; z++ )
878 level.newzones[ zkeys[z] ].is_active =
false;
879 level.newzones[ zkeys[z] ].is_occupied =
false;
884 a_zone_is_active =
false;
885 a_zone_is_spawning_allowed =
false;
886 level.zone_scanning_active = 1;
887 for( z=0; z<zkeys.size; z++ )
889 zone = level.zones[ zkeys[z] ];
890 newzone = level.newzones[ zkeys[z] ];
891 if ( !zone.is_enabled )
896 if ( isdefined( level.zone_occupied_func ) )
898 newzone.is_occupied = [[ level.zone_occupied_func ]]( zkeys[z] );
905 if ( newzone.is_occupied )
907 newzone.is_active =
true;
908 a_zone_is_active =
true;
909 if ( zone.is_spawning_allowed )
911 a_zone_is_spawning_allowed =
true;
914 if( !isdefined( oldzone ) || (oldzone != newzone) )
916 level notify(
"newzoneActive", zkeys[z] );
920 azkeys = GetArrayKeys( zone.adjacent_zones );
921 for ( az=0; az<zone.adjacent_zones.size; az++ )
923 if ( zone.adjacent_zones[ azkeys[az] ].is_connected &&
924 level.zones[ azkeys[az] ].is_enabled )
927 level.newzones[ azkeys[ az ] ].is_active =
true;
928 if ( level.zones[ azkeys[ az ] ].is_spawning_allowed )
930 a_zone_is_spawning_allowed =
true;
936 if ( zone_choke >= 3 )
943 level.zone_scanning_active = 0;
945 for( z=0; z<zkeys.size; z++ )
947 level.zones[ zkeys[z] ].is_active = level.newzones[ zkeys[z] ].is_active;
948 level.zones[ zkeys[z] ].is_occupied = level.newzones[ zkeys[z] ].is_occupied;
952 if ( !a_zone_is_active || !a_zone_is_spawning_allowed )
954 if ( IsArray( initial_zone ) )
956 level.zones[ initial_zone[0] ].is_active =
true;
957 level.zones[ initial_zone[0] ].is_occupied =
true;
958 level.zones[ initial_zone[0] ].is_spawning_allowed =
true;
962 level.zones[ initial_zone ].is_active =
true;
963 level.zones[ initial_zone ].is_occupied =
true;
964 level.zones[ initial_zone ].is_spawning_allowed =
true;
966 level.player_zone_found =
false;
970 level.player_zone_found =
true;
974 [[ level.create_spawner_list_func ]]( zkeys );
991 if(
IS_TRUE( level.toggle_show_spawn_locations ) )
993 host_player = util::GetHostPlayer();
994 foreach( location
in level.zm_loc_types[
"zombie_location" ] )
996 distance = Distance( location.origin, host_player.origin );
998 if( distance > ( GetDvarInt(
"scr_spawner_location_distance" ) * 12 ) )
1002 debugstar( location.origin, GetDvarInt(
"scr_spawner_location_time" ), color );
1016 assert( IsDefined( initial_zone ),
"You must specify an initial zone to manage" );
1024 for( i = 0; i < spawn_points.size; i++ )
1026 assert( IsDefined( spawn_points[i].script_noteworthy ),
"player_respawn_point: You must specify a script noteworthy with the zone name" );
1027 spawn_points[i].locked =
true;
1031 if ( IsDefined( level.zone_manager_init_func ) )
1033 [[ level.zone_manager_init_func ]]();
1038 if ( IsArray( initial_zone ) )
1040 for ( i = 0; i < initial_zone.size; i++ )
1054 zkeys = GetArrayKeys( level.zones );
1055 level.zone_keys = zkeys;
1069 while(GetDvarInt(
"noclip") == 0 ||GetDvarInt(
"notarget") != 0 )
1072 for( z=0; z<zkeys.size; z++ )
1074 level.zones[ zkeys[z] ].is_active =
false;
1075 level.zones[ zkeys[z] ].is_occupied =
false;
1080 a_zone_is_active =
false;
1081 a_zone_is_spawning_allowed =
false;
1082 for( z=0; z<zkeys.size; z++ )
1084 zone = level.zones[ zkeys[z] ];
1085 if ( !zone.is_enabled )
1090 if ( isdefined( level.zone_occupied_func ) )
1092 zone.is_occupied = [[ level.zone_occupied_func ]]( zkeys[z] );
1099 if ( zone.is_occupied )
1101 zone.is_active =
true;
1102 a_zone_is_active =
true;
1103 if ( zone.is_spawning_allowed )
1105 a_zone_is_spawning_allowed =
true;
1108 azkeys = GetArrayKeys( zone.adjacent_zones );
1109 for ( az=0; az<zone.adjacent_zones.size; az++ )
1111 if ( zone.adjacent_zones[ azkeys[az] ].is_connected &&
1112 level.zones[ azkeys[az] ].is_enabled )
1114 level.zones[ azkeys[ az ] ].is_active =
true;
1115 if ( level.zones[ azkeys[ az ] ].is_spawning_allowed )
1117 a_zone_is_spawning_allowed =
true;
1125 if ( !a_zone_is_active || !a_zone_is_spawning_allowed )
1127 if ( IsArray( initial_zone ) )
1129 level.zones[ initial_zone[0] ].is_active =
true;
1130 level.zones[ initial_zone[0] ].is_occupied =
true;
1131 level.zones[ initial_zone[0] ].is_spawning_allowed =
true;
1135 level.zones[ initial_zone ].is_active =
true;
1136 level.zones[ initial_zone ].is_occupied =
true;
1137 level.zones[ initial_zone ].is_spawning_allowed =
true;
1142 [[ level.create_spawner_list_func ]]( zkeys );
1156 foreach( str_index,a_locs
in level.zm_loc_types )
1158 level.zm_loc_types[ str_index ] = [];
1162 for( z=0; z<zkeys.size; z++ )
1164 zone = level.zones[ zkeys[z] ];
1166 if ( zone.is_enabled && zone.is_active && zone.is_spawning_allowed )
1168 foreach( a_locs
in zone.a_loc_types )
1170 foreach( loc
in a_locs )
1172 if ( isdefined( loc.is_enabled ) && loc.is_enabled ==
false )
1178 tokens = StrTok( loc.script_noteworthy,
" " );
1179 foreach ( token
in tokens )
1184 case "spawn_location":
1185 case "riser_location":
1186 case "faller_location":
1187 case "custom_spawner_entry":
1188 array::add( level.zm_loc_types[
"zombie_location" ], loc,
false );
1191 if ( !isdefined( level.zm_loc_types[ token ] ) )
1193 level.zm_loc_types[ token ] = [];
1196 array::add( level.zm_loc_types[ token ], loc,
false );
1209 if(!isdefined(level.zone_keys))
1214 while ( level.zone_scanning_active )
1217 for(i = 0; i < level.zone_keys.size; i ++)
1219 if(level.zones[level.zone_keys[i]].is_active)
1221 ret_list[ret_list.size] = level.zone_keys[i];
1232 a_player_zones = getentarray(
"player_volume",
"script_noteworthy" );
1234 a_active_zones = [];
1236 for( i=0; i<a_player_zones.size; i++ )
1238 e_zone = a_player_zones[i];
1239 zone = level.zones[ e_zone.targetname ];
1240 if( isdefined(zone) &&
IS_TRUE(zone.is_enabled) )
1242 a_active_zones[ a_active_zones.size ] = e_zone;
1245 return( a_active_zones );
1252 level.last_debug_zone_index = 0;
1265 zkeys = GetArrayKeys( level.zones );
1266 for ( i = 0; i < zkeys.size; i++ )
1268 zoneName = zkeys[i];
1269 zone = level.zones[zoneName];
1271 zone.debug_hud = [];
1273 for ( j = 0; j < 6; j++ )
1275 zone.debug_hud[j] = NewDebugHudElem();
1278 zone.debug_hud[j].alignX =
"right";
1282 zone.debug_hud[j].alignX =
"left";
1284 zone.debug_hud[j].x = xloc[j];
1285 zone.debug_hud[j].y = current_y;
1291 for ( x=0; x < xloc.size; x++ )
1301 zone.debug_hud[0] SetText(zoneName);
1308 level.last_debug_zone_index = undefined;
1310 zkeys = GetArrayKeys( level.zones );
1311 for ( i = 0; i < zkeys.size; i++ )
1313 zoneName = zkeys[i];
1314 zone = level.zones[zoneName];
1316 for ( j = 0; j < 6; j++ )
1318 zone.debug_hud[j] Destroy();
1319 zone.debug_hud[j] = undefined;
1326 if( isDefined( zone ) )
1328 foreach( volume
in zone.volumes )
1330 if( !isDefined( color ) || !isDefined( alpha ) )
1332 ShowInfoVolume( volume GetEntityNumber(), (0.2, 0.5, 0), 0.05 );
1336 ShowInfoVolume( volume GetEntityNumber(), color, alpha );
1344 if ( GetDvarString(
"zombiemode_debug_zones") ==
"" )
1346 SetDvar(
"zombiemode_debug_zones",
"0");
1349 InfoVolumeDebugInit();
1350 zkeys = GetArrayKeys( level.zones );
1351 for ( i = 0; i < zkeys.size; i++ )
1353 zoneName = zkeys[i];
1354 zone = level.zones[zoneName];
1355 _debug_show_zone( zone, ( RandomFloatRange( 0, 1.0 ), RandomFloatRange( 0, 1.0 ), RandomFloatRange( 0, 1.0 ) ), 0.2 );
1361 wasEnabled = enabled;
1362 enabled = GetDvarInt(
"zombiemode_debug_zones");
1363 if ( enabled && !wasEnabled )
1367 else if ( !enabled && wasEnabled )
1372 occupied_zone = undefined;
1376 zkeys = GetArrayKeys( level.zones );
1377 for ( i = 0; i < zkeys.size; i++ )
1379 zoneName = zkeys[i];
1380 zone = level.zones[zoneName];
1383 zone.debug_hud[0] SetText(text);
1385 if ( zone.is_enabled )
1388 zone.debug_hud[1] SetText(
"Enabled");
1392 zone.debug_hud[1] SetText(
"");
1394 if ( zone.is_active )
1397 zone.debug_hud[2] SetText(
"Active");
1401 zone.debug_hud[2] SetText(
"");
1403 if ( zone.is_occupied )
1405 text +=
" Occupied";
1406 zone.debug_hud[3] SetText(
"Occupied");
1407 occupied_zone = zone;
1411 zone.debug_hud[3] SetText(
"");
1413 if ( zone.is_spawning_allowed )
1416 zone.debug_hud[4] SetText(
"SpawnOK");
1420 zone.debug_hud[4] SetText(
"");
1424 text += zone.a_loc_types[
"zombie_location" ].size +
" spawn";
1425 zone.debug_hud[5] SetText(zone.a_loc_types[
"zombie_location" ].size +
" - " + zone.total_spawn_count +
" - " + zone.round_spawn_count );