// Ryzom - MMORPG Framework
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
#ifndef AI_SHARE_H
#define AI_SHARE_H
namespace NLLIGO
{
class CLigoConfig;
class CPrimitives;
}
namespace AI_SHARE
{
extern bool LinkWithAiSpawnCommands;
extern bool LinkWithAiActionCommands;
extern bool LinkWithPrimitiveParser;
extern NLLIGO::CLigoConfig *LigoConfig;
inline void init(NLLIGO::CLigoConfig *config)
{
// this code forces the linker to link in files that would otherwise be lost
// these files use constructors of static objects to instantiate objects
LinkWithAiSpawnCommands=true;
LinkWithAiActionCommands=true;
LinkWithPrimitiveParser=true;
LigoConfig=config;
}
// the parser for '.primitive' files
extern void parsePrimFile(const std::string &filename);
// the parser for 'AiActions' stream in pdr (R2 format)
extern void parsePrimStream(NLMISC::IStream & stream, const std::string & streamName);
// the parser for 'AiActions' primitives in pdr (R2 format)
extern void parsePrimNoStream( NLLIGO::CPrimitives* primDoc, const std::string & streamName );
//-------------------------------------------------------------------------------------------------
// some handy utilities
//-------------------------------------------------------------------------------------------------
// dumb routine to simplify repetitive text parsing code
inline bool isWhiteSpace(char c)
{
return (c==' ' || c=='\t');
}
// -- stringToKeywordAndTail() --
// The following routine splits a text string into a keyword and a tail.
// A ':' is used as separator between keyword and tail
// All leading and trailing ' ' and '\t' round keyword and tail characters are stripped
// If no keyword is found routine retuns false (keyword and tail retain previous content)
inline bool stringToKeywordAndTail(const std::string &input,std::string &keyword, std::string &tail)
{
uint i=0, j, k;
// skip white space
while (ii && isWhiteSpace(input[k-1]);)--k; // k points to character after end of keyword
// if no keyword found then give up
if (k==i) return false;
// copy out the keyword
keyword=input.substr(i,k-i);
// find the end of the tail text
for (k=input.size();k>j && isWhiteSpace(input[k-1]);) --k; // k points to character after end of tail text
// find start of tail text
do { ++j; } while(jj && isWhiteSpace(input[i-1]);) --i; // i points to character after end of tail text
// find start of tail text
do { ++j; } while(j