Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function bool ParseSquadElement( const out String ElemDef, out AISquadElement SquadElement )
- {
- local int i, ElemStrLen, UnicodePoint, ElemCount, ModifierCharIndex;
- local string ElemType, MaybeModifierChar;
- local array<string> CustomElemType;
- local bool IsSpecial, IsRagedOnSpawn;
- local class<KFPawn_Monster> CustomElem${1}< ${3} >
- local ECDZedNameResolv ZedNameResolv;
- IsSpecial = false;
- IsRagedOnSpawn = false;
- ElemStrLen = Len( ElemDef );
- if ( 0 == ElemStrLen )
- {
- return PrintElemParseError("Spawn elements must not be empty.");
- }
- // Locate the first index into ElemDef where the count
- // of zeds in the element ends and the type of zed should begin
- for ( i = 0; i < ElemStrLen; i++ )
- {
- // Get unicode codepoint (as int) for char at index i
- UnicodePoint = Asc( Mid( ElemDef, i, 1 ) );
- // Check for low ascii numerals [0-9]
- if ( !( 48 <= UnicodePoint && UnicodePoint <= 57 ) )
- {
- break; // not a numeral
- }
- }
- // The index must not be at the very beginning or end of the string.
- // If that's true, then we can assume it was malformed.
- if ( i <= 0 || i >= ElemStrLen )
- {
- return PrintElemParseError("Spawn element \""$ ElemDef $"\" could not be parsed.");
- }
- // Check whether the element string ends with a *. The
- // asterisk suffix denotes special/albino zeds. It is only
- // valid on crawlers and alphas (when this comment was written,
- // at least). We will have to check that constraint later so
- // that we correctly reject requests for nonexistent specials,
- // e.g. albino scrake.
- for ( ModifierCharIndex = ElemStrLen - 1; 0 <= ModifierCharIndex; ModifierCharIndex-- )
- {
- MaybeModifierChar = Mid( ElemDef, ModifierCharIndex, 1 );
- if ( "*" == MaybeModifierChar )
- {
- IsSpecial = true;
- // Check that the zed name is not empty
- if ( ModifierCharIndex <= i )
- {
- return PrintElemParseError("Spawn element \""$ ElemDef $"\" could not be parsed.");
- }
- continue;
- }
- if ( "!" == MaybeModifierChar )
- {
- IsRagedOnSpawn = true;
- // Check that the zed name is not empty
- if ( ModifierCharIndex <= i )
- {
- return PrintElemParseError("Spawn element \""$ ElemDef $"\" could not be parsed.");
- }
- continue;
- }
- // This char did not match any known modifiers chars. We've started cutting into the zed name.
- break;
- }
- // Cut string into two parts.
- //
- // Left is the count as a stringified int. We know it is a
- // parseable int because of the preceding unicode check loop.
- //
- // Right is possibly the name of a zed as a string, but it is
- // totally unverified at this stage. We exclude the * suffix
- // (if it was detected above).
- ElemCount = int( Mid( ElemDef, 0, i ) );
- ElemType = Mid( ElemDef, i, ElemStrLen - i - ( IsSpecial ? 1 : 0 ) - ( IsRagedOnSpawn ? 1 : 0 ) );
- SquadElement.Num = ElemCount;
- // Check value range for ElemCount
- if ( ElemCount < MinZedsInElement )
- {
- return PrintElemParseError("Element count "$ ElemCount $" is not positive. "$
- "Must be between "$ MinZedsInElement $" to "$ MaxZedsInElement $" (inclusive).");
- }
- if ( ElemCount > MaxZedsInElement )
- {
- return PrintElemParseError("Element count "$ ElemCount $" is too large. "$
- "Must be between "$ MinZedsInElement $" to "$ MaxZedsInElement $" (inclusive).");
- }
- // Set custom element
- for ( i = 0; i < ExternalCustomZed.Length; i++ )
- {
- CustomElemType.AddItem( ExternalCustomZed[i].ZedName );
- if ( ElemType ~= CustomElemType[i] )
- {
- CustomElemClass = class<KFPawn_Monster>( DynamicLoadObject( ExternalCustomZed[i].ZedClassPath, class'Class' ) );
- }
- }
- // Convert user-provided zed info into a EAIType enum and possibly custom class
- ZedNameResolv = class'CD_ZedNameUtils'.static.GetZedType(
- /* const input params */
- ElemType, CustomElemType, IsSpecial, IsRagedOnSpawn,
- /* mutable output params */
- SquadElement.Type, SquadElement.CustomClass, CustomElemClass );
- // Was it a valid zed type name?
- if ( ZedNameResolv == ZNR_INVALID_NAME )
- {
- return PrintElemParseError("\""$ ElemType $"\" does not appear to be a zed name."$
- " Must be a zed name or abbreviation like cyst, fp, etc.");
- }
- // If the ElemDef requested a special zed, then we need to
- // check that the zed described by ElemType actually has a
- // special/albino variant.
- if ( ZedNameResolv == ZNR_INVALID_SPECIAL )
- {
- return PrintElemParseError("\""$ ElemType $"\" does not have a special variant."$
- " Remove the asterisk from \""$ ElemDef $"\" for a non-special equivalent.");
- }
- if ( ZedNameResolv == ZNR_INVALID_RAGE )
- {
- return PrintElemParseError("\""$ ElemType $"\" does not have a raged-on-spawn variant."$
- " Remove the exclamation point from \""$ ElemDef $"\" for a non raged-on-spawn equivalent.");
- }
- // Should have ZNR_OK == ZedNameResolve by process of elimination here,
- // but check just in case we add a new ZNR enum entry and forget to
- // update this function.
- if ( ZedNameResolv != ZNR_OK )
- {
- return PrintElemParseError("\""$ ElemDef $"\" could not be parsed: " $ ZedNameResolv);
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement