Exemple #1
0
static void test_fishing_feeds_2_people(CuTest * tc)
{
    const resource_type *rtype;
    region *r;
    faction *f;
    unit *u;
    ship *sh;
    
    test_cleanup();
    test_create_world();
    r = findregion(-1, 0);
    CuAssertStrEquals(tc, "ocean", r->terrain->_name);    /* test_create_world needs coverage */
    f = test_create_faction(rc_find("human"));
    u = test_create_unit(f, r);
    sh = new_ship(st_find("boat"), r, 0);
    u_set_ship(u, sh);
    rtype = get_resourcetype(R_SILVER);
    i_change(&u->items, rtype->itype, 42);
    
    scale_number(u, 1);
    sh->flags |= SF_FISHING;
    get_food(r);
    CuAssertIntEquals(tc, 42, i_get(u->items, rtype->itype));

    scale_number(u, 2);
    sh->flags |= SF_FISHING;
    get_food(r);
    CuAssertIntEquals(tc, 42, i_get(u->items, rtype->itype));

    scale_number(u, 3);
    sh->flags |= SF_FISHING;
    get_food(r);
    CuAssertIntEquals(tc, 32, i_get(u->items, rtype->itype));
}
Exemple #2
0
ENTRYPOINT void init_commander(ModeInfo *mi) 
{
  commander_conf *cp;
	int i;
	int do_which = -1;

  if(!commander) {
    commander = (commander_conf *)calloc(MI_NUM_SCREENS(mi), sizeof(commander_conf));
    if(!commander) return;
  }
  cp = &commander[MI_SCREEN(mi)];

  if ((cp->glx_context = init_GL(mi)) != NULL) {
    init_gl(mi);
    cp->which = -1;
    reshape_commander(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  } else {
    MI_CLEARWINDOW(mi);
  }

  {
    double spin_speed = 0.7 * speed;
    double spin_accel = 0.1 * speed;

    cp->rot = make_rotator (spin_speed, spin_speed, spin_speed,
                            spin_accel, 0, True);
    cp->trackball = gltrackball_init (True);
  }

	/* figure out which ship to display */

	/* do_which=-1 for "random" mode */
	if(!strcasecmp (do_which_str, "random"))
		;
	else {
		for(i=0;i<NUM_ELEM(ship_names);i++) {
			if(!strcasecmp(do_which_str, ship_names[i])) {
					do_which=i;
					cp->which=i;
			}
		}
		if(do_which<0) {
			fprintf(stderr, "%s: no such ship: \"%s\"\n",
					progname, do_which_str);
			exit(1);
		}
	}

	/* FIXME (what?) */
	if(do_which==-1) {
		cp->which=random() % NUM_ELEM(ship_names);
	}

	new_ship(mi);

}
Exemple #3
0
game* new_game(point *s) {
    game *g = calloc(1, sizeof(game));
    g->Ship = new_ship(p_times(s, 0.5));
    g->Size = s;
    g->status = Pause;
    g->score = 0;

    int i;
    for(i = 0; i <= ASTEROID_COUNT; i++)
        new_asteroid(ASTEROID_MAX_LVL);
    
    return g;
}
Exemple #4
0
void
create_ship(region * r, unit * u, const struct ship_type *newtype, int want,
order * ord)
{
    ship *sh;
    int msize;
    const construction *cons = newtype->construction;
    order *new_order;

    if (!eff_skill(u, SK_SHIPBUILDING, r)) {
        cmistake(u, ord, 100, MSG_PRODUCE);
        return;
    }
    if (besieged(u)) {
        cmistake(u, ord, 60, MSG_PRODUCE);
        return;
    }

    /* check if skill and material for 1 size is available */
    if (eff_skill(u, cons->skill, r) < cons->minskill) {
        ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder,
            "error_build_skill_low", "value", cons->minskill));
        return;
    }

    msize = maxbuild(u, cons);
    if (msize == 0) {
        cmistake(u, ord, 88, MSG_PRODUCE);
        return;
    }
    if (want > 0)
        want = _min(want, msize);
    else
        want = msize;

    sh = new_ship(newtype, r, u->faction->locale);

    if (leave(u, false)) {
        if (fval(u_race(u), RCF_CANSAIL)) {
            u_set_ship(u, sh);
        }
    }
    new_order =
        create_order(K_MAKE, u->faction->locale, "%s %i", LOC(u->faction->locale,
        parameters[P_SHIP]), sh->no);
    replace_order(&u->orders, ord, new_order);
    free_order(new_order);

    build_ship(u, sh, want);
}
Exemple #5
0
static int tolua_ship_create(lua_State * L)
{
    region *r = (region *)tolua_tousertype(L, 1, 0);
    const char *sname = tolua_tostring(L, 2, 0);
    if (sname) {
        const ship_type *stype = st_find(sname);
        if (stype) {
            ship *sh = new_ship(stype, r, default_locale);
            sh->size = stype->construction ? stype->construction->maxsize : 1;
            tolua_pushusertype(L, (void *)sh, TOLUA_CAST "ship");
            return 1;
        }
        else {
            log_error("Unknown ship type '%s'\n", sname);
        }
    }
    return 0;
}
Exemple #6
0
static void equip_newunits(const struct equipment *eq, struct unit *u)
{
    struct region *r = u->region;
    const struct resource_type *rtype;
    switch (old_race(u_race(u))) {
    case RC_ELF:
        rtype = rt_find("fairyboot");
        set_show_item(u->faction, rtype->itype);
        break;
    case RC_GOBLIN:
        rtype = rt_find("roi");
        set_show_item(u->faction, rtype->itype);
        set_number(u, 10);
    break;
    case RC_HUMAN:
        if (u->building == NULL) {
            const building_type *btype = bt_find("castle");
            if (btype != NULL) {
                building *b = new_building(btype, r, u->faction->locale);
                b->size = 10;
                u_set_building(u, b);
                building_set_owner(u);
            }
        }
        break;
    case RC_CAT:
        rtype = rt_find("roi");
        set_show_item(u->faction, rtype->itype);
        break;
    case RC_AQUARIAN:
        {
            ship *sh = new_ship(st_find("boat"), r, u->faction->locale);
            sh->size = sh->type->construction->maxsize;
            u_set_ship(u, sh);
        }
        break;
    case RC_CENTAUR:
        rsethorses(r, 250 + rng_int() % 51 + rng_int() % 51);
        break;
    default:
        break;
  }
}
Exemple #7
0
ship * test_create_ship(region * r, const ship_type * stype)
{
  ship * s = new_ship(stype?stype:st_find("boat"), r, default_locale);
  s->size = s->type->construction?s->type->construction->maxsize:1;
  return s;
}
Exemple #8
0
int main(int argc, char **argv)
{
  ALLEGRO_DISPLAY *display = NULL;
  ALLEGRO_EVENT_QUEUE *event_queue = NULL;
  ALLEGRO_TIMER *timer = NULL;
  ALLEGRO_FONT *font_arial_36 = NULL;
  ALLEGRO_FONT *font_arial_24 = NULL;
  ALLEGRO_TRANSFORM transform;
  bool key[6] = { false, false, false, false, false, true };
  bool redraw = true;
  bool doexit = false;
  char display_score[20];
  char display_lives[20];
  char display_ammo[20];
  char display_countdown[20];
  int ammo = 99;

  if(!al_init()) {
    fprintf(stderr, "failed to initialize allegro!\n");
    return -1;
  }

  al_init_font_addon();
  if (!al_init_ttf_addon()) {
    fprintf(stderr, "failed to initialize ttf addon!\n");
    return -1;
  }

  if(!al_install_keyboard()) {
    fprintf(stderr, "failed to initialize the keyboard!\n");
    return -1;
  }

  timer = al_create_timer(1.0 / FPS);
  if(!timer) {
    fprintf(stderr, "failed to create timer!\n");
    return -1;
  }

  display = al_create_display(SCREEN_W, SCREEN_H);
  if(!display) {
    fprintf(stderr, "failed to create display!\n");
    al_destroy_timer(timer);
    return -1;
  }

  event_queue = al_create_event_queue();
    if(!event_queue) {
      fprintf(stderr, "failed to create event_queue!\n");
      al_destroy_display(display);
      al_destroy_timer(timer);
      return -1;
    }

  font_arial_36 = al_load_ttf_font("arial.ttf", 36, 0);
  if (!font_arial_36){
    fprintf(stderr, "arial 36 not loaded!\n" );
    return -1;
  }

  font_arial_24 = al_load_ttf_font("arial.ttf", 24, 0);
  if (!font_arial_36){
    fprintf(stderr, "arial 24 not loaded!\n" );
    return -1;
  }

  al_init_primitives_addon();

  al_register_event_source(event_queue, al_get_display_event_source(display));
  al_register_event_source(event_queue, al_get_timer_event_source(timer));
  al_register_event_source(event_queue, al_get_keyboard_event_source());

  /* Start game */
  Spaceship* ship = new_ship();
  last = make_roids(ROIDS);
  Blast **blasts = new_blasts();
  
  int countdown = 10;
  while(countdown && !DEBUG_MODE) {
    al_clear_to_color(al_map_rgb(0,0,0));
    /* Welcome - Ugly code, write nicer function. */
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_36, 
                 al_map_rgb(255,0,0), 
                 SCREEN_W/2, 
                 100,
                 ALLEGRO_ALIGN_CENTRE, 
                 "Welcome to Casper's BLASTEROIDS!");
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 150,
                 ALLEGRO_ALIGN_CENTRE, 
                 "You got three lives, 100 shots and a lot of asteroids to blast.");
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 170,
                 ALLEGRO_ALIGN_CENTRE, 
                 "Fire with space, steer with the arrow keys and hit escape");
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 190,
                 ALLEGRO_ALIGN_CENTRE, 
                 "if you don't dare to play to the end...");
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 230,
                 ALLEGRO_ALIGN_CENTRE, 
                 "(If you get hit by and asteroid, you will die,"); 
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 250,
                 ALLEGRO_ALIGN_CENTRE, 
                 "the first five seconds of a new life, they won't hurt you.)");
    sprintf(display_countdown, "%d", countdown);
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 300,
                 ALLEGRO_ALIGN_CENTRE, 
                 display_countdown);

    al_flip_display();
    sleep(1);
    countdown--;
  }

  al_start_timer(timer);

  while(!doexit) {
    ALLEGRO_EVENT ev;
    al_wait_for_event(event_queue, &ev);
    if(ev.type == ALLEGRO_EVENT_TIMER) {
      redraw = true;
      if(ship->timer > 0)
      ship->timer--;
    }

    else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
      break;
    }

    else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) {
      switch(ev.keyboard.keycode) {
        case ALLEGRO_KEY_K:
        case ALLEGRO_KEY_UP:
          key[KEY_UP] = true;
          move_ship(ship, KEY_UP);
          break;
        case ALLEGRO_KEY_J:
        case ALLEGRO_KEY_DOWN:
          key[KEY_DOWN] = true;
          move_ship(ship, KEY_DOWN);
          break;
        case ALLEGRO_KEY_H:
        case ALLEGRO_KEY_LEFT:
          key[KEY_LEFT] = true;
          move_ship(ship, KEY_LEFT);
          break;
        case ALLEGRO_KEY_L:
        case ALLEGRO_KEY_RIGHT:
          key[KEY_RIGHT] = true;
          move_ship(ship, KEY_RIGHT);
          break;
        case ALLEGRO_KEY_SPACE:
          key[KEY_SPACE] = true;
          if (ammo>0) {
            shoot_blast(blasts[ammo], ship);
            ammo--;
          }
          break;
        case ALLEGRO_KEY_ESCAPE:
          doexit = true;
          break;
      }
    }

    if(redraw && al_is_event_queue_empty(event_queue)) {
      redraw = false;
      al_clear_to_color(al_map_rgb(0,0,0));

      move_ship(ship, NONE);
      draw_ship(ship);

      move_blasts(blasts);
      draw_blasts(blasts);

      check_collision(last, ship, blasts);

      move_roids(last);
      draw_roids(last);

      if(!ship->lives || !ammo) {
        /* Game over. */
        al_identity_transform(&transform);
        al_use_transform(&transform);
        al_draw_text(font_arial_36, 
                     al_map_rgb(200,200,200), 
                     SCREEN_W/2, 
                     SCREEN_H/2-100, 
                     ALLEGRO_ALIGN_CENTRE, 
                     "GAME OVER");
        doexit = "true";
      }

      if(!ROIDS_ALIVE) {
        /* You Won. */
        al_identity_transform(&transform);
        al_use_transform(&transform);
        al_draw_text(font_arial_36, 
                     al_map_rgb(200,200,200), 
                     SCREEN_W/2, 
                     SCREEN_H/2-100, 
                     ALLEGRO_ALIGN_CENTRE, 
                     "YOU WON");
        doexit = "true";
      }

      /* Score */
      al_identity_transform(&transform);
      al_use_transform(&transform);

      sprintf(display_score, "%d", score);
      al_draw_text(font_arial_24, 
                   al_map_rgb(200,200,200), 
                   50, 
                   10, 
                   ALLEGRO_ALIGN_CENTRE, 
                   display_score);
      /* Lives */
      sprintf(display_lives, "%d", ship->lives);
      al_draw_text(font_arial_24, 
                   al_map_rgb(200,200,200), 
                   SCREEN_W-50, 
                   10, 
                   ALLEGRO_ALIGN_CENTRE, 
                   display_lives);
      /* Ammo */
      al_identity_transform(&transform);
      al_use_transform(&transform);

      sprintf(display_ammo, "%d", ammo);
      al_draw_text(font_arial_24, 
                   al_map_rgb(200,200,200), 
                   50, 
                   SCREEN_H-50,
                   ALLEGRO_ALIGN_CENTRE, 
                   display_ammo);

      al_flip_display();
      if (doexit)
        sleep(3);
    }
  }

  destroy_ship(ship);
  destroy_roids(last);
  destroy_blasts(blasts);

  /* End game. */

  al_shutdown_primitives_addon();
  al_destroy_timer(timer);
  al_destroy_display(display);
  al_destroy_event_queue(event_queue);

  return 0;
}