Esempio n. 1
0
// Pause 1.5 seconds
void dodGame::WAIT()
{
	Uint32 ticks1;
	ticks1 = SDL_GetTicks();
	scheduler.curTime = ticks1;

	do
	{
		if (scheduler.curTime >= scheduler.TCBLND[0].next_time)
		{
			scheduler.CLOCK();
			if (game.AUTFLG && game.demoRestart == false)
			{
				return;
			}
			scheduler.EscCheck();
		}
		scheduler.curTime = SDL_GetTicks();
	} while (scheduler.curTime < ticks1 + 1500);
}
// This method is called from the scheduler to move the
// creatures.  This is where most of the creature logic
// resides.  It's frequency is determined by the creature
// type, and its location relative to the player.
int Creature::CMOVE(int task, int cidx)
{
	int oidx, dir, X, loop;
	bool doRandom = false;
	dodBYTE r, c, rnd, d;
	dodBYTE shA, shB;
	dodSHORT shD, shD2;

	if (FRZFLG == 0)
	{
		// ignore dead creatures
		if (CCBLND[cidx].P_CCUSE == 0)
		{
			return 0;
		}

		// pick up object
		if (
			CCBLND[cidx].creature_id != CRT_SCORPION &&
			CCBLND[cidx].creature_id < CRT_WIZIMG &&
			!(
			  game.CreaturesIgnoreObjects &&
			  CCBLND[cidx].P_CCROW == player.PROW &&
			  CCBLND[cidx].P_CCCOL == player.PCOL
			)
		   )
		{
			object.OFINDF = 0;
			oidx = object.OFIND(RowCol(CCBLND[cidx].P_CCROW,
									   CCBLND[cidx].P_CCCOL));
			if (oidx != -1)
			{
				object.OCBLND[oidx].P_OCPTR = CCBLND[cidx].P_CCOBJ;
				CCBLND[cidx].P_CCOBJ = oidx;
				--object.OCBLND[oidx].P_OCOWN;
				viewer.PUPDAT();
				if (CCBLND[cidx].P_CCROW == player.PROW &&
					CCBLND[cidx].P_CCCOL == player.PCOL)
				{
					viewer.PUPDAT();
					viewer.NEWLUK = 0;
					scheduler.TCBLND[task].next_time = scheduler.curTime +
						CCBLND[cidx].P_CCTAT;
					return 0;
				}
				else
				{
					scheduler.TCBLND[task].next_time = scheduler.curTime +
						CCBLND[cidx].P_CCTMV;
					return 0;
				}
			}
		}

		// attack player
		if (CCBLND[cidx].P_CCROW == player.PROW &&
			CCBLND[cidx].P_CCCOL == player.PCOL)
		{
			// do creature sound
			Mix_PlayChannel(creChannel, creSound[CCBLND[cidx].creature_id], 0);
			while (Mix_Playing(creChannel) == 1)
			{
				if (scheduler.curTime >= scheduler.TCBLND[0].next_time)
				{
					scheduler.CLOCK();
					if (game.AUTFLG && game.demoRestart == false)
					{
						return 0;
					}
				}
				scheduler.curTime = SDL_GetTicks();
			}

			// set player shielding parameters
			shA = 0x80;
			shB = 0x80;

			if (player.PLHAND != -1 && object.OCBLND[player.PLHAND].obj_type == Object::OBJT_SHIELD)
			{
				shD = (((int)shA << 8) | shB);
				shD2 = (((int)object.OCBLND[player.PLHAND].P_OCXX0 << 8) |
						 object.OCBLND[player.PLHAND].P_OCXX1);
				if (shD2 < shD)
				{
					shA = (shD2 >> 8);
					shB = (shD2 & 255);
				}
			}