コード例 #1
0
ファイル: ecology.cpp プロジェクト: SirIvanMoReau/lincity-ng
void setup_land()
{
	int x, y, xw, yw;
	int aridity = global_aridity;

	distance_to_river();

	for (y = 0; y < WORLD_SIDE_LEN; y++) {
		for (x = 0; x < WORLD_SIDE_LEN; x++) {
			int d2w_min = 2 * WORLD_SIDE_LEN * WORLD_SIDE_LEN;
			int r;
			int arid = aridity;
			//int alt0 = 0;

			/* test against IS_RIVER to prevent terrible recursion */
			if (IS_RIVER(x, y))
				continue;

			d2w_min = lmap.dist2w[x][y];

			/* near river lower aridity */
			if (aridity > 0) {
				if (d2w_min < 5)
					arid = aridity / 3;
				else if (d2w_min < 17)
					arid = (aridity * 2) / 3;
			}
			/* Altitude has same effect as distance */
			r = rand() % (d2w_min / 3 + 1) \
			    + arid \
			    + abs(ALT(x, y) * 15 / alt_step) \
			    + 3 * (ALT(x, y) * ALT(x, y)) / 1000000;

			lmap.ecotable[x][y] = r;
			/* needed to setup quasi randome land. The flag is set below */
			MP_FLAG(x, y) |= FLAG_HAS_UNDERGROUND_WATER;
			do_rand_ecology(x, y);

			/* preserve rivers, so that we can connect port later */
			if (MP_TYPE(x, y) == WATER) {
				int navigable = MP_FLAG(x, y) & FLAG_IS_RIVER;
				set_mappoint(x, y, WATER);
				MP_FLAG(x, y) |= navigable;
				MP_FLAG(x, y) |= FLAG_HAS_UNDERGROUND_WATER;
			}
			/* set undergroung water according to first random land setup */
			if (MP_TYPE(x, y) == DESERT) {
				MP_FLAG(x, y) &= (0xffffffff - FLAG_HAS_UNDERGROUND_WATER);
			}
		}
	}
	for (y = 0; y < WORLD_SIDE_LEN; y++)
		for (x = 0; x < WORLD_SIDE_LEN; x++)
			if (MP_TYPE(x, y) == WATER)
				MP_FLAG(x, y) |= FLAG_HAS_UNDERGROUND_WATER;

	//connect_rivers();
}
コード例 #2
0
void
add_a_shanty (void)
{
  int r, x, y;
  x = rand () % WORLD_SIDE_LEN;
  y = rand () % WORLD_SIDE_LEN;
  if (numof_shanties > 0 && rand () % 8 != 0)
    {
      r = spiral_find_group (x, y, GROUP_SHANTY);
      if (r == -1)
	{
	  printf ("Looked for a shanty, without any! x=%d y=%d\n", x, y);
	  return;
	}
      y = r / WORLD_SIDE_LEN;
      x = r % WORLD_SIDE_LEN;
      r = spiral_find_2x2 (x, y);
      if (r == -1)
	{
#ifdef commentout /* wck: These are annoying when the map is full */
	 	  printf ("Adding a shanty (s), no space for it?!\n");
#endif
	  return;
	}
      y = r / WORLD_SIDE_LEN;
      x = r % WORLD_SIDE_LEN;
    }
  else
    {
      r = spiral_find_group (x, y, GROUP_MARKET);
      if (r == -1)
	return;			/* silently return, we havn't started yet. */

      y = r / WORLD_SIDE_LEN;
      x = r % WORLD_SIDE_LEN;
      r = spiral_find_2x2 (x, y);
      if (r == -1)
	{
#ifdef commentout /* see above */
	  printf ("Adding a shanty (r), no space for it?!\n");
#endif
	  return;
	}
      y = r / WORLD_SIDE_LEN;
      x = r % WORLD_SIDE_LEN;
    }
  set_mappoint (x, y, CST_SHANTY);
  numof_shanties++;
}
コード例 #3
0
void 
handle_msg_item_placed (void)
{
  int x, y;
  unsigned short selected_item;
  MsgBuf* msg = &recvbuf;
  Int32* msgp = (Int32*) MSG_BODY(msg);

  printf ("Client received MSG_ITEM_PLACED.\n");
  x = ntohl(*msgp++);
  y = ntohl(*msgp++);
  selected_item = (unsigned short) ntohl(*msgp++);

  set_mappoint (x, y, selected_item);
  refresh_main_screen ();
}
コード例 #4
0
void 
handle_msg_map_types (void)
{
    int x, y;
    MsgBuf* msg = &recvbuf;
    Int16* msgp = (Int16*) MSG_BODY(msg);

    printf ("Client received MSG_MAP_TYPES.\n");
    for (y = 0; y < WORLD_SIDE_LEN; y++) {
	for (x = 0; x < WORLD_SIDE_LEN; x++) {
	    MP_TYPE(x,y) = ntohs(*msgp++);
	    if (MP_TYPE(x,y) != CST_USED && MP_TYPE(x,y) != CST_GREEN) {
		set_mappoint (x, y, MP_TYPE(x,y));
	    }
	}
    }
}
コード例 #5
0
void 
handle_msg_map_types_region (void)
{
  int x, y, xx, yy, size;
  MsgBuf* msg = &recvbuf;
  Int16* msgp16 = (Int16*) MSG_BODY(msg);
  Int32* msgp32 = (Int32*) MSG_BODY(msg);

  printf ("Client received MSG_MAP_TYPES_REGION.\n");
  x = ntohl(*msgp32++);
  y = ntohl(*msgp32++);
  size = ntohl(*msgp32++);
  msgp16 = (Int16*) msgp32;
  for (yy = y; yy < y + size; yy++) {
    for (xx = x; xx < x + size; xx++) {
      MP_TYPE(xx,yy) = ntohs(*msgp16++);
      if (MP_TYPE(xx,yy) != CST_USED) {
	set_mappoint (xx, yy, MP_TYPE(xx,yy));
      }
    }
  }
}
コード例 #6
0
int 
place_item (int x, int y, short type)
{
    int group;
    int size;

    group = get_group_of_type(type);
    if (group < 0) return -1;

    size = main_groups[group].size;

    /* You can't build because credit not available. */
    if (no_credit_build (group) != 0) {
	return -1;
    }

    /* Not enough slots in the substation array */

    switch (group) {
    case GROUP_SUBSTATION:
    case GROUP_WINDMILL:
    {
	if (add_a_substation (x, y) == 0)
	    return -3;
    } break;
    case GROUP_PORT:
    {
	if (is_real_river (x + 4, y) != 1 
	    || is_real_river (x + 4, y + 1) != 1
	    || is_real_river (x + 4, y + 2) != 1 
	    || is_real_river (x + 4, y + 3) != 1) {
	    return -2;
	}
    } break;
    case GROUP_COMMUNE:
    {
	numof_communes++;
    } break;
    case GROUP_MARKET:
    {
	/* Test for enough slots in the market array */
	if (add_a_market (x, y) == 0)
	    return -3;
	MP_INFO(x,y).flags += (FLAG_MB_FOOD | FLAG_MB_JOBS
			       | FLAG_MB_COAL | FLAG_MB_ORE | FLAG_MB_STEEL
			       | FLAG_MB_GOODS | FLAG_MS_FOOD | FLAG_MS_JOBS
			       | FLAG_MS_COAL | FLAG_MS_GOODS | FLAG_MS_ORE
			       | FLAG_MS_STEEL);
    } break;
    case GROUP_TIP:
    {
	/* Don't build a tip if there has already been one.  If we succeed,
	   mark the spot permanently by "doubling" the ore reserve */
	int i,j;
	int prev_tip = 0;
	for (i=0;i<3;i++) {
	    for (j=0;j<3;j++) {
		if (MP_INFO(x+i,y+j).ore_reserve > ORE_RESERVE) {
		    prev_tip = 1;
		    break;
		}
	    }
	}
	if (prev_tip) {
	    dialog_box(red(12),3,
		       0,0,_("You can't build a tip here"),
		       0,0,_("This area was once a landfill"),
		       2,' ',_("OK"));
	    return -4;
	} else {
	    for (i=0;i<3;i++) {
		for (j=0;j<3;j++) {
		    MP_INFO(x+i,y+j).ore_reserve = ORE_RESERVE * 2;
		}
	    }
	}
    } break;
    case GROUP_OREMINE:
    {
	/* Don't allow new mines on old mines or old tips */
	/* GCS: mines over old mines is OK if there is enough remaining 
	        ore, as is the case when there is partial overlap. */
	int i,j;
	int prev_tip = 0;
	int total_ore = 0;
	for (i=0;i<3;i++) {
	    for (j=0;j<3;j++) {
		total_ore += MP_INFO(x+i,y+j).ore_reserve;
		if (MP_INFO(x+i,y+j).ore_reserve > ORE_RESERVE) {
		    prev_tip = 1;
		    break;
		}
	    }
	}
	if (prev_tip) {
	    dialog_box(red(12),3,
		       0,0,_("You can't build a mine here"),
		       0,0,_("This area was once a landfill"),
		       2,' ',_("OK"));
	    return -4;
	}
	if (total_ore < MIN_ORE_RESERVE_FOR_MINE) {
	    dialog_box(red(12),3,
		       0,0,_("You can't build a mine here"),
		       0,0,_("There is no ore left at this site"),
		       2,' ',_("OK"));
	    return -4;
	}
    }
    } /* end case */

    /* Store last_built for refund on "mistakes" */
    last_built_x = x;
    last_built_y = y;

    /* Make sure that the correct windmill graphic shows up */
    if (group == GROUP_WINDMILL) {
	if (tech_level > MODERN_WINDMILL_TECH) {
	    type = CST_WINDMILL_1_R;
	} else {
	    type = CST_WINDMILL_1_W;
	}
    }

    if (group == GROUP_SOLAR_POWER || group == GROUP_WINDMILL) {
	MP_INFO(x,y).int_2 = tech_level;
	let_one_through = 1;
    }
    else if (group == GROUP_RECYCLE || group == GROUP_COAL_POWER)
	MP_INFO(x,y).int_4 = tech_level;
    else if (group == GROUP_ORGANIC_FARM)
	MP_INFO(x,y).int_1 = tech_level;
    else if (group == GROUP_TRACK
	     || group == GROUP_ROAD
	     || group == GROUP_RAIL)
	MP_INFO(x,y).flags |= FLAG_IS_TRANSPORT;
    else if (group == GROUP_COALMINE
	     || group == GROUP_OREMINE)
	let_one_through = 1;

    set_mappoint (x, y, type);

    update_tech_dep (x, y);

    if (group == GROUP_RIVER)
	connect_rivers ();

    connect_transport (x-2,y-2,x+size+1,y+size+1);

    adjust_money(-selected_module_cost);
    map_power_grid();
    return 0;
}
コード例 #7
0
int 
place_item (int x, int y, short type)
{
    int i,j;
    int prev_tip = 0;
    int group;
    int size;

    group = get_group_of_type(type);
    if (group < 0) {
#ifdef DEBUG
        fprintf(stderr,"Error: group does not exist %i\n", group);
#endif
        ok_dial_box ("warning.mes", BAD,
                _("ERROR: group does not exist. This should not happen! Please consider filling a bug report to lincity-ng team, with the saved game and what you did :-) "));
        return -1000;
    }

    size = main_groups[group].size;

    /* You can't build because credit not available. */
    if (no_credit_build (group) != 0) {
        no_credit_build_msg_ng (group);
	return -1;
    }

    switch (group) {
    case GROUP_ORGANIC_FARM:
	MP_INFO(x,y).int_1 = tech_level;
        break;
    case GROUP_TRACK:
    case GROUP_ROAD:
    case GROUP_RAIL:
	MP_INFO(x,y).flags |= FLAG_IS_TRANSPORT;
        break;
    case GROUP_PORT:
	if (is_real_river (x + 4, y) != 1 
	        || is_real_river (x + 4, y + 1) != 1
	        || is_real_river (x + 4, y + 2) != 1 
	        || is_real_river (x + 4, y + 3) != 1) {
            if (last_warning_message_group != group)
                ok_dial_box ("warning.mes", BAD,
                    _("Port must be connected to river all along right side."));
            last_warning_message_group = group;
            return -2;
        }
        break;
    case GROUP_SUBSTATION:
        if (add_a_substation (x, y) == 0) {
            /* Not enough slots in the substation array */
            if (last_warning_message_group != group)
                ok_dial_box ("warning.mes", BAD,
                    _("Too many substations + windmills. You cannot build one more"));
            last_warning_message_group = group;
	    return -3;
        }
        break;
    case GROUP_WINDMILL:
	if (add_a_substation (x, y) == 0) {
            /* Not enough slots in the substation array */
            if (last_warning_message_group != group)
                ok_dial_box ("warning.mes", BAD,
                    _("Too many substations + windmills. You cannot build one more"));
            last_warning_message_group = group;
	    return -3;
        }
        MP_INFO(x,y).int_2 = tech_level;
        MP_INFO(x,y).int_1 = (int)(WINDMILL_POWER
	        + (((double) MP_INFO(x,y).int_2 * WINDMILL_POWER) / MAX_TECH_LEVEL));
        /* Make sure that the correct windmill graphic shows up */
	if (tech_level > MODERN_WINDMILL_TECH)
	    type = CST_WINDMILL_1_R;
	else 
	    type = CST_WINDMILL_1_W;
        break;
    case (GROUP_COAL_POWER):
        MP_INFO(x,y).int_4 = tech_level;
        MP_INFO(x,y).int_1 = (int)(POWERS_COAL_OUTPUT
	        + (((double) MP_INFO(x,y).int_4 * POWERS_COAL_OUTPUT)
	                / MAX_TECH_LEVEL));
        break;
    case (GROUP_SOLAR_POWER):
 	MP_INFO(x,y).int_2 = tech_level;
        MP_INFO(x,y).int_1 = (int)(POWERS_SOLAR_OUTPUT
	        + (((double) MP_INFO(x,y).int_2 * POWERS_SOLAR_OUTPUT)
	                / MAX_TECH_LEVEL)); /* like other power sources */
        MP_INFO(x,y).int_3 = MP_INFO(x,y).int_1; /* Int_3 is kept for compatibility */
        break;
    case GROUP_COMMUNE:
	numof_communes++;
        break;
    case GROUP_MARKET:
	/* Test for enough slots in the market array */
	if (add_a_market (x, y) == 0) {
            if (last_warning_message_group != group)
                ok_dial_box ("warning.mes", BAD,
                        _("Too many markets. You cannot build one more"));
            last_warning_message_group = group;
	    return -4;
        }
	MP_INFO(x,y).flags += (FLAG_MB_FOOD | FLAG_MB_JOBS
			       | FLAG_MB_COAL | FLAG_MB_ORE | FLAG_MB_STEEL
			       | FLAG_MB_GOODS | FLAG_MS_FOOD | FLAG_MS_JOBS
			       | FLAG_MS_COAL | FLAG_MS_GOODS | FLAG_MS_ORE
			       | FLAG_MS_STEEL);
        break;
    case GROUP_RECYCLE:
        MP_INFO(x,y).int_4 = tech_level;
        break;
    case GROUP_TIP:
	/* Don't build a tip if there has already been one.  If we succeed,
	   mark the spot permanently by "doubling" the ore reserve */
	prev_tip = 0;
	for (i=0; i < size; i++)
	    for (j=0; j < size; j++)
		if (MP_INFO(x+i,y+j).ore_reserve > ORE_RESERVE) {
		    prev_tip = 1;
		    break;
		}
	if (prev_tip) {
	    ok_dial_box ("warning.mes", BAD,
                    _("You can't build a tip here: this area was once a landfill"));
	    return -5;
	} else {
	    for (i=0; i < size; i++)
		for (j=0; j < size; j++)
		    MP_INFO(x+i,y+j).ore_reserve = ORE_RESERVE * 2;
	}
        break;
    case GROUP_OREMINE:
    {
	/* Don't allow new mines on old mines or old tips */
	/* GCS: mines over old mines is OK if there is enough remaining 
	        ore, as is the case when there is partial overlap. */
	int total_ore = 0;
	prev_tip = 0;
	for (i=0;i<size;i++) {
	    for (j=0;j<size;j++) {
		total_ore += MP_INFO(x+i,y+j).ore_reserve;
		if (MP_INFO(x+i,y+j).ore_reserve > ORE_RESERVE) {
		    prev_tip = 1;
		    break;
		}
	    }
	}
	if (prev_tip) {
	    ok_dial_box ("warning.mes", BAD,
                    _("You can't build a mine here: This area was once a landfill"));
	    return -6;
	}
	if (total_ore < MIN_ORE_RESERVE_FOR_MINE) {
	    ok_dial_box("warning.mes", BAD,
                    _("You can't build a mine here: there is no ore left at this site"));
	    return -7;
	}
        break;
    } 
    case GROUP_WATERWELL:
	numof_waterwell++;
        break;
    case GROUP_PARKLAND:
        if (use_waterwell)
            if (!HAS_UGWATER(x,y)) {
                ok_dial_box("warning.mes", BAD,
                        _("You can't build a park here: it is a desert, parks need water"));
                return -8;
            }

    } /* end case */
    last_warning_message_group = 0;

    /* Store last_built for refund on "mistakes" */
    last_built_x = x;
    last_built_y = y;

    set_mappoint (x, y, type);

    if (group == GROUP_RIVER)
	connect_rivers ();

    connect_transport (x-2,y-2,x+size+1,y+size+1);

    adjust_money(-selected_module_cost);
    map_power_grid();
    return 0;
}
コード例 #8
0
ファイル: ecology.cpp プロジェクト: SirIvanMoReau/lincity-ng
static void do_rand_ecology(int x, int y)
{
	int r = lmap.ecotable[x][y];
	if ((MP_FLAG(x, y) | FLAG_HAS_UNDERGROUND_WATER) == 0) {
		/*true desert */
		return;
	}

	if (r >= 300) {
		/* very dry land */
		int r2 = rand() % 10;
		if (r2 <= 6)
			set_mappoint(x, y, DESERT);
		else if (r2 <= 8)
			set_mappoint(x, y, GREEN);
		else
			set_mappoint(x, y, TREE);
	} else if (r >= 160) {
		int r2 = rand() % 10;
		if (r2 <= 2)
			set_mappoint(x, y, DESERT);
		else if (r2 <= 6)
			set_mappoint(x, y, GREEN);
		else
			set_mappoint(x, y, TREE);
	} else if (r >= 80) {
		int r2 = rand() % 10;
		if (r2 <= 1)
			set_mappoint(x, y, DESERT);
		else if (r2 <= 4)
			set_mappoint(x, y, GREEN);
		else if (r2 <= 6)
			set_mappoint(x, y, TREE);
		else
			set_mappoint(x, y, TREE2);
	} else if (r >= 40) {
		int r2 = rand() % 40;
		if (r2 == 0)
			set_mappoint(x, y, DESERT);
		else if (r2 <= 12)
			set_mappoint(x, y, GREEN);
		else if (r2 <= 24)
			set_mappoint(x, y, TREE);
		else if (r2 <= 36)
			set_mappoint(x, y, TREE2);
		else
			set_mappoint(x, y, TREE3);
	} else if (r >= 0) {
		/* normal land */
		int r2 = rand() % 40;
		if (r2 <= 10)
			set_mappoint(x, y, GREEN);
		else if (r2 <= 20)
			set_mappoint(x, y, TREE);
		else if (r2 <= 30)
			set_mappoint(x, y, TREE2);
		else
			set_mappoint(x, y, TREE3);
	} else if (r >= -40) {
		/* forest */
		int r2 = rand() % 40;
		if (r2 <= 5)
			set_mappoint(x, y, GREEN);
		else if (r2 <= 10)
			set_mappoint(x, y, TREE);
		else if (r2 <= 25)
			set_mappoint(x, y, TREE2);
		else
			set_mappoint(x, y, TREE3);
	} else if (r >= -80) {
		int r2 = rand() % 40;
		if (r2 <= 0)
			MP_TYPE(x, y) = WATER;
		else if (r2 <= 6)
			set_mappoint(x, y, GREEN);
		else if (r2 <= 15)
			set_mappoint(x, y, TREE);
		else if (r2 <= 28)
			set_mappoint(x, y, TREE2);
		else
			set_mappoint(x, y, TREE3);
	} else if (r >= -120) {
		int r2 = rand() % 40;
		if (r2 <= 1)
			MP_TYPE(x, y) = WATER;
		else if (r2 <= 6)
			set_mappoint(x, y, GREEN);
		else if (r2 <= 16)
			set_mappoint(x, y, TREE);
		else if (r2 <= 30)
			set_mappoint(x, y, TREE2);
		else
			set_mappoint(x, y, TREE3);
	} else {
		/* wetland */
		int r2 = rand() % 40;
		if (r2 <= 3)
			MP_TYPE(x, y) = WATER;
		else if (r2 <= 8)
			set_mappoint(x, y, GREEN);
		else if (r2 <= 20)
			set_mappoint(x, y, TREE);
		else if (r2 <= 35)
			set_mappoint(x, y, TREE2);
		else
			set_mappoint(x, y, TREE3);
	}
}