/* return the actual score added to the total */ int add_score(int delta) { if (score + delta < 0) delta = -score; score += delta; if ((get_stage_number() >= 1) && (get_stage_number() <= 6)) stage_score[get_stage_number() - 1] += delta; while (score >= extend_next) { extend_next += EXTEND_LATER_EVERY; /* you don't get an extra ship if you have already * lost the game, if you have cleared the game or * if you are watching the tutorial demo */ if ((get_ship() >= 0) && (get_stage_number() >= 1) && (get_stage_number() <= 5) && (get_stage_id(get_stage_number()) > 0)) add_ship(1); } return delta; }
int get_transfer_point () { char *temp_ptr; /* Find out if it is a ship or a planet. First try for a correctly spelled ship name. */ temp_ptr = input_line_pointer; correct_spelling_required = TRUE; if (get_ship ()) return TRUE; /* Probably not a ship. See if it's a planet. */ input_line_pointer = temp_ptr; if (get_location ()) return (nampla != NULL); /* Now check for an incorrectly spelled ship name. */ input_line_pointer = temp_ptr; if (get_ship ()) return TRUE; return FALSE; }
int run_game () { RUNNING = 1; ship = get_ship(100,100); stars = get_starfield(); while (RUNNING){ handle_events(); update(); draw(); SDL_Flip(SDL_GetVideoSurface()); SDL_Delay (16); } return 0; }
SHIP_DATA *load_ship( FILE * fp ) { SHIP_DATA *ship = NULL; const char *word; bool fMatch; word = feof( fp ) ? "EndShip" : fread_word( fp ); if( !str_cmp( word, "EndShip" ) ) return NULL; if( !str_cmp( word, "SHIPFNAME" ) ) { const char *name = fread_string_nohash( fp ); /* is this right? - Gavin */ SHIP_DATA *temp_ship = NULL; for( temp_ship = first_ship; temp_ship; temp_ship = temp_ship->next ) { if( !str_cmp( name, temp_ship->filename ) ) { ship = temp_ship; break; } } if( ship == NULL ) { bug( "%s: No ship data for filename %s", __FUNCTION__, name ); DISPOSE( name ); return NULL; for( ;; ) { word = feof( fp ) ? "EndShip" : fread_word( fp ); if( !str_cmp( word, "EndShip" ) ) break; } } DISPOSE( name ); } else { for( ;; ) { word = feof( fp ) ? "EndShip" : fread_word( fp ); if( !str_cmp( word, "EndShip" ) ) break; } bug( "%s: shipfname not found", __FUNCTION__ ); return NULL; } for( ;; ) { word = feof( fp ) ? "EndShip" : fread_word( fp ); fMatch = FALSE; switch ( UPPER( word[0] ) ) { case '*': fMatch = TRUE; fread_to_eol( fp ); break; /* * case '#': * if ( !str_cmp( word, "#TORPEDO" ) ) * { * mob->tempnum = -9999; * fread_obj( mob, fp, OS_CARRY ); * } * break; */ case 'A': KEY( "Autorecharge", ship->autorecharge, ( bool ) fread_number( fp ) ); KEY( "Autotrack", ship->autotrack, ( bool ) fread_number( fp ) ); KEY( "Autospeed", ship->autospeed, ( bool ) fread_number( fp ) ); KEY( "Autopilot", ship->autopilot, ( bool ) fread_number( fp ) ); break; case 'C': KEY( "Currspeed", ship->currspeed, fread_number( fp ) ); if( !str_cmp( word, "Currjump" ) ) { const char *temp = fread_string_nohash( fp ); extract_ship( ship ); ship->location = 0; ship->currjump = starsystem_from_name( temp ); DISPOSE( temp ); fMatch = TRUE; break; } KEY( "Chaff", ship->chaff, fread_number( fp ) ); break; case 'E': KEY( "Energy", ship->energy, fread_number( fp ) ); if( !str_cmp( word, "EndShip" ) ) { return ship; } if( !str_cmp( word, "End" ) ) /* End of object, need to ignore this. sometimes they creep in there somehow -- Scion */ fMatch = TRUE; /* Trick the system into thinking it matched something */ break; case 'H': KEY( "Hull", ship->hull, fread_number( fp ) ); KEY( "HX", ship->hx, ( float )fread_number( fp ) ); KEY( "HY", ship->hy, ( float )fread_number( fp ) ); KEY( "HZ", ship->hz, ( float )fread_number( fp ) ); KEY( "Hyperdistance", ship->hyperdistance, fread_number( fp ) ); break; case 'J': KEY( "JX", ship->jx, ( float )fread_number( fp ) ); KEY( "JY", ship->jy, ( float )fread_number( fp ) ); KEY( "JZ", ship->jz, ( float )fread_number( fp ) ); break; case 'L': if( !str_cmp( word, "Landdest" ) ) { STRFREE( ship->dest ); ship->dest = fread_string( fp ); fMatch = TRUE; break; } break; case 'M': KEY( "Missiles", ship->missiles, fread_number( fp ) ); break; case 'R': KEY( "Rockets", ship->rockets, fread_number( fp ) ); break; case 'S': KEY( "Shield", ship->shield, fread_number( fp ) ); KEY( "Shipstate", ship->shipstate, fread_number( fp ) ); if( !str_cmp( word, "Starsystem" ) ) { const char *star_name = fread_string_nohash( fp ); SPACE_DATA *starsystem = starsystem_from_name( star_name ); DISPOSE( star_name ); fMatch = TRUE; extract_ship( ship ); ship->location = 0; if( ship->starsystem ) ship_from_starsystem( ship, starsystem ); ship_to_starsystem( ship, starsystem ); break; } break; case 'T': KEY( "Torpedos", ship->torpedos, fread_number( fp ) ); if( !str_cmp( word, "target0" ) ) { const char *temp = fread_string( fp ); SHIP_DATA *target = get_ship( temp ); ship->target0 = target; STRFREE( temp ); fMatch = TRUE; break; } if( !str_cmp( word, "target1" ) ) { const char *temp = fread_string( fp ); SHIP_DATA *target = get_ship( temp ); ship->target1 = target; STRFREE( temp ); fMatch = TRUE; break; } if( !str_cmp( word, "target2" ) ) { const char *temp = fread_string( fp ); SHIP_DATA *target = get_ship( temp ); ship->target2 = target; STRFREE( temp ); fMatch = TRUE; break; } break; case 'V': KEY( "VX", ship->vx, ( float )fread_number( fp ) ); KEY( "VY", ship->vy, ( float )fread_number( fp ) ); KEY( "VZ", ship->vz, ( float )fread_number( fp ) ); break; } if( !fMatch && str_cmp( word, "End" ) ) bug( "%s: no match: %s", __FUNCTION__, word ); } return NULL; }
void do_shiphail( CHAR_DATA *ch, char *argument ) { SHIP_DATA *ship; SHIP_DATA *ship2 = ship_from_cockpit( ch->in_room->vnum ); int count; int top_num=15; int vnum[top_num]; DESCRIPTOR_DATA *i; CHAR_DATA *och; char buf[MAX_STRING_LENGTH]; char buf1[MAX_STRING_LENGTH]; char arg1[MAX_INPUT_LENGTH]; char arg2[MAX_INPUT_LENGTH]; argument = one_argument( argument, arg1 ); strcpy(arg2,argument); if(IS_NPC(ch)) return; if (arg1[0] == '\0' || arg2[0] == '\0') { send_to_char ("Syntax: Hail <ship> <message>\n\r", ch); return; } ship = get_ship( arg1 ); send_to_char ("\n\r", ch); if (!ship) { send_to_char ("No Such Ship!\n\r", ch); return; } if (!ship2) { send_to_char("But your not in a cockpit!\n\r", ch); return; } if ( !IS_NPC(ch) && ( IS_SET (ch->act, PLR_SILENCE ) ) ) { send_to_char("You can't do this while silenced!\n\r", ch); return; } sprintf (buf, "&B(&YShip Hail&B) &G&W%s: %s\n\r", ship2->name, arg2); sprintf (buf1, "&g%s adjusts some settings on the comm system and says something", ch->name, arg2); act( AT_GREEN, buf1, ch, NULL, NULL, TO_NOTVICT ); sprintf (buf1, "&B(&YShip Hail&B) &G&WYou: %s\n\r", arg2); act(AT_PLAIN, buf1, ch, NULL, NULL, TO_CHAR); act(AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM); /* vnum[0] = ship->cockpit; vnum[1] = ship->pilotseat; vnum[2] = ship->gunseat; vnum[3] = ship->coseat; vnum[4] = ship->navseat; vnum[5] = ship->turret1; vnum[6] = ship->turret2; for (i = first_descriptor; i; i = i->next) { if (!i->connected && i->character) { och = i->original ? i->original : i->character; } for( count=1; count <= top_num; count = count + 1 ) { if (och->in_room->vnum == vnum[count] && och->desc) { send_to_char(buf, och); break; } } } */ int highroom = 0, lowroom = 0; if(ship->firstroom <= 0 || ship->lastroom <= 0) { send_to_char("Contact Immoortal Staff, Hail target ship has vnum range problem.\r\n", ch); return; } highroom = ship->firstroom; lowroom = ship->lastroom; for(highroom; highroom <= lowroom; highroom++) { echo_to_room(AT_PLAIN, get_room_index(highroom), buf); } }
do_LAND_command () { int i, n, found, siege_effectiveness, landing_detected, landed, alien_number, alien_index, alien_pn, array_index, bit_number, requested_alien_landing, alien_here, already_logged; long bit_mask; char *original_line_pointer; struct species_data *alien; struct nampla_data *alien_nampla; /* Get the ship. */ original_line_pointer = input_line_pointer; found = get_ship (); if (! found) { /* Check for missing comma or tab after ship name. */ input_line_pointer = original_line_pointer; fix_separator (); found = get_ship (); if (! found) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Invalid ship name in LAND command.\n"); return; } } /* Make sure the ship is not a starbase. */ if (ship->type == STARBASE) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! A starbase cannot land on a planet!\n"); return; } if (ship->status == UNDER_CONSTRUCTION) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Ship is still under construction.\n"); return; } if (ship->status == FORCED_JUMP || ship->status == JUMPED_IN_COMBAT) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Ship jumped during combat and is still in transit.\n"); return; } /* Get the planet number, if specified. */ found = get_value (); get_planet: alien_pn = 0; alien_here = FALSE; requested_alien_landing = FALSE; landed = FALSE; if (! found) { found = get_location (); if (! found || nampla == NULL) found = FALSE; } else { /* Check if we or another species that has declared us ALLY has a colony on this planet. */ found = FALSE; alien_pn = value; requested_alien_landing = TRUE; array_index = (species_number - 1) / 32; bit_number = (species_number - 1) % 32; bit_mask = 1 << bit_number; for (alien_index = 0; alien_index < galaxy.num_species; alien_index++) { if (! data_in_memory[alien_index]) continue; alien = &spec_data[alien_index]; alien_nampla = namp_data[alien_index] - 1; for (i = 0; i < alien->num_namplas; i++) { ++alien_nampla; if (ship->x != alien_nampla->x) continue; if (ship->y != alien_nampla->y) continue; if (ship->z != alien_nampla->z) continue; if (alien_pn != alien_nampla->pn) continue; if ((alien_nampla->status & POPULATED) == 0) continue; if (alien_index == species_number - 1) { /* We have a colony here. No permission needed. */ nampla = alien_nampla; found = TRUE; alien_here = FALSE; requested_alien_landing = FALSE; goto finish_up; } alien_here = TRUE; if ((alien->ally[array_index] & bit_mask) == 0) continue; found = TRUE; break; } if (found) break; } } finish_up: already_logged = FALSE; if (requested_alien_landing && alien_here) { /* Notify the other alien(s). */ landed = found; for (alien_index = 0; alien_index < galaxy.num_species; alien_index++) { if (! data_in_memory[alien_index]) continue; if (alien_index == species_number - 1) continue; alien = &spec_data[alien_index]; alien_nampla = namp_data[alien_index] - 1; for (i = 0; i < alien->num_namplas; i++) { ++alien_nampla; if (ship->x != alien_nampla->x) continue; if (ship->y != alien_nampla->y) continue; if (ship->z != alien_nampla->z) continue; if (alien_pn != alien_nampla->pn) continue; if ((alien_nampla->status & POPULATED) == 0) continue; if ((alien->ally[array_index] & bit_mask) != 0) found = TRUE; else found = FALSE; if (landed && ! found) continue; if (landed) log_string (" "); else log_string ("!!! "); log_string (ship_name (ship)); if (landed) log_string (" was granted"); else log_string (" was denied"); log_string (" permission to land on PL "); log_string (alien_nampla->name); log_string (" by SP "); log_string (alien->name); log_string (".\n"); already_logged = TRUE; nampla = alien_nampla; if (first_pass) break; /* Define a 'landing request' transaction. */ if (num_transactions == MAX_TRANSACTIONS) { fprintf (stderr, "\n\n\tERROR! num_transactions > MAX_TRANSACTIONS!\n\n"); exit (-1); } n = num_transactions++; transaction[n].type = LANDING_REQUEST; transaction[n].value = landed; transaction[n].number1 = alien_index + 1; strcpy (transaction[n].name1, alien_nampla->name); strcpy (transaction[n].name2, ship_name(ship)); strcpy (transaction[n].name3, species->name); break; } } found = TRUE; } if (alien_here && ! landed) return; if (! found) { if ((ship->status == IN_ORBIT || ship->status == ON_SURFACE) && ! requested_alien_landing) { /* Player forgot to specify planet. Use the one it's already at. */ value = ship->pn; found = TRUE; goto get_planet; } fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Invalid or missing planet in LAND command.\n"); return; } /* Make sure the ship and the planet are in the same star system. */ if (ship->x != nampla->x || ship->y != nampla->y || ship->z != nampla->z) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Ship and planet are not in the same sector.\n"); return; } /* Make sure planet is populated. */ if ((nampla->status & POPULATED) == 0) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Planet in LAND command is not populated.\n"); return; } /* Move the ship. */ ship->pn = nampla->pn; ship->status = ON_SURFACE; if (already_logged) return; /* If the planet is under siege, the landing may be detected by the besiegers. */ log_string (" "); log_string (ship_name (ship)); if (nampla->siege_eff != 0) { if (first_pass) { log_string (" will attempt to land on PL "); log_string (nampla->name); log_string (" in spite of the siege"); } else { if (nampla->siege_eff < 0) siege_effectiveness = -nampla->siege_eff; else siege_effectiveness = nampla->siege_eff; landing_detected = FALSE; if (rnd(100) <= siege_effectiveness) { landing_detected = TRUE; for (i = 0; i < num_transactions; i++) { /* Find out who is besieging this planet. */ if (transaction[i].type != BESIEGE_PLANET) continue; if (transaction[i].x != nampla->x) continue; if (transaction[i].y != nampla->y) continue; if (transaction[i].z != nampla->z) continue; if (transaction[i].pn != nampla->pn) continue; if (transaction[i].number2 != species_number) continue; alien_number = transaction[i].number1; /* Define a 'detection' transaction. */ if (num_transactions == MAX_TRANSACTIONS) { fprintf (stderr, "\n\n\tERROR! num_transactions > MAX_TRANSACTIONS!\n\n"); exit (-1); } n = num_transactions++; transaction[n].type = DETECTION_DURING_SIEGE; transaction[n].value = 1; /* Landing. */ strcpy (transaction[n].name1, nampla->name); strcpy (transaction[n].name2, ship_name(ship)); strcpy (transaction[n].name3, species->name); transaction[n].number3 = alien_number; } } if (rnd(100) <= siege_effectiveness) { /* Ship doesn't know if it was detected. */ log_string (" may have been detected by the besiegers when it landed on PL "); log_string (nampla->name); } else { /* Ship knows whether or not it was detected. */ if (landing_detected) { log_string (" was detected by the besiegers when it landed on PL "); log_string (nampla->name); } else { log_string (" landed on PL "); log_string (nampla->name); log_string (" without being detected by the besiegers"); } } } } else { if (first_pass) log_string (" will land on PL "); else log_string (" landed on PL "); log_string (nampla->name); } log_string (".\n"); }
do_ORBIT_command () { int i, found, specified_planet_number; char *original_line_pointer; /* Get the ship. */ original_line_pointer = input_line_pointer; found = get_ship (); if (! found) { /* Check for missing comma or tab after ship name. */ input_line_pointer = original_line_pointer; fix_separator (); found = get_ship (); if (! found) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Invalid ship name in ORBIT command.\n"); return; } } if (ship->status == UNDER_CONSTRUCTION) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Ship is still under construction.\n"); return; } if (ship->status == FORCED_JUMP || ship->status == JUMPED_IN_COMBAT) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Ship jumped during combat and is still in transit.\n"); return; } /* Make sure this ship didn't just arrive via a MOVE command. */ if (ship->just_jumped == 50) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! ORBIT not allowed immediately after a MOVE!\n"); return; } /* Make sure ship is not salvage of a disbanded colony. */ if (disbanded_ship (ship)) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! This ship is salvage of a disbanded colony!\n"); return; } /* Get the planet. */ specified_planet_number = get_value (); get_planet: if (specified_planet_number) { found = FALSE; specified_planet_number = value; for (i = 0; i < num_stars; i++) { star = star_base + i; if (star->x != ship->x) continue; if (star->y != ship->y) continue; if (star->z != ship->z) continue; if (specified_planet_number >= 1 && specified_planet_number <= star->num_planets) found = TRUE; break; } if (! found) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Invalid planet in ORBIT command.\n"); return; } ship->pn = specified_planet_number; goto finish_up; } found = get_location (); if (! found || nampla == NULL) { if (ship->status == IN_ORBIT || ship->status == ON_SURFACE) { /* Player forgot to specify planet. Use the one it's already at. */ specified_planet_number = ship->pn; value = specified_planet_number; goto get_planet; } fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Invalid or missing planet in ORBIT command.\n"); return; } /* Make sure the ship and the planet are in the same star system. */ if (ship->x != nampla->x || ship->y != nampla->y || ship->z != nampla->z) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Ship and planet are not in the same sector.\n"); return; } /* Move the ship. */ ship->pn = nampla->pn; finish_up: ship->status = IN_ORBIT; /* If a planet number is being used, see if it has a name. If so, use the name. */ if (specified_planet_number) { for (i = 0; i < species->num_namplas; i++) { nampla = nampla_base + i; if (nampla->x != ship->x) continue; if (nampla->y != ship->y) continue; if (nampla->z != ship->z) continue; if (nampla->pn != specified_planet_number) continue; specified_planet_number = 0; break; } } /* Log result. */ log_string (" "); log_string (ship_name (ship)); if (first_pass) log_string (" will enter orbit around "); else log_string (" entered orbit around "); if (specified_planet_number) { log_string ("planet number "); log_int (specified_planet_number); } else { log_string ("PL "); log_string (nampla->name); } log_string (".\n"); }
do_DEEP_command () { int i, found; char *original_line_pointer; /* Get the ship. */ original_line_pointer = input_line_pointer; found = get_ship (); if (! found) { /* Check for missing comma or tab after ship name. */ input_line_pointer = original_line_pointer; fix_separator (); found = get_ship (); if (! found) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Invalid ship name in ORBIT command.\n"); return; } } if (ship->type == STARBASE) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! DEEP order may not be given for a starbase.\n"); return; } if (ship->status == UNDER_CONSTRUCTION) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Ship is still under construction.\n"); return; } if (ship->status == FORCED_JUMP || ship->status == JUMPED_IN_COMBAT) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! Ship jumped during combat and is still in transit.\n"); return; } /* Make sure ship is not salvage of a disbanded colony. */ if (disbanded_ship (ship)) { fprintf (log_file, "!!! Order ignored:\n"); fprintf (log_file, "!!! %s", original_line); fprintf (log_file, "!!! This ship is salvage of a disbanded colony!\n"); return; } /* Move the ship. */ ship->pn = 0; ship->status = IN_DEEP_SPACE; /* Log result. */ log_string (" "); log_string (ship_name (ship)); log_string (" moved into deep space.\n"); }