Пример #1
0
void FIGHTER::Update()
{
    switch(Mode) //This Will Probably Be Eliminated
    {
        case WAIT: //If Unit Is Waiting Then Return To Normal Mode
            Mode = NORMAL;
        return;
        
        case CHASE: //If Unit Is In CHASE Mode They Will Not Choose A New Destination
            Move();
        break;
        
        case NORMAL:
            Move();
        break;
        
        case RUN:
            Move();
        break;
        
        default:
        break;
    }
    
    if((Pos.x == Dest.x) && (Pos.y == Dest.y))
    {   
        NewDest();
    }
    
    if(Time.GetElapsedTime() >= 1) //Reload Timer NOTE: This Should NOT Be A Constant, SFML 2.0 Is Moving To Miliseconds
    {
        if(Ammo > 0)
        {
            Mode = NORMAL;
            Loaded = true;
            Time.Reset();
        }
    }
}
Пример #2
0
void SoldierTriesToContinueAlongPath(SOLDIERTYPE *pSoldier)
{
	INT16 usNewGridNo,bAPCost;


	// turn off the flag now that we're going to do something about it...
	// ATE: USed to be redundent, now if called befroe NewDest can cause some side efects...
	// AdjustNoAPToFinishMove( pSoldier, FALSE );

	if (pSoldier->bNewSituation == IS_NEW_SITUATION)
	{
		CancelAIAction(pSoldier,DONTFORCE);
		return;
	}

	if (pSoldier->usActionData >= NOWHERE)
	{
		CancelAIAction(pSoldier,DONTFORCE);	
		return;
	}

	if (!NewOKDestination( pSoldier,pSoldier->usActionData, TRUE, pSoldier->bLevel ))
	{
		CancelAIAction(pSoldier,DONTFORCE);
		return;
	}

	if (IsActionAffordable(pSoldier))
	{
		if (pSoldier->bActionInProgress == FALSE)
		{
			// start a move that didn't even get started before...
			// hope this works...
			NPCDoesAct(pSoldier);

			// perform the chosen action
			pSoldier->bActionInProgress = ExecuteAction(pSoldier); // if started, mark us as busy
		}
		else
		{
			// otherwise we shouldn't have to do anything(?)
		}
	}
	else
	{
		CancelAIAction(pSoldier,DONTFORCE);
#ifdef TESTAI
		DebugMsg( TOPIC_JA2AI, DBG_LEVEL_3, 
						String("Soldier (%d) HAS NOT ENOUGH AP to continue along path",pSoldier->ubID) );
#endif
	}

	usNewGridNo = NewGridNo( (UINT16)pSoldier->sGridNo, DirectionInc( (UINT8)pSoldier->usPathingData[ pSoldier->usPathIndex ] ) );

	// Find out how much it takes to move here!
	bAPCost = EstimateActionPointCost( pSoldier, usNewGridNo, (INT8)pSoldier->usPathingData[ pSoldier->usPathIndex ], pSoldier->usUIMovementMode, (INT8) pSoldier->usPathIndex, (INT8) pSoldier->usPathDataSize );

	if (pSoldier->bActionPoints >= bAPCost)
	{
		// seems to have enough points...
		NewDest(pSoldier,usNewGridNo);
		// maybe we didn't actually start the action last turn...
		pSoldier->bActionInProgress = TRUE;
#ifdef TESTAI
		DebugMsg( TOPIC_JA2AI, DBG_LEVEL_3, 
						String("Soldier (%d) continues along path",pSoldier->ubID) );
#endif
	}
	else
	 {
		CancelAIAction(pSoldier,DONTFORCE);
#ifdef TESTAI
		DebugMsg( TOPIC_JA2AI, DBG_LEVEL_3, 
						String("Soldier (%d) HAS NOT ENOUGH AP to continue along path",pSoldier->ubID) );
#endif
	 }
}											
Пример #3
0
int TryToResumeMovement(SOLDIERTYPE *pSoldier, INT16 sGridno)
{
	UINT8 ubGottaCancel = FALSE;
	UINT8 ubSuccess = FALSE;


	// have to make sure the old destination is still legal (somebody may
	// have occupied the destination gridno in the meantime!)
	if (LegalNPCDestination(pSoldier,sGridno,ENSURE_PATH,WATEROK,0))
	{
#ifdef DEBUGDECISIONS
		DebugAI( String( "%d CONTINUES MOVEMENT to gridno %d...\n",pSoldier->ubID,gridno ) );
#endif

		pSoldier->bPathStored = TRUE;	// optimization - Ian

		// make him go to it (needed to continue movement across multiple turns)
		NewDest(pSoldier,sGridno);

		ubSuccess = TRUE;
	 
		// make sure that it worked (check that pSoldier->sDestination == pSoldier->sGridNo)
		if (pSoldier->sDestination == sGridno)
		{
			ubSuccess = TRUE;
		}
		else
		{
#ifdef BETAVERSION
			sprintf(tempstr,"TryToResumeMovement: ERROR - NewDest failed for %s, action CANCELED",pSoldier->name);

#ifdef RECORDNET
			fprintf(NetDebugFile,"\n\t%s\n",tempstr);
#endif

			PopMessage(tempstr);
			SaveGame(ERROR_SAVE);
#endif

			// must work even for escorted civs, can't just set the flag
			CancelAIAction(pSoldier,FORCE);
		}

  }
 else
  {
		// don't black-list anything here, this situation can come up quite
		// legally if another soldier gets in the way between turns

#ifdef BETAVERSION
		sprintf(tempstr,"TryToResumeMovement: %d can't continue to gridno %d, no longer legal!",pSoldier->ubID,gridno);

#ifdef RECORDNET
		fprintf(NetDebugFile,"\n\t%s\n",tempstr);
#endif

#ifdef DEBUGDECISIONS
		AIPopMessage(tempstr);
#endif

#endif


		if (!pSoldier->bUnderEscort)
		{
			CancelAIAction(pSoldier,DONTFORCE);	// no need to force this
		}
		else
		{
			// this is an escorted NPC, don't want to just completely stop
			// moving, try to find a nearby "next best" destination if possible
			pSoldier->usActionData = GoAsFarAsPossibleTowards(pSoldier,sGridno,pSoldier->bAction);

			// if it's not possible to get any closer
			if (pSoldier->usActionData == NOWHERE)
			{
				ubGottaCancel = TRUE;
			}
			else
			{
				// change his desired destination to this new one
				sGridno = pSoldier->usActionData;

				// GoAsFar... sets pathStored TRUE only if he could go all the way

				// make him go to it (needed to continue movement across multiple turns)
				NewDest(pSoldier,sGridno);


				// make sure that it worked (check that pSoldier->sDestination == pSoldier->sGridNo)
				if (pSoldier->sDestination == sGridno)
					ubSuccess = TRUE;
				else
					ubGottaCancel = TRUE;
			}

			if (ubGottaCancel)
			{
				// can't get close, gotta abort the movement!
				CancelAIAction(pSoldier,FORCE);

				// tell the player doing the escorting that civilian has stopped
				//EscortedMoveCanceled(pSoldier,COMMUNICATE);
			}
		}
	}

	return(ubSuccess);
}