Пример #1
0
bool Parser::parseName( std::string &name )
{
    if( !isInSet( firstNameSet, current ) )
        return false;

    name = "";

    do
    {
        name += current;
        readChar( true );
    }
    while( isInSet( nameSet, current ) );

    return true;
}
Пример #2
0
bool Parser::parseAttributeValue( std::string &attValue )
{
    if( !isInSet( "\"'", current ) )
        return false;

    char quoteChar = current;
    std::string value;

    readChar( false );

    while( current != quoteChar )
    {
        if( current == '<' )
            reportError( "Invalid character '<' in attribute value" );
        else if( current == '&' )
            current = parseReference();

        value += current;
        readChar( false );
    }

    attValue = value;

    readChar( false ); // Skip Quote
    return true;
}
Пример #3
0
Set::Set(int* m, int s) {
    size = 0;
    for (int i = 0; i < s; i++) {
        if (!(isInSet(m[i]))) {
            members[size++] = m[i];
        }
        if (size == MAX_MEMBERS) break;
    }
}
Пример #4
0
void writeSet(refStream stream, set elements)
{ int element = 0;
  refChar delimiter = " ";
  fprintf(stream, "{");
  while (element < bitsPerInt * intsPerSet)
  { if (isInSet(element, elements))
    { fprintf(stream, "%s%i", delimiter, element);
      delimiter = ", "; }
    element += 1; }
 fprintf(stream, " }"); }
Пример #5
0
/*
 * Calculates the set theoretic intersection of two sets. An intersection creates a set whose
 * elements are present in setA AND present in setB. For this to work, the two sets should
 * contain the same type of elements and the comparison functions for setA and setB should be
 * functionally equivalent as well.
 *
 * Arguments:
 * setA -- The first set in the pair of sets to intersection
 * setB -- The second set in the pair of sets to intersection
 * comparisonfunction -- A function to compare the elements in the union. If this is NULL, the
 *                       comparison function from setA will be used.
 *
 * Returns:
 * A set containing all elements present in both sets.
 */
Set *setIntersect( Set *setA, Set *setB, ComparisonFunction comparisonFunction ) {
    // Ensure that the proper comparison function gets used
    if( ! comparisonFunction ) {
        comparisonFunction = setA->elements->comparisonFunction;
    }

    Set *intersectionResult = newSet( comparisonFunction );

    // Iterate over the smaller set
    if( setA->size <= setB->size ) {
        void **elements = bstElements( setA->elements );

        for( int i = 0; i < setA->size; i++ ) {
            void *element = elements[i];

            // If the element is in both sets, add it
            if( isInSet( setB, element ) ) {
                setAdd( intersectionResult, element );
            }
        }

        free( elements );
    } else {
        void **elements = bstElements( setB->elements );

        for( int i = 0; i < setB->size; i++ ) {
            void *element = elements[i];

            // If the element is in both sets, add it
            if( isInSet( setA, element ) ) {
                setAdd( intersectionResult, element );
            }
        }

        free( elements );
    }

    return intersectionResult;
}
Пример #6
0
bool Parser::parseWhitespace()
{
    bool found = false;

    while( isInSet( whitespaceSet, current ) )
    {
        found = true;
        readChar();
        if( endOfData() )
            break;
    }

    return found;
}
Пример #7
0
void writeTokenSet(refStream stream, set elements)
{ int element = 0;
  refChar delimiter = " ";
  fprintf(stream, "{");
  while (element < bitsPerInt * intsPerSet)
  { if (isInSet(element, elements))
    { fputs(delimiter, stream);
      if (minToken <= element && element <= maxToken)
      { fputs(tokenName[element], stream); }
      else
      { fprintf(stream, "%i", element); }
      delimiter = ", "; }
    element += 1; }
 fprintf(stream, " }"); }
Пример #8
0
bool Parser::parseCharData( Node *node )
{
    std::string data;

    while( !isInSet( "<&\0", current ) )
    {
        data += current;
        readChar();
    }

    if( data.find( "]]>" ) != 0xffffffff )
        reportError( "Character data cannot contain ']]>'" );

    node->setData( node->data() + data );
    return ( data.length() > 0 );
}
Пример #9
0
/* Take out duplicated entries. So the result is a unique set of pids.*/
static int uniqueSet (int lhs, int rhs)
{
    int curProc = procTable[lhs];
    int dup = 0;

    if (lhs == rhs - 1)
    {
        if (procTable [lhs] == procTable [rhs])
            return lhs;
        else
            return rhs;
    }
    rhs = uniqueSet (lhs + 1, rhs);
    dup = isInSet (lhs + 1, rhs, curProc);
    if (dup != -1)
    {
        procTable[dup] = procTable[rhs];
        flagTable[dup] = flagTable[rhs];
        rhs --;
    }
    return rhs;
}
Пример #10
0
Coor aStar(int xDep, int yDep , int xArr, int yArr, Point list)
{
	
    int startId,goalId;
    calculDepartArrivee(list,xDep,yDep,xArr,yArr,&startId,&goalId);///
    int danger;

    int x,y,yr;//varialble d'id pas de coordonées
    int tentativeGscore,tentativeIsBetter;

    Point p =NULL;
    ListeFils f = NULL;

    Set presqueResultat = NULL;
    Coor resultat = NULL;

    Set closedSet = NULL;
    Set openSet = NULL;
    addSet(&openSet , startId);

    Came cameFrom = NULL;

    Data data = NULL;

    data = setGscore(startId, 0 ,data);
    data = setHscore(startId, heuristicCostEstimate(startId,goalId,list),data);
    data = setFscore(startId, data->g + data->h, data);

    while (openSet != NULL)
    {
        x = lowestFscore(openSet,data);
        if ( x == goalId)
        {
            presqueResultat = reconstruireChemin(cameFrom,startId,goalId);
            resultat = setToCoor(presqueResultat,list);
            resultat = simplifierResultat(resultat);

            addCoor(&resultat,0,xArr,yArr);
			resultat = inverser(resultat);
            return resultat;
        }


        openSet = removeIdSet(openSet,x);
        addSet(&closedSet, x);


        p = sePlacerEn(x,list);
        for ( f = p->lPt ; f != NULL ; f = f->queue )//pour tout les y voisins de x
        {
            y = f->id;
            yr = y;
            if ( y > 1000)
            {
                y = y-1000;
            }


            if ( isInSet(closedSet,y) || p->enable == 0)
            {
                continue;
            }
            tentativeGscore = getGscore(x,data) + distBetween(x,yr);
            if ( isInSet(openSet,y) == 0)
            {
                addSet(&openSet,y);
                data = setHscore(y,heuristicCostEstimate(y,goalId,list),data);
                tentativeIsBetter = 1;
            }
            else if (tentativeGscore <= getGscore(y,data))
            {
                tentativeIsBetter = 1;
            }
            else
            {
                tentativeIsBetter = 0;
            }

            if ( tentativeIsBetter == 1)
            {
                cameFrom = setCameFrom( y , x , cameFrom);
                data = setGscore(y,tentativeGscore,data);
                 danger = p->enable;
                if (danger == 3)
                    danger = 0;
                else if (danger == 2)
                    danger = 100;
                else if (danger  == 1)
                    danger = 500;
                data = setFscore(y,getGscore(y,data) + getHscore(y,data) + danger, data);
            }
        }
    }
    return NULL;// = erreur
}
Пример #11
0
void emitStatement(refObject term, set wraps)

//  PRE EMIT. Write an open brace if needed.

{ void preEmit(int hook)
  { if (isInSet(hook, wraps))
    { writeChar(target, '{'); }}

//  POST EMIT. Write a close brace if needed.

  void postEmit(int hook)
  { if (isInSet(hook, wraps))
    { writeChar(target, '}'); }}

//  Dispatch to an appropriate case based on TERM's outer hook.

   if (isPair(term))
   { switch (toHook(car(term)))

//  Write C code for a CASE clause.

    { case caseHook:
      { refObject subterm;
        preEmit(caseHook);
        term = cdr(term);
        writeFormat(target, "switch");
        writeChar(target, '(');
        emitExpression(car(term), 13);
        writeChar(target, ')');
        writeChar(target, '{');
        term = cdr(term);
        while (cdr(term) != nil)
        { emitLabels(car(term));
          term = cdr(term);
          subterm = car(term);
          if (isEffected(subterm))
          { emitStatement(subterm, withSet); }
          writeFormat(target, "break");
          writeChar(target, ';');
          term = cdr(term); }
        subterm = car(term);
        if (isEffected(subterm))
        { writeFormat(target, "default");
          writeChar(target, ':');
          emitStatement(subterm, withSet); }
        writeChar(target, '}');
        postEmit(caseHook);
        break; }

//  Write C code for an IF clause.

      case ifHook:
      { refObject subterm;
        preEmit(ifHook);
        term = cdr(term);
        while (true)
        { writeFormat(target, "if");
          writeChar(target, '(');
          emitExpression(car(term), 13);
          writeChar(target, ')');
          term = cdr(term);
          subterm = car(term);
          if (isEffected(subterm))
          { emitStatement(subterm, ifLastWithSet); }
          else
          { writeChar(target, ';'); }
          term = cdr(term);
          if (cdr(term) == nil)
          { subterm = car(term);
            if (isEffected(subterm))
            { writeFormat(target, "else");
              writeBlank(target);
              if (isCar(subterm, ifHook))
              { term = cdr(subterm); }
              else
              { emitStatement(subterm, lastWithSet);
                break; }}
            else
            { break; }}
          else
          { writeFormat(target, "else");
            writeBlank(target); }}
        postEmit(ifHook);
        break; }

//  Write C code for a LAST clause.

      case lastHook:
      { refObject subterm;
        preEmit(lastHook);
        term = cdr(term);
        while (term != nil)
        { subterm = car(term);
          if (isEffected(subterm))
          { emitStatement(subterm, withSet); }
          term = cdr(term); }
        postEmit(lastHook);
        break; }

//  Write C code for a WHILE clause.

      case whileHook:
      { preEmit(whileHook);
        term = cdr(term);
        writeFormat(target, "while");
        writeChar(target, '(');
        emitExpression(car(term), 13);
        writeChar(target, ')');
        term = cadr(term);
        if (isEffected(term))
        { emitStatement(term, lastWithSet); }
        else
        { writeChar(target, ';'); }
        postEmit(whileHook);
        break; }

//  Write C code for a WITH clause.

      case withHook:
      { refObject frame;
        preEmit(withHook);
        term = cdr(term);
        frame = car(term);
        term = cdr(term);
        if (frame == nil)
        { emitVariableDeclarations(term);
          emitFunctionDefinitions(true, term);
          emitVariableDefinitions(nil, term);
          term = car(lastPair(term));
          if (isEffected(term))
          { emitStatement(term, withSet); }}
        else
        { emitFrameDeclaration(frame, term);
          emitVariableDeclarations(term);
          emitFunctionDefinitions(true, term);
          emitFramePush(frame, frameLength(term));
          emitFrameInitialization(frame, term);
          emitVariableDefinitions(frame, term);
          term = car(lastPair(term));
          if (isEffected(term))
          { emitStatement(term, withSet); }
          emitFramePop(frame); }
        postEmit(withHook);
        break; }

//  Other TERMs become C expressions.

      default:
      { if (isEffected(term))
        { emitExpression(term, 13);
          writeChar(target, ';'); }
        break; }}}
  else
  { if (isEffected(term))
    { emitExpression(term, 13);
      writeChar(target, ';'); }}}
Пример #12
0
void Actor::sayLine(const char *msgId, bool background) {
	assert(msgId);

	char id[50];
	Common::String msg = LuaBase::instance()->parseMsgText(msgId, id);

	if (msgId[0] == 0) {
		error("Actor::sayLine: No message ID for text");
		return;
	}

	// During Fullscreen movies SayLine is usually called for text display only.
	// The movie with Charlie screaming after Manny put the sheet on him instead
	// uses sayLine for the voice too.
	// However, normal SMUSH movies may call SayLine, for example:
	// When Domino yells at Manny (a SMUSH movie) he does it with
	// a SayLine request rather than as part of the movie!

	Common::String soundName = id;

	if (g_grim->getGameType() == GType_GRIM) {
		soundName += ".wav";
	} else if (g_grim->getGameType() == GType_MONKEY4 && g_grim->getGamePlatform() == Common::kPlatformPS2) {
		soundName += ".scx";
	} else {
		soundName += ".wVC";
	}
	if (_talkSoundName == soundName)
		return;

	if (_talking || msg.empty())
		shutUp();

	_talkSoundName = soundName;
	if (g_grim->getSpeechMode() != GrimEngine::TextOnly) {
		_talkDelay = 500;
		if (g_sound->startVoice(_talkSoundName.c_str()) && g_grim->getCurrSet()) {
			g_grim->getCurrSet()->setSoundPosition(_talkSoundName.c_str(), _pos);
		}
	}

	// If the actor is clearly not visible then don't try to play the lip sync
	if (_visible && (!g_movie->isPlaying() || g_grim->getMode() == GrimEngine::NormalMode)) {
		Common::String soundLip = id;
		soundLip += ".lip";

		if (!_talkChore[0].isPlaying()) {
			// _talkChore[0] is *_stop_talk
			_talkChore[0].setLastFrame();
		}
		// Sometimes actors speak offscreen before they, including their
		// talk chores are initialized.
		// For example, when reading the work order (a LIP file exists for no reason).
		// Also, some lip sync files have no entries
		// In these cases, revert to using the mumble chore.
		if (g_grim->getSpeechMode() != GrimEngine::TextOnly)
			_lipSync = g_resourceloader->getLipSync(soundLip);
		// If there's no lip sync file then load the mumble chore if it exists
		// (the mumble chore doesn't exist with the cat races announcer)
		if (!_lipSync)
			_mumbleChore.playLooping();

		_talkAnim = -1;
	}

	_talking = true;
	g_grim->addTalkingActor(this);

	_backgroundTalk = background;
	if (background)
		_isTalkingBackground = true;

	if (_sayLineText && g_grim->getMode() != GrimEngine::SmushMode) {
		delete TextObject::getPool().getObject(_sayLineText);
		_sayLineText = 0;
	}

	if (!msg.empty()) {
		GrimEngine::SpeechMode m = g_grim->getSpeechMode();
		if (!g_grim->_sayLineDefaults.getFont() || m == GrimEngine::VoiceOnly)
			return;

		TextObject *textObject = new TextObject(false, true);
		textObject->setDefaults(&g_grim->_sayLineDefaults);
		textObject->setFGColor(_talkColor);
		if (m == GrimEngine::TextOnly || g_grim->getMode() == GrimEngine::SmushMode) {
			textObject->setDuration(500 + msg.size() * 15 * (11 - g_grim->getTextSpeed()));
		}
		if (g_grim->getMode() == GrimEngine::SmushMode) {
			textObject->setX(640 / 2);
			textObject->setY(456);
			g_grim->setMovieSubtitle(textObject);
		} else {
			if (_visible && isInSet(g_grim->getCurrSet()->getName())) {
				_mustPlaceText = true;
			} else {
				_mustPlaceText = false;
				textObject->setX(640 / 2);
				textObject->setY(463);
			}
		}
		textObject->setText(msgId);
		if (g_grim->getMode() != GrimEngine::SmushMode)
			_sayLineText = textObject->getId();
	}
}
Пример #13
0
short estAstarDistance(Point& start,Point& goal,DataForAI& data)
{
	std::vector<Point> closeSet,openSet,step;
	short g_score[MAP_HEIGHT+2][MAP_WIDTH+2];
	short h_score[MAP_HEIGHT+2][MAP_WIDTH+2];
	short f_score[MAP_HEIGHT+2][MAP_WIDTH+2];
	for(short i=0;i<MAP_HEIGHT+2;i++)
		for(short j=0;j<MAP_WIDTH+2;j++)
		{
			//cameFrom[i][j]=origin;//no path
			g_score[i][j]=MAP_HEIGHT*MAP_WIDTH;
			h_score[i][j]=MAP_HEIGHT*MAP_WIDTH;
			f_score[i][j]=MAP_HEIGHT*MAP_WIDTH;
		}
		openSet.push_back(start);//set the open set containing the initial node
		g_score[start.row][start.col]=0;
		h_score[start.row][start.col]=heuristic_estimate_of_distance(start,goal);
		f_score[start.row][start.col]=h_score[start.row][start.col];

		while(!openSet.empty())
		{
			short min;
			Point x;
			std::vector<Point>::iterator iter=openSet.begin();
			x.row=iter->row;
			x.col=iter->col;
			//get the node which have the lowest fscore in open set
			for(min=f_score[iter->row][iter->col];iter!=openSet.end();iter++)
			{
				if(min>=f_score[iter->row][iter->col])
				{
					min=f_score[iter->row][iter->col];
					x.row=iter->row;
					x.col=iter->col;
				}

			}
			//if(data.round==1&&data.myID==4)
			//printf("round%d tank%d:x(%d,%d) have lowest f_score:%d\n",data.round,data.myID,x.row,x.col,f_score[x.row][x.col]);
			if(x.row==goal.row&&x.col==goal.col)
				return step.size();
			//return reconstructPath(cameFrom[goal.row][goal.col]);
			//remove x from open set
			//if(data.round==1&&data.myID==4)
			//printf("round%d tank%d:erase x(%d,%d) from open set and add to close set\n",data.round,data.myID,x.row,x.col);
			for(std::vector<Point>::iterator i=openSet.begin();i!=openSet.end();i++)
			{
				if(x.row==i->row&&x.col==i->col)
				{
					openSet.erase(i);
					break;
				}
			}
			//add x to close set
			closeSet.push_back(x);
			short r=x.row,c=x.col;//index of x
			//each neighbor y of x
			for(short j=0;j<4;j++)
			{
				//printf("direction %d:%d,%d\n",j,dir[j][0],dir[j][1]);
				short nr=r+dir[j][0],nc=c+dir[j][1];
				Point y;//index of y
				y.row=nr;
				y.col=nc;			 

				if(nr<=MAP_HEIGHT && nr>=1 && nc<=MAP_WIDTH && nc>=1)//bound detection
					if(data.map[nr][nc].type!=STONE)//not stone
					{
						if(isInSet(y,closeSet))
							continue;
						short tentative_g_score=g_score[r][c]+1;//tentative_g_score := g_score[x] + dist_between(x,y)
						bool tentative_is_better;
						if(!isInSet(y,openSet))
						{
							openSet.push_back(y);
							tentative_is_better=true;

						}
						else if(tentative_g_score<g_score[nr][nc])
							tentative_is_better=true;
						else
							tentative_is_better=false;
						if(tentative_is_better==true)
						{
							/*
							came_from[y] := x
							g_score[y] := tentative_g_score
							h_score[y] := heuristic_estimate_of_distance(y, goal)
							f_score[y] := g_score[y] + h_score[y]
							*/

							if(!isInSet(x,step))
								step.push_back(x);
							g_score[nr][nc]=tentative_g_score;
							h_score[nr][nc]=heuristic_estimate_of_distance(y,goal);
							f_score[nr][nc]=g_score[nr][nc]+h_score[nr][nc];
						}
					}//if obstacles
			}//end for 4 directions
		}//end while
		//if(data.round==1)
		//printf("end astar for tank%d\n",data.myID);
		return MAP_HEIGHT*MAP_WIDTH;

}