Skip to content
Permalink
Browse files

Added junkyard logic. Wrecked vehicles now save to the junkyard until…

… the next boot.
  • Loading branch information...
luciensadi committed Jun 25, 2019
1 parent 8d28a22 commit c345c40fab4b914ef940b35048f1b547d77c71a5
Showing with 117 additions and 45 deletions.
  1. +28 −18 src/awake.h
  2. +2 −2 src/db.cpp
  3. +2 −1 src/fight.cpp
  4. +85 −24 src/limits.cpp
@@ -2011,24 +2011,34 @@ enum {
// End new combat modifiers.

// Locations, to remove the magic numbers from the code.
#define RM_CHARGEN_START_ROOM 60500
#define RM_NEWBIE_LOADROOM 60565 // The Neophyte Hotel.
#define RM_NEWBIE_LOBBY 60563
#define RM_ENTRANCE_TO_DANTES 35500
#define RM_DANTES_GARAGE 35693
#define RM_DANTES_GARAGE_RANDOM 35693 + number(0,4)
#define RM_DANTES_DESCENT 35502
#define RM_SEATTLE_DOCWAGON RM_ENTRANCE_TO_DANTES
#define RM_PORTLAND_DOCWAGON RM_ENTRANCE_TO_DANTES
#define RM_CARIB_DOCWAGON RM_ENTRANCE_TO_DANTES
#define RM_OCEAN_DOCWAGON RM_ENTRANCE_TO_DANTES
#define RM_SEATTLE_PARKING_GARAGE RM_DANTES_GARAGE
#define RM_CARIB_PARKING_GARAGE RM_DANTES_GARAGE
#define RM_OCEAN_PARKING_GARAGE RM_DANTES_GARAGE
#define RM_PORTLAND_PARKING_GARAGE RM_DANTES_GARAGE
#define RM_PAINTER_LOT 1
#define RM_MULTNOMAH_GATE_NORTH 1
#define RM_MULTNOMAH_GATE_SOUTH 1
#define RM_CHARGEN_START_ROOM 60500
#define RM_NEWBIE_LOADROOM 60565 // The Neophyte Hotel.
#define RM_NEWBIE_LOBBY 60563
#define RM_ENTRANCE_TO_DANTES 35500
#define RM_DANTES_GARAGE 35693
#define RM_DANTES_GARAGE_RANDOM 35693 + number(0,4)
#define RM_DANTES_DESCENT 35502
#define RM_SEATTLE_DOCWAGON RM_ENTRANCE_TO_DANTES
#define RM_PORTLAND_DOCWAGON RM_ENTRANCE_TO_DANTES
#define RM_CARIB_DOCWAGON RM_ENTRANCE_TO_DANTES
#define RM_OCEAN_DOCWAGON RM_ENTRANCE_TO_DANTES
#define RM_SEATTLE_PARKING_GARAGE RM_DANTES_GARAGE
#define RM_CARIB_PARKING_GARAGE RM_DANTES_GARAGE
#define RM_OCEAN_PARKING_GARAGE RM_DANTES_GARAGE
#define RM_PORTLAND_PARKING_GARAGE RM_DANTES_GARAGE
#define RM_PAINTER_LOT 1
#define RM_MULTNOMAH_GATE_NORTH 1
#define RM_MULTNOMAH_GATE_SOUTH 1

#define RM_JUNKYARD_GATES 70501
#define RM_JUNKYARD_PARTS 70502
#define RM_JUNKYARD_GLASS 70504
#define RM_JUNKYARD_APPLI 70505
#define RM_JUNKYARD_ELECT 70509
#define NUM_JUNKYARD_ROOMS 5

// This is specifically not included in the above since not every vehicle can leave it successfully. BIKES AND DRONES ONLY.
#define RM_JUNKYARD_BIKES 70508

// Objects, to remove the magic numbers from the code.
#define OBJ_NEWBIE_RADIO 60531
@@ -3984,8 +3984,8 @@ void purge_unowned_vehs() {

// This vehicle is owned by a valid player: Do not delete.
if (does_player_exist(veh->owner)) {
sprintf(buf, "Skipping vehicle '%s' (%ld) since its owner is a valid player.", veh->short_description, veh->idnum);
log(buf);
//sprintf(buf, "Skipping vehicle '%s' (%ld) since its owner is a valid player.", veh->short_description, veh->idnum);
//log(buf);

if (!prior_veh) {
break;
@@ -75,6 +75,7 @@ extern int modify_veh(struct veh_data *veh);
extern SPECIAL(shop_keeper);
extern void mob_magic(struct char_data *ch);
extern void cast_spell(struct char_data *ch, int spell, int sub, int force, char *arg);
extern char *get_player_name(vnum_t id);
/* Weapon attack texts */
struct attack_hit_type attack_hit_text[] =
{
@@ -5295,7 +5296,7 @@ void vcombat(struct char_data * ch, struct veh_data * veh)
veh->damage += damage_total;
if (veh->owner && !IS_NPC(ch))
{
sprintf(buf, "%s attacked vehicle (%s) owned by player.", GET_CHAR_NAME(ch), veh->name);
sprintf(buf, "%s attacked vehicle (%s) owned by player %s (%ld).", GET_CHAR_NAME(ch), GET_VEH_NAME(veh), get_player_name(veh->owner), veh->owner);
mudlog(buf, ch, LOG_WRECKLOG, TRUE);
}
chkdmg(veh);
@@ -738,6 +738,26 @@ void point_update(void)
ObjList.UpdateCounters();
}

vnum_t junkyard_room_numbers[] = {
RM_JUNKYARD_GATES, // Just Inside the Gates
RM_JUNKYARD_PARTS, // Rounding a Tottering Pile of Drone Parts
RM_JUNKYARD_GLASS, // Beside a Mound of Glass
RM_JUNKYARD_APPLI, // Amidst Aging Appliances
RM_JUNKYARD_ELECT // The Electronics Scrapheap
};

// Returns TRUE if vehicle is in one of the Junkyard vehicle-depositing rooms, FALSE otherwise.
bool veh_is_in_junkyard(struct veh_data *veh) {
if (!veh || !veh->in_room)
return FALSE;

for (int index = 0; index < NUM_JUNKYARD_ROOMS; index++)
if (veh->in_room->number == junkyard_room_numbers[index])
return TRUE;

return FALSE;
}

void save_vehicles(void)
{
struct veh_data *veh;
@@ -749,8 +769,7 @@ void save_vehicles(void)
int num_veh = 0;
bool found;
for (veh = veh_list; veh; veh = veh->next)
if ((veh->owner > 0 && (veh->damage < 10 || veh->in_veh || ROOM_FLAGGED(veh->in_room, ROOM_GARAGE))) &&
(does_player_exist(veh->owner)))
if ((veh->owner > 0 && (veh->damage < 10 || !veh_is_in_junkyard(veh) || veh->in_veh || ROOM_FLAGGED(veh->in_room, ROOM_GARAGE))) && (does_player_exist(veh->owner)))
num_veh++;

if (!(fl = fopen("veh/vfile", "w"))) {
@@ -760,8 +779,22 @@ void save_vehicles(void)
fprintf(fl, "%d\n", num_veh);
fclose(fl);
for (veh = veh_list, v = 0; veh && v < num_veh; veh = veh->next) {
if (veh->owner < 1 || (veh->damage >= 10 && !(veh->in_veh || ROOM_FLAGGED(veh->in_room, ROOM_GARAGE))))
// Skip NPC-owned vehicles and world vehicles.
if (veh->owner < 1)
continue;

bool send_veh_to_junkyard = FALSE;
if ((veh->damage >= 10 && !(veh->in_veh || ROOM_FLAGGED(veh->in_room, ROOM_GARAGE)))) {
// If the vehicle is wrecked and is in neither a containing vehicle nor a garage...
if (veh_is_in_junkyard(veh)) {
// If it's already in the junkyard, we don't save it-- they should have come and fixed it.
continue;
} else {
// If it's not in the junkyard yet, flag it for moving to the junkyard.
send_veh_to_junkyard = TRUE;
}
}

/* Disabling this code-- we want to save ownerless vehicles so that they can disgorge their contents when they load in next.
if (!does_player_exist(veh->owner)) {
veh->owner = 0;
@@ -790,32 +823,60 @@ void save_vehicles(void)
break;
}

temp_room = get_veh_in_room(veh);
if (!ROOM_FLAGGED(temp_room, ROOM_GARAGE))
switch (GET_JURISDICTION(veh->in_room)) {
case ZONE_PORTLAND:
switch (number(0, 2)) {
case 0:
temp_room = &world[real_room(RM_PORTLAND_PARKING_GARAGE)];
break;
case 1:
temp_room = &world[real_room(RM_PORTLAND_PARKING_GARAGE)];
break;
case 2:
temp_room = &world[real_room(RM_PORTLAND_PARKING_GARAGE)];
break;
}
if (send_veh_to_junkyard) {
// Pick a spot and put the vehicle there. Sort roughly based on type.
int junkyard_number;
switch (veh->type) {
case VEH_DRONE:
// Drones in the drone spot.
junkyard_number = RM_JUNKYARD_PARTS;
break;
case ZONE_SEATTLE:
temp_room = &world[real_room(RM_SEATTLE_PARKING_GARAGE)];
case VEH_BIKE:
// Bikes in the bike spot.
junkyard_number = RM_JUNKYARD_BIKES;
break;
case ZONE_CARIB:
temp_room = &world[real_room(RM_CARIB_PARKING_GARAGE)];
case VEH_CAR:
case VEH_TRUCK:
// Standard vehicles just inside the gates.
junkyard_number = RM_JUNKYARD_GATES;
break;
case ZONE_OCEAN:
temp_room = &world[real_room(RM_OCEAN_PARKING_GARAGE)];
default:
// Pick a random one to scatter them about.
junkyard_number = junkyard_room_numbers[number(0, NUM_JUNKYARD_ROOMS)];
break;
}
temp_room = &world[real_room(junkyard_number)];
} else {
// If veh is not in a garage, send it to a garage.
temp_room = get_veh_in_room(veh);
if (!ROOM_FLAGGED(temp_room, ROOM_GARAGE)) {
switch (GET_JURISDICTION(veh->in_room)) {
case ZONE_PORTLAND:
switch (number(0, 2)) {
case 0:
temp_room = &world[real_room(RM_PORTLAND_PARKING_GARAGE)];
break;
case 1:
temp_room = &world[real_room(RM_PORTLAND_PARKING_GARAGE)];
break;
case 2:
temp_room = &world[real_room(RM_PORTLAND_PARKING_GARAGE)];
break;
}
break;
case ZONE_SEATTLE:
temp_room = &world[real_room(RM_SEATTLE_PARKING_GARAGE)];
break;
case ZONE_CARIB:
temp_room = &world[real_room(RM_CARIB_PARKING_GARAGE)];
break;
case ZONE_OCEAN:
temp_room = &world[real_room(RM_OCEAN_PARKING_GARAGE)];
break;
}
}
}

fprintf(fl, "[VEHICLE]\n");
fprintf(fl, "\tVnum:\t%ld\n", veh_index[veh->veh_number].vnum);
fprintf(fl, "\tOwner:\t%ld\n", veh->owner);

0 comments on commit c345c40

Please sign in to comment.
You can’t perform that action at this time.