Skip to content

Commit

Permalink
Improved spacerace, based partly on a patch by
Browse files Browse the repository at this point in the history
Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>.
New/changed features:
- Travel time, success chance etc are implemented, based on
  reverse-engineered Civ1; you can now only launch a spaceship
  if it is "viable".
- Only parts of the spacehip connnected to structurals count.
- The protocol is such that the player could choose which
  type of module to build (like in Civ1), but currently the
  client makes this choice.  That is, fixing this further
  should require changes to the client only.
- Better handling of spaceships arriving in the same turn.
- An arrived spaceship adds to your final score.  But I
  don't know what the score bonus should be; for now, I
  chose an arbitrary bonus.
- Capturing a player's capital stops that player's spaceship.
- There is some help about spaceships and spaceship parts.
The capability string now has "+spacerace2".
There are still problems if you launch in BC years.

[[originally from CVS; cvs2svn created svn r1041]]
  • Loading branch information
David Pfitzner committed Feb 16, 1999
1 parent fd56cef commit 334262d
Show file tree
Hide file tree
Showing 29 changed files with 1,259 additions and 241 deletions.
11 changes: 7 additions & 4 deletions client/Freeciv.h
Expand Up @@ -1024,10 +1024,13 @@ Out = Output window, Mes = Messages window, Pop = Popup individual window ",
"Freeciv*spaceshipimagecanvas.left: chainLeft",
"Freeciv*spaceshipimagecanvas.right: chainLeft",
"Freeciv*spaceshipinfolabel.label: \
Structurals: 111\\n\
Components: 111\\n\
Modules: 111\\n\
Year of arrival: 5000",
Population: 1234\\n\
Support: 100 %\\n\
Energy: 100 %\\n\
Mass: 12345 tons\\n\
Travel time: 1234 years\\n\
Success prob.: 100 %\\n\
Year of arrival: 1234",
"Freeciv*spaceshipinfolabel.fromVert: spaceshipimagecanvas",
"Freeciv*spaceshipclosecommand.label: Close",
"Freeciv*spaceshipclosecommand.fromVert: spaceshipinfolabel",
Expand Down
4 changes: 4 additions & 0 deletions client/civclient.c
Expand Up @@ -245,6 +245,10 @@ void handle_packet_input(char *packet, int type)
handle_city_options((struct packet_generic_values *)packet);
break;

case PACKET_SPACESHIP_INFO:
handle_spaceship_info((struct packet_spaceship_info *)packet);
break;

default:
freelog(LOG_FATAL, "Received unknown packet from server!");
exit(1);
Expand Down
183 changes: 176 additions & 7 deletions client/packhand.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include <packets.h>
#include <climisc.h>
Expand All @@ -24,6 +25,8 @@
#include <clinet.h> /* aconnection */
#include <capability.h>
#include <helpdlg.h> /* boot_help_texts */
#include <spaceship.h>
#include <spaceshipdlg.h>

extern int seconds_to_turndone;
extern int turn_gold_difference;
Expand Down Expand Up @@ -624,13 +627,6 @@ void handle_player_info(struct packet_player_info *pinfo)
pplayer->future_tech=pinfo->future_tech;
pplayer->ai.tech_goal=pinfo->tech_goal;

pplayer->spaceship.structurals=pinfo->structurals;
pplayer->spaceship.components=pinfo->components;
pplayer->spaceship.modules=pinfo->modules;
pplayer->spaceship.state=pinfo->sship_state;
pplayer->spaceship.arrival_year=pinfo->arrival_year;


if(!pplayer->conn){
/* It is only the client that does this */

Expand Down Expand Up @@ -684,6 +680,179 @@ void handle_player_info(struct packet_player_info *pinfo)
}
}

/**************************************************************************
Ideally the client should let the player choose which type of
modules and components to build, and (possibly) where to extend
structurals. The protocol now makes this possible, but the
client is not yet that good (would require GUI improvements)
so currently the client choices stuff automatically if there
is anything unplaced.
This function makes a choice (sends spaceship_action) and
returns 1 if we placed something, else 0.
Do things one at a time; the server will send us an updated
spaceship_info packet, and we'll be back here to do anything
which is left.
**************************************************************************/
int spaceship_autoplace(struct player_spaceship *ship)
{
struct packet_spaceship_action packet;
int i;

if (ship->modules > (ship->habitation + ship->life_support
+ ship->solar_panels)) {
if (ship->habitation==0) {
packet.action = SSHIP_ACT_PLACE_HABITATION;
packet.num = ship->habitation + 1;
} else if (ship->life_support==0) {
packet.action = SSHIP_ACT_PLACE_LIFE_SUPPORT;
packet.num = ship->life_support + 1;
} else if (ship->solar_panels==0) {
packet.action = SSHIP_ACT_PLACE_SOLAR_PANELS;
packet.num = ship->solar_panels + 1;
} else if (ship->life_support < ship->habitation) {
packet.action = SSHIP_ACT_PLACE_LIFE_SUPPORT;
packet.num = ship->life_support + 1;
} else if (ship->solar_panels < (ship->habitation + ship->life_support)/2) {
packet.action = SSHIP_ACT_PLACE_SOLAR_PANELS;
packet.num = ship->solar_panels + 1;
} else {
packet.action = SSHIP_ACT_PLACE_HABITATION;
packet.num = ship->habitation + 1;
}
send_packet_spaceship_action(&aconnection, &packet);
return 1;
}
if (ship->components > ship->fuel + ship->propulsion) {
if (ship->fuel <= ship->propulsion) {
packet.action = SSHIP_ACT_PLACE_FUEL;
packet.num = ship->fuel + 1;
} else {
packet.action = SSHIP_ACT_PLACE_PROPULSION;
packet.num = ship->propulsion + 1;
}
send_packet_spaceship_action(&aconnection, &packet);
return 1;
}
if (ship->structurals > num_spaceship_structurals_placed(ship)) {
/* Want to choose which structurals are most important.
Else we first want to connect one of each type of module,
then all placed components, pairwise, then any remaining
modules, or else finally in numerical order.
*/
int req = -1;

if (!ship->structure[0]) {
/* if we don't have the first structural, place that! */
packet.action = SSHIP_ACT_PLACE_STRUCTURAL;
packet.num = 0;
send_packet_spaceship_action(&aconnection, &packet);
return 1;
}

if (ship->habitation >= 1
&& !ship->structure[modules_info[0].required]) {
req = modules_info[0].required;
} else if (ship->life_support >= 1
&& !ship->structure[modules_info[1].required]) {
req = modules_info[1].required;
} else if (ship->solar_panels >= 1
&& !ship->structure[modules_info[2].required]) {
req = modules_info[2].required;
} else {
int i;
for(i=0; i<NUM_SS_COMPONENTS; i++) {
if ((i%2==0 && ship->fuel > (i/2))
|| (i%2==1 && ship->propulsion > (i/2))) {
if (!ship->structure[components_info[i].required]) {
req = components_info[i].required;
break;
}
}
}
}
if (req == -1) {
for(i=0; i<NUM_SS_MODULES; i++) {
if ((i%3==0 && ship->habitation > (i/3))
|| (i%3==1 && ship->life_support > (i/3))
|| (i%3==2 && ship->solar_panels > (i/3))) {
if (!ship->structure[modules_info[i].required]) {
req = modules_info[i].required;
break;
}
}
}
}
if (req == -1) {
for(i=0; i<NUM_SS_STRUCTURALS; i++) {
if (!ship->structure[i]) {
req = i;
break;
}
}
}
/* sanity: */
assert(req!=-1);
assert(!ship->structure[req]);

/* Now we want to find a structural we can build which leads to req.
This loop should bottom out, because everything leads back to s0,
and we made sure above that we do s0 first.
*/
while(!ship->structure[structurals_info[req].required]) {
req = structurals_info[req].required;
}
packet.action = SSHIP_ACT_PLACE_STRUCTURAL;
packet.num = req;
send_packet_spaceship_action(&aconnection, &packet);
return 1;
}
return 0;
}

/**************************************************************************
...
**************************************************************************/
void handle_spaceship_info(struct packet_spaceship_info *p)
{
int i;
struct player *pplayer=&game.players[p->player_num];
struct player_spaceship *ship = &pplayer->spaceship;

ship->state = p->sship_state;
ship->structurals = p->structurals;
ship->components = p->components;
ship->modules = p->modules;
ship->fuel = p->fuel;
ship->fuel = p->fuel;
ship->propulsion = p->propulsion;
ship->habitation = p->habitation;
ship->life_support = p->life_support;
ship->solar_panels = p->solar_panels;
ship->launch_year = p->launch_year;
ship->population = p->population;
ship->mass = p->mass;
ship->support_rate = p->support_rate;
ship->energy_rate = p->energy_rate;
ship->success_rate = p->success_rate;
ship->travel_time = p->travel_time;

for(i=0; i<NUM_SS_STRUCTURALS; i++) {
ship->structure[i] = p->structure[i]-'0';
}

if (pplayer != game.player_ptr) {
refresh_spaceship_dialog(pplayer);
return;
}
update_menus();

if (!spaceship_autoplace(ship)) {
refresh_spaceship_dialog(pplayer);
}
}

/**************************************************************************
...
**************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions client/packhand.h
Expand Up @@ -9,4 +9,6 @@ void handle_incite_cost(struct packet_generic_values *packet);

void handle_city_options(struct packet_generic_values *preq);

void handle_spaceship_info(struct packet_spaceship_info *packet);

#endif

0 comments on commit 334262d

Please sign in to comment.