Standard disclaimer ------------------- This code is provided as is with out warranty of any kind express or implied. I am not responsible to damage to your code, area, planet files, computer, sanity or really for anything that could go wrong directly or indirectly related to this code. make backups and use at your own risk. -------------------- OK here it is the long awaited Cargo snippet v2.0 much more versitile allows for mulitple imports/exports on planets. Also has resource consumption/production added. which helps to keep players from abusing the BEST cargo run to make millions too quickly. Installs easily into stock swr 1.0. the instructions may be a little vauge, but most coders should be able to understand it. Any questions/comments email: ortluk@hotmail.com in mud.h: --------- in struct ship_data { int maxcargo; int cargo; int cargotype; before struct planet_data /* cargo types */ #define CARGO_NONE 0 #define CARGO_LOMMITE 1 #define CARGO_MELEEN 2 #define CARGO_NEUTRON 3 #define CARGO_ZERSIUM 4 #define CARGO_STEEL 5 #define CARGO_RYLL 6 #define CARGO_ALAZHI 7 #define CARGO_MAX 8 in struct planet_data { int import[CARGO_MAX]; int export[CARGO_MAX]; int resource[CARGO_MAX]; int consumes[CARGO_MAX]; int produces[CARGO_MAX]; before struct planet_data with other DECLARE_DO_FUNC lines - DECLARE_DO_FUN( do_load_cargo ); DECLARE_DO_FUN( do_unload_cargo ); DECLARE_DO_FUN( do_imports ); in clans.c: ------------ char * const cargo_names[CARGO_MAX] = { "none", "lommite","Meleenium","Neutronium","Zersium", "steel", "rhyll","alazhi" }; in do_setplanet - add the following if ( !strcmp( arg2, "import")) { for (i = 0; i < CARGO_MAX; i++) { if (!str_cmp( arg3, cargo_names[i])) { planet->import[i] = atoi(argument); planet->export[i] = 0; send_to_char("done.\n\r", ch ); save_planet( planet ); return; } } send_to_char("No such resource type\r\n", ch); return; } if ( !strcmp( arg2, "export")) { for (i = 0; i < CARGO_MAX; i++) { if (!str_cmp( arg3, cargo_names[i])) { planet->export[i] = atoi(argument); planet->import[i] = 0; send_to_char("done.\n\r", ch ); save_planet( planet ); return; } } send_to_char("No such resource type\r\n", ch); return; } if ( !strcmp( arg2, "resource")) { for (i = 0; i < CARGO_MAX; i++) { if (!str_cmp( arg3, cargo_names[i])) { planet->resource[i] = atoi(argument); send_to_char("done.\n\r", ch ); save_planet( planet ); return; } } send_to_char("No such resource type\r\n", ch); return; } if ( !strcmp( arg2, "produces")) { for (i = 0; i < CARGO_MAX; i++) { if (!str_cmp( arg3, cargo_names[i])) { planet->produces[i] = atoi(argument); send_to_char("done.\n\r", ch ); save_planet( planet ); return; } } send_to_char("No such resource type\r\n", ch); return; } if ( !strcmp( arg2, "consumes")) { for (i = 0; i < CARGO_MAX; i++) { if (!str_cmp( arg3, cargo_names[i])) { planet->consumes[i] = atoi(argument); send_to_char("done.\n\r", ch ); save_planet( planet ); return; } } send_to_char("No such resource type\r\n", ch); return; } in save_planet add: for(i = 1; iimport[i], planet->export[i], planet->resource[i], planet->consumes[i], planet->produces[i]) in fread_planet: add at the beginning - char *line; int x0,x1,x2,x3,x4,x5; add in the switch section with the other cases - case 'R': if( !str_cmp( word, "Resource" ) ); { line = fread_line(fp); x0=x1=x2=x3=x4=x5=0; sscanf(line, "%d %d %d %d %d %d\n", &x0, &x1, &x2, &x3, &x4, &x5); planet->import[x0] = x1; planet->export[x0] = x2; planet->resource[x0] = x3; planet->consumes[x0] = x4; planet->produces[x0] = x5; } break; and add this function. void do_imports( CHAR_DATA *ch, char *argument ) { PLANET_DATA *planet; int i; if (argument[0] == '\0') { send_to_char("Usage: imports \r\n", ch); return; } planet = get_planet( argument ); if (!planet) { send_to_char("&RNo such planet\r\n", ch); return; } ch_printf(ch,"&BImport and Export data for %s:\r\n", planet->name); ch_printf(ch,"&GResource &CImport &YExport &PProduces &RConsumes &GAmount\r\n"); ch_printf(ch, "&G---------- ------ ------ -------- -------- ------\r\n"); for (i = 1; i < CARGO_MAX; i++) ch_printf(ch,"&G%-10.10s &C%5d/ton &Y%5d/ton &P%6d tons &R%6d tons &G%9d\r\n", cargo_names[i], planet->import[i], planet->export[i], planet->produces[i], planet->consumes[i], planet->resource[i]); return; } in space.c ------------ add this line - extern char * const cargo_names[CARGO_MAX]; in save_ship - with the other fprinfs - fprintf( fp, "MaxCargo %d\n", ship->maxcargo ); if (ship->cargo > 0) { fprintf( fp, "Cargo %d\n", ship->cargo ); fprintf( fp, "CargoType %d\n", ship->cargotype ); } in fread_ship - you know where they go KEY( "Cargo", ship->cargo, fread_number( fp ) ); KEY( "CargoType", ship->cargotype, fread_number( fp ) ); KEY( "MaxCargo", ship->maxcargo, fread_number( fp ) ); if (ship->cargotype != CARGO_NONE && ship->cargo < 1) ship->cargotype = CARGO_NONE; in do_setship - if ( !str_cmp( arg2, "maxcargo" ) ) { ship->maxcargo = URANGE(0, atoi(argument), 500); send_to_char( "Done.\n\r", ch ); save_ship(ship); return; } in do_showship ch_printf( ch, "Cargo: %d/%d, Cargo Type: %s \n\r", ship->cargo, ship->maxcargo, cargo_names[ship->cargotype]); in do_makeship ship->maxcargo=0; ship->cargo=0; ship->cargotype=0; in do_info - ch_printf( ch, "Maximum Speed: %d Hyperspeed: %d Maximum Cargo %d\n\r", target->realspeed, target->hyperspeed, target->maxcargo ); in do_stat - ch_printf( ch, "&OCargo: &Y%d/&O%d Cargo Type: &Y%s&w\n\r", ship->cargo, ship->maxcargo, cargo_names[ship->cargotype]); add these functions - void do_unload_cargo( CHAR_DATA *ch, char *argument) { SHIP_DATA *ship; SHIP_DATA *target; int cost; PLANET_DATA *planet; if ( argument[0] == '\0' ) { act( AT_PLAIN, "Which ship do you want to unload?.", ch, NULL, NULL, TO_CHAR); return; } target = ship_in_room( ch->in_room , argument ); if ( !target ) { act( AT_PLAIN, "I see no $T here.", ch, NULL, argument, TO_CHAR ); return; } if (!check_pilot(ch, target)) { send_to_char("Hey, that's not your ship!\r\n", ch); return; } if ( target->cargo == 0 ) { send_to_char("You don't have any cargo.\r\n",ch); return; } if ( !IS_SET( ch->in_room->room_flags, ROOM_IMPORT ) && !IS_SET( ch->in_room->room_flags, ROOM_SPACECRAFT )) { send_to_char("You can't do that here!", ch); return; } planet = ch->in_room->area->planet; if (!planet) { ship = ship_from_hanger( ch->in_room->vnum ); if (!ship) { send_to_char("You can't do that here!", ch); return; } if ((ship->maxcargo - ship->cargo) < 1) { send_to_char("There is no room for anymore cargo\r\n",ch); return; } if (ship->cargo == 0) ship->cargotype = CARGO_NONE; if ((ship->cargo > 0) && (ship->cargotype != target->cargo)) { send_to_char("They have a differnt type of cargo.\n\r",ch); return; } if (ship->cargotype == CARGO_NONE) ship->cargotype = target->cargotype; if ((ship->maxcargo - ship->cargo) >= target->cargo) { ship->cargo += target->cargo; target->cargo = 0; target->cargo = CARGO_NONE; send_to_char("Cargo unloaded.\r\n",ch); return; } else { target->cargo -= ship->maxcargo - ship->cargo; ship->cargo = ship->maxcargo; ch_printf(ch, "%s Loaded, %d tons still in %s hold.\r\n", ship->name, target->cargo, target->name); return; } } if (planet->import[target->cargotype] < 1) { send_to_char("You can't deliver that here.\r\n",ch); return; } cost = target->cargo; cost *= planet->import[target->cargotype]; ch->gold += cost; target->cargo = 0; ch_printf(ch,"You recieve %d credits for a load of %s.\r\n", cost, cargo_names[target->cargotype]); target->cargotype = CARGO_NONE; return; } void do_load_cargo( CHAR_DATA *ch, char *argument) { SHIP_DATA *ship; SHIP_DATA *target; int cost,cargo, i; PLANET_DATA *planet; char arg1[MAX_INPUT_LENGTH]; argument = one_argument(argument, arg1); if ( arg1[0] == '\0' ) { act( AT_PLAIN, "Which ship do you want to load?.", ch, NULL, NULL, TO_CHAR); return; } target = ship_in_room( ch->in_room , arg1 ); if ( !target ) { act( AT_PLAIN, "I see no $T here.", ch, NULL, argument, TO_CHAR ); return; } if (!check_pilot(ch, target)) { send_to_char("Hey, that's not your ship!\r\n", ch); return; } if ( !IS_SET( ch->in_room->room_flags, ROOM_IMPORT ) && !IS_SET( ch->in_room->room_flags, ROOM_SPACECRAFT )) { send_to_char("You can't do that here!", ch); return; } planet = ch->in_room->area->planet; if (!planet) { ship = ship_from_hanger( ch->in_room->vnum ); if (!ship) { send_to_char("You can't do that here!", ch); return; } if (ship->cargo == 0) { send_to_char("They don't have any cargo\n\r", ch); return; } if ((target->maxcargo - target->cargo) < 1) { send_to_char("There is no room for anymore cargo\r\n",ch); return; } if ((target->cargotype =! CARGO_NONE) && (ship->cargotype != target->cargotype)); { send_to_char("Maybe you should deliver your cargo first.\n\r",ch); return; } if (target->cargotype == CARGO_NONE) target->cargotype = ship->cargotype; if ((target->maxcargo - target->cargo) >= ship->cargo) { target->cargo += ship->cargo; ship->cargo = 0; send_to_char("Cargo loaded.\r\n",ch); return; } else { ship->cargo -= target->maxcargo - target->cargo; target->cargo = target->maxcargo; send_to_char("Cargo Loaded.\r\n",ch); return; } } if (argument[0] == '\0') { send_to_char("&RWhat do you wnat to load&C&w\r\n", ch); return; } if (target->maxcargo - target->cargo <= 0) { send_to_char("There is no room for more Cargo.\r\n", ch); return; } for(i = 1; i < CARGO_MAX; i++) { if(!strcmp(argument, cargp_names[i])) cargo = i; } if ((target->cargo > 0) && (target->cargotype != cargo)) { send_to_char("Maybe you should deliver your cargo first\r\n",ch); return; } if (planet->export[cargo] < 1) { send_to_char("We don't export those goods here\r\n", ch); return; } if (planet->resource[cargo] < 1) { send_to_char("&RSorry we have none left to ship\r\n", ch); return; } if ((target->maxcargo - target->cargo) >= planet->resource[cargo]) cost = planet->resource[cargo]; else cost = (target->maxcargo - target->cargo); cost *= planet->export[cargo]; if (ch->gold < cost) { send_to_char("You can't afford it!\r\n", ch); return; } ch->gold -= cost; if ((target->maxcargo - target->cargo) >= planet->resource[cargo]) { target->cargo += planet->resource[cargo]; planet->resource[cargo] = 0; target->cargotype = cargo; } else { planet->resource[cargo] -= target->maxcargo - target->cargo; target->cargo = target->maxcargo; target->cargotype = cargo; } ch_printf(ch,"You pay %d credits for a load of %s.\r\n", cost, cargo_names[cargo]); return; } in tables.c ----------- if ( !str_cmp( name, "do_imports")) return do_imports; if ( !str_cmp( name, "do_load_cargo")) return do_load_cargo; if ( !str_cmp( name, "do_unload_cargo")) return do_unload_cargo; if ( skill == do_imports) return "do_imports"; if ( skill == do_load_cargo) return "do_load_cargo"; if ( skill == do_unload_cargo ) return "do_unload_cargo"; in update.c ----------- in function update_taxes - int i; then in the for (planet = ........ part add this - for( i = 1; i < CARGO_MAX; i++) { planet->resource[i] += planet->produces[i]; planet->resource[i] -= planet->consumes[i]; } save_planet(planet); almost done .... now just make clean make and add the commands online cedit imports create do_imports cedit imports level 1 cedit loadcargo create do_load_cargo cedit loadcargo level 1 cedit unloadcargo create do_unload_cargo cedit unloadcargo level 1 cedit save