Files
oboe/osx/boe.townspec.cpp
Celtic Minstrel c413d292a9 Tear out most of the legacy code in the game - see below for details
(PC Editor and Scenario Editor are unaffected by this commit.)

Things removed:
- All references to Carbon and QuickDraw are gone.
- No more Resource Manager; the game no longer relies on old resource files at all
- The old dialog framework (from dlogtool.c, functions usually prefixed with cd_) is no longer used.
- Files that weren't being compiled
- Boost libraries that are now in the C++ library (function, shared_ptr)
- Obsolete build settings

Replacement dependencies:
- Boost Filesystem replaces references to things like FSSpec
- SFML replaces all the QuickDraw code and most window management
- Cocoa replaces AppleEvent management, menu management, and some window management
- I wrote a resource manager interface to mimick the important aspects of the behaviour of the Mac Resource Manager
- I had to rewrite some functions that QuickDraw provided natively, such as clipping regions; not all of these are tested

Things added:
- Every referenced dialog has been converted from a DITL resource into the new XML-based dialog format.
- All referenced STR# resources have been extracted into simple text files
- Now compiles against Mac OSX 10.7 SDK and libc++
- The first item in the Help menu opens the docs on Sylae's website
- It seems all the constants for soundtool vanished somewhere, so I added them back from the original Mac source

Other changes:
- Updated to XCode 4(?) project format
- Added the xcschemes created by XCode 4; I'm not sure how important these are, but they seem like they might be important
- Added document on converting dialogs to the XML format.
- Make string formatting mismatches into errors instead of warnings
- Disable error limit
- Graphics sheets that previously used masking now have alpha transparency
- Converted all graphics sheets to 8-bit PNG
- Trimmed white border from intro image
- Converted dialogs in the resource file have their resource name set to the name of the XML file of the converted version
- Referenced string resources in the resource file have their resource name set to the name of the text file of the extracted version
- Add the black-and-white patterns from the PAT resources to the pixpats.png; at least one of them is used somewhere in the game
- Recreated the menu.xib as a Cocoa xib file instead of a Carbon xib file
- Disable GNU C++ extensions; maybe this'll make it easier to compile with cl.exe later
- Add marks to the enormous handle_action function to make it easier to navigate\
- A build step to validate the XML dialogs using xmllint (doesn't quite work properly yet but does at least catch dialogs that are not well-formed)- Fix a lot of warnings about assigning string constants to non-const char pointers
- Fixed the file and application icons (which had somehow become corrupted at some point)
- Lots of additional functions in the custom location and rectangle classes, including implicit conversion to and from SFML rects and vectors; also they now store coordinates as int instead of char
- A new enum for encounter note types
- Much tweaking of the encounter note recording mechanisms
- To ease porting, I added a simple function that converts from classic Mac ticks (about 1/60 of a second) to the SFML time type
- Python script to convert STR# resources to txt files, replacing newlines with vertical bars
- Extracted the Mac font (Dungeon Bold) from the resource file and also added the Windows font (MaidenWord)

XML Dialog Framework changes:
- Remove the static initialization object in favour of manually calling cDialog::init()
- {set,get}Format() no longer used for colour; there's a dedicated {set,get}Colour() instead
- draw() methods unprotected in the control classes so that controls can be drawn in the main window
- There's no longer a friend relationship between the dialogs and the controls
- Fixed buttons duplicating the "depressed" boolean
- Buttons now properly offset the label for tiny and push buttons, and for LEDs
- Buttons no longer assume that either none or both of "width" and "height" are given in the XML
- Add {get,set}BtnType() to cButton
- cLedGroup now overrides handleClick(), which has also been made virtual; this was necessary for LEDs within a group to properly hilite while being clicked
- Add addChoice() to cLedGroup to insert additional LED choices
- Moved the key enums and cKey to a separate file
- Add a method to get a control's attached key
- Add methods to get and set a control's rect and position
- Controls can now directly take a window as a parent rather than a dialog
- Add addLabelFor() method to cDialog which adds a static text control as a label for another control
- Remove hack for storing a dialog result of arbitrary type in favour of boost::any
- Add method to get default text colour for a dialog
- Add method to get a dialog's rect
- Add method to add the same event handler to multiple controls in a dialog
- Add concept of default button to dialogs
- Add enum for text field type (currently either number or text)
- Implement the text field without use of native controls, including somewhat decent text input and a flashing insertion point
- cPict no longer stores references to every sheet; it fetches them as needed from the resource manager
- The many draw functions in cPict are no longer static, since they need to access the window containing the pict (before they could only be static due to QuickDraw's global state)
- Add setPict() without a type argument to change the graphic without changing the type, which is a common operation
- Add a scrollbar control; the specifics aren't implemented yet
- Change signature of the record callback for cStrDlog; it will no longer be passed the strings
- Publicize the no-button constructor of cChoiceDlog; it'll assume "okay" is the only button
- Add operator-> to cPictChoice for accessing the underlying dialog
- Add constructor to cPictChoice that takes a starting and ending pic num
- Remove err parameter from giveError
- Many more keys handled, plus support for catching copy, paste, cut, and select all keyboard shortcuts
- Text input fields take priority, overriding any other keyboard shortcuts in the dialog, but they never catch help (F1), escape, or enter
- Some changes to the format itself:
-> keys go in the "def-key" attribute, but modifiers go in "key-mod"
-> "clickable" is no longer a recognized attribute
-> "title" is now a recognized text size (18pt, even larger than "large" at 12pt)
-> "defbtn" attribute on the root element
2014-04-14 13:52:01 -04:00

236 lines
5.6 KiB
C++

//#include "item.h"
#include "boe.global.h"
#include "classes.h"
#include "boe.party.h"
#include "boe.town.h"
#include "boe.items.h"
#include "boe.combat.h"
#include "boe.monster.h"
#include "boe.infodlg.h"
#include "boe.locutils.h"
#include "boe.fields.h"
#include "boe.text.h"
#include "boe.itemdata.h"
#include "boe.townspec.h"
#include "soundtool.h"
#include "mathutil.h"
#include "dlogutil.h"
extern eGameMode overall_mode;
//extern party_record_type univ.party;
//extern current_town_type univ.town;
//extern unsigned char out[96][96],out_e[96][96];
extern ter_num_t combat_terrain[64][64];
extern short current_pc,stat_window;
//extern cOutdoors outdoors[2][2];
extern location pc_pos[6],center;
//extern town_item_list t_i;
//extern big_tr_type t_d;
extern sf::RenderWindow mainPtr;
extern cScenario scenario;
extern cUniverse univ;
char answer[256];
/*bool (which)
short which;
{
short choice,i;
item_record_type treas[] = {
{0,0,0,0,0,0,0,0,0,0,0,0,false,false,false,{0,0},"",""}
};
bool can_enter = true;
location where;
where = get_spec_loc(which);
switch (which) {
case 1:
break;
}
return can_enter;
} */
void activate_monster_enc(short enc_num,std::string list,short str,short strsnd,short *flip_bit)
{
if (*flip_bit == 0) {
cStrDlog display_enc_string(get_str(list,str),"","",8,PIC_DLOG);
display_enc_string.setSound(strsnd);
display_enc_string.show();
activate_monsters(enc_num,1);
*flip_bit = 20;
}
}
bool run_trap(short pc_num,eTrapType trap_type,short trap_level,short diff)
//short pc_num; // 6 - BOOM! 7 - pick here
//short trap_type; // 0 - random 1 - blade 2 - dart 3 - gas 4 - boom 5 - paralyze 6 - no
// 7 - level drain 8 - alert 9 - big flames 10 - dumbfound 11 - disease 1
// 12 - disease all
{
short r1,skill,i,num_hits = 1,i_level;
short trap_odds[30] = {5,30,35,42,48, 55,63,69,75,77,
78,80,82,84,86, 88,90,92,94,96,98,99,99,99,99,99,99,99,99,99};
if (pc_num > 7) { // Debug
// TODO: Play an error sound here
ASB("TRAP ERROR! REPORT!");
return true;
}
if (pc_num == 7) {
pc_num = select_pc(1,0);
if (pc_num == 6)
return false;
}
num_hits += trap_level;
if (trap_type == TRAP_RANDOM)
trap_type = (eTrapType) get_ran(1,1,4);
if (trap_type == TRAP_FALSE_ALARM)
return true;
if (pc_num < 6) {
i = stat_adj(pc_num,1);
if ((i_level = get_prot_level(pc_num,42)) > 0)
i = i + i_level / 2;
skill = minmax(0,20,univ.party[pc_num].skills[SKILL_DISARM_TRAPS] +
+ univ.party[pc_num].skills[SKILL_LUCK] / 2 + 1 - univ.town.difficulty + 2 * i);
r1 = get_ran(1,1,100) + diff;
// Nimble?
if (univ.party[pc_num].traits[TRAIT_NIMBLE])
r1 -= 6;
if (r1 < trap_odds[skill]) {
add_string_to_buf(" Trap disarmed. ");
return true;
}
else add_string_to_buf(" Disarm failed. ");
}
switch (trap_type) {
case TRAP_BLADE:
for (i = 0; i < num_hits; i++) {
add_string_to_buf(" A knife flies out! ");
r1 = get_ran(2 + univ.town.difficulty / 14,1,10);
damage_pc(pc_num,r1,DAMAGE_WEAPON,MONSTER_TYPE_UNKNOWN,0);
}
break;
case TRAP_DART:
add_string_to_buf(" A dart flies out. ");
r1 = 3 + univ.town.difficulty / 14;
r1 = r1 + trap_level * 2;
poison_pc(pc_num,r1);
break;
case TRAP_GAS:
add_string_to_buf(" Poison gas pours out. ");
r1 = 2 + univ.town.difficulty / 14;
r1 = r1 + trap_level * 2;
for(i = 0; i < 6; i++)
poison_pc(i,r1);
break;
case TRAP_EXPLOSION:
for (i = 0; i < num_hits; i++) {
add_string_to_buf(" There is an explosion. ");
r1 = get_ran(3 + univ.town.difficulty / 13,1,8);
hit_party(r1,DAMAGE_FIRE);
}
break;
case TRAP_SLEEP_RAY:
add_string_to_buf(" A purple ray flies out. ");
r1 = 200 + univ.town.difficulty * 100;
r1 = r1 + trap_level * 400;
sleep_pc(pc_num,r1,STATUS_PARALYZED,50);
break;
case TRAP_DRAIN_XP:
add_string_to_buf(" You feel weak. ");
r1 = 40;
r1 = r1 + trap_level * 30;
univ.party[pc_num].experience = max (0,univ.party[pc_num].experience - r1);
break;
case TRAP_ALERT:
add_string_to_buf(" An alarm goes off!!! ");
make_town_hostile();
break;
case TRAP_FLAMES:
add_string_to_buf(" Flames shoot from the walls. ");
r1 = get_ran(10 + trap_level * 5,1,8);
hit_party(r1,DAMAGE_FIRE);
break;
case TRAP_DUMBFOUND:
add_string_to_buf(" You feel disoriented. ");
for(i = 0; i < 6; i++)
dumbfound_pc(i,2 + trap_level * 2);
break;
case TRAP_DISEASE:
add_string_to_buf(" You prick your finger. ");
r1 = 3 + univ.town.difficulty / 14;
r1 = r1 + trap_level * 2;
disease_pc(pc_num,r1);
break;
case TRAP_DISEASE_ALL:
add_string_to_buf(" A foul substance sprays out.");
r1 = 2 + univ.town.difficulty / 14;
r1 = r1 + trap_level * 2;
for(i = 0; i < 6; i++)
disease_pc(i,r1);
break;
default:
add_string_to_buf("ERROR: Invalid trap type."); // should never be reached
}
put_pc_screen();
put_item_screen(stat_window,0);
return true;
}
location get_spec_loc(short which)
{
location where;
short i;
for (i = 0; i < 50; i++)
if (univ.town->spec_id[i] == which)
return univ.town->special_locs[i];
return where;
}
// 0 if no pull.
// 1 if pull
// levers should always start to left.
short handle_lever(location w)
{
if(cChoiceDlog("basic-lever.xml",{"pull", "leave"}).show() == "leave")
return 0;
play_sound(94);
switch_lever(w);
return 1;
}
void switch_lever(location w)
{
alter_space(w.x,w.y,scenario.ter_types[univ.town->terrain(w.x,w.y)].trans_to_what);
}