Fixed a code collision in a previous attempt at merging Windows and Mac codes, which would prevent the move_to_zero function to work with short types.
Most obvious effects were infinite bless, haste, poison, webs not cleaning, etc Chokboyz git-svn-id: http://openexile.googlecode.com/svn/trunk@151 4ebdad44-0ea0-11de-aab3-ff745001d230
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "globvar.h"
|
#include "globvar.h"
|
||||||
|
#include "tools/mathutil.h"
|
||||||
|
|
||||||
RECT RECT16::rect32()
|
RECT RECT16::rect32()
|
||||||
{
|
{
|
||||||
@@ -20,7 +21,7 @@ RECT16::RECT16 (const RECT & tmp)
|
|||||||
right = tmp.right;
|
right = tmp.right;
|
||||||
bottom = tmp.bottom;
|
bottom = tmp.bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
RECT16 & RECT16::operator=(const RECT & tmp)
|
RECT16 & RECT16::operator=(const RECT & tmp)
|
||||||
{
|
{
|
||||||
left = tmp.left;
|
left = tmp.left;
|
||||||
@@ -33,10 +34,10 @@ RECT16 & RECT16::operator=(const RECT & tmp)
|
|||||||
POINT MAKEPOINT(LONG lParam)
|
POINT MAKEPOINT(LONG lParam)
|
||||||
{
|
{
|
||||||
POINT point;
|
POINT point;
|
||||||
|
|
||||||
point.x = LOWORD(lParam);
|
point.x = LOWORD(lParam);
|
||||||
point.y = HIWORD(lParam);
|
point.y = HIWORD(lParam);
|
||||||
|
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ void DebugQuit(char * msg)
|
|||||||
PostQuitMessage(EXIT_FAILURE);
|
PostQuitMessage(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void alter_rect(RECT *r)
|
void alter_rect(RECT *r)
|
||||||
{
|
{
|
||||||
long a;
|
long a;
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ void alter_rect(RECT *r)
|
|||||||
r->right = a;
|
r->right = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alter_rect(RECT16 *r)
|
void alter_rect(RECT16 *r)
|
||||||
{
|
{
|
||||||
short a;
|
short a;
|
||||||
|
|
||||||
@@ -79,7 +80,7 @@ void alter_rect(RECT16 *r)
|
|||||||
|
|
||||||
if ((max - min + 1) == 0)
|
if ((max - min + 1) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (i = 1; i < times + 1; i++)
|
for (i = 1; i < times + 1; i++)
|
||||||
{
|
{
|
||||||
store = rand() % (max - min + 1);
|
store = rand() % (max - min + 1);
|
||||||
|
|||||||
@@ -57,11 +57,11 @@ struct RECT16
|
|||||||
typedef char Boolean;
|
typedef char Boolean;
|
||||||
|
|
||||||
struct shortloc { short x, y; };
|
struct shortloc { short x, y; };
|
||||||
|
|
||||||
struct special_node_type
|
struct special_node_type
|
||||||
{
|
{
|
||||||
short type,sd1,sd2,pic,m1,m2,ex1a,ex1b,ex2a,ex2b,jumpto;
|
short type,sd1,sd2,pic,m1,m2,ex1a,ex1b,ex2a,ex2b,jumpto;
|
||||||
|
|
||||||
void flip(); /* reverse byte order */
|
void flip(); /* reverse byte order */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,11 +81,11 @@ typedef struct {
|
|||||||
unsigned char blockage,flag1,flag2,special,trans_to_what,fly_over,boat_over;
|
unsigned char blockage,flag1,flag2,special,trans_to_what,fly_over,boat_over;
|
||||||
unsigned char block_horse,light_radius,step_sound,shortcut_key,res1,res2,res3;
|
unsigned char block_horse,light_radius,step_sound,shortcut_key,res1,res2,res3;
|
||||||
} terrain_type_type;
|
} terrain_type_type;
|
||||||
|
|
||||||
struct wandering_type
|
struct wandering_type
|
||||||
{
|
{
|
||||||
unsigned char monst[4];
|
unsigned char monst[4];
|
||||||
|
|
||||||
bool isNull() const;
|
bool isNull() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ struct out_wandering_type
|
|||||||
unsigned char friendly[3];
|
unsigned char friendly[3];
|
||||||
short spec_on_meet,spec_on_win,spec_on_flee,cant_flee;
|
short spec_on_meet,spec_on_win,spec_on_flee,cant_flee;
|
||||||
short end_spec1,end_spec2;
|
short end_spec1,end_spec2;
|
||||||
|
|
||||||
bool isNull() const;
|
bool isNull() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ struct outdoor_record_type
|
|||||||
RECT16 info_rect[8];
|
RECT16 info_rect[8];
|
||||||
unsigned char strlens[180];
|
unsigned char strlens[180];
|
||||||
special_node_type specials[60];
|
special_node_type specials[60];
|
||||||
|
|
||||||
void flip(); /* reverse byte order */
|
void flip(); /* reverse byte order */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,20 +126,20 @@ typedef struct {
|
|||||||
short spec1, spec2;
|
short spec1, spec2;
|
||||||
char spec_enc_code, time_code;
|
char spec_enc_code, time_code;
|
||||||
short monster_time,personality;
|
short monster_time,personality;
|
||||||
short special_on_kill,facial_pic;
|
short special_on_kill,facial_pic;
|
||||||
} creature_start_type;
|
} creature_start_type;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
location item_loc;
|
location item_loc;
|
||||||
short item_code,ability;
|
short item_code,ability;
|
||||||
unsigned char charges,always_there,property,contained;
|
unsigned char charges,always_there,property,contained;
|
||||||
} preset_item_type;
|
} preset_item_type;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
location field_loc;
|
location field_loc;
|
||||||
short field_type;
|
short field_type;
|
||||||
} preset_field_type;
|
} preset_field_type;
|
||||||
|
|
||||||
struct town_record_type
|
struct town_record_type
|
||||||
{
|
{
|
||||||
short town_chop_time,town_chop_key;
|
short town_chop_time,town_chop_key;
|
||||||
@@ -167,7 +167,7 @@ struct town_record_type
|
|||||||
bool defy_mapping : 1;
|
bool defy_mapping : 1;
|
||||||
char reserved_bits : 6;*/
|
char reserved_bits : 6;*/
|
||||||
short difficulty;
|
short difficulty;
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
location getSpecLoc(int spec);
|
location getSpecLoc(int spec);
|
||||||
};
|
};
|
||||||
@@ -186,13 +186,13 @@ typedef struct {
|
|||||||
creature_start_type creatures[40];
|
creature_start_type creatures[40];
|
||||||
unsigned char lighting[6][48];
|
unsigned char lighting[6][48];
|
||||||
} ave_tr_type;
|
} ave_tr_type;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned char terrain[32][32];
|
unsigned char terrain[32][32];
|
||||||
RECT16 room_rect[16];
|
RECT16 room_rect[16];
|
||||||
creature_start_type creatures[30];
|
creature_start_type creatures[30];
|
||||||
unsigned char lighting[4][32];
|
unsigned char lighting[4][32];
|
||||||
} tiny_tr_type;
|
} tiny_tr_type;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
item_record_type scen_items[400];
|
item_record_type scen_items[400];
|
||||||
@@ -217,7 +217,7 @@ typedef struct {
|
|||||||
unsigned char default_attitude,summon_type,default_facial_pic,res1,res2,res3;
|
unsigned char default_attitude,summon_type,default_facial_pic,res1,res2,res3;
|
||||||
short picture_num;
|
short picture_num;
|
||||||
} monster_record_type;
|
} monster_record_type;
|
||||||
|
|
||||||
/* CREATURE_DATA_TYPE */
|
/* CREATURE_DATA_TYPE */
|
||||||
class creature_data_type
|
class creature_data_type
|
||||||
{
|
{
|
||||||
@@ -230,7 +230,7 @@ public:
|
|||||||
Boolean mobile;
|
Boolean mobile;
|
||||||
short summoned;
|
short summoned;
|
||||||
creature_start_type monst_start;
|
creature_start_type monst_start;
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
private:
|
private:
|
||||||
void adjustMagic(short *how_much);
|
void adjustMagic(short *how_much);
|
||||||
@@ -245,14 +245,14 @@ public:
|
|||||||
void dumbfound(short how_much);
|
void dumbfound(short how_much);
|
||||||
void charm(short penalty, short which_status, short amount);
|
void charm(short penalty, short which_status, short amount);
|
||||||
void record();
|
void record();
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
location horse_loc,horse_loc_in_sec,horse_sector;
|
location horse_loc,horse_loc_in_sec,horse_sector;
|
||||||
short which_town;
|
short which_town;
|
||||||
Boolean exists,property;
|
Boolean exists,property;
|
||||||
} horse_record_type;
|
} horse_record_type;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
location boat_loc,boat_loc_in_sec,boat_sector;
|
location boat_loc,boat_loc_in_sec,boat_sector;
|
||||||
short which_town;
|
short which_town;
|
||||||
@@ -264,7 +264,7 @@ typedef struct {
|
|||||||
unsigned char ver[3],min_run_ver,prog_make_ver[3],num_towns;
|
unsigned char ver[3],min_run_ver,prog_make_ver[3],num_towns;
|
||||||
unsigned char out_width,out_height,difficulty,intro_pic,default_ground;
|
unsigned char out_width,out_height,difficulty,intro_pic,default_ground;
|
||||||
} scen_header_type;
|
} scen_header_type;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned char flag1, flag2, flag3, flag4;
|
unsigned char flag1, flag2, flag3, flag4;
|
||||||
unsigned char ver[3],min_run_ver,prog_make_ver[3],num_towns;
|
unsigned char ver[3],min_run_ver,prog_make_ver[3],num_towns;
|
||||||
@@ -328,7 +328,7 @@ struct current_town_type
|
|||||||
creature_list_type monst;
|
creature_list_type monst;
|
||||||
Boolean in_boat;
|
Boolean in_boat;
|
||||||
location p_loc;
|
location p_loc;
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
short placeMonster(unsigned char which, location where);
|
short placeMonster(unsigned char which, location where);
|
||||||
short countMonsters();
|
short countMonsters();
|
||||||
@@ -340,9 +340,9 @@ struct outdoor_creature_type
|
|||||||
Boolean exists;
|
Boolean exists;
|
||||||
short direction;
|
short direction;
|
||||||
out_wandering_type what_monst;
|
out_wandering_type what_monst;
|
||||||
location which_sector,m_loc;
|
location which_sector,m_loc;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct party_record_type
|
struct party_record_type
|
||||||
{
|
{
|
||||||
long age;
|
long age;
|
||||||
@@ -373,10 +373,10 @@ struct party_record_type
|
|||||||
short m_killed[200];
|
short m_killed[200];
|
||||||
unsigned long total_m_killed,total_dam_done,total_xp_gained,total_dam_taken;
|
unsigned long total_m_killed,total_dam_done,total_xp_gained,total_dam_taken;
|
||||||
char scen_name[256];
|
char scen_name[256];
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
bool isFlying() { return (bool) stuff_done[305][1]; }
|
bool isFlying() { return (bool) stuff_done[305][1]; }
|
||||||
|
|
||||||
void giveGold(short amount, bool print_result);
|
void giveGold(short amount, bool print_result);
|
||||||
bool takeGold(short amount, bool print_result);
|
bool takeGold(short amount, bool print_result);
|
||||||
void giveFood(short amount, bool print_result);
|
void giveFood(short amount, bool print_result);
|
||||||
@@ -385,12 +385,12 @@ struct party_record_type
|
|||||||
|
|
||||||
typedef struct { char town_maps[200][8][64]; } stored_town_maps_type;
|
typedef struct { char town_maps[200][8][64]; } stored_town_maps_type;
|
||||||
typedef struct { char town_strs[180][256]; } piles_of_stuff_dumping_type;
|
typedef struct { char town_strs[180][256]; } piles_of_stuff_dumping_type;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char scen_header_strs[3][80];
|
char scen_header_strs[3][80];
|
||||||
char scen_names[256];
|
char scen_names[256];
|
||||||
} piles_of_stuff_dumping_type2;
|
} piles_of_stuff_dumping_type2;
|
||||||
|
|
||||||
typedef struct { char talk_strs[170][256]; } piles_of_stuff_dumping_type3;
|
typedef struct { char talk_strs[170][256]; } piles_of_stuff_dumping_type3;
|
||||||
typedef struct { char out_strs[9][256]; } outdoor_strs_type;
|
typedef struct { char out_strs[9][256]; } outdoor_strs_type;
|
||||||
typedef struct { outdoor_strs_type outdoor_text[2][2]; } piles_of_stuff_dumping_type4;
|
typedef struct { outdoor_strs_type outdoor_text[2][2]; } piles_of_stuff_dumping_type4;
|
||||||
@@ -401,10 +401,10 @@ class pc_array
|
|||||||
private:
|
private:
|
||||||
//pc_record_type pc[6];
|
//pc_record_type pc[6];
|
||||||
pc_record_type pc[NUM_OF_PCS];
|
pc_record_type pc[NUM_OF_PCS];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
pc_record_type & operator[](int num) { return pc[num]; }
|
pc_record_type & operator[](int num) { return pc[num]; }
|
||||||
|
|
||||||
/* remember - all this functions refer to all PCs */
|
/* remember - all this functions refer to all PCs */
|
||||||
void affect(short type, short how_much);
|
void affect(short type, short how_much);
|
||||||
void cure(short how_much); /* cure all */
|
void cure(short how_much); /* cure all */
|
||||||
@@ -416,26 +416,26 @@ public:
|
|||||||
void poison(short how_much); /* poison all */
|
void poison(short how_much); /* poison all */
|
||||||
|
|
||||||
void drainXP(short how_much); // drain experience points
|
void drainXP(short how_much); // drain experience points
|
||||||
|
|
||||||
void giveXP(short how_much); // give experience points
|
void giveXP(short how_much); // give experience points
|
||||||
|
|
||||||
void restoreSP(short how_much); // restore spell points
|
void restoreSP(short how_much); // restore spell points
|
||||||
|
|
||||||
bool hasAbil(short ability);
|
bool hasAbil(short ability);
|
||||||
|
|
||||||
bool isPoisoned(); /* is someone posioned? */
|
bool isPoisoned(); /* is someone posioned? */
|
||||||
|
|
||||||
short getMageLore(); /* count total mage lore */
|
short getMageLore(); /* count total mage lore */
|
||||||
short getTotalLevel();
|
short getTotalLevel();
|
||||||
short getTotalLuck();
|
short getTotalLuck();
|
||||||
|
|
||||||
bool checkClass(short item_class,short mode);
|
bool checkClass(short item_class,short mode);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct { unsigned char setup[4][64][64]; } setup_save_type;
|
typedef struct { unsigned char setup[4][64][64]; } setup_save_type;
|
||||||
typedef struct { unsigned char pattern[9][9]; } effect_pat_type;
|
typedef struct { unsigned char pattern[9][9]; } effect_pat_type;
|
||||||
typedef struct { item_record_type items[NUM_TOWN_ITEMS]; } stored_items_list;
|
typedef struct { item_record_type items[NUM_TOWN_ITEMS]; } stored_items_list;
|
||||||
typedef struct { char outdoor_maps[100][6][48]; } stored_outdoor_maps_type;
|
typedef struct { char outdoor_maps[100][6][48]; } stored_outdoor_maps_type;
|
||||||
|
|
||||||
//extern short s_pow(short x,short y);
|
//extern short s_pow(short x,short y);
|
||||||
//extern short get_ran (short times, short min, short max);
|
//extern short get_ran (short times, short min, short max);
|
||||||
@@ -446,27 +446,8 @@ void alter_rect(RECT *r) ;
|
|||||||
void alter_rect(RECT16 *r) ;
|
void alter_rect(RECT16 *r) ;
|
||||||
Boolean sd_legit(short a, short b);
|
Boolean sd_legit(short a, short b);
|
||||||
|
|
||||||
template <class T>
|
typedef struct {
|
||||||
T minmax(T min, T max, T k)
|
|
||||||
{
|
|
||||||
return (k < min)? min : (k > max)? max : k;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
T ex_abs(T value)
|
|
||||||
{
|
|
||||||
return (value < 0)? (-value) : value;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
void move_to_zero(T & value)
|
|
||||||
{
|
|
||||||
if (value > 0) --value;
|
|
||||||
else if (value < 0) ++value;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
|
|
||||||
short queued_special;
|
short queued_special;
|
||||||
long trigger_time;
|
long trigger_time;
|
||||||
unsigned short mode;
|
unsigned short mode;
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include "mathutil.h"
|
#include "mathutil.h"
|
||||||
|
|
||||||
|
//minmax, move_to_zero and ex_abs (return absolute value) are templates in the header file
|
||||||
|
|
||||||
short get_ran (short times,short min,short max){
|
short get_ran (short times,short min,short max){
|
||||||
long int store;
|
long int store;
|
||||||
@@ -43,22 +45,6 @@ short min(short a,short b){
|
|||||||
else return b;
|
else return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
short minmax(short min,short max,short k){
|
|
||||||
if (k < min)
|
|
||||||
return min;
|
|
||||||
if (k > max)
|
|
||||||
return max;
|
|
||||||
return k;
|
|
||||||
}
|
|
||||||
|
|
||||||
short move_to_zero(short val){
|
|
||||||
if (val < 0)
|
|
||||||
return val + 1;
|
|
||||||
if (val > 0)
|
|
||||||
return val - 1;
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
short gcd(short a, short b){ // Grabbed from Wikipedia and translated to C code
|
short gcd(short a, short b){ // Grabbed from Wikipedia and translated to C code
|
||||||
short t;
|
short t;
|
||||||
while(b != 0){
|
while(b != 0){
|
||||||
|
|||||||
@@ -22,6 +22,23 @@ extern short s_pow(short x,short y);
|
|||||||
short s_sqrt(short val);
|
short s_sqrt(short val);
|
||||||
short max(short a,short b);
|
short max(short a,short b);
|
||||||
short min(short a,short b);
|
short min(short a,short b);
|
||||||
short minmax(short min,short max,short k);
|
|
||||||
short move_to_zero(short val);
|
|
||||||
short gcd(short a, short b);
|
short gcd(short a, short b);
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void move_to_zero(T & value)
|
||||||
|
{
|
||||||
|
if (value > 0) --value;
|
||||||
|
else if (value < 0) ++value;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
T minmax(T min, T max, T k)
|
||||||
|
{
|
||||||
|
return (k < min)? min : (k > max)? max : k;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
T ex_abs(T value)
|
||||||
|
{
|
||||||
|
return (value < 0)? (-value) : value;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user