void
runners(void)
{
    register struct linked_list *item;
    register struct thing *tp = NULL;

	for(item = mlist; item != NULL; item = next(item)) {
		tp = THINGPTR(item);
		turn_on(*tp, ISREADY);
	}

	for (;;) {
		
	for (item = mlist; item != NULL; item = next(item)) {
		tp = THINGPTR(item);

		if (on(*tp, ISREADY))
			break;
	}

	if (item == NULL)
		break;

	turn_off(*tp, ISREADY);

	if (on(*tp, ISHELD) && rnd(tp->t_stats.s_lvl) > 11) {
	    turn_off(*tp, ISHELD);
	    turn_on(*tp, ISRUN);
	    turn_off(*tp, ISDISGUISE);
	    tp->t_dest = &hero;
	    if (tp->t_stats.s_hpt < tp->maxstats.s_hpt)
		turn_on(*tp, ISFLEE);
	    if (cansee(tp->t_pos.y, tp->t_pos.x))
		msg("The %s breaks free from the hold spell!!!", 
			monsters[tp->t_index].m_name);
	}
	if (off(*tp, ISHELD) && on(*tp, ISRUN)) {
	    register int flee;

	    /* Should monster run away? */
	    flee = (on(*tp, ISFLEE) ||
		((tp->t_dest == &hero) && on(player, ISINWALL) &&
		 off(*tp, CANINWALL)));

	    if (off(*tp, ISSLOW) || tp->t_turn) {
		doctor(tp);
		do_chase(tp, flee);
	    }
	    if (off(*tp, ISDEAD) && on(*tp, ISHASTE)) {
		doctor(tp);
		do_chase(tp, flee);
	    }
	    if (off(*tp, ISDEAD)) {
		tp->t_turn ^= TRUE;
		tp->t_wasshot = FALSE;	/* Not shot anymore */
	    }
	}
    }
}
Example #2
0
LightMap LightMap::corner_evolve() {
    auto result = evolve();
    result.turn_on(0,0);
    result.turn_on(max_x-1,0);
    result.turn_on(max_x-1,max_y-1);
    result.turn_on(0,max_y-1);
    return result;
}
void
add_haste(int blessed)
{
    short   hasttime;

    if (blessed)
        hasttime = 10;
    else
        hasttime = 6;

    if (on(player, ISSLOW))    /* Is person slow? */
    {
        extinguish_fuse(FUSE_NOSLOW);
        noslow(NULL);

        if (blessed)
            hasttime = 4;
        else
            return;
    }

    if (on(player, ISHASTE))
    {
        msg("You faint from exhaustion.");
        no_command += rnd(hasttime);
        lengthen_fuse(FUSE_NOHASTE, rnd(hasttime) + (roll(1, 4) * hasttime));
    }
    else
    {
        turn_on(player, ISHASTE);
        light_fuse(FUSE_NOHASTE, 0, roll(hasttime, hasttime), AFTER);
    }
}
Example #4
0
void		op_pipe2(t_ast *tree, int pfd[2], int *pid)
{
	int			status;
	char		*line;
	t_token		*token;

	token = NULL;
	if (tree->right)
		*pid = execute(tree->right->tk->value, NULL, pfd, 0);
	else
	{
		waitpid(*pid, &status, 0);
		g_handler.cmd = WEXITSTATUS(status);
		g_handler.len = 6;
		turn_on(g_handler.term);
		ft_putstr("\033[31mpipe> \033[m");
		line = reader(0, g_handler.hist);
		lexer(&token, line);
		parse_string(&token);
		ft_strdel(&line);
		g_handler.len = 0;
		if (ft_modify_token_for_redir(&token) != -42)
			op_pipe3(tree, token, pfd, pid);
	}
	close_pfd(pfd);
}
Example #5
0
int main(void)
{
#ifdef _ENABLE_OUTPUT_
  printf("C main(void) function\n");
#endif

  struct Hardware hardware;
  struct Hardware* hw = &hardware;

  struct Firmware firmware;
  struct Firmware* fw = &firmware;

  // burn firmware on chip
  firmware.hw = hw;
  hardware.fw = fw;

  // start hardware
  turn_on(hw);

  // start firmware
#ifdef _ENABLE_POSIX_
  pthread_t firmware_thread;
  pthread_create(&firmware_thread, NULL, poll, (void *) fw);
#else
  ASYNC(poll((void *) fw));
#endif

#ifdef _EXPOSE_BUG_
  sleep(SHORT_DELAY);
#endif

  // environment stimulus
#ifdef _ENABLE_POSIX_
  pthread_t stimulus_thread;
  pthread_create(&stimulus_thread, NULL, stimulus, (void *) hw);
#else
  ASYNC(stimulus((void *) hw));
#endif

#ifdef _EXPOSE_BUG_
  sleep(SHORT_DELAY);
#endif

  // stop hardware
  turn_off(hw);

  // check verification condition:
  //
  // the firmware must have reacted to every environment
  // stimulus that triggered the hardware functionality.
  assert(hardware.regs[SIGNAL_REG_ID] == 0);

#ifdef _ENABLE_POSIX_
  pthread_join(firmware_thread, NULL);
  pthread_join(stimulus_thread, NULL);
  pthread_mutex_destroy(&hw->lock);
#endif

  return 0;
}
Example #6
0
int main(int argc, char *argv[])
{
    char* line = NULL;
    size_t len = 0;
    ssize_t read;

    char action[8];
    int lights[1000][1000];
    int from[2] = {0, 0};
    int to[2] = {0, 0};

    init(lights);

    while ((read = getline(&line, &len, stdin)) != -1) {
        sscanf(line, "%[ togleurnf] %d,%d through %d,%d", action, &from[0], &from[1], &to[0], &to[1]);

        if (strcmp(action, "turn on ") == 0) {
            turn_on(lights, from, to);
        } else if (strcmp(action, "turn off ") == 0) {
            turn_off(lights, from, to);
        } else if (strcmp(action, "toggle ") == 0) {
            toggle(lights, from, to);
        } else {
            puts("bad action");
            return 1;
        }

    }

    printf("%d\n", count(lights));

    return 0;
}
void
chase_it(coord *runner, struct thing *th)
{
    struct linked_list  *item;
    struct thing    *tp;

    /* If we couldn't find him, something is funny */

    if ((item = find_mons(runner->y, runner->x)) == NULL)
    {
        debug("CHASER '%s'", unctrl(winat(runner->y, runner->x)));
        return;
    }

    tp = THINGPTR(item);

    /* Start the beastie running */

    tp->t_ischasing = TRUE;
    tp->t_chasee    = th;

    turn_on(*tp, ISRUN);
    turn_off(*tp, ISDISGUISE);

    return;
}
Example #8
0
int  main()
{
    pthread_t blinker;
    struct sigaction new_action;
    int device, i;
	struct timeval start, end;

	device = open(DEVICE, O_RDWR);
	if (device < 0)
	{
		fprintf(stderr, "could not open " DEVICE "\n");
	}	
	
	gettimeofday(&start, NULL);
	for (i = 0; i < NUMBER; i++)
	{
		turn_on(device);
		turn_off(device);
    }
    gettimeofday(&end, NULL);
    	
	printf("%lf usec\n", timevaldiff(&start, &end) / NUMBER);

	close(device);
      
    return 0;
}
void
electrificate(void)
{
    int affect_dist = 4 + player.t_stats.s_lvl / 4;
    struct linked_list  *item, *nitem;

    for (item = mlist; item != NULL; item = nitem)
    {
        struct thing *tp = THINGPTR(item);
        char *mname = monsters[tp->t_index].m_name;

        nitem = next(item);

        if (DISTANCE(tp->t_pos, hero) < affect_dist)
        {
            int damage = roll(2, player.t_stats.s_lvl);

            debug("Charge does %d (%d)", damage, tp->t_stats.s_hpt - damage);

            if (on(*tp, NOBOLT))
                continue;

            if ((tp->t_stats.s_hpt -= damage) <= 0)
            {
                msg("The %s is killed by an electric shock.", mname);
                killed(&player, item, NOMESSAGE, POINTS);
                continue;
            }

            if (rnd(tp->t_stats.s_intel / 5) == 0)
            {
                turn_on(*tp, ISFLEE);
                msg("The %s is shocked by electricity.", mname);
            }
            else
                msg("The %s is zapped by your electricity.", mname);

            summon_help(tp, NOFORCE);
            turn_off(*tp, ISFRIENDLY);
            turn_off(*tp, ISCHARMED);
            turn_on(*tp, ISRUN);
            turn_off(*tp, ISDISGUISE);
            chase_it(&tp->t_pos, &player);
            fighting = after = running = FALSE;
        }
    }
}
Example #10
0
iPeakPluginDlg::~iPeakPluginDlg()
{
		if(peak)
		{
		 peak->destroy();
		 delete peak;
		 peak=0;
		}
         	turn_on(0);
}
Example #11
0
void lifDIODevice::handle_msg() {
  std::string toDo;
  lifMsg nextMsg;
  runThread = true;
  bool sendStatus;
  std::string successMsg;

  while (runThread) {
    //Lock the msgMutex
    pthread_mutex_lock(&msgMutex);
    //Check if msgQueue is empty
    // - If it is empty, wait hear until you receive a signal that
    //   a message has been pushed onto mainMsgQueue
    if (msgQueue.empty()) {
      pthread_cond_wait(&msgQueuePushed, &msgMutex);
    }
    nextMsg = msgQueue.front();
    msgQueue.pop();
    pthread_mutex_unlock(&msgMutex);

    //PUT CODE TO DO STUFF HERE
    toDo = nextMsg.get_command();
    successMsg = "";
    sendStatus = true;

    try {
      if (toDo == "Initialize") {
        initialize();
      } else if (toDo == "Output") {
        output(nextMsg);
      } else if (toDo == "Input") {
        input(nextMsg);
      } else if (toDo == "High") {
        high(nextMsg);
      } else if (toDo == "Low") {
        low(nextMsg);
      } else if (toDo == "TurnOn") {
        turn_on(nextMsg);
      } else if (toDo == "TurnOff") {
        turn_off(nextMsg);
      } else if (toDo == "GetPinNames") {
        get_pin_names();
      } else if (toDo == "StatusReport") {
        sendStatus = false;
      } else {
        default_msg_handling(nextMsg);
      }
      if (sendStatus)
        status_report("ALL", toDo + "SUCCESS" + " " + successMsg);
    } catch (std::string errStr) {
      status_report("ALL", toDo + "ERROR " + errStr);
    }
  }
}
Example #12
0
/*static */
void display_t::change_state()
{
	if (is_off())
	{
		turn_off();
	}
	else
	{
		turn_on();
	}
}
Example #13
0
iMixyPluginDlg::~iMixyPluginDlg()
{	
	for (int i=0;i<9;i++)	
	{			
		if(vu[i])		
		{		 
			vu[i]->destroy();		 
			delete vu[i];		 
			vu[i]=0;		
		}
         	turn_on(0);	
	} 
}
void SpindleControl::on_gcode_received(void *argument) 
{
    
    Gcode *gcode = static_cast<Gcode *>(argument);
        
    if (gcode->has_m)
    {
        if (gcode->m == 957)
        {
            // M957: report spindle speed
            report_speed();
        }
        else if (gcode->m == 958)
        {
            THECONVEYOR->wait_for_idle();
            // M958: set spindle PID parameters
            if (gcode->has_letter('P'))
                set_p_term( gcode->get_value('P') );
            if (gcode->has_letter('I'))
                set_p_term( gcode->get_value('I') );
            if (gcode->has_letter('D'))
                set_p_term( gcode->get_value('D') );
            // report PID settings
            get_pid_settings();
          
        }
        else if (gcode->m == 3) 
        {
            THECONVEYOR->wait_for_idle();
            // M3: Spindle on
            if(!spindle_on) {
                turn_on();
            }
            
            // M3 with S value provided: set speed
            if (gcode->has_letter('S'))
            {
                set_speed(gcode->get_value('S'));
            }
        }
        else if (gcode->m == 5)
        {
            THECONVEYOR->wait_for_idle();
            // M5: spindle off
            if(spindle_on) {
                turn_off();
            }
        }
    }

}
Example #15
0
int main()
{
	//DDRD=0xFF;
	DDRB=0b00000001;

	int i;
	int delay=5000;//ms
	
	//PULL UP
	on(3);
	on(4);

	//-20080610
	off(0);
	_delay_ms(delay);
	//read from EEPROM
	if(eeprom_read_byte((uint8_t*)EEADDR)) 
	{
		turn_on();
		_delay_ms(delay);
	}
  	while(1) {
		if(is_full())
		{
			turn_off();
			eeprom_write_byte ((uint8_t*)EEADDR,0);
		}
		_delay_ms(delay);
		if(is_empty())
		{
			turn_on();
			eeprom_write_byte ((uint8_t*)EEADDR,1);
		}
		_delay_ms(delay);
	}

}
int main() {
    int t, n, k;
    for(scanf("%d", &t); t--;) {
        int mx = 0;
        for(int i = 0; i < 4096; ++i) {
            sum[i] = 0;
            pre[i] = i;
        }
        for(scanf("%d", &n); n--;) {
            scanf("%d", &k);
            if(sum[k-1]) turn_off(k-1);
            else mx = max(mx, turn_on(k-1));
        }
        printf("%d\n", mx);
    }
}
Example #17
0
int main(void)
{
	HCSR04LP sensor;
	sensor.trigger_pin_number = TRIGGER_PIN;
	sensor.echo_pin_number = ECHO_PIN;
	sensor.power_pin_number = POWER_PIN;

	hcsr04_init(&sensor);
	turn_on(&sensor);
	nrf_delay_us(1000000);

	volatile double result = 0.0;
	result = get_dist(&sensor);
	turn_off(&sensor);
	return (int)result;
}
Example #18
0
PFDigitalPin::PFDigitalPin(zmqpp::context &ctx,
        const std::string &name,
        int gpio_no,
        Direction direction,
        bool value) :
        gpio_no_(gpio_no),
        sock_(ctx, zmqpp::socket_type::rep),
        bus_push_(new zmqpp::socket(ctx, zmqpp::socket_type::push)),
        name_(name),
        direction_(direction),
        default_value_(value),
        want_update_(false)
{
    DEBUG("trying to bind to " << ("inproc://" + name));
    sock_.bind("inproc://" + name);
    bus_push_->connect("inproc://zmq-bus-pull");

    if (direction == Direction::Out)
        value ? turn_on() : turn_off();
}
Example #19
0
void PFDigitalPin::handle_message()
{
    zmqpp::message_t msg;
    std::string frame1;
    sock_.receive(msg);

    msg >> frame1;
    bool ok = false;
    if (frame1 == "ON")
        ok = turn_on(&msg);
    else if (frame1 == "OFF")
        ok = turn_off();
    else if (frame1 == "TOGGLE")
        ok = toggle();
    else if (frame1 == "STATE")
        return send_state();
    else // invalid cmd
        ERROR("Invalid command received (" << frame1 << "). Potential missconfiguration !");
    sock_.send(ok ? "OK" : "KO");
}
/*
 * runto:
 *	Set a mosnter running after something
 *	or stop it from running (for when it dies)
 */
void
runto(coord *runner, coord *spot)
{
    register struct linked_list *item;
    register struct thing *tp;

    /*
     * If we couldn't find him, something is funny
     */
    if ((item = find_mons(runner->y, runner->x)) == NULL) {
	debug("CHASER '%s'", unctrl(winat(runner->y, runner->x)));
	return;
    }
    tp = (struct thing *) ldata(item);
    /*
     * Start the beastie running
     */
    tp->t_dest = spot;
    turn_on(*tp, ISRUN);
    turn_off(*tp, ISDISGUISE);
}
Example #21
0
static ssize_t timeout_store(struct device *dev, struct device_attribute *attr,
			     const char *buf, size_t count)
{
	struct gb_vibrator_device *vib = dev_get_drvdata(dev);
	unsigned long val;
	int retval;

	retval = kstrtoul(buf, 10, &val);
	if (retval < 0) {
		dev_err(dev, "could not parse timeout value %d\n", retval);
		return retval;
	}

	if (val)
		retval = turn_on(vib, (u16)val);
	else
		retval = turn_off(vib);
	if (retval)
		return retval;

	return count;
}
Example #22
0
int main(int argc, char *argv[])
{
  const char *p;
  unsigned long options = 0;
  int verbose = 0;
  int c;

  /* Options --3gb and --4gb are for compatibitity with an old Debian setarch
     implementation. */
  static const struct option longopts[] =
  {
      { "help",               0, 0, 'h' },
      { "version",            0, 0, 'V' },
      { "verbose",            0, 0, 'v' },
      { "addr-no-randomize",  0, 0, 'R' },
      { "fdpic-funcptrs",     0, 0, 'F' },
      { "mmap-page-zero",     0, 0, 'Z' },
      { "addr-compat-layout", 0, 0, 'L' },
      { "read-implies-exec",  0, 0, 'X' },
      { "32bit",              0, 0, 'B' },
      { "short-inode",        0, 0, 'I' },
      { "whole-seconds",      0, 0, 'S' },
      { "sticky-timeouts",    0, 0, 'T' },
      { "3gb",                0, 0, '3' },
      { "4gb",                0, 0, OPT_4GB },
      { "uname-2.6",          0, 0, OPT_UNAME26 },
      { NULL,                 0, 0, 0 }
  };

  setlocale(LC_ALL, "");
  bindtextdomain(PACKAGE, LOCALEDIR);
  textdomain(PACKAGE);

  if (argc < 1)
    show_usage(_("Not enough arguments"));

  p = program_invocation_short_name;
  if (!strcmp(p, "setarch")) {
    argv++;
    argc--;
    if (argc < 1)
      show_usage(_("Not enough arguments"));
    p = argv[0];
    argv[0] = argv[-1];      /* for getopt_long() to get the program name */
    if (!strcmp(p, "-h") || !strcmp(p, "--help"))
      show_help();
    else if (!strcmp(p, "-V") || !strcmp(p, "--version"))
      show_version();
  }
  #if defined(__sparc64__) || defined(__sparc__)
   if (!strcmp(p, "sparc32bash")) {
       if (set_arch(p, 0L))
           err(EXIT_FAILURE, _("Failed to set personality to %s"), p);
       execl("/bin/bash", NULL);
       err(EXIT_FAILURE, "/bin/bash");
   }
  #endif

  while ((c = getopt_long(argc, argv, "+hVv3BFILRSTXZ", longopts, NULL)) != -1) {
    switch (c) {
    case 'h':
      show_help();
      break;
    case 'V':
      show_version();
      break;
    case 'v':
      verbose = 1;
      break;
    case 'R':
	turn_on(ADDR_NO_RANDOMIZE, options);
	break;
    case 'F':
	turn_on(FDPIC_FUNCPTRS, options);
	break;
    case 'Z':
	turn_on(MMAP_PAGE_ZERO, options);
	break;
    case 'L':
	turn_on(ADDR_COMPAT_LAYOUT, options);
	break;
    case 'X':
	turn_on(READ_IMPLIES_EXEC, options);
	break;
    case 'B':
	turn_on(ADDR_LIMIT_32BIT, options);
	break;
    case 'I':
	turn_on(SHORT_INODE, options);
	break;
    case 'S':
	turn_on(WHOLE_SECONDS, options);
	break;
    case 'T':
	turn_on(STICKY_TIMEOUTS, options);
	break;
    case '3':
	turn_on(ADDR_LIMIT_3GB, options);
	break;
    case OPT_4GB:          /* just ignore this one */
      break;
    case OPT_UNAME26:
	turn_on(UNAME26, options);
	break;
    }
  }

  argc -= optind;
  argv += optind;

  if (set_arch(p, options))
    err(EXIT_FAILURE, _("Failed to set personality to %s"), p);

  if (!argc) {
    execl("/bin/sh", "-sh", NULL);
    err(EXIT_FAILURE, "/bin/sh");
  }

  execvp(argv[0], argv);
  err(EXIT_FAILURE, "%s", argv[0]);
  return EXIT_FAILURE;
}
Example #23
0
void run_led_driver() {
	prep_leds();

	switch(led_state) {

	case led_off:
		break;
	case led_start:
		turn_on(REDLED);
		break;

	case led_setup_start:
		turn_on(REDLED);
		blink_slow(YELLOWLED);
		blink_slow(GREENLED1);
		blink_slow(GREENLED2);
		break;
	case led_setup_slave_assoc:
		turn_on(REDLED);
		blink_slow(YELLOWLED);
		turn_on(GREENLED1);
		blink_slow(GREENLED2);
		break;
	case led_setup_slave_found_master:
		turn_on(REDLED);
		blink_slow(YELLOWLED);
		turn_on(GREENLED1);
		turn_on(GREENLED2);
		break;
	case led_setup_master_assoc:
		turn_on(REDLED);
		blink_fast(YELLOWLED);
		turn_on(GREENLED1);
		turn_on(GREENLED2);
		break;

	case led_main_start:
		turn_on(REDLED);
		blink_slow(YELLOWLED);
		blink_slow_sliding(GREENLED1);
		blink_slow_alternating(GREENLED2);
		break;
	case led_main_assoc:
		turn_on(REDLED);
		turn_on(YELLOWLED);
		blink_slow_alternating(GREENLED1);
		break;
	case led_main_connected:
		turn_on(REDLED);
		turn_on(YELLOWLED);
		turn_on(GREENLED1);
		blink_slow(GREENLED2);
		break;

	case led_error:
		blink_slow(REDLED + YELLOWLED + GREENLED1);
		break;
	}

	update_leds();
}
struct linked_list *
wake_monster(int y, int x)
{
    struct thing    *tp;
    struct linked_list  *it;
    struct room *trp;
    char    *mname;

    if ((it = find_mons(y, x)) == NULL)
    {
        debug("Can't find monster in show.");
        return(NULL);
    }

    tp = THINGPTR(it);

    if ((good_monster(*tp)) || on(player, SUMMONING))
    {
        chase_it(&tp->t_pos, &player);
        turn_off(*tp, ISINVIS);
        turn_off(*tp, CANSURPRISE);
        return(it);
    }

    trp = roomin(tp->t_pos);   /* Current room for monster */
    mname = monsters[tp->t_index].m_name;

    /* Let greedy ones guard gold */

    if (on(*tp, ISGREED) && off(*tp, ISRUN))
        if ((trp != NULL) && (lvl_obj != NULL))
        {
            struct linked_list  *item;
            struct object   *cur;

            for (item = lvl_obj; item != NULL; item = next(item))
            {
                cur = OBJPTR(item);

                if ((cur->o_type == GOLD) &&
                    (roomin(cur->o_pos) == trp))
                {
                    /* Run to the gold */
                    tp->t_horde = cur;
                    turn_on(*tp, ISRUN);
                    turn_off(*tp, ISDISGUISE);
                    tp->t_ischasing = FALSE;
                    /* Make it worth protecting */
                    cur->o_count += roll(2, 3) * GOLDCALC;
                    break;
                }
            }
        }

    /*
     * Every time he sees mean monster, it might start chasing him unique
     * monsters always do
     */

    if (  (on(*tp, ISUNIQUE)) ||
          ( (rnd(100) > 33) &&
            on(*tp, ISMEAN) &&
            off(*tp, ISHELD) &&
            off(*tp, ISRUN) &&
            !is_stealth(&player) &&
            (off(player, ISINVIS) || on(*tp, CANSEE))
          )
       )
    {
        chase_it(&tp->t_pos, &player);
    }

    /* Handle gaze attacks */

    if (on(*tp, ISRUN) && cansee(tp->t_pos.y, tp->t_pos.x) &&
            off(player, ISINVIS))
    {
        if (on(*tp, CANHUH))    /* Confusion */
        {
            if (on(player, CANREFLECT))
            {
                msg("You reflect the bewildering stare of the %s.", mname);

                if (save_throw(VS_MAGIC, tp))
                {
                    msg("The %s is confused!", mname);
                    turn_on(*tp, ISHUH);
                }
                else
                    msg("The %s staggers for a moment.", mname);
            }
            else if (save(VS_MAGIC))
            {
                msg("You feel dizzy for a moment, but it quickly passes.");

                if (rnd(100) < 67)
                    turn_off(*tp, CANHUH);
            }
            else if (off(player, ISCLEAR))
            {
                if (off(player, ISHUH))
                {
                    light_fuse(FUSE_UNCONFUSE, 0, rnd(20) + HUHDURATION, AFTER);
                    msg("The %s's gaze has confused you.", mname);
                    turn_on(player, ISHUH);
                }
                else
                    lengthen_fuse(FUSE_UNCONFUSE, rnd(20) + HUHDURATION);
            }
        }

        if (on(*tp, CANSNORE))      /* Sleep */
        {
            if (on(player, CANREFLECT))
            {
                msg("You reflect the lethargic glance of the %s", mname);

                if (save_throw(VS_PARALYZATION, tp))
                {
                    msg("The %s falls asleep!", mname);
                    tp->t_no_move += SLEEPTIME;
                }
            }
            else if (no_command == 0 && !save(VS_PARALYZATION))
            {
                if (is_wearing(R_ALERT))
                    msg("You feel slightly drowsy for a moment.");
                else
                {
                    msg("The %s's gaze puts you to sleep.", mname);
                    no_command = SLEEPTIME;

                    if (rnd(100) < 50)
                        turn_off(*tp, CANSNORE);
                }
            }
        }

        if (on(*tp, CANFRIGHTEN))   /* Fear */
        {
            turn_off(*tp, CANFRIGHTEN);

            if (on(player, CANREFLECT))
            {
                msg("The %s sees its reflection. ", mname);

                if (save_throw(VS_MAGIC,tp))
                {
                    msg("The %s is terrified by its reflection!", mname);
                    turn_on(*tp, ISFLEE);
                }
            }
            else
            {
                if (!save(VS_WAND) && !(on(player, ISFLEE) &&
                       (player.t_chasee==tp)))
                {
                    if ((player.t_ctype != C_PALADIN) &&
                        off(player, SUPERHERO))
                    {
                        turn_on(player, ISFLEE);
                        player.t_ischasing = FALSE;
                        player.t_chasee    = tp;
                        msg("The sight of the %s terrifies you.", mname);
                    }
                    else
                        msg("My, the %s looks ugly.", mname);
                }
            }
        }

        if (on(*tp, LOOKSLOW))     /* Slow */
        {
            turn_off(*tp, LOOKSLOW);

            if (on(player, CANREFLECT))
            {
                msg("You reflect the mournful glare of the %s.", mname);

                if (save_throw(VS_MAGIC,tp))
                {
                    msg("The %s is slowing down!", mname);
                    turn_on(*tp, ISSLOW);
                }
            }
            else if (is_wearing(R_FREEDOM) || save(VS_MAGIC))
                msg("You feel run-down for a moment.");
            else
            {
                if (on(player, ISHASTE))    /* Already sped up */
                {
                    extinguish_fuse(FUSE_NOHASTE);
                    nohaste(NULL);
                }
                else
                {
                    msg("You feel yourself moving %sslower.",
                     on(player, ISSLOW) ? "even " : "");

                    if (on(player, ISSLOW))
                        lengthen_fuse(FUSE_NOSLOW, rnd(4) + 4);
                    else
                    {
                        turn_on(player, ISSLOW);
                        player.t_turn = TRUE;
                        light_fuse(FUSE_NOSLOW, 0, rnd(4) + 4, AFTER);
                    }
                }
            }
        }

        if (on(*tp, CANBLIND))  /* Blinding */
        {
            turn_off(*tp, CANBLIND);

            if (on(player, CANREFLECT))
            {
                msg("You reflect the blinding stare of the %s.", mname);

                if (save_throw(VS_WAND, tp))
                {
                    msg("The %s is blinded!", mname);
                    turn_on(*tp, ISHUH);
                }
            }
            else if (off(player, ISBLIND))
                if (save(VS_WAND) || is_wearing(R_TRUESEE) || is_wearing(R_SEEINVIS))
                    msg("Your eyes film over for a moment.");
                else
                {
                    msg("The gaze of the %s blinds you.", mname);
                    turn_on(player, ISBLIND);
                    light_fuse(FUSE_SIGHT, 0, rnd(30) + 20, AFTER);
                    look(FALSE);
                }
        }

        if (on(*tp, LOOKSTONE))  /* Stoning */
        {
            turn_off(*tp, LOOKSTONE);

            if (on(player, CANREFLECT))
            {
                msg("You reflect the flinty look of the %s.", mname);

                if (save_throw(VS_PETRIFICATION,tp))
                {
                    msg("The %s suddenly stiffens", mname);
                    tp->t_no_move += STONETIME;
                }
                else
                {
                    msg("The %s is turned to stone!", mname);
                    killed(&player, it, NOMESSAGE, POINTS);
                }
            }
            else
            {
                if (on(player, CANINWALL))
                    msg("The %s cannot focus on you.", mname);
                else
                {
                    msg("The gaze of the %s stiffens your limbs.", mname);

                    if (save(VS_PETRIFICATION))
                        no_command = STONETIME;
                    else if (rnd(100))
                        no_command = STONETIME * 3;
                    else
                    {
                        msg("The gaze of the %s petrifies you.", mname);
                        msg("You are turned to stone!!! --More--");
                        wait_for(' ');
                        death(D_PETRIFY);
                        return(it);
                    }
                }
            }
        }
    }

    /*
     * True Sight sees all Never see ISINWALL or CANSURPRISE See ISSHADOW
     * 80% See ISINVIS with See Invisibilty
     */

    if (off(player, CANTRUESEE) &&
        on(*tp, ISINWALL) || on(*tp, CANSURPRISE) ||
        (on(*tp, ISSHADOW) && rnd(100) < 80) ||
        (on(*tp, ISINVIS) && off(player, CANSEE)))
	{
	    /* 
	    TODO: incomplete - need to finish logic
	    int ch = mvwinch(stdscr, y, x); 
	    */
	}
	

    /* hero might be able to hear or smell monster if he can't see it */

    if ((rnd(player.t_ctype == C_THIEF ? 40 : 200) == 0 ||
            on(player, CANHEAR)) && !cansee(tp->t_pos.y, tp->t_pos.x))
        msg("You hear a %s nearby.", mname);
    else if ((rnd(player.t_ctype == C_THIEF ? 40 : 200) == 0 ||
            on(player, CANSCENT)) && !cansee(tp->t_pos.y, tp->t_pos.x))
        msg("You smell a %s nearby.", mname);

    return(it);
}
void
wanderer(void)
{
    int i, cnt = 0;
    struct room *hr = roomin(hero);
    struct linked_list  *item;
    struct thing    *tp;
    coord   cp;
    char    *loc;
    int which;

    /* Find a place for it -- avoid the player's room */

    do
    {
        do
        {
            cnt++;
            i = rnd_room();
        }
        while (!(hr != &rooms[i] || levtype == MAZELEV
               || levtype == THRONE || cnt > 5000));

        rnd_pos(&rooms[i], &cp);
    }
    while(!step_ok(cp.y, cp.x, NOMONST, NULL));

    /* Create a new wandering monster */

    item = new_item(sizeof *tp);
    which = randmonster(TRUE, FALSE);
    new_monster(item, which, &cp, FALSE);

    tp = THINGPTR(item);
    tp->t_pos = cp;     /* Assign the position to the monster */

    chase_it(&tp->t_pos, &player);

    i = rnd(7);

    if (on(*tp, ISSWARM) && i < 5)
        cnt = roll(2, 4);
    else if (on(*tp, ISFLOCK) && i < 5)
        cnt = roll(1, 4);
    else
        cnt = 0;

    for (i = 1; i <= cnt; i++)
    {
        struct linked_list  *ip = creat_mons(tp, which, NOMESSAGE);

        if (ip != NULL)
        {
            struct thing    *mp = THINGPTR(ip);

            if (on(*tp, ISFRIENDLY))
                turn_on(*mp, ISFRIENDLY);
            else
                turn_off(*mp, ISFRIENDLY);
        }
    }

    if (cnt > 0)
    {
        if (on(*tp, LOWCAST) || on(*tp, MEDCAST) || on(*tp, HIGHCAST))
            turn_on(*tp, CANCAST);

        tp->t_stats.s_hpt += roll(2, 8);
        tp->t_stats.s_lvl += roll(2, 3);
        tp->t_stats.s_arm -= roll(1, 6);
        tp->t_stats.s_str += roll(2, 3);
        tp->t_stats.s_intel += roll(2, 3);
        tp->t_stats.s_exp += roll(2, 8) * monsters[which].m_add_exp;
    }

    i = DISTANCE(cp, hero);

    if (i < 20)
        loc = "very close to you";
    else if (i < 400)
        loc = "nearby";
    else
        loc = "in the distance";

    if (wizard)
        msg("Started a wandering %s.", monsters[tp->t_index].m_name);
    else if (on(*tp, ISUNDEAD) && (player.t_ctype == C_CLERIC ||
            player.t_ctype == C_PALADIN || is_wearing(R_PIETY)))
        msg("You sense a new ungodly monster %s.", loc);
    else if (on(player, CANHEAR) || (player.t_ctype == C_THIEF &&
            rnd(20) == 0))
        msg("You hear a new %s moving %s.",
            monsters[tp->t_index].m_name, loc);
    else if (on(player, CANSCENT) || (player.t_ctype == C_THIEF &&
            rnd(20) == 0))
        msg("You smell a new %s %s.", monsters[tp->t_index].m_name,
            loc);
}
struct linked_list *
summon_monster(int type, int familiar, int print_message)
{
    struct linked_list  *mp;
    struct thing    *tp;
    int   monster;

    if (familiar && !is_wearing(R_WIZARD) && off(player, CANSUMMON))
    {
        msg("Only spellcasters can summon familiars!");
        return(NULL);
    }

    if (type == 0)    /* Random monster modified by level */
    {
        int ndice = min(pstats.s_lvl, (nummonst - NUMSUMMON) / 8);

        monster = min(nummonst, roll(ndice, pstats.s_charisma));
        
		/*
         * if a familiar exists, and it is higher in level, make it
         * again 
         */

        if (fam_ptr != NULL) 
		{
            struct thing   *fp = THINGPTR(fam_ptr);

            monster = max(fp->t_index, monster);
        }
	}
    else
        monster = type;

    turn_on(player, SUMMONING);

    mp = creat_mons(&player, monster, NOMESSAGE);

    if (!mp)
    {
        msg("Summon failed.");
        turn_off(player, SUMMONING);
        return(NULL);
    }

    if (print_message == MESSAGE)
    {
        msg("A %s appears out of nowhere!", monsters[monster].m_name);

        if (familiar)
            msg("I am here to serve %s.", whoami);
        else
        {
            msg("My goodness, are you Yendor?");
            ++mons_summoned;
            debug("%d monsters now summoned.", mons_summoned);
        }
    }

    tp = THINGPTR(mp);
    turn_on(*tp, ISCHARMED);    /* Summoned monsters are always charmed */

    if (familiar)
    {
        int i;
        static const unsigned long fam_on[]= {ISREGEN,CANSHOOT,CANWIELD,HASARMOR,ISFAMILIAR,0};
        static const unsigned long fam_off[]={ISMEAN, ISHUH, ISINVIS,
                    CANSURPRISE, NOMOVE,
                    ISSLOW, ISSHADOW, ISGREED, ISFAST,
                    CANFLY, ISFLEE, 0};

        for (i = 0; fam_on[i]; i++)
            turn_on(*tp, fam_on[i]);

        for (i = 0; fam_off[i]; i++)
            turn_off(*tp, fam_off[i]);

        if (fam_ptr != NULL)    /* Get rid of old familiar */
        {
            struct thing    *fp = THINGPTR(fam_ptr);
            struct linked_list  *fpack = fp->t_pack;
            struct linked_list  *item;

            if (fpack != NULL)  /* Transfer pack */
            {
                if (tp->t_pack == NULL)
                    tp->t_pack = fpack;
                else
                {
                    for(item=tp->t_pack; item->l_next != NULL; item=next(item))
                        ;   /* find last item in list */

                    item->l_next = fpack;
                    fpack->l_prev = item;
                }
            }

            fpack = NULL;
            killed(NULL, fam_ptr, NOMESSAGE, NOPOINTS);
        }

        fam_ptr = mp;
        fam_type = monster;

        /* improve their abilities a bit */

        tp->t_stats.s_hpt += roll(2, pstats.s_lvl);
        tp->t_stats.s_lvl += roll(2, (pstats.s_lvl / 4) + 1);
        tp->t_stats.s_arm -= roll(2, (pstats.s_lvl / 4) + 1);
        tp->t_stats.s_str += roll(2, (pstats.s_lvl / 4) + 1);
        tp->t_stats.s_intel += roll(2, (pstats.s_lvl / 4) + 1);
        tp->t_stats.s_wisdom += roll(2, (pstats.s_lvl / 4) + 1);
        tp->t_stats.s_dext += roll(2, (pstats.s_lvl / 4) + 1);
        tp->t_stats.s_const += roll(2, (pstats.s_lvl / 4) + 1);
        tp->t_stats.s_charisma += roll(2, (pstats.s_lvl / 4) + 1);
		
		/* some monsters do no damage by default */
		
		if (strcmp(tp->t_stats.s_dmg, "0d0") == 0)
            tp->t_stats.s_dmg = "1d8";
			
        tp->maxstats = tp->t_stats; /* structure assignment */
    }

    turn_off(player, SUMMONING);

    return(mp);
}
void
new_monster(struct linked_list *item, int type, coord *cp, int max_monster)
{
    struct thing    *tp;
    struct monster  *mp;
    char    *ip, *hitp;
    int   i, min_intel, max_intel;
    int   num_dice, num_sides = 8, num_extra = 0;
    int eff_charisma = pstats.s_charisma;
    int eff_intel = pstats.s_intel;

    attach(mlist, item);
    tp = THINGPTR(item);
    tp->t_index = type;
    tp->t_wasshot = FALSE;
    tp->t_type = monsters[type].m_appear;
    tp->t_ctype = C_MONSTER;
    tp->t_no_move = 0;
    tp->t_doorgoal = -1;
    tp->t_pos = *cp;
    tp->t_oldpos = *cp;
    tp->t_oldch = CCHAR( mvwinch(cw, cp->y, cp->x) );
    mvwaddch(mw, cp->y, cp->x, tp->t_type);
    mp = &monsters[tp->t_index];

    /* Figure out monster's hit points */

    hitp = mp->m_stats.s_hpt;
    num_dice = atoi(hitp);

    if ((hitp = strchr(hitp, 'd')) != NULL)
    {
        num_sides = atoi(++hitp);

        if ((hitp = strchr(hitp, '+')) != NULL)
            num_extra = atoi(++hitp);
    }

    if (max_monster == MAXSTATS)
        tp->t_stats.s_hpt = num_dice * num_sides + num_extra;
    else
        tp->t_stats.s_hpt = roll(num_dice, num_sides) + num_extra;

    tp->t_stats.s_lvl = mp->m_stats.s_lvl;
    tp->t_stats.s_arm = mp->m_stats.s_arm;
    tp->t_stats.s_dmg = mp->m_stats.s_dmg;
    tp->t_stats.s_exp = mp->m_stats.s_exp + mp->m_add_exp * tp->t_stats.s_hpt;
    tp->t_stats.s_str = mp->m_stats.s_str;

    if (max_level > 30)
    {
        tp->t_stats.s_hpt += roll(4, (max_level - 60) * 2);
        tp->t_stats.s_lvl += roll(4, (max_level - 60) / 8);
        tp->t_stats.s_arm -= roll(2, (max_level - 60) / 8);
        tp->t_stats.s_str += roll(2, (max_level - 60) / 12);
        tp->t_stats.s_exp += roll(4, (max_level - 60) * 2) * mp->m_add_exp;
    }

    /*
     * just initailize others values to something reasonable for now
     * maybe someday will *really* put these in monster table
     */

    tp->t_stats.s_wisdom = 8 + rnd(4);
    tp->t_stats.s_dext = 8 + rnd(4);
    tp->t_stats.s_const = 8 + rnd(4);
    tp->t_stats.s_charisma = 8 + rnd(4);

    if (max_level > 45)
        tp->t_stats.s_dext += roll(2, (max_level - 50) / 8);

    /* Set the initial flags */

    for (i = 0; i < 16; i++)
        tp->t_flags[i] = 0;

    for (i = 0; i < 16; i++)
        turn_on(*tp, mp->m_flags[i]);

    /* suprising monsters don't always surprise you */

    if (!max_monster && on(*tp, CANSURPRISE) && rnd(100) < 20)
        turn_off(*tp, CANSURPRISE);

    /* If this monster is unique, genocide it */

    if (on(*tp, ISUNIQUE))
        mp->m_normal = FALSE;

    /* gods automatically get special abilities */

    if (on(*tp, ISGOD))
    {
        turn_on(*tp, CANFRIGHTEN);
        turn_on(*tp, CANCAST);
        turn_on(*tp, CANFLY);
        turn_on(*tp, CANBARGAIN);
        turn_on(*tp, ISLARGE);
        turn_on(*tp, CANTELEPORT);
        turn_on(*tp, CANSPEAK);
        turn_on(*tp, CANDARKEN);
        turn_on(*tp, CANSEE);
        turn_on(*tp, CANLIGHT);
        turn_on(*tp, BMAGICHIT);
    }

    tp->t_turn = TRUE;
    tp->t_pack = NULL;

    /* Figure intelligence */

    min_intel = atoi(mp->m_intel);

    if ((ip = (char *) strchr(mp->m_intel, '-')) == NULL)
        tp->t_stats.s_intel = min_intel;
    else
    {
        max_intel = atoi(++ip);

        if (max_monster)
            tp->t_stats.s_intel = max_intel;
        else
            tp->t_stats.s_intel = min_intel + rnd(max_intel - min_intel);
    }

    tp->t_stats.s_power = (rnd(tp->t_stats.s_lvl / 5) + 1) * tp->t_stats.s_intel;

    tp->maxstats = tp->t_stats; /* structure assignment */

    /* If the monster can shoot, it may have a weapon */

    if (on(*tp, CANSHOOT) && (max_monster || rnd(9) < 6))
    {
        struct linked_list  *thrower_item, *missile_item;
        struct object *thrower, *a_missile;

        thrower_item = new_item(sizeof *thrower);
        thrower = OBJPTR(thrower_item);
        carried_weapon(tp, thrower);

        missile_item = new_item(sizeof *a_missile);
        a_missile = OBJPTR(missile_item);
        carried_weapon(tp, a_missile);

        /* The monster may use a crossbow, sling, footbow, or an arrow */
        /* Take racial preferences into account */

        if ((strcmp(mp->m_name, "elf") == 0) ||
            (strcmp(mp->m_name, "noldor elf") == 0))
        {
            thrower->o_which = BOW;

            if (rnd(5) == 0)
                a_missile->o_which = SILVERARROW;
            else
                a_missile->o_which = ARROW;
        }
        else if ((strcmp(mp->m_name, "dwarf") == 0) ||
                (strcmp(mp->m_name, "kazad dwarf") == 0))
        {
            thrower->o_which = CROSSBOW;
            a_missile->o_which = BOLT;
        }
        else if (on(*tp, ISSMALL))
        {
            switch (rnd(3))
            {
                case 0:
                    thrower->o_which = SLING;
                    a_missile->o_which = BULLET;
                    break;
                default:
                    thrower->o_which = SLING;
                    a_missile->o_which = ROCK;
            }
        }
        else if (on(*tp, ISLARGE))
        {
            switch (rnd(4))
            {
                case 0:
                    thrower->o_which = CROSSBOW;
                    a_missile->o_which = BOLT;
                    break;

                case 1:
                    thrower->o_which = FOOTBOW;
                    a_missile->o_which = FBBOLT;
                    break;

                default:
                    thrower->o_which = BOW;

                    if (rnd(5) == 0)
                        a_missile->o_which = FLAMEARROW;
                    else
                        a_missile->o_which = ARROW;

                    break;
            }
        }
        else
        {
            switch (rnd(6))
            {
                case 1:
                    thrower->o_which = SLING;
                    a_missile->o_which = ROCK;
                    break;

                case 2:
                    thrower->o_which = CROSSBOW;
                    a_missile->o_which = BOLT;
                    break;

                case 3:
                    thrower->o_which = FOOTBOW;
                    a_missile->o_which = FBBOLT;
                    break;

                case 4:
                    thrower->o_which = BOW;
                    a_missile->o_which = ARROW;
                    break;

                default:
                    thrower->o_which = SLING;
                    a_missile->o_which = BULLET;
                    break;
            }
        }

        init_weapon(thrower, thrower->o_which);
        init_weapon(a_missile, a_missile->o_which);

        attach(tp->t_pack, thrower_item);
        attach(tp->t_pack, missile_item);
    }

    /* monsters that wield weapons */

    if (on(*tp, CANWIELD))
    {
        if (max_monster || rnd(3))
        {
            struct linked_list  *wield_item;
            struct object   *wielded;

            wield_item = new_item(sizeof *wielded);
            wielded = OBJPTR(wield_item);
            carried_weapon(tp, wielded);

            i = rnd(CLAYMORE - CLUB) + rnd(2 * tp->t_stats.s_lvl);
            i = min(i, CLAYMORE);
            wielded->o_which = i;
            init_weapon(wielded, wielded->o_which);

            /* Is it too heavy? */

            if (itemweight(wielded) > 8 * tp->t_stats.s_str)
                discard(wield_item);
            else
                attach(tp->t_pack, wield_item);
        }
    }

    if (is_wearing(R_AGGR))
        chase_it(cp, &player);
    else
    {
        turn_off(*tp, ISRUN);

        if (on(*tp, ISFLEE) && (rnd(4) == 0))
            turn_off(*tp, ISFLEE);

        if (rnd(luck) == 0)
            switch (player.t_ctype)
            {
                case C_MAGICIAN:
                case C_ILLUSION:
                    eff_intel = 2 * pstats.s_intel;
                    break;
                case C_DRUID:
                    eff_intel = 2 * pstats.s_intel;
                case C_RANGER:
                    eff_charisma = 2 * pstats.s_charisma;
                    break;
                case C_ASSASIN:
                case C_THIEF:
                case C_NINJA:
                    eff_charisma = pstats.s_charisma / 2;
                    break;
            }

        /* LOWFRIENDLY monsters might be friendly */

        i = roll(1,100);

        if (i == 0 || (on(*tp, LOWFRIENDLY) && i < eff_charisma) ||
            (on(*tp, MEDFRIENDLY) && i < 3 * eff_charisma) ||
            (on(*tp, HIGHFRIENDLY) && i < 5 * eff_charisma))
        {
            turn_on(*tp, ISFRIENDLY);
            turn_off(*tp, ISMEAN);
        }

        i = roll(1,100);

        if (i == 0 || (on(*tp, LOWCAST) && i < eff_intel) ||
            (on(*tp, MEDCAST) && i < 3 * eff_intel) ||
            (on(*tp, HIGHCAST) && i < 5 * eff_intel))
        {
            turn_on(*tp, CANCAST);
        }

        if (on(*tp, ISDISGUISE))
        {
            char    mch = 0;

            if (tp->t_pack != NULL)
                mch = (OBJPTR(tp->t_pack))->o_type;
            else
                switch (rnd(level > arts[0].ar_level ? 10 : 9))
                {
                    case 0: mch = GOLD;     break;
                    case 1: mch = POTION;   break;
                    case 2: mch = SCROLL;   break;
                    case 3: mch = FOOD;     break;
                    case 4: mch = WEAPON;   break;
                    case 5: mch = ARMOR;    break;
                    case 6: mch = RING;     break;
                    case 7: mch = STICK;    break;
                    case 8: mch = monsters[randmonster(NOWANDER, NOGRAB)].m_appear;
                                break;
                    case 9: mch = ARTIFACT; break;
                }

            tp->t_disguise = mch;
        }
    }
}
Example #28
0
void game_manager::init(int w, int h) {
    WINDOW_WIDTH = w;
    WINDOW_HEIGHT = h;

    last_time_ = glutGet(GLUT_ELAPSED_TIME);

    auto frog_ = std::make_shared<frog>();
    frog_->position() = vector3(0.0, FROG_LEVEL, 1.95);
    frog_->scale(0.1);
    game_objects_.push_back(frog_);
    collision_manager::instance().register_object(frog_);

    auto car1_ = std::make_shared<car>();
    car1_->position() = vector3(-1.2, ROAD_LEVEL, LINE_4);
    car1_->scale(0.1);
    car1_->speed().x() = 1.0;
    game_objects_.push_back(car1_);
    collision_manager::instance().register_object(car1_);

    for (int i = 0; i < 3; i++) {
        auto truck_ = std::make_shared<truck>();
        truck_->position() = vector3(-1.5 + i * 1.5, ROAD_LEVEL, LINE_3);
        truck_->scale(0.1);
        truck_->speed().x() = 0.5;
        game_objects_.push_back(truck_);
        collision_manager::instance().register_object(truck_);
    }

    auto bus1_ = std::make_shared<bus>();
    bus1_->position() = vector3(0.9, ROAD_LEVEL, LINE_5);
    bus1_->scale(0.1);
    bus1_->speed().x() = 1.5;
    game_objects_.push_back(bus1_);
    collision_manager::instance().register_object(bus1_);

    auto bus2_ = std::make_shared<bus>();
    bus2_->position() = vector3(-0.1, ROAD_LEVEL, LINE_4);
    bus2_->scale(0.1);
    bus2_->speed().x() = 1.0;
    game_objects_.push_back(bus2_);
    collision_manager::instance().register_object(bus2_);

    for (int i = 0; i < 2; i++) {
        auto log_ = std::make_shared<timberlog>();
        log_->position() = vector3(-0.6 + i * 2.0, RIVER_LEVEL, LINE_1);
        log_->scale(0.1);
        log_->speed().x() = 0.5;
        game_objects_.push_back(log_);
        collision_manager::instance().register_object(log_);

        auto log1_ = std::make_shared<timberlog>();
        log1_->position() = vector3(-1.1 + i * 1.9, RIVER_LEVEL, LINE_2);
        log1_->scale(0.1);
        log1_->speed().x() = 0.75;
        game_objects_.push_back(log1_);
        collision_manager::instance().register_object(log1_);
    }

    for (int i = 0; i < 4; i++) {
        auto turtle_ = std::make_shared<turtle>();
        turtle_->position() =
            vector3(-2.5 + i * 1.3, RIVER_LEVEL + 0.05, LINE_6);
        turtle_->scale(0.1);
        turtle_->speed().x() = 0.75;
        game_objects_.push_back(turtle_);
        collision_manager::instance().register_object(turtle_);
    }

    auto river_ = std::make_shared<river>();
    river_->position() = vector3(0.0, 0.0, LINE_1);
    game_objects_.push_back(river_);
    collision_manager::instance().register_object(river_);

    auto tunnel_ = std::make_shared<tunnel>();
    tunnel_->position() = vector3(0.0, 0.0, LINE_1);
    game_objects_.push_back(tunnel_);

    auto road_ = std::make_shared<road>();
    road_->position() = vector3(0.0, 0.0, LINE_4);
    game_objects_.push_back(road_);

    // INVALID CAMERAS: they will be set correctly on reshape
    // Camera 0: top view orthogonal camera
    cameras_.push_back(std::make_shared<orthogonal_camera>());
    cameras_.back()->eye().set(0.0, 0.0, 0.0);
    cameras_.back()->at().set(0.0, -1.0, 0.0);
    cameras_.back()->up().set(0.0, 0.0, -1.0);

    // Camera 1: top view perspective camera
    cameras_.push_back(std::make_shared<perspective_camera>());
    cameras_.back()->eye().set(0.0, 3.0, 2.0);
    cameras_.back()->at().set(0.0, 0.0, 0.0);
    cameras_.back()->up().set(0.0, 0.0, -1.0);

    // Camera 2: frog perspective camera
    cameras_.push_back(frog_->cam());

    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT0));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT1));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT2));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT3));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT4));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT5));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT6));
    light_sources_.push_back(frog_->headlight());

    auto light = light_sources_[0];
    light->ambient().set(0.2, 0.2, 0.2, 1.0);
    light->diffuse().set(0.3, 0.3, 0.3, 1.0);
    light->position().set(0.0, 5.0, 0.0, 1.0);
    light->turn_on();
    light->toggle_key() = 'n';

    for (size_t i : {1, 2, 3, 4, 5, 6}) {
        light = light_sources_[i];
        light->toggle_key() = 'c';
        light->diffuse().set(0.23, 0.23, 0.23, 1.0);
        light->turn_off();

        light->position().x() = i % 2 == 0 ? 2.0 : -2.0;
        light->direction().x() = -light->position().x() / 2;

        light->position().y() = 1.5;
        light->direction().y() = -light->position().y();

        light->position().z() = -2.0 + 2.0 * ((i - 1) / 2);
        light->direction().z() = -light->position().z() / 2;

        // make positional light
        light->position().w() = 1;
        light->cutoff() = 30;
        light->exponent() = 15;
    }
}
Example #29
0
void GPIOPins::set_state(bool state) {
    if(state) turn_on();
    else turn_off();
}
Example #30
0
void
death(int monst)
{
    char **dp = (char **) rip, *killer;
    struct tm   *lt;
    time_t  date;
    char    buf[80];
	int c;

    if (is_wearing(R_RESURRECT) || rnd(wizard ? 3 : 67) == 0)
    {
        int die = TRUE;

        if (resurrect-- == 0)
            msg("You've run out of lives.");
        else if (!save_resurrect(ring_value(R_RESURRECT)))
            msg("Your attempt to return from the grave fails.");
        else
        {
            struct linked_list  *item;
            struct linked_list  *next_item;
            struct object   *obj;
            int rm, flags;
            coord   pos;

            die = FALSE;
            msg("You feel a sudden warmth and then nothingness.");
            teleport();

            if (ring_value(R_RESURRECT) > 1 && rnd(10))
            {
                pstats.s_hpt = 2 * pstats.s_const;
                pstats.s_const = max(pstats.s_const - 1, 3);
            }
            else
            {
                for (item = pack; item != NULL; item = next_item)
                {
                    obj = OBJPTR(item);

                    if (obj->o_flags & ISOWNED || obj->o_flags & ISPROT)
                    {
                        next_item = next(item);
                        continue;
                    }

                    flags = obj->o_flags;
                    obj->o_flags &= ~ISCURSED;
                    dropcheck(obj);
                    obj->o_flags = flags;
                    next_item = next(item);
                    rem_pack(obj);

                    if (obj->o_type == ARTIFACT)
                        has_artifact &= ~(1 << obj->o_which);

                    do
                    {
                        rm = rnd_room();
                        rnd_pos(&rooms[rm], &pos);
                    }
                    while(winat(pos.y, pos.x) != FLOOR);

                    obj->o_pos = pos;
                    add_obj(item, obj->o_pos.y, obj->o_pos.x);
                }

                pstats.s_hpt = pstats.s_const;
                pstats.s_const = max(pstats.s_const - roll(2, 2), 3);
            }

            chg_str(roll(1, 4), TRUE, FALSE);
            pstats.s_lvl = max(pstats.s_lvl, 1);
            no_command += 2 + rnd(4);

            if (on(player, ISHUH))
                lengthen_fuse(FUSE_UNCONFUSE, rnd(8) + HUHDURATION);
            else
                light_fuse(FUSE_UNCONFUSE, 0, rnd(8) + HUHDURATION, AFTER);

            turn_on(player, ISHUH);
            light(&hero);
        }

        if (die)
        {
            wmove(cw, mpos, 0);
            waddstr(cw, morestr);
            wrefresh(cw);
            wait_for(' ');
        }
        else
            return;
    }

    time(&date);
    lt = localtime(&date);
    clear();
    wclear(cw);
    move(8, 0);

    while (*dp)
        printw("%s\n", *dp++);

    mvaddstr(14, 28 - ((int)(strlen(whoami) + 1) / 2), whoami);
    sprintf(buf, "%d+%ld Points", pstats.s_lvl, pstats.s_exp);
    mvaddstr(15, 28 - ((int)(strlen(buf) + 1) / 2), buf);
    killer = killname(monst,buf);
    mvaddstr(17, 28 - ((int)(strlen(killer) + 1) / 2), killer);
    mvaddstr(18, 28, (sprintf(prbuf, "%2d", lt->tm_year), prbuf));
    move(LINES - 1, 0);

    mvaddstr(LINES - 1, 0, retstr);

    while ((c = readcharw(stdscr)) != '\n' && c != '\r')
        continue;
    idenpack();
    wrefresh(cw);
    refresh();

    score(pstats.s_exp, pstats.s_lvl, KILLED, monst);
    byebye();
}