Update of /cvsroot/xconq/xconq/src/gdl/side
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv22145/side
Modified Files:
cellview.cc doctrine.cc side.cc sidemask.cc sorder.cc
Log Message:
Add GDL serialization support.
Fix copyrights.
Fix automakefile.
Index: sidemask.cc
===================================================================
RCS file: /cvsroot/xconq/xconq/src/gdl/side/sidemask.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** sidemask.cc 30 May 2006 02:34:13 -0000 1.2
--- sidemask.cc 2 Jun 2006 16:57:43 -0000 1.3
***************
*** 6,10 ****
/*//////////////////////////// COPYRIGHT NOTICE ////////////////////////////////
! Copyright (C) 1989 Stanley T. Shebs
Copyright (C) 1991-2000 Stanley T. Shebs
Copyright (C) 2006 Eric A. McDonald
--- 6,10 ----
/*//////////////////////////// COPYRIGHT NOTICE ////////////////////////////////
! Copyright (C) 1987-1989 Stanley T. Shebs
Copyright (C) 1991-2000 Stanley T. Shebs
Copyright (C) 2006 Eric A. McDonald
Index: side.cc
===================================================================
RCS file: /cvsroot/xconq/xconq/src/gdl/side/side.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** side.cc 30 May 2006 02:34:13 -0000 1.1
--- side.cc 2 Jun 2006 16:57:43 -0000 1.2
***************
*** 40,47 ****
--- 40,50 ----
#include "gdl/dir.h"
#include "gdl/namer.h"
+ #include "gdl/player.h"
#include "gdl/side/side.h"
#include "gdl/history.h"
+ #include "gdl/score.h"
#include "gdl/gamearea/area.h"
#include "gdl/world.h"
+ #include "gdl/module.h"
// Function Macros: Queries
***************
*** 60,63 ****
--- 63,68 ----
int numtotsides;
+ AI_ops *all_ai_ops;
+
// Global Variables: Uniques
***************
*** 72,77 ****
--- 77,88 ----
int nextsideid;
+ // Global Variables: Behavior Options
+
+ //! To compress layer output or not to compress layer output?
+ int tmpcompress;
+
// Global Variables: Buffers
+ //! Scratch side.
Side *tmpside;
***************
*** 2246,2249 ****
--- 2257,2624 ----
}
+ void
+ ai_save_state(Side *side)
+ {
+ Obj *(*fn)(Side *side), *state = lispnil;
+
+ fn = all_ai_ops[side->aitype].to_save_state;
+ if (fn)
+ state = (*fn)(side);
+ /* Don't bother if there's no AI state to mess with. */
+ if (side->aidata == lispnil && state == lispnil)
+ return;
+ side->aidata =
+ replace_at_key(side->aidata, side->player->aitypename, state);
+ }
+
+ void
+ write_side_view(Side *side, int compress)
+ {
+ int t, m, x, y;
+ UnitView *uview;
+
+ tmpside = side;
+ tmpcompress = compress;
+ if (side->terrview)
+ write_one_side_view_layer(K_TERRAIN_VIEW, fn_terrain_view);
+ if (!g_see_terrain_always()) {
+ if (side->terrview)
+ write_one_side_view_layer(K_TERRAIN_VIEW_DATES,
+ fn_terrain_view_date);
+ if (numcelltypes < numttypes) {
+ for_all_terrain_types(t) {
+ if (!t_is_cell(t)) {
+ tmpttype = t;
+ if (side->auxterrview[t])
+ write_one_side_view_layer(K_AUX_TERRAIN_VIEW,
+ fn_aux_terrain_view);
+ /* Caused crashes since the code that allocates this layer in init_view
+ is currently commented out. */
+ #if 0
+ if (side->auxterrviewdate[t])
+ write_one_side_view_layer(K_AUX_TERRAIN_VIEW_DATES,
+ fn_aux_terrain_view_date);
+ #endif
+ }
+ }
+ }
+ }
+ if (side->materialview) {
+ for_all_material_types(m) {
+ if (1) {
+ tmpmtype = m;
+ if (side->materialview[m])
+ write_one_side_view_layer(K_MATERIAL_VIEW, fn_material_view);
+ if (side->materialviewdate[m])
+ write_one_side_view_layer(K_MATERIAL_VIEW_DATES,
+ fn_material_view_date);
+ }
+ }
+ }
+ /* Write out unit view objects. */
+ if (!side->see_all && side->unit_views != NULL) {
+ newline_form();
+ start_form(key(K_SIDE));
+ add_num_to_form(side->id);
+ space_form();
+ start_form(key(K_UNIT_VIEWS));
+ newline_form();
+ for_all_cells(x, y) {
+ for_all_view_stack_with_occs(side, x, y, uview) {
+ /* (should filter out side's own units?) */
+ space_form();
+ space_form();
+ start_form(shortest_escaped_name(uview->type));
+ add_num_to_form(uview->siden);
+ add_to_form(uview->name);
+ add_num_to_form(uview->size);
+ add_num_to_form(uview->x);
+ add_num_to_form(uview->y);
+ add_num_to_form(uview->complete);
+ add_num_to_form(uview->date);
+ add_num_to_form(uview->id);
+ add_to_form(uview->image_name);
+ end_form();
+ newline_form();
+ }
+ }
+ space_form();
+ space_form();
+ end_form();
+ end_form();
+ newline_form();
+ }
+ if (!g_see_weather_always()) {
+ if (side->tempview) {
+ write_one_side_view_layer(K_TEMPERATURE_VIEW, fn_temp_view);
+ write_one_side_view_layer(K_TEMPERATURE_VIEW_DATES,
+ fn_temp_view_date);
+ }
+ if (side->cloudview) {
+ write_one_side_view_layer(K_CLOUD_VIEW, fn_cloud_view);
+ write_one_side_view_layer(K_CLOUD_BOTTOM_VIEW,
+ fn_cloud_bottom_view);
+ write_one_side_view_layer(K_CLOUD_HEIGHT_VIEW,
+ fn_cloud_height_view);
+ write_one_side_view_layer(K_CLOUD_VIEW_DATES, fn_cloud_view_date);
+ }
+ if (side->windview) {
+ write_one_side_view_layer(K_WIND_VIEW, fn_wind_view);
+ write_one_side_view_layer(K_WIND_VIEW_DATES, fn_wind_view_date);
+ }
+ }
+ }
+
+ void
+ write_side_properties(Side *side)
+ {
+ int i, u, u2, anyudoctrines;
+
+ write_str_prop(key(K_NAME), side->name, "", FALSE, TRUE);
+ write_str_prop(key(K_LONG_NAME), side->longname, "", FALSE, TRUE);
+ write_str_prop(key(K_SHORT_NAME), side->shortname, "", FALSE, TRUE);
+ write_str_prop(key(K_NOUN), side->noun, "", FALSE, TRUE);
+ write_str_prop(key(K_PLURAL_NOUN), side->pluralnoun, "", FALSE, TRUE);
+ write_str_prop(key(K_ADJECTIVE), side->adjective, "", FALSE, TRUE);
+ write_str_prop(key(K_COLOR), side->colorscheme, "", FALSE, TRUE);
+ write_str_prop(key(K_EMBLEM_NAME), side->emblemname, "", FALSE, TRUE);
+ write_utype_string_list(key(K_UNIT_NAMERS), side->unitnamers, "", TRUE);
+ write_lisp_prop(
+ key(K_UNITS), side->possible_units, lispnil, FALSE, FALSE, TRUE);
+ write_str_prop(key(K_CLASS), side->sideclass, "", FALSE, TRUE);
+ write_bool_prop(key(K_ACTIVE), side->ingame, 1, FALSE, TRUE);
+ /* side->everingame is only interesting if it differs from ingame,
+ so use the value of ingame as the default. */
+ write_bool_prop(key(K_EVER_ACTIVE), side->everingame, side->ingame,
+ FALSE, TRUE);
+ write_num_prop(key(K_PRIORITY), side->priority, -1, FALSE, TRUE);
+ write_num_prop(key(K_STATUS), side->status, 0, FALSE, TRUE);
+ if (!debugging_state_sync)
+ write_num_prop(key(K_TURN_TIME_USED), side->turntimeused, 0, FALSE, TRUE);
+ if (!debugging_state_sync)
+ write_num_prop(
+ key(K_TOTAL_TIME_USED), side->totaltimeused, 0, FALSE, TRUE);
+ write_num_prop(key(K_TIMEOUTS), side->timeouts, 0, FALSE, TRUE);
+ write_num_prop(key(K_TIMEOUTS_USED), side->timeoutsused, 0, FALSE, TRUE);
+ write_num_prop(key(K_FINISHED_TURN), side->finishedturn, 0, FALSE, TRUE);
+ write_num_prop(key(K_WILLING_TO_DRAW), side->willingtodraw, 0, FALSE, TRUE);
+ write_num_prop(key(K_ADVANTAGE), side->advantage, 1, FALSE, TRUE);
+ write_num_prop(key(K_ADVANTAGE_MIN), side->minadvantage, 1, FALSE, TRUE);
+ write_num_prop(key(K_ADVANTAGE_MAX), side->maxadvantage, 1, FALSE, TRUE);
+ write_num_prop(
+ key(K_CONTROLLED_BY),
+ (side->controlled_by ? side_number(side->controlled_by) : -1),
+ -1, FALSE, TRUE);
+ write_num_prop(
+ key(K_SELF_UNIT),
+ (side->self_unit ? side->self_unit->id : 0), 0, FALSE, TRUE);
+ write_num_prop(
+ key(K_PLAYER), (side->player ? side->player->id : -1), -1, FALSE, TRUE);
+ write_num_prop(key(K_DEFAULT_DOCTRINE),
+ (side->default_doctrine ? side->default_doctrine->id : 0),
+ 0, FALSE, TRUE);
+ write_num_prop(key(K_CURRENT_ADVANCE), side->research_topic, NOADVANCE,
+ FALSE, TRUE);
+ write_num_prop(key(K_ADVANCE_GOAL), side->research_goal, NONATYPE, FALSE,
+ TRUE);
+ write_atype_value_list(key(K_ADVANCES_DONE), side->advance, 0, TRUE);
+ write_treasury_list(key(K_TREASURY), side->treasury, 0, TRUE);
+ anyudoctrines = FALSE;
+ if (side->udoctrine != NULL) {
+ for_all_unit_types(u) {
+ if (side->udoctrine[u] != side->default_doctrine) {
+ anyudoctrines = TRUE;
+ break;
+ }
+ }
+ }
+ if (anyudoctrines) {
+ space_form();
+ start_form(key(K_DOCTRINES));
+ for_all_unit_types(u) {
+ if (side->udoctrine[u] != side->default_doctrine) {
+ space_form();
+ start_form(shortest_escaped_name(u));
+ if (side->udoctrine[u]->name)
+ add_to_form(escaped_symbol(side->udoctrine[u]->name));
+ else
+ add_num_to_form(side->udoctrine[u]->id);
+ end_form();
+ }
+ }
+ end_form();
+ newline_form();
+ space_form();
+ }
+ write_side_value_list(key(K_TRUSTS), side->trusts, FALSE, TRUE);
+ write_side_value_list(key(K_TRADES), side->trades, FALSE, TRUE);
+ write_utype_value_list(key(K_START_WITH), side->startwith, 0, TRUE);
+ write_utype_value_list(key(K_NEXT_NUMBERS), side->counts, 0, TRUE);
+ write_utype_value_list(key(K_TECH), side->tech, 0, TRUE);
+ write_utype_value_list(key(K_INIT_TECH), side->inittech, 0, TRUE);
+ write_utype_value_list(key(K_ALREADY_SEEN), side->already_seen, -1, TRUE);
+ write_utype_value_list(
+ key(K_ALREADY_SEEN_INDEPENDENT), side->already_seen_indep, -1, TRUE);
+ write_standing_orders(side);
+ if (side->scores) {
+ space_form();
+ start_form(key(K_SCORES));
+ for (i = 0; i < numscores; ++i) {
+ add_num_to_form(side->scores[i]);
+ }
+ end_form();
+ newline_form();
+ space_form();
+ }
+ write_lisp_prop(key(K_INSTRUCTIONS), side->instructions,
+ lispnil, FALSE, FALSE, TRUE);
+ /* Write out statistics. */
+ if (side->gaincounts != NULL) {
+ space_form();
+ start_form(key(K_GAIN_COUNTS));
+ for (i = 0; i < numutypes * num_gain_reasons; ++i) {
+ add_num_to_form(side->gaincounts[i]);
+ }
+ end_form();
+ newline_form();
+ space_form();
+ }
+ if (side->losscounts != NULL) {
+ space_form();
+ start_form(key(K_LOSS_COUNTS));
+ for (i = 0; i < numutypes * num_loss_reasons; ++i) {
+ add_num_to_form(side->losscounts[i]);
+ }
+ end_form();
+ newline_form();
+ space_form();
+ }
+ if (side->atkstats != NULL) {
+ space_form();
+ start_form(key(K_ATTACK_STATS));
+ for_all_unit_types(u) {
+ if (side->atkstats[u] != NULL) {
+ newline_form();
+ space_form();
+ space_form();
+ space_form();
+ start_form(shortest_escaped_name(u));
+ for_all_unit_types(u2) {
+ add_num_to_form(side_atkstats(side, u, u2));
+ }
+ end_form();
+ }
+ }
+ end_form();
+ newline_form();
+ space_form();
+ }
+ if (side->hitstats != NULL) {
+ space_form();
+ start_form(key(K_HIT_STATS));
+ for_all_unit_types(u) {
+ if (side->hitstats[u] != NULL) {
+ newline_form();
+ space_form();
+ space_form();
+ space_form();
+ start_form(shortest_escaped_name(u));
+ for_all_unit_types(u2) {
+ add_num_to_form(side_hitstats(side, u, u2));
+ }
+ end_form();
+ }
+ }
+ end_form();
+ newline_form();
+ space_form();
+ }
+ if (side->could_act_with)
+ write_utype_value_list(
+ key(K_COULD_ACT_WITH), side->could_act_with, FALSE, TRUE);
+ if (side->could_construct)
+ write_utype_value_list(
+ key(K_COULD_CONSTRUCT), side->could_construct, FALSE, TRUE);
+ if (side->could_develop)
+ write_utype_value_list(
+ key(K_COULD_DEVELOP), side->could_develop, FALSE, TRUE);
+ if (side->could_research)
+ write_atype_value_list(
+ key(K_COULD_RESEARCH), side->could_research, FALSE, TRUE);
+ /* Have the AI paste its useful state into distinct element of
+ side->aidata. */
+ if (side_has_local_ai(side)) {
+ ai_save_state(side);
+ }
+ write_lisp_prop(key(K_AI_DATA), side->aidata, lispnil, FALSE, TRUE, TRUE);
+ write_lisp_prop(key(K_UI_DATA), side->uidata, lispnil, FALSE, TRUE, TRUE);
+ }
+
+ void
+ write_sides(Module *module)
+ {
+ Side *side;
+
+ newline_form();
+ add_to_form(";");
+ add_num_to_form(numtotsides);
+ add_to_form("sides including the independent 0 side.");
+ newline_form();
+ Dprintf("Will try to write %d sides ...\n", numtotsides);
+ for_all_real_sides(side) {
+ start_form(key(K_SIDE));
+ add_num_to_form(side->id);
+ if (symbolp(side->symbol))
+ add_to_form(escaped_symbol(c_string(side->symbol)));
+ newline_form();
+ space_form();
+ write_side_properties(side);
+ space_form();
+ end_form();
+ newline_form();
+ if (module->def_all || module->def_side_views)
+ write_side_view(side, module->compress_layers);
+ Dprintf(" Wrote side %s\n", side_desig(side));
+ }
+ /* Even though the indepside is another side, the properties of
+ independent units are a separate type of form. */
+ start_form(key(K_INDEPENDENT_UNITS));
+ newline_form();
+ write_side_properties(indepside);
+ space_form();
+ end_form();
+ newline_form();
+ Dprintf(" Wrote independent unit properties\n");
+ Dprintf("... Done writing sides\n");
+ }
+
+ void
+ write_side_value_list(char *name, short *arr, int dflt, int addnewline)
+ {
+ int s, writeany;
+
+ if (arr == NULL)
+ return;
+ writeany = FALSE;
+ for (s = 0; s <= numsides; ++s) {
+ if (arr[s] != dflt) {
+ writeany = TRUE;
+ break;
+ }
+ }
+ if (!writeany)
+ return;
+ space_form();
+ start_form(name);
+ for (s = 0; s <= numsides; ++s) {
+ add_num_to_form(arr[s]);
+ }
+ end_form();
+ if (addnewline) {
+ newline_form();
+ space_form();
+ }
+ }
+
NAMESPACE_GDL_END
NAMESPACE_XCONQ_END
Index: cellview.cc
===================================================================
RCS file: /cvsroot/xconq/xconq/src/gdl/side/cellview.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** cellview.cc 30 May 2006 02:34:13 -0000 1.1
--- cellview.cc 2 Jun 2006 16:57:43 -0000 1.2
***************
*** 49,52 ****
--- 49,136 ----
// Game Area View Layer Accessors
+ int
+ fn_terrain_view(int x, int y)
+ {
+ return terrain_view(tmpside, x, y);
+ }
+
+ int
+ fn_terrain_view_date(int x, int y)
+ {
+ return terrain_view_date(tmpside, x, y);
+ }
+
+ int
+ fn_aux_terrain_view(int x, int y)
+ {
+ return aux_terrain_view(tmpside, x, y, tmpttype);
+ }
+
+ int
+ fn_aux_terrain_view_date(int x, int y)
+ {
+ return aux_terrain_view_date(tmpside, x, y, tmpttype);
+ }
+
+ int
+ fn_material_view(int x, int y)
+ {
+ return material_view(tmpside, x, y, tmpmtype);
+ }
+
+ int
+ fn_material_view_date(int x, int y)
+ {
+ return material_view_date(tmpside, x, y, tmpmtype);
+ }
+
+ int
+ fn_temp_view(int x, int y)
+ {
+ return temperature_view(tmpside, x, y);
+ }
+
+ int
+ fn_temp_view_date(int x, int y)
+ {
+ return temperature_view_date(tmpside, x, y);
+ }
+
+ int
+ fn_cloud_view(int x, int y)
+ {
+ return cloud_view(tmpside, x, y);
+ }
+
+ int
+ fn_cloud_bottom_view(int x, int y)
+ {
+ return cloud_bottom_view(tmpside, x, y);
+ }
+
+ int
+ fn_cloud_height_view(int x, int y)
+ {
+ return cloud_height_view(tmpside, x, y);
+ }
+
+ int
+ fn_cloud_view_date(int x, int y)
+ {
+ return cloud_view_date(tmpside, x, y);
+ }
+
+ int
+ fn_wind_view(int x, int y)
+ {
+ return wind_view(tmpside, x, y);
+ }
+
+ int
+ fn_wind_view_date(int x, int y)
+ {
+ return wind_view_date(tmpside, x, y);
+ }
+
void
fn_set_terrain_view(int x, int y, int val)
***************
*** 331,334 ****
--- 415,435 ----
}
+ void
+ write_one_side_view_layer(int propkey, int (*fn)(int x, int y))
+ {
+ newline_form();
+ start_form(key(K_SIDE));
+ add_num_to_form(tmpside->id);
+ space_form();
+ start_form(key((enum keywords)propkey));
+ newline_form();
+ write_rle(fn, -32767, 32767, NULL, tmpcompress);
+ space_form();
+ space_form();
+ end_form();
+ end_form();
+ newline_form();
+ }
+
NAMESPACE_GDL_END
NAMESPACE_XCONQ_END
Index: doctrine.cc
===================================================================
RCS file: /cvsroot/xconq/xconq/src/gdl/side/doctrine.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** doctrine.cc 30 May 2006 02:34:13 -0000 1.2
--- doctrine.cc 2 Jun 2006 16:57:43 -0000 1.3
***************
*** 243,246 ****
--- 243,276 ----
}
+ void
+ write_doctrines(void)
+ {
+ Doctrine *doc;
+
+ for_all_doctrines(doc) {
+ /* (should filter out doctrines with no non-default values) */
+ start_form(key(K_DOCTRINE));
+ if (doc->name)
+ add_to_form(escaped_symbol(doc->name));
+ else
+ add_num_to_form(doc->id);
+ newline_form();
+ space_form();
+ write_num_prop(key(K_RESUPPLY_PERCENT), doc->resupply_percent,
+ /* (should get these defaults from a common place) */
+ 50, FALSE, TRUE);
+ write_num_prop(key(K_REARM_PERCENT), doc->rearm_percent,
+ 20, FALSE, TRUE);
+ write_num_prop(key(K_REPAIR_PERCENT), doc->repair_percent,
+ 35, FALSE, TRUE);
+ write_utype_value_list(key(K_CONSTRUCTION_RUN), doc->construction_run,
+ 0, TRUE);
+ write_num_prop(key(K_LOCKED), doc->locked, 0, FALSE, TRUE);
+ space_form();
+ end_form();
+ newline_form();
+ }
+ }
+
NAMESPACE_GDL_END
NAMESPACE_XCONQ_END
Index: sorder.cc
===================================================================
RCS file: /cvsroot/xconq/xconq/src/gdl/side/sorder.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** sorder.cc 30 May 2006 02:34:13 -0000 1.1
--- sorder.cc 2 Jun 2006 16:57:43 -0000 1.2
***************
*** 228,231 ****
--- 228,298 ----
}
+ void
+ write_standing_orders(Side *side)
+ {
+ int u, u1, numtypes, numargs;
+ char *str = NULL;
+ StandingOrder *sorder;
+
+ for (sorder = side->orders; sorder != NULL; sorder = sorder->next) {
+ space_form();
+ start_form(key(K_STANDING_ORDER));
+ /* (should break into a write_utype_list) */
+ numtypes = u1 = 0;
+ for_all_unit_types(u) {
+ if (sorder->types[u]) {
+ ++numtypes;
+ u1 = u;
+ }
+ }
+ if (numtypes == 1) {
+ add_to_form(shortest_escaped_name(u1));
+ } else if (numtypes == numutypes) {
+ add_to_form(key(K_USTAR));
+ } else {
+ space_form();
+ start_form("");
+ for_all_unit_types(u)
+ add_num_to_form(sorder->types[u]);
+ end_form();
+ }
+ space_form();
+ switch (sorder->condtype) {
+ case sorder_always:
+ str = key(K_ALWAYS);
+ numargs = 0;
+ break;
+ case sorder_at:
+ str = key(K_AT);
+ numargs = 2;
+ break;
+ case sorder_in:
+ str = key(K_IN);
+ numargs = 1;
+ break;
+ case sorder_near:
+ str = key(K_NEAR);
+ numargs = 3;
+ break;
+ default:
+ case_panic("standing order condition type", sorder->condtype);
+ break;
+ }
+ start_form(str);
+ if (numargs > 0)
+ add_num_to_form(sorder->a1);
+ if (numargs > 1)
+ add_num_to_form(sorder->a2);
+ if (numargs > 2)
+ add_num_to_form(sorder->a3);
+ end_form();
+ space_form();
+ write_task(sorder->task);
+ end_form();
+ newline_form();
+ space_form();
+ }
+ }
+
NAMESPACE_GDL_END
NAMESPACE_XCONQ_END
|