/********************************** cities.c ************************/ #include #include "sdi.h" #include "sdi_color.h" /* * Copyright 1987 by Mark Weiser. * Permission to reproduce and use in any manner whatsoever on Suns is granted * so long as this copyright and other identifying marks of authorship * in the code and the game remain intact and visible. Use of this code * in other products is reserved to me--I'm working on Mac and IBM versions. */ /* * Code to do things to cities. Much of the code here consists of * passing a routine into doto_cities, which then calls that routine * on each city. See the comment for doto_cities (near the end of the file) * for more information. */ /* flags for doto_cities */ #define TYPE_CITY 0x1 #define TYPE_NONCITY 0x2 static short default_city_data_1[] = { #include "default_city.h" }; mpr_static(default_city_pr_1, 64, 64, 1, default_city_data_1); struct pixrect *default_city_pr = &default_city_pr_1; static short melted_city_data[] = { #include "melt.h" }; mpr_static(melted_city_pr, 64, 64, 1, melted_city_data); #define MIN_SPACE 4 #define MAX_CITIES 40 static int city_space, excess, global_count; static long bits_in_city; static int do_update(), do_count(), do_placement(), do_kill(), do_update_all(), do_grow(), do_update_cities(), do_melt_all(); static int cities_inited = 0; static short cities[MAX_CITIES]; static int growcount; /* ugh, another weird global. * set by do_update_cities, used only by 'do_grow'. */ /* * Read a new city pixrect from a file. */ init_city_bits(filename) char *filename; { /* this routine is only called if there is non-default city. */ if (filename != NULL) { char error_msg[256]; struct pixrect *tmp,*icon_load_mpr(); if ((tmp = icon_load_mpr(filename, error_msg)) == NULL) { printf("Could not get pr '%s'.\n", filename); printf("%s",error_msg); printf("Using default cities.\n"); } else { city_pw = xv_create(NULL, SERVER_IMAGE, XV_HEIGHT, 64, XV_WIDTH, 64, SERVER_IMAGE_DEPTH, SDI_COLOR_DEPTH, NULL); if (use_color) xv_set(city_pw, SERVER_IMAGE_COLORMAP, sdi_colormap_name, NULL); xv_rop(city_pw, 0, 0, 64, 64, PIX_SRC, tmp, 0, 0); } } } /* * Compute the positions of all the cities based on current screen size, * and declare all the cities to be unmelted. */ init_cities() { int i, old_num_cities = num_cities; city_pw = xv_create(NULL, SERVER_IMAGE, XV_HEIGHT, 64, XV_WIDTH, 64, SERVER_IMAGE_DEPTH, SDI_COLOR_DEPTH, NULL); if (use_color) xv_set(city_pw, SERVER_IMAGE_COLORMAP, sdi_colormap_name, NULL); xv_rop(city_pw, 0, 0, 64, 64, PIX_SRC | PIX_COLOR(CITY_BASE), &default_city_pr_1, 0, 0); bits_in_city = xv_count_pixels(city_pw, CITY_BASE); melted_city_pw = xv_create(NULL, SERVER_IMAGE, XV_HEIGHT, 64, XV_WIDTH, 64, SERVER_IMAGE_DEPTH, SDI_COLOR_DEPTH, NULL); if (use_color) xv_set(melted_city_pw, SERVER_IMAGE_COLORMAP, sdi_colormap_name, NULL); xv_rop(melted_city_pw, 0, 0, 64, 64, PIX_SRC | PIX_COLOR(CITY_MELTED), &melted_city_pr, 0, 0); tmpcity_pw = xv_create(NULL, SERVER_IMAGE, XV_HEIGHT, 64, XV_WIDTH, 64, SERVER_IMAGE_DEPTH, SDI_COLOR_DEPTH, NULL); if (use_color) xv_set(tmpcity_pw, SERVER_IMAGE_COLORMAP, sdi_colormap_name, NULL); num_cities = ((max_x - MARGIN)/64) + 1; /* bigger than possible */ city_space = 0; while (city_space < MIN_SPACE) { num_cities -= 1; city_space = ((max_x - MARGIN) - (num_cities * 64))/(num_cities-1); }; excess = max_x - (MARGIN + 64*num_cities + city_space*(num_cities-1)); for (i=old_num_cities; i