void Game5World::setObjectsPositionsAndRooms()
{
	for (int i=0;i<GAME4_NUMBER_OF_ROOMS;i++) { usedRooms[i] = 0; }

	itsYellowKeyRoom = getRandomRoom(FALSE,0);
	itsYellowKeyX = -1;

	itsWhiteKeyRoom = getRandomRoom(FALSE,0);
	itsWhiteKeyX = -1;

	itsBlackKeyRoom = getRandomRoom(FALSE,0);
	itsBlackKeyX = -1;

	itsSwordRoom = getRandomRoom(FALSE,0);
	itsSwordX = -1;

	itsMagnetRoom = getRandomRoom(FALSE,0);
	itsMagnetX = -1;

	itsBridgeRoom = getRandomRoom(FALSE,0);
	itsBridgeX = -1;

	itsBridge2Room = getRandomRoom(FALSE,0);
	itsBridge2X = -1;

	itsChaliceRoom = getRandomRoom(TRUE,0);
	itsChaliceX = -1;

	itsArmourRoom = getRandomRoom(TRUE,0);
	itsArmourX = -1;

	itsCandleRoom = getRandomRoom(TRUE,0);
	itsCandleX = -1;

	itsYellowDragonRoom = getRandomRoom(FALSE,1);
	itsYellowDragonX = 320;
	itsYellowDragonY = 0;

	itsGreenDragonRoom = getRandomRoom(FALSE,1);
	itsGreenDragonX = 544;
	itsGreenDragonY = 160;

	itsRedDragonRoom = getRandomRoom(FALSE,1);
	itsRedDragonX = 72;
	itsRedDragonY = 224;

	itsPurpleDragonRoom = getRandomRoom(FALSE,1);
	itsPurpleDragonX = -1;

	itsBatRoom = getRandomRoom(FALSE,2);
	itsBatX = 64;
	itsBatY = 0;


}
Example #2
0
void _actorLogic(character *actor) {
	int moved = 0;

	if (!actor->hp) {
		return;
	}
	
	character *player = getPlayer(), *ptr = CHARACTERS;
	item *weaponPtr = NULL, *actorWeapon = actorGetItemWithFlag(actor, IS_WEAPON);
	int hitActor = 0;
	int nx = actor->x + actor->vx;
	int ny = actor->y + actor->vy;
	int spawnPosition[2];
	
	if (!actor->turns) {
		return;
	}
	
	if (actor->delay > 1) {
		actor->delay --;
		
		return;
	}
	
	actor->turns = 0;
	actor->delay = 0;

	if (actor->nextStanceFlagsToAdd) {
		tickSystemsWithMaskForEntity(getWorld(), actor->entityId, EVENT_ADD_STANCE);

		actor->stanceFlags |= actor->nextStanceFlagsToAdd;
		actor->nextStanceFlagsToAdd = 0x0;
	}

	if (actor->nextStanceFlagsToRemove) {
		tickSystemsWithMaskForEntity(getWorld(), actor->entityId, EVENT_REMOVE_STANCE);

		actor->stanceFlags ^= actor->nextStanceFlagsToRemove;
		
		if (actor->nextStanceFlagsToRemove & IS_STUNNED) {
			if (actor == player) {
				showMessage(5, "You regain composure.", NULL);
			} else {
				showMessage(5, "It regains composure.", NULL);
			}
		} else if (actor->nextStanceFlagsToRemove & IS_HOLDING_LODGED_WEAPON) {
			if (actor == player) {
				showMessage(5, "You dislodge the weapon.", NULL);
			} else {
				showMessage(5, "Something dislodges their weapon.", NULL);
			}
		}
		
		if (actor->nextStanceFlagsToRemove & IS_STUCK_WITH_LODGED_WEAPON) {
			weaponPtr = getItemLodgedInActor(actor);
			
			weaponPtr->itemFlags ^= IS_LODGED;
			weaponPtr->lodgedInActor = NULL;
		}
		
		actor->nextStanceFlagsToRemove = 0x0;
	}
	
	while (ptr != NULL) {
		if (ptr == actor || ptr->hp <= 0) {
			ptr = ptr->next;
			
			continue;
		}
		
		if (ptr->x == nx && ptr->y == ny) {
			hitActor = 1;
			
			break;
		}

		ptr = ptr->next;
	}
	
	if (_checkForTouchedItemAndHandle(actor, nx, ny)) {
		actor->vx = 0;
		actor->vy = 0;
		
		return;
	}

	if (hitActor) {
		actor->vx = 0;
		actor->vy = 0;

		if (attack(actor, ptr)) {
			return;
		}
	} else if (actor->vx || actor->vy) {
		if (actor->stanceFlags & IS_STUCK_WITH_LODGED_WEAPON && getItemLodgedInActor(actor)->owner) {
			printf("Cant move because of stuck weapon.\n");
			
			return;
		}
		
		if (actor->stanceFlags & IS_HOLDING_LODGED_WEAPON) {
			actor->stanceFlags ^= IS_HOLDING_LODGED_WEAPON;
			dropItem(actor, actorWeapon);
			
			printf("Handle letting go of weapon!\n");
			
			showMessage(10, "You let go of the weapon.", NULL);
			
			return;
		}
		
		if (isPositionWalkable(nx, ny)) {
			moved = 1;

			if (actor->aiFlags & IS_VOID_WORM && getRandomFloat(0, 1) > .95) {
				getOpenPositionInRoom(getRandomRoom(), spawnPosition);
				createVoidWorm(spawnPosition[0], spawnPosition[1]);
			}

			if (actor->aiFlags & IS_VOID_WORM) {
				createVoidWormTail(actor->x, actor->y);
			}

			actor->lastX = actor->x;
			actor->lastY = actor->y;
			actor->x = nx;
			actor->y = ny;
			setStance(actor, IS_MOVING);

			if (actor->itemLight) {
				actor->itemLight->fuel -= getLevel();
			}

			if (actor->stanceFlags & IS_STABBING) {
				actor->statStabCount --;

				if (!actor->statStabCount) {
					unsetStance(actor, IS_STABBING);
				}
			}

			TCOD_map_compute_fov(actor->fov, actor->x, actor->y, actor->sightRange, 1, FOV_SHADOW);
		} else {
			if (actor->stanceFlags & IS_MOVING) {
				unsetStance(actor, IS_MOVING);

				if (actor->stanceFlags & IS_STABBING) {
					actor->statStabCount = 0;
					unsetStance(actor, IS_STABBING);
				}
			}
		}
	} else {
		if (actor->stanceFlags & IS_MOVING) {
			unsetStance(actor, IS_MOVING);

			if (actor->stanceFlags & IS_STABBING) {
				actor->statStabCount = 0;
				unsetStance(actor, IS_STABBING);
			}
		}
	}

	if (moved) {
		_checkForItemCollisions(actor);
	}
	
	if (!(actor->aiFlags & IS_IMMUNE_TO_DARKNESS) && _checkIfPositionLit(actor)) {
		return;
	}
	
	if (actor->itemLight) {
		actor->itemLight->x = actor->x;
		actor->itemLight->y = actor->y;
	}

	actor->vx = 0;
	actor->vy = 0;
}