Exemplo n.º 1
0
void CWarZombieAttackState::Execute(CWarZombie * pMonster, float fFrameTime)
{
	const Real targetDisSq = pPlayer->getPosition().squaredDistance(pMonster->getPosition());
	if (targetDisSq > attackRangeSq)
	{
		pMonster->getStateMachine()->ChangeState(&CWarZombieIdleState::getInstance());
	}
	else
	{
		auto timePos = pMonster->getAnimState()->getTimePosition();
		if (0.7f < timePos && timePos < 0.8f)
		{
			if (pMonster->isAttackDelay()) return;

			auto player = InGameState::getInstance()->getPlayer();
			auto pos = pMonster->getPosition();
			auto targetPos = player->getPosition();
			if (targetPos.squaredDistance(pos) < attackRangeSq)
			{
				player->damaged(8);
				pMonster->setAttackDelay(true);
			}
		}
		else
			pMonster->setAttackDelay(false);
	}
}
Exemplo n.º 2
0
	void CCameraFeedbackNotifier::process(const std::shared_ptr<CMessage>& message) {
		//Ambas hacen lo mismo de momento, pero lo dejo separado por si luego queremos poner 
		//comportamientos distintos en función del daño
		switch( message->getMessageType() ) {
			case Message::DAMAGED: {
				std::shared_ptr<CMessageDamaged> damageMess = std::static_pointer_cast<CMessageDamaged>(message);
				CEntity* enemy = damageMess->getEnemy();
				if(enemy != NULL)
					damaged( enemy->getPosition() );
				
				break;
			}
			/*case Message::SET_REDUCED_DAMAGE: {
				damaged();
				break;
			}*/
			case Message::FLASH: {
				std::shared_ptr<CMessageFlash> flashMsg = std::static_pointer_cast<CMessageFlash>(message);
				_flashFactor = flashMsg->getFlashFactor();
				_flashVisible = true;
				_scene->setCompositorVisible(_flashEffect, true);
				break;
			}
		}
	} // process
Exemplo n.º 3
0
void QWindowCompositor::setCursorSurface(QWaylandSurface *surface, int hotspotX, int hotspotY)
{
    if ((m_cursorSurface != surface) && surface)
        connect(surface, SIGNAL(damaged(QRect)), this, SLOT(updateCursor()));

    m_cursorSurface = surface;
    m_cursorHotspotX = hotspotX;
    m_cursorHotspotY = hotspotY;
}
Exemplo n.º 4
0
/*ARGSUSED*/
void
capture(int v __unused)
{
	int		i;
	struct kling	*k;
	double			x;

	/* check for not cloaked */
	if (Ship.cloaked) {
		printf("Ship-ship communications out when cloaked\n");
		return;
	}
	if (damaged(SSRADIO)) {
		out(SSRADIO);
		return;
	}
	/* find out if there are any at all */
	if (Etc.nkling <= 0) {
		printf("Uhura: Getting no response, sir\n");
		return;
	}

	/* if there is more than one Klingon, find out which one */
	k = selectklingon();
	Move.free = 0;
	Move.time = 0.05;

	/* check out that Klingon */
	k->srndreq++;
	x = Param.klingpwr;
	x *= Ship.energy;
	x /= k->power * Etc.nkling;
	x *= Param.srndrprob;
	i = x;
#ifdef xTRACE
	if (Trace)
		printf("Prob = %d (%.4f)\n", i, x);
#endif
	if (i > ranf(100)) {
		/* guess what, he surrendered!!! */
		printf("Klingon at %d,%d surrenders\n", k->x, k->y);
		i = ranf(Param.klingcrew);
		if ( i > 0 )
			printf("%d klingons commit suicide rather than be "
			       "taken captive\n", Param.klingcrew - i);
		if (i > Ship.brigfree)
			i = Ship.brigfree;
		Ship.brigfree -= i;
		printf("%d captives taken\n", i);
		killk(k->x, k->y);
		return;
	}

	/* big surprise, he refuses to surrender */
	printf("Fat chance, captain\n");
	return;
}
Exemplo n.º 5
0
void Text::draw(Canvas*, const Allocation&) const 
{
	canvas_->push_clipping();
	canvas_->clip_rect(allocation_->left(), allocation_->bottom(),
		allocation_->right(), allocation_->top());

	FontBoundingBox fbb;
	font_->font_bbox(fbb);
	Coord r = curLowerY_ / (fbb.ascent() + fbb.descent());
	unsigned i = unsigned(r);
	Coord y = allocation_->top() + (r - i) * (fbb.ascent() + fbb.descent());
	unsigned max = Math::max(Math::max(selection_.line2(), insertion_.line_),
		(unsigned) text_->Height() ? (unsigned) text_->Height() - 1 : 0);
	for (; i <= max; ++i) 
	{
		y -= fbb.ascent();

		if (damaged(i)) 
		{
			Coord x = allocation_->left() - curLowerX_;
			if (i < text_->Height()) 
			{
				const String line = text_->getNth(i);
				drawRegion(selection_, i, x, y, line);
				if (! readOnly_) 
				{
					drawLocation(insertion_, i, x, y, line);
				}
				for (GlyphIndex j = 0; j < annotation_.count(); ++j) 
				{
					drawRegion(*annotation_.item(j), i, x, y, line);
				}
				drawLine(i, x, y, line);
			} 
			else 
			{
				String line;
				drawRegion(selection_, i, x, y, line);
				if (! readOnly_) 
				{
					drawLocation(insertion_, i, x, y, line);
				}
				for (GlyphIndex j = 0; j < annotation_.count(); ++j) 
				{
					drawRegion(*annotation_.item(j), i, x, y, line);
				}
				drawLine(i, x, y, line);
			}
		}
  
		y -= fbb.descent();
		if (y < (allocation_->bottom() - fbb.ascent())) 
			break;
	}
	canvas_->pop_clipping();
}
Exemplo n.º 6
0
void
killb(int qx, int qy)
{
	struct quad	*q;
	struct xy	*b;

	q = &Quad[qx][qy];

	if (q->bases <= 0)
		return;
	if (!damaged(SSRADIO)) {
		/* then update starchart */
		if (q->scanned < 1000)
			q->scanned -= 10;
		else
			if (q->scanned > 1000)
				q->scanned = -1;
	}
	q->bases = 0;
	Now.bases -= 1;
	for (b = Now.base; ; b++)
		if (qx == b->x && qy == b->y)
			break;
	*b = Now.base[Now.bases];
	if (qx == Ship.quadx && qy == Ship.quady) {
		Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY;
		if (Ship.cond == DOCKED)
			undock(0);
		printf("Starbase at %d,%d destroyed\n",
			Etc.starbase.x, Etc.starbase.y);
	} else {
		if (!damaged(SSRADIO)) {
			printf("Uhura: Starfleet command reports that the "
			       "starbase in\n");
			printf("   quadrant %d,%d has been destroyed\n",
				qx, qy);
		}
		else
			schedule(E_KATSB | E_GHOST, TOOLARGE, qx, qy, 0);
	}
}
Exemplo n.º 7
0
void LipstickCompositor::surfaceCreated(QWaylandSurface *surface)
{
    Q_UNUSED(surface)
    connect(surface, SIGNAL(mapped()), this, SLOT(surfaceMapped()));
    connect(surface, SIGNAL(unmapped()), this, SLOT(surfaceUnmapped()));
    connect(surface, SIGNAL(sizeChanged()), this, SLOT(surfaceSizeChanged()));
    connect(surface, SIGNAL(titleChanged()), this, SLOT(surfaceTitleChanged()));
    connect(surface, SIGNAL(windowPropertyChanged(QString,QVariant)), this, SLOT(windowPropertyChanged(QString)));
    connect(surface, SIGNAL(raiseRequested()), this, SLOT(surfaceRaised()));
    connect(surface, SIGNAL(lowerRequested()), this, SLOT(surfaceLowered()));
    connect(surface, SIGNAL(damaged(QRect)), this, SLOT(surfaceDamaged(QRect)));
}
	void CScreamerShieldDamageNotifier::process(const std::shared_ptr<CMessage>& message) {
		switch( message->getMessageType() ) {
			case Message::DAMAGED: {
				std::shared_ptr<CMessageDamaged> dmgMsg = std::static_pointer_cast<CMessageDamaged>(message);
				damaged( dmgMsg->getDamage(), dmgMsg->getEnemy() );
				break;
			}
			case Message::SET_REDUCED_DAMAGE: {
				std::shared_ptr<CMessageSetReducedDamage> reducedDmgMsg = std::static_pointer_cast<CMessageSetReducedDamage>(message);
				reducedDamageAbsorption( reducedDmgMsg->getReducedDamage() );
				break;
			}
		}
	} // process
Exemplo n.º 9
0
void
ram(int ix, int iy)
{
    int		i;
    char		c;

    printf("\07RED ALERT\07: collision imminent\n");
    c = Sect[ix][iy];
    switch (c) {

    case KLINGON:
        printf("%s rams Klingon at %d,%d\n", Ship.shipname, ix, iy);
        killk(ix, iy);
        break;

    case STAR:
    case INHABIT:
        printf("Yeoman Rand: Captain, isn't it getting hot in here?\n");
        sleep(2);
        printf("Spock: Hull temperature approaching 550 Degrees Kelvin.\n");
        lose(L_STAR);

    case BASE:
        printf("You ran into the starbase at %d,%d\n", ix, iy);
        killb(Ship.quadx, Ship.quady);
        /* don't penalize the captain if it wasn't his fault */
        if (!damaged(SINS))
            Game.killb += 1;
        break;
    }
    sleep(2);
    printf("%s heavily damaged\n", Ship.shipname);

    /* select the number of deaths to occur */
    i = 10 + ranf(20 * Game.skill);
    Game.deaths += i;
    Ship.crew -= i;
    printf("McCoy: Take it easy Jim; we had %d casualties.\n", i);

    /* damage devices with an 80% probability */
    for (i = 0; i < NDEV; i++) {
        if (ranf(100) < 20)
            continue;
        damage(i, (2.5 * (franf() + franf()) + 1.0) * Param.damfac[i]);
    }

    /* no chance that your shields remained up in all that */
    Ship.shldup = 0;
}
Exemplo n.º 10
0
int
check_out(int device)
{
	int	dev;

	dev = device;

	/* check for device ok */
	if (!damaged(dev))
		return (0);

	/* report it as being dead */
	out(dev);

	/* but if we are docked, we can go ahead anyhow */
	if (Ship.cond != DOCKED)
		return (1);
	printf("  Using starbase %s\n", Device[dev].name);
	return (0);
}
Exemplo n.º 11
0
impulse()
{
	int			course;
	register int		power;
	double			dist, time;
	register int		percent;
	extern double		move();

	if (Ship.cond == DOCKED)
		return (printf("Scotty: Sorry captain, but we are still docked.\n"));
	if (damaged(IMPULSE))
		return (out(IMPULSE));
	if (getcodi(&course, &dist))
		return;
	power = 20 + 100 * dist;
	percent = 100 * power / Ship.energy + 0.5;
	if (percent >= 85)
	{
		printf("Scotty: That would consume %d%% of our remaining energy.\n",
			percent);
		if (!getynpar("Are you sure that is wise"))
			return;
		printf("Aye aye, sir\n");
	}
	time = dist / 0.095;
	percent = 100 * time / Now.time + 0.5;
	if (percent >= 85)
	{
		printf("Spock: That would take %d%% of our remaining time.\n",
			percent);
		if (!getynpar("Are you sure that is wise"))
			return;
		printf("(He's finally gone mad)\n");
	}
	Move.time = move(0, course, time, 0.095);
	Ship.energy -= 20 + 100 * Move.time * 0.095;
}
Exemplo n.º 12
0
void Player::update(sf::Time deltaTime)
{
	float maxVel = 3.0f;
	const b2Vec2& vel = body->GetLinearVelocity();
	if(hitTimer.getElapsedTime().asSeconds() <= 3.0f)
	{
		leftHitCollision->setActive(false);
		rightHitCollision->setActive(false);
	}
	else
	{
		leftHitCollision->setActive(true);
		rightHitCollision->setActive(true);
	}

	if(rightHitCollision->isHitColliding() && rightHitCollision->isActive())
	{
		setFacing(RIGHT);
		hitTimer.restart();
		damaged();
	}
	if(leftHitCollision->isHitColliding()&& leftHitCollision->isActive())
	{
		setFacing(LEFT);
		hitTimer.restart();
		damaged();
	}
	if(shadeCollision->isHitColliding()&&!groundCallBack->isColliding() && state != GRABBING)
	{
		
		//For funtimes ;)
		//body->SetFixedRotation(false);
		if(getFacing() == LEFT)
		{
			body->ApplyForce(b2Vec2(knockForce,0.1f),b2Vec2(0.0f,0.0f),true);
		}
		else if(getFacing() == RIGHT)
		{
			body->ApplyForce(b2Vec2(-knockForce,0.1f),b2Vec2(0.0f,0.0f),true);
		}
		else{body->ApplyForce(b2Vec2(knockForce,0.1f),b2Vec2(0.0f,0.0f),true);}
		
		setState(KNOCKEDBACKED);
	}

	if (flashLight->isEnabled())
	{
		Shade* shade = flashLightCallBack->getClosestShade(flashLight->getPosition());
		if (shade)
		{
			Facing dir = (getFacing() == Facing::LEFT) ? RIGHT : LEFT;
			shade->increaseTimeInFlashLight(deltaTime.asSeconds());
			shade->setFacing(dir);
		}
	}

	switch(state)
	{
	case NORMAL:
	
		if ((!rightButton && !leftButton) || (rightButton && leftButton))
		{
			body->SetLinearVelocity(b2Vec2(0,vel.y));
		}
		else if (rightButton)
		{
			if (!rightSideCollision->isColliding() && vel.x < maxVel)
			{
				//body->SetLinearVelocity(b2Vec2(SPEED, vel.y));
				body->ApplyLinearImpulse(b2Vec2(0.8f,0.0f),b2Vec2(body->GetWorldCenter()),true);
			}
			
			setFacing(Entity::RIGHT);
		}
		else if (leftButton)
		{
			if (!leftSideCollision->isColliding() && vel.x > -maxVel)
			{
				//body->SetLinearVelocity(b2Vec2(-SPEED, vel.y));
				 body->ApplyLinearImpulse(b2Vec2(-0.8f,0.0f),b2Vec2(body->GetWorldCenter()),true);
			}

			setFacing(Entity::LEFT);
		}
		

		//Check for grabbing if we are not flying upwards.
		if (!groundCallBack->isColliding() && vel.y >= 0)
		{
			if (leftGrabCallBack->isColliding() && !leftAntiGrabCallBack->isColliding() && getFacing() == Facing::LEFT)
			{
				this->setState(PLAYER_STATE::GRABBING);
				const sf::FloatRect& bounds = leftGrabCallBack->getGrabbedFixtureBounds();
				body->SetTransform(Convert::sfmlToB2(sf::Vector2f(bounds.left + bounds.width + (bodyBounds.width / 2.0f), bounds.top)), 0);
			}
			else if (rightGrabCallBack->isColliding() && !rightAntiGrabCallBack->isColliding() && getFacing() == Facing::RIGHT)
			{
				this->setState(PLAYER_STATE::GRABBING);
				const sf::FloatRect& bounds = rightGrabCallBack->getGrabbedFixtureBounds();
				body->SetTransform(Convert::sfmlToB2(sf::Vector2f(bounds.left-(bodyBounds.width/2.0f), bounds.top)), 0);
			}
		}
		
	break;
	case GRABBING:
	
		//Check if we should just drop down
		//Jumping while grabbing is handled in Player::jump() and not here.
		if (downButton || (rightButton && getFacing() == Facing::LEFT) || (leftButton && getFacing() == Facing::RIGHT))
		{
			const float pushDistance = 12.0f;
			//If we are facing right, push the player a bit left
			if (getFacing() == Facing::RIGHT)
			{
				sf::Vector2f pos = Convert::b2ToSfml(body->GetPosition());
				pos.x -= pushDistance;
				body->SetTransform(Convert::sfmlToB2(pos), 0.0f);
				setFacing(Entity::LEFT);
			}
			//Else just push the player a bit right.
			else if (getFacing() == Facing::LEFT)
			{
				sf::Vector2f pos = Convert::b2ToSfml(body->GetPosition());
				pos.x += pushDistance;
				body->SetTransform(Convert::sfmlToB2(pos), 0.0f);
				setFacing(Entity::RIGHT);
			}

			setState(PLAYER_STATE::NORMAL);
		}
	break;
	case DAMAGED:
	anime.setLooped(false);
	if(!anime.isFinished())
	{
		body->SetLinearVelocity(b2Vec2(0,0));
	}
	if(anime.isFinished())
	{
		setState(NORMAL);
		anime.setLooped(true);
	}
	if(mStats.health <=0)
	{
		setState(DYING);
	}
	break;
	case KNOCKEDBACKED:
		if(mStats.health <=0){setState(DYING);}
		else if (knockedbackClock.getElapsedTime().asSeconds() > 1)
		{
			setState(NORMAL);
		}
		break;
	case DYING:
		mPlatformState.getOverlay(PlatformState::DEATH_SCREEN).setEnabled(true);
		std::cout<<"Waaaaaaaaaaaah"<<std::endl;
		std::cout<<"---------Player Dead----------"<<std::endl;
		break;
	default:
		break;
	}

	updateAnimation();
	updateSound();
	anime.update(deltaTime);
	updateFlashlightPosition();
}
Exemplo n.º 13
0
/*ARGSUSED*/
void
torped(int v __unused)
{
	int		ix, iy;
	double		x, y, dx, dy;
	double		angle;
	int		course, course2;
	int		k;
	double		bigger;
	double		sectsize;
	int		burst;
	int		n;

	if (Ship.cloaked) {
		printf("Federation regulations do not permit attack while "
		       "cloaked.\n");
		return;
	}
	if (check_out(TORPED))
		return;
	if (Ship.torped <= 0) {
		printf("All photon torpedos expended\n");
		return;
	}

	/* get the course */
	course = getintpar("Torpedo course");
	if (course < 0 || course > 360)
		return;
	burst = -1;

	/* need at least three torpedoes for a burst */
	if (Ship.torped < 3) {
		printf("No-burst mode selected\n");
		burst = 0;
	} else {
		/* see if the user wants one */
		if (!testnl()) {
			k = ungetc(getchar(), stdin);
			if (k >= '0' && k <= '9')
				burst = 1;
		}
	}
	if (burst < 0) {
		burst = getynpar("Do you want a burst");
	}
	if (burst) {
		burst = getintpar("burst angle");
		if (burst <= 0)
			return;
		if (burst > 15) {
			printf("Maximum burst angle is 15 degrees\n");
			return;
		}
	}
	sectsize = NSECTS;
	n = -1;
	if (burst) {
		n = 1;
		course -= burst;
	}
	for (; n && n <= 3; n++) {
		/* select a nice random course */
		course2 = course + randcourse(n);
		/* convert to radians */
		angle = course2 * 0.0174532925;
		dx = -cos(angle);
		dy =  sin(angle);
		bigger = fabs(dx);
		x = fabs(dy);
		if (x > bigger)
			bigger = x;
		dx /= bigger;
		dy /= bigger;
		x = Ship.sectx + 0.5;
		y = Ship.secty + 0.5;
		if (Ship.cond != DOCKED)
			Ship.torped -= 1;
		printf("Torpedo track");
		if (n > 0)
			printf(", torpedo number %d", n);
		printf(":\n%6.1f\t%4.1f\n", x, y);
		while (1) {
			ix = x += dx;
			iy = y += dy;
			if (x < 0.0 || x >= sectsize ||
			    y < 0.0 || y >= sectsize) {
				printf("Torpedo missed\n");
				break;
			}
			printf("%6.1f\t%4.1f\n", x, y);
			switch (Sect[ix][iy]) {
			  case EMPTY:
				continue;

			  case HOLE:
				printf("Torpedo disappears into a black "
				       "hole\n");
				break;

			  case KLINGON:
				for (k = 0; k < Etc.nkling; k++) {
					if (Etc.klingon[k].x != ix ||
					    Etc.klingon[k].y != iy)
						continue;
					Etc.klingon[k].power -= 500 + ranf(501);
					if (Etc.klingon[k].power > 0) {
						printf("*** Hit on Klingon at "
						       "%d,%d: extensive "
						       "damages\n",
							ix, iy);
						break;
					}
					killk(ix, iy);
					break;
				}
				break;

			  case STAR:
				nova(ix, iy);
				break;

			  case INHABIT:
				kills(ix, iy, -1);
				break;

			  case BASE:
				killb(Ship.quadx, Ship.quady);
				Game.killb += 1;
				break;

			  default:
				printf("Unknown object %c at %d,%d destroyed\n",
					Sect[ix][iy], ix, iy);
				Sect[ix][iy] = EMPTY;
				break;
			}
			break;
		}
		if (damaged(TORPED) || Quad[Ship.quadx][Ship.quady].stars < 0)
			break;
		course += burst;
	}
	Move.free = 0;
}
Exemplo n.º 14
0
/* argument is set if attack while resting */
void
attack(int resting)
{
	int	hit, i, l;
	int	maxhit, tothit, shldabsb;
	double	chgfac, propor, extradm;
	double	dustfac, tothe;
	int	cas;
	int	hitflag;

	if (Move.free)
		return;
	if (Etc.nkling <= 0 || Quad[Ship.quadx][Ship.quady].stars < 0)
		return;
	if (Ship.cloaked && Ship.cloakgood)
		return;
	/* move before attack */
	klmove(0);
	if (Ship.cond == DOCKED)
	{
		if (!resting)
			printf("Starbase shields protect the %s\n", Ship.shipname);
		return;
	}
	/* setup shield effectiveness */
	chgfac = 1.0;
	if (Move.shldchg)
		chgfac = 0.25 + 0.50 * franf();
	maxhit = tothit = 0;
	hitflag = 0;

	/* let each Klingon do his damndest */
	for (i = 0; i < Etc.nkling; i++)
	{
		/* if he's low on power he won't attack */
		if (Etc.klingon[i].power < 20)
			continue;
		if (!hitflag)
		{
			printf("\nStardate %.2f: Klingon attack:\n",
				Now.date);
			hitflag++;
		}
		/* complete the hit */
		dustfac = 0.90 + 0.01 * franf();
		tothe = Etc.klingon[i].avgdist;
		hit = Etc.klingon[i].power * pow(dustfac, tothe) * Param.hitfac;
		/* deplete his energy */
		dustfac = Etc.klingon[i].power;
		Etc.klingon[i].power = dustfac * Param.phasfac * (1.0 + (franf() - 0.5) * 0.2);
		/* see how much of hit shields will absorb */
		shldabsb = 0;
		if (Ship.shldup || Move.shldchg)
		{
			propor = Ship.shield;
			propor /= Param.shield;
			shldabsb = propor * chgfac * hit;
			if (shldabsb > Ship.shield)
				shldabsb = Ship.shield;
			Ship.shield -= shldabsb;
		}
		/* actually do the hit */
		printf("\aHIT: %d units", hit);
		if (!damaged(SRSCAN))
			printf(" from %d,%d", Etc.klingon[i].x, Etc.klingon[i].y);
		cas = (shldabsb * 100) / hit;
		hit -= shldabsb;
		if (shldabsb > 0)
			printf(", shields absorb %d%%, effective hit %d\n",
				cas, hit);
		else
			printf("\n");
		tothit += hit;
		if (hit > maxhit)
			maxhit = hit;
		Ship.energy -= hit;
		/* see if damages occurred */
		if (hit >= (15 - Game.skill) * (25 - ranf(12)))
		{
			printf("\aCRITICAL HIT!!!\a\n");
			/* select a device from probability vector */
			cas = ranf(1000);
			for (l = 0; cas >= 0; l++)
				cas -= Param.damprob[l];
			l -= 1;
			/* compute amount of damage */
			extradm = (hit * Param.damfac[l]) / (75 + ranf(25)) + 0.5;
			/* damage the device */
			damage(l, extradm);
			if (damaged(SHIELD))
			{
				if (Ship.shldup)
					printf("Sulu: Shields knocked down, captain.\n");
				Ship.shldup = 0;
				Move.shldchg = 0;
			}
		}
		if (Ship.energy <= 0)
			lose(L_DSTRYD);
	}

	/* see what our casualities are like */
	if (maxhit >= 200 || tothit >= 500)
	{
		cas = tothit * 0.015 * franf();
		if (cas >= 2)
		{
			printf("McCoy: we suffered %d casualties in that attack.\n",
				cas);
			Game.deaths += cas;
			Ship.crew -= cas;
		}
	}

	/* allow Klingons to move after attacking */
	klmove(1);
}
Exemplo n.º 15
0
void
klmove(int fl)
{
	int		n;
	struct kling	*k;
	double		dx, dy;
	int		nextx, nexty;
	int		lookx, looky;
	int		motion;
	int		fudgex, fudgey;
	int		qx, qy;
	double		bigger;
	int		i;

#	ifdef xTRACE
	if (Trace)
		printf("klmove: fl = %d, Etc.nkling = %d\n", fl, Etc.nkling);
#	endif
	for (n = 0; n < Etc.nkling; n++)
	{
		k = &Etc.klingon[n];
		i = 100;
		if (fl)
			i = 100.0 * k->power / Param.klingpwr;
		if (ranf(i) >= Param.moveprob[2 * Move.newquad + fl])
			continue;
		/* compute distance to move */
		motion = ranf(75) - 25;
		motion *= k->avgdist * Param.movefac[2 * Move.newquad + fl];
		/* compute direction */
		dx = Ship.sectx - k->x + ranf(3) - 1;
		dy = Ship.secty - k->y + ranf(3) - 1;
		bigger = dx;
		if (dy > bigger)
			bigger = dy;
		if (bigger == 0.0)
			bigger = 1.0;
		dx = dx / bigger + 0.5;
		dy = dy / bigger + 0.5;
		if (motion < 0)
		{
			motion = -motion;
			dx = -dx;
			dy = -dy;
		}
		fudgex = fudgey = 1;
		/* try to move the klingon */
		nextx = k->x;
		nexty = k->y;
		for (; motion > 0; motion--)
		{
			lookx = nextx + dx;
			looky = nexty + dy;
			if (lookx < 0 || lookx >= NSECTS || looky < 0 || looky >= NSECTS)
			{
				/* new quadrant */
				qx = Ship.quadx;
				qy = Ship.quady;
				if (lookx < 0)
					qx -= 1;
				else
					if (lookx >= NSECTS)
						qx += 1;
				if (looky < 0)
					qy -= 1;
				else
					if (looky >= NSECTS)
						qy += 1;
				if (qx < 0 || qx >= NQUADS || qy < 0 || qy >= NQUADS ||
						Quad[qx][qy].stars < 0 || Quad[qx][qy].klings > MAXKLQUAD - 1)
					break;
				if (!damaged(SRSCAN))
				{
					printf("Klingon at %d,%d escapes to quadrant %d,%d\n",
						k->x, k->y, qx, qy);
					motion = Quad[qx][qy].scanned;
					if (motion >= 0 && motion < 1000)
						Quad[qx][qy].scanned += 100;
					motion = Quad[Ship.quadx][Ship.quady].scanned;
					if (motion >= 0 && motion < 1000)
						Quad[Ship.quadx][Ship.quady].scanned -= 100;
				}
				Sect[k->x][k->y] = EMPTY;
				Quad[qx][qy].klings += 1;
				Etc.nkling -= 1;
				*k = Etc.klingon[Etc.nkling];
				Quad[Ship.quadx][Ship.quady].klings -= 1;
				k = 0;
				break;
			}
			if (Sect[lookx][looky] != EMPTY)
			{
				lookx = nextx + fudgex;
				if (lookx < 0 || lookx >= NSECTS)
					lookx = nextx + dx;
				if (Sect[lookx][looky] != EMPTY)
				{
					fudgex = -fudgex;
					looky = nexty + fudgey;
					if (looky < 0 || looky >= NSECTS || Sect[lookx][looky] != EMPTY)
					{
						fudgey = -fudgey;
						break;
					}
				}
			}
			nextx = lookx;
			nexty = looky;
		}
		if (k && (k->x != nextx || k->y != nexty))
		{
			if (!damaged(SRSCAN))
				printf("Klingon at %d,%d moves to %d,%d\n",
					k->x, k->y, nextx, nexty);
			Sect[k->x][k->y] = EMPTY;
			Sect[k->x = nextx][k->y = nexty] = KLINGON;
		}
	}
	compkldist(0);
}
Exemplo n.º 16
0
void
snova(int x, int y)
{
	int		qx, qy;
	int		ix, iy = 0;
	int		f, n;
	int		dx, dy;
	struct quad	*q;

	f = 0;
	ix = x;
	if (ix < 0)
	{
		/* choose a quadrant */
		while (1)
		{
			qx = ranf(NQUADS);
			qy = ranf(NQUADS);
			q = &Quad[qx][qy];
			if (q->stars > 0)
				break;
		}
		if (Ship.quadx == qx && Ship.quady == qy)
		{
			/* select a particular star */
			n = ranf(q->stars);
			for (ix = 0; ix < NSECTS; ix++)
			{
				for (iy = 0; iy < NSECTS; iy++)
					if (Sect[ix][iy] == STAR || Sect[ix][iy] == INHABIT)
						if ((n -= 1) <= 0)
							break;
				if (n <= 0)
					break;
			}
			f = 1;
		}
	}
	else
	{
		/* current quadrant */
		iy = y;
		qx = Ship.quadx;
		qy = Ship.quady;
		q = &Quad[qx][qy];
		f = 1;
	}
	if (f)
	{
		/* supernova is in same quadrant as Enterprise */
		printf("\a\nRED ALERT: supernova occuring at %d,%d\n", ix, iy);
		dx = ix - Ship.sectx;
		dy = iy - Ship.secty;
		if (dx * dx + dy * dy <= 2)
		{
			printf("***  Emergency override attem");
			sleep(1);
			printf("\n");
			lose(L_SNOVA);
		}
		q->scanned = 1000;
	}
	else
	{
		if (!damaged(SSRADIO))
		{
			q->scanned = 1000;
			printf("\nUhura: Captain, Starfleet Command reports a supernova\n");
			printf("  in quadrant %d,%d.  Caution is advised\n", qx, qy);
		}
	}

	/* clear out the supernova'ed quadrant */
	dx = q->klings;
	dy = q->stars;
	Now.klings -= dx;
	if (x >= 0)
	{
		/* Enterprise caused supernova */
		Game.kills += dy;
		if (q->bases)
			killb(qx, qy);
		Game.killk += dx;
	}
	else
		if (q->bases)
			killb(qx, qy);
	killd(qx, qy, (x >= 0));
	q->stars = -1;
	q->klings = 0;
	if (Now.klings <= 0)
	{
		printf("Lucky devil, that supernova destroyed the last klingon\n");
		win();
	}
}
Exemplo n.º 17
0
void
warp(int fl, int c, double d)
{
	int		course;
	double		power;
	double		dist;
	double		p_time;
	double		speed;
	double		frac;
	int		percent;
	int		i;
	char		*s;

	if (Ship.cond == DOCKED) {
		printf("%s is docked\n", Ship.shipname);
		return;
	}
	if (damaged(WARP)) {
		out(WARP);
		return;
	}
	course = c;
	dist = d;

	/* check to see that we are not using an absurd amount of power */
	power = (dist + 0.05) * Ship.warp3;
	percent = 100 * power / Ship.energy + 0.5;
	if (percent >= 85) {
		printf("Scotty: That would consume %d%% of our remaining energy.\n",
			percent);
		if (!getynpar("Are you sure that is wise"))
			return;
	}

	/* compute the speed we will move at, and the time it will take */
	speed = Ship.warp2 / Param.warptime;
	p_time = dist / speed;

	/* check to see that that value is not ridiculous */
	percent = 100 * p_time / Now.time + 0.5;
	if (percent >= 85) {
		printf("Spock: That would take %d%% of our remaining time.\n",
			percent);
		if (!getynpar("Are you sure that is wise"))
			return;
	}

	/* compute how far we will go if we get damages */
	if (Ship.warp > 6.0 && ranf(100) < 20 + 15 * (Ship.warp - 6.0)) {
		frac = franf();
		dist *= frac;
		p_time *= frac;
		damage(WARP, (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20);
	}

	/* do the move */
	Move.time = move(fl, course, p_time, speed);

	/* see how far we actually went, and decrement energy appropriately */
	dist = Move.time * speed;
	Ship.energy -= dist * Ship.warp3 * (Ship.shldup + 1);

	/* test for bizarre events */
	if (Ship.warp <= 9.0)
		return;
	printf("\n\n  ___ Speed exceeding warp nine ___\n\n");
	sleep(2);
	printf("Ship's safety systems malfunction\n");
	sleep(2);
	printf("Crew experiencing extreme sensory distortion\n");
	sleep(4);
	if (ranf(100) >= 100 * dist) {
		printf("Equilibrium restored -- all systems normal\n");
		return;
	}

	/* select a bizzare thing to happen to us */
	percent = ranf(100);
	if (percent < 70) {
		/* time warp */
		if (percent < 35 || !Game.snap) {
			/* positive time warp */
			p_time = (Ship.warp - 8.0) * dist * (franf() + 1.0);
			Now.date += p_time;
			printf("Positive time portal entered -- it is now Stardate %.2f\n",
				Now.date);
			for (i = 0; i < MAXEVENTS; i++) {
				percent = Event[i].evcode;
				if (percent == E_FIXDV || percent == E_LRTB)
					Event[i].date += p_time;
			}
			return;
		}

		/* s/he got lucky: a negative time portal */
		p_time = Now.date;
		s = Etc.snapshot;
		bmove(s, Quad, sizeof Quad);
		bmove(s += sizeof Quad, Event, sizeof Event);
		bmove(s += sizeof Event, &Now, sizeof Now);
		printf("Negative time portal entered -- it is now Stardate %.2f\n",
			Now.date);
		for (i = 0; i < MAXEVENTS; i++)
			if (Event[i].evcode == E_FIXDV)
				reschedule(&Event[i], Event[i].date - p_time);
		return;
	}

	/* test for just a lot of damage */
	if (percent < 80)
		lose(L_TOOFAST);
	printf("Equilibrium restored -- extreme damage occurred to ship systems\n");
	for (i = 0; i < NDEV; i++)
		damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]);
	Ship.shldup = 0;
}
Exemplo n.º 18
0
phaser()
{
	register int		i;
	int			j;
	register struct kling	*k;
	double			dx, dy;
	double			anglefactor, distfactor;
	register struct banks	*b;
	int			manual, flag, extra;
	int			hit;
	double			tot;
	int			n;
	int			hitreqd[NBANKS];
	struct banks		bank[NBANKS];
	struct cvntab		*ptr;

	if (Ship.cond == DOCKED)
		return(printf("Phasers cannot fire through starbase shields\n"));
	if (damaged(PHASER))
		return (out(PHASER));
	if (Ship.shldup)
		return (printf("Sulu: Captain, we cannot fire through shields.\n"));
	if (Ship.cloaked)
	{
		printf("Sulu: Captain, surely you must realize that we cannot fire\n");
		printf("  phasers with the cloaking device up.\n");
		return;
	}

	/* decide if we want manual or automatic mode */
	manual = 0;
	if (testnl())
	{
		if (damaged(COMPUTER))
		{
			printf(Device[COMPUTER].name);
			manual++;
		}
		else
			if (damaged(SRSCAN))
			{
				printf(Device[SRSCAN].name);
				manual++;
			}
		if (manual)
			printf(" damaged, manual mode selected\n");
	}

	if (!manual)
	{
		ptr = getcodpar("Manual or automatic", Matab);
		manual = (int) ptr->value;
	}
	if (!manual && damaged(COMPUTER))
	{
		printf("Computer damaged, manual selected\n");
		skiptonl(0);
		manual++;
	}

	/* initialize the bank[] array */
	flag = 1;
	for (i = 0; i < NBANKS; i++)
		bank[i].units = 0;
	if (manual)
	{
		/* collect manual mode statistics */
		while (flag)
		{
			printf("%d units available\n", Ship.energy);
			extra = 0;
			flag = 0;
			for (i = 0; i < NBANKS; i++)
			{
				b = &bank[i];
				printf("\nBank %d:\n", i);
				hit = getintpar("units");
				if (hit < 0)
					return;
				if (hit == 0)
					break;
				extra += hit;
				if (extra > Ship.energy)
				{
					printf("available energy exceeded.  ");
					skiptonl(0);
					flag++;
					break;
				}
				b->units = hit;
				hit = getintpar("course");
				if (hit < 0 || hit > 360)
					return;
				b->angle = hit * 0.0174532925;
				b->spread = getfltpar("spread");
				if (b->spread < 0 || b->spread > 1)
					return;
			}
			Ship.energy -= extra;
		}
		extra = 0;
	}
	else
	{
		/* automatic distribution of power */
		if (Etc.nkling <= 0)
			return (printf("Sulu: But there are no Klingons in this quadrant\n"));
		printf("Phasers locked on target.  ");
		while (flag)
		{
			printf("%d units available\n", Ship.energy);
			hit = getintpar("Units to fire");
			if (hit <= 0)
				return;
			if (hit > Ship.energy)
			{
				printf("available energy exceeded.  ");
				skiptonl(0);
				continue;
			}
			flag = 0;
			Ship.energy -= hit;
			extra = hit;
			n = Etc.nkling;
			if (n > NBANKS)
				n = NBANKS;
			tot = n * (n + 1) / 2;
			for (i = 0; i < n; i++)
			{
				k = &Etc.klingon[i];
				b = &bank[i];
				distfactor = k->dist;
				anglefactor = ALPHA * BETA * OMEGA / (distfactor * distfactor + EPSILON);
				anglefactor *= GAMMA;
				distfactor = k->power;
				distfactor /= anglefactor;
				hitreqd[i] = distfactor + 0.5;
				dx = Ship.sectx - k->x;
				dy = k->y - Ship.secty;
				b->angle = atan2(dy, dx);
				b->spread = 0.0;
				b->units = ((n - i) / tot) * extra;
#				ifdef xTRACE
				if (Trace)
				{
					printf("b%d hr%d u%d df%.2f af%.2f\n",
						i, hitreqd[i], b->units,
						distfactor, anglefactor);
				}
#				endif
				extra -= b->units;
				hit = b->units - hitreqd[i];
				if (hit > 0)
				{
					extra += hit;
					b->units -= hit;
				}
			}

			/* give out any extra energy we might have around */
			if (extra > 0)
			{
				for (i = 0; i < n; i++)
				{
					b = &bank[i];
					hit = hitreqd[i] - b->units;
					if (hit <= 0)
						continue;
					if (hit >= extra)
					{
						b->units += extra;
						extra = 0;
						break;
					}
					b->units = hitreqd[i];
					extra -= hit;
				}
				if (extra > 0)
					printf("%d units overkill\n", extra);
			}
		}
	}

#	ifdef xTRACE
	if (Trace)
	{
		for (i = 0; i < NBANKS; i++)
		{
			b = &bank[i];
			printf("b%d u%d", i, b->units);
			if (b->units > 0)
				printf(" a%.2f s%.2f\n", b->angle, b->spread);
			else
				printf("\n");
		}
	}
#	endif

	/* actually fire the shots */
	Move.free = 0;
	for (i = 0; i < NBANKS; i++)
	{
		b = &bank[i];
		if (b->units <= 0)
		{
			continue;
		}
		printf("\nPhaser bank %d fires:\n", i);
		n = Etc.nkling;
		k = Etc.klingon;
		for (j = 0; j < n; j++)
		{
			if (b->units <= 0)
				break;
			/*
			** The formula for hit is as follows:
			**
			**  zap = OMEGA * [(sigma + ALPHA) * (rho + BETA)]
			**	/ (dist ** 2 + EPSILON)]
			**	* [cos(delta * sigma) + GAMMA]
			**	* hit
			**
			** where sigma is the spread factor,
			** rho is a random number (0 -> 1),
			** GAMMA is a crud factor for angle (essentially
			**	cruds up the spread factor),
			** delta is the difference in radians between the
			**	angle you are shooting at and the actual
			**	angle of the klingon,
			** ALPHA scales down the significance of sigma,
			** BETA scales down the significance of rho,
			** OMEGA is the magic number which makes everything
			**	up to "* hit" between zero and one,
			** dist is the distance to the klingon
			** hit is the number of units in the bank, and
			** zap is the amount of the actual hit.
			**
			** Everything up through dist squared should maximize
			** at 1.0, so that the distance factor is never
			** greater than one.  Conveniently, cos() is
			** never greater than one, but the same restric-
			** tion applies.
			*/
			distfactor = BETA + franf();
			distfactor *= ALPHA + b->spread;
			distfactor *= OMEGA;
			anglefactor = k->dist;
			distfactor /= anglefactor * anglefactor + EPSILON;
			distfactor *= b->units;
			dx = Ship.sectx - k->x;
			dy = k->y - Ship.secty;
			anglefactor = atan2(dy, dx) - b->angle;
			anglefactor = cos((anglefactor * b->spread) + GAMMA);
			if (anglefactor < 0.0)
			{
				k++;
				continue;
			}
			hit = anglefactor * distfactor + 0.5;
			k->power -= hit;
			printf("%d unit hit on Klingon", hit);
			if (!damaged(SRSCAN))
				printf(" at %d,%d", k->x, k->y);
			printf("\n");
			b->units -= hit;
			if (k->power <= 0)
			{
				killk(k->x, k->y);
				continue;
			}
			k++;
		}
	}

	/* compute overkill */
	for (i = 0; i < NBANKS; i++)
		extra += bank[i].units;
	if (extra > 0)
		printf("\n%d units expended on empty space\n", extra);
}
Exemplo n.º 19
0
void
abandon(int v __unused)
{
	struct quad	*q;
	int		i;
	int		j;
	struct event	*e;

	if (Ship.ship == QUEENE) {
		printf("You may not abandon ye Faire Queene\n");
		return;
	}
	if (Ship.cond != DOCKED) {
		if (damaged(SHUTTLE)) {
			out(SHUTTLE);
			return;
		}
		printf("Officers escape in shuttlecraft\n");
		/* decide on fate of crew */
		q = &Quad[Ship.quadx][Ship.quady];
		if (q->qsystemname == 0 || damaged(XPORTER)) {
			printf("Entire crew of %d left to die in outer space\n",
				Ship.crew);
			Game.deaths += Ship.crew;
		} else {
			printf("Crew beams down to planet %s\n", systemname(q));
		}
	}
	/* see if you can be exchanged */
	if (Now.bases == 0 || Game.captives < 20 * Game.skill)
		lose(L_CAPTURED);
	/* re-outfit new ship */
	printf("You are hereby put in charge of an antiquated but still\n");
	printf("  functional ship, the Fairie Queene.\n");
	Ship.ship = QUEENE;
	Ship.shipname = "Fairie Queene";
	Param.energy = Ship.energy = 3000;
	Param.torped = Ship.torped = 6;
	Param.shield = Ship.shield = 1250;
	Ship.shldup = 0;
	Ship.cloaked = 0;
	Ship.warp = 5.0;
	Ship.warp2 = 25.0;
	Ship.warp3 = 125.0;
	Ship.cond = GREEN;
	/* clear out damages on old ship */
	for (i = 0; i < MAXEVENTS; i++) {
		e = &Event[i];
		if (e->evcode != E_FIXDV)
			continue;
		unschedule(e);
	}
	/* get rid of some devices and redistribute probabilities */
	i = Param.damprob[SHUTTLE] + Param.damprob[CLOAK];
	Param.damprob[SHUTTLE] = Param.damprob[CLOAK] = 0;
	while (i > 0)
		for (j = 0; j < NDEV; j++) {
			if (Param.damprob[j] != 0) {
				Param.damprob[j] += 1;
				i--;
				if (i <= 0)
					break;
			}
		}
	/* pick a starbase to restart at */
	i = ranf(Now.bases);
	Ship.quadx = Now.base[i].x;
	Ship.quady = Now.base[i].y;
	/* setup that quadrant */
	while (1) {
		initquad(1);
		Sect[Ship.sectx][Ship.secty] = EMPTY;
		for (i = 0; i < 5; i++) {
			Ship.sectx = Etc.starbase.x + ranf(3) - 1;
			if (Ship.sectx < 0 || Ship.sectx >= NSECTS)
				continue;
			Ship.secty = Etc.starbase.y + ranf(3) - 1;
			if (Ship.secty < 0 || Ship.secty >= NSECTS)
				continue;
			if (Sect[Ship.sectx][Ship.secty] == EMPTY) {
				Sect[Ship.sectx][Ship.secty] = QUEENE;
				dock(0);
				compkldist(0);
				return;
			}
		}
	}
}
Exemplo n.º 20
0
double
move(int ramflag, int course, double p_time, double speed)
{
	double			angle;
	double			x, y, dx, dy;
	int		ix, iy;
	double			bigger;
	int			n;
	int		i;
	double			dist;
	double			sectsize;
	double			xn;
	double			evtime;

	ix = iy = 0;
#ifdef xTRACE
	if (Trace)
		printf("move: ramflag %d course %d time %.2f speed %.2f\n",
			ramflag, course, p_time, speed);
#endif
	sectsize = NSECTS;
	/* initialize delta factors for move */
	angle = course * 0.0174532925;
	if (damaged(SINS))
		angle += Param.navigcrud[1] * (franf() - 0.5);
	else
		if (Ship.sinsbad)
			angle += Param.navigcrud[0] * (franf() - 0.5);
	dx = -cos(angle);
	dy = sin(angle);
	bigger = fabs(dx);
	dist = fabs(dy);
	if (dist > bigger)
		bigger = dist;
	dx /= bigger;
	dy /= bigger;

	/* check for long range tractor beams */
	/****  TEMPORARY CODE == DEBUGGING  ****/
	evtime = Now.eventptr[E_LRTB]->date - Now.date;
#ifdef xTRACE
	if (Trace)
		printf("E.ep = %p, ->evcode = %d, ->date = %.2f, evtime = %.2f\n",
			(void *)Now.eventptr[E_LRTB],
			Now.eventptr[E_LRTB]->evcode,
			Now.eventptr[E_LRTB]->date, evtime);
#endif
	if (p_time > evtime && Etc.nkling < 3) {
		/* then we got a LRTB */
		evtime += 0.005;
		p_time = evtime;
	} else
		evtime = -1.0e50;
	dist = p_time * speed;

	/* move within quadrant */
	Sect[Ship.sectx][Ship.secty] = EMPTY;
	x = Ship.sectx + 0.5;
	y = Ship.secty + 0.5;
	xn = NSECTS * dist * bigger;
	n = xn + 0.5;
#ifdef xTRACE
	if (Trace)
		printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n);
#endif
	Move.free = 0;

	for (i = 0; i < n; i++) {
		ix = (x += dx);
		iy = (y += dy);
#ifdef xTRACE
		if (Trace)
			printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y);
#endif
		if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize) {
			/* enter new quadrant */
			dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn;
			dy = Ship.quady * NSECTS + Ship.secty + dy * xn;
			if (dx < 0.0)
				ix = -1;
			else
				ix = dx + 0.5;
			if (dy < 0.0)
				iy = -1;
			else
				iy = dy + 0.5;
#ifdef xTRACE
			if (Trace)
				printf("New quad: ix = %d, iy = %d\n", ix, iy);
#endif
			Ship.sectx = x;
			Ship.secty = y;
			compkldist(0);
			Move.newquad = 2;
			attack(0);
			checkcond();
			Ship.quadx = ix / NSECTS;
			Ship.quady = iy / NSECTS;
			Ship.sectx = ix % NSECTS;
			Ship.secty = iy % NSECTS;
			if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 ||
			    Ship.quady >= NQUADS) {
				if (!damaged(COMPUTER)) {
					dumpme(0);
				} else
					lose(L_NEGENB);
			}
			initquad(0);
			n = 0;
			break;
		}
		if (Sect[ix][iy] != EMPTY) {
			/* we just hit something */
			if (!damaged(COMPUTER) && ramflag <= 0) {
				ix = x - dx;
				iy = y - dy;
				printf("Computer reports navigation error; %s stopped at %d,%d\n",
					Ship.shipname, ix, iy);
				Ship.energy -= Param.stopengy * speed;
				break;
			}
			/* test for a black hole */
			if (Sect[ix][iy] == HOLE) {
				/* get dumped elsewhere in the galaxy */
				dumpme(1);
				initquad(0);
				n = 0;
				break;
			}
			ram(ix, iy);
			break;
		}
	}
	if (n > 0) {
		dx = Ship.sectx - ix;
		dy = Ship.secty - iy;
		dist = sqrt(dx * dx + dy * dy) / NSECTS;
		p_time = dist / speed;
		if (evtime > p_time)
			p_time = evtime;		/* spring the LRTB trap */
		Ship.sectx = ix;
		Ship.secty = iy;
	}
	Sect[Ship.sectx][Ship.secty] = Ship.ship;
	compkldist(0);
	return (p_time);
}