00001 /*************************************************************************** 00002 * File: mem.c * 00003 * * 00004 * Much time and thought has gone into this software and you are * 00005 * benefitting. We hope that you share your changes too. What goes * 00006 * around, comes around. * 00007 * * 00008 * This code was freely distributed with the The Isles 1.1 source code, * 00009 * and has been used here for OLC - OLC would not be what it is without * 00010 * all the previous coders who released their source code. * 00011 * * 00012 ***************************************************************************/ 00013 00014 00015 00016 #if defined(macintosh) 00017 #include <types.h> 00018 #else 00019 #include <sys/types.h> 00020 #endif 00021 #include <ctype.h> 00022 #include <stdio.h> 00023 #include <stdlib.h> 00024 #include <string.h> 00025 #include <time.h> 00026 #include "merc.h" 00027 00028 /* 00029 * Globals 00030 */ 00031 extern int top_reset; 00032 extern int top_area; 00033 extern int top_exit; 00034 extern int top_ed; 00035 extern int top_room; 00036 extern int top_mprog_index; 00037 00038 AREA_DATA *area_free; 00039 //OCLASS_DATA *class_free; 00040 EXTRA_DESCR_DATA *extra_descr_free; 00041 EXIT_DATA *exit_free; 00042 ROOM_INDEX_DATA *room_index_free; 00043 OBJ_INDEX_DATA *obj_index_free; 00044 SHOP_DATA *shop_free; 00045 MOB_INDEX_DATA *mob_index_free; 00046 RESET_DATA *reset_free; 00047 SOCIAL_LIST *social_free; 00048 //HELP_DATA *help_free; 00049 00050 //HELP_DATA *help_last; 00051 OCLASS_DATA *class_last; 00052 OCLASS_DATA *class_first; 00053 void free_extra_descr args ((EXTRA_DESCR_DATA * pExtra)); 00054 void free_affect args ((AFFECT_DATA * af)); 00055 void free_mprog args ((MPROG_LIST * mp)); 00056 00057 void add_social (SOCIAL_LIST *social) 00058 { 00059 00060 00061 social->next = sociallist; 00062 sociallist = social; 00063 00064 00065 00066 return; 00067 00068 00069 } 00070 00071 00072 SOCIAL_LIST *new_social(void) 00073 { 00074 SOCIAL_LIST *stemp; 00075 static SOCIAL_LIST sl; 00076 00077 if (social_free == NULL) 00078 { 00079 stemp = alloc_perm(sizeof(*stemp)); 00080 } 00081 else 00082 { 00083 stemp = social_free; 00084 social_free = social_free->next; 00085 } 00086 00087 *stemp = sl; 00088 stemp->name = NULL; 00089 stemp->char_no_arg = NULL; 00090 stemp->others_no_arg = NULL; 00091 stemp->char_found = NULL; 00092 stemp->others_found = NULL; 00093 stemp->vict_found = NULL; 00094 stemp->char_not_found = NULL; 00095 stemp->char_auto = NULL; 00096 stemp->others_auto = NULL; 00097 00098 00099 return stemp; 00100 } 00101 00102 void free_social(SOCIAL_LIST *sline) 00103 { 00104 free_string(sline->name); 00105 free_string(sline->char_no_arg); 00106 free_string(sline->others_no_arg); 00107 free_string(sline->char_found); 00108 free_string(sline->others_found); 00109 free_string(sline->vict_found); 00110 free_string(sline->char_not_found); 00111 free_string(sline->char_auto); 00112 free_string(sline->others_auto); 00113 00114 sline->next = social_free->next; 00115 sociallist = sline; 00116 } 00117 00118 00119 HELP_DATA *new_help(void) 00120 { 00121 HELP_DATA *NewHelp; 00122 NewHelp = alloc_perm(sizeof(*NewHelp) ); 00123 NewHelp->level = 0; 00124 NewHelp->keyword = str_dup(""); 00125 NewHelp->text = str_dup(""); 00126 NewHelp->next = NULL; 00127 return NewHelp; 00128 } 00129 00130 RESET_DATA *new_reset_data (void) 00131 { 00132 RESET_DATA *pReset; 00133 00134 if (!reset_free) 00135 { 00136 pReset = alloc_perm (sizeof (*pReset)); 00137 top_reset++; 00138 } 00139 else 00140 { 00141 pReset = reset_free; 00142 reset_free = reset_free->next; 00143 } 00144 00145 pReset->next = NULL; 00146 pReset->command = 'X'; 00147 pReset->arg1 = 0; 00148 pReset->arg2 = 0; 00149 pReset->arg3 = 0; 00150 pReset->arg4 = 0; 00151 00152 return pReset; 00153 } 00154 00155 00156 00157 void free_reset_data (RESET_DATA * pReset) 00158 { 00159 pReset->next = reset_free; 00160 reset_free = pReset; 00161 return; 00162 } 00163 00164 00165 00166 AREA_DATA *new_area (void) 00167 { 00168 AREA_DATA *pArea; 00169 char buf[MAX_INPUT_LENGTH]; 00170 00171 if (!area_free) 00172 { 00173 pArea = alloc_perm (sizeof (*pArea)); 00174 top_area++; 00175 } 00176 else 00177 { 00178 pArea = area_free; 00179 area_free = area_free->next; 00180 } 00181 00182 pArea->next = NULL; 00183 pArea->name = str_dup ("New area"); 00184 /* pArea->recall = ROOM_VNUM_TEMPLE; ROM OLC */ 00185 pArea->area_flags = AREA_ADDED; 00186 pArea->security = 1; 00187 pArea->builders = str_dup ("None"); 00188 pArea->min_vnum = 0; 00189 pArea->max_vnum = 0; 00190 pArea->age = 0; 00191 pArea->nplayer = 0; 00192 pArea->empty = TRUE; /* ROM patch */ 00193 sprintf (buf, "area%d.are", pArea->vnum); 00194 pArea->file_name = str_dup (buf); 00195 pArea->vnum = top_area - 1; 00196 00197 return pArea; 00198 } 00199 /*oCLASS_DATA *new_class(void) 00200 { 00201 OCLASS_DATA *pClass; 00202 // OCLASS_DATA *cClass; 00203 char buf[MAX_STRING_LENGTH]; 00204 if (!class_free) 00205 { 00206 bug("Class not free!\n\r",0); 00207 pClass = alloc_perm(sizeof(*pClass)); 00208 } 00209 else 00210 { 00211 pClass = class_free; 00212 class_free = class_free->next; 00213 } 00214 00215 //pClass = class_free; 00216 //class_free = class_free->next; 00217 // pClass = cClass; 00218 // cClass = cClass->next; 00219 00220 pClass->next = NULL; 00221 pClass->name = "Give me a name"; 00222 pClass->who_name = "Give me a whoname"; 00223 pClass->thac_0 = 0; 00224 pClass->thac_32 = 0; 00225 pClass->primary = 0; 00226 pClass->weapon = 0; 00227 pClass->guild1 = 0; 00228 pClass->guild2 = 0; 00229 pClass->skill = 0; 00230 pClass->minhp = 0; 00231 pClass->maxhp = 0; 00232 pClass->base = "Give me a base"; 00233 pClass->c_default = "Give me a default"; 00234 return pClass; 00235 } 00236 00237 00238 00239 */ 00240 void free_area (AREA_DATA * pArea) 00241 { 00242 free_string (pArea->name); 00243 free_string (pArea->file_name); 00244 free_string (pArea->builders); 00245 free_string (pArea->credits); 00246 00247 pArea->next = area_free->next; 00248 area_free = pArea; 00249 return; 00250 } 00251 00252 00253 00254 EXIT_DATA *new_exit (void) 00255 { 00256 EXIT_DATA *pExit; 00257 00258 if (!exit_free) 00259 { 00260 pExit = alloc_perm (sizeof (*pExit)); 00261 top_exit++; 00262 } 00263 else 00264 { 00265 pExit = exit_free; 00266 exit_free = exit_free->next; 00267 } 00268 00269 pExit->u1.to_room = NULL; /* ROM OLC */ 00270 pExit->next = NULL; 00271 /* pExit->vnum = 0; ROM OLC */ 00272 pExit->exit_info = 0; 00273 pExit->key = 0; 00274 pExit->keyword = &str_empty[0]; 00275 pExit->description = &str_empty[0]; 00276 pExit->rs_flags = 0; 00277 00278 return pExit; 00279 } 00280 00281 00282 00283 void free_exit (EXIT_DATA * pExit) 00284 { 00285 free_string (pExit->keyword); 00286 free_string (pExit->description); 00287 00288 pExit->next = exit_free; 00289 exit_free = pExit; 00290 return; 00291 } 00292 00293 00294 ROOM_INDEX_DATA *new_room_index (void) 00295 { 00296 ROOM_INDEX_DATA *pRoom; 00297 int door; 00298 00299 if (!room_index_free) 00300 { 00301 pRoom = alloc_perm (sizeof (*pRoom)); 00302 top_room++; 00303 } 00304 else 00305 { 00306 pRoom = room_index_free; 00307 room_index_free = room_index_free->next; 00308 } 00309 00310 pRoom->next = NULL; 00311 pRoom->people = NULL; 00312 pRoom->contents = NULL; 00313 pRoom->extra_descr = NULL; 00314 pRoom->area = NULL; 00315 00316 for (door = 0; door < MAX_DIR; door++) 00317 pRoom->exit[door] = NULL; 00318 00319 pRoom->name = &str_empty[0]; 00320 pRoom->description = &str_empty[0]; 00321 pRoom->owner = &str_empty[0]; 00322 pRoom->vnum = 0; 00323 pRoom->room_flags = 0; 00324 pRoom->light = 0; 00325 pRoom->sector_type = 0; 00326 pRoom->clan = 0; 00327 pRoom->heal_rate = 100; 00328 pRoom->mana_rate = 100; 00329 00330 return pRoom; 00331 } 00332 00333 00334 00335 void free_room_index (ROOM_INDEX_DATA * pRoom) 00336 { 00337 int door; 00338 EXTRA_DESCR_DATA *pExtra; 00339 RESET_DATA *pReset; 00340 00341 free_string (pRoom->name); 00342 free_string (pRoom->description); 00343 free_string (pRoom->owner); 00344 00345 for (door = 0; door < MAX_DIR; door++) 00346 { 00347 if (pRoom->exit[door]) 00348 free_exit (pRoom->exit[door]); 00349 } 00350 00351 for (pExtra = pRoom->extra_descr; pExtra; pExtra = pExtra->next) 00352 { 00353 free_extra_descr (pExtra); 00354 } 00355 00356 for (pReset = pRoom->reset_first; pReset; pReset = pReset->next) 00357 { 00358 free_reset_data (pReset); 00359 } 00360 00361 pRoom->next = room_index_free; 00362 room_index_free = pRoom; 00363 return; 00364 } 00365 00366 extern AFFECT_DATA *affect_free; 00367 00368 00369 SHOP_DATA *new_shop (void) 00370 { 00371 SHOP_DATA *pShop; 00372 int buy; 00373 00374 if (!shop_free) 00375 { 00376 pShop = alloc_perm (sizeof (*pShop)); 00377 top_shop++; 00378 } 00379 else 00380 { 00381 pShop = shop_free; 00382 shop_free = shop_free->next; 00383 } 00384 00385 pShop->next = NULL; 00386 pShop->keeper = 0; 00387 00388 for (buy = 0; buy < MAX_TRADE; buy++) 00389 pShop->buy_type[buy] = 0; 00390 00391 pShop->profit_buy = 100; 00392 pShop->profit_sell = 100; 00393 pShop->open_hour = 0; 00394 pShop->close_hour = 23; 00395 00396 return pShop; 00397 } 00398 00399 00400 00401 void free_shop (SHOP_DATA * pShop) 00402 { 00403 pShop->next = shop_free; 00404 shop_free = pShop; 00405 return; 00406 } 00407 00408 00409 00410 OBJ_INDEX_DATA *new_obj_index (void) 00411 { 00412 OBJ_INDEX_DATA *pObj; 00413 int value; 00414 00415 if (!obj_index_free) 00416 { 00417 pObj = alloc_perm (sizeof (*pObj)); 00418 top_obj_index++; 00419 } 00420 else 00421 { 00422 pObj = obj_index_free; 00423 obj_index_free = obj_index_free->next; 00424 } 00425 00426 pObj->next = NULL; 00427 pObj->extra_descr = NULL; 00428 pObj->affected = NULL; 00429 pObj->area = NULL; 00430 pObj->name = str_dup ("no name"); 00431 pObj->short_descr = str_dup ("(no short description)"); 00432 pObj->description = str_dup ("(no description)"); 00433 pObj->vnum = 0; 00434 pObj->item_type = ITEM_TRASH; 00435 pObj->extra_flags = 0; 00436 pObj->wear_flags = 0; 00437 pObj->count = 0; 00438 pObj->weight = 0; 00439 pObj->cost = 0; 00440 pObj->material = str_dup ("unknown"); /* ROM */ 00441 pObj->condition = 100; /* ROM */ 00442 for (value = 0; value < 5; value++) /* 5 - ROM */ 00443 pObj->value[value] = 0; 00444 00445 pObj->new_format = TRUE; /* ROM */ 00446 00447 return pObj; 00448 } 00449 00450 00451 00452 void free_obj_index (OBJ_INDEX_DATA * pObj) 00453 { 00454 EXTRA_DESCR_DATA *pExtra; 00455 AFFECT_DATA *pAf; 00456 00457 free_string (pObj->name); 00458 free_string (pObj->short_descr); 00459 free_string (pObj->description); 00460 00461 for (pAf = pObj->affected; pAf; pAf = pAf->next) 00462 { 00463 free_affect (pAf); 00464 } 00465 00466 for (pExtra = pObj->extra_descr; pExtra; pExtra = pExtra->next) 00467 { 00468 free_extra_descr (pExtra); 00469 } 00470 00471 pObj->next = obj_index_free; 00472 obj_index_free = pObj; 00473 return; 00474 } 00475 00476 00477 00478 MOB_INDEX_DATA *new_mob_index (void) 00479 { 00480 MOB_INDEX_DATA *pMob; 00481 00482 if (!mob_index_free) 00483 { 00484 pMob = alloc_perm (sizeof (*pMob)); 00485 top_mob_index++; 00486 } 00487 else 00488 { 00489 pMob = mob_index_free; 00490 mob_index_free = mob_index_free->next; 00491 } 00492 00493 pMob->next = NULL; 00494 pMob->spec_fun = NULL; 00495 pMob->pShop = NULL; 00496 pMob->area = NULL; 00497 pMob->player_name = str_dup ("no name"); 00498 pMob->short_descr = str_dup ("(no short description)"); 00499 pMob->long_descr = str_dup ("(no long description)\n\r"); 00500 pMob->description = &str_empty[0]; 00501 pMob->vnum = 0; 00502 pMob->count = 0; 00503 pMob->killed = 0; 00504 pMob->sex = 0; 00505 pMob->level = 0; 00506 pMob->act = ACT_IS_NPC; 00507 pMob->affected_by = 0; 00508 pMob->alignment = 0; 00509 pMob->hitroll = 0; 00510 pMob->race = race_lookup ("human"); /* - Hugin */ 00511 pMob->form = 0; /* ROM patch -- Hugin */ 00512 pMob->parts = 0; /* ROM patch -- Hugin */ 00513 pMob->imm_flags = 0; /* ROM patch -- Hugin */ 00514 pMob->res_flags = 0; /* ROM patch -- Hugin */ 00515 pMob->vuln_flags = 0; /* ROM patch -- Hugin */ 00516 pMob->material = str_dup ("unknown"); /* -- Hugin */ 00517 pMob->off_flags = 0; /* ROM patch -- Hugin */ 00518 pMob->size = SIZE_MEDIUM; /* ROM patch -- Hugin */ 00519 pMob->ac[AC_PIERCE] = 0; /* ROM patch -- Hugin */ 00520 pMob->ac[AC_BASH] = 0; /* ROM patch -- Hugin */ 00521 pMob->ac[AC_SLASH] = 0; /* ROM patch -- Hugin */ 00522 pMob->ac[AC_EXOTIC] = 0; /* ROM patch -- Hugin */ 00523 pMob->hit[DICE_NUMBER] = 0; /* ROM patch -- Hugin */ 00524 pMob->hit[DICE_TYPE] = 0; /* ROM patch -- Hugin */ 00525 pMob->hit[DICE_BONUS] = 0; /* ROM patch -- Hugin */ 00526 pMob->mana[DICE_NUMBER] = 0; /* ROM patch -- Hugin */ 00527 pMob->mana[DICE_TYPE] = 0; /* ROM patch -- Hugin */ 00528 pMob->mana[DICE_BONUS] = 0; /* ROM patch -- Hugin */ 00529 pMob->damage[DICE_NUMBER] = 0; /* ROM patch -- Hugin */ 00530 pMob->damage[DICE_TYPE] = 0; /* ROM patch -- Hugin */ 00531 pMob->damage[DICE_NUMBER] = 0; /* ROM patch -- Hugin */ 00532 pMob->start_pos = POS_STANDING; /* -- Hugin */ 00533 pMob->default_pos = POS_STANDING; /* -- Hugin */ 00534 pMob->wealth = 0; 00535 00536 pMob->new_format = TRUE; /* ROM */ 00537 00538 return pMob; 00539 } 00540 00541 00542 00543 void free_mob_index (MOB_INDEX_DATA * pMob) 00544 { 00545 free_string (pMob->player_name); 00546 free_string (pMob->short_descr); 00547 free_string (pMob->long_descr); 00548 free_string (pMob->description); 00549 free_mprog (pMob->mprogs); 00550 00551 free_shop (pMob->pShop); 00552 00553 pMob->next = mob_index_free; 00554 mob_index_free = pMob; 00555 return; 00556 } 00557 00558 MPROG_CODE *mpcode_free; 00559 00560 MPROG_CODE *new_mpcode (void) 00561 { 00562 MPROG_CODE *NewCode; 00563 00564 if (!mpcode_free) 00565 { 00566 NewCode = alloc_perm (sizeof (*NewCode)); 00567 top_mprog_index++; 00568 } 00569 else 00570 { 00571 NewCode = mpcode_free; 00572 mpcode_free = mpcode_free->next; 00573 } 00574 00575 NewCode->vnum = 0; 00576 NewCode->code = str_dup (""); 00577 NewCode->next = NULL; 00578 00579 return NewCode; 00580 } 00581 00582 void free_mpcode (MPROG_CODE * pMcode) 00583 { 00584 free_string (pMcode->code); 00585 pMcode->next = mpcode_free; 00586 mpcode_free = pMcode; 00587 return; 00588 }
1.4.0