00001
00018
00019
00020 #include "lev_data.h"
00021
00022 #include <math.h>
00023 #include <time.h>
00024 #include "globals.h"
00025 #include "obj_column_def.h"
00026 #include "obj_slabs.h"
00027 #include "obj_things.h"
00028 #include "obj_column.h"
00029 #include "lev_script.h"
00030 #include "draw_map.h"
00031
00032 const int idir_subtl_x[]={
00033 0, 1, 2,
00034 0, 1, 2,
00035 0, 1, 2,};
00036
00037 const int idir_subtl_y[]={
00038 0, 0, 0,
00039 1, 1, 1,
00040 2, 2, 2,};
00041
00042 const char default_map_name[]="Unnamed %Y.%m.%d map";
00043
00053 short level_init(struct LEVEL **lvl_ptr,short map_version,struct UPOINT_3D *lvl_size)
00054 {
00055 message_log(" level_init: started");
00056 (*lvl_ptr)=(struct LEVEL *)malloc(sizeof(struct LEVEL));
00057 struct LEVEL *lvl;
00058 lvl=(*lvl_ptr);
00059 if (lvl==NULL)
00060 {
00061 message_error("level_init: Cannot alloc memory for level");
00062 return false;
00063 }
00064 lvl->format_version=map_version;
00065
00066 lvl->fname=(char *)malloc(DISKPATH_SIZE*sizeof(char));
00067 memset(lvl->fname,0,DISKPATH_SIZE*sizeof(char));
00068 lvl->savfname=(char *)malloc(DISKPATH_SIZE*sizeof(char));
00069 memset(lvl->savfname,0,DISKPATH_SIZE*sizeof(char));
00070
00071
00072
00073 if ((lvl->format_version!=MFV_DKSTD)&&(lvl->format_version!=MFV_DKGOLD)&&(lvl_size!=NULL))
00074 {
00075 lvl->tlsize.x=lvl_size->x;
00076 lvl->tlsize.y=lvl_size->y;
00077 } else
00078 {
00079 lvl->tlsize.x=MAP_SIZE_DKSTD_X;
00080 lvl->tlsize.y=MAP_SIZE_DKSTD_Y;
00081 }
00082 lvl->subsize.x=lvl->tlsize.x*MAP_SUBNUM_X+1;
00083 lvl->subsize.y=lvl->tlsize.y*MAP_SUBNUM_Y+1;
00084
00085 const int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
00086 const int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
00087
00088 {
00089 lvl->clm = (unsigned char **)malloc(COLUMN_ENTRIES*sizeof(char *));
00090 if (lvl->clm==NULL)
00091 {
00092 message_error("level_init: Cannot alloc clm memory");
00093 return false;
00094 }
00095 int i;
00096 for (i=0; i<COLUMN_ENTRIES; i++)
00097 {
00098 lvl->clm[i]=(unsigned char *)malloc(SIZEOF_DK_CLM_REC);
00099 if (lvl->clm[i]==NULL)
00100 {
00101 message_error("level_init: Cannot alloc clm entries");
00102 return false;
00103 }
00104 }
00105 lvl->clm_hdr=(unsigned char *)malloc(SIZEOF_DK_CLM_HEADER);
00106 lvl->clm_utilize=(unsigned int *)malloc(COLUMN_ENTRIES*sizeof(unsigned int *));
00107 }
00108 {
00109 int i;
00110 lvl->slb = (unsigned short **)malloc(lvl->tlsize.y*sizeof(unsigned short *));
00111 if (lvl->slb==NULL)
00112 {
00113 message_error("level_init: Cannot alloc slb memory");
00114 return false;
00115 }
00116 for (i=0; i < lvl->tlsize.y; i++)
00117 {
00118 lvl->slb[i] = (unsigned short *)malloc(lvl->tlsize.x*sizeof(unsigned short));
00119 if (lvl->slb[i]==NULL)
00120 {
00121 message_error("level_init: Cannot alloc slb entries");
00122 return false;
00123 }
00124 }
00125 }
00126 {
00127 int i;
00128 lvl->own = (unsigned char **)malloc(lvl->subsize.y*sizeof(char *));
00129 if (lvl->own==NULL)
00130 {
00131 message_error("level_init: Cannot alloc own memory");
00132 return false;
00133 }
00134 for (i=0; i < lvl->subsize.y; i++)
00135 {
00136 lvl->own[i] = (unsigned char *)malloc(lvl->subsize.x*sizeof(char));
00137 if (lvl->own[i]==NULL)
00138 {
00139 message_error("level_init: Cannot alloc own entries");
00140 return false;
00141 }
00142 }
00143 }
00144 {
00145 lvl->dat= (unsigned short **)malloc(lvl->subsize.y*sizeof(short *));
00146 if (lvl->dat==NULL)
00147 {
00148 message_error("level_init: Cannot alloc dat memory");
00149 return false;
00150 }
00151 int i;
00152 for (i=0; i < lvl->subsize.y; i++)
00153 {
00154 lvl->dat[i]= (unsigned short *)malloc(lvl->subsize.x*sizeof(unsigned short));
00155 if (lvl->dat[i]==NULL)
00156 {
00157 message_error("level_init: Cannot alloc dat entries");
00158 return false;
00159 }
00160 }
00161 }
00162 {
00163 lvl->wib= (unsigned char **)malloc(lvl->subsize.y*sizeof(char *));
00164 if (lvl->wib==NULL)
00165 {
00166 message_error("level_init: Cannot alloc wib memory");
00167 return false;
00168 }
00169 int i;
00170 for (i=0; i < lvl->subsize.y; i++)
00171 {
00172 lvl->wib[i]= (unsigned char *)malloc(lvl->subsize.x*sizeof(char));
00173 if (lvl->wib[i]==NULL)
00174 {
00175 message_error("level_init: Cannot alloc wib entries");
00176 return false;
00177 }
00178 }
00179 }
00180 {
00181 lvl->flg= (unsigned short **)malloc(lvl->subsize.y*sizeof(short *));
00182 if (lvl->flg==NULL)
00183 {
00184 message_error("level_init: Cannot alloc flg memory");
00185 return false;
00186 }
00187 int i;
00188 for (i=0; i < lvl->subsize.y; i++)
00189 {
00190 lvl->flg[i]= (unsigned short *)malloc(lvl->subsize.x*sizeof(unsigned short));
00191 if (lvl->flg[i]==NULL)
00192 {
00193 message_error("level_init: Cannot alloc flg entries");
00194 return false;
00195 }
00196 }
00197 }
00198 {
00199 int i;
00200 lvl->tng_apt_lgt_nums = (unsigned short **)malloc(lvl->tlsize.y*sizeof(unsigned short *));
00201 if (lvl->tng_apt_lgt_nums==NULL)
00202 {
00203 message_error("level_init: Cannot alloc apt memory");
00204 return false;
00205 }
00206 for (i=0; i<lvl->tlsize.y; i++)
00207 {
00208 lvl->tng_apt_lgt_nums[i]= (unsigned short *)malloc(lvl->tlsize.x*sizeof(unsigned short));
00209 if (lvl->tng_apt_lgt_nums[i]==NULL)
00210 {
00211 message_error("level_init: Cannot alloc apt entries");
00212 return false;
00213 }
00214 }
00215 }
00216 {
00217 lvl->tng_lookup = (unsigned char ****)malloc(arr_entries_y*sizeof(unsigned char ***));
00218 lvl->tng_subnums= (unsigned short **)malloc(arr_entries_y*sizeof(unsigned short *));
00219 if ((lvl->tng_lookup==NULL) || (lvl->tng_subnums==NULL))
00220 {
00221 message_error("level_init: Cannot alloc tng memory");
00222 return false;
00223 }
00224 int i;
00225 for (i=0; i<arr_entries_y; i++)
00226 {
00227 lvl->tng_lookup[i]=(unsigned char ***)malloc (arr_entries_x*sizeof(unsigned char **));
00228 lvl->tng_subnums[i]=(unsigned short *)malloc (arr_entries_x*sizeof(unsigned short));
00229 if ((lvl->tng_lookup[i]==NULL) || (lvl->tng_subnums[i]==NULL))
00230 {
00231 message_error("level_init: Cannot alloc tng subnums");
00232 return false;
00233 }
00234 }
00235 }
00236 {
00237 lvl->apt_lookup = (unsigned char ****)malloc(arr_entries_y*sizeof(unsigned char ***));
00238 lvl->apt_subnums= (unsigned short **)malloc(arr_entries_y*sizeof(unsigned short *));
00239 if ((lvl->apt_lookup==NULL) || (lvl->apt_subnums==NULL))
00240 {
00241 message_error("level_init: Cannot alloc apt lookup");
00242 return false;
00243 }
00244 int i;
00245 for (i=0; i<arr_entries_y; i++)
00246 {
00247 lvl->apt_lookup[i]=(unsigned char ***)malloc (arr_entries_x*sizeof(unsigned char **));
00248 lvl->apt_subnums[i]=(unsigned short *)malloc (arr_entries_x*sizeof(unsigned short));
00249 if ((lvl->apt_lookup[i]==NULL) || (lvl->apt_subnums[i]==NULL))
00250 {
00251 message_error("level_init: Cannot alloc apt entries");
00252 return false;
00253 }
00254 }
00255 }
00256 {
00257 lvl->lgt_lookup = (unsigned char ****)malloc(arr_entries_y*sizeof(unsigned char ***));
00258 lvl->lgt_subnums= (unsigned short **)malloc(arr_entries_y*sizeof(unsigned short *));
00259 if ((lvl->lgt_lookup==NULL) || (lvl->lgt_subnums==NULL))
00260 {
00261 message_error("level_init: Cannot alloc lgt lookup");
00262 return false;
00263 }
00264 int i;
00265 for (i=0; i<arr_entries_y; i++)
00266 {
00267 lvl->lgt_lookup[i]=(unsigned char ***)malloc (arr_entries_x*sizeof(unsigned char **));
00268 lvl->lgt_subnums[i]=(unsigned short *)malloc (arr_entries_x*sizeof(unsigned short));
00269 if ((lvl->lgt_lookup[i]==NULL) || (lvl->lgt_subnums[i]==NULL))
00270 {
00271 message_error("level_init: Cannot alloc lgt entries");
00272 return false;
00273 }
00274 }
00275 }
00276 {
00277 lvl->wlb = (unsigned char **)malloc(lvl->tlsize.y*sizeof(unsigned char *));
00278 if (lvl->wlb==NULL)
00279 {
00280 message_error("level_init: Cannot alloc wlb memory");
00281 return false;
00282 }
00283 int i;
00284 for (i=0; i<lvl->tlsize.y; i++)
00285 {
00286 lvl->wlb[i]=(unsigned char *)malloc(lvl->tlsize.x*sizeof(unsigned char));
00287 if (lvl->wlb[i]==NULL)
00288 {
00289 message_error("level_init: Cannot alloc wlb entries");
00290 return false;
00291 }
00292 }
00293 }
00294 {
00295 int idx;
00296 lvl->script.par.player=(struct DK_SCRIPT_PLAYER *)malloc(PLAYERS_COUNT*sizeof(struct DK_SCRIPT_PLAYER));
00297 lvl->script.par.creature_pool=(unsigned int *)malloc(creatures_cmd_arrsize()*sizeof(unsigned int));
00298 if ((lvl->script.par.player==NULL)||(lvl->script.par.creature_pool==NULL))
00299 {
00300 message_error("level_init: Cannot alloc script params memory");
00301 return false;
00302 }
00303
00304 for (idx=0;idx<PLAYERS_COUNT;idx++)
00305 {
00306 lvl->script.par.player[idx].ally=(unsigned short *)malloc(PLAYERS_COUNT*sizeof(unsigned short));
00307 lvl->script.par.player[idx].creature_avail=(unsigned short *)malloc(creatures_cmd_arrsize()*sizeof(unsigned short));
00308 lvl->script.par.player[idx].creature_maxlvl=(int *)malloc(creatures_cmd_arrsize()*sizeof(int));
00309 lvl->script.par.player[idx].room_avail=(unsigned short *)malloc(room_cmd_arrsize()*sizeof(unsigned short));
00310 lvl->script.par.player[idx].spell_avail=(unsigned short *)malloc(spell_cmd_arrsize()*sizeof(unsigned short));
00311 lvl->script.par.player[idx].trap_avail=(unsigned short *)malloc(trap_cmd_arrsize()*sizeof(unsigned short));
00312 lvl->script.par.player[idx].door_avail=(unsigned short *)malloc(door_cmd_arrsize()*sizeof(unsigned short));
00313 lvl->script.par.player[idx].trap_amount=(unsigned int *)malloc(trap_cmd_arrsize()*sizeof(unsigned int));
00314 lvl->script.par.player[idx].door_amount=(unsigned int *)malloc(door_cmd_arrsize()*sizeof(unsigned int));
00315 if ((lvl->script.par.player[idx].ally==NULL)||(lvl->script.par.player[idx].creature_avail==NULL)||
00316 (lvl->script.par.player[idx].creature_maxlvl==NULL)||
00317 (lvl->script.par.player[idx].room_avail==NULL)||(lvl->script.par.player[idx].spell_avail==NULL)||
00318 (lvl->script.par.player[idx].trap_avail==NULL)||(lvl->script.par.player[idx].door_avail==NULL)||
00319 (lvl->script.par.player[idx].trap_amount==NULL)||(lvl->script.par.player[idx].door_amount==NULL))
00320 {
00321 message_error("level_init: Cannot alloc script params entries");
00322 return false;
00323 }
00324 }
00325 }
00326 {
00327 lvl->cust_clm_lookup= (struct DK_CUSTOM_CLM ***)malloc(lvl->subsize.y*sizeof(struct DK_CUSTOM_CLM **));
00328 if (lvl->cust_clm_lookup==NULL)
00329 {
00330 message_error("level_init: Cannot alloc clm memory");
00331 return false;
00332 }
00333 int i;
00334 for (i=0; i < lvl->subsize.y; i++)
00335 {
00336 lvl->cust_clm_lookup[i]= (struct DK_CUSTOM_CLM **)malloc(lvl->subsize.x*sizeof(struct DK_CUSTOM_CLM *));
00337 if (lvl->cust_clm_lookup[i]==NULL)
00338 {
00339 message_error("level_init: Cannot alloc clm lookup");
00340 return false;
00341 }
00342 }
00343 }
00344 message_log(" level_init: finished, now clearing");
00345 level_clear_options(&(lvl->optns));
00346 return level_clear(lvl);
00347 }
00348
00357 short level_set_size(struct LEVEL *lvl,struct UPOINT_3D *lvl_size)
00358 {
00359 message_log(" level_set_size: started");
00360 if (lvl==NULL)
00361 {
00362 message_error("level_set_size: Level structure doesn't exist");
00363 return false;
00364 }
00365 lvl->tlsize.x=lvl_size->x;
00366 lvl->tlsize.y=lvl_size->y;
00367 lvl->subsize.x=lvl->tlsize.x*MAP_SUBNUM_X+1;
00368 lvl->subsize.y=lvl->tlsize.y*MAP_SUBNUM_Y+1;
00369
00370 message_log(" level_set_size: finished");
00371 return true;
00372 }
00373
00380 short level_clear_options(struct LEVOPTIONS *optns)
00381 {
00382 optns->unaffected_gems=false;
00383 optns->unaffected_rock=false;
00384 optns->fill_reinforced_corner=true;
00385 optns->frail_columns=true;
00386 optns->datclm_auto_update=true;
00387 optns->obj_auto_update=true;
00388 optns->levels_path=NULL;
00389 optns->data_path=NULL;
00390 optns->load_redundant_objects=true;
00391 optns->verify_warn_flags=VWFLAG_NONE;
00392 optns->picture.rescale=4;
00393 optns->picture.data_path=NULL;
00394 optns->picture.bmfonts=BMFONT_DONT_LOAD;
00395 optns->picture.tngflags=TNGFLG_NONE;
00396 optns->script.level_spaces=4;
00397 return ERR_NONE;
00398 }
00399
00407 short level_set_options(struct LEVEL *lvl,struct LEVOPTIONS *optns)
00408 {
00409 memcpy(&(lvl->optns),optns,sizeof(struct LEVOPTIONS));
00410 lvl->optns.picture.data_path=lvl->optns.data_path;
00411 return ERR_NONE;
00412 }
00413
00420 struct LEVOPTIONS *level_get_options(struct LEVEL *lvl)
00421 {
00422 return &(lvl->optns);
00423 }
00424
00433 short level_set_mapdraw_options(struct LEVEL *lvl,struct MAPDRAW_OPTIONS *mdrwopts)
00434 {
00435 memcpy(&(lvl->optns.picture),mdrwopts,sizeof(struct MAPDRAW_OPTIONS));
00436 lvl->optns.picture.data_path=lvl->optns.data_path;
00437 return ERR_NONE;
00438 }
00439
00446 struct MAPDRAW_OPTIONS *level_get_mapdraw_options(struct LEVEL *lvl)
00447 {
00448 return &(lvl->optns.picture);
00449 }
00450
00457 short level_clear_tng(struct LEVEL *lvl)
00458 {
00459
00460 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
00461 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
00462
00463 lvl->tng_total_count=0;
00464
00465 int i,j;
00466 for (i=0; i<arr_entries_y; i++)
00467 for (j=0; j<arr_entries_x; j++)
00468 {
00469 lvl->tng_lookup[i][j]=NULL;
00470 lvl->tng_subnums[i][j]=0;
00471 }
00472 for (i=0; i<lvl->tlsize.y; i++)
00473 for (j=0; j<lvl->tlsize.x; j++)
00474 lvl->tng_apt_lgt_nums[i][j]=0;
00475
00476
00477 lvl->stats.hero_gates_count=0;
00478 return true;
00479 }
00480
00487 short level_clear_apt(struct LEVEL *lvl)
00488 {
00489
00490 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
00491 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
00492
00493 lvl->apt_total_count=0;
00494
00495 int i,j;
00496 for (i=0; i<arr_entries_y; i++)
00497 for (j=0; j<arr_entries_x; j++)
00498 {
00499 lvl->apt_lookup[i][j]=NULL;
00500 lvl->apt_subnums[i][j]=0;
00501 }
00502 return true;
00503 }
00504
00511 short level_clear_lgt(struct LEVEL *lvl)
00512 {
00513
00514 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
00515 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
00516
00517 lvl->lgt_total_count=0;
00518
00519 int i,j;
00520 for (i=0; i<arr_entries_y; i++)
00521 for (j=0; j<arr_entries_x; j++)
00522 {
00523 lvl->lgt_lookup[i][j]=NULL;
00524 lvl->lgt_subnums[i][j]=0;
00525 }
00526 return true;
00527 }
00528
00535 short level_clear_datclm(struct LEVEL *lvl)
00536 {
00537
00538 const int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
00539 const int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
00540
00541
00542 int i,k;
00543 for (i=0; i<COLUMN_ENTRIES; i++)
00544 {
00545 lvl->clm_utilize[i]=0;
00546 clear_clm_entry(lvl->clm[i]);
00547 }
00548
00549 memset(lvl->clm_hdr,0,SIZEOF_DK_CLM_HEADER);
00550 write_int32_le_buf(lvl->clm_hdr+0,COLUMN_ENTRIES);
00551
00552
00553 for (k=0; k<lvl->subsize.y; k++)
00554 for (i=0; i<lvl->subsize.x; i++)
00555 {
00556 set_dat_subtile(lvl, i, k, 0);
00557 lvl->clm_utilize[0]++;
00558 }
00559
00560
00561 unsigned char *clmentry;
00562 struct COLUMN_REC *clm_rec;
00563 clm_rec=create_column_rec();
00564
00565 clmentry = (unsigned char *)(lvl->clm[0]);
00566 fill_column_rec_sim(clm_rec,lvl->clm_utilize[0], 0, 0, 0, 0, 0, 0, 0, 0, 0);
00567 set_clm_entry(clmentry, clm_rec);
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578 free_column_rec(clm_rec);
00579 return true;
00580 }
00581
00587 short level_clear_stats(struct LEVEL *lvl)
00588 {
00589 lvl->stats.creatures_count=0;
00590 lvl->stats.effectgenrts_count=0;
00591 lvl->stats.traps_count=0;
00592 lvl->stats.doors_count=0;
00593 lvl->stats.items_count=0;
00594
00595 lvl->stats.hero_gates_count=0;
00596 lvl->stats.dn_hearts_count=0;
00597 int i;
00598 for (i=0;i<THING_CATEGR_COUNT;i++)
00599 lvl->stats.things_count[i]=0;
00600
00601 lvl->stats.room_things_count=0;
00602
00603 lvl->stats.things_removed=0;
00604 lvl->stats.things_added=0;
00605
00606 lvl->stats.saves_count=0;
00607
00608 lvl->stats.unsaved_changes=0;
00609 return true;
00610 }
00611
00617 short level_clear_info(struct LEVEL *lvl)
00618 {
00619
00620 lvl->info.usr_cmds_count=0;
00621 lvl->info.usr_mdswtch_count=0;
00622 lvl->info.usr_slbchng_count=0;
00623 lvl->info.usr_creatobj_count=0;
00624
00625 lvl->info.creat_date=time(NULL);
00626 lvl->info.lastsav_date=lvl->info.creat_date;
00627
00628 lvl->info.ver_major=0;
00629 lvl->info.ver_minor=0;
00630 lvl->info.ver_rel=0;
00631 int name_len=strlen(default_map_name)+10;
00632 char *name_text=malloc(name_len);
00633 if (name_text!=NULL)
00634 strftime(name_text,name_len, default_map_name, localtime(&(lvl->info.creat_date)) );
00635 lvl->info.name_text=name_text;
00636 lvl->info.desc_text=NULL;
00637 lvl->info.author_text=NULL;
00638 lvl->info.editor_text=NULL;
00639 return true;
00640 }
00641
00647 short level_clear_script(struct LEVEL *lvl)
00648 {
00649 message_log(" level_clear_script: started");
00650 lvl->script.list=NULL;
00651 lvl->script.txt=NULL;
00652 lvl->script.lines_count=0;
00653
00654 return level_clear_script_param(&(lvl->script.par));
00655 }
00656
00662 short level_clear_script_param(struct DK_SCRIPT_PARAMETERS *par)
00663 {
00664 par->portal_gen_speed=600;
00665 par->end_level=0;
00666 int i;
00667 int max_idx;
00668 for (i=0;i<PLAYERS_COUNT;i++)
00669 {
00670
00671 par->player[i].max_creatures=0;
00672 par->player[i].start_gold=0;
00673 par->player[i].computer_player=-1;
00674
00675 int k;
00676 for (k=0;k<PLAYERS_COUNT;k++)
00677 {
00678 par->player[i].ally[k]=false;
00679 }
00680 max_idx=creatures_cmd_arrsize();
00681 for (k=0;k<max_idx;k++)
00682 {
00683 par->player[i].creature_avail[k]=AVAIL_NO;
00684 par->player[i].creature_maxlvl[k]=-1;
00685 }
00686 max_idx=trap_cmd_arrsize();
00687 for (k=0;k<max_idx;k++)
00688 {
00689 par->player[i].trap_avail[k]=AVAIL_NO;
00690 par->player[i].trap_amount[k]=0;
00691 }
00692 max_idx=door_cmd_arrsize();
00693 for (k=0;k<max_idx;k++)
00694 {
00695 par->player[i].door_avail[k]=AVAIL_NO;
00696 par->player[i].door_amount[k]=0;
00697 }
00698 max_idx=room_cmd_arrsize();
00699 for (k=0;k<max_idx;k++)
00700 {
00701 par->player[i].room_avail[k]=AVAIL_NO;
00702 }
00703 max_idx=spell_cmd_arrsize();
00704 for (k=0;k<max_idx;k++)
00705 {
00706 par->player[i].spell_avail[k]=AVAIL_NO;
00707 }
00708 }
00709 max_idx=creatures_cmd_arrsize();
00710 for (i=0;i<max_idx;i++)
00711 par->creature_pool[i]=0;
00712 return true;
00713 }
00714
00723 short level_clear_other(struct LEVEL *lvl)
00724 {
00725
00726 const int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
00727 const int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
00728
00729 int i;
00730 for (i=0; i < lvl->tlsize.y; i++)
00731 {
00732 if (lvl->slb[i]!=NULL)
00733 memset(lvl->slb[i],0,lvl->tlsize.x*sizeof(unsigned short));
00734 }
00735 for (i=0; i < lvl->subsize.y; i++)
00736 {
00737 if (lvl->own[i]!=NULL)
00738 memset(lvl->own[i],PLAYER_UNSET,lvl->subsize.x*sizeof(char));
00739 }
00740
00741 for (i=0; i < lvl->subsize.y; i++)
00742 {
00743 if (lvl->dat[i]!=NULL)
00744 memset(lvl->dat[i],0,lvl->subsize.x*sizeof(unsigned short));
00745 }
00746
00747 for (i=0; i < lvl->subsize.y; i++)
00748 {
00749 if (lvl->wib[i]!=NULL)
00750 memset(lvl->wib[i],COLUMN_WIB_SKEW,lvl->subsize.x*sizeof(char));
00751 }
00752
00753 for (i=0; i < lvl->subsize.y; i++)
00754 {
00755 if (lvl->flg[i]!=NULL)
00756 memset(lvl->flg[i],0,lvl->subsize.x*sizeof(unsigned short));
00757 }
00758
00759 for (i=0; i < lvl->tlsize.y; i++)
00760 {
00761 if (lvl->wlb[i]!=NULL)
00762 memset(lvl->wlb[i],0,lvl->tlsize.x*sizeof(char));
00763 }
00764
00765
00766 lvl->inf=0x00;
00767
00768
00769 if (lvl->cust_clm_lookup!=NULL)
00770 {
00771 for (i=0; i < lvl->subsize.y; i++)
00772 {
00773 if (lvl->cust_clm_lookup[i]!=NULL)
00774 memset(lvl->cust_clm_lookup[i],0,lvl->subsize.x*sizeof(struct DK_CUSTOM_CLM *));
00775 }
00776 }
00777 lvl->cust_clm_count=0;
00778 lvl->graffiti=NULL;
00779 lvl->graffiti_count=0;
00780 return true;
00781 }
00782
00790 short level_clear(struct LEVEL *lvl)
00791 {
00792 message_log(" level_clear: started");
00793 short result=true;
00794 result&=level_clear_lgt(lvl);
00795 result&=level_clear_apt(lvl);
00796 result&=level_clear_tng(lvl);
00797 result&=level_clear_datclm(lvl);
00798 result&=level_clear_stats(lvl);
00799 result&=level_clear_info(lvl);
00800 result&=level_clear_script(lvl);
00801 result&=level_clear_other(lvl);
00802 message_log(" level_clear: finished");
00803 return result;
00804 }
00805
00811 short level_free_script_param(struct DK_SCRIPT_PARAMETERS *par)
00812 {
00813 message_log(" level_free_script_param: starting");
00814 int idx;
00815 free(par->creature_pool);
00816
00817
00818 for (idx=0;idx<PLAYERS_COUNT;idx++)
00819 {
00820 free(par->player[idx].ally);
00821 free(par->player[idx].creature_avail);
00822 free(par->player[idx].creature_maxlvl);
00823 free(par->player[idx].room_avail);
00824 free(par->player[idx].spell_avail);
00825 free(par->player[idx].trap_avail);
00826 free(par->player[idx].door_avail);
00827 free(par->player[idx].trap_amount);
00828 free(par->player[idx].door_amount);
00829 }
00830 free(par->player);
00831 return true;
00832 }
00833
00842 short level_deinit(struct LEVEL **lvl_ptr)
00843 {
00844 message_log(" level_deinit: started");
00845 if ((lvl_ptr==NULL)||((*lvl_ptr)==NULL))
00846 return false;
00847 struct LEVEL *lvl;
00848 lvl=(*lvl_ptr);
00849
00850 const int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
00851 const int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
00852
00853
00854 if (lvl->slb!=NULL)
00855 {
00856 int i;
00857 for (i=0; i<lvl->tlsize.y; i++)
00858 free(lvl->slb[i]);
00859 free(lvl->slb);
00860 }
00861
00862
00863 if (lvl->own!=NULL)
00864 {
00865 int i;
00866 for (i=0; i<lvl->subsize.y; i++)
00867 free(lvl->own[i]);
00868 free(lvl->own);
00869 }
00870
00871
00872 if (lvl->dat!=NULL)
00873 {
00874 int i;
00875 for (i=0; i<lvl->subsize.y; i++)
00876 free(lvl->dat[i]);
00877 free (lvl->dat);
00878 }
00879
00880
00881 if (lvl->wib!=NULL)
00882 {
00883 int i;
00884 for (i=0; i<lvl->subsize.y; i++)
00885 free(lvl->wib[i]);
00886 free (lvl->wib);
00887 }
00888
00889
00890 if (lvl->flg!=NULL)
00891 {
00892 int i;
00893 for (i=0; i<lvl->subsize.y; i++)
00894 free(lvl->flg[i]);
00895 free (lvl->flg);
00896 }
00897
00898
00899 if (lvl->tng_apt_lgt_nums!=NULL)
00900 {
00901 int i;
00902 for (i=0; i<lvl->tlsize.y; i++)
00903 free(lvl->tng_apt_lgt_nums[i]);
00904 free(lvl->tng_apt_lgt_nums);
00905 }
00906 if (lvl->tng_lookup!=NULL)
00907 {
00908 int i;
00909 for (i=0; i<arr_entries_y; i++)
00910 free(lvl->tng_lookup[i]);
00911 free(lvl->tng_lookup);
00912 }
00913 if (lvl->tng_subnums!=NULL)
00914 {
00915 int i;
00916 for (i=0; i<arr_entries_y; i++)
00917 free(lvl->tng_subnums[i]);
00918 free(lvl->tng_subnums);
00919 }
00920
00921
00922 if (lvl->apt_lookup!=NULL)
00923 {
00924 int i;
00925 for (i=0; i<arr_entries_y; i++)
00926 free(lvl->apt_lookup[i]);
00927 free(lvl->apt_lookup);
00928 }
00929 if (lvl->apt_subnums!=NULL)
00930 {
00931 int i;
00932 for (i=0; i<arr_entries_y; i++)
00933 free(lvl->apt_subnums[i]);
00934 free(lvl->apt_subnums);
00935 }
00936
00937
00938 if (lvl->lgt_lookup!=NULL)
00939 {
00940 int i;
00941 for (i=0; i<arr_entries_y; i++)
00942 free(lvl->lgt_lookup[i]);
00943 free(lvl->lgt_lookup);
00944 }
00945 if (lvl->lgt_subnums!=NULL)
00946 {
00947 int i;
00948 for (i=0; i<arr_entries_y; i++)
00949 free(lvl->lgt_subnums[i]);
00950 free(lvl->lgt_subnums);
00951 }
00952
00953
00954 if (lvl->clm!=NULL)
00955 {
00956 int i;
00957 for (i=0; i<COLUMN_ENTRIES; i++)
00958 free (lvl->clm[i]);
00959 free(lvl->clm);
00960 free(lvl->clm_hdr);
00961 free(lvl->clm_utilize);
00962 }
00963
00964
00965 if (lvl->wlb!=NULL)
00966 {
00967 int i;
00968 for (i=0; i<lvl->tlsize.y; i++)
00969 free(lvl->wlb[i]);
00970 free(lvl->wlb);
00971 }
00972
00973 level_free_script_param(&(lvl->script.par));
00974
00975
00976 if (lvl->cust_clm_lookup!=NULL)
00977 {
00978 int i;
00979 for (i=0; i<lvl->subsize.y; i++)
00980 free(lvl->cust_clm_lookup[i]);
00981 free (lvl->cust_clm_lookup);
00982 }
00983
00984
00985
00986 free(lvl->info.name_text);
00987 free(lvl->info.desc_text);
00988 free(lvl->info.author_text);
00989 free(lvl->info.editor_text);
00990
00991 free(lvl->fname);
00992 free(lvl->savfname);
00993
00994
00995 free(lvl);
00996 *lvl_ptr=NULL;
00997 message_log(" level_deinit: finished");
00998 return true;
00999 }
01000
01008 short level_free_tng(struct LEVEL *lvl)
01009 {
01010
01011 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01012 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01013
01014 if ((lvl->tng_subnums!=NULL) && (lvl->tng_lookup!=NULL))
01015 {
01016 int cx,cy,k;
01017 for (cx=0; cx<arr_entries_x; cx++)
01018 {
01019 for (cy=0; cy<arr_entries_y; cy++)
01020 {
01021 int last_idx=lvl->tng_subnums[cx][cy]-1;
01022 for (k=last_idx; k >=0; k--)
01023 thing_del(lvl,cx, cy, k);
01024 }
01025 }
01026 }
01027 return true;
01028 }
01029
01037 short level_free_apt(struct LEVEL *lvl)
01038 {
01039
01040 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01041 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01042
01043 if ((lvl->apt_subnums!=NULL) && (lvl->apt_lookup!=NULL))
01044 {
01045 int cx,cy,k;
01046 for (cx=0; cx<arr_entries_x; cx++)
01047 {
01048 for (cy=0; cy<arr_entries_y; cy++)
01049 {
01050 int last_idx=lvl->apt_subnums[cx][cy]-1;
01051 for (k=last_idx; k >=0; k--)
01052 actnpt_del(lvl,cx, cy, k);
01053 }
01054 }
01055 }
01056 return true;
01057 }
01058
01066 short level_free_txt(struct LEVEL *lvl)
01067 {
01068 int idx=lvl->script.lines_count;
01069 while (idx>0)
01070 {
01071 idx--;
01072 free(lvl->script.txt[idx]);
01073 free(lvl->script.list[idx]);
01074 }
01075 free(lvl->script.txt);
01076 free(lvl->script.list);
01077 lvl->script.lines_count=0;
01078 return true;
01079 }
01080
01088 short free_text_file(char ***lines,int *lines_count)
01089 {
01090 int idx=(*lines_count);
01091 while (idx>0)
01092 {
01093 idx--;
01094 free((*lines)[idx]);
01095 }
01096 free(*lines);
01097 (*lines)=NULL;
01098 (*lines_count)=0;
01099 return true;
01100 }
01101
01109 short level_free_lgt(struct LEVEL *lvl)
01110 {
01111
01112 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01113 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01114
01115 if ((lvl->lgt_subnums!=NULL) && (lvl->lgt_lookup!=NULL))
01116 {
01117 int cx,cy,k;
01118 for (cx=0; cx<arr_entries_x; cx++)
01119 {
01120 for (cy=0; cy<arr_entries_y; cy++)
01121 {
01122 int last_idx=lvl->lgt_subnums[cx][cy]-1;
01123 for (k=last_idx; k >=0; k--)
01124 stlight_del(lvl,cx, cy, k);
01125 }
01126 }
01127 }
01128 return true;
01129 }
01130
01139 short level_free(struct LEVEL *lvl)
01140 {
01141 message_log(" level_free: started");
01142 short result=true;
01143 result&=level_free_lgt(lvl);
01144 result&=level_free_apt(lvl);
01145 result&=level_free_tng(lvl);
01146 result&=level_free_txt(lvl);
01147 result&=level_free_graffiti(lvl);
01148 message_log(" level_free: finished");
01149 return result;
01150 }
01151
01157 struct DK_SCRIPT_PARAMETERS *level_get_script_param(struct LEVEL *lvl)
01158 {
01159 if (lvl==NULL)
01160 return NULL;
01161 return &(lvl->script.par);
01162 }
01163
01173 short level_verify(struct LEVEL *lvl, char *actn_name,struct IPOINT_2D *errpt)
01174 {
01175 char err_msg[LINEMSG_SIZE];
01176 strcpy(err_msg,"Unknown error");
01177 short result=VERIF_OK;
01178 short nres;
01179 if (result!=VERIF_ERROR)
01180 {
01181 nres=level_verify_struct(lvl,err_msg,errpt);
01182 if (nres!=VERIF_OK) result=nres;
01183 }
01184 if (result!=VERIF_ERROR)
01185 {
01186 nres=things_verify(lvl,err_msg,errpt);
01187 if (nres!=VERIF_OK) result=nres;
01188 }
01189 if (result!=VERIF_ERROR)
01190 {
01191 nres=slabs_verify(lvl,err_msg,errpt);
01192 if (nres!=VERIF_OK) result=nres;
01193 }
01194 if (result!=VERIF_ERROR)
01195 {
01196 nres=actnpts_verify(lvl,err_msg,errpt);
01197 if (nres!=VERIF_OK) result=nres;
01198 }
01199 if (result!=VERIF_ERROR)
01200 {
01201 nres=columns_verify(lvl,err_msg,errpt);
01202 if (nres!=VERIF_OK) result=nres;
01203 }
01204 if (result!=VERIF_ERROR)
01205 {
01206 nres=dat_verify(lvl,err_msg,errpt);
01207 if (nres!=VERIF_OK) result=nres;
01208 }
01209 if (result!=VERIF_ERROR)
01210 {
01211 nres=txt_verify(lvl,err_msg,errpt);
01212 if (nres!=VERIF_OK) result=nres;
01213 }
01214 if (result!=VERIF_ERROR)
01215 {
01216 nres=level_verify_logic(lvl,err_msg,errpt);
01217 if (nres!=VERIF_OK) result=nres;
01218 }
01219 switch (result)
01220 {
01221 case VERIF_OK:
01222 message_info("Level verification passed.");
01223 return VERIF_OK;
01224 case VERIF_WARN:
01225 if (actn_name==NULL)
01226 message_error("Warning: %s",err_msg);
01227 else
01228 message_error("Warning: %s (%s performed)",err_msg,actn_name);
01229 return VERIF_WARN;
01230 default:
01231 if (actn_name==NULL)
01232 message_error("Error: %s",err_msg);
01233 else
01234 message_error("Error: %s (%s cancelled)",err_msg,actn_name);
01235 return VERIF_ERROR;
01236 }
01237 }
01238
01247 short level_verify_struct(struct LEVEL *lvl, char *err_msg,struct IPOINT_2D *errpt)
01248 {
01249
01250 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01251 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01252
01253 if (lvl->tng_subnums==NULL)
01254 {
01255 strncpy(err_msg,"Null internal object tng_subnums!",LINEMSG_SIZE);
01256 errpt->x=-1;errpt->y=-1;
01257 return VERIF_ERROR;
01258 }
01259 if (lvl->apt_subnums==NULL)
01260 {
01261 strncpy(err_msg,"Null internal object apt_subnums!",LINEMSG_SIZE);
01262 errpt->x=-1;errpt->y=-1;
01263 return VERIF_ERROR;
01264 }
01265 if (lvl->lgt_subnums==NULL)
01266 {
01267 strncpy(err_msg,"Null internal object lgt_subnums!",LINEMSG_SIZE);
01268 errpt->x=-1;errpt->y=-1;
01269 return VERIF_ERROR;
01270 }
01271
01272 int i, j, k;
01273 for (i=0; i < arr_entries_y; i++)
01274 {
01275 for (j=0; j < arr_entries_x; j++)
01276 {
01277 int things_count=get_thing_subnums(lvl,i,j);
01278 for (k=0; k <things_count ; k++)
01279 {
01280 unsigned char *thing = get_thing(lvl,i,j,k);
01281 if (thing==NULL)
01282 {
01283 errpt->x=i/MAP_SUBNUM_X;
01284 errpt->y=j/MAP_SUBNUM_Y;
01285 sprintf(err_msg,"Null thing pointer at slab %d,%d.",errpt->x,errpt->y);
01286 return VERIF_ERROR;
01287 }
01288 }
01289
01290 int actpt_count=lvl->apt_subnums[i][j];
01291 for (k=0; k <actpt_count ; k++)
01292 {
01293 unsigned char *actnpt = lvl->apt_lookup[i][j][k];
01294 if (actnpt==NULL)
01295 {
01296 errpt->x=i/MAP_SUBNUM_X;
01297 errpt->y=j/MAP_SUBNUM_Y;
01298 sprintf(err_msg,"Null action point pointer at slab %d,%d.",errpt->x,errpt->y);
01299 return VERIF_ERROR;
01300 }
01301 }
01302
01303 int stlight_count=lvl->lgt_subnums[i][j];
01304 for (k=0; k <stlight_count ; k++)
01305 {
01306 unsigned char *stlight = lvl->lgt_lookup[i][j][k];
01307 if (stlight==NULL)
01308 {
01309 errpt->x=i/MAP_SUBNUM_X;
01310 errpt->y=j/MAP_SUBNUM_Y;
01311 sprintf(err_msg,"Null static light pointer at slab %d,%d.",errpt->x,errpt->y);
01312 return VERIF_ERROR;
01313 }
01314 }
01315 }
01316 }
01317 for (i=0; i<COLUMN_ENTRIES; i++)
01318 {
01319 if (lvl->clm[i]==NULL)
01320 {
01321 errpt->x=-1;errpt->y=-1;
01322 sprintf(err_msg,"Null CoLuMn entry at index %d.",i);
01323 return VERIF_ERROR;
01324 }
01325 }
01326 if ((lvl->clm_hdr==NULL)||(lvl->clm_utilize==NULL))
01327 {
01328 errpt->x=-1;errpt->y=-1;
01329 sprintf(err_msg,"Null CoLuMn help arrays.");
01330 return VERIF_ERROR;
01331 }
01332 if (lvl->inf>7)
01333 {
01334 errpt->x=-1;errpt->y=-1;
01335 strncpy(err_msg,"Unexpected value of INF entry.",LINEMSG_SIZE);
01336 return VERIF_WARN;
01337 }
01338 return VERIF_OK;
01339 }
01340
01349 short actnpts_verify(struct LEVEL *lvl, char *err_msg,struct IPOINT_2D *errpt)
01350 {
01351
01352 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01353 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01354 int i, j, k;
01355 for (i=0; i < arr_entries_y; i++)
01356 for (j=0; j < arr_entries_x; j++)
01357 {
01358 int actnpt_count=get_actnpt_subnums(lvl,i,j);
01359 for (k=0; k <actnpt_count ; k++)
01360 {
01361 unsigned char *actnpt = get_actnpt(lvl,i,j,k);
01362 unsigned char subt_x=get_actnpt_subtile_x(actnpt);
01363 unsigned char subt_y=get_actnpt_subtile_y(actnpt);
01364 unsigned char subt_r=get_actnpt_range_subtile(actnpt);
01365 unsigned short n=get_actnpt_number(actnpt);
01366 unsigned short slab=get_tile_slab(lvl,i/MAP_SUBNUM_X,j/MAP_SUBNUM_Y);
01367 int col_h=get_subtile_column_height(lvl,i,j);
01368 if ((subt_x>=arr_entries_x)||(subt_y>=arr_entries_y))
01369 {
01370 errpt->x=i/MAP_SUBNUM_X;
01371 errpt->y=j/MAP_SUBNUM_Y;
01372 sprintf(err_msg,"Action point has bad position data on slab %d,%d.",errpt->x,errpt->y);
01373 return VERIF_WARN;
01374 }
01375 if (subt_r>60)
01376 {
01377 errpt->x=i/MAP_SUBNUM_X;
01378 errpt->y=j/MAP_SUBNUM_Y;
01379 sprintf(err_msg,"Action point range too big on slab %d,%d.",errpt->x,errpt->y);
01380 return VERIF_WARN;
01381 }
01382 if ((n<1)||(n>4096))
01383 {
01384 errpt->x=i/MAP_SUBNUM_X;
01385 errpt->y=j/MAP_SUBNUM_Y;
01386 sprintf(err_msg,"Incorrect action point number on slab %d,%d.",errpt->x,errpt->y);
01387 return VERIF_WARN;
01388 }
01389 }
01390 }
01391 return VERIF_OK;
01392 }
01393
01402 short level_verify_logic(struct LEVEL *lvl, char *err_msg,struct IPOINT_2D *errpt)
01403 {
01404
01405 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01406 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01407 int i, j, k;
01408 for (i=0; i < arr_entries_y; i++)
01409 {
01410 for (j=0; j < arr_entries_x; j++)
01411 {
01412 int things_count=get_thing_subnums(lvl,i,j);
01413 for (k=0; k <things_count ; k++)
01414 {
01415 unsigned char *thing = get_thing(lvl,i,j,k);
01416 unsigned char type_idx=get_thing_type(thing);
01417
01418 {
01419 int pos_h=(unsigned short)get_thing_subtile_h(thing);
01420 int subt_x=(unsigned short)get_thing_subtpos_x(thing);
01421 int subt_y=(unsigned short)get_thing_subtpos_y(thing);
01422 unsigned short slab=get_tile_slab(lvl,i/MAP_SUBNUM_X,j/MAP_SUBNUM_Y);
01423 int col_h=get_subtile_column_height(lvl,i,j);
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439 if ((pos_h<col_h)&&(!slab_is_door(slab))||(pos_h<min(col_h,1)))
01440 {
01441 errpt->x=i/MAP_SUBNUM_X;
01442 errpt->y=j/MAP_SUBNUM_Y;
01443 sprintf(err_msg,"Thing trapped in solid column on slab %d,%d (h=%d<%d).",errpt->x,errpt->y,pos_h,col_h);
01444 return VERIF_WARN;
01445 }
01446 }
01447 }
01448
01449 }
01450 }
01451
01452
01453 int hearts[PLAYERS_COUNT];
01454 for (i=0; i < PLAYERS_COUNT; i++)
01455 hearts[i]=0;
01456 owned_things_count(hearts,lvl,THING_TYPE_ITEM,ITEM_SUBTYPE_DNHEART);
01457
01458 if (hearts[PLAYER_UNSET]>0)
01459 {
01460 errpt->x=-1;errpt->y=-1;
01461 sprintf(err_msg,"Found %d unowned dungeon heart things.",hearts[PLAYER_UNSET]);
01462 return VERIF_WARN;
01463 }
01464 for (i=0; i < PLAYERS_COUNT; i++)
01465 {
01466 if ((hearts[i]>1)&&((lvl->optns.verify_warn_flags&VWFLAG_NOWARN_MANYHEART)==0))
01467 {
01468 errpt->x=-1;errpt->y=-1;
01469 sprintf(err_msg,"Player %d owns %d dungeon heart things.",i, hearts[i]);
01470 return VERIF_WARN;
01471 }
01472 }
01473 if (hearts[0]==0)
01474 {
01475 errpt->x=-1;errpt->y=-1;
01476 sprintf(err_msg,"Human player doesn't have a dungeon heart thing.");
01477 return VERIF_WARN;
01478 }
01479 return VERIF_OK;
01480 }
01481
01489 void generate_slab_bkgnd_default(struct LEVEL *lvl,unsigned short def_slab)
01490 {
01491 const struct UPOINT_2D tl_maxindex={lvl->tlsize.x-1,lvl->tlsize.y-1};
01492
01493 int i,j;
01494 for (i=1; i < tl_maxindex.y; i++)
01495 for (j=1; j < tl_maxindex.x; j++)
01496 {
01497 set_tile_slab(lvl,i,j,def_slab);
01498 set_tile_owner(lvl,i,j,PLAYER_UNSET);
01499 }
01500
01501 for (i=0; i < lvl->tlsize.x; i++)
01502 {
01503 set_tile_slab(lvl,i,0,SLAB_TYPE_ROCK);
01504 set_tile_slab(lvl,i,tl_maxindex.y,SLAB_TYPE_ROCK);
01505 set_tile_owner(lvl,i,0,PLAYER_UNSET);
01506 set_tile_owner(lvl,i,tl_maxindex.y,PLAYER_UNSET);
01507 }
01508 for (i=0; i < lvl->tlsize.y; i++)
01509 {
01510 set_tile_slab(lvl,0,i,SLAB_TYPE_ROCK);
01511 set_tile_slab(lvl,tl_maxindex.x,i,SLAB_TYPE_ROCK);
01512 set_tile_owner(lvl,0,i,PLAYER_UNSET);
01513 set_tile_owner(lvl,tl_maxindex.x,i,PLAYER_UNSET);
01514 }
01515
01516 int sx, sy;
01517 sx=lvl->subsize.x-1;
01518 for (sy=0; sy<lvl->subsize.y; sy++)
01519 set_subtl_owner(lvl,sx,sy,PLAYER_UNSET);
01520 sy=lvl->subsize.y-1;
01521 for (sx=0; sx<lvl->subsize.x; sx++)
01522 set_subtl_owner(lvl,sx,sy,PLAYER_UNSET);
01523 }
01524
01531 void generate_slab_bkgnd_random(struct LEVEL *lvl)
01532 {
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555 int i,j,k,l;
01556
01557 const struct UPOINT_2D tl_maxindex={lvl->tlsize.x-1,lvl->tlsize.y-1};
01558 for (i=1; i < tl_maxindex.y; i++)
01559 for (j=1; j < tl_maxindex.x; j++)
01560 set_tile_slab(lvl,i,j,SLAB_TYPE_EARTH);
01561
01562 for (i=0; i < lvl->tlsize.x; i++)
01563 {
01564 set_tile_slab(lvl,i,0,SLAB_TYPE_ROCK);
01565 set_tile_slab(lvl,i,tl_maxindex.y,SLAB_TYPE_ROCK);
01566 }
01567 for (i=0; i < lvl->tlsize.y; i++)
01568 {
01569 set_tile_slab(lvl,0,i,SLAB_TYPE_ROCK);
01570 set_tile_slab(lvl,tl_maxindex.x,i,SLAB_TYPE_ROCK);
01571 }
01572
01573
01574 int sx, sy;
01575 sx=lvl->subsize.x-1;
01576 for (sy=0; sy<lvl->subsize.y; sy++)
01577 set_subtl_owner(lvl,sx,sy,PLAYER_UNSET);
01578 sy=lvl->subsize.y-1;
01579 for (sx=0; sx<lvl->subsize.x; sx++)
01580 set_subtl_owner(lvl,sx,sy,PLAYER_UNSET);
01581
01582
01583 for (i=1; i < (tl_maxindex.y>>1); i++)
01584 for (j=0; j < tl_maxindex.x-1; j++)
01585 {
01586 int ir=tl_maxindex.y-i;
01587 int rnd_bound=RAND_MAX/((i/2)+1);
01588 if (rand()<rnd_bound)
01589 {
01590 set_tile_slab(lvl,j,i,SLAB_TYPE_ROCK);
01591 }
01592 if (rand()<rnd_bound)
01593 {
01594 set_tile_slab(lvl,j,tl_maxindex.y-i,SLAB_TYPE_ROCK);
01595 }
01596 if (rand()<rnd_bound)
01597 {
01598 set_tile_slab(lvl,i,j,SLAB_TYPE_ROCK);
01599 }
01600 if (rand()<rnd_bound)
01601 {
01602 set_tile_slab(lvl,tl_maxindex.x-i,j,SLAB_TYPE_ROCK);
01603 }
01604 }
01605 int num_smears=(rand()%20);
01606 if (num_smears<10)
01607 {
01608 while (num_smears>4) num_smears=num_smears>>1;
01609 for (l=0;l<num_smears;l++)
01610 {
01611 int val=rand();
01612 int smr_startx = val%lvl->tlsize.x;
01613 int smr_starty=(val>>8)%lvl->tlsize.y;
01614 val=rand();
01615 int smr_endx = (val)%lvl->tlsize.x;
01616 int smr_endy=(val>>8)%lvl->tlsize.y;
01617 val=rand();
01618 int startr=(val)%4+2;
01619 int endr=(val>>8)%3+1;
01620 val=rand();
01621 int distance=ceil(sqrt((smr_startx-smr_endx)*(smr_startx-smr_endx)+(smr_starty-smr_endy)*(smr_starty-smr_endy)));
01622 int bend=((val)%(distance+1))-(distance>>1);
01623 slab_draw_smear(lvl,smr_startx,smr_starty,startr,smr_endx,smr_endy,endr,bend,SLAB_TYPE_ROCK);
01624 }
01625 }
01626
01627 const int slabgrow_bound_val=4;
01628 int cx,cy;
01629 for (i=1; i < (lvl->tlsize.x>>1); i++)
01630 for (j=1; j < (lvl->tlsize.y>>1); j++)
01631 for (k=0; k < 4; k++)
01632 {
01633 if ((k%2)==0) cx=i; else cx=tl_maxindex.x-i;
01634 if ((k>>1)==0) cy=j; else cy=tl_maxindex.y-j;
01635 int nsibln=slab_siblings_oftype(lvl,cx,cy,SLAB_TYPE_ROCK);
01636 if (nsibln>slabgrow_bound_val)
01637 {
01638 set_tile_slab(lvl,cx,cy,SLAB_TYPE_ROCK);
01639 } else
01640 {
01641 set_tile_slab(lvl,cx,cy,SLAB_TYPE_EARTH);
01642 }
01643 }
01644 for (i=1; i < tl_maxindex.x-1; i++)
01645 for (j=1; j < tl_maxindex.y-1; j++)
01646 {
01647 int nsibln=slab_siblings_oftype(lvl,i,j,SLAB_TYPE_ROCK);
01648 if (nsibln<2)
01649 {
01650 set_tile_slab(lvl,i,j,SLAB_TYPE_EARTH);
01651 }
01652 if (nsibln>7)
01653 {
01654 set_tile_slab(lvl,i,j,SLAB_TYPE_ROCK);
01655 }
01656 }
01657
01658 for (i=0; i < lvl->tlsize.x; i++)
01659 for (j=0; j < lvl->tlsize.y; j++)
01660 set_tile_owner(lvl, i, j, PLAYER_UNSET);
01661 }
01662
01668 void start_new_map(struct LEVEL *lvl)
01669 {
01670 message_log(" start_new_map: starting");
01671 level_clear(lvl);
01672
01673 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01674 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01675
01676 message_log(" start_new_map: generating background");
01677 generate_slab_bkgnd_default(lvl,SLAB_TYPE_EARTH);
01678
01679 message_log(" start_new_map: updating columns");
01680
01681 add_permanent_columns(lvl);
01682
01683 if (lvl->optns.datclm_auto_update)
01684 update_datclm_for_whole_map(lvl);
01685
01686 lvl->inf=0x00;
01687
01688 message_log(" start_new_map: updating level stats");
01689 update_level_stats(lvl);
01690 message_log(" start_new_map: finished");
01691 }
01692
01698 void generate_random_map(struct LEVEL *lvl)
01699 {
01700 level_clear(lvl);
01701
01702 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01703 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01704
01705 generate_slab_bkgnd_random(lvl);
01706
01707
01708 add_permanent_columns(lvl);
01709
01710 if (lvl->optns.datclm_auto_update)
01711 update_datclm_for_whole_map(lvl);
01712 lvl->inf=rnd(8);
01713 update_level_stats(lvl);
01714 }
01715
01721 void free_map(struct LEVEL *lvl)
01722 {
01723 level_free(lvl);
01724 level_clear(lvl);
01725 }
01726
01733 short level_generate_random_extension(struct LEVEL *lvl,char *ret_msg)
01734 {
01735 short result;
01736 const struct IPOINT_2D heart_size={3,3};
01737 unsigned char rown;
01738
01739
01740 rown=PLAYER0;
01741 if (true)
01742 {
01743 result=place_room_rndpos(lvl,SLAB_TYPE_DUNGHEART,rown,&heart_size);
01744 if (result)
01745 {
01746 sprintf(ret_msg,"Dungeon Heart placed.");
01747 return true;
01748 }
01749 }
01750 sprintf(ret_msg,"Can't find anything to add.");
01751 return false;
01752 }
01753
01761 char *get_thing(const struct LEVEL *lvl,unsigned int sx,unsigned int sy,unsigned int num)
01762 {
01763
01764 unsigned int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01765 unsigned int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01766
01767 sx %= arr_entries_x;
01768 sy %= arr_entries_y;
01769 unsigned char *thing=NULL;
01770 if (num < lvl->tng_subnums[sx][sy])
01771 thing = lvl->tng_lookup[sx][sy][num];
01772 return thing;
01773 }
01774
01782 int thing_add(struct LEVEL *lvl,unsigned char *thing)
01783 {
01784
01785 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01786 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01787 unsigned int x, y;
01788 x = get_thing_subtile_x(thing)%arr_entries_x;
01789 y = get_thing_subtile_y(thing)%arr_entries_y;
01790 lvl->tng_total_count++;
01791
01792 lvl->tng_subnums[x][y]++;
01793 lvl->tng_apt_lgt_nums[(x/MAP_SUBNUM_X)][(y/MAP_SUBNUM_Y)]++;
01794 if (lvl->tng_lookup[x][y]==NULL)
01795 lvl->tng_lookup[x][y]=(unsigned char **)malloc(sizeof(char *));
01796 else
01797 lvl->tng_lookup[x][y]=(unsigned char **)realloc(lvl->tng_lookup[x][y],
01798 lvl->tng_subnums[x][y]*sizeof(char *));
01799 if (lvl->tng_lookup[x][y]==NULL)
01800 {
01801 message_error("thing_add: Cannot alloc tng entry");
01802 return -1;
01803 }
01804 int new_idx=lvl->tng_subnums[x][y]-1;
01805 lvl->tng_lookup[x][y][new_idx]=thing;
01806 update_thing_stats(lvl,thing,1);
01807 return new_idx;
01808 }
01809
01817 void thing_del(struct LEVEL *lvl,unsigned int sx, unsigned int sy, unsigned int num)
01818 {
01819
01820 unsigned int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01821 unsigned int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01822
01823 if ((sx>=arr_entries_x)||(sy>=arr_entries_y)) return;
01824 unsigned char *thing;
01825 thing = lvl->tng_lookup[sx][sy][num];
01826 thing_drop(lvl,sx,sy,num);
01827 free(thing);
01828 }
01829
01838 void thing_drop(struct LEVEL *lvl,unsigned int sx, unsigned int sy, unsigned int num)
01839 {
01840
01841 unsigned int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01842 unsigned int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01843
01844 if ((sx>=arr_entries_x)||(sy>=arr_entries_y)) return;
01845 int i;
01846 if (num >= lvl->tng_subnums[sx][sy])
01847 return;
01848 lvl->tng_total_count--;
01849 unsigned char *thing;
01850 thing = lvl->tng_lookup[sx][sy][num];
01851 update_thing_stats(lvl,thing,-1);
01852 for (i=num; i < lvl->tng_subnums[sx][sy]-1; i++)
01853 lvl->tng_lookup[sx][sy][i]=lvl->tng_lookup[sx][sy][i+1];
01854 lvl->tng_subnums[sx][sy]--;
01855 lvl->tng_apt_lgt_nums[sx/3][sy/3]--;
01856 lvl->tng_lookup[sx][sy]=(unsigned char **)realloc(lvl->tng_lookup[sx][sy],
01857 lvl->tng_subnums[sx][sy]*sizeof(char *));
01858 }
01859
01866 unsigned int get_thing_subnums(const struct LEVEL *lvl,unsigned int sx,unsigned int sy)
01867 {
01868
01869 unsigned int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01870 unsigned int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01871
01872 if ((sx>=arr_entries_x)||(sy>=arr_entries_y)) return 0;
01873 return lvl->tng_subnums[sx][sy];
01874 }
01875
01883 char *get_actnpt(const struct LEVEL *lvl,unsigned int sx,unsigned int sy,unsigned int num)
01884 {
01885
01886 unsigned int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01887 unsigned int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01888
01889 sx %= arr_entries_x;
01890 sy %= arr_entries_y;
01891 unsigned char *actnpt=NULL;
01892 if (num < get_actnpt_subnums(lvl,sx,sy))
01893 actnpt = lvl->apt_lookup[sx][sy][num];
01894 return actnpt;
01895 }
01896
01904 int actnpt_add(struct LEVEL *lvl,unsigned char *actnpt)
01905 {
01906
01907 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01908 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01909 unsigned int x, y;
01910 x = get_actnpt_subtile_x(actnpt)%arr_entries_x;
01911 y = get_actnpt_subtile_y(actnpt)%arr_entries_y;
01912 lvl->apt_total_count++;
01913
01914 unsigned int apt_snum=get_actnpt_subnums(lvl,x,y);
01915 apt_snum++;
01916 lvl->apt_subnums[x][y]=apt_snum;
01917 lvl->tng_apt_lgt_nums[(x/MAP_SUBNUM_X)][(y/MAP_SUBNUM_Y)]++;
01918 if (lvl->apt_lookup[x][y]==NULL)
01919 lvl->apt_lookup[x][y]=(unsigned char **)malloc(sizeof(char *));
01920 else
01921 lvl->apt_lookup[x][y]=(unsigned char **)realloc(lvl->apt_lookup[x][y],
01922 apt_snum*sizeof(char *));
01923 if (lvl->apt_lookup[x][y]==NULL)
01924 {
01925 message_error("actnpt_add: Cannot allocate memory");
01926 return -1;
01927 }
01928 unsigned int new_idx=apt_snum-1;
01929 lvl->apt_lookup[x][y][new_idx]=actnpt;
01930 return new_idx;
01931 }
01932
01940 void actnpt_del(struct LEVEL *lvl,unsigned int sx, unsigned int sy, unsigned int num)
01941 {
01942
01943 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01944 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01945 sx%=arr_entries_x;
01946 sy%=arr_entries_y;
01947 unsigned int apt_snum=get_actnpt_subnums(lvl,sx,sy);
01948 if (num >= apt_snum)
01949 return;
01950 lvl->apt_total_count--;
01951 unsigned char *actnpt;
01952 actnpt = lvl->apt_lookup[sx][sy][num];
01953 free(actnpt);
01954 int i;
01955 apt_snum--;
01956 for (i=num; i < apt_snum; i++)
01957 lvl->apt_lookup[sx][sy][i]=lvl->apt_lookup[sx][sy][i+1];
01958 lvl->apt_subnums[sx][sy]=apt_snum;
01959 lvl->tng_apt_lgt_nums[sx/MAP_SUBNUM_X][sy/MAP_SUBNUM_Y]--;
01960 lvl->apt_lookup[sx][sy]=(unsigned char **)realloc(lvl->apt_lookup[sx][sy],
01961 apt_snum*sizeof(char *));
01962 }
01963
01970 unsigned int get_actnpt_subnums(const struct LEVEL *lvl,unsigned int sx,unsigned int sy)
01971 {
01972
01973 unsigned int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01974 unsigned int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01975
01976 sx %= arr_entries_x;
01977 sy %= arr_entries_y;
01978 return lvl->apt_subnums[sx][sy];
01979 }
01980
01988 char *get_stlight(const struct LEVEL *lvl,unsigned int sx,unsigned int sy,unsigned int num)
01989 {
01990
01991 unsigned int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
01992 unsigned int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
01993
01994 sx %= arr_entries_x;
01995 sy %= arr_entries_y;
01996 unsigned char *stlight=NULL;
01997 if (num < lvl->lgt_subnums[sx][sy])
01998 stlight = lvl->lgt_lookup[sx][sy][num];
01999 return stlight;
02000 }
02001
02008 int stlight_add(struct LEVEL *lvl,unsigned char *stlight)
02009 {
02010
02011 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
02012 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
02013 unsigned int x, y;
02014 x = get_stlight_subtile_x(stlight)%arr_entries_x;
02015 y = get_stlight_subtile_y(stlight)%arr_entries_y;
02016 lvl->lgt_total_count++;
02017
02018 unsigned int lgt_snum=lvl->lgt_subnums[x][y];
02019 lgt_snum++;
02020 lvl->lgt_subnums[x][y]=lgt_snum;
02021 lvl->tng_apt_lgt_nums[(x/MAP_SUBNUM_X)][(y/MAP_SUBNUM_Y)]++;
02022 if (lvl->lgt_lookup[x][y]==NULL)
02023 lvl->lgt_lookup[x][y]=(unsigned char **)malloc(sizeof(char *));
02024 else
02025 lvl->lgt_lookup[x][y]=(unsigned char **)realloc(lvl->lgt_lookup[x][y],
02026 lgt_snum*sizeof(char *));
02027 if (lvl->lgt_lookup[x][y]==NULL)
02028 {
02029 message_error("stlight_add: Cannot allocate memory");
02030 return -1;
02031 }
02032 unsigned int new_idx=lgt_snum-1;
02033 lvl->lgt_lookup[x][y][new_idx]=stlight;
02034 return new_idx;
02035 }
02036
02044 void stlight_del(struct LEVEL *lvl,unsigned int sx, unsigned int sy, unsigned int num)
02045 {
02046
02047 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
02048 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
02049 sx%=arr_entries_x;
02050 sy%=arr_entries_y;
02051 unsigned int lgt_snum=lvl->lgt_subnums[sx][sy];
02052 if (num >= lgt_snum)
02053 return;
02054 lvl->lgt_total_count--;
02055 unsigned char *stlight;
02056 stlight = lvl->lgt_lookup[sx][sy][num];
02057 free(lvl->lgt_lookup[sx][sy][num]);
02058 int i;
02059 lgt_snum--;
02060 for (i=num; i < lgt_snum; i++)
02061 lvl->lgt_lookup[sx][sy][i]=lvl->lgt_lookup[sx][sy][i+1];
02062 lvl->lgt_subnums[sx][sy]=lgt_snum;
02063 lvl->tng_apt_lgt_nums[sx/MAP_SUBNUM_X][sy/MAP_SUBNUM_Y]--;
02064 lvl->lgt_lookup[sx][sy]=(unsigned char **)realloc(lvl->lgt_lookup[sx][sy],
02065 lgt_snum*sizeof(char *));
02066 }
02067
02074 unsigned int get_stlight_subnums(const struct LEVEL *lvl,unsigned int sx,unsigned int sy)
02075 {
02076
02077 unsigned int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
02078 unsigned int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
02079
02080 sx %= arr_entries_x;
02081 sy %= arr_entries_y;
02082 return lvl->lgt_subnums[sx][sy];
02083 }
02084
02095 short get_object_type(const struct LEVEL *lvl, unsigned int sx, unsigned int sy, unsigned int z)
02096 {
02097
02098 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
02099 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
02100
02101 if ((sx>=arr_entries_x)||(sy>=arr_entries_y))
02102 return OBJECT_TYPE_NONE;
02103 int tng_num=lvl->tng_subnums[sx][sy];
02104 if (z<tng_num) return OBJECT_TYPE_THING;
02105 int apt_num=get_actnpt_subnums(lvl,sx,sy);
02106 if (z<(tng_num+apt_num)) return OBJECT_TYPE_ACTNPT;
02107 int lgt_num=lvl->lgt_subnums[sx][sy];
02108 if (z<(tng_num+apt_num+lgt_num)) return OBJECT_TYPE_STLIGHT;
02109 return OBJECT_TYPE_NONE;
02110 }
02111
02122 unsigned char *get_object(const struct LEVEL *lvl,unsigned int sx,unsigned int sy,unsigned int z)
02123 {
02124
02125 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
02126 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
02127
02128 if ((sx>=arr_entries_x)||(sy>=arr_entries_y))
02129 return NULL;
02130 int tng_num=lvl->tng_subnums[sx][sy];
02131 if (z<tng_num)
02132 return get_thing(lvl,sx,sy,z);
02133 int apt_num=get_actnpt_subnums(lvl,sx,sy);
02134 if (z<(tng_num+apt_num))
02135 return get_actnpt(lvl,sx,sy,z-tng_num);
02136 int lgt_num=lvl->lgt_subnums[sx][sy];
02137 if (z<(tng_num+apt_num+lgt_num))
02138 return get_stlight(lvl,sx,sy,z-tng_num-apt_num);
02139 return NULL;
02140 }
02141
02151 void object_del(struct LEVEL *lvl,unsigned int sx,unsigned int sy,unsigned int z)
02152 {
02153
02154 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
02155 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
02156
02157 sx%=arr_entries_x;
02158 sy%=arr_entries_y;
02159 int tng_num=lvl->tng_subnums[sx][sy];
02160 if (z<tng_num)
02161 {
02162 thing_del(lvl,sx,sy,z);
02163 return;
02164 }
02165 int apt_num=get_actnpt_subnums(lvl,sx,sy);
02166 if (z<(tng_num+apt_num))
02167 {
02168 actnpt_del(lvl,sx,sy,z-tng_num);
02169 return;
02170 }
02171 int lgt_num=lvl->lgt_subnums[sx][sy];
02172 if (z<(tng_num+apt_num+lgt_num))
02173 {
02174 stlight_del(lvl,sx,sy,z-tng_num-apt_num);
02175 return;
02176 }
02177 }
02178
02187 unsigned int get_object_subnums(const struct LEVEL *lvl,unsigned int sx,unsigned int sy)
02188 {
02189
02190 unsigned int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
02191 unsigned int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
02192
02193 if ((sx>=arr_entries_x)||(sy>=arr_entries_y))
02194 return 0;
02195 return lvl->tng_subnums[sx][sy]+get_actnpt_subnums(lvl,sx,sy)+lvl->lgt_subnums[sx][sy];
02196 }
02197
02206 unsigned int get_object_tilnums(const struct LEVEL *lvl,unsigned int tx,unsigned int ty)
02207 {
02208 if (lvl->tng_apt_lgt_nums==NULL) return 0;
02209 return lvl->tng_apt_lgt_nums[tx%lvl->tlsize.x][ty%lvl->tlsize.y];
02210 }
02211
02220 int get_object_subtl_last(const struct LEVEL *lvl,unsigned int sx,unsigned int sy,short obj_type)
02221 {
02222
02223 unsigned int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
02224 unsigned int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
02225
02226 if ((sx>=arr_entries_x)||(sy>=arr_entries_y))
02227 return 0;
02228 int last=-1;
02229 last+=lvl->tng_subnums[sx][sy];
02230 if (obj_type==OBJECT_TYPE_THING)
02231 return last;
02232 last+=get_actnpt_subnums(lvl,sx,sy);
02233 if (obj_type==OBJECT_TYPE_ACTNPT)
02234 return last;
02235 last+=lvl->lgt_subnums[sx][sy];
02236 if (obj_type==OBJECT_TYPE_STLIGHT)
02237 return last;
02238 return get_object_subnums(lvl,sx,sy)-1;
02239 }
02240
02247 short get_subtl_wib(struct LEVEL *lvl, unsigned int sx, unsigned int sy)
02248 {
02249
02250 sx %= lvl->subsize.x;
02251 sy %= lvl->subsize.y;
02252 return lvl->wib[sx][sy];
02253 }
02254
02261 void set_subtl_wib(struct LEVEL *lvl, unsigned int sx, unsigned int sy, short nval)
02262 {
02263
02264 if ((sx>=lvl->subsize.x)||(sy>=lvl->subsize.y))
02265 return;
02266 lvl->wib[sx][sy]=nval;
02267 }
02268
02275 short get_tile_wlb(struct LEVEL *lvl, unsigned int tx, unsigned int ty)
02276 {
02277
02278 tx %= lvl->tlsize.x;
02279 ty %= lvl->tlsize.y;
02280 return lvl->wlb[tx][ty];
02281 }
02282
02289 void set_tile_wlb(struct LEVEL *lvl, unsigned int tx, unsigned int ty, short nval)
02290 {
02291
02292 if ((tx>=lvl->tlsize.x)||(ty>=lvl->tlsize.y)) return;
02293 lvl->wlb[tx][ty]=nval;
02294 }
02295
02302 unsigned char get_subtl_owner(const struct LEVEL *lvl, unsigned int sx, unsigned int sy)
02303 {
02304
02305 sx %= lvl->subsize.x;
02306 sy %= lvl->subsize.y;
02307 return lvl->own[sx][sy];
02308 }
02309
02316 void set_subtl_owner(struct LEVEL *lvl, unsigned int sx, unsigned int sy, unsigned char nval)
02317 {
02318
02319 if ((sx>=lvl->subsize.x)||(sy>=lvl->subsize.y)) return;
02320 lvl->own[sx][sy]=nval;
02321 }
02322
02329 unsigned char get_tile_owner(const struct LEVEL *lvl, unsigned int tx, unsigned int ty)
02330 {
02331 return get_subtl_owner(lvl,tx*MAP_SUBNUM_X+1,ty*MAP_SUBNUM_Y+1);
02332 }
02333
02341 void set_tile_owner(struct LEVEL *lvl, unsigned int tx, unsigned int ty, unsigned char nval)
02342 {
02343 int subtl_x,subtl_y;
02344 for (subtl_y=0;subtl_y<MAP_SUBNUM_Y;subtl_y++)
02345 for (subtl_x=0;subtl_x<MAP_SUBNUM_X;subtl_x++)
02346 set_subtl_owner(lvl,tx*MAP_SUBNUM_X+subtl_x,ty*MAP_SUBNUM_Y+subtl_y,nval);
02347 }
02348
02355 unsigned short get_tile_slab(const struct LEVEL *lvl, unsigned int tx, unsigned int ty)
02356 {
02357 if (lvl->slb==NULL) return SLAB_TYPE_ROCK;
02358
02359 if ((tx>=lvl->tlsize.x)||(ty>=lvl->tlsize.y)) return SLAB_TYPE_ROCK;
02360 return lvl->slb[tx][ty];
02361 }
02362
02371 void set_tile_slab(struct LEVEL *lvl, unsigned int tx, unsigned int ty, unsigned short nval)
02372 {
02373
02374 if ((tx>=lvl->tlsize.x)||(ty>=lvl->tlsize.y)) return;
02375 lvl->slb[tx][ty]=nval;
02376 }
02377
02384 unsigned int get_dat_val(const struct LEVEL *lvl, const unsigned int sx, const unsigned int sy)
02385 {
02386 if (lvl->dat==NULL) return 0;
02387 if ((sx>=lvl->subsize.x)||(sy>=lvl->subsize.y)) return 0;
02388 return lvl->dat[sx][sy];
02389 }
02390
02398 void set_dat_val(struct LEVEL *lvl, int sx, int sy, unsigned int d)
02399 {
02400 if (lvl->dat==NULL) return;
02401 if ((sx<0)||(sy<0)||(sx>=lvl->subsize.x)||(sy>=lvl->subsize.y)) return;
02402 lvl->dat[sx][sy]=d;
02403 }
02404
02411 unsigned short get_subtl_flg(struct LEVEL *lvl, unsigned int sx, unsigned int sy)
02412 {
02413 if (lvl->flg==NULL) return 0;
02414 if ((sx>=lvl->subsize.x)||(sy>=lvl->subsize.y)) return 0;
02415 return lvl->flg[sx][sy];
02416 }
02417
02424 void set_subtl_flg(struct LEVEL *lvl, unsigned int sx, unsigned int sy,unsigned short nval)
02425 {
02426 if (lvl->flg==NULL) return;
02427 if ((sx<0)||(sy<0)||(sx>=lvl->subsize.x)||(sy>=lvl->subsize.y)) return;
02428 lvl->flg[sx][sy]=nval;
02429 }
02430
02436 void update_level_stats(struct LEVEL *lvl)
02437 {
02438 update_clm_utilize_counters(lvl);
02439 update_things_stats(lvl);
02440 }
02441
02447 void update_things_stats(struct LEVEL *lvl)
02448 {
02449
02450 int arr_entries_x=lvl->tlsize.x*MAP_SUBNUM_X;
02451 int arr_entries_y=lvl->tlsize.y*MAP_SUBNUM_Y;
02452
02453 level_clear_stats(lvl);
02454
02455 int i, j, k;
02456 for (i=0; i < arr_entries_y; i++)
02457 {
02458 for (j=0; j < arr_entries_x; j++)
02459 {
02460 int things_count=get_thing_subnums(lvl,i,j);
02461 for (k=0; k <things_count ; k++)
02462 {
02463 unsigned char *thing = get_thing(lvl,i,j,k);
02464 update_thing_stats(lvl,thing,1);
02465 }
02466 }
02467 }
02468 }
02469
02477 void update_thing_stats(struct LEVEL *lvl,const unsigned char *thing,short change)
02478 {
02479 if (thing==NULL) return;
02480 unsigned char type_idx=get_thing_type(thing);
02481 switch (type_idx)
02482 {
02483 case THING_TYPE_CREATURE:
02484 lvl->stats.creatures_count+=change;
02485 break;
02486 case THING_TYPE_EFFECTGEN:
02487 lvl->stats.effectgenrts_count+=change;
02488 break;
02489 case THING_TYPE_TRAP:
02490 lvl->stats.traps_count+=change;
02491 break;
02492 case THING_TYPE_DOOR:
02493 lvl->stats.doors_count+=change;
02494 break;
02495 case THING_TYPE_ITEM:
02496 lvl->stats.items_count+=change;
02497 break;
02498 }
02499 if (is_herogate(thing))
02500 lvl->stats.hero_gates_count+=change;
02501 if (is_dnheart(thing))
02502 lvl->stats.dn_hearts_count+=change;
02503
02504 int categr=get_thing_subtypes_arridx(thing);
02505 if (categr<THING_CATEGR_COUNT)
02506 lvl->stats.things_count[categr]+=change;
02507
02508 if (is_room_inventory(thing))
02509 lvl->stats.room_things_count+=change;
02510 if (change>0)
02511 lvl->stats.things_added+=change;
02512 else
02513 lvl->stats.things_removed-=change;
02514 }
02515
02521 unsigned int get_lgt_total_count(struct LEVEL *lvl)
02522 {
02523 if (lvl==NULL) return 0;
02524 return lvl->lgt_total_count;
02525 }
02526
02532 unsigned int get_apt_total_count(struct LEVEL *lvl)
02533 {
02534 if (lvl==NULL) return 0;
02535 return lvl->apt_total_count;
02536 }
02537
02543 unsigned int get_tng_total_count(struct LEVEL *lvl)
02544 {
02545 if (lvl==NULL) return 0;
02546 return lvl->tng_total_count;
02547 }
02548
02554 short get_datclm_auto_update(struct LEVEL *lvl)
02555 {
02556 if (lvl==NULL) return false;
02557 return lvl->optns.datclm_auto_update;
02558 }
02559
02565 short switch_datclm_auto_update(struct LEVEL *lvl)
02566 {
02567 if (lvl==NULL) return false;
02568 short nval=!(lvl->optns.datclm_auto_update);
02569 lvl->optns.datclm_auto_update=nval;
02570 return nval;
02571 }
02572
02579 short set_datclm_auto_update(struct LEVEL *lvl,short val)
02580 {
02581 if (lvl==NULL) return false;
02582 lvl->optns.datclm_auto_update=val;
02583 return true;
02584 }
02585
02591 short get_obj_auto_update(struct LEVEL *lvl)
02592 {
02593 if (lvl==NULL) return false;
02594 return lvl->optns.obj_auto_update;
02595 }
02596
02602 short switch_obj_auto_update(struct LEVEL *lvl)
02603 {
02604 if (lvl==NULL) return false;
02605 short nval=!(lvl->optns.obj_auto_update);
02606 lvl->optns.obj_auto_update=nval;
02607 return nval;
02608 }
02609
02616 short set_obj_auto_update(struct LEVEL *lvl,short val)
02617 {
02618 if (lvl==NULL) return false;
02619 lvl->optns.obj_auto_update=val;
02620 return true;
02621 }
02622
02629 short set_lvl_fname(struct LEVEL *lvl,char *fname)
02630 {
02631 if (lvl==NULL) return false;
02632 if (fname == NULL)
02633 {
02634 free(lvl->fname);
02635 lvl->fname=NULL;
02636 }
02637 free(lvl->fname);
02638 lvl->fname=strdup(fname);
02639 if (lvl->fname==NULL)
02640 return false;
02641 return true;
02642 }
02643
02651 short format_lvl_fname(struct LEVEL *lvl,char *namefmt)
02652 {
02653 if (lvl==NULL) return false;
02654 if (namefmt == NULL)
02655 {
02656 free(lvl->fname);
02657 lvl->fname=NULL;
02658 }
02659 free(lvl->fname);
02660 lvl->fname=(char *)malloc(DISKPATH_SIZE*sizeof(char));
02661 if (lvl->fname==NULL)
02662 return false;
02663 return format_map_fname(lvl->fname,namefmt,lvl->optns.levels_path);
02664 }
02665
02671 char *get_lvl_fname(struct LEVEL *lvl)
02672 {
02673 if (lvl==NULL) return "";
02674 if (lvl->fname == NULL)
02675 return "";
02676 return lvl->fname;
02677 }
02678
02685 short set_lvl_savfname(struct LEVEL *lvl,char *fname)
02686 {
02687 if (lvl==NULL) return false;
02688 if (fname == NULL)
02689 {
02690 free(lvl->savfname);
02691 lvl->savfname=NULL;
02692 }
02693 free(lvl->savfname);
02694 lvl->savfname=strdup(fname);
02695 if (lvl->savfname==NULL)
02696 return false;
02697 return true;
02698 }
02699
02707 short format_lvl_savfname(struct LEVEL *lvl,char *namefmt)
02708 {
02709 if (lvl==NULL) return false;
02710 if (namefmt == NULL)
02711 {
02712 free(lvl->savfname);
02713 lvl->savfname=NULL;
02714 }
02715 free(lvl->savfname);
02716 lvl->savfname=(char *)malloc(DISKPATH_SIZE*sizeof(char));
02717 if (lvl->savfname==NULL)
02718 return false;
02719 return format_map_fname(lvl->savfname,namefmt,lvl->optns.levels_path);
02720 }
02721
02727 char *get_lvl_savfname(struct LEVEL *lvl)
02728 {
02729 if (lvl==NULL) return "";
02730 if (lvl->savfname == NULL)
02731 return "";
02732 return lvl->savfname;
02733 }
02734
02740 char *get_lif_name_text(struct LEVEL *lvl)
02741 {
02742 if (lvl==NULL) return "";
02743 if (lvl->info.name_text == NULL)
02744 return "";
02745 return lvl->info.name_text;
02746 }
02747
02755 short set_lif_name_text(struct LEVEL *lvl,char *name)
02756 {
02757 if (lvl==NULL) return false;
02758 free(lvl->info.name_text);
02759 lvl->info.name_text=name;
02760 return true;
02761 }
02762
02770 short set_levels_path(struct LEVEL *lvl,char *lvpath)
02771 {
02772 if (lvl==NULL) return false;
02773 if (lvpath == NULL)
02774 {
02775 free(lvl->optns.levels_path);
02776 lvl->optns.levels_path=NULL;
02777 return true;
02778 }
02779 free(lvl->optns.levels_path);
02780 lvl->optns.levels_path=strdup(lvpath);
02781 if (lvl->optns.levels_path==NULL)
02782 return false;
02783 return true;
02784 }
02785
02791 char *get_levels_path(struct LEVEL *lvl)
02792 {
02793 if (lvl==NULL) return NULL;
02794 return lvl->optns.levels_path;
02795 }
02796
02804 short set_data_path(struct LEVEL *lvl,char *datpath)
02805 {
02806 if (lvl==NULL) return false;
02807 if (datpath == NULL)
02808 {
02809 free(lvl->optns.data_path);
02810 lvl->optns.data_path=NULL;
02811 lvl->optns.picture.data_path=lvl->optns.data_path;
02812 return true;
02813 }
02814 free(lvl->optns.data_path);
02815 lvl->optns.data_path=strdup(datpath);
02816 lvl->optns.picture.data_path=lvl->optns.data_path;
02817 if (lvl->optns.data_path==NULL)
02818 return false;
02819 return true;
02820 }
02821
02827 char *get_data_path(struct LEVEL *lvl)
02828 {
02829 if (lvl==NULL) return NULL;
02830 return lvl->optns.data_path;
02831 }
02832
02838 struct DK_SCRIPT *get_lvl_script(struct LEVEL *lvl)
02839 {
02840 if (lvl==NULL) return NULL;
02841 return &(lvl->script);
02842 }
02843
02849 struct LEVSTATS *get_lvl_stats(struct LEVEL *lvl)
02850 {
02851 if (lvl==NULL) return NULL;
02852 return &(lvl->stats);
02853 }
02854
02861 unsigned long inc_info_usr_mdswtch_count(struct LEVEL *lvl)
02862 {
02863 if (lvl==NULL) return false;
02864 lvl->info.usr_mdswtch_count++;
02865 return lvl->info.usr_mdswtch_count;
02866 }
02867
02874 unsigned long inc_info_usr_slbchng_count(struct LEVEL *lvl)
02875 {
02876 if (lvl==NULL) return false;
02877 lvl->info.usr_slbchng_count++;
02878 return lvl->info.usr_slbchng_count;
02879 }
02880
02887 unsigned long inc_info_usr_cmds_count(struct LEVEL *lvl)
02888 {
02889 if (lvl==NULL) return false;
02890 lvl->info.usr_cmds_count++;
02891 return lvl->info.usr_cmds_count;
02892 }
02893
02900 unsigned long inc_info_usr_creatobj_count(struct LEVEL *lvl)
02901 {
02902 if (lvl==NULL) return false;
02903 lvl->info.usr_creatobj_count++;
02904 return lvl->info.usr_creatobj_count;
02905 }
02906
02912 unsigned int inc_info_ver_major(struct LEVEL *lvl)
02913 {
02914 if (lvl==NULL) return false;
02915 lvl->info.ver_major++;
02916 lvl->info.ver_minor=0;
02917 lvl->info.ver_rel=0;
02918 return lvl->info.ver_major;
02919 }
02920
02926 unsigned int inc_info_ver_minor(struct LEVEL *lvl)
02927 {
02928 if (lvl==NULL) return false;
02929 lvl->info.ver_minor++;
02930 lvl->info.ver_rel=0;
02931 return lvl->info.ver_minor;
02932 }
02933
02939 unsigned int inc_info_ver_rel(struct LEVEL *lvl)
02940 {
02941 if (lvl==NULL) return false;
02942 lvl->info.ver_rel++;
02943 return lvl->info.ver_rel++;
02944 }
02945
02951 unsigned char get_lvl_inf(struct LEVEL *lvl)
02952 {
02953 if (lvl==NULL) return 0;
02954 return lvl->inf;
02955 }
02956
02963 short get_lvl_format_version(struct LEVEL *lvl)
02964 {
02965 if (lvl==NULL) return MFV_DKSTD;
02966 return lvl->format_version;
02967 }
02968
02975 short set_lvl_inf(struct LEVEL *lvl,unsigned char ninf)
02976 {
02977 if (lvl==NULL) return false;
02978 lvl->inf=ninf;
02979 return true;
02980 }
02981
02989 short get_level_objstats_textln(struct LEVEL *lvl,char *stat_buf,const int line_num)
02990 {
02991 struct LEVSTATS *stats=get_lvl_stats(lvl);
02992 switch (line_num)
02993 {
02994 case 0:
02995 sprintf(stat_buf,"Map objects statistics");
02996 return STLT_HEADER;
02997 case 1:
02998 sprintf(stat_buf,"Static lights:%4d",get_lgt_total_count(lvl));
02999 return STLT_MAINITEM;
03000 case 2:
03001 sprintf(stat_buf,"Graffiti:%5d",get_graffiti_count(lvl));
03002 return STLT_MAINITEM;
03003 case 3:
03004 sprintf(stat_buf,"Action points:%4d",get_apt_total_count(lvl));
03005 return STLT_MAINITEM;
03006 case 4:
03007 sprintf(stat_buf,"Cust.clms:%4d",get_cust_clm_count(lvl));
03008 return STLT_MAINITEM;
03009 case 5:
03010 sprintf(stat_buf,"Things on map:%4d",get_tng_total_count(lvl));
03011 return STLT_HEADER;
03012 case 6:
03013 sprintf(stat_buf,"Creatures:%6d",stats->creatures_count);
03014 return STLT_SUBITEM;
03015 case 7:
03016 sprintf(stat_buf,"Traps:%4d",stats->traps_count);
03017 return STLT_SUBITEM;
03018 case 8:
03019 sprintf(stat_buf,"EffctGenrts:%4d",stats->effectgenrts_count);
03020 return STLT_SUBITEM;
03021 case 9:
03022 sprintf(stat_buf,"Doors:%4d",stats->doors_count);
03023 return STLT_SUBITEM;
03024 case 10:
03025 sprintf(stat_buf,"Room things:%4d",stats->room_things_count);
03026 return STLT_SUBITEM;
03027 case 11:
03028 sprintf(stat_buf,"Items:%4d",stats->items_count);
03029 return STLT_SUBITEM;
03030 case 12:
03031 sprintf(stat_buf,"Detailed items");
03032 return STLT_HEADER;
03033 case 13:
03034 sprintf(stat_buf,"Dung hearts:%4d",stats->dn_hearts_count);
03035 return STLT_SUBITEM;
03036 case 14:
03037 sprintf(stat_buf,"Hero gates:%3d",stats->hero_gates_count);
03038 return STLT_SUBITEM;
03039 case 15:
03040 sprintf(stat_buf,"%9s:%6d",get_thing_category_shortname(THING_CATEGR_ITEMEFFCT),
03041 stats->things_count[THING_CATEGR_ITEMEFFCT]);
03042 return STLT_SUBITEM;
03043 case 16:
03044 sprintf(stat_buf,"%9s:%4d",get_thing_category_shortname(THING_CATEGR_CREATLAIR),
03045 stats->things_count[THING_CATEGR_CREATLAIR]);
03046 return STLT_SUBITEM;
03047 case 17:
03048 sprintf(stat_buf,"%9s:%6d",get_thing_category_shortname(THING_CATEGR_SPECIALBOX),
03049 stats->things_count[THING_CATEGR_SPECIALBOX]);
03050 return STLT_SUBITEM;
03051 case 18:
03052 sprintf(stat_buf,"%9s:%4d",get_thing_category_shortname(THING_CATEGR_SPELLBOOK),
03053 stats->things_count[THING_CATEGR_SPELLBOOK]);
03054 return STLT_SUBITEM;
03055 case 19:
03056 sprintf(stat_buf,"%9s:%6d",get_thing_category_shortname(THING_CATEGR_WRKSHOPBOX),
03057 stats->things_count[THING_CATEGR_WRKSHOPBOX]);
03058 return STLT_SUBITEM;
03059 case 20:
03060 sprintf(stat_buf,"%9s:%4d",get_thing_category_shortname(THING_CATEGR_SPINNTNG),
03061 stats->things_count[THING_CATEGR_SPINNTNG]);
03062 return STLT_SUBITEM;
03063 case 21:
03064 sprintf(stat_buf,"%9s:%6d",get_thing_category_shortname(THING_CATEGR_FOOD),
03065 stats->things_count[THING_CATEGR_FOOD]);
03066 return STLT_SUBITEM;
03067 case 22:
03068 sprintf(stat_buf,"%9s:%4d",get_thing_category_shortname(THING_CATEGR_GOLD),
03069 stats->things_count[THING_CATEGR_GOLD]);
03070 return STLT_SUBITEM;
03071 case 23:
03072 sprintf(stat_buf,"%9s:%6d",get_thing_category_shortname(THING_CATEGR_TORCHCNDL),
03073 stats->things_count[THING_CATEGR_TORCHCNDL]);
03074 return STLT_SUBITEM;
03075 case 24:
03076 sprintf(stat_buf,"%9s:%4d",get_thing_category_shortname(THING_CATEGR_HEARTFLAME),
03077 stats->things_count[THING_CATEGR_HEARTFLAME]);
03078 return STLT_SUBITEM;
03079 case 25:
03080 sprintf(stat_buf,"%9s:%6d",get_thing_category_shortname(THING_CATEGR_POLEBAR),
03081 stats->things_count[THING_CATEGR_POLEBAR]);
03082 return STLT_SUBITEM;
03083 case 26:
03084 sprintf(stat_buf,"%9s:%4d",get_thing_category_shortname(THING_CATEGR_STATUE),
03085 stats->things_count[THING_CATEGR_STATUE]);
03086 return STLT_SUBITEM;
03087 case 27:
03088 sprintf(stat_buf,"%9s:%6d",get_thing_category_shortname(THING_CATEGR_FURNITURE),
03089 stats->things_count[THING_CATEGR_FURNITURE]);
03090 return STLT_SUBITEM;
03091 case 28:
03092 sprintf(stat_buf,"%9s:%4d",get_thing_category_shortname(THING_CATEGR_ROOMEQUIP),
03093 stats->things_count[THING_CATEGR_ROOMEQUIP]);
03094 return STLT_SUBITEM;
03095 case 29:
03096 sprintf(stat_buf,"%9s:%6d",get_thing_category_shortname(THING_CATEGR_PWHAND),
03097 stats->things_count[THING_CATEGR_PWHAND]);
03098 return STLT_SUBITEM;
03099 default:
03100 stat_buf[0]='\0';
03101 return STLT_NONE;
03102 }
03103 }
03104
03113 short user_set_slab(struct LEVEL *lvl, unsigned int tx, unsigned int ty, unsigned short nslab)
03114 {
03115
03116 set_tile_slab(lvl,tx,ty,nslab);
03117
03118 inc_info_usr_slbchng_count(lvl);
03119
03120 if (get_obj_auto_update(lvl))
03121 update_obj_for_square_radius1(lvl,tx,ty);
03122 if (get_datclm_auto_update(lvl))
03123 update_datclm_for_square_radius1(lvl,tx,ty);
03124 if (get_obj_auto_update(lvl))
03125 update_obj_subpos_and_height_for_square_radius1(lvl,tx,ty);
03126 return true;
03127 }
03128
03137 short user_set_tile_owner(struct LEVEL *lvl, unsigned int tx, unsigned int ty, unsigned short nown)
03138 {
03139
03140 set_tile_owner(lvl,tx,ty,nown);
03141
03142 inc_info_usr_slbchng_count(lvl);
03143
03144 if (get_obj_auto_update(lvl))
03145 update_obj_for_square_radius1(lvl,tx,ty);
03146 if (get_datclm_auto_update(lvl))
03147 update_datclm_for_square_radius1(lvl,tx,ty);
03148 if (get_obj_auto_update(lvl))
03149 update_obj_subpos_and_height_for_square_radius1(lvl,tx,ty);
03150 return true;
03151 }
03152
03161 short user_set_slab_rect(struct LEVEL *lvl, unsigned int startx, unsigned int endx,
03162 unsigned int starty, unsigned int endy, unsigned short nslab)
03163 {
03164
03165 if ((endx>=lvl->tlsize.x) || (endy>=lvl->tlsize.y) ||
03166 (startx>endx) || (starty>endy) )
03167 {
03168 message_error("Map coordinates out of bounds");
03169 return false;
03170 }
03171 int tile_x,tile_y;
03172 for (tile_x=startx; tile_x<=endx; tile_x++)
03173 for (tile_y=starty; tile_y<=endy; tile_y++)
03174 {
03175
03176
03177 set_tile_slab(lvl,tile_x,tile_y,nslab);
03178 inc_info_usr_slbchng_count(lvl);
03179 }
03180 if (get_obj_auto_update(lvl))
03181 update_obj_for_square(lvl, startx-1, endx+1, starty-1, endy+1);
03182 if (get_datclm_auto_update(lvl))
03183 update_datclm_for_square(lvl, startx-1, endx+1, starty-1, endy+1);
03184 if (get_obj_auto_update(lvl))
03185 update_obj_subpos_and_height_for_square(lvl, startx-1, endx+1, starty-1, endy+1);
03186 return true;
03187 }
03188
03197 short user_set_owner_rect(struct LEVEL *lvl, unsigned int startx, unsigned int endx,
03198 unsigned int starty, unsigned int endy, unsigned short nown)
03199 {
03200
03201 if ((endx>=lvl->tlsize.x) || (endy>=lvl->tlsize.y) ||
03202 (startx>endx) || (starty>endy) )
03203 {
03204 message_error("Map coordinates out of bounds");
03205 return false;
03206 }
03207 int tile_x,tile_y;
03208 for (tile_x=startx; tile_x<=endx; tile_x++)
03209 for (tile_y=starty; tile_y<=endy; tile_y++)
03210 {
03211 set_tile_owner(lvl,tile_x,tile_y,nown);
03212 inc_info_usr_slbchng_count(lvl);
03213 }
03214 if (get_obj_auto_update(lvl))
03215 update_obj_for_square(lvl, startx-1, endx+1, starty-1, endy+1);
03216 if (get_datclm_auto_update(lvl))
03217 update_datclm_for_square(lvl, startx-1, endx+1, starty-1, endy+1);
03218 if (get_obj_auto_update(lvl))
03219 update_obj_subpos_and_height_for_square(lvl, startx-1, endx+1, starty-1, endy+1);
03220 return true;
03221 }
03222
03232 short user_set_slabown_rect(struct LEVEL *lvl, unsigned int startx, unsigned int endx,
03233 unsigned int starty, unsigned int endy, unsigned short nslab,unsigned short nown)
03234 {
03235
03236 if ((endx>=lvl->tlsize.x) || (endy>=lvl->tlsize.y) ||
03237 (startx>endx) || (starty>endy) )
03238 {
03239 message_error("Map coordinates out of bounds");
03240 return false;
03241 }
03242 int tile_x,tile_y;
03243 for (tile_x=startx; tile_x<=endx; tile_x++)
03244 for (tile_y=starty; tile_y<=endy; tile_y++)
03245 {
03246 set_tile_slab(lvl,tile_x,tile_y,nslab);
03247 set_tile_owner(lvl,tile_x,tile_y,nown);
03248 inc_info_usr_slbchng_count(lvl);
03249 }
03250 if (get_obj_auto_update(lvl))
03251 update_obj_for_square(lvl, startx-1, endx+1, starty-1, endy+1);
03252 if (get_datclm_auto_update(lvl))
03253 update_datclm_for_square(lvl, startx-1, endx+1, starty-1, endy+1);
03254 if (get_obj_auto_update(lvl))
03255 update_obj_subpos_and_height_for_square(lvl, startx-1, endx+1, starty-1, endy+1);
03256 return true;
03257 }