11class BunkerBroadcastHandlerPersistenceData
18 private const string STORAGE_PATH =
"$mission:BunkerBroadcastPersistenceStorage.bin";
85class BunkerBroadcastLockCodeMode
114 protected ref BunkerBroadcastConfigInstance
m_Config;
126 #ifdef DIAG_DEVELOPER
128 static ref
TIntArray m_BunkersHistoryStorage;
129 static bool m_LoggingEnabled;
165 #ifdef DIAG_DEVELOPER
167 m_BunkersHistoryStorage =
new TIntArray();
209 #ifdef ENABLE_LOGGING
210 Log(
string.Format(
"Directly registering (store load) - object=%1, id=%2, pos=%3, code=%4",
component, componentId,
component.GetPosition(), lockCode));
220 #ifdef ENABLE_LOGGING
221 Log(
string.Format(
"Already in register queue - object=%1, id=%2, pos=%3",
component, componentId,
component.GetPosition()));
241 #ifdef ENABLE_LOGGING
242 Log(
string.Format(
"Already in un-register queue - object=%1, id=%2, pos=%3",
component, componentId,
component.GetPosition()));
318 if (registeredCountRound > 2)
329 #ifdef ENABLE_LOGGING
338 #ifdef ENABLE_LOGGING
347 #ifdef DIAG_DEVELOPER
350 SyncBunkersInfo(bunkerList, bunkersHistory);
369 int numOfActivatedBunkers =
Activate();
371 if (numOfActivatedBunkers > 0)
373 #ifdef DIAG_DEVELOPER
375 #ifdef ENABLE_LOGGING
376 Log(
"No active bunker selected");
390 bunker.OnActivate(lockCode);
404 int componentId = bunker.GetId();
405 #ifdef ENABLE_LOGGING
406 Log(
string.Format(
"Deactivating bunker:%1", componentId));
408 bunker.OnDeactivate();
409 toRemove.Insert(bunker);
426 #ifdef DIAG_DEVELOPER
427 #ifdef BUNKER_BROADCAST_CHEAT_CODE
432 bool needGenerate =
true;
434 while (needGenerate )
437 for (
int i = 0; i <
m_Config.bunkerSettings.lockCodeLength; ++i)
440 lockCodeArray.Insert(charCode.AsciiToString());
443 lockCode =
string.
Join(
"", lockCodeArray);
450 needGenerate =
false;
481 bool returnValue = target == count;
504 if (!componentToUnregister)
506 #ifdef ENABLE_LOGGING
507 Log(
string.Format(
"Invalid bunker to unregister (%1).", componentToUnregister));
514 #ifdef ENABLE_LOGGING
515 Log(
string.Format(
"Bunker (id=%1) is not registered, cannot unregister.", uid));
526 if (!componentToRegister)
528 #ifdef ENABLE_LOGGING
529 Log(
string.Format(
"Invalid bunker to register (%1)", componentToRegister));
536 #ifdef ENABLE_LOGGING
537 Log(
string.Format(
"Bunker (id=%1) is already registered", rid));
549 #ifdef DIAG_DEVELOPER
554 case ERPCs.DIAG_MISC_RADIOGAMEPLAY_BUNKERS_LIST:
555 if (!m_RegisteredBunkersStorage)
558 if (!m_BunkersHistoryStorage)
559 m_BunkersHistoryStorage =
new TIntArray();
561 m_RegisteredBunkersStorage.Clear();
562 m_BunkersHistoryStorage.Clear();
563 ctx.
Read(m_RegisteredBunkersStorage);
564 ctx.
Read(m_BunkersHistoryStorage);
573 if (bunkers && bunkers.Count() > 0 )
575 ScriptRPC rpc =
new ScriptRPC();
577 rpc.
Write(bunkersHistory);
578 rpc.
Send(null,
ERPCs.DIAG_MISC_RADIOGAMEPLAY_BUNKERS_LIST,
true, null);
583 #ifdef ENABLE_LOGGING
584 private static void Log(
string message,
bool indented =
false)
586 #ifdef DIAG_DEVELOPER
587 if (m_LoggingEnabled || LogManager.IsRadioGameplayLogEnabled())
589 if (LogManager.IsRadioGameplayLogEnabled())
592 string indentation =
"";
594 indentation =
" \\__";
596 Debug.RadioGameplayLog(
string.Format(
"%1 %2", indentation, message),
m_Instance.ClassName(),
"n/a",
"n/a",
"n/a");
613 if (
m_Config.bunkerSettings.lockCodeMode == BunkerBroadcastLockCodeMode.ALPHANUMERIC)
633 bunkers.ShuffleArray();
634 #ifdef ENABLE_LOGGING
635 Log(
"Random bunker selection:");
642 available.Insert(bunker);
643 #ifdef ENABLE_LOGGING
645 Log(
string.Format(
"Bunker was already used (%1)", bunker.GetId()),
true);
649 int n = available.Count();
656 while (selected.Count() < amount)
660 bool alreadyUsed =
false;
661 foreach (
int u : used)
663 if (u == randomIndex)
672 selected.Insert(available[randomIndex]);
673 #ifdef ENABLE_LOGGING
674 Log(
string.Format(
"Selecting bunker (%1)", available[randomIndex].
GetId()),
true);
676 used.Insert(randomIndex);
array< ref BunkerBroadcastComponentBase > BunkerComponentsArray
BunkerBroadcastPersistenceStorage DIGITSONLY
class BunkerBroadcastSchedulerPersistenceData m_LastActiveBunkers
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
class LogTemplates Log(string message, LogTemplateID template_id=0)
Creates debug log (optional) from LogTemplate which are registred.
ref BunkerBroadcastConfigInstance m_Config
BunkerComponentsArray SelectRandomBunkers(BunkerComponentsArray bunkers, int amount)
TIntArray GetActiveBunkersHistory()
ref map< int, ref BunkerBroadcastComponentBase > m_UnregisterQueue
void Update(float timeslice)
static ref BunkerBroadcastHandler m_Instance
ref SimpleCircularBuffer< int > m_ActiveBunkersHistory
void ~BunkerBroadcastHandler()
bool ProcessBatch()
returns 'true' when all the batches are finished
void BunkerBroadcastHandler()
BunkerComponentsArray GetRegisteredBunkers()
ref map< int, ref BunkerBroadcastComponentBase > m_RegisterQueue
ref map< int, ref BunkerBroadcastComponentBase > m_RegisteredBunkers
how often is update called [seconds]
const float UPDATE_TIME
max batch size
static BunkerBroadcastHandler GetInstance()
int m_LastActiveBunkersCount
bool m_ProcessingFinished
string GenerateLockCode()
ref ScriptInvoker m_OnActiveBunkersSelected
BunkerBroadcastScheduler m_BroadcastScheduler
void Unregister(BunkerBroadcastComponentBase component)
ref BunkerComponentsArray m_ActiveBunkers
int m_ActiveBunkersFromStorageCount
void Register(BunkerBroadcastComponentBase component)
ScriptInvoker GetOnActiveBunkersSelected()
BunkerBroadcastPersistenceStorage m_PersitenceStorage
const int UPDATE_BATCH_SIZE
how many of previously generated codes are stored (prevents the reuse)
void HandleChangedComponents()
const int LOCK_CODE_HISTORY_LENGTH
BunkerComponentsArray GetActiveBunkers()
ref SimpleCircularBuffer< string > m_LockCodeHistory
void BunkerBroadcastPersistenceStorage()
static BunkerBroadcastPersistenceStorage GetInstance()
ref BunkerBroadcastSchedulerPersistenceData m_SchedulerData
const string STORAGE_PATH
static ref BunkerBroadcastPersistenceStorage m_Instance
ref BunkerBroadcastHandlerPersistenceData m_HandlerData
static BunkerBroadcastScheduler GetInstance(notnull BunkerBroadcastHandler handler)
static BunkerBroadcastConfigInstance GetData()
static bool IsInitialized()
proto native bool Open(string path, FileMode mode=FileMode.READ)
proto native void Close()
Serializer API implementation for File IO. See Serializer for more info. usage:
void OnRPC(ParamsReadContext ctx)
The class that will be instanced (moddable)
ScriptInvoker Class provide list of callbacks usage:
proto native void Send(Object target, int rpc_type, bool guaranteed, PlayerIdentity recipient=NULL)
Initiate remote procedure call. When called on client, RPC is evaluated on server; When called on ser...
proto bool Write(void value_out)
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
const int INDEX_NOT_FOUND
Serializer ParamsReadContext
map< int, string > TIntStringMap
class array< Class T > TStringArray
static proto float Max(float x, float y)
Returns bigger of two given values.
static proto float Round(float f)
Returns mathematical round of value.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
static string Join(string separator, notnull TStringArray tokens)