1148330Snetchild/* $OpenBSD: impulse.c,v 1.7 2016/01/07 14:37:51 mestre Exp $ */ 2148330Snetchild/* $NetBSD: impulse.c,v 1.3 1995/04/22 10:59:03 cgd Exp $ */ 3148330Snetchild 4148330Snetchild/* 5148330Snetchild * Copyright (c) 1980, 1993 6148330Snetchild * The Regents of the University of California. All rights reserved. 7148330Snetchild * 8148330Snetchild * Redistribution and use in source and binary forms, with or without 9148330Snetchild * modification, are permitted provided that the following conditions 10148330Snetchild * are met: 11148330Snetchild * 1. Redistributions of source code must retain the above copyright 12148330Snetchild * notice, this list of conditions and the following disclaimer. 13148330Snetchild * 2. Redistributions in binary form must reproduce the above copyright 14148543Snetchild * notice, this list of conditions and the following disclaimer in the 15148543Snetchild * documentation and/or other materials provided with the distribution. 16148330Snetchild * 3. Neither the name of the University nor the names of its contributors 17169815Sdelphij * may be used to endorse or promote products derived from this software 18169815Sdelphij * without specific prior written permission. 19169815Sdelphij * 20169815Sdelphij * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21169815Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22169815Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23169815Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24169815Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25169815Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26169815Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27169815Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28169815Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29170204Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30169815Sdelphij * SUCH DAMAGE. 31169815Sdelphij */ 32169815Sdelphij 33169815Sdelphij#include <stdio.h> 34170204Sru 35169815Sdelphij#include "getpar.h" 36169815Sdelphij#include "trek.h" 37169815Sdelphij 38169815Sdelphij/** 39169815Sdelphij ** move under impulse power 40169815Sdelphij **/ 41169815Sdelphij 42169815Sdelphijvoid 43169815Sdelphijimpulse(int v) 44169815Sdelphij{ 45169815Sdelphij int course, power, percent; 46169815Sdelphij double dist, time; 47169815Sdelphij 48169815Sdelphij if (Ship.cond == DOCKED) 49169815Sdelphij { 50169815Sdelphij printf("Scotty: Sorry captain, but we are still docked.\n"); 51169815Sdelphij return; 52169815Sdelphij } 53169815Sdelphij if (damaged(IMPULSE)) 54169815Sdelphij { 55169815Sdelphij out(IMPULSE); 56169815Sdelphij return; 57169815Sdelphij } 58169815Sdelphij if (getcodi(&course, &dist)) 59169815Sdelphij return; 60169815Sdelphij power = 20 + 100 * dist; 61169815Sdelphij percent = 100 * power / Ship.energy + 0.5; 62169815Sdelphij if (percent >= 85) 63169815Sdelphij { 64169815Sdelphij printf("Scotty: That would consume %d%% of our remaining energy.\n", 65169815Sdelphij percent); 66169815Sdelphij if (!getynpar("Are you sure that is wise")) 67169815Sdelphij return; 68169815Sdelphij printf("Aye aye, sir\n"); 69169815Sdelphij } 70169815Sdelphij time = dist / 0.095; 71170204Sru percent = 100 * time / Now.time + 0.5; 72169815Sdelphij if (percent >= 85) 73169815Sdelphij { 74169815Sdelphij printf("Spock: That would take %d%% of our remaining time.\n", 75169815Sdelphij percent); 76169815Sdelphij if (!getynpar("Are you sure that is wise")) 77169815Sdelphij return; 78169815Sdelphij printf("(He's finally gone mad)\n"); 79169815Sdelphij } 80169815Sdelphij Move.time = move(0, course, time, 0.095); 81169815Sdelphij Ship.energy -= 20 + 100 * Move.time * 0.095; 82169815Sdelphij} 83169815Sdelphij