Exemplo n.º 1
0
void rent_movie()
{
  movie_node_t *node;
  unsigned int movie_id, num_movies = 0;
  char buf[256];

  /* Present the full movie list with index */
  printf("\nMovies (Full)\n--------------\n");
  for (node = movies_full; node != NULL; node = node->next)
  {
    num_movies++;
    node->movie->print_info(num_movies, node->movie);
  }
  printf("--------------\n%d movie(s)\n", num_movies);
  if (num_movies == 0)
  {
    /* Shouldn't really happen with successful init */
    printf("[ERROR] Movie list is empty. Please try again later.\n");
    return;
  }

  /* Get and validate the index */
  while (1)
  {
    printf("Enter movie id: ");
    if (readuntil(STDIN, buf, sizeof(buf), '\n') < 0)
      return;
    movie_id = strtoul(buf, NULL, 10);
    if (movie_id >=1 && movie_id <= num_movies)
      break;
    printf("[ERROR] Invalid movie id. Try again.\n");
  }

  /* Check if the movie isn't rented already */
  movie_node_t *tmp = movie_find_by_id(movies_full, movie_id);
  movie_t *movie = tmp->movie;
  tmp = movie_find(movies_rented, movie->title);
  if (tmp)
  {
    printf("Sorry, [%s] is already rented at this time. Please try again later.\n", tmp->movie->title);
    return;
  }

  /* If not in rental list, insert it into rental list */
  tmp = movie_find_by_id(movies_full, movie_id);
  if (movie_add(&movies_rented, tmp->movie) != 0)
    printf("[ERROR] Failed to rent. Please try again later.\n");
  else
    printf("Successfully rented [%s]! Enjoy!\n", tmp->movie->title);
}
Exemplo n.º 2
0
int movie_add(movie_list_t *list, movie_t *movie)
{
  if (list)
  {
    movie_node_t *node = (movie_node_t *) malloc(sizeof(movie_node_t));
    if (node == NULL)
      return -1;

    if (*list == NULL)
    {
      node->movie = movie;
      node->next = NULL;
      *list = node;
      return 0;
    }

    movie_node_t *tmp = movie_find(*list, movie->title);
    if (tmp)
    {
      if (node) free(node);
      return -1;
    }

    tmp = *list;
    while (1)
    {
      if (tmp->next == NULL) break;
      tmp = tmp->next;
    }

    node->movie = movie;
    node->next = NULL;
    tmp->next = node;
    return 0;
  }
  return -1;
}
Exemplo n.º 3
0
// Play one movie
bool movie_play(char *name)
{
	// mark the movie as viewable to the player when in a campaign
	// do this before anything else so that we're sure the movie is available
	// to the player even if it's not going to play right now
	if (Game_mode & GM_CAMPAIGN_MODE) {
		cutscene_mark_viewable(name);
	}

	extern int Mouse_hidden;
	extern int Is_standalone;

	if (Cmdline_nomovies || Is_standalone)
		return false;


	char full_name[MAX_PATH];
	int rc = 0;

	memset(full_name, 0, sizeof(full_name));

	rc = movie_find(name, full_name);

	if (rc == MOVIE_NONE) {
		strcpy_s(full_name, name);
		char *p = strrchr(full_name, '.');
		if ( p ) *p = 0;

		mprintf(("Movie Error:  Unable to open '%s' movie in any supported format.\n", full_name));
		return false;
	}

	// clear the screen and hide the mouse cursor
	Mouse_hidden++;
	gr_reset_clip();
	gr_set_color(255, 255, 255);
	gr_set_clear_color(0, 0, 0);
	gr_zbuffer_clear(0);
	// clear first buffer
	gr_clear();
	gr_flip();
	// clear second buffer (may not be one, but that's ok)
	gr_clear();
	gr_flip();
	// clear third buffer (may not be one, but that's ok)
	gr_clear();

	if (rc == MOVIE_OGG) {
		THEORAFILE *movie_ogg = theora_open(name);

		if (movie_ogg) {
			// start playing ...
			theora_play(movie_ogg);

			// ... done playing, close the movie
			theora_close(movie_ogg);
		} else {
			// uh-oh, movie is invalid... Abory, Retry, Fail?
			mprintf(("MOVIE ERROR: Found invalid movie! (%s)\n", name));
			Mouse_hidden--;	// show the mouse cursor!
			return false;
		}
	} else if (rc == MOVIE_MVE) {
		MVESTREAM *movie_mve = mve_open(name);

		if (movie_mve) {
			// start playing ...
			mve_init(movie_mve);
			mve_play(movie_mve);

			// ... done playing, close the movie
			mve_shutdown();
			mve_close(movie_mve);
		} else {
			// uh-oh, movie is invalid... Abory, Retry, Fail?
			mprintf(("MOVIE ERROR: Found invalid movie! (%s)\n", name));
			Mouse_hidden--;	// show the mouse cursor!
			return false;
		}
	}

	// show the mouse cursor again
	Mouse_hidden--;

	return true;
}