00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "lev_script.h"
00021
00022 #include "globals.h"
00023 #include "arr_utils.h"
00024 #include "lev_data.h"
00025 #include "obj_column_def.h"
00026 #include "obj_slabs.h"
00027 #include "obj_column.h"
00028 #include "lev_column.h"
00029
00030
00031 const char if_cmdtext[]="IF";
00032 const char if_available_cmdtext[]="IF_AVAILABLE";
00033 const char if_actnpt_cmdtext[]="IF_ACTION_POINT";
00034 const char endif_cmdtext[]="ENDIF";
00035
00036 const char *cmd_condit_arr[]={
00037 "",if_cmdtext,if_available_cmdtext,
00038 if_actnpt_cmdtext,endif_cmdtext,
00039 };
00040
00041
00042 const char custom_column_cmdtext[]="CUSTOM_COLUMN";
00043 const char graffiti_cmdtext[]="GRAFFITI";
00044 const char leveltimestmp_cmdtext[]="LEVEL_TIMESTAMP";
00045 const char usrcmnds_count_cmdtext[]="USER_COMMANDS_COUNT";
00046 const char levversion_cmdtext[]="LEVEL_VERSION";
00047 const char levname_cmdtext[]="LEVEL_NAME";
00048 const char levdesc_cmdtext[]="LEVEL_DESCRIPTION";
00049 const char levauthors_cmdtext[]="LEVEL_AUTHORS";
00050
00051
00052 const char *cmd_adikted_arr[]={
00053 "",custom_column_cmdtext,graffiti_cmdtext,
00054 leveltimestmp_cmdtext,usrcmnds_count_cmdtext,levversion_cmdtext,
00055 levname_cmdtext, levdesc_cmdtext, levauthors_cmdtext,
00056 };
00057
00058
00059 const char create_party_cmdtext[]="CREATE_PARTY";
00060 const char add_tunneler_tolev_cmdtext[]="ADD_TUNNELLER_TO_LEVEL";
00061 const char add_to_party_cmdtext[]="ADD_TO_PARTY";
00062 const char add_party_tolev_cmdtext[]="ADD_PARTY_TO_LEVEL";
00063 const char add_creatr_tolev_cmdtext[]="ADD_CREATURE_TO_LEVEL";
00064 const char add_tunneller_party_tolev_cmdtext[]="ADD_TUNNELLER_PARTY_TO_LEVEL";
00065
00066 const char *cmd_party_arr[]={
00067 "",create_party_cmdtext,add_tunneler_tolev_cmdtext,
00068 add_to_party_cmdtext,add_party_tolev_cmdtext,add_creatr_tolev_cmdtext,
00069 add_tunneller_party_tolev_cmdtext,
00070 };
00071
00072
00073 const char room_avail_cmdtext[]="ROOM_AVAILABLE";
00074 const char creatr_avail_cmdtext[]="CREATURE_AVAILABLE";
00075 const char magic_avail_cmdtext[]="MAGIC_AVAILABLE";
00076 const char trap_avail_cmdtext[]="TRAP_AVAILABLE";
00077 const char door_avail_cmdtext[]="DOOR_AVAILABLE";
00078
00079 const char *cmd_avail_arr[]={
00080 "",room_avail_cmdtext,creatr_avail_cmdtext,
00081 magic_avail_cmdtext,trap_avail_cmdtext,door_avail_cmdtext,
00082 };
00083
00084
00085 const char display_objectv_cmdtext[]="DISPLAY_OBJECTIVE";
00086 const char display_objectv_wpos_cmdtext[]="DISPLAY_OBJECTIVE_WITH_POS";
00087 const char display_info_cmdtext[]="DISPLAY_INFORMATION";
00088 const char display_info_wpos_cmdtext[]="DISPLAY_INFORMATION_WITH_POS";
00089 const char bonus_lev_time_cmdtext[]="BONUS_LEVEL_TIME";
00090 const char tutorial_flash_btn_cmdtext[]="TUTORIAL_FLASH_BUTTON";
00091 const char quick_objectv_cmdtext[]="QUICK_OBJECTIVE";
00092 const char quick_info_cmdtext[]="QUICK_INFORMATION";
00093
00094 const char *cmd_custobj_arr[]={
00095 "",display_objectv_cmdtext,display_objectv_wpos_cmdtext,
00096 display_info_cmdtext,display_info_wpos_cmdtext,bonus_lev_time_cmdtext,
00097 tutorial_flash_btn_cmdtext,quick_objectv_cmdtext,quick_info_cmdtext,
00098 };
00099
00100
00101 const char set_gen_speed_cmdtext[]="SET_GENERATE_SPEED";
00102 const char start_money_cmdtext[]="START_MONEY";
00103 const char comp_player_cmdtext[]="COMPUTER_PLAYER";
00104 const char ally_players_cmdtext[]="ALLY_PLAYERS";
00105 const char set_hate_cmdtext[]="SET_HATE";
00106 const char resrch_cmdtext[]="RESEARCH";
00107 const char set_computer_globals_cmdtext[]="SET_COMPUTER_GLOBALS";
00108 const char set_computer_checks_cmdtext[]="SET_COMPUTER_CHECKS";
00109 const char set_computer_event_cmdtext[]="SET_COMPUTER_EVENT";
00110 const char set_computer_process_cmdtext[]="SET_COMPUTER_PROCESS";
00111 const char max_creatures_cmdtext[]="MAX_CREATURES";
00112
00113 const char *cmd_setup_arr[]={
00114 "",set_gen_speed_cmdtext,start_money_cmdtext,
00115 resrch_cmdtext,comp_player_cmdtext,ally_players_cmdtext,
00116 set_hate_cmdtext,
00117 set_computer_globals_cmdtext,set_computer_checks_cmdtext,
00118 set_computer_event_cmdtext,set_computer_process_cmdtext,
00119 max_creatures_cmdtext,};
00120
00121
00122 const char reset_actnpt_cmdtext[]="RESET_ACTION_POINT";
00123 const char next_cmd_reusable_cmdtext[]="NEXT_COMMAND_REUSABLE";
00124 const char set_flag_cmdtext[]="SET_FLAG";
00125 const char set_timer_cmdtext[]="SET_TIMER";
00126 const char game_lose_cmdtext[]="LOSE_GAME";
00127 const char game_win_cmdtext[]="WIN_GAME";
00128 const char set_music_cmdtext[]="SET_MUSIC";
00129
00130 const char *cmd_triger_arr[]={
00131 "",reset_actnpt_cmdtext,next_cmd_reusable_cmdtext,
00132 set_flag_cmdtext,set_timer_cmdtext,
00133 game_lose_cmdtext,game_win_cmdtext,
00134 set_music_cmdtext,};
00135
00136
00137 const char dead_creatures_ret_to_pool_cmdtext[]="DEAD_CREATURES_RETURN_TO_POOL";
00138 const char add_creatr_to_pool_cmdtext[]="ADD_CREATURE_TO_POOL";
00139 const char set_creatr_fear_cmdtext[]="SET_CREATURE_FEAR";
00140 const char set_creatr_armour_cmdtext[]="SET_CREATURE_ARMOUR";
00141 const char set_creatr_health_cmdtext[]="SET_CREATURE_HEALTH";
00142 const char set_creatr_strength_cmdtext[]="SET_CREATURE_STRENGTH";
00143 const char set_creatr_max_level_cmdtext[]="SET_CREATURE_MAX_LEVEL";
00144 const char creatr_swap_cmdtext[]="SWAP_CREATURE";
00145
00146 const char *cmd_crtradj_arr[]={
00147 "",dead_creatures_ret_to_pool_cmdtext,
00148 add_creatr_to_pool_cmdtext,set_creatr_max_level_cmdtext,
00149 set_creatr_strength_cmdtext,set_creatr_health_cmdtext,
00150 set_creatr_armour_cmdtext,set_creatr_fear_cmdtext,
00151 creatr_swap_cmdtext,
00152 };
00153
00154
00155 const char rem_cmdtext[]="REM";
00156 const char emptyln_cmdtext[]="";
00157 const char *cmd_commnt_arr[]={
00158 "",emptyln_cmdtext,rem_cmdtext,
00159 };
00160
00161
00162 const char print_cmdtext[]="PRINT";
00163 const char create_text_cmdtext[]="CREATE_TEXT";
00164 const char *cmd_obsolt_arr[]={
00165 "",print_cmdtext,create_text_cmdtext,
00166 };
00167
00168
00169 const char random_cmdtext[]="RANDOM";
00170
00171
00172
00173 const char flag0_cmdtext[]="FLAG0";
00174 const char flag1_cmdtext[]="FLAG1";
00175 const char flag2_cmdtext[]="FLAG2";
00176 const char flag3_cmdtext[]="FLAG3";
00177 const char flag4_cmdtext[]="FLAG4";
00178 const char flag5_cmdtext[]="FLAG5";
00179 const char flag6_cmdtext[]="FLAG6";
00180 const char flag7_cmdtext[]="FLAG7";
00181
00182 const char *cmd_flag_arr[]={
00183 "",flag0_cmdtext,flag1_cmdtext,
00184 flag2_cmdtext,flag3_cmdtext,flag4_cmdtext,
00185 flag5_cmdtext,flag6_cmdtext,flag7_cmdtext,
00186 };
00187
00188
00189 const char timer0_cmdtext[]="TIMER0";
00190 const char timer1_cmdtext[]="TIMER1";
00191 const char timer2_cmdtext[]="TIMER2";
00192 const char timer3_cmdtext[]="TIMER3";
00193 const char timer4_cmdtext[]="TIMER4";
00194 const char timer5_cmdtext[]="TIMER5";
00195 const char timer6_cmdtext[]="TIMER6";
00196 const char timer7_cmdtext[]="TIMER7";
00197
00198 const char *cmd_timer_arr[]={
00199 "",timer0_cmdtext,timer1_cmdtext,
00200 timer2_cmdtext,timer3_cmdtext,timer4_cmdtext,
00201 timer5_cmdtext,timer6_cmdtext,timer7_cmdtext,
00202 };
00203
00204
00205 const char oper_equ_cmdtext[]="==";
00206 const char oper_neq_cmdtext[]="!=";
00207 const char oper_less_cmdtext[]="<";
00208 const char oper_grtr_cmdtext[]=">";
00209 const char oper_lesseq_cmdtext[]="<=";
00210 const char oper_grtreq_cmdtext[]=">=";
00211
00212 const char *cmd_operator_arr[]={
00213 "",oper_equ_cmdtext,oper_neq_cmdtext,
00214 oper_less_cmdtext,oper_grtr_cmdtext,oper_lesseq_cmdtext,
00215 oper_grtreq_cmdtext,
00216 };
00217
00218
00219 const char all_dngns_destroyed_cmdtext[]="ALL_DUNGEONS_DESTROYED";
00220 const char crtrs_scavng_gained_cmdtext[]="CREATURES_SCAVENGED_GAINED";
00221 const char crtrs_scavng_lost_cmdtext[]="CREATURES_SCAVENGED_LOST";
00222 const char doors_destroyed_cmdtext[]="DOORS_DESTROYED";
00223 const char total_gold_mined_cmdtext[]="TOTAL_GOLD_MINED";
00224 const char dngn_destroyed_cmdtext[]="DUNGEON_DESTROYED";
00225 const char gold_pots_stolen_cmdtext[]="GOLD_POTS_STOLEN";
00226 const char times_broken_into_cmdtext[]="TIMES_BROKEN_INTO";
00227 const char spells_stolen_cmdtext[]="SPELLS_STOLEN";
00228 const char rooms_destroyed_cmdtext[]="ROOMS_DESTROYED";
00229 const char battles_won_cmdtext[]="BATTLES_WON";
00230 const char battles_lost_cmdtext[]="BATTLES_LOST";
00231 const char creatrs_annoyed_cmdtext[]="CREATURES_ANNOYED";
00232 const char total_creatrs_left_cmdtext[]="TOTAL_CREATURES_LEFT";
00233 const char total_area_cmdtext[]="TOTAL_AREA";
00234 const char total_doors_cmdtext[]="TOTAL_DOORS";
00235 const char total_research_cmdtext[]="TOTAL_RESEARCH";
00236 const char total_creatrs_cmdtext[]="TOTAL_CREATURES";
00237 const char total_imps_cmdtext[]="TOTAL_IMPS";
00238 const char break_in_cmdtext[]="BREAK_IN";
00239 const char game_turn_cmdtext[]="GAME_TURN";
00240 const char money_cmdtext[]="MONEY";
00241
00242 const char *cmd_variabl_arr[]={
00243 "",all_dngns_destroyed_cmdtext,crtrs_scavng_gained_cmdtext,
00244 crtrs_scavng_lost_cmdtext,doors_destroyed_cmdtext,total_gold_mined_cmdtext,
00245 dngn_destroyed_cmdtext,gold_pots_stolen_cmdtext,times_broken_into_cmdtext,
00246 spells_stolen_cmdtext,rooms_destroyed_cmdtext,battles_won_cmdtext,
00247 battles_lost_cmdtext,creatrs_annoyed_cmdtext,total_creatrs_left_cmdtext,
00248 total_area_cmdtext,total_doors_cmdtext,total_research_cmdtext,
00249 total_creatrs_cmdtext,total_imps_cmdtext,break_in_cmdtext,
00250 game_turn_cmdtext,money_cmdtext,
00251 };
00252
00253
00254 const char objctv_defend_party_cmdtext[]="DEFEND_PARTY";
00255 const char objctv_attack_rooms_cmdtext[]="ATTACK_ROOMS";
00256 const char objctv_attack_dnheart_cmdtext[]="ATTACK_DUNGEON_HEART";
00257 const char objctv_enemies_cmdtext[]="ATTACK_ENEMIES";
00258 const char objctv_steal_spells_cmdtext[]="STEAL_SPELLS";
00259 const char objctv_steal_gold_cmdtext[]="STEAL_GOLD";
00260
00261 const char objctv_approp_dung_cmdtext[]="APPROPIATE_DUNGEON";
00262 const char objctv_dnheart_cmdtext[]="DUNGEON_HEART";
00263 const char objctv_dungeon_cmdtext[]="DUNGEON";
00264 const char objctv_actnpt_cmdtext[]="ACTION_POINT";
00265
00266 const char *cmd_party_objectv_arr[]={
00267 "",objctv_actnpt_cmdtext,objctv_dungeon_cmdtext,
00268 objctv_dnheart_cmdtext,objctv_approp_dung_cmdtext,
00269 objctv_steal_gold_cmdtext,objctv_steal_spells_cmdtext,objctv_enemies_cmdtext,
00270 objctv_attack_dnheart_cmdtext,objctv_attack_rooms_cmdtext,objctv_defend_party_cmdtext,
00271 };
00272
00273
00274 const char comp_sell_trapsdoors_cmdtext[]="COMPUTER_SELL_TRAPS_AND_DOORS";
00275 const char comp_attack_magic_cmdtext[]="COMPUTER_ATTACK_MAGIC";
00276 const char comp_wait_for_bridge_cmdtext[]="COMPUTER_WAIT_FOR_BRIDGE";
00277 const char comp_magic_speed_up_cmdtext[]="COMPUTER_MAGIC_SPEED_UP";
00278 const char comp_dig_to_neutral_cmdtext[]="COMPUTER_DIG_TO_NEUTRAL";
00279 const char comp_slap_imps_cmdtext[]="COMPUTER_SLAP_IMPS";
00280 const char comp_move_creatrs_todefens_cmdtext[]="COMPUTER_MOVE_CREATURES_TO_DEFEND";
00281 const char comp_move_creatrs_topos_cmdtext[]="COMPUTER_MOVE_CREATURE_TO_POS";
00282 const char comp_move_creatrs_toroom_cmdtext[]="COMPUTER_MOVE_CREATURE_TO_ROOM";
00283 const char comp_pickup_for_attack_cmdtext[]="COMPUTER_PICKUP_FOR_ATTACK";
00284 const char comp_magic_callarms_cmdtext[]="COMPUTER_MAGIC_CALL_TO_ARMS";
00285 const char comp_dig_toattack_cmdtext[]="COMPUTER_DIG_TO_ATTACK";
00286 const char comp_dig_togold_cmdtext[]="COMPUTER_DIG_TO_GOLD";
00287 const char comp_dig_toentrnce_cmdtext[]="COMPUTER_DIG_TO_ENTRANCE";
00288 const char comp_place_room_cmdtext[]="COMPUTER_PLACE_ROOM";
00289 const char comp_check_room_dug_cmdtext[]="COMPUTER_CHECK_ROOM_DUG";
00290 const char comp_dig_room_cmdtext[]="COMPUTER_DIG_ROOM";
00291 const char comp_dig_room_passage_cmdtext[]="COMPUTER_DIG_ROOM_PASSAGE";
00292
00293 const char *cmd_comp_plyr_arr[]={
00294 "",comp_sell_trapsdoors_cmdtext,comp_attack_magic_cmdtext,
00295 comp_wait_for_bridge_cmdtext,comp_magic_speed_up_cmdtext,comp_dig_to_neutral_cmdtext,
00296 comp_slap_imps_cmdtext,comp_move_creatrs_todefens_cmdtext,comp_move_creatrs_topos_cmdtext,
00297 comp_move_creatrs_toroom_cmdtext,comp_pickup_for_attack_cmdtext,comp_magic_callarms_cmdtext,
00298 comp_dig_toattack_cmdtext,comp_dig_togold_cmdtext,comp_dig_toentrnce_cmdtext,
00299 comp_place_room_cmdtext,comp_check_room_dug_cmdtext,comp_dig_room_cmdtext,
00300 comp_dig_room_passage_cmdtext,
00301 };
00302
00303 const char obj_room_cmdtext[]="ROOM";
00304 const char obj_magic_cmdtext[]="MAGIC";
00305 const char obj_creature_cmdtext[]="CREATURE";
00306
00307
00308 const char *cmd_objtype_arr[]={
00309 "",obj_creature_cmdtext,"\t",
00310 obj_room_cmdtext,obj_magic_cmdtext,
00311 };
00312
00313
00314 const char door_steel_cmdtext[]="STEEL";
00315 const char door_braced_cmdtext[]="BRACED";
00316 const char door_wood_cmdtext[]="WOOD";
00317 const char door_magic_cmdtext[]="MAGIC";
00318
00319 const char *cmd_doors_arr[]={
00320 "", door_wood_cmdtext, door_braced_cmdtext,
00321 door_steel_cmdtext,door_magic_cmdtext,
00322 };
00323 const char *cmd_doors_fullname[]={
00324 "", "Wooden", "Braced",
00325 "Iron", "Magic",
00326 };
00327
00328
00329 const char trap_boulder_cmdtext[]="BOULDER";
00330 const char trap_alarm_cmdtext[]="ALARM";
00331 const char trap_gas_cmdtext[]="POISON_GAS";
00332 const char trap_lightng_cmdtext[]="LIGHTNING";
00333 const char trap_wordpwr_cmdtext[]="WORD_OF_POWER";
00334 const char trap_lava_cmdtext[]="LAVA";
00335
00336 const char *cmd_traps_arr[]={
00337 "", trap_boulder_cmdtext, trap_alarm_cmdtext,
00338 trap_gas_cmdtext,trap_lightng_cmdtext,trap_wordpwr_cmdtext,
00339 trap_lava_cmdtext,
00340 };
00341 const char *cmd_traps_fullname[]={
00342 "", "Boulder", "Alarm",
00343 "Poison gas", "Lightning", "Word of Power",
00344 "Lava",
00345 };
00346
00347
00348 const char spell_armag_cmdtext[]="POWER_ARMAGEDDON";
00349 const char spell_possess_cmdtext[]="POWER_POSSESS";
00350 const char spell_destrwalls_cmdtext[]="POWER_DESTROY_WALLS";
00351 const char spell_chickn_cmdtext[]="POWER_CHICKEN";
00352 const char spell_disease_cmdtext[]="POWER_DISEASE";
00353 const char spell_conceal_cmdtext[]="POWER_CONCEAL";
00354 const char spell_protect_cmdtext[]="POWER_PROTECT";
00355 const char spell_speed_cmdtext[]="POWER_SPEED";
00356 const char spell_lightng_cmdtext[]="POWER_LIGHTNING";
00357 const char spell_holdaud_cmdtext[]="POWER_HOLD_AUDIENCE";
00358 const char spell_healcrtr_cmdtext[]="POWER_HEAL_CREATURE";
00359 const char spell_cavein_cmdtext[]="POWER_CAVE_IN";
00360 const char spell_callarms_cmdtext[]="POWER_CALL_TO_ARMS";
00361 const char spell_sight_cmdtext[]="POWER_SIGHT";
00362 const char spell_slap_cmdtext[]="POWER_SLAP";
00363 const char spell_obey_cmdtext[]="POWER_OBEY";
00364 const char spell_imp_cmdtext[]="POWER_IMP";
00365 const char spell_hand_cmdtext[]="POWER_HAND";
00366
00367 const char *cmd_spells_arr[]={
00368 "", spell_hand_cmdtext, spell_imp_cmdtext,
00369 spell_obey_cmdtext,spell_slap_cmdtext,spell_sight_cmdtext,
00370 spell_callarms_cmdtext,spell_cavein_cmdtext,spell_healcrtr_cmdtext,
00371 spell_holdaud_cmdtext,spell_lightng_cmdtext,spell_speed_cmdtext,
00372 spell_protect_cmdtext,spell_conceal_cmdtext,spell_disease_cmdtext,
00373 spell_chickn_cmdtext,spell_destrwalls_cmdtext,spell_possess_cmdtext,
00374 spell_armag_cmdtext,
00375 };
00376 const char *cmd_spells_fullname[]={
00377 "", "Hand of Evil", "Create imp",
00378 "Must obey", "Slap", "Evil Sight",
00379 "Call to arms", "Cave in", "Heal creature",
00380 "Hold audience", "Lightning", "Speed",
00381 "Protect", "Conceal", "Disease",
00382 "Chicken", "Destroy walls", "Possess",
00383 "Armageddon",
00384 };
00385
00386
00387 const char player_all_cmdtext[]="ALL_PLAYERS";
00388 const char player_good_cmdtext[]="PLAYER_GOOD";
00389 const char player3_cmdtext[]="PLAYER3";
00390 const char player2_cmdtext[]="PLAYER2";
00391 const char player1_cmdtext[]="PLAYER1";
00392 const char player0_cmdtext[]="PLAYER0";
00393
00394 const char *cmd_players_arr[]={
00395 player0_cmdtext,player1_cmdtext,player2_cmdtext,
00396 player3_cmdtext,player_good_cmdtext,"\t",
00397 player_all_cmdtext,
00398 };
00399
00400 const char creatr_horny_cmdtext[]="HORNY";
00401 const char creatr_skeleton_cmdtext[]="SKELETON";
00402 const char creatr_troll_cmdtext[]="TROLL";
00403 const char creatr_dragon_cmdtext[]="DRAGON";
00404 const char creatr_dmspawn_cmdtext[]="DEMONSPAWN";
00405 const char creatr_fly_cmdtext[]="FLY";
00406 const char creatr_dkmist_cmdtext[]="DARK_MISTRESS";
00407 const char creatr_sorcer_cmdtext[]="SORCEROR";
00408 const char creatr_biledm_cmdtext[]="BILE_DEMON";
00409 const char creatr_imp_cmdtext[]="IMP";
00410 const char creatr_bug_cmdtext[]="BUG";
00411 const char creatr_vampire_cmdtext[]="VAMPIRE";
00412 const char creatr_spider_cmdtext[]="SPIDER";
00413 const char creatr_hound_cmdtext[]="HELL_HOUND";
00414 const char creatr_ghost_cmdtext[]="GHOST";
00415 const char creatr_tentacl_cmdtext[]="TENTACLE";
00416 const char creatr_orc_cmdtext[]="ORC";
00417
00418 const char creatr_wizard_cmdtext[]="WIZARD";
00419 const char creatr_barbarin_cmdtext[]="BARBARIAN";
00420 const char creatr_archr_cmdtext[]="ARCHER";
00421 const char creatr_monk_cmdtext[]="MONK";
00422 const char creatr_dwarfa_cmdtext[]="DWARFA";
00423 const char creatr_knight_cmdtext[]="KNIGHT";
00424 const char creatr_avatar_cmdtext[]="AVATAR";
00425 const char creatr_tunnelr_cmdtext[]="TUNNELLER";
00426 const char creatr_witch_cmdtext[]="WITCH";
00427 const char creatr_giant_cmdtext[]="GIANT";
00428 const char creatr_fairy_cmdtext[]="FAIRY";
00429 const char creatr_thief_cmdtext[]="THIEF";
00430 const char creatr_samurai_cmdtext[]="SAMURAI";
00431 const char creatr_newa_cmdtext[]="NEW_CREATURE_B";
00432 const char creatr_newb_cmdtext[]="NEW_CREATURE_A";
00433 const char creatr_flspirit_cmdtext[]="FLOATING_SPIRIT";
00434
00435
00436 const char *cmd_creatures_arr[]={
00437 "", creatr_wizard_cmdtext, creatr_barbarin_cmdtext,
00438 creatr_archr_cmdtext, creatr_monk_cmdtext, creatr_dwarfa_cmdtext,
00439 creatr_knight_cmdtext, creatr_avatar_cmdtext, creatr_tunnelr_cmdtext,
00440 creatr_witch_cmdtext, creatr_giant_cmdtext, creatr_fairy_cmdtext,
00441 creatr_thief_cmdtext, creatr_samurai_cmdtext, creatr_horny_cmdtext,
00442 creatr_skeleton_cmdtext, creatr_troll_cmdtext, creatr_dragon_cmdtext,
00443 creatr_dmspawn_cmdtext, creatr_fly_cmdtext, creatr_dkmist_cmdtext,
00444 creatr_sorcer_cmdtext, creatr_biledm_cmdtext, creatr_imp_cmdtext,
00445 creatr_bug_cmdtext, creatr_vampire_cmdtext, creatr_spider_cmdtext,
00446 creatr_hound_cmdtext, creatr_ghost_cmdtext, creatr_tentacl_cmdtext,
00447 creatr_orc_cmdtext, creatr_flspirit_cmdtext, creatr_newa_cmdtext,
00448 creatr_newb_cmdtext,
00449 };
00450
00451 const char room_grdpost_cmdtext[]="GUARD_POST";
00452 const char room_brige_cmdtext[]="BRIDGE";
00453 const char room_lair_cmdtext[]="LAIR";
00454 const char room_hatchery_cmdtext[]="GARDEN";
00455 const char room_barracks_cmdtext[]="BARRACKS";
00456 const char room_graveyrd_cmdtext[]="GRAVEYARD";
00457 const char room_temple_cmdtext[]="TEMPLE";
00458 const char room_scavng_cmdtext[]="SCAVENGER";
00459 const char room_workshp_cmdtext[]="WORKSHOP";
00460 const char room_training_cmdtext[]="TRAINING";
00461 const char room_torture_cmdtext[]="TORTURE";
00462 const char room_prison_cmdtext[]="PRISON";
00463
00464
00465 const char room_library_cmdtext[]="RESEARCH";
00466 const char room_treasure_cmdtext[]="TREASURE";
00467 const char room_entrance_cmdtext[]="ENTRANCE";
00468
00469 const char *cmd_rooms_arr[]={
00470 "", room_entrance_cmdtext, room_treasure_cmdtext,
00471 room_library_cmdtext,room_prison_cmdtext,room_torture_cmdtext,
00472 room_training_cmdtext,room_workshp_cmdtext,room_scavng_cmdtext,
00473 room_temple_cmdtext,room_graveyrd_cmdtext,room_hatchery_cmdtext,
00474 room_lair_cmdtext,room_barracks_cmdtext,room_brige_cmdtext,
00475 room_grdpost_cmdtext,
00476 };
00477
00478
00479 const char orient_ns_cmdtext[]="ORIENT_NS";
00480 const char orient_we_cmdtext[]="ORIENT_WE";
00481 const char orient_sn_cmdtext[]="ORIENT_SN";
00482 const char orient_ew_cmdtext[]="ORIENT_EW";
00483 const char orient_tpns_cmdtext[]="ORIENT_TOPNS";
00484 const char orient_tpwe_cmdtext[]="ORIENT_TOPWE";
00485 const char orient_tpsn_cmdtext[]="ORIENT_TOPSN";
00486 const char orient_tpew_cmdtext[]="ORIENT_TOPEW";
00487
00488 const short orient_constants[]={
00489 ORIENT_NS,ORIENT_WE,ORIENT_SN,ORIENT_EW,
00490 ORIENT_TNS,ORIENT_TWE,ORIENT_TSN,ORIENT_TEW
00491 };
00492
00493 const char *cmd_orient_arr[]={
00494 orient_ns_cmdtext,orient_we_cmdtext,orient_sn_cmdtext,
00495 orient_ew_cmdtext,orient_tpns_cmdtext, orient_tpwe_cmdtext,
00496 orient_tpsn_cmdtext,orient_tpew_cmdtext,
00497 };
00498
00499
00500 const char font_none_cmdtext[]="FONT_NONE";
00501 const char font_adiclssc_cmdtext[]="FONT_ADICLSSC";
00502 const char font_adisize8_cmdtext[]="FONT_ADISIZE8";
00503
00504 const char *cmd_font_arr[]={
00505 font_none_cmdtext,font_adiclssc_cmdtext,font_adisize8_cmdtext,
00506 };
00507
00508 const char *cmd_orient_shortnames[]={
00509 "NS","WE","SN","EW","TpNS","TpWE","TpSN","TpEW" };
00510
00511 const char *cmd_font_fullnames[]={
00512 "none","Classic","Size 8" };
00513
00514 const char *object_available_shortnames[]={
00515 "None", "Rsch", "Got",};
00516
00517 short script_param_to_int(int *val,const char *param)
00518 {
00519 if ((param==NULL)||(val==NULL)) return false;
00520 int n_read;
00521 if (strncmp(param,"0x",2)==0)
00522 {
00523 n_read=sscanf(param+2,"%x",val);
00524 } else
00525 {
00526 n_read=sscanf(param,"%d",val);
00527 }
00528 return (n_read==1);
00529 }
00530
00531 short script_param_to_ulong(unsigned long *val,const char *param)
00532 {
00533 if ((param==NULL)||(val==NULL)) return false;
00534 int n_read;
00535 if (strncmp(param,"0x",2)==0)
00536 {
00537 n_read=sscanf(param+2,"%lx",val);
00538 } else
00539 {
00540 n_read=sscanf(param,"%lu",val);
00541 }
00542 return (n_read==1);
00543 }
00544
00545
00546
00547
00548 short execute_adikted_command(struct LEVEL *lvl,struct DK_SCRIPT_COMMAND *cmd,char *err_msg)
00549 {
00550 char text[READ_BUFSIZE];
00551 switch (cmd->index)
00552 {
00553 case CUSTOM_COLUMN:
00554 if (cmd->param_count<14)
00555 {
00556 sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index));
00557 return false;
00558 }
00559 int sx=-1,sy=-1;
00560 short result=true;
00561 result&=script_param_to_int(&sx,cmd->params[0]);
00562 result&=script_param_to_int(&sy,cmd->params[1]);
00563 if (!result)
00564 {
00565 sprintf(err_msg,"Cannot read map subtile coordinates");
00566 return false;
00567 }
00568 int wib_val;
00569 int lintel;
00570 int orient;
00571 int base;
00572 result&=script_param_to_int(&wib_val,cmd->params[2]);
00573 result&=script_param_to_int(&lintel,cmd->params[3]);
00574 result&=script_param_to_int(&orient,cmd->params[4]);
00575 result&=script_param_to_int(&base,cmd->params[5]);
00576 if (!result)
00577 {
00578 sprintf(err_msg,"Cannot read basic column parameters");
00579 return false;
00580 }
00581 int c[8];
00582 int i;
00583 for (i=0;i<8;i++)
00584 result&=script_param_to_int(&c[i],cmd->params[6+i]);
00585 if (!result)
00586 {
00587 sprintf(err_msg,"Cannot read column cubes");
00588 return false;
00589 }
00590
00591 struct DK_CUSTOM_CLM *ccol;
00592 ccol=create_cust_col();
00593 struct COLUMN_REC *clm_rec=ccol->rec;
00594 ccol->wib_val=wib_val;
00595 fill_column_rec_sim(clm_rec, 0, base,
00596 c[0],c[1],c[2],c[3],c[4],c[5],c[6],c[7]);
00597 clm_rec->lintel=lintel;
00598 clm_rec->orientation=orient;
00599
00600 cust_col_add_or_update(lvl,sx,sy,ccol);
00601 return true;
00602 case DEFINE_GRAFFITI:
00603 {
00604 if (cmd->param_count<7)
00605 {
00606 sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index));
00607 return false;
00608 }
00609 int tx=-1,ty=-1,height=0;
00610 short result=true;
00611 result&=script_param_to_int(&tx,cmd->params[0]);
00612 result&=script_param_to_int(&ty,cmd->params[1]);
00613 if (!result)
00614 {
00615 sprintf(err_msg,"Cannot read map tile coordinates");
00616 return false;
00617 }
00618 if (sscanf(cmd->params[2],"%d",&height)<1)
00619 {
00620 sprintf(err_msg,"Cannot read height in tile");
00621 return false;
00622 }
00623 int orient;
00624 orient=orient_cmd_index(cmd->params[3]);
00625 int font;
00626 font=font_cmd_index(cmd->params[4]);
00627 if (orient<0) orient=ORIENT_NS;
00628 if (font<0) font=GRAFF_FONT_ADICLSSC;
00629 int i,textlen;
00630 unsigned int cube=0x0184;
00631
00632 if (sscanf(cmd->params[5]+2,"%x",&cube)<1)
00633 {
00634 sprintf(err_msg,"Cannot read filler cube index");
00635 return false;
00636 }
00637 textlen=strlen(cmd->params[6]);
00638 if (textlen>=READ_BUFSIZE) textlen=READ_BUFSIZE-1;
00639 for (i=0;i<textlen;i++)
00640 {
00641 char c=cmd->params[6][i];
00642 if ((c<=32)||(c=='_')) text[i]=' '; else
00643 if (c=='.') text[i]=','; else
00644 if (c=='{') text[i]='('; else
00645 if (c=='}') text[i]=')'; else
00646 text[i]=c;
00647 }
00648 text[textlen]='\0';
00649 int graf_idx=graffiti_add(lvl,tx,ty,height,text,font,orient,cube);
00650 if (graf_idx<0)
00651 {
00652 sprintf(err_msg,"Cannot add graffiti");
00653 return false;
00654 }
00655 };return true;
00656 case LEVEL_TIMESTAMP:
00657 {
00658 if (cmd->param_count<2)
00659 {
00660 sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index));
00661 return false;
00662 }
00663 short result=true;
00664 unsigned long creat_date;
00665 unsigned long lastsav_date;
00666 result&=script_param_to_ulong(&creat_date,cmd->params[0]);
00667 result&=script_param_to_ulong(&lastsav_date,cmd->params[1]);
00668 if (!result)
00669 {
00670 sprintf(err_msg,"Cannot read level date parameters");
00671 return false;
00672 }
00673 lvl->info.creat_date=creat_date;
00674 lvl->info.lastsav_date=lastsav_date;
00675 };return true;
00676 case USER_CMNDS_COUNT:
00677 {
00678 if (cmd->param_count<1)
00679 {
00680 sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index));
00681 return false;
00682 }
00683 short result=true;
00684 unsigned long ucmdcnt;
00685 unsigned long umdswcnt,umslbcnt,ucrobcnt;
00686 result&=script_param_to_ulong(&ucmdcnt,cmd->params[0]);
00687 if (!result)
00688 {
00689 sprintf(err_msg,"Cannot read first user commands count parameter");
00690 return false;
00691 }
00692 lvl->info.usr_cmds_count=ucmdcnt;
00693
00694 if (cmd->param_count>3)
00695 {
00696 result&=script_param_to_ulong(&umdswcnt,cmd->params[1]);
00697 result&=script_param_to_ulong(&umslbcnt,cmd->params[2]);
00698 result&=script_param_to_ulong(&ucrobcnt,cmd->params[3]);
00699 if (!result)
00700 {
00701 sprintf(err_msg,"Cannot read user commands count parameters");
00702 return false;
00703 }
00704 lvl->info.usr_mdswtch_count=umdswcnt;
00705 lvl->info.usr_slbchng_count=umslbcnt;
00706 lvl->info.usr_creatobj_count=ucrobcnt;
00707 }
00708 };return true;
00709 case LEVEL_VERSION:
00710 {
00711 if (cmd->param_count<3)
00712 {
00713 sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index));
00714 return false;
00715 }
00716 short result=true;
00717 int vma,vmi,vre;
00718 result&=script_param_to_int(&vma,cmd->params[0]);
00719 result&=script_param_to_int(&vmi,cmd->params[1]);
00720 result&=script_param_to_int(&vre,cmd->params[2]);
00721 if (!result)
00722 {
00723 sprintf(err_msg,"Cannot read version parameters");
00724 return false;
00725 }
00726 lvl->info.ver_major=vma;
00727 lvl->info.ver_minor=vmi;
00728 lvl->info.ver_rel=vre;
00729 };return true;
00730 case LEVEL_NAME:
00731 {
00732 if (cmd->param_count<1)
00733 {
00734 sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index));
00735 return false;
00736 }
00737 char *levname=strdup_noquot(cmd->params[0]);
00738 if (levname!=NULL)
00739 set_lif_name_text(lvl,levname);
00740 int pos=0;
00741 };return true;
00742 case LEVEL_DESC:
00743 {
00744 if (cmd->param_count<1)
00745 {
00746 sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index));
00747 return false;
00748 }
00749 free(lvl->info.desc_text);
00750 lvl->info.desc_text=strdup_noquot(cmd->params[0]);
00751 };return true;
00752 case LEVEL_AUTHORS:
00753 {
00754 if (cmd->param_count<2)
00755 {
00756 sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index));
00757 return false;
00758 }
00759 free(lvl->info.author_text);
00760 lvl->info.author_text=strdup_noquot(cmd->params[0]);
00761 free(lvl->info.editor_text);
00762 lvl->info.editor_text=strdup_noquot(cmd->params[1]);
00763 };return true;
00764 default:
00765 {
00766 sprintf(err_msg,"Internal command unrecognized");
00767 };return false;
00768 }
00769 }
00770
00771 short script_cmd_verify_argcount(char *err_msg,const struct DK_SCRIPT_COMMAND *cmd,const int prop_count)
00772 {
00773 if (cmd->param_count!=prop_count)
00774 {
00775 if (prop_count>0)
00776 {
00777 const char *cmd_text=script_cmd_text(cmd->group,cmd->index,"(unknown)");
00778 if (strlen(cmd_text) <= 16)
00779 sprintf(err_msg,"Script command \"%s\" requires %d arguments, has %d",
00780 cmd_text,prop_count,cmd->param_count);
00781 else
00782 sprintf(err_msg,"Script command requires %d arguments, has %d",
00783 prop_count,cmd->param_count);
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793 return false;
00794 } else
00795 {
00796 const char *cmd_text=script_cmd_text(cmd->group,cmd->index,"(unknown)");
00797 if (strlen(cmd_text) <= 16)
00798 sprintf(err_msg,"Script command \"%s\" shouldn't have arguments",
00799 cmd_text);
00800 else
00801 sprintf(err_msg,"Script command shouldn't have arguments");
00802 return false;
00803 }
00804 }
00805 return true;
00806 }
00807
00808 short string_is_decimal_number(const char *str,const short allow_sign)
00809 {
00810 if (str==NULL) return false;
00811 if (str[0]=='\0') return false;
00812 int len=strlen(str);
00813 if (!isdigit(str[0]))
00814 {
00815 if ((!allow_sign)||(len<2)||((str[0]!='+')&&(str[0]!='-')))
00816 return false;
00817 }
00818 int i;
00819 for (i=1;i<len;i++)
00820 {
00821 if (!isdigit(str[i]))
00822 return false;
00823 }
00824 return true;
00825 }
00826
00827 short script_cmd_verify_arg_actnpt(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
00828 const char *param,const short allow_herogate,const short allow_plyrheart)
00829 {
00830 if (allow_plyrheart)
00831 {
00832 int cmd_idx;
00833 cmd_idx=players_cmd_index(param);
00834 if (cmd_idx>=0)
00835 return true;
00836 }
00837 if (!string_is_decimal_number(param,true))
00838 {
00839 if (strlen(param) <= 16)
00840 sprintf(err_msg,"Invalid action point number \"%s\" in script",param);
00841 else
00842 sprintf(err_msg,"Invalid action point number in script");
00843 return false;
00844 }
00845 if (strlen(param)>6)
00846 {
00847 if (strlen(param) <= 16)
00848 sprintf(err_msg,"Too long action point number \"%s\" in script",param);
00849 else
00850 sprintf(err_msg,"Too long action point number in script");
00851 return false;
00852 }
00853 if ((!allow_herogate)&&(!string_is_decimal_number(param,false)))
00854 {
00855 sprintf(err_msg,"Hero gate not allowed as action point in script");
00856 return false;
00857 }
00858 int val;
00859 if (!script_param_to_int(&val,param))
00860 {
00861 if (strlen(param) <= 16)
00862 sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param);
00863 else
00864 sprintf(err_msg,"Internal - no numeric value for in script");
00865 return false;
00866 }
00867 if (val>0)
00868 {
00869 if (val >= (scverif->actnpts_count))
00870 {
00871 sprintf(err_msg,"Too large %s number %d used in script","action point",val);
00872 return false;
00873 }
00874 if ((scverif->actnpts[val]) == 0)
00875 {
00876 sprintf(err_msg,"Nonexisting %s %d used in script","action point",val);
00877 return false;
00878 }
00879 } else
00880 if (val<0)
00881 {
00882 if ((-val) >= (scverif->herogts_count))
00883 {
00884 sprintf(err_msg,"Too large %s number %d used in script","hero gate",(-val));
00885 return false;
00886 }
00887 if ((scverif->herogts[-val]) == 0)
00888 {
00889 sprintf(err_msg,"Nonexisting %s %d used in script","hero gate",(-val));
00890 return false;
00891 }
00892 } else
00893 {
00894 sprintf(err_msg,"Zero is not valid action point number in script");
00895 return false;
00896 }
00897 return true;
00898 }
00899
00900 short script_cmd_verify_arg_gameturn(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
00901 const char *param)
00902 {
00903 if (!string_is_decimal_number(param,false))
00904 {
00905 if (strlen(param) <= 16)
00906 sprintf(err_msg,"Invalid game turns amount \"%s\" in script",param);
00907 else
00908 sprintf(err_msg,"Invalid game turns amount in script");
00909 return false;
00910 }
00911 if (strlen(param)>7)
00912 {
00913 if (strlen(param) <= 16)
00914 sprintf(err_msg,"Game turns amount \"%s\" too long in script",param);
00915 else
00916 sprintf(err_msg,"Game turns amount too long in script");
00917 return false;
00918 }
00919 int val;
00920 if (!script_param_to_int(&val,param))
00921 {
00922 if (strlen(param) <= 16)
00923 sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param);
00924 else
00925 sprintf(err_msg,"Internal - no numeric value for param in script");
00926 return false;
00927 }
00928 if (val<0)
00929 {
00930 if (strlen(param) <= 16)
00931 sprintf(err_msg,"Game turns amout \"%s\" exceeds integer range in script",param);
00932 else
00933 sprintf(err_msg,"Game turns amout exceeds integer range in script");
00934 return false;
00935 }
00936 if (val > (20*60*60*24))
00937 {
00938 sprintf(err_msg,"Game turns amout %d exceeds one day delay in script",val);
00939 return false;
00940 }
00941 return true;
00942 }
00943
00944 short script_cmd_verify_arg_goldamnt(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
00945 const char *param)
00946 {
00947 if (!string_is_decimal_number(param,false))
00948 {
00949 if (strlen(param) <= 16)
00950 sprintf(err_msg,"Invalid gold amount \"%s\" in script",param);
00951 else
00952 sprintf(err_msg,"Invalid gold amount in script");
00953 return false;
00954 }
00955 if (strlen(param)>10)
00956 {
00957 if (strlen(param) <= 16)
00958 sprintf(err_msg,"Gold amount \"%s\" too long in script",param);
00959 else
00960 sprintf(err_msg,"Gold amount too long in script");
00961 return false;
00962 }
00963 int val;
00964 if (!script_param_to_int(&val,param))
00965 {
00966 if (strlen(param) <= 16)
00967 sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param);
00968 else
00969 sprintf(err_msg,"Internal - no numeric value for param in script");
00970 return false;
00971 }
00972 if (val<0)
00973 {
00974 if (strlen(param) <= 16)
00975 sprintf(err_msg,"Gold amout \"%s\" exceeds integer range in script",param);
00976 else
00977 sprintf(err_msg,"Gold amout exceeds integer range in script");
00978 return false;
00979 }
00980 if (val > 2000000000)
00981 {
00982 sprintf(err_msg,"Gold amout %d exceeds safe value in script",val);
00983 return false;
00984 }
00985 return true;
00986 }
00987
00988 short script_cmd_verify_arg_experience(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
00989 const char *param)
00990 {
00991 if (!string_is_decimal_number(param,false))
00992 {
00993 if (strlen(param) <= 16)
00994 sprintf(err_msg,"Invalid experience level \"%s\" in script",param);
00995 else
00996 sprintf(err_msg,"Invalid experience level in script");
00997 return false;
00998 }
00999 if (strlen(param)>2)
01000 {
01001 if (strlen(param) <= 16)
01002 sprintf(err_msg,"Experience level \"%s\" too long in script",param);
01003 else
01004 sprintf(err_msg,"Experience level too long in script");
01005 return false;
01006 }
01007 int val;
01008 if (!script_param_to_int(&val,param))
01009 {
01010 if (strlen(param) <= 16)
01011 sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param);
01012 else
01013 sprintf(err_msg,"Internal - no numeric value for param in script");
01014 return false;
01015 }
01016 if (val>10)
01017 {
01018 sprintf(err_msg,"Experience level %d exceeds maximum of %u in script",val,10);
01019 return false;
01020 }
01021 if (val < 1)
01022 {
01023 sprintf(err_msg,"Experience level must be at least 1, but is %d in script",val);
01024 return false;
01025 }
01026 return true;
01027 }
01028
01029 short script_cmd_verify_arg_ncrtrs(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01030 const char *param,int min_val,int *count)
01031 {
01032 if (!string_is_decimal_number(param,false))
01033 {
01034 if (strlen(param) <= 16)
01035 sprintf(err_msg,"Invalid creatures count \"%s\" in script",param);
01036 else
01037 sprintf(err_msg,"Invalid creatures count in script");
01038 return false;
01039 }
01040 if (strlen(param)>3)
01041 {
01042 if (strlen(param) <= 16)
01043 sprintf(err_msg,"Creatures count \"%s\" too long in script",param);
01044 else
01045 sprintf(err_msg,"Creatures count too long in script");
01046 return false;
01047 }
01048 int val;
01049 if (!script_param_to_int(&val,param))
01050 {
01051 if (strlen(param) <= 16)
01052 sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param);
01053 else
01054 sprintf(err_msg,"Internal - no numeric value for param in script");
01055 return false;
01056 }
01057 if (val > 255)
01058 {
01059 sprintf(err_msg,"Creatures count %d exceeds maximum of %u in script",val,255);
01060 return false;
01061 }
01062 if (val < min_val)
01063 {
01064 sprintf(err_msg,"Creatures count must be at least %d, but is %d in script",min_val,val);
01065 return false;
01066 }
01067 return true;
01068 }
01069
01070 short script_cmd_verify_arg_operator(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01071 const char *param,int *opertr_idx)
01072 {
01073 int cmd_idx;
01074 cmd_idx=operator_cmd_index(param);
01075 if (cmd_idx<0)
01076 {
01077 if (strlen(param) <= 16)
01078 sprintf(err_msg,"Unrecognized operator \"%s\" in script",param);
01079 else
01080 sprintf(err_msg,"Unrecognized operator in script");
01081 return false;
01082 }
01083 *opertr_idx=cmd_idx;
01084 return true;
01085 }
01086
01087 short script_cmd_verify_arg_conditvar(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01088 const char *param,short allow_vars,int *cmd_type,int *var_idx)
01089 {
01090 (*cmd_type)=-1;
01091 int cmd_idx;
01092 if (allow_vars)
01093 {
01094 cmd_idx=variabl_cmd_index(param);
01095 if (cmd_idx>=0)
01096 {
01097 (*var_idx)=cmd_idx;
01098 (*cmd_type)=CMD_VARIBL;
01099 }
01100 cmd_idx=timer_cmd_index(param);
01101 if (cmd_idx>=0)
01102 {
01103 (*var_idx)=cmd_idx;
01104 (*cmd_type)=CMD_TIMER;
01105 }
01106 cmd_idx=flag_cmd_index(param);
01107 if (cmd_idx>=0)
01108 {
01109 (*var_idx)=cmd_idx;
01110 (*cmd_type)=CMD_FLAG;
01111 }
01112 } else
01113 {
01114 cmd_idx=spell_cmd_index(param);
01115 if (cmd_idx>=0)
01116 {
01117 (*var_idx)=cmd_idx;
01118 (*cmd_type)=CMD_SPELL;
01119 }
01120 }
01121 cmd_idx=creatures_cmd_index(param);
01122 if (cmd_idx>=0)
01123 {
01124 (*var_idx)=cmd_idx;
01125 (*cmd_type)=CMD_CREATR;
01126 }
01127 cmd_idx=door_cmd_index(param);
01128 if (cmd_idx>=0)
01129 {
01130 (*var_idx)=cmd_idx;
01131 (*cmd_type)=CMD_DOOR;
01132 }
01133 cmd_idx=trap_cmd_index(param);
01134 if (cmd_idx>=0)
01135 {
01136 (*var_idx)=cmd_idx;
01137 (*cmd_type)=CMD_TRAP;
01138 }
01139 cmd_idx=room_cmd_index(param);
01140 if (cmd_idx>=0)
01141 {
01142 (*var_idx)=cmd_idx;
01143 (*cmd_type)=CMD_ROOM;
01144 }
01145 if ((*cmd_type)<0)
01146 {
01147 char *whatis;
01148 if (allow_vars)
01149 whatis="variable";
01150 else
01151 whatis="name";
01152 if (strlen(param) <= 16)
01153 sprintf(err_msg,"Unrecognized %s \"%s\" in script",whatis,param);
01154 else
01155 sprintf(err_msg,"Unrecognized %s in script",whatis);
01156 return false;
01157 }
01158 return true;
01159 }
01160
01161 short script_cmd_verify_arg_singlevar(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01162 const char *param,char *param_name,func_cmd_index f_cmd_index,int *res_idx)
01163 {
01164 int cmd_idx;
01165 cmd_idx=f_cmd_index(param);
01166 if (cmd_idx<0)
01167 {
01168 if (strlen(param) <= 16)
01169 sprintf(err_msg,"Unrecognized %s \"%s\" in script",param_name,param);
01170 else
01171 sprintf(err_msg,"Unrecognized %s in script",param_name);
01172 return false;
01173 }
01174 (*res_idx)=cmd_idx;
01175 return true;
01176 }
01177
01178 short script_cmd_verify_arg_btnparam(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01179 const char *param)
01180 {
01181 int cmd_idx;
01182 cmd_idx=players_cmd_index(param);
01183 if (cmd_idx>=0)
01184 return true;
01185 if (!string_is_decimal_number(param,true))
01186 {
01187 if (strlen(param) <= 16)
01188 sprintf(err_msg,"Invalid %s value \"%s\" in script","player/time",param);
01189 else
01190 sprintf(err_msg,"Invalid %s value in script","player/time");
01191 return false;
01192 }
01193 const int max_digits=7;
01194 if (strlen(param)>max_digits)
01195 {
01196 if (strlen(param) <= 16)
01197 sprintf(err_msg,"%s value \"%s\" too long in script","Game turns",param);
01198 else
01199 sprintf(err_msg,"%s value too long in script","Game turns");
01200 return false;
01201 }
01202 int val;
01203 if (!script_param_to_int(&val,param))
01204 {
01205 if (strlen(param) <= 16)
01206 sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param);
01207 else
01208 sprintf(err_msg,"Internal - no numeric value for param in script");
01209 return false;
01210 }
01211 if (val<-1)
01212 {
01213 if (strlen(param) <= 16)
01214 sprintf(err_msg,"%s amout \"%s\" exceeds range in script","Game turns",param);
01215 else
01216 sprintf(err_msg,"%s amout exceeds range in script","Game turns");
01217 return false;
01218 }
01219 if (val > (20*60*60*24))
01220 {
01221 sprintf(err_msg,"%s amout %d exceeds one day delay in script","Game turns",val);
01222 return false;
01223 }
01224 return true;
01225 }
01226
01227
01228 short script_cmd_verify_arg_creatr(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01229 const char *param,int *crtr_idx)
01230 {
01231 int cmd_idx;
01232 cmd_idx=creatures_cmd_index(param);
01233 if (cmd_idx<0)
01234 {
01235 if (strlen(param) <= 16)
01236 sprintf(err_msg,"Unrecognized creature \"%s\" in script",param);
01237 else
01238 sprintf(err_msg,"Unrecognized creature in script");
01239 return false;
01240 }
01241 (*crtr_idx)=cmd_idx;
01242 return true;
01243 }
01244
01245 short script_cmd_verify_arg_party_objectv(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01246 const char *param,const short heading_objctv,int *obj_idx)
01247 {
01248 int cmd_idx;
01249 cmd_idx=party_objectv_cmd_index(param);
01250 char *whos;
01251 if (heading_objctv)
01252 whos="tunneller";
01253 else
01254 whos="party member";
01255 if (cmd_idx<0)
01256 {
01257 if (strlen(param) <= 16)
01258 sprintf(err_msg,"Unrecognized %s objective \"%s\" in script",whos,param);
01259 else
01260 sprintf(err_msg,"Unrecognized %s objective in script",whos);
01261 return false;
01262 }
01263 if (((heading_objctv)&&(cmd_idx>OBJCTV_APPROP_DUNG))||
01264 ((!heading_objctv)&&(cmd_idx<=OBJCTV_APPROP_DUNG)))
01265 {
01266 if (strlen(param) <= 16)
01267 sprintf(err_msg,"Parameter \"%s\" is not %s objective in script",param,whos);
01268 else
01269 sprintf(err_msg,"Parameter is not %s objective in script",whos);
01270 return false;
01271 }
01272 (*obj_idx)=cmd_idx;
01273 return true;
01274 }
01275
01276 short script_cmd_verify_arg_party_name(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01277 const char *param,const short create_new,int *party_idx)
01278 {
01279 int i;
01280 if (create_new)
01281 {
01282 i=0;
01283 while (i<MAX_PARTYS)
01284 {
01285 if (scverif->partys[i]==NULL) break;
01286 i++;
01287 }
01288 if (i>=MAX_PARTYS)
01289 {
01290 sprintf(err_msg,"Amount of partys in script exceeds %d",MAX_PARTYS);
01291 return false;
01292 }
01293 scverif->partys[i]=strdup(param);
01294 (*party_idx)=i;
01295 } else
01296 {
01297 i=0;
01298 while (i<MAX_PARTYS)
01299 {
01300 if (scverif->partys[i]!=NULL)
01301 {
01302 if (stricmp(param,scverif->partys[i])==0)
01303 break;
01304 }
01305 i++;
01306 }
01307 if (i>=MAX_PARTYS)
01308 {
01309 if (strlen(param) <= 16)
01310 sprintf(err_msg,"Party \"%s\" used before definition in script",param);
01311 else
01312 sprintf(err_msg,"Party used before definition in script");
01313 return false;
01314 }
01315 (*party_idx)=i;
01316 }
01317 return true;
01318 }
01319
01320 short script_cmd_verify_arg_quotparam(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01321 const char *param,const char *param_name,unsigned int *par_idx)
01322 {
01323 int parlen=strlen(param);
01324 if (parlen<3)
01325 {
01326 sprintf(err_msg,"Text parameter %s too short to be in quote",param);
01327 return false;
01328 }
01329
01330 short quote_dbl=((param[0]=='\"')&&(param[parlen-1]=='\"'));
01331 if ((!quote_dbl))
01332 {
01333 if (strlen(param) <= 16)
01334 sprintf(err_msg,"Text parameter %s should be closed in quote",param);
01335 else
01336 sprintf(err_msg,"Text parameter should be closed in quote");
01337 return false;
01338 }
01339 if (strlen(param) > 511)
01340 {
01341 sprintf(err_msg,"Text parameter is longer than 511 chars");
01342 return false;
01343 }
01344 return true;
01345 }
01346
01347 short script_cmd_verify_arg_limparam(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01348 const char *param,const char *param_name,int min_val,unsigned int max_val)
01349 {
01350 if (!string_is_decimal_number(param,false))
01351 {
01352 if (strlen(param) <= 16)
01353 sprintf(err_msg,"Invalid %s value \"%s\" in script",param_name,param);
01354 else
01355 sprintf(err_msg,"Invalid %s value in script",param_name);
01356 return false;
01357 }
01358 int max_digits=1;
01359 unsigned int tmp=max_val;
01360 while (true)
01361 {
01362 tmp=tmp/10;
01363 if (tmp>0)
01364 max_digits++;
01365 else
01366 break;
01367 }
01368 if (strlen(param)>max_digits)
01369 {
01370 sprintf(err_msg,"%s value \"%s\" too long in script",param_name,param);
01371 return false;
01372 }
01373 int val;
01374 if (!script_param_to_int(&val,param))
01375 {
01376 sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param);
01377 return false;
01378 }
01379 if (val>max_val)
01380 {
01381 sprintf(err_msg,"%s value %d exceeds maximum of %u in script",param_name,val,max_val);
01382 return false;
01383 }
01384 if (val < min_val)
01385 {
01386 sprintf(err_msg,"%s value must be at least %d, but is %d in script",param_name,min_val,val);
01387 return false;
01388 }
01389 return true;
01390 }
01391
01392 short script_cmd_verify_arg_unsg_int(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01393 const char *param,int min_val,unsigned int max_val)
01394 {
01395 if (!string_is_decimal_number(param,false))
01396 {
01397 sprintf(err_msg,"Invalid integer value \"%s\" in script",param);
01398 return false;
01399 }
01400 int max_digits=1;
01401 unsigned int tmp=max_val;
01402 while (true)
01403 {
01404 tmp=tmp/10;
01405 if (tmp>0)
01406 max_digits++;
01407 else
01408 break;
01409 }
01410 if (strlen(param)>max_digits)
01411 {
01412 sprintf(err_msg,"Integer value \"%s\" too long in script",param);
01413 return false;
01414 }
01415 int val;
01416 if (!script_param_to_int(&val,param))
01417 {
01418 sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param);
01419 return false;
01420 }
01421 if (val<0)
01422 {
01423 sprintf(err_msg,"Value \"%s\" exceeds integer range in script",param);
01424 return false;
01425 }
01426 if (val > max_val)
01427 {
01428 sprintf(err_msg,"Integer value %d exceeds maximum of %u in script",val,max_val);
01429 return false;
01430 }
01431 if (val < min_val)
01432 {
01433 sprintf(err_msg,"Value %d is smaller than minimum of %u in script",val,min_val);
01434 return false;
01435 }
01436 return true;
01437 }
01438
01439 short script_cmd_verify_arg_logic_int(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01440 const char *param,short *logic_val)
01441 {
01442 if (strlen(param)>1)
01443 {
01444 sprintf(err_msg,"Logic integer value \"%s\" too long in script",param);
01445 return false;
01446 }
01447 if (param[0]=='0')
01448 {
01449 *logic_val=false;
01450 return true;
01451 }
01452 if (param[0]=='1')
01453 {
01454 *logic_val=true;
01455 return true;
01456 }
01457 sprintf(err_msg,"Logic value can only be 0 or 1, not \"%s\" in script",param);
01458 return false;
01459 }
01460
01461 short script_cmd_verify_arg_specval(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,
01462 const char *param,char def_val)
01463 {
01464 if (strlen(param)>1)
01465 {
01466 sprintf(err_msg,"Unused value \"%s\" should be \"%c\" in script",param,def_val);
01467 return false;
01468 }
01469 if (param[0]==def_val)
01470 return true;
01471 sprintf(err_msg,"Unused value \"%s\" should be \"%c\" in script",param,def_val);
01472 return false;
01473 }
01474
01475 short script_cmd_verify_condit(struct SCRIPT_VERIFY_DATA *scverif,
01476 char *err_msg,int *err_param,const struct DK_SCRIPT_COMMAND *cmd)
01477 {
01478 int plyr_idx;
01479 int opertr_idx;
01480 int cmd_type;
01481 int cmd_idx;
01482 int i;
01483 short logic_val;
01484 switch (cmd->index)
01485 {
01486 case COND_IF:
01487 if (!script_cmd_verify_argcount(err_msg,cmd,4))
01488 {
01489 (*err_param)=ERR_SCRIPTPARAM_NARGS;
01490 return VERIF_WARN;
01491 }
01492 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
01493 "player",players_cmd_index,&plyr_idx))
01494 {
01495 (*err_param)=0;
01496 return VERIF_WARN;
01497 }
01498 if (!script_cmd_verify_arg_conditvar(scverif,err_msg,cmd->params[1],true,
01499 &cmd_type,&cmd_idx))
01500 {
01501 (*err_param)=1;
01502 return VERIF_WARN;
01503 }
01504 if (!script_cmd_verify_arg_operator(scverif,err_msg,cmd->params[2],&opertr_idx))
01505 {
01506 (*err_param)=2;
01507 return VERIF_WARN;
01508 }
01509 long min_val;
01510 unsigned long max_val;
01511 switch (cmd_type)
01512 {
01513 case CMD_CREATR:
01514 if (!script_cmd_verify_arg_ncrtrs(scverif,err_msg,cmd->params[3],0,&i))
01515 {
01516 (*err_param)=3;
01517 return VERIF_WARN;
01518 }
01519 break;
01520 case CMD_TIMER:
01521 if (!script_cmd_verify_arg_gameturn(scverif,err_msg,cmd->params[3]))
01522 {
01523 (*err_param)=3;
01524 return VERIF_WARN;
01525 }
01526 break;
01527 case CMD_FLAG:
01528 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],"Flag",0,255))
01529 {
01530 (*err_param)=3;
01531 return VERIF_WARN;
01532 }
01533 break;
01534 case CMD_DOOR:
01535 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],"Doors count",0,32767))
01536 {
01537 (*err_param)=3;
01538 return VERIF_WARN;
01539 }
01540 break;
01541 case CMD_TRAP:
01542 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],"Traps count",0,32767))
01543 {
01544 (*err_param)=3;
01545 return VERIF_WARN;
01546 }
01547 break;
01548 case CMD_ROOM:
01549 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],"Room slabs",0,7225))
01550 {
01551 (*err_param)=3;
01552 return VERIF_WARN;
01553 }
01554 break;
01555 case CMD_VARIBL:
01556 switch (cmd_idx)
01557 {
01558 case CRTRS_SCAVNG_GAINED:
01559 case CRTRS_SCAVNG_LOST:
01560 case CREATRS_ANNOYED:
01561 case TOTAL_CREATRS:
01562 case TOTAL_IMPS:
01563 case TOTAL_CREATRS_LEFT:
01564 if (!script_cmd_verify_arg_ncrtrs(scverif,err_msg,cmd->params[3],0,&i))
01565 {
01566 (*err_param)=3;
01567 return VERIF_WARN;
01568 }
01569 break;
01570 case MONEY:
01571 case TOTAL_GOLD_MINED:
01572 if (!script_cmd_verify_arg_gameturn(scverif,err_msg,cmd->params[3]))
01573 {
01574 (*err_param)=3;
01575 return VERIF_WARN;
01576 }
01577 break;
01578 case TOTAL_AREA:
01579 case ROOMS_DESTROYED:
01580 case DOORS_DESTROYED:
01581 case TOTAL_DOORS:
01582 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],"Slabs count",0,7225))
01583 {
01584 (*err_param)=3;
01585 return VERIF_WARN;
01586 }
01587 break;
01588 case GAME_TURN:
01589 if (!script_cmd_verify_arg_gameturn(scverif,err_msg,cmd->params[3]))
01590 {
01591 (*err_param)=3;
01592 return VERIF_WARN;
01593 }
01594 break;
01595 case ALL_DNGNS_DESTROYED:
01596 case DNGN_DESTROYED:
01597 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[3],&logic_val))
01598 {
01599 (*err_param)=3;
01600 return VERIF_WARN;
01601 }
01602 break;
01603
01604 case TIMES_BROKEN_INTO:
01605 case BREAK_IN:
01606 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],"Walls break",0,1024))
01607 {
01608 (*err_param)=3;
01609 return VERIF_WARN;
01610 }
01611 break;
01612 case SPELLS_STOLEN:
01613 case GOLD_POTS_STOLEN:
01614 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],"Stolen items",0,1024))
01615 {
01616 (*err_param)=3;
01617 return VERIF_WARN;
01618 }
01619 break;
01620 case BATTLES_WON:
01621 case BATTLES_LOST:
01622 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],"Battles count",0,1024))
01623 {
01624 (*err_param)=3;
01625 return VERIF_WARN;
01626 }
01627 break;
01628 case TOTAL_RESEARCH:
01629 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],"Battles count",0,2147483647))
01630 {
01631 (*err_param)=3;
01632 return VERIF_WARN;
01633 }
01634 break;
01635 default:
01636 sprintf(err_msg,"Internal problem with variable index in script");
01637 (*err_param)=1;
01638 return VERIF_WARN;
01639 }
01640 break;
01641 default:
01642 sprintf(err_msg,"Internal problem with variable in script");
01643 (*err_param)=1;
01644 return VERIF_WARN;
01645 }
01646 scverif->level++;
01647 scverif->total_ifs++;
01648 break;
01649 case IF_AVAILABLE:
01650 if (!script_cmd_verify_argcount(err_msg,cmd,4))
01651 {
01652 (*err_param)=ERR_SCRIPTPARAM_NARGS;
01653 return VERIF_WARN;
01654 }
01655 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
01656 "player",players_cmd_index,&plyr_idx))
01657 {
01658 (*err_param)=0;
01659 return VERIF_WARN;
01660 }
01661 if (!script_cmd_verify_arg_conditvar(scverif,err_msg,cmd->params[1],false,
01662 &cmd_type,&cmd_idx))
01663 {
01664 (*err_param)=1;
01665 return VERIF_WARN;
01666 }
01667 if (!script_cmd_verify_arg_operator(scverif,err_msg,cmd->params[2],&opertr_idx))
01668 {
01669 (*err_param)=2;
01670 return VERIF_WARN;
01671 }
01672 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[3],&logic_val))
01673 {
01674 (*err_param)=3;
01675 return VERIF_WARN;
01676 }
01677 scverif->level++;
01678 scverif->total_ifs++;
01679 break;
01680 case IF_ACTNPT:
01681 if (!script_cmd_verify_argcount(err_msg,cmd,2))
01682 {
01683 (*err_param)=ERR_SCRIPTPARAM_NARGS;
01684 return VERIF_WARN;
01685 }
01686 if (!script_cmd_verify_arg_actnpt(scverif,err_msg,cmd->params[0],false,false))
01687 {
01688 (*err_param)=0;
01689 return VERIF_WARN;
01690 }
01691 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[1],
01692 "player",players_cmd_index,&plyr_idx))
01693 {
01694 (*err_param)=1;
01695 return VERIF_WARN;
01696 }
01697 scverif->level++;
01698 scverif->total_ifs++;
01699 break;
01700 case COND_ENDIF:
01701 if (!script_cmd_verify_argcount(err_msg,cmd,0))
01702 {
01703 (*err_param)=ERR_SCRIPTPARAM_NARGS;
01704 return VERIF_WARN;
01705 }
01706 scverif->level--;
01707 break;
01708 default:
01709 sprintf(err_msg,"Internal warn - wrong CONDIT script command");
01710 return VERIF_WARN;
01711 }
01712 if (scverif->level<0)
01713 {
01714 sprintf(err_msg,"Script command ENDIF found without IF");
01715 return VERIF_WARN;
01716 }
01717 return VERIF_OK;
01718 }
01719
01720 short script_cmd_verify_party(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,int *err_param,const struct DK_SCRIPT_COMMAND *cmd)
01721 {
01722 int i;
01723 int plyr_idx;
01724 int crtr_idx;
01725 int party_idx;
01726 switch (cmd->index)
01727 {
01728 case CREATE_PARTY:
01729 if (!script_cmd_verify_argcount(err_msg,cmd,1))
01730 {
01731 (*err_param)=ERR_SCRIPTPARAM_NARGS;
01732 return VERIF_WARN;
01733 }
01734 if (!script_cmd_verify_arg_party_name(scverif,err_msg,cmd->params[0],
01735 true,&party_idx))
01736 {
01737 (*err_param)=0;
01738 return VERIF_WARN;
01739 }
01740 break;
01741 case ADD_TUNNELER_TOLEV:
01742 if (!script_cmd_verify_argcount(err_msg,cmd,6))
01743 {
01744 (*err_param)=ERR_SCRIPTPARAM_NARGS;
01745 return VERIF_WARN;
01746 }
01747 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
01748 "player",players_cmd_index,&plyr_idx))
01749 {
01750 (*err_param)=0;
01751 return VERIF_WARN;
01752 }
01753 if (!script_cmd_verify_arg_actnpt(scverif,err_msg,cmd->params[1],true,true))
01754 {
01755 (*err_param)=1;
01756 return VERIF_WARN;
01757 }
01758 if (!script_cmd_verify_arg_party_objectv(scverif,err_msg,cmd->params[2],true,&i))
01759 {
01760 (*err_param)=2;
01761 return VERIF_WARN;
01762 }
01763 switch (i)
01764 {
01765 case OBJCTV_ACTNPT:
01766 if (!script_cmd_verify_arg_actnpt(scverif,err_msg,cmd->params[3],true,true))
01767 {
01768 (*err_param)=3;
01769 return VERIF_WARN;
01770 }
01771 break;
01772 case OBJCTV_DUNGEON:
01773 case OBJCTV_DNHEART:
01774
01775 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],
01776 "Player index",0,5))
01777
01778 {
01779 (*err_param)=3;
01780 return VERIF_WARN;
01781 }
01782 break;
01783 case OBJCTV_APPROP_DUNG:
01784
01785 if (!script_cmd_verify_arg_specval(scverif,err_msg,cmd->params[3],'0'))
01786 {
01787 (*err_param)=3;
01788 return VERIF_WARN;
01789 }
01790 break;
01791 default:
01792 sprintf(err_msg,"Internal problem with party objective in script");
01793 (*err_param)=3;
01794 return VERIF_WARN;
01795 }
01796 if (!script_cmd_verify_arg_experience(scverif,err_msg,cmd->params[4]))
01797 {
01798 (*err_param)=4;
01799 return VERIF_WARN;
01800 }
01801 if (!script_cmd_verify_arg_goldamnt(scverif,err_msg,cmd->params[5]))
01802 {
01803 (*err_param)=5;
01804 return VERIF_WARN;
01805 }
01806 break;
01807 case ADD_TO_PARTY:
01808 if (!script_cmd_verify_argcount(err_msg,cmd,6))
01809 {
01810 (*err_param)=ERR_SCRIPTPARAM_NARGS;
01811 return VERIF_WARN;
01812 }
01813 if (!script_cmd_verify_arg_party_name(scverif,err_msg,cmd->params[0],
01814 false,&party_idx))
01815 {
01816 (*err_param)=0;
01817 return VERIF_WARN;
01818 }
01819 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[1],&crtr_idx))
01820 {
01821 (*err_param)=1;
01822 return VERIF_WARN;
01823 }
01824 if (!script_cmd_verify_arg_experience(scverif,err_msg,cmd->params[2]))
01825 {
01826 (*err_param)=2;
01827 return VERIF_WARN;
01828 }
01829 if (!script_cmd_verify_arg_goldamnt(scverif,err_msg,cmd->params[3]))
01830 {
01831 (*err_param)=3;
01832 return VERIF_WARN;
01833 }
01834 if (!script_cmd_verify_arg_party_objectv(scverif,err_msg,cmd->params[4],false,&i))
01835 {
01836 (*err_param)=4;
01837 return VERIF_WARN;
01838 }
01839 if (!script_cmd_verify_arg_gameturn(scverif,err_msg,cmd->params[5]))
01840 {
01841 (*err_param)=5;
01842 return VERIF_WARN;
01843 }
01844 break;
01845 case ADD_PARTY_TOLEV:
01846 if (!script_cmd_verify_argcount(err_msg,cmd,4))
01847 {
01848 (*err_param)=ERR_SCRIPTPARAM_NARGS;
01849 return VERIF_WARN;
01850 }
01851 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
01852 "player",players_cmd_index,&plyr_idx))
01853 {
01854 (*err_param)=0;
01855 return VERIF_WARN;
01856 }
01857 if (!script_cmd_verify_arg_party_name(scverif,err_msg,cmd->params[1],
01858 false,&party_idx))
01859 {
01860 (*err_param)=1;
01861 return VERIF_WARN;
01862 }
01863 if (!script_cmd_verify_arg_actnpt(scverif,err_msg,cmd->params[2],true,true))
01864 {
01865 (*err_param)=2;
01866 return VERIF_WARN;
01867 }
01868 if (!script_cmd_verify_arg_unsg_int(scverif,err_msg,cmd->params[3],1,200))
01869 {
01870 (*err_param)=3;
01871 return VERIF_WARN;
01872 }
01873 break;
01874 case ADD_CREATR_TOLEV:
01875 if (!script_cmd_verify_argcount(err_msg,cmd,6))
01876 {
01877 (*err_param)=ERR_SCRIPTPARAM_NARGS;
01878 return VERIF_WARN;
01879 }
01880 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
01881 "player",players_cmd_index,&plyr_idx))
01882 {
01883 (*err_param)=0;
01884 return VERIF_WARN;
01885 }
01886 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[1],&crtr_idx))
01887 {
01888 (*err_param)=1;
01889 return VERIF_WARN;
01890 }
01891 if (!script_cmd_verify_arg_actnpt(scverif,err_msg,cmd->params[2],true,true))
01892 {
01893 (*err_param)=2;
01894 return VERIF_WARN;
01895 }
01896 if (!script_cmd_verify_arg_ncrtrs(scverif,err_msg,cmd->params[3],1,&i))
01897 {
01898 (*err_param)=3;
01899 return VERIF_WARN;
01900 }
01901 if (!script_cmd_verify_arg_experience(scverif,err_msg,cmd->params[4]))
01902 {
01903 (*err_param)=4;
01904 return VERIF_WARN;
01905 }
01906 if (!script_cmd_verify_arg_goldamnt(scverif,err_msg,cmd->params[5]))
01907 {
01908 (*err_param)=5;
01909 return VERIF_WARN;
01910 }
01911 break;
01912 case ADD_TUNNELLER_PARTY_TOLEV:
01913 if (!script_cmd_verify_argcount(err_msg,cmd,7))
01914 {
01915 (*err_param)=ERR_SCRIPTPARAM_NARGS;
01916 return VERIF_WARN;
01917 }
01918 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
01919 "player",players_cmd_index,&plyr_idx))
01920 {
01921 (*err_param)=0;
01922 return VERIF_WARN;
01923 }
01924 if (!script_cmd_verify_arg_party_name(scverif,err_msg,cmd->params[1],
01925 false,&party_idx))
01926 {
01927 (*err_param)=1;
01928 return VERIF_WARN;
01929 }
01930 if (!script_cmd_verify_arg_actnpt(scverif,err_msg,cmd->params[2],true,true))
01931 {
01932 (*err_param)=2;
01933 return VERIF_WARN;
01934 }
01935 if (!script_cmd_verify_arg_party_objectv(scverif,err_msg,cmd->params[3],true,&i))
01936 {
01937 (*err_param)=3;
01938 return VERIF_WARN;
01939 }
01940 switch (i)
01941 {
01942 case OBJCTV_ACTNPT:
01943 if (!script_cmd_verify_arg_actnpt(scverif,err_msg,cmd->params[4],true,true))
01944 {
01945 (*err_param)=4;
01946 return VERIF_WARN;
01947 }
01948 break;
01949 case OBJCTV_DUNGEON:
01950 case OBJCTV_DNHEART:
01951
01952 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[4],
01953 "Player index",0,5))
01954
01955 {
01956 (*err_param)=4;
01957 return VERIF_WARN;
01958 }
01959 break;
01960 case OBJCTV_APPROP_DUNG:
01961 if (!script_cmd_verify_arg_specval(scverif,err_msg,cmd->params[4],'0'))
01962 {
01963 (*err_param)=4;
01964 return VERIF_WARN;
01965 }
01966 break;
01967 default:
01968 sprintf(err_msg,"Internal problem with party objective in script");
01969 (*err_param)=4;
01970 return VERIF_WARN;
01971 }
01972 if (!script_cmd_verify_arg_experience(scverif,err_msg,cmd->params[5]))
01973 {
01974 (*err_param)=5;
01975 return VERIF_WARN;
01976 }
01977 if (!script_cmd_verify_arg_goldamnt(scverif,err_msg,cmd->params[6]))
01978 {
01979 (*err_param)=6;
01980 return VERIF_WARN;
01981 }
01982 break;
01983 default:
01984 sprintf(err_msg,"Internal warn - wrong PARTY script command");
01985 return VERIF_WARN;
01986 }
01987 return VERIF_OK;
01988 }
01989
01990 short script_cmd_verify_avail(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,int *err_param,const struct DK_SCRIPT_COMMAND *cmd)
01991 {
01992 int plyr_idx;
01993 int crtr_idx;
01994 int i;
01995 short logic_val;
01996 switch (cmd->index)
01997 {
01998 case ROOM_AVAIL:
01999 if (!script_cmd_verify_argcount(err_msg,cmd,4))
02000 {
02001 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02002 return VERIF_WARN;
02003 }
02004 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02005 "player",players_cmd_index,&plyr_idx))
02006 {
02007 (*err_param)=0;
02008 return VERIF_WARN;
02009 }
02010 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[1],
02011 "room",room_cmd_index,&i))
02012 {
02013 (*err_param)=1;
02014 return VERIF_WARN;
02015 }
02016 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[2],&logic_val))
02017 {
02018 (*err_param)=2;
02019 return VERIF_WARN;
02020 }
02021 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[3],&logic_val))
02022 {
02023 (*err_param)=3;
02024 return VERIF_WARN;
02025 }
02026 break;
02027 case CREATR_AVAIL:
02028 if (!script_cmd_verify_argcount(err_msg,cmd,4))
02029 {
02030 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02031 return VERIF_WARN;
02032 }
02033 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02034 "player",players_cmd_index,&plyr_idx))
02035 {
02036 (*err_param)=0;
02037 return VERIF_WARN;
02038 }
02039 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[1],&crtr_idx))
02040 {
02041 (*err_param)=1;
02042 return VERIF_WARN;
02043 }
02044 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[2],&logic_val))
02045 {
02046 (*err_param)=2;
02047 return VERIF_WARN;
02048 }
02049 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[3],&logic_val))
02050 {
02051 (*err_param)=3;
02052 return VERIF_WARN;
02053 }
02054 break;
02055 case MAGIC_AVAIL:
02056 if (!script_cmd_verify_argcount(err_msg,cmd,4))
02057 {
02058 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02059 return VERIF_WARN;
02060 }
02061 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02062 "player",players_cmd_index,&plyr_idx))
02063 {
02064 (*err_param)=0;
02065 return VERIF_WARN;
02066 }
02067 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[1],
02068 "spell",spell_cmd_index,&i))
02069 {
02070 (*err_param)=1;
02071 return VERIF_WARN;
02072 }
02073 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[2],&logic_val))
02074 {
02075 (*err_param)=2;
02076 return VERIF_WARN;
02077 }
02078 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[3],&logic_val))
02079 {
02080 (*err_param)=3;
02081 return VERIF_WARN;
02082 }
02083 break;
02084 case TRAP_AVAIL:
02085 if (!script_cmd_verify_argcount(err_msg,cmd,4))
02086 {
02087 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02088 return VERIF_WARN;
02089 }
02090 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02091 "player",players_cmd_index,&plyr_idx))
02092 {
02093 (*err_param)=0;
02094 return VERIF_WARN;
02095 }
02096 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[1],
02097 "trap",trap_cmd_index,&i))
02098 {
02099 (*err_param)=1;
02100 return VERIF_WARN;
02101 }
02102 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[2],&logic_val))
02103 {
02104 (*err_param)=2;
02105 return VERIF_WARN;
02106 }
02107 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],
02108 "Traps amount",0,32767))
02109 {
02110 (*err_param)=3;
02111 return VERIF_WARN;
02112 }
02113 break;
02114 case DOOR_AVAIL:
02115 if (!script_cmd_verify_argcount(err_msg,cmd,4))
02116 {
02117 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02118 return VERIF_WARN;
02119 }
02120 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02121 "player",players_cmd_index,&plyr_idx))
02122 {
02123 (*err_param)=0;
02124 return VERIF_WARN;
02125 }
02126 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[1],
02127 "door",door_cmd_index,&i))
02128 {
02129 (*err_param)=1;
02130 return VERIF_WARN;
02131 }
02132 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[2],&logic_val))
02133 {
02134 (*err_param)=2;
02135 return VERIF_WARN;
02136 }
02137 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],
02138 "Doors amount",0,32767))
02139 {
02140 (*err_param)=3;
02141 return VERIF_WARN;
02142 }
02143 break;
02144 default:
02145 sprintf(err_msg,"Internal warn - wrong AVAIL script command");
02146 return VERIF_WARN;
02147 }
02148 return VERIF_OK;
02149 }
02150
02151 short script_cmd_verify_custobj(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,int *err_param,const struct DK_SCRIPT_COMMAND *cmd)
02152 {
02153 int plyr_idx;
02154 int i;
02155 switch (cmd->index)
02156 {
02157 case DISPLAY_OBJECTV:
02158 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02159 {
02160 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02161 return VERIF_WARN;
02162 }
02163 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[0],
02164 "Message index",0,1023))
02165 {
02166 (*err_param)=0;
02167 return VERIF_WARN;
02168 }
02169 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[1],
02170 "player",players_cmd_index,&plyr_idx))
02171 {
02172 (*err_param)=1;
02173 return VERIF_WARN;
02174 }
02175 break;
02176 case DISPLAY_OBJECTV_WPOS:
02177 if (!script_cmd_verify_argcount(err_msg,cmd,3))
02178 {
02179 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02180 return VERIF_WARN;
02181 }
02182 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[0],
02183 "Message index",0,1023))
02184 {
02185 (*err_param)=0;
02186 return VERIF_WARN;
02187 }
02188 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[1],
02189 "Map X coord",0,84))
02190 {
02191 (*err_param)=1;
02192 return VERIF_WARN;
02193 }
02194 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[2],
02195 "Map Y coord",0,84))
02196 {
02197 (*err_param)=2;
02198 return VERIF_WARN;
02199 }
02200 break;
02201 case DISPLAY_INFO:
02202 if (cmd->param_count!=2)
02203 if (!script_cmd_verify_argcount(err_msg,cmd,1))
02204 {
02205 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02206 return VERIF_WARN;
02207 }
02208 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[0],
02209 "Message index",0,1023))
02210 {
02211 (*err_param)=0;
02212 return VERIF_WARN;
02213 }
02214 break;
02215 case DISPLAY_INFO_WPOS:
02216 if (!script_cmd_verify_argcount(err_msg,cmd,3))
02217 {
02218 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02219 return VERIF_WARN;
02220 }
02221 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[0],
02222 "Message index",0,1023))
02223 {
02224 (*err_param)=0;
02225 return VERIF_WARN;
02226 }
02227 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[1],
02228 "Map X coord",0,84))
02229 {
02230 (*err_param)=1;
02231 return VERIF_WARN;
02232 }
02233 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[2],
02234 "Map Y coord",0,84))
02235 {
02236 (*err_param)=2;
02237 return VERIF_WARN;
02238 }
02239 break;
02240 case BONUS_LEV_TIME:
02241 if (!script_cmd_verify_argcount(err_msg,cmd,1))
02242 {
02243 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02244 return VERIF_WARN;
02245 }
02246 if (!script_cmd_verify_arg_gameturn(scverif,err_msg,cmd->params[0]))
02247 {
02248 (*err_param)=0;
02249 return VERIF_WARN;
02250 }
02251 break;
02252 case TUTORIAL_FLASH_BTN:
02253 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02254 {
02255 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02256 return VERIF_WARN;
02257 }
02258 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[0],
02259 "Button index",0,255))
02260 {
02261 (*err_param)=0;
02262 return VERIF_WARN;
02263 }
02264 if (!script_cmd_verify_arg_btnparam(scverif,err_msg,cmd->params[1]))
02265 {
02266 (*err_param)=1;
02267 return VERIF_WARN;
02268 }
02269 break;
02270 case QUICK_OBJECTV:
02271 if (cmd->param_count > 1)
02272 if (!script_cmd_verify_arg_quotparam(scverif,err_msg,cmd->params[1],
02273 "Objective text",&i))
02274 {
02275 (*err_param)=1;
02276 return VERIF_WARN;
02277 }
02278 if (!script_cmd_verify_argcount(err_msg,cmd,3))
02279 {
02280 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02281 return VERIF_WARN;
02282 }
02283 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[0],
02284 "Objective index",0,49))
02285 {
02286 (*err_param)=0;
02287 return VERIF_WARN;
02288 }
02289 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[2],
02290 "player",players_cmd_index,&plyr_idx))
02291 {
02292 (*err_param)=2;
02293 return VERIF_WARN;
02294 }
02295 break;
02296 case QUICK_INFO:
02297 if (cmd->param_count > 1)
02298 if (!script_cmd_verify_arg_quotparam(scverif,err_msg,cmd->params[1],
02299 "Information text",&i))
02300 {
02301 (*err_param)=1;
02302 return VERIF_WARN;
02303 }
02304 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02305 {
02306 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02307 return VERIF_WARN;
02308 }
02309 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[0],
02310 "Information index",0,49))
02311 {
02312 (*err_param)=0;
02313 return VERIF_WARN;
02314 }
02315 break;
02316 default:
02317 sprintf(err_msg,"Internal warn - wrong CUSTOBJ script command");
02318 return VERIF_WARN;
02319 }
02320 return VERIF_OK;
02321 }
02322
02323 short script_cmd_verify_setup(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,int *err_param,const struct DK_SCRIPT_COMMAND *cmd)
02324 {
02325 int obj_type;
02326 int i;
02327 int plyr_idx;
02328 int plyr2_idx;
02329 switch (cmd->index)
02330 {
02331 case SET_GEN_SPEED:
02332 if (!script_cmd_verify_argcount(err_msg,cmd,1))
02333 {
02334 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02335 return VERIF_WARN;
02336 }
02337 if (!script_cmd_verify_arg_gameturn(scverif,err_msg,cmd->params[0]))
02338 {
02339 (*err_param)=0;
02340 return VERIF_WARN;
02341 }
02342 break;
02343 case START_MONEY:
02344 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02345 {
02346 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02347 return VERIF_WARN;
02348 }
02349 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02350 "player",players_cmd_index,&plyr_idx))
02351 {
02352 (*err_param)=0;
02353 return VERIF_WARN;
02354 }
02355 if (!script_cmd_verify_arg_goldamnt(scverif,err_msg,cmd->params[1]))
02356 {
02357 (*err_param)=1;
02358 return VERIF_WARN;
02359 }
02360 break;
02361 case COMP_PLAYER:
02362 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02363 {
02364 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02365 return VERIF_WARN;
02366 }
02367 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02368 "player",players_cmd_index,&plyr_idx))
02369 {
02370 (*err_param)=0;
02371 return VERIF_WARN;
02372 }
02373 if (plyr_idx==PLAYER0)
02374 {
02375 sprintf(err_msg,"%s is set as AI player in script",players_cmd_text(PLAYER0));
02376 (*err_param)=0;
02377 return VERIF_WARN;
02378 }
02379 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[1],
02380 "Computer player",0,10))
02381 {
02382 (*err_param)=1;
02383 return VERIF_WARN;
02384 }
02385 break;
02386 case ALLY_PLAYERS:
02387 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02388 {
02389 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02390 return VERIF_WARN;
02391 }
02392 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02393 "player",players_cmd_index,&plyr_idx))
02394 {
02395 (*err_param)=0;
02396 return VERIF_WARN;
02397 }
02398 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[1],
02399 "player",players_cmd_index,&plyr2_idx))
02400 {
02401 (*err_param)=1;
02402 return VERIF_WARN;
02403 }
02404 if (plyr_idx==plyr2_idx)
02405 {
02406 sprintf(err_msg,"Cannot ally player with himself");
02407 (*err_param)=ERR_SCRIPTPARAM_WHOLE;
02408 return VERIF_WARN;
02409 }
02410 break;
02411 case SET_HATE:
02412 if (!script_cmd_verify_argcount(err_msg,cmd,3))
02413 {
02414 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02415 return VERIF_WARN;
02416 }
02417 break;
02418 case RESEARCH:
02419 if (!script_cmd_verify_argcount(err_msg,cmd,4))
02420 {
02421 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02422 return VERIF_WARN;
02423 }
02424 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02425 "player",players_cmd_index,&plyr_idx))
02426 {
02427 (*err_param)=0;
02428 return VERIF_WARN;
02429 }
02430 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[1],
02431 "object type",objtype_cmd_index,&obj_type))
02432 {
02433 (*err_param)=1;
02434 return VERIF_WARN;
02435 }
02436 switch (obj_type)
02437 {
02438 case OBJTYPE_CREATURE:
02439 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[2],&i))
02440 {
02441 (*err_param)=2;
02442 return VERIF_WARN;
02443 }
02444 break;
02445 case OBJTYPE_ROOM:
02446 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[2],
02447 "room",room_cmd_index,&i))
02448 {
02449 (*err_param)=2;
02450 return VERIF_WARN;
02451 }
02452 break;
02453 case OBJTYPE_SPELL:
02454 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[2],
02455 "spell",spell_cmd_index,&i))
02456 {
02457 (*err_param)=2;
02458 return VERIF_WARN;
02459 }
02460 break;
02461 default:
02462 sprintf(err_msg,"Internal problem with object type in script");
02463 (*err_param)=1;
02464 return VERIF_WARN;
02465 }
02466 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[3],
02467 "Research points",1,16777216))
02468 {
02469 (*err_param)=3;
02470 return VERIF_WARN;
02471 }
02472 break;
02473 case SET_COMPUTER_GLOBALS:
02474 if (!script_cmd_verify_argcount(err_msg,cmd,7))
02475 {
02476 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02477 return VERIF_WARN;
02478 }
02479 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02480 "player",players_cmd_index,&plyr_idx))
02481 {
02482 (*err_param)=0;
02483 return VERIF_WARN;
02484 }
02485 break;
02486 case SET_COMPUTER_CHECKS:
02487 if (!script_cmd_verify_argcount(err_msg,cmd,7))
02488 {
02489 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02490 return VERIF_WARN;
02491 }
02492 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02493 "player",players_cmd_index,&plyr_idx))
02494 {
02495 (*err_param)=0;
02496 return VERIF_WARN;
02497 }
02498 break;
02499 case SET_COMPUTER_EVENT:
02500 if (!script_cmd_verify_argcount(err_msg,cmd,4))
02501 {
02502 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02503 return VERIF_WARN;
02504 }
02505 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02506 "player",players_cmd_index,&plyr_idx))
02507 {
02508 (*err_param)=0;
02509 return VERIF_WARN;
02510 }
02511 break;
02512 case SET_COMPUTER_PROCESS:
02513 if (!script_cmd_verify_argcount(err_msg,cmd,7))
02514 {
02515 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02516 return VERIF_WARN;
02517 }
02518 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02519 "player",players_cmd_index,&plyr_idx))
02520 {
02521 (*err_param)=0;
02522 return VERIF_WARN;
02523 }
02524 break;
02525 case MAX_CREATURES:
02526 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02527 {
02528 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02529 return VERIF_WARN;
02530 }
02531 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02532 "player",players_cmd_index,&plyr_idx))
02533 {
02534 (*err_param)=0;
02535 return VERIF_WARN;
02536 }
02537 if (!script_cmd_verify_arg_ncrtrs(scverif,err_msg,cmd->params[1],0,&i))
02538 {
02539 (*err_param)=1;
02540 return VERIF_WARN;
02541 }
02542 break;
02543 default:
02544 sprintf(err_msg,"Internal warn - wrong SETUP script command");
02545 return VERIF_WARN;
02546 }
02547 return VERIF_OK;
02548 }
02549
02550 short script_cmd_verify_triger(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,int *err_param,const struct DK_SCRIPT_COMMAND *cmd)
02551 {
02552 int plyr_idx;
02553 int i;
02554 switch (cmd->index)
02555 {
02556 case RESET_ACTNPT:
02557 if (!script_cmd_verify_argcount(err_msg,cmd,1))
02558 {
02559 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02560 return VERIF_WARN;
02561 }
02562 if (!script_cmd_verify_arg_actnpt(scverif,err_msg,cmd->params[0],false,false))
02563 {
02564 (*err_param)=0;
02565 return VERIF_WARN;
02566 }
02567 break;
02568 case NEXT_CMD_REUSABLE:
02569 if (!script_cmd_verify_argcount(err_msg,cmd,0))
02570 {
02571 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02572 return VERIF_WARN;
02573 }
02574 break;
02575 case SET_FLAG:
02576 if (!script_cmd_verify_argcount(err_msg,cmd,3))
02577 {
02578 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02579 return VERIF_WARN;
02580 }
02581 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02582 "player",players_cmd_index,&plyr_idx))
02583 {
02584 (*err_param)=0;
02585 return VERIF_WARN;
02586 }
02587 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[1],
02588 "flag",flag_cmd_index,&i))
02589 {
02590 (*err_param)=1;
02591 return VERIF_WARN;
02592 }
02593 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[2],"Flag",0,255))
02594 {
02595 (*err_param)=2;
02596 return VERIF_WARN;
02597 }
02598 break;
02599 case SET_TIMER:
02600 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02601 {
02602 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02603 return VERIF_WARN;
02604 }
02605 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02606 "player",players_cmd_index,&plyr_idx))
02607 {
02608 (*err_param)=0;
02609 return VERIF_WARN;
02610 }
02611 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[1],
02612 "timer",timer_cmd_index,&i))
02613 {
02614 (*err_param)=1;
02615 return VERIF_WARN;
02616 }
02617 break;
02618 case GAME_LOSE:
02619 if (!script_cmd_verify_argcount(err_msg,cmd,0))
02620 {
02621 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02622 return VERIF_WARN;
02623 }
02624 break;
02625 case GAME_WIN:
02626 if (!script_cmd_verify_argcount(err_msg,cmd,0))
02627 {
02628 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02629 return VERIF_WARN;
02630 }
02631 break;
02632 case SET_MUSIC:
02633 if (!script_cmd_verify_argcount(err_msg,cmd,1))
02634 {
02635 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02636 return VERIF_WARN;
02637 }
02638 break;
02639 default:
02640 sprintf(err_msg,"Internal warn - wrong TRIGER script command");
02641 return VERIF_WARN;
02642 }
02643 return VERIF_OK;
02644 }
02645
02646 short script_cmd_verify_crtradj(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,int *err_param,const struct DK_SCRIPT_COMMAND *cmd)
02647 {
02648 int i;
02649 int plyr_idx;
02650 int crtr_idx;
02651 int crtr2_idx;
02652 short logic_val;
02653 switch (cmd->index)
02654 {
02655 case DEAD_CREATURES_RET_TO_POOL:
02656 if (!script_cmd_verify_argcount(err_msg,cmd,1))
02657 {
02658 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02659 return VERIF_WARN;
02660 }
02661 if (!script_cmd_verify_arg_logic_int(scverif,err_msg,cmd->params[0],&logic_val))
02662 {
02663 (*err_param)=0;
02664 return VERIF_WARN;
02665 }
02666 break;
02667 case ADD_CREATR_TO_POOL:
02668 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02669 {
02670 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02671 return VERIF_WARN;
02672 }
02673 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[0],&crtr_idx))
02674 {
02675 (*err_param)=0;
02676 return VERIF_WARN;
02677 }
02678 if (!script_cmd_verify_arg_ncrtrs(scverif,err_msg,cmd->params[1],0,&i))
02679 {
02680 (*err_param)=1;
02681 return VERIF_WARN;
02682 }
02683 scverif->total_in_pool+=i;
02684 break;
02685 case SET_CREATR_MAX_LEVEL:
02686 if (!script_cmd_verify_argcount(err_msg,cmd,3))
02687 {
02688 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02689 return VERIF_WARN;
02690 }
02691 if (!script_cmd_verify_arg_singlevar(scverif,err_msg,cmd->params[0],
02692 "player",players_cmd_index,&plyr_idx))
02693 {
02694 (*err_param)=0;
02695 return VERIF_WARN;
02696 }
02697 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[1],&crtr_idx))
02698 {
02699 (*err_param)=1;
02700 return VERIF_WARN;
02701 }
02702 if (!script_cmd_verify_arg_experience(scverif,err_msg,cmd->params[2]))
02703 {
02704 (*err_param)=2;
02705 return VERIF_WARN;
02706 }
02707 break;
02708 case SET_CREATR_STRENGTH:
02709 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02710 {
02711 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02712 return VERIF_WARN;
02713 }
02714 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[0],&crtr_idx))
02715 {
02716 (*err_param)=0;
02717 return VERIF_WARN;
02718 }
02719 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[1],"Strength",0,255))
02720 {
02721 (*err_param)=1;
02722 return VERIF_WARN;
02723 }
02724 break;
02725 case SET_CREATR_HEALTH:
02726 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02727 {
02728 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02729 return VERIF_WARN;
02730 }
02731 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[0],&crtr_idx))
02732 {
02733 (*err_param)=0;
02734 return VERIF_WARN;
02735 }
02736 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[1],"Health",0,7895))
02737 {
02738 (*err_param)=1;
02739 return VERIF_WARN;
02740 }
02741 break;
02742 case SET_CREATR_ARMOUR:
02743 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02744 {
02745 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02746 return VERIF_WARN;
02747 }
02748 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[0],&crtr_idx))
02749 {
02750 (*err_param)=0;
02751 return VERIF_WARN;
02752 }
02753 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[1],"Armour",0,255))
02754 {
02755 (*err_param)=1;
02756 return VERIF_WARN;
02757 }
02758 break;
02759 case SET_CREATR_FEAR:
02760 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02761 {
02762 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02763 return VERIF_WARN;
02764 }
02765 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[0],&crtr_idx))
02766 {
02767 (*err_param)=0;
02768 return VERIF_WARN;
02769 }
02770 if (!script_cmd_verify_arg_limparam(scverif,err_msg,cmd->params[1],"Fear",0,255))
02771 {
02772 (*err_param)=1;
02773 return VERIF_WARN;
02774 }
02775 break;
02776 case CREATR_SWAP:
02777 if (!script_cmd_verify_argcount(err_msg,cmd,2))
02778 {
02779 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02780 return VERIF_WARN;
02781 }
02782 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[0],&crtr_idx))
02783 {
02784 (*err_param)=0;
02785 return VERIF_WARN;
02786 }
02787 if (!script_cmd_verify_arg_creatr(scverif,err_msg,cmd->params[1],&crtr2_idx))
02788 {
02789 (*err_param)=1;
02790 return VERIF_WARN;
02791 }
02792 break;
02793 default:
02794 sprintf(err_msg,"Internal warn - wrong CRTRADJ script command");
02795 return VERIF_WARN;
02796 }
02797 return VERIF_OK;
02798 }
02799
02800 short script_cmd_verify_commnt(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,int *err_param,const struct DK_SCRIPT_COMMAND *cmd)
02801 {
02802 switch (cmd->index)
02803 {
02804 case EMPTYLN:
02805 case CMNT_REM:
02806 break;
02807 default:
02808 sprintf(err_msg,"Internal warn - wrong COMMNT script command");
02809 return VERIF_WARN;
02810 }
02811 return VERIF_OK;
02812 }
02813
02814 short script_cmd_verify_obsol(struct SCRIPT_VERIFY_DATA *scverif,char *err_msg,int *err_param,const struct DK_SCRIPT_COMMAND *cmd)
02815 {
02816 switch (cmd->index)
02817 {
02818 case OBSOLT_PRINT:
02819 if (!script_cmd_verify_argcount(err_msg,cmd,1))
02820 {
02821 (*err_param)=ERR_SCRIPTPARAM_NARGS;
02822 return VERIF_WARN;
02823 }
02824 break;
02825 default:
02826 sprintf(err_msg,"Obsolete command used in script");
02827 return VERIF_WARN;
02828 }
02829 return VERIF_OK;
02830 }
02831
02832
02833
02834
02835
02836 short txt_verify(const struct LEVEL *lvl, char *err_msg,struct IPOINT_2D *errpt)
02837 {
02838 int err_line=-1;
02839 int err_param=ERR_SCRIPTPARAM_WHOLE;
02840 short result=dkscript_verify(lvl,err_msg,&err_line,&err_param);
02841 if (result!=VERIF_OK)
02842 {
02843 errpt->x=-1;
02844 errpt->y=-1;
02845 }
02846 return result;
02847 }
02848
02849
02850
02851
02852
02853 short dkscript_verify(const struct LEVEL *lvl, char *err_msg,int *err_line,int *err_param)
02854 {
02855 char child_err_msg[LINEMSG_SIZE];
02856 child_err_msg[0]='\0';
02857 struct SCRIPT_VERIFY_DATA scverif;
02858 scverif.dnhearts_count=0;
02859 scverif.herogts_count=256;
02860 if (!create_herogate_number_used_arr(lvl,&(scverif.herogts),&(scverif.herogts_count)))
02861 sprintf(child_err_msg,"hero gates");
02862 scverif.actnpts_count=256;
02863 if (!create_actnpt_number_used_arr(lvl,&(scverif.actnpts),&(scverif.actnpts_count)))
02864 sprintf(child_err_msg,"action points");
02865 if (child_err_msg[0]!='\0')
02866 {
02867 sprintf(err_msg,"Internal - cannot list %s to verify script",child_err_msg);
02868 return VERIF_WARN;
02869 }
02870 scverif.level=0;
02871 scverif.total_ifs=0;
02872 scverif.total_in_pool=0;
02873 scverif.partys=(char **)malloc((MAX_PARTYS+1)*sizeof(char *));
02874 if (scverif.partys==NULL)
02875 {
02876 message_error("txt_verify: Cannot allocate memory");
02877 return VERIF_WARN;
02878 }
02879 int i;
02880 for (i=0; i<(MAX_PARTYS+1); i++)
02881 scverif.partys[i]=NULL;
02882
02883 short result=VERIF_OK;
02884
02885 for (i=0; i<lvl->script.lines_count; i++)
02886 {
02887 struct DK_SCRIPT_COMMAND *cmd;
02888 cmd=lvl->script.list[i];
02889 switch (cmd->group)
02890 {
02891 case CMD_CONDIT:
02892 result=script_cmd_verify_condit(&scverif,child_err_msg,err_param,cmd);
02893 break;
02894 case CMD_PARTY:
02895 result=script_cmd_verify_party(&scverif,child_err_msg,err_param,cmd);
02896 break;
02897 case CMD_AVAIL:
02898 result=script_cmd_verify_avail(&scverif,child_err_msg,err_param,cmd);
02899 break;
02900 case CMD_CUSTOBJ:
02901 result=script_cmd_verify_custobj(&scverif,child_err_msg,err_param,cmd);
02902 break;
02903 case CMD_SETUP:
02904 result=script_cmd_verify_setup(&scverif,child_err_msg,err_param,cmd);
02905 break;
02906 case CMD_TRIGER:
02907 result=script_cmd_verify_triger(&scverif,child_err_msg,err_param,cmd);
02908 break;
02909 case CMD_CRTRADJ:
02910 result=script_cmd_verify_crtradj(&scverif,child_err_msg,err_param,cmd);
02911 break;
02912 case CMD_COMMNT:
02913 result=script_cmd_verify_commnt(&scverif,child_err_msg,err_param,cmd);
02914 break;
02915 case CMD_OBSOLT:
02916 result=script_cmd_verify_obsol(&scverif,child_err_msg,err_param,cmd);
02917 break;
02918 case CMD_UNKNOWN:
02919 sprintf(child_err_msg,"Unrecognized script command");
02920 result=VERIF_WARN;
02921 break;
02922 case CMD_ADIKTED:
02923 sprintf(child_err_msg,"%s specific command used in DK script",PROGRAM_NAME);
02924 result=VERIF_WARN;
02925 break;
02926 default:
02927 sprintf(child_err_msg,"Internal - bad script command group");
02928 result=VERIF_WARN;
02929 break;
02930 }
02931
02932 if (result!=VERIF_OK)
02933 {
02934 sprintf(err_msg,"%s at line %d.",child_err_msg,i+1);
02935 *err_line=i;
02936 break;
02937 }
02938 }
02939 const int max_condit_if=48;
02940 if ((result==VERIF_OK)&&(scverif.total_ifs>max_condit_if))
02941 {
02942 sprintf(err_msg,"Script file contains more than %d IF statements.",max_condit_if);
02943 result=VERIF_WARN;
02944 }
02945 if ((result==VERIF_OK)&&(scverif.level!=0))
02946 {
02947 if (scverif.level>0)
02948 sprintf(err_msg,"There are %d unclosed IF statements",scverif.level);
02949 else
02950 sprintf(err_msg,"Amount of ENDIFs is larger than of IF statements");
02951 result=VERIF_WARN;
02952 }
02953
02954 for (i=0; i<16; i++)
02955 free(scverif.partys[i]);
02956 free(scverif.partys);
02957 free(scverif.actnpts);
02958 free(scverif.herogts);
02959 return result;
02960 }
02961
02962 short execute_script_line(struct LEVEL *lvl,char *line,char *err_msg)
02963 {
02964 struct DK_SCRIPT_COMMAND *cmd;
02965 cmd=malloc(sizeof(struct DK_SCRIPT_COMMAND));
02966 if (cmd==NULL)
02967 {
02968 message_error("Cannot allocate memory to execute script command");
02969 return false;
02970 }
02971 script_command_clear(cmd);
02972 int result;
02973 if (decompose_script_command(cmd,line,&(lvl->optns.script)))
02974 {
02975 switch (cmd->group)
02976 {
02977 case CMD_ADIKTED:
02978 result=execute_adikted_command(lvl,cmd,err_msg);
02979 break;
02980 case CMD_COMMNT:
02981 result=true;
02982 break;
02983 default:
02984 sprintf(err_msg,"Command is not executable in %s",PROGRAM_NAME);
02985 result=false;
02986 break;
02987 }
02988 } else
02989 {
02990
02991 if ((line==NULL)||(strlen(line)<1))
02992 {
02993 result=true;
02994 } else
02995 {
02996 sprintf(err_msg,"Cannot identify command");
02997 result=false;
02998 }
02999 }
03000 script_command_free(cmd);
03001 return result;
03002 }
03003
03004 short decompose_script(struct DK_SCRIPT *script,const struct SCRIPT_OPTIONS *optns)
03005 {
03006 if (script==NULL) return false;
03007 message_log(" decompose_script: %d lines to analyze",script->lines_count);
03008 int i;
03009 for (i=0;i<script->lines_count;i++)
03010 {
03011
03012 struct DK_SCRIPT_COMMAND *cmd=script->list[i];
03013 script_command_renew(&cmd);
03014 decompose_script_command(cmd,script->txt[i],optns);
03015
03016 script->list[i]=cmd;
03017 }
03018 return true;
03019 }
03020
03021 short recompose_script(struct DK_SCRIPT *script,const struct SCRIPT_OPTIONS *optns)
03022 {
03023 if (script==NULL) return false;
03024 int i;
03025 for (i=0;i<script->lines_count;i++)
03026 {
03027 char *nline;
03028 nline=recompose_script_command(script->list[i],optns);
03029 free(script->txt[i]);
03030 if (nline!=NULL)
03031 script->txt[i]=nline;
03032 else
03033 script->txt[i]=strdup("");
03034 }
03035 return true;
03036 }
03037
03038 short recompute_script_levels(struct DK_SCRIPT *script)
03039 {
03040 if (script==NULL) return false;
03041 int i;
03042 int lev=0;
03043 short result=true;
03044 for (i=0;i<script->lines_count;i++)
03045 {
03046 struct DK_SCRIPT_COMMAND *cmd=script->list[i];
03047 switch (cmd->group)
03048 {
03049 case CMD_CONDIT:
03050 if (cmd->index==COND_ENDIF)
03051 {
03052 lev--;
03053 cmd->level=max(lev,0);
03054 } else
03055 {
03056 cmd->level=max(lev,0);
03057 lev++;
03058 }
03059 break;
03060 case CMD_PARTY:
03061 if (cmd->index==ADD_TO_PARTY)
03062 cmd->level=max(lev+1,1);
03063 else
03064 cmd->level=max(lev,0);
03065 break;
03066 default:
03067 cmd->level=max(lev,0);
03068 break;
03069 }
03070 if (lev<0)
03071 result=false;
03072 }
03073 if (lev!=0)
03074 result=false;
03075 return result;
03076 }
03077
03078 int get_script_command_level(const char *text,const struct SCRIPT_OPTIONS *optns)
03079 {
03080 int lev=0;
03081 int nspac=0;
03082 int len=strlen(text);
03083 int i;
03084 for (i=0;i<len;i++)
03085 {
03086 if (text[i]==' ')
03087 {
03088 nspac++;
03089 if (nspac>=optns->level_spaces)
03090 {
03091 nspac=0;
03092 lev++;
03093 }
03094 } else
03095 if (text[i]=='\t')
03096 {
03097 lev++;
03098 } else
03099 break;
03100 }
03101 if (nspac>0)
03102 lev++;
03103 return lev;
03104 }
03105
03106
03107
03108
03109 short script_decomposed_to_params_cmd_condit(struct DK_SCRIPT_PARAMETERS *par,
03110 struct DK_SCRIPT_COMMAND *cmd,const struct SCRIPT_OPTIONS *optns)
03111 {
03112 int plyr_idx;
03113 int conditvar_type;
03114 int conditvar_idx;
03115 int cmpvar_type;
03116 int cmpvar_idx;
03117 int opertr_idx;
03118 int actnpt_num;
03119 switch (cmd->index)
03120 {
03121 case COND_IF:
03122 par->end_level++;
03123 if (cmd->param_count<4)
03124 return false;
03125 plyr_idx=players_cmd_index(cmd->params[0]);
03126 opertr_idx=operator_cmd_index(cmd->params[2]);
03127 if ((plyr_idx<0)||(opertr_idx<0))
03128 return false;
03129 conditvar_idx=-1;
03130 cmpvar_idx-1;
03131 conditvar_type=recognize_script_word_group_and_idx(&conditvar_idx,cmd->params[1],true);
03132 cmpvar_type=recognize_script_word_group_and_idx(&cmpvar_idx,cmd->params[3],true);
03133 if ((conditvar_idx<0)||(cmpvar_idx<0))
03134 return false;
03135
03136
03137 break;
03138 case IF_AVAILABLE:
03139 par->end_level++;
03140 if (cmd->param_count<4)
03141 return false;
03142 plyr_idx=players_cmd_index(cmd->params[0]);
03143 opertr_idx=operator_cmd_index(cmd->params[2]);
03144 if ((plyr_idx<0)||(opertr_idx<0))
03145 return false;
03146 conditvar_idx=-1;
03147 cmpvar_idx-1;
03148 conditvar_type=recognize_script_word_group_and_idx(&conditvar_idx,cmd->params[1],true);
03149 cmpvar_type=recognize_script_word_group_and_idx(&cmpvar_idx,cmd->params[3],true);
03150 if ((conditvar_idx<0)||(cmpvar_idx<0))
03151 return false;
03152
03153
03154 break;
03155 case IF_ACTNPT:
03156 par->end_level++;
03157 if (cmd->param_count<2)
03158 return false;
03159 if (!script_param_to_int(&actnpt_num,cmd->params[0]))
03160 return false;
03161 plyr_idx=players_cmd_index(cmd->params[1]);
03162 if (plyr_idx<0)
03163 return false;
03164
03165
03166 break;
03167 case COND_ENDIF:
03168 par->end_level--;
03169
03170
03171 break;
03172 default:
03173 return false;
03174 }
03175 return true;
03176 }
03177
03178
03179
03180
03181
03182 short script_decomposed_to_params_cmd_blockbody(struct DK_SCRIPT_PARAMETERS *par,
03183 struct DK_SCRIPT_COMMAND *cmd,const struct SCRIPT_OPTIONS *optns)
03184 {
03185
03186
03187 return true;
03188 }
03189
03190
03191
03192
03193 short script_decomposed_to_params_cmd_party(struct DK_SCRIPT_PARAMETERS *par,
03194 struct DK_SCRIPT_COMMAND *cmd,const struct SCRIPT_OPTIONS *optns)
03195 {
03196
03197
03198 return true;
03199 }
03200
03201
03202
03203
03204 short script_decomposed_to_params_cmd_avail(struct DK_SCRIPT_PARAMETERS *par,
03205 struct DK_SCRIPT_COMMAND *cmd,const struct SCRIPT_OPTIONS *optns)
03206 {
03207 int plyr_idx;
03208 int object_idx;
03209 int logic_val;
03210 int amount;
03211 short available;
03212 int i;
03213 switch (cmd->index)
03214 {
03215 case ROOM_AVAIL:
03216 if (cmd->param_count<4)
03217 return false;
03218 plyr_idx=players_cmd_index(cmd->params[0]);
03219 object_idx=room_cmd_index(cmd->params[1]);
03220 if ((plyr_idx<0)||(object_idx<0))
03221 return false;
03222 if (!script_param_to_int(&logic_val,cmd->params[2]))
03223 return false;
03224 if (!script_param_to_int(&amount,cmd->params[3]))
03225 return false;
03226 if (amount)
03227 available=AVAIL_INSTANT;
03228 else
03229 if (logic_val)
03230 available=AVAIL_RESEARCH;
03231 else
03232 available=AVAIL_NO;
03233 if (plyr_idx<PLAYERS_COUNT)
03234 {
03235 par->player[plyr_idx].room_avail[object_idx]=available;
03236 } else
03237 if (plyr_idx==PLAYER_ALL)
03238 {
03239 for (i=0;i<PLAYERS_COUNT;i++)
03240 par->player[i].room_avail[object_idx]=available;
03241 } else
03242 {
03243 return false;
03244 }
03245 break;
03246 case CREATR_AVAIL:
03247 if (cmd->param_count<4)
03248 return false;
03249 plyr_idx=players_cmd_index(cmd->params[0]);
03250 object_idx=creatures_cmd_index(cmd->params[1]);
03251 if ((plyr_idx<0)||(object_idx<0))
03252 return false;
03253 if (!script_param_to_int(&logic_val,cmd->params[2]))
03254 return false;
03255 if (!script_param_to_int(&amount,cmd->params[3]))
03256 return false;
03257 if (amount)
03258 available=AVAIL_INSTANT;
03259 else
03260 if (logic_val)
03261 available=AVAIL_RESEARCH;
03262 else
03263 available=AVAIL_NO;
03264 if (plyr_idx<PLAYERS_COUNT)
03265 {
03266 par->player[plyr_idx].creature_avail[object_idx]=available;
03267 } else
03268 if (plyr_idx==PLAYER_ALL)
03269 {
03270 for (i=0;i<PLAYERS_COUNT;i++)
03271 par->player[i].creature_avail[object_idx]=available;
03272 } else
03273 {
03274 return false;
03275 }
03276 break;
03277 case MAGIC_AVAIL:
03278 if (cmd->param_count<4)
03279 return false;
03280 plyr_idx=players_cmd_index(cmd->params[0]);
03281 object_idx=spell_cmd_index(cmd->params[1]);
03282 if ((plyr_idx<0)||(object_idx<0))
03283 return false;
03284 if (!script_param_to_int(&logic_val,cmd->params[2]))
03285 return false;
03286 if (!script_param_to_int(&amount,cmd->params[3]))
03287 return false;
03288 if (amount)
03289 available=AVAIL_INSTANT;
03290 else
03291 if (logic_val)
03292 available=AVAIL_RESEARCH;
03293 else
03294 available=AVAIL_NO;
03295 if (plyr_idx<PLAYERS_COUNT)
03296 {
03297 par->player[plyr_idx].spell_avail[object_idx]=available;
03298 } else
03299 if (plyr_idx==PLAYER_ALL)
03300 {
03301 for (i=0;i<PLAYERS_COUNT;i++)
03302 par->player[i].spell_avail[object_idx]=available;
03303 } else
03304 {
03305 return false;
03306 }
03307 break;
03308 case TRAP_AVAIL:
03309 if (cmd->param_count<4)
03310 return false;
03311 plyr_idx=players_cmd_index(cmd->params[0]);
03312 object_idx=trap_cmd_index(cmd->params[1]);
03313 if ((plyr_idx<0)||(object_idx<0))
03314 return false;
03315 if (!script_param_to_int(&logic_val,cmd->params[2]))
03316 return false;
03317 if (!script_param_to_int(&amount,cmd->params[3]))
03318 return false;
03319 if (plyr_idx<PLAYERS_COUNT)
03320 {
03321 par->player[plyr_idx].trap_avail[object_idx]=(logic_val!=0);
03322 par->player[plyr_idx].trap_amount[object_idx]=amount;
03323 } else
03324 if (plyr_idx==PLAYER_ALL)
03325 {
03326 for (i=0;i<PLAYERS_COUNT;i++)
03327 {
03328 par->player[i].trap_avail[object_idx]=(logic_val!=0);
03329 par->player[i].trap_amount[object_idx]=amount;
03330 }
03331 } else
03332 {
03333 return false;
03334 }
03335 break;
03336 case DOOR_AVAIL:
03337 if (cmd->param_count<4)
03338 return false;
03339 plyr_idx=players_cmd_index(cmd->params[0]);
03340 object_idx=door_cmd_index(cmd->params[1]);
03341 if ((plyr_idx<0)||(object_idx<0))
03342 return false;
03343 if (!script_param_to_int(&logic_val,cmd->params[2]))
03344 return false;
03345 if (!script_param_to_int(&amount,cmd->params[3]))
03346 return false;
03347 if (plyr_idx<PLAYERS_COUNT)
03348 {
03349 par->player[plyr_idx].door_avail[object_idx]=(logic_val!=0);
03350 par->player[plyr_idx].door_amount[object_idx]=amount;
03351 } else
03352 if (plyr_idx==PLAYER_ALL)
03353 {
03354 for (i=0;i<PLAYERS_COUNT;i++)
03355 {
03356 par->player[i].door_avail[object_idx]=(logic_val!=0);
03357 par->player[i].door_amount[object_idx]=amount;
03358 }
03359 } else
03360 {
03361 return false;
03362 }
03363 break;
03364 default:
03365 return false;
03366 }
03367 return true;
03368 }
03369
03370
03371
03372 short script_decomposed_to_params_cmd_custobj(struct DK_SCRIPT_PARAMETERS *par,
03373 struct DK_SCRIPT_COMMAND *cmd,const struct SCRIPT_OPTIONS *optns)
03374 {
03375
03376
03377 return true;
03378 }
03379
03380
03381
03382 short script_decomposed_to_params_cmd_setup(struct DK_SCRIPT_PARAMETERS *par,
03383 struct DK_SCRIPT_COMMAND *cmd,const struct SCRIPT_OPTIONS *optns)
03384 {
03385 int obj_type;
03386 int i;
03387 int plyr_idx;
03388 int plyr2_idx;
03389 int amount;
03390 int type_idx;
03391 switch (cmd->index)
03392 {
03393 case SET_GEN_SPEED:
03394 if (cmd->param_count<1)
03395 return false;
03396 if (!script_param_to_int(&amount,cmd->params[0]))
03397 return false;
03398 par->portal_gen_speed=amount;
03399 break;
03400 case START_MONEY:
03401 if (cmd->param_count<2)
03402 return false;
03403 plyr_idx=players_cmd_index(cmd->params[0]);
03404 if (plyr_idx<0)
03405 return false;
03406 if (!script_param_to_int(&amount,cmd->params[1]))
03407 return false;
03408 if (plyr_idx<PLAYERS_COUNT)
03409 {
03410 par->player[plyr_idx].start_gold=amount;
03411 } else
03412 if (plyr_idx==PLAYER_ALL)
03413 {
03414 for (i=0;i<PLAYERS_COUNT;i++)
03415 par->player[i].start_gold=amount;
03416 } else
03417 {
03418 return false;
03419 }
03420 break;
03421 case COMP_PLAYER:
03422 if (cmd->param_count<2)
03423 return false;
03424 plyr_idx=players_cmd_index(cmd->params[0]);
03425 if (plyr_idx<0)
03426 return false;
03427 if (!script_param_to_int(&amount,cmd->params[1]))
03428 return false;
03429 if (plyr_idx<PLAYERS_COUNT)
03430 {
03431 par->player[plyr_idx].computer_player=amount;
03432 } else
03433 if (plyr_idx==PLAYER_ALL)
03434 {
03435 for (i=0;i<PLAYERS_COUNT;i++)
03436 par->player[i].computer_player=amount;
03437 } else
03438 {
03439 return false;
03440 }
03441 break;
03442 case ALLY_PLAYERS:
03443 if (cmd->param_count<2)
03444 return false;
03445 plyr_idx=players_cmd_index(cmd->params[0]);
03446 plyr2_idx=players_cmd_index(cmd->params[1]);
03447 if ((plyr_idx<0)||(plyr2_idx<0))
03448 return false;
03449 if ((plyr_idx<PLAYERS_COUNT)&&(plyr2_idx<PLAYERS_COUNT))
03450 {
03451 par->player[plyr_idx].ally[plyr2_idx]=1;
03452 par->player[plyr2_idx].ally[plyr_idx]=1;
03453 } else
03454 {
03455 return false;
03456 }
03457 break;
03458 case SET_HATE:
03459 if (cmd->param_count<3)
03460 return false;
03461
03462
03463 return false;
03464 break;
03465 case RESEARCH:
03466 if (cmd->param_count<4)
03467 return false;
03468 plyr_idx=players_cmd_index(cmd->params[0]);
03469 if (plyr_idx<0)
03470 return false;
03471 type_idx=objtype_cmd_index(cmd->params[1]);
03472 if (type_idx<0)
03473 return false;
03474
03475
03476 return false;
03477 break;
03478 case SET_COMPUTER_GLOBALS:
03479 if (cmd->param_count<7)
03480 return false;
03481 plyr_idx=players_cmd_index(cmd->params[0]);
03482 if ((plyr_idx<0))
03483 return false;
03484
03485
03486 return false;
03487 break;
03488 case SET_COMPUTER_CHECKS:
03489 if (cmd->param_count<7)
03490 return false;
03491 plyr_idx=players_cmd_index(cmd->params[0]);
03492 if ((plyr_idx<0))
03493 return false;
03494
03495
03496 return false;
03497 break;
03498 case SET_COMPUTER_EVENT:
03499 if (cmd->param_count<4)
03500 return false;
03501 plyr_idx=players_cmd_index(cmd->params[0]);
03502 if ((plyr_idx<0))
03503 return false;
03504
03505
03506 return false;
03507 break;
03508 case SET_COMPUTER_PROCESS:
03509 if (cmd->param_count<7)
03510 return false;
03511 plyr_idx=players_cmd_index(cmd->params[0]);
03512 if ((plyr_idx<0))
03513 return false;
03514
03515
03516 return false;
03517 break;
03518 case MAX_CREATURES:
03519 if (cmd->param_count<2)
03520 return false;
03521 plyr_idx=players_cmd_index(cmd->params[0]);
03522 if ((plyr_idx<0))
03523 return false;
03524 if (!script_param_to_int(&amount,cmd->params[1]))
03525 return false;
03526 if (plyr_idx<PLAYERS_COUNT)
03527 {
03528 par->player[plyr_idx].max_creatures=amount;
03529 } else
03530 if (plyr_idx==PLAYER_ALL)
03531 {
03532 for (i=0;i<PLAYERS_COUNT;i++)
03533 par->player[i].max_creatures=amount;
03534 } else
03535 {
03536 return false;
03537 }
03538 break;
03539 default:
03540 return false;
03541 }
03542 return true;
03543 }
03544
03545
03546
03547 short script_decomposed_to_params_cmd_triger(struct DK_SCRIPT_PARAMETERS *par,
03548 struct DK_SCRIPT_COMMAND *cmd,const struct SCRIPT_OPTIONS *optns)
03549 {
03550
03551
03552 return true;
03553 }
03554
03555
03556
03557 short script_decomposed_to_params_cmd_crtradj(struct DK_SCRIPT_PARAMETERS *par,
03558 struct DK_SCRIPT_COMMAND *cmd,const struct SCRIPT_OPTIONS *optns)
03559 {
03560 int i;
03561 int plyr_idx;
03562 int crtr_idx;
03563 int crtr2_idx;
03564 int logic_val;
03565 int amount;
03566 switch (cmd->index)
03567 {
03568 case DEAD_CREATURES_RET_TO_POOL:
03569 if (cmd->param_count<1)
03570 return false;
03571 if (!script_param_to_int(&logic_val,cmd->params[0]))
03572 return false;
03573 par->dead_return_to_pool=(logic_val!=0);
03574 break;
03575 case ADD_CREATR_TO_POOL:
03576 if (cmd->param_count<2)
03577 return false;
03578 crtr_idx=creatures_cmd_index(cmd->params[0]);
03579 if (crtr_idx<0)
03580 return false;
03581 if (!script_param_to_int(&amount,cmd->params[1]))
03582 return false;
03583 par->creature_pool[crtr_idx]=amount;
03584 break;
03585 case SET_CREATR_MAX_LEVEL:
03586 if (cmd->param_count<3)
03587 return false;
03588 plyr_idx=players_cmd_index(cmd->params[0]);
03589 crtr_idx=creatures_cmd_index(cmd->params[1]);
03590 if ((plyr_idx<0)||(crtr_idx<0))
03591 return false;
03592 if (!script_param_to_int(&amount,cmd->params[2]))
03593 return false;
03594 if (plyr_idx<PLAYERS_COUNT)
03595 {
03596 par->player[plyr_idx].creature_maxlvl[crtr_idx]=amount;
03597 } else
03598 if (plyr_idx==PLAYER_ALL)
03599 {
03600 for (i=0;i<PLAYERS_COUNT;i++)
03601 par->player[i].creature_maxlvl[crtr_idx]=amount;
03602 } else
03603 {
03604 return false;
03605 }
03606 break;
03607 case SET_CREATR_STRENGTH:
03608 if (cmd->param_count<2)
03609 return false;
03610 crtr_idx=creatures_cmd_index(cmd->params[0]);
03611 if (crtr_idx<0)
03612 return false;
03613 if (!script_param_to_int(&amount,cmd->params[1]))
03614 return false;
03615
03616 break;
03617 case SET_CREATR_HEALTH:
03618 if (cmd->param_count<2)
03619 return false;
03620 crtr_idx=creatures_cmd_index(cmd->params[0]);
03621 if (crtr_idx<0)
03622 return false;
03623 if (!script_param_to_int(&amount,cmd->params[1]))
03624 return false;
03625
03626 break;
03627 case SET_CREATR_ARMOUR:
03628 if (cmd->param_count<2)
03629 return false;
03630 crtr_idx=creatures_cmd_index(cmd->params[0]);
03631 if (crtr_idx<0)
03632 return false;
03633 if (!script_param_to_int(&amount,cmd->params[1]))
03634 return false;
03635
03636 break;
03637 case SET_CREATR_FEAR:
03638 if (cmd->param_count<2)
03639 return false;
03640 crtr_idx=creatures_cmd_index(cmd->params[0]);
03641 if (crtr_idx<0)
03642 return false;
03643 if (!script_param_to_int(&amount,cmd->params[1]))
03644 return false;
03645
03646 break;
03647 case CREATR_SWAP:
03648 if (cmd->param_count<2)
03649 return false;
03650 crtr_idx=creatures_cmd_index(cmd->params[0]);
03651 crtr2_idx=creatures_cmd_index(cmd->params[1]);
03652 if ((crtr_idx<0)||(crtr2_idx<0))
03653 return false;
03654
03655 break;
03656 default:
03657 return false;
03658 }
03659 return true;
03660 }
03661
03662
03663
03664
03665 short script_decomposed_to_params_cmd(struct DK_SCRIPT_PARAMETERS *par,
03666 struct DK_SCRIPT_COMMAND *cmd,const struct SCRIPT_OPTIONS *optns)
03667 {
03668 if (par->end_level==0)
03669 {
03670 switch (cmd->group)
03671 {
03672 case CMD_CONDIT:
03673 return script_decomposed_to_params_cmd_condit(par,cmd,optns);
03674 case CMD_PARTY:
03675 return script_decomposed_to_params_cmd_party(par,cmd,optns);
03676 case CMD_AVAIL:
03677 return script_decomposed_to_params_cmd_avail(par,cmd,optns);
03678 case CMD_CUSTOBJ:
03679 return script_decomposed_to_params_cmd_custobj(par,cmd,optns);
03680 case CMD_SETUP:
03681 return script_decomposed_to_params_cmd_setup(par,cmd,optns);
03682 case CMD_TRIGER:
03683 return script_decomposed_to_params_cmd_triger(par,cmd,optns);
03684 case CMD_CRTRADJ:
03685 return script_decomposed_to_params_cmd_crtradj(par,cmd,optns);
03686 case CMD_COMMNT:
03687 return true;
03688 case CMD_OBSOLT:
03689 return true;
03690 case CMD_UNKNOWN:
03691 case CMD_ADIKTED:
03692 default:
03693 return false;
03694 }
03695 } else
03696 {
03697 return script_decomposed_to_params_cmd_blockbody(par,cmd,optns);
03698 }
03699 }
03700
03701
03702
03703
03704
03705 short script_decomposed_to_params(struct DK_SCRIPT *script,const struct SCRIPT_OPTIONS *optns)
03706 {
03707 if (script==NULL) return false;
03708 short result;
03709
03710 result=level_clear_script_param(&(script->par));
03711 int i;
03712
03713 for (i=0;i<script->lines_count;i++)
03714 {
03715
03716 result&=script_decomposed_to_params_cmd(&(script->par),script->list[i],optns);
03717 }
03718 return result;
03719 }
03720
03721 short script_params_to_decomposed(struct DK_SCRIPT *script,const struct SCRIPT_OPTIONS *optns)
03722 {
03723
03724
03725
03726 }
03727
03728 short script_strword_pos( char const **ptr, unsigned int *ptr_len, const char *str, const short whole_rest )
03729 {
03730 static const char *text;
03731 if (str!=NULL)
03732 {
03733 text=str;
03734 }
03735 if (text==NULL)
03736 {
03737 (*ptr_len)=0;
03738
03739 return false;
03740 }
03741 int len;
03742 do {
03743 len=strcspn(text," \t,();");
03744 if (len==0)
03745 {
03746 if (text[0]=='\0')
03747 {
03748 (*ptr_len)=0;
03749 text=NULL;
03750
03751 return false;
03752 }
03753 text++;
03754 }
03755 } while (len==0);
03756 int text_len;
03757 text_len=strlen(text);
03758 if (whole_rest)
03759 {
03760 (*ptr)=text;
03761 (*ptr_len)=text_len;
03762
03763 text=NULL;
03764 return true;
03765 }
03766
03767
03768
03769
03770 if ((text[0]=='=')||(text[0]=='>')||(text[0]=='<')
03771 ||(text[0]=='|')||(text[0]=='/')||(text[0]=='*')||(text[0]=='!'))
03772 {
03773 len=1;
03774 while (((text[len]=='=')||(text[len]=='>')||(text[len]=='<')||
03775 (text[len]=='|')||(text[len]=='/')||(text[len]=='*'))&&(len<3))
03776 {
03777 len++;
03778 }
03779 } else
03780
03781 if ((text[0]=='\"')||(text[0]=='\''))
03782 {
03783 char quot_chr[2];
03784 quot_chr[0]=text[0];
03785 quot_chr[1]='\0';
03786 len=1;
03787 do {
03788 len=strcspn( text+len, quot_chr );
03789 if (len<text_len) len++;
03790 } while ((len<text_len)&&(text[len-1]=='\\'));
03791 if (len<text_len) len++;
03792 } else
03793
03794 {
03795
03796 int oplen=0;
03797 if (text[0]!='\0')
03798 oplen=strcspn(text+1,"=><|/*\"\'-+!")+1;
03799 if (oplen<len)
03800 len=oplen;
03801 }
03802 (*ptr)=text;
03803 (*ptr_len)=len;
03804 text+=len;
03805 return true;
03806 }
03807
03808 char *script_strword( const char *str, const short whole_rest )
03809 {
03810 const char *ptr;
03811 unsigned int len;
03812 if (!script_strword_pos(&ptr,&len,str,whole_rest))
03813 return NULL;
03814 char *wordtxt;
03815 wordtxt=malloc(len+1);
03816 if (wordtxt==NULL)
03817 {
03818 message_error("script_strword: cannot allocate memory");
03819 return NULL;
03820 }
03821 strncpy(wordtxt,ptr,len);
03822 wordtxt[len]='\0';
03823 return wordtxt;
03824 }
03825
03826
03827
03828
03829 int recognize_script_word_group_and_idx(int *index,const char *wordtxt,const short is_parameter)
03830 {
03831 int cmd_idx;
03832 if (is_parameter)
03833 {
03834 cmd_idx=comp_plyr_cmd_index(wordtxt);
03835 if (cmd_idx>=0)
03836 {
03837 *index=cmd_idx;
03838 return CMD_COMP;
03839 }
03840 cmd_idx=players_cmd_index(wordtxt);
03841 if (cmd_idx>=0)
03842 {
03843 *index=cmd_idx;
03844 return CMD_PLAYER;
03845 }
03846 cmd_idx=operator_cmd_index(wordtxt);
03847 if (cmd_idx>=0)
03848 {
03849 *index=cmd_idx;
03850 return CMD_OPERATR;
03851 }
03852 cmd_idx=objtype_cmd_index(wordtxt);
03853 if (cmd_idx>=0)
03854 {
03855 *index=cmd_idx;
03856 return CMD_OBJTYPE;
03857 }
03858 cmd_idx=variabl_cmd_index(wordtxt);
03859 if (cmd_idx>=0)
03860 {
03861 *index=cmd_idx;
03862 return CMD_VARIBL;
03863 }
03864 cmd_idx=timer_cmd_index(wordtxt);
03865 if (cmd_idx>=0)
03866 {
03867 *index=cmd_idx;
03868 return CMD_TIMER;
03869 }
03870 cmd_idx=flag_cmd_index(wordtxt);
03871 if (cmd_idx>=0)
03872 {
03873 *index=cmd_idx;
03874 return CMD_FLAG;
03875 }
03876 cmd_idx=party_objectv_cmd_index(wordtxt);
03877 if (cmd_idx>=0)
03878 {
03879 *index=cmd_idx;
03880 return CMD_PAROBJ;
03881 }
03882 cmd_idx=creatures_cmd_index(wordtxt);
03883 if (cmd_idx>=0)
03884 {
03885 *index=cmd_idx;
03886 return CMD_CREATR;
03887 }
03888 cmd_idx=door_cmd_index(wordtxt);
03889 if (cmd_idx>=0)
03890 {
03891 *index=cmd_idx;
03892 return CMD_DOOR;
03893 }
03894 cmd_idx=trap_cmd_index(wordtxt);
03895 if (cmd_idx>=0)
03896 {
03897 *index=cmd_idx;
03898 return CMD_TRAP;
03899 }
03900 cmd_idx=spell_cmd_index(wordtxt);
03901 if (cmd_idx>=0)
03902 {
03903 *index=cmd_idx;
03904 return CMD_SPELL;
03905 }
03906 cmd_idx=room_cmd_index(wordtxt);
03907 if (cmd_idx>=0)
03908 {
03909 *index=cmd_idx;
03910 return CMD_ROOM;
03911 }
03912 cmd_idx=special_cmd_index(wordtxt);
03913 if (cmd_idx>=0)
03914 {
03915 *index=cmd_idx;
03916 return CMD_SPECIAL;
03917 }
03918 } else
03919 {
03920 cmd_idx=adikted_cmd_index(wordtxt);
03921 if (cmd_idx>=0)
03922 {
03923 *index=cmd_idx;
03924 return CMD_ADIKTED;
03925 }
03926 cmd_idx=condit_cmd_index(wordtxt);
03927 if (cmd_idx>=0)
03928 {
03929 *index=cmd_idx;
03930 return CMD_CONDIT;
03931 }
03932 cmd_idx=party_cmd_index(wordtxt);
03933 if (cmd_idx>=0)
03934 {
03935 *index=cmd_idx;
03936 return CMD_PARTY;
03937 }
03938 cmd_idx=avail_cmd_index(wordtxt);
03939 if (cmd_idx>=0)
03940 {
03941 *index=cmd_idx;
03942 return CMD_AVAIL;
03943 }
03944 cmd_idx=custobj_cmd_index(wordtxt);
03945 if (cmd_idx>=0)
03946 {
03947 *index=cmd_idx;
03948 return CMD_CUSTOBJ;
03949 }
03950 cmd_idx=setup_cmd_index(wordtxt);
03951 if (cmd_idx>=0)
03952 {
03953 *index=cmd_idx;
03954 return CMD_SETUP;
03955 }
03956 cmd_idx=triger_cmd_index(wordtxt);
03957 if (cmd_idx>=0)
03958 {
03959 *index=cmd_idx;
03960 return CMD_TRIGER;
03961 }
03962 cmd_idx=crtradj_cmd_index(wordtxt);
03963 if (cmd_idx>=0)
03964 {
03965 *index=cmd_idx;
03966 return CMD_CRTRADJ;
03967 }
03968 cmd_idx=obsolt_cmd_index(wordtxt);
03969 if (cmd_idx>=0)
03970 {
03971 *index=cmd_idx;
03972 return CMD_OBSOLT;
03973 }
03974 cmd_idx=commnt_cmd_index(wordtxt);
03975 if (cmd_idx>=0)
03976 {
03977 *index=cmd_idx;
03978 return CMD_COMMNT;
03979 }
03980 }
03981 *index=-1;
03982 return CMD_UNKNOWN;
03983 }
03984
03985 short decompose_script_command(struct DK_SCRIPT_COMMAND *cmd,const char *text,const struct SCRIPT_OPTIONS *optns)
03986 {
03987 if ((cmd==NULL)||(text==NULL)) return false;
03988
03989 char *wordtxt;
03990 cmd->level=get_script_command_level(text,optns);
03991 wordtxt = script_strword(text,false);
03992 int cmd_idx;
03993 cmd->group=recognize_script_word_group_and_idx(&cmd_idx,wordtxt,false);
03994 cmd->index=cmd_idx;
03995 if (cmd->index<0)
03996 {
03997 cmd->group=CMD_UNKNOWN;
03998 message_log(" decompose_script_command: \"%s\" not recognized",wordtxt);
03999 free(wordtxt);
04000 script_command_param_add(cmd,strdup(text));
04001 return false;
04002 }
04003 free(wordtxt);
04004
04005 if (cmd->group==CMD_COMMNT)
04006 {
04007 wordtxt = script_strword(NULL,true);
04008
04009 script_command_param_add(cmd,wordtxt);
04010 } else
04011
04012 {
04013 while (wordtxt != NULL)
04014 {
04015 wordtxt = script_strword(NULL,false);
04016
04017 script_command_param_add(cmd,wordtxt);
04018 }
04019 }
04020 return true;
04021 }
04022
04023
04024
04025
04026
04027 short script_command_param_add(struct DK_SCRIPT_COMMAND *cmd,char *param)
04028 {
04029 if ((cmd==NULL)||(param==NULL)) return false;
04030 int param_idx=cmd->param_count;
04031 cmd->params=realloc(cmd->params,(param_idx+1)*sizeof(char *));
04032 cmd->params[param_idx]=param;
04033 cmd->param_count=param_idx+1;
04034 return true;
04035 }
04036
04037 short is_no_bracket_command(int group,int cmdidx)
04038 {
04039 switch (group)
04040 {
04041 case CMD_CONDIT:
04042 switch (cmdidx)
04043 {
04044 case COND_ENDIF:
04045 return true;
04046 }
04047 return false;
04048 case CMD_PARTY:
04049 return false;
04050 case CMD_AVAIL:
04051 return false;
04052 case CMD_CUSTOBJ:
04053 return false;
04054 case CMD_SETUP:
04055 return false;
04056 case CMD_TRIGER:
04057 switch (cmdidx)
04058 {
04059 case NEXT_CMD_REUSABLE:
04060 case GAME_LOSE:
04061 case GAME_WIN:
04062 return true;
04063 }
04064 return false;
04065 case CMD_CRTRADJ:
04066 return false;
04067 case CMD_COMMNT:
04068 return true;
04069 case CMD_OBSOLT:
04070 return false;
04071
04072 case CMD_ADIKTED:
04073 return false;
04074 case CMD_UNKNOWN:
04075 return true;
04076 default:
04077 return false;
04078 }
04079 }
04080
04081 char *recompose_script_command(const struct DK_SCRIPT_COMMAND *cmd,const struct SCRIPT_OPTIONS *optns)
04082 {
04083 if (cmd==NULL) return strdup("");
04084 const char *cmd_name=script_cmd_text(cmd->group,cmd->index,rem_cmdtext);
04085 int len;
04086 len=(cmd->level*optns->level_spaces)+strlen(cmd_name)+2;
04087 int param_idx;
04088 for (param_idx=0;param_idx<cmd->param_count;param_idx++)
04089 {
04090 len+=strlen(cmd->params[param_idx])+2;
04091 }
04092 len+=2;
04093 char *text=(char *)malloc(len);
04094 if (text==NULL)
04095 {
04096 message_error("recompose_script_command: cannot allocate memory");
04097 return strdup("");
04098 }
04099 text[0]='\0';
04100 if (len<192)
04101 {
04102 int i,k;
04103 for (i=0;i<cmd->level;i++)
04104 {
04105 for (k=0;k<optns->level_spaces;k++)
04106 strcat(text," ");
04107 }
04108 }
04109 strcat(text,cmd_name);
04110 short no_bracket=is_no_bracket_command(cmd->group,cmd->index);
04111 if (no_bracket)
04112 {
04113 if (cmd->param_count>0)
04114 strcat(text," ");
04115 } else
04116 {
04117 strcat(text,"(");
04118 }
04119 int last_param=cmd->param_count-1;
04120 for (param_idx=0;param_idx<last_param;param_idx++)
04121 {
04122 renew_cmd_param(cmd,param_idx,optns);
04123 strcat(text,cmd->params[param_idx]);
04124 if ((param_idx>0)&&(cmd->group==CMD_CONDIT)&&
04125 ((cmd->index==COND_IF)||(cmd->index==IF_AVAILABLE)))
04126 strcat(text," ");
04127 else
04128 strcat(text,",");
04129 }
04130 if (last_param>=0)
04131 {
04132 renew_cmd_param(cmd,last_param,optns);
04133 strcat(text,cmd->params[last_param]);
04134 }
04135 if (!no_bracket)
04136 strcat(text,")");
04137 return text;
04138 }
04139
04140
04141
04142
04143
04144 short renew_cmd_param(const struct DK_SCRIPT_COMMAND *cmd,const unsigned int param_idx,
04145 const struct SCRIPT_OPTIONS *optns)
04146 {
04147 if ((cmd == NULL) || (param_idx >= cmd->param_count))
04148 return false;
04149 char *wordtxt=cmd->params[param_idx];
04150 int par_idx;
04151 int par_group;
04152 par_group=recognize_script_word_group_and_idx(&par_idx,wordtxt,true);
04153 if (par_idx<0)
04154 return false;
04155 const char *nword=script_cmd_text(par_group,par_idx,wordtxt);
04156 wordtxt=strdup(nword);
04157 if (wordtxt==NULL)
04158 return false;
04159 free(cmd->params[param_idx]);
04160 cmd->params[param_idx]=wordtxt;
04161 }
04162
04163 const char *script_cmd_text(const int group,const int cmdidx,const char *prev_val)
04164 {
04165 switch (group)
04166 {
04167
04168 case CMD_COMP:
04169 return comp_plyr_cmd_text(cmdidx);
04170 case CMD_PLAYER:
04171 return players_cmd_text(cmdidx);
04172 case CMD_OPERATR:
04173 return operator_cmd_text(cmdidx);
04174 case CMD_OBJTYPE:
04175 return objtype_cmd_text(cmdidx);
04176 case CMD_VARIBL:
04177 return variabl_cmd_text(cmdidx);
04178 case CMD_TIMER:
04179 return timer_cmd_text(cmdidx);
04180 case CMD_FLAG:
04181 return flag_cmd_text(cmdidx);
04182 case CMD_PAROBJ:
04183 return party_objectv_cmd_text(cmdidx);
04184 case CMD_CREATR:
04185 return creatures_cmd_text(cmdidx);
04186 case CMD_DOOR:
04187 return door_cmd_text(cmdidx);
04188 case CMD_TRAP:
04189 return trap_cmd_text(cmdidx);
04190 case CMD_SPELL:
04191 return spell_cmd_text(cmdidx);
04192 case CMD_ROOM:
04193 return room_cmd_text(cmdidx);
04194 case CMD_SPECIAL:
04195 return special_cmd_text(cmdidx,prev_val);
04196
04197 case CMD_CONDIT:
04198 return condit_cmd_text(cmdidx);
04199 case CMD_PARTY:
04200 return party_cmd_text(cmdidx);
04201 case CMD_AVAIL:
04202 return avail_cmd_text(cmdidx);
04203 case CMD_CUSTOBJ:
04204 return custobj_cmd_text(cmdidx);
04205 case CMD_SETUP:
04206 return setup_cmd_text(cmdidx);
04207 case CMD_TRIGER:
04208 return triger_cmd_text(cmdidx);
04209 case CMD_CRTRADJ:
04210 return crtradj_cmd_text(cmdidx);
04211 case CMD_COMMNT:
04212 return commnt_cmd_text(cmdidx);
04213 case CMD_OBSOLT:
04214 return obsolt_cmd_text(cmdidx);
04215
04216 case CMD_ADIKTED:
04217 return adikted_cmd_text(cmdidx);
04218 case CMD_UNKNOWN:
04219 default:
04220 return prev_val;
04221 }
04222 }
04223
04224 int adikted_cmd_arrsize()
04225 {
04226 return sizeof(cmd_adikted_arr)/sizeof(char *);
04227 }
04228
04229 int adikted_cmd_index(const char *cmdtext)
04230 {
04231 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04232 int i=0;
04233 int array_count=sizeof(cmd_adikted_arr)/sizeof(char *);
04234 while (i<array_count)
04235 {
04236 if (stricmp(cmd_adikted_arr[i],cmdtext)==0)
04237 return i;
04238 i++;
04239 }
04240 return -1;
04241 }
04242
04243 const char *adikted_cmd_text(int cmdidx)
04244 {
04245 int array_count=sizeof(cmd_adikted_arr)/sizeof(char *);
04246 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04247 return cmd_adikted_arr[cmdidx];
04248 }
04249
04250 int condit_cmd_arrsize()
04251 {
04252 return sizeof(cmd_condit_arr)/sizeof(char *);
04253 }
04254
04255 int condit_cmd_index(const char *cmdtext)
04256 {
04257 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04258 int i=0;
04259 int array_count=sizeof(cmd_condit_arr)/sizeof(char *);
04260 while (i<array_count)
04261 {
04262 if (stricmp(cmd_condit_arr[i],cmdtext)==0)
04263 return i;
04264 i++;
04265 }
04266 return -1;
04267 }
04268
04269 const char *condit_cmd_text(int cmdidx)
04270 {
04271 int array_count=sizeof(cmd_condit_arr)/sizeof(char *);
04272 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04273 return cmd_condit_arr[cmdidx];
04274 }
04275
04276 int flag_cmd_arrsize()
04277 {
04278 return sizeof(cmd_flag_arr)/sizeof(char *);
04279 }
04280
04281 int flag_cmd_index(const char *cmdtext)
04282 {
04283 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04284 int i=0;
04285 int array_count=sizeof(cmd_flag_arr)/sizeof(char *);
04286 while (i<array_count)
04287 {
04288 if (stricmp(cmd_flag_arr[i],cmdtext)==0)
04289 return i;
04290 i++;
04291 }
04292 return -1;
04293 }
04294
04295 const char *flag_cmd_text(int cmdidx)
04296 {
04297 int array_count=sizeof(cmd_flag_arr)/sizeof(char *);
04298 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04299 return cmd_flag_arr[cmdidx];
04300 }
04301
04302 int party_objectv_cmd_arrsize()
04303 {
04304 return sizeof(cmd_party_objectv_arr)/sizeof(char *);
04305 }
04306
04307 int party_objectv_cmd_index(const char *cmdtext)
04308 {
04309 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04310 int i=0;
04311 int array_count=sizeof(cmd_party_objectv_arr)/sizeof(char *);
04312 while (i<array_count)
04313 {
04314 if (stricmp(cmd_party_objectv_arr[i],cmdtext)==0)
04315 return i;
04316 i++;
04317 }
04318 return -1;
04319 }
04320
04321 const char *party_objectv_cmd_text(int cmdidx)
04322 {
04323 int array_count=sizeof(cmd_party_objectv_arr)/sizeof(char *);
04324 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04325 return cmd_party_objectv_arr[cmdidx];
04326 }
04327
04328 int party_cmd_arrsize()
04329 {
04330 return sizeof(cmd_party_arr)/sizeof(char *);
04331 }
04332
04333 int party_cmd_index(const char *cmdtext)
04334 {
04335 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04336 int i=0;
04337 int array_count=sizeof(cmd_party_arr)/sizeof(char *);
04338 while (i<array_count)
04339 {
04340 if (stricmp(cmd_party_arr[i],cmdtext)==0)
04341 return i;
04342 i++;
04343 }
04344 return -1;
04345 }
04346
04347 const char *party_cmd_text(int cmdidx)
04348 {
04349 int array_count=sizeof(cmd_party_arr)/sizeof(char *);
04350 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04351 return cmd_party_arr[cmdidx];
04352 }
04353
04354 int avail_cmd_arrsize()
04355 {
04356 return sizeof(cmd_avail_arr)/sizeof(char *);
04357 }
04358
04359 int avail_cmd_index(const char *cmdtext)
04360 {
04361 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04362 int i=0;
04363 int array_count=sizeof(cmd_avail_arr)/sizeof(char *);
04364 while (i<array_count)
04365 {
04366 if (stricmp(cmd_avail_arr[i],cmdtext)==0)
04367 return i;
04368 i++;
04369 }
04370 return -1;
04371 }
04372
04373 const char *avail_cmd_text(int cmdidx)
04374 {
04375 int array_count=sizeof(cmd_avail_arr)/sizeof(char *);
04376 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04377 return cmd_avail_arr[cmdidx];
04378 }
04379
04380 int comp_plyr_cmd_arrsize()
04381 {
04382 return sizeof(cmd_comp_plyr_arr)/sizeof(char *);
04383 }
04384
04385 int comp_plyr_cmd_index(const char *cmdtext)
04386 {
04387 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04388 int i=0;
04389 int array_count=sizeof(cmd_comp_plyr_arr)/sizeof(char *);
04390 while (i<array_count)
04391 {
04392 if (stricmp(cmd_comp_plyr_arr[i],cmdtext)==0)
04393 return i;
04394 i++;
04395 }
04396 return -1;
04397 }
04398
04399 const char *comp_plyr_cmd_text(int cmdidx)
04400 {
04401 int array_count=sizeof(cmd_comp_plyr_arr)/sizeof(char *);
04402 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04403 return cmd_comp_plyr_arr[cmdidx];
04404 }
04405
04406 int players_cmd_arrsize()
04407 {
04408 return sizeof(cmd_players_arr)/sizeof(char *);
04409 }
04410
04411 int players_cmd_index(const char *cmdtext)
04412 {
04413 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04414 int i=0;
04415 int array_count=sizeof(cmd_players_arr)/sizeof(char *);
04416 while (i<array_count)
04417 {
04418 if (stricmp(cmd_players_arr[i],cmdtext)==0)
04419 return i;
04420 i++;
04421 }
04422 return -1;
04423 }
04424
04425 const char *players_cmd_text(int cmdidx)
04426 {
04427 int array_count=sizeof(cmd_players_arr)/sizeof(char *);
04428 if ((cmdidx<0)||(cmdidx>=array_count)) return "X";
04429 return cmd_players_arr[cmdidx];
04430 }
04431
04432 int creatures_cmd_arrsize()
04433 {
04434 return sizeof(cmd_creatures_arr)/sizeof(char *);
04435 }
04436
04437 int creatures_cmd_index(const char *cmdtext)
04438 {
04439 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04440 int i=0;
04441 int array_count=sizeof(cmd_creatures_arr)/sizeof(char *);
04442 while (i<array_count)
04443 {
04444 if (stricmp(cmd_creatures_arr[i],cmdtext)==0)
04445 return i;
04446 i++;
04447 }
04448 return -1;
04449 }
04450
04451 const char *creatures_cmd_text(int cmdidx)
04452 {
04453 int array_count=sizeof(cmd_creatures_arr)/sizeof(char *);
04454 if ((cmdidx<0)||(cmdidx>=array_count)) return "X";
04455 return cmd_creatures_arr[cmdidx];
04456 }
04457
04458 int room_cmd_arrsize()
04459 {
04460 return sizeof(cmd_rooms_arr)/sizeof(char *);
04461 }
04462
04463 int room_cmd_index(const char *cmdtext)
04464 {
04465 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04466 int i=0;
04467 int array_count=sizeof(cmd_rooms_arr)/sizeof(char *);
04468 while (i<array_count)
04469 {
04470 if (stricmp(cmd_rooms_arr[i],cmdtext)==0)
04471 return i;
04472 i++;
04473 }
04474 return -1;
04475 }
04476
04477 const char *room_cmd_text(int cmdidx)
04478 {
04479 int array_count=sizeof(cmd_rooms_arr)/sizeof(char *);
04480 if ((cmdidx<0)||(cmdidx>=array_count)) return "X";
04481 return cmd_rooms_arr[cmdidx];
04482 }
04483
04484 int spell_cmd_arrsize()
04485 {
04486 return sizeof(cmd_spells_arr)/sizeof(char *);
04487 }
04488
04489 int spell_cmd_index(const char *cmdtext)
04490 {
04491 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04492 int i=0;
04493 int array_count=sizeof(cmd_spells_arr)/sizeof(char *);
04494 while (i<array_count)
04495 {
04496 if (stricmp(cmd_spells_arr[i],cmdtext)==0)
04497 return i;
04498 i++;
04499 }
04500 return -1;
04501 }
04502
04503 const char *spell_cmd_text(int cmdidx)
04504 {
04505 int array_count=sizeof(cmd_spells_arr)/sizeof(char *);
04506 if ((cmdidx<0)||(cmdidx>=array_count)) return "X";
04507 return cmd_spells_arr[cmdidx];
04508 }
04509
04510 const char *spell_cmd_fullname(int cmdidx)
04511 {
04512 int array_count=sizeof(cmd_spells_fullname)/sizeof(char *);
04513 if ((cmdidx<0)||(cmdidx>=array_count)) return "BAD";
04514 return cmd_spells_fullname[cmdidx];
04515 }
04516
04517 int trap_cmd_arrsize()
04518 {
04519 return sizeof(cmd_traps_arr)/sizeof(char *);
04520 }
04521
04522 int trap_cmd_index(const char *cmdtext)
04523 {
04524 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04525 int i=0;
04526 int array_count=sizeof(cmd_traps_arr)/sizeof(char *);
04527 while (i<array_count)
04528 {
04529 if (stricmp(cmd_traps_arr[i],cmdtext)==0)
04530 return i;
04531 i++;
04532 }
04533 return -1;
04534 }
04535
04536 const char *trap_cmd_text(int cmdidx)
04537 {
04538 int array_count=sizeof(cmd_traps_arr)/sizeof(char *);
04539 if ((cmdidx<0)||(cmdidx>=array_count)) return "X";
04540 return cmd_traps_arr[cmdidx];
04541 }
04542
04543 const char *trap_cmd_fullname(int cmdidx)
04544 {
04545 int array_count=sizeof(cmd_traps_fullname)/sizeof(char *);
04546 if ((cmdidx<0)||(cmdidx>=array_count)) return "BAD";
04547 return cmd_traps_fullname[cmdidx];
04548 }
04549
04550 int door_cmd_arrsize()
04551 {
04552 return sizeof(cmd_doors_arr)/sizeof(char *);
04553 }
04554
04555 int door_cmd_index(const char *cmdtext)
04556 {
04557 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04558 int i=0;
04559 int array_count=sizeof(cmd_doors_arr)/sizeof(char *);
04560 while (i<array_count)
04561 {
04562 if (stricmp(cmd_doors_arr[i],cmdtext)==0)
04563 return i;
04564 i++;
04565 }
04566 return -1;
04567 }
04568
04569 const char *door_cmd_text(int cmdidx)
04570 {
04571 int array_count=sizeof(cmd_doors_arr)/sizeof(char *);
04572 if ((cmdidx<0)||(cmdidx>=array_count)) return "X";
04573 return cmd_doors_arr[cmdidx];
04574 }
04575
04576 const char *door_cmd_fullname(int cmdidx)
04577 {
04578 int array_count=sizeof(cmd_doors_fullname)/sizeof(char *);
04579 if ((cmdidx<0)||(cmdidx>=array_count)) return "BAD";
04580 return cmd_doors_fullname[cmdidx];
04581 }
04582
04583 int special_cmd_arrsize()
04584 {
04585 return 2;
04586 }
04587
04588 int special_cmd_index(const char *cmdtext)
04589 {
04590 if ((cmdtext==NULL)||(strlen(cmdtext)<1)) return -1;
04591 if (stricmp(random_cmdtext,cmdtext)==0)
04592 return SPEC_RANDOM;
04593 int val;
04594 if (script_param_to_int(&val,cmdtext))
04595 return SPEC_NUMBER;
04596 return -1;
04597 }
04598
04599 const char *special_cmd_text(int cmdidx,const char *cmdtext)
04600 {
04601 switch (cmdidx)
04602 {
04603 case SPEC_RANDOM:
04604 return random_cmdtext;
04605 case SPEC_NUMBER:
04606 default:
04607 return cmdtext;
04608 }
04609 }
04610
04611 int operator_cmd_arrsize()
04612 {
04613 return sizeof(cmd_operator_arr)/sizeof(char *);
04614 }
04615
04616 int operator_cmd_index(const char *cmdtext)
04617 {
04618 if ((cmdtext==NULL)||(strlen(cmdtext)<1)) return -1;
04619 int i=0;
04620 int array_count=sizeof(cmd_operator_arr)/sizeof(char *);
04621 while (i<array_count)
04622 {
04623 if (stricmp(cmd_operator_arr[i],cmdtext)==0)
04624 return i;
04625 i++;
04626 }
04627 return -1;
04628 }
04629
04630 const char *operator_cmd_text(int cmdidx)
04631 {
04632 int array_count=sizeof(cmd_operator_arr)/sizeof(char *);
04633 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04634 return cmd_operator_arr[cmdidx];
04635 }
04636
04637 int objtype_cmd_arrsize()
04638 {
04639 return sizeof(cmd_objtype_arr)/sizeof(char *);
04640 }
04641
04642 int objtype_cmd_index(const char *cmdtext)
04643 {
04644 if ((cmdtext==NULL)||(strlen(cmdtext)<1)) return -1;
04645 int i=0;
04646 int array_count=sizeof(cmd_objtype_arr)/sizeof(char *);
04647 while (i<array_count)
04648 {
04649 if (stricmp(cmd_objtype_arr[i],cmdtext)==0)
04650 return i;
04651 i++;
04652 }
04653 return -1;
04654 }
04655
04656 const char *objtype_cmd_text(int cmdidx)
04657 {
04658 int array_count=sizeof(cmd_objtype_arr)/sizeof(char *);
04659 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04660 return cmd_objtype_arr[cmdidx];
04661 }
04662
04663 int variabl_cmd_arrsize()
04664 {
04665 return sizeof(cmd_variabl_arr)/sizeof(char *);
04666 }
04667
04668 int variabl_cmd_index(const char *cmdtext)
04669 {
04670 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04671 int i=0;
04672 int array_count=sizeof(cmd_variabl_arr)/sizeof(char *);
04673 while (i<array_count)
04674 {
04675 if (stricmp(cmd_variabl_arr[i],cmdtext)==0)
04676 return i;
04677 i++;
04678 }
04679 return -1;
04680 }
04681
04682 const char *variabl_cmd_text(int cmdidx)
04683 {
04684 int array_count=sizeof(cmd_variabl_arr)/sizeof(char *);
04685 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04686 return cmd_variabl_arr[cmdidx];
04687 }
04688
04689 int timer_cmd_arrsize()
04690 {
04691 return sizeof(cmd_timer_arr)/sizeof(char *);
04692 }
04693
04694 int timer_cmd_index(const char *cmdtext)
04695 {
04696 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04697 int i=0;
04698 int array_count=sizeof(cmd_timer_arr)/sizeof(char *);
04699 while (i<array_count)
04700 {
04701 if (stricmp(cmd_timer_arr[i],cmdtext)==0)
04702 return i;
04703 i++;
04704 }
04705 return -1;
04706 }
04707
04708 const char *timer_cmd_text(int cmdidx)
04709 {
04710 int array_count=sizeof(cmd_timer_arr)/sizeof(char *);
04711 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04712 return cmd_timer_arr[cmdidx];
04713 }
04714
04715 int custobj_cmd_arrsize()
04716 {
04717 return sizeof(cmd_custobj_arr)/sizeof(char *);
04718 }
04719
04720 int custobj_cmd_index(const char *cmdtext)
04721 {
04722 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04723 int i=0;
04724 int array_count=sizeof(cmd_custobj_arr)/sizeof(char *);
04725 while (i<array_count)
04726 {
04727 if (stricmp(cmd_custobj_arr[i],cmdtext)==0)
04728 return i;
04729 i++;
04730 }
04731 return -1;
04732 }
04733
04734 const char *custobj_cmd_text(int cmdidx)
04735 {
04736 int array_count=sizeof(cmd_custobj_arr)/sizeof(char *);
04737 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04738 return cmd_custobj_arr[cmdidx];
04739 }
04740
04741 int setup_cmd_arrsize()
04742 {
04743 return sizeof(cmd_setup_arr)/sizeof(char *);
04744 }
04745
04746 int setup_cmd_index(const char *cmdtext)
04747 {
04748 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04749 int i=0;
04750 int array_count=sizeof(cmd_setup_arr)/sizeof(char *);
04751 while (i<array_count)
04752 {
04753 if (stricmp(cmd_setup_arr[i],cmdtext)==0)
04754 return i;
04755 i++;
04756 }
04757 return -1;
04758 }
04759
04760 const char *setup_cmd_text(int cmdidx)
04761 {
04762 int array_count=sizeof(cmd_setup_arr)/sizeof(char *);
04763 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04764 return cmd_setup_arr[cmdidx];
04765 }
04766
04767 int triger_cmd_arrsize()
04768 {
04769 return sizeof(cmd_triger_arr)/sizeof(char *);
04770 }
04771
04772 int triger_cmd_index(const char *cmdtext)
04773 {
04774 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04775 int i=0;
04776 int array_count=sizeof(cmd_triger_arr)/sizeof(char *);
04777 while (i<array_count)
04778 {
04779 if (stricmp(cmd_triger_arr[i],cmdtext)==0)
04780 return i;
04781 i++;
04782 }
04783 return -1;
04784 }
04785
04786 const char *triger_cmd_text(int cmdidx)
04787 {
04788 int array_count=sizeof(cmd_triger_arr)/sizeof(char *);
04789 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04790 return cmd_triger_arr[cmdidx];
04791 }
04792
04793 int crtradj_cmd_arrsize()
04794 {
04795 return sizeof(cmd_crtradj_arr)/sizeof(char *);
04796 }
04797
04798 int crtradj_cmd_index(const char *cmdtext)
04799 {
04800 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04801 int i=0;
04802 int array_count=sizeof(cmd_crtradj_arr)/sizeof(char *);
04803 while (i<array_count)
04804 {
04805 if (stricmp(cmd_crtradj_arr[i],cmdtext)==0)
04806 return i;
04807 i++;
04808 }
04809 return -1;
04810 }
04811
04812 const char *crtradj_cmd_text(int cmdidx)
04813 {
04814 int array_count=sizeof(cmd_crtradj_arr)/sizeof(char *);
04815 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04816 return cmd_crtradj_arr[cmdidx];
04817 }
04818
04819 int obsolt_cmd_arrsize()
04820 {
04821 return sizeof(cmd_obsolt_arr)/sizeof(char *);
04822 }
04823
04824 int obsolt_cmd_index(const char *cmdtext)
04825 {
04826 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04827 int i=0;
04828 int array_count=sizeof(cmd_obsolt_arr)/sizeof(char *);
04829 while (i<array_count)
04830 {
04831 if (stricmp(cmd_obsolt_arr[i],cmdtext)==0)
04832 return i;
04833 i++;
04834 }
04835 return -1;
04836 }
04837
04838 const char *obsolt_cmd_text(int cmdidx)
04839 {
04840 int array_count=sizeof(cmd_obsolt_arr)/sizeof(char *);
04841 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04842 return cmd_obsolt_arr[cmdidx];
04843 }
04844
04845 int commnt_cmd_arrsize()
04846 {
04847 return sizeof(cmd_commnt_arr)/sizeof(char *);
04848 }
04849
04850 int commnt_cmd_index(const char *cmdtext)
04851 {
04852 if (cmdtext==NULL) return EMPTYLN;
04853 if (strlen(cmdtext)<1) return EMPTYLN;
04854 int i=0;
04855 int array_count=sizeof(cmd_commnt_arr)/sizeof(char *);
04856 while (i<array_count)
04857 {
04858 if (stricmp(cmd_commnt_arr[i],cmdtext)==0)
04859 return i;
04860 i++;
04861 }
04862 return -1;
04863 }
04864
04865 const char *commnt_cmd_text(int cmdidx)
04866 {
04867 int array_count=sizeof(cmd_commnt_arr)/sizeof(char *);
04868 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04869 return cmd_commnt_arr[cmdidx];
04870 }
04871
04872 int orient_cmd_arrsize()
04873 {
04874 return sizeof(cmd_orient_arr)/sizeof(char *);
04875 }
04876
04877 int orient_cmd_index(const char *cmdtext)
04878 {
04879 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04880 int i=0;
04881 int array_count=sizeof(cmd_orient_arr)/sizeof(char *);
04882 while (i<array_count)
04883 {
04884 if (stricmp(cmd_orient_arr[i],cmdtext)==0)
04885 return i;
04886 i++;
04887 }
04888 return -1;
04889 }
04890
04891 const char *orient_cmd_text(int cmdidx)
04892 {
04893 int array_count=sizeof(cmd_orient_arr)/sizeof(char *);
04894 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04895 return cmd_orient_arr[cmdidx];
04896 }
04897
04898 int font_cmd_arrsize()
04899 {
04900 return sizeof(cmd_font_arr)/sizeof(char *);
04901 }
04902
04903 int font_cmd_index(const char *cmdtext)
04904 {
04905 if ((cmdtext==NULL)||(strlen(cmdtext)<2)) return -1;
04906 int i=0;
04907 int array_count=sizeof(cmd_font_arr)/sizeof(char *);
04908 while (i<array_count)
04909 {
04910 if (stricmp(cmd_font_arr[i],cmdtext)==0)
04911 return i;
04912 i++;
04913 }
04914 return -1;
04915 }
04916
04917 const char *font_cmd_text(int cmdidx)
04918 {
04919 int array_count=sizeof(cmd_font_arr)/sizeof(char *);
04920 if ((cmdidx<0)||(cmdidx>=array_count)) return rem_cmdtext;
04921 return cmd_font_arr[cmdidx];
04922 }
04923
04924
04925
04926
04927 struct DK_SCRIPT_COMMAND *script_command_create(void)
04928 {
04929 struct DK_SCRIPT_COMMAND *cmd=(struct DK_SCRIPT_COMMAND *)malloc(sizeof(struct DK_SCRIPT_COMMAND));
04930 script_command_clear(cmd);
04931 return cmd;
04932 }
04933
04934
04935
04936
04937 void script_command_clear(struct DK_SCRIPT_COMMAND *cmd)
04938 {
04939 cmd->group=CMD_UNKNOWN;
04940 cmd->index=-1;
04941 cmd->params=NULL;
04942 cmd->param_count=0;
04943 }
04944
04945
04946
04947
04948 void script_command_free(struct DK_SCRIPT_COMMAND *cmd)
04949 {
04950 int i;
04951 for (i=cmd->param_count-1;i>=0;i--)
04952 free(cmd->params[i]);
04953 free(cmd);
04954 }
04955
04956
04957
04958
04959
04960
04961 void script_command_renew(struct DK_SCRIPT_COMMAND **cmd)
04962 {
04963 if ((*cmd)==NULL)
04964 {
04965 (*cmd)=script_command_create();
04966 return;
04967 }
04968 int i;
04969 for (i=(*cmd)->param_count-1;i>=0;i--)
04970 free((*cmd)->params[i]);
04971 script_command_clear(*cmd);
04972 }
04973
04974
04975
04976
04977 void text_file_free(char **lines,int lines_count)
04978 {
04979 int i;
04980 for (i=lines_count-1;i>=0;i--)
04981 free(lines[i]);
04982 free(lines);
04983 }
04984
04985
04986
04987
04988
04989 int text_file_line_add(char ***lines,int *lines_count,char *text)
04990 {
04991 int line_idx=*lines_count;
04992 *lines=realloc(*lines,(line_idx+1)*sizeof(char *));
04993 if ((*lines)==NULL)
04994 {
04995 message_error("Cannot allocate text file lines");
04996 return -1;
04997 }
04998 (*lines)[line_idx]=text;
04999 (*lines_count)++;
05000 return line_idx;
05001 }
05002
05003
05004
05005
05006
05007 int text_file_linecp_add(char ***lines,int *lines_count,char *text)
05008 {
05009 int line_idx=*lines_count;
05010 *lines=realloc(*lines,(line_idx+1)*sizeof(char *));
05011 if ((*lines)==NULL)
05012 {
05013 message_error("Cannot allocate text file lines");
05014 return -1;
05015 }
05016 (*lines)[line_idx]=strdup(text);
05017 (*lines_count)++;
05018 return line_idx;
05019 }
05020
05021 short add_stats_to_script(char ***lines,int *lines_count,struct LEVEL *lvl)
05022 {
05023 char *line;
05024 char *tmp;
05025 char *tmp2;
05026 char *tmp3;
05027 long max_len=LINEMSG_SIZE;
05028
05029 if (lvl->info.desc_text!=NULL)
05030 max_len=max(max_len,strlen(lvl->info.desc_text)+(LINEMSG_SIZE>>1));
05031 if ((lvl->info.author_text!=NULL)&&(lvl->info.editor_text!=NULL))
05032 max_len=max(max_len,strlen(lvl->info.author_text)+strlen(lvl->info.editor_text)+(LINEMSG_SIZE>>1));
05033 line=(char *)malloc(max_len*sizeof(char));
05034 tmp=(char *)malloc(max_len*sizeof(char));
05035 unsigned long curr_time=time(NULL);
05036
05037 tmp2=prepare_short_fname(lvl->savfname,24);
05038 sprintf(line,"%s %s script file for %s",rem_cmdtext,PROGRAM_NAME,tmp2);
05039 free(tmp2);
05040 text_file_linecp_add(lines,lines_count,line);
05041 strftime(tmp,LINEMSG_SIZE/2, "%d %b %Y, %H:%M:%S", localtime(&curr_time) );
05042 sprintf(line,"%s %s %s",rem_cmdtext,"Automatically generated on",tmp);
05043 text_file_linecp_add(lines,lines_count,line);
05044 text_file_linecp_add(lines,lines_count,"");
05045
05046 sprintf(line,"%s(%d,%d,%d)",levversion_cmdtext,lvl->info.ver_major,
05047 lvl->info.ver_minor,lvl->info.ver_rel);
05048 text_file_linecp_add(lines,lines_count,line);
05049
05050 sprintf(line,"%s(%lu,%lu)",leveltimestmp_cmdtext,lvl->info.creat_date,curr_time);
05051 text_file_linecp_add(lines,lines_count,line);
05052
05053 sprintf(line,"%s(%lu,%lu,%lu,%lu)",usrcmnds_count_cmdtext,lvl->info.usr_cmds_count,
05054 lvl->info.usr_mdswtch_count,lvl->info.usr_slbchng_count,lvl->info.usr_creatobj_count);
05055 text_file_linecp_add(lines,lines_count,line);
05056
05057
05058
05059
05060
05061
05062 tmp2=lvl->info.desc_text;
05063 if (tmp2==NULL) tmp2="";
05064 sprintf(line,"%s(\"%s\")",adikted_cmd_text(LEVEL_DESC),tmp2);
05065 text_file_linecp_add(lines,lines_count,line);
05066
05067 tmp2=lvl->info.author_text;
05068 if (tmp2==NULL) tmp2="";
05069 tmp3=lvl->info.editor_text;
05070 if (tmp3==NULL) tmp3="";
05071 sprintf(line,"%s(\"%s\",\"%s\")",adikted_cmd_text(LEVEL_AUTHORS),tmp2,tmp3);
05072 text_file_linecp_add(lines,lines_count,line);
05073 free(tmp);
05074 free(line);
05075 return true;
05076 }
05077
05078 short add_graffiti_to_script(char ***lines,int *lines_count,struct LEVEL *lvl)
05079 {
05080 int i,k;
05081 struct DK_GRAFFITI *graf;
05082 char *line;
05083 line=(char *)malloc(LINEMSG_SIZE*sizeof(char));
05084 char *graftxt;
05085 graftxt=(char *)malloc(LINEMSG_SIZE*sizeof(char));
05086 for (i=0; i < lvl->graffiti_count; i++)
05087 {
05088 graf = lvl->graffiti[i];
05089 if (graf==NULL) continue;
05090 int graf_len=strlen(graf->text);
05091 for (k=0;k<graf_len;k++)
05092 {
05093 char c=graf->text[k];
05094 if (c<=32) graftxt[k]='_'; else
05095 if (c==',') graftxt[k]='.'; else
05096 if (c=='(') graftxt[k]='{'; else
05097 if (c==')') graftxt[k]='}'; else
05098 graftxt[k]=c;
05099 }
05100 graftxt[graf_len]='\0';
05101 sprintf(line,"%s(%d,%d,%d,%s,%s,0x%03x,%s)",graffiti_cmdtext,graf->tile.x,graf->tile.y,graf->height,
05102 orient_cmd_text(graf->orient),font_cmd_text(graf->font),graf->cube,graftxt);
05103 text_file_linecp_add(lines,lines_count,line);
05104 }
05105 free(line);
05106 free(graftxt);
05107 return true;
05108 }
05109
05110 short add_custom_clms_to_script(char ***lines,int *lines_count,struct LEVEL *lvl)
05111 {
05112 int sx,sy;
05113 char *line;
05114 line=(char *)malloc(LINEMSG_SIZE*sizeof(char));
05115 for (sy=0; sy < lvl->subsize.y; sy++)
05116 for (sx=0; sx < lvl->subsize.x; sx++)
05117 {
05118 struct DK_CUSTOM_CLM *cclm;
05119 struct COLUMN_REC *clm_rec;
05120 cclm=get_cust_col(lvl,sx,sy);
05121 if (cclm!=NULL)
05122 clm_rec = cclm->rec;
05123 else
05124 clm_rec = NULL;
05125 if (clm_rec!=NULL)
05126 {
05127 sprintf(line,"%s(%d,%d,%d,%d,%d,0x%03x,0x%03x,0x%03x,0x%03x,0x%03x,0x%03x,0x%03x,0x%03x,0x%03x)",
05128 custom_column_cmdtext,sx,sy,
05129 cclm->wib_val,clm_rec->lintel,clm_rec->orientation,clm_rec->base,
05130 clm_rec->c[0],clm_rec->c[1],clm_rec->c[2],clm_rec->c[3],
05131 clm_rec->c[4],clm_rec->c[5],clm_rec->c[6],clm_rec->c[7]);
05132 text_file_linecp_add(lines,lines_count,line);
05133 }
05134 }
05135 free(line);
05136 return true;
05137 }
05138
05139
05140
05141
05142 char *get_orientation_shortname(unsigned short orient)
05143 {
05144 int types_count=sizeof(cmd_orient_shortnames)/sizeof(char *);
05145 if (orient<types_count)
05146 return (char *)cmd_orient_shortnames[orient];
05147 else
05148 return "unkn";
05149 }
05150
05156 unsigned short get_orientation_next(unsigned short orient)
05157 {
05158 int array_count=sizeof(orient_constants)/sizeof(unsigned short);
05159
05160 int idx=arr_ushort_pos(orient_constants,orient,array_count);
05161 if ((idx<0)||(idx+1>=array_count))
05162 idx=0;
05163 else
05164 idx++;
05165 return orient_constants[idx];
05166 }
05167
05173 char *get_font_longname(unsigned short font)
05174 {
05175 int types_count=sizeof(cmd_font_fullnames)/sizeof(char *);
05176 if (font<types_count)
05177 return (char *)cmd_font_fullnames[font];
05178 else
05179 return "unkn";
05180 }