0% found this document useful (0 votes)
30 views

Obsolete Script Fun Cs

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Obsolete Script Fun Cs

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 17

This file contains unused/unsupported functions from

script library. These were mostly intended for


single player non-scenario use, and are not supported
If they need to be reinstanted for some reason,
the header file and .cpp are below

//---------------------------------------------------------------------------------
--------

//<<<<<<<<<<<<<<From Scriptfuncs.h >>>>>>>>>>>>>>>>>>>>>>

//////////////////////////////////////////////////////
// SCRIPT FUNCTIONS
// This library of script-accessable functions can
// only be called from 'user' scripts. User scripts
// are written in a 'script' block and can can only
// get information or perform actions that pertain to
// the player sitting at the machine that the script is
// executing on.
//
// eg. A player can write a user script that gives waypoints
// to a scout
class ScriptData;

class ScriptFuncs : virtual private MiscAccess, public GameAccessConst, public


ScriptUtils, public ScriptData
{
public:

/////////////////////////
//display functions
/////////////////////////
//FUNC_LIB_CATEGORY(SCRIPT_GAME) //don't export these, they're not being used
static void ScriptFuncs::init_class(void);
static void ScriptFuncs::close_class(void);

static void ScriptFuncs::print_msg(const String &str); //prints to game message


area
static void ScriptFuncs::set_msg_color(const String &str);
static void ScriptFuncs::set_msg_align(const String &str);
static void ScriptFuncs::set_msg_time(const int &time);
static void ScriptFuncs::chat(const String &str); //chats to currently selected
recipients
static void ScriptFuncs::chat_all(const String &str); //chats to all players
static int ScriptFuncs::ping(const int &who, const int &x, const int &y);
//pings location on screen

/////////////////////////////////////////////////////////////
//information functions- return data values or -1 for failed
/////////////////////////////////////////////////////////////
static int ScriptFuncs::player_pop(void);
static int ScriptFuncs::player_pop_cap(void);
static int ScriptFuncs::player_age(void);
static int ScriptFuncs::player_settlements(void);
static int ScriptFuncs::player_points(void);
static int ScriptFuncs::player_num_type(const String &type);
static int ScriptFuncs::player_num_domain(const String &domain);
static int ScriptFuncs::time(void);
static int ScriptFuncs::object_position_x(const int &object_o);
static int ScriptFuncs::object_position_y(const int &object_o);
static int ScriptFuncs::find_idle_peasant(void);
static int ScriptFuncs::find_idle_military(void);
static int ScriptFuncs::find_capital(void);
static int ScriptFuncs::find_settlement(void);
static int ScriptFuncs::find_unit(const String &type);
static int ScriptFuncs::find_build(const String &type);
static int ScriptFuncs::find_wall(void);

////////////////////////////////////////////////////////
//action functions- return 1 if successful, -1 if error
//////////////////////////////////////////////////////////
static int ScriptFuncs::train_peasant(void);
static int ScriptFuncs::train_peasant_at(const int &where_o);
static int ScriptFuncs::train_unit(const String &type);
static int ScriptFuncs::train_unit_at(const String &type, const int &where_o);
static int ScriptFuncs::research_tech(const String &type);

static int ScriptFuncs::declare_war (const int &declarer, const int &declaree);


static int ScriptFuncs::send_tribute (const int &sender, const int &who_receiver,
const String &resource, const int &amt);

static int ScriptFuncs::ask_tribute(const int &who_askee, const String &resource,


const int &amt);
static int ScriptFuncs::ask_peace(const int &who_askee);
static int ScriptFuncs::ask_ally(const int &who_askee);
static int ScriptFuncs::ask_mutual_attack(const int &who_askee, const int
&attacked);
static int ScriptFuncs::revoke_offer(const int &who_askee);

static int ScriptFuncs::unit_move_order(const int &object_o, const int &x, const


int &y);
static int ScriptFuncs::unit_waypoint_order(const int &object_o, const int &x,
const int &y);
static int ScriptFuncs::unit_explore_order(const int &object_o, const int &x,
const int &y);
static int ScriptFuncs::unit_flee_order(const int &object_o, const int &x, const
int &y);
static int ScriptFuncs::unit_attack_order(const int &attacker_o, const int
&attacked_who, const int &attacked_o);
static int ScriptFuncs::unit_stance_order(const int &object_o, const String
&stance);

static int ScriptFuncs::buy_good(const String &good);


static int ScriptFuncs::sell_good(const String &good);

///////////////////////////////////////////////
//system functions
///////////////////////////////////////////////

//zoom_in();
//moves camera to full zoom
//pass in -1's for x and y to not specify a location
static int ScriptFuncs::zoom_in(const int &x, const int &y);
//zoom_out();
//moves camera to full zoom out
//pass in -1's for x and y to not specify a location
static int ScriptFuncs::zoom_out(const int &x, const int &y);

//set_camera_pos(23, 34);
//sets camera to specified position at current zoom
static int ScriptFuncs::move_camera(const int &x, const int &y);

//center_camera_on(300)
//sets camera to center on your own object with id 300 at current zoom level
static int ScriptFuncs::center_camera_on(const int &object_o);

//zoom_in_on(300)
//sets camera to zoom in and center on your own object with id 300
static int ScriptFuncs::zoom_in_on(const int &object_o);

static int ScriptFuncs::get_sound_x(void);


static int ScriptFuncs::get_sound_y(void);
static void ScriptFuncs::set_sound_pan(const int &pan);
static void ScriptFuncs::set_sound_volume(const int &volume);

static int ScriptFuncs::get_near_zoom(void);


static int ScriptFuncs::get_current_zoom(void);
static int ScriptFuncs::get_camera_x(void);
static int ScriptFuncs::get_camera_y(void);

static int ScriptFuncs::get_mouse_x(void);


static int ScriptFuncs::get_mouse_y(void);
};

//<<<<<<<<<<<<<<From Scriptfuncs.cpp >>>>>>>>>>>>>>>>>>>>>>

//******************************************
////////////////////////////////////////////
// ScriptFuncs
////////////////////////////////////////////
//******************************************

//===========================================================

void ScriptFuncs::init_class(void)
{
user_color = WHITE;
user_time = 10000;
user_align = MSG_ALIGN_LEFT;
}

//===========================================================

void ScriptFuncs::close_class(void)
{
}

//===========================================================

void ScriptFuncs::print_msg(const String &str)


{
MESSAGE_WIN.set_message_color(user_color);
String copy = str;
String sub;

do {

copy.copy(&sub, PRINT_MAX);
copy.add_offset(PRINT_MAX);
MESSAGE_WIN.set_message_color(user_color);
MESSAGE_WIN.add_message(sub,-1, -1, user_time);

} while( copy.length());

//===========================================================

void ScriptFuncs::set_msg_color(const String &str)


{
user_color = get_color(str);
}

//===========================================================

void ScriptFuncs::set_msg_align(const String &str)


{
if (str.ignore("Left")) {
user_align = MSG_ALIGN_LEFT;
} else if (str.ignore("Right")) {
user_align = MSG_ALIGN_RIGHT;
} else if (str.ignore("Center")) {
user_align = MSG_ALIGN_CENTER;
} else {
user_align = MSG_ALIGN_LEFT;
}
}

//===========================================================

void ScriptFuncs::set_msg_time(const int &t)


{
if (t < 0) {
user_time = 10;
} else if (t > 60) {
user_time = 60;
} else {
user_time = t;
}
}

//===========================================================

void ScriptFuncs::chat(const String &str)


{
int whom = WHO;
int play = LEADER2.get_player();

LEADER2.issue_chat(str);//, PLAYER.chat_play);
}

//===========================================================

void ScriptFuncs::chat_all(const String &str)


{
int players = 0x0FFFFFFF;
int whom = WHO;

LEADER2.issue_chat(str, players);//_play(str, players);

//===========================================================

int ScriptFuncs::ping(const int &who, const int &x, const int &y)
{
int whom = WHO;
if (ScriptUtils::active_who(whom) && WORLD.is_valid((TCoord)x, (TCoord)y )) {
LEADER2.issue_ping((TCoord)x, (TCoord)y );
return 1;
} else {
return -1;
}
}

//===========================================================

int ScriptFuncs::player_pop()
{
return MYLEADER.control;
}

//===========================================================

int ScriptFuncs::player_pop_cap(void)
{
return MYLEADER.pop_cap;
}

//===========================================================

int ScriptFuncs::player_age()
{
int whom = WHO;
return LEADER2.ages;
}

//===========================================================

int ScriptFuncs::player_settlements()
{

return MYLEADER.city_num;
}

//===========================================================

int ScriptFuncs::player_points()
{
return MYLEADER.score;
}

//===========================================================

int ScriptFuncs::player_num_type (const String &type)


{
int t = ScriptUtils::get_type_index(type);
int whom = WHO;
if (t >= 0 ) {
if (BASETYPE.is_unit_type()) {
return LEADER2.num_units[t-BASE_UNITTYPES];
} else if (BASETYPE.is_build_type()) {
return LEADER2.num_buildings[t-BASE_BUILDTYPES];
} else {
return -1;
}
} else {
return -1;
}
}

//===========================================================

int ScriptFuncs::player_num_domain(const String &domain)


{return -1;
}

//===========================================================

int ScriptFuncs::time()
{
return GAME.tick / 60;
}

//=================================================================

int ScriptFuncs::object_position_x(const int &id)


{
int whom = WHO;
int ox = id;

if (ScriptUtils::valid_unit_o(whom, ox) || ScriptUtils::valid_build_o(whom, ox))


{
return (TCoord)XX;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::object_position_y(const int &id)


{
int whom = WHO;
int ox = id;

if (ScriptUtils::valid_unit_o(whom, ox) || ScriptUtils::valid_build_o(whom, ox))


{
return (TCoord)YY;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::find_idle_peasant()
{
int whom = WHO;
static int last_o = BASE_UNITS;
if (!ScriptUtils::active_who( whom )) return -1;
int t = LEADER2.current_upgrade(PEASANTS);

int ox = last_o+1;
do {
if (ox >= OBJECTS.unit_mark[whom] ) {
ox = BASE_UNITS;
}
if (OBJECTX.is_map_unit() && UNITX.is(t) && UNITX.order_type() == NONE) {
last_o = ox;
return ox;
}
ox++;
} while( ox != last_o + 1 );
last_o = BASE_UNITS;
return -1;

//=================================================================

int ScriptFuncs::find_idle_military()
{
int whom = WHO;
static int last_o = BASE_UNITS;
if (!ScriptUtils::active_who( whom )) return -1;
int ox = last_o+1;
do {
if (ox >= OBJECTS.unit_mark[whom] ) {
ox = BASE_UNITS;
}
if (OBJECTX.is_map_unit() && UNITX.is_military() && UNITX.order_type() ==
NONE ) {
last_o = ox;
return ox;
}
ox++;
} while( ox != last_o + 1 );
last_o = BASE_UNITS;
return -1;

//=================================================================

int ScriptFuncs::find_capital()
{
int whom = WHO;
int city2;

for (int ox = BASE_BUILDS; ox < OBJECTS.build_mark[whom]; ox++) {


if (!OBJECTX.is_active_build()) continue;
if (!BUILDX.is_city()) continue;
city2 = BUILDX.city;
if (!CITY2.is_capital()) continue;
return ox;
}

return -1;
}

//=================================================================

int ScriptFuncs::find_settlement()
{
int who = WHO;
static int last_o = 0;

if (ScriptUtils::valid_who(who)) {
int city = last_o+1;
do {
if (city >= LEADER.city_mark ) {
city = 0;
}
if (CITY.is_valid()) {
last_o = city;
return CITY.o;
}
city++;
} while( city != last_o+1 );
last_o = 0;
return -1;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::find_unit(const String &type)


{
int whom = WHO;
static int last_o = BASE_UNITS;
int t = ScriptUtils::get_type_index(type);
if ((t < 0) || !BASETYPE.is_unit_type()) {
return -1;
}
int ox = ScriptUtils::find_unit(whom, t, last_o);
if (ox >= 0 ) {
last_o = ox;
return ox;
}

return -1;
}

//=================================================================

int ScriptFuncs::find_build(const String &type)


{
int whom = WHO;
static int last_o = BASE_BUILDS;
int t = ScriptUtils::get_type_index(type);
if ((t < 0) || !BASETYPE.is_build_type()) {
return -1;
}

int ox = ScriptUtils::find_build(whom, t, last_o);


if (ox >= 0 ) {
last_o = ox;
return ox;
}

return -1;
}

//=================================================================

int ScriptFuncs::find_wall()
{
int whom = WHO;
static int last_o = BASE_WALLS;
int t = WALL_CHUNK;

int ox = ScriptUtils::find_wall(whom, last_o);


if (ox >= 0 ) {
last_o = ox;
return ox;
}

return -1;
}

//=================================================================

int ScriptFuncs::train_peasant()
{
static int last_build = BASE_BUILDS;
int whom = WHO;
if (!ScriptUtils::active_who( whom )) return -1;

int t = LEADER2.current_upgrade(PEASANTS);
int t2 = LEADER2.current_upgrade(BASETYPE.where);
int ox = ScriptUtils::find_build(whom, t2, last_build);
Group group;
if (ox >= 0 ) {
last_build = ox;
group.add(ox, whom);
group.issue_queue_up((TypeIndex)t);
return ox;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::train_peasant_at(const int &where_id)


{
int whom = WHO;
if (!ScriptUtils::active_who(whom)) return -1;

int ox = where_id;
Group group;
int t = LEADER2.current_upgrade(PEASANTS);

if (ScriptUtils::valid_build_o(whom, ox) && BUILDX.get_type()->is_city() ) {


group.add(ox, whom);
group.issue_queue_up((TypeIndex)t);
return ox;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::train_unit(const String &type)


{
static int last_build = BASE_BUILDS;
int whom = WHO;
int t = ScriptUtils::get_type_index(type);
if ((t < 0) || !ScriptUtils::active_who(whom)) return -1;
t = LEADER2.current_upgrade(t);
t = LEADER2.get_graft(t);

int t2 = LEADER2.current_upgrade(BASETYPE.where);
int ox = ScriptUtils::find_build(whom, t2, last_build);
Group group;

if (ox >= 0 ) {
last_build = ox;
group.add(ox, whom);
group.issue_queue_up((TypeIndex)t);
return ox;
} else {
return 0;
}
}

//=================================================================

int ScriptFuncs::train_unit_at(const String &type, const int &where_id)


{
int whom = WHO;
int t = ScriptUtils::get_type_index(type);
if (t < 0) return -1;
t = LEADER2.current_upgrade(t);
t = LEADER2.get_graft(t);
int ox = where_id;
Group group;

if (ScriptUtils::valid_build_o(whom, ox) && BUILDX.can_make(t)) {


group.add(ox, whom);
group.issue_queue_up((TypeIndex)t);
return ox;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::research_tech(const String &type)


{
int whom = WHO;
int ox = LEADER2.get_first_library();
Group group;
int t = ScriptUtils::get_type_index(type);

if ((ox >= 0) && ScriptUtils::active_who(whom) && (t >= 0)) {


group.add(ox, whom);
group.issue_queue_up((TypeIndex)t);
return 1;
} else {
return -1;
}

int ScriptFuncs::declare_war (const int &declarer, const int &declaree)


{
return -1;
}
int ScriptFuncs::send_tribute (const int &sender, const int &receiver, const String
&resource, const int &amt)
{
return -1;
}
int ScriptFuncs::ask_tribute(const int &asked, const String &resource, const int
&amt)
{
return -1;
}
int ScriptFuncs::ask_peace(const int &asked)
{
return -1;
}
int ScriptFuncs::ask_ally(const int &asked)
{
return -1;
}
int ScriptFuncs::ask_mutual_attack(const int &asked, const int &attacked)
{
return -1;
}
int ScriptFuncs::revoke_offer(const int &asked)
{
return -1;
}

//=================================================================

int ScriptFuncs::unit_move_order(const int &id, const int &x, const int &y)
{
int whom = WHO;
int ox = id;
Group group;

if (ScriptUtils::valid_unit_o(whom, ox) && WORLD.is_valid((TCoord)x, (TCoord)y ))


{
group.add(ox, whom);
group.issue_move_to((TCoord)x, (TCoord)y);
return true;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::unit_waypoint_order(const int &id, const int &x, const int &y)
{
int whom = WHO;
int ox = id;
Group group;

if (ScriptUtils::valid_unit_o(whom, ox) && WORLD.is_valid((TCoord)x, (TCoord)y ))


{
group.add(ox, whom);
group.issue_move_to((TCoord)x, (TCoord)y, QUEUE_LAST);
return true;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::unit_explore_order(const int &id, const int &x, const int &y)
{
int whom = WHO;
int ox = id;
Group group;

if (ScriptUtils::valid_unit_o(whom, ox) && WORLD.is_valid((TCoord)x, (TCoord)y ))


{
group.add(ox, whom);
group.issue_move_to((TCoord)x, (TCoord)y, QUEUE_LAST, false, 0, EXPLORE_TO);
return true;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::unit_flee_order(const int &id, const int &x, const int &y)
{
int whom = WHO;
int ox = id;
Group group;

if (ScriptUtils::valid_unit_o(whom, ox) && WORLD.is_valid((TCoord)x, (TCoord)y ))


{
group.add(ox, whom);
group.issue_move_to((TCoord)x, (TCoord)y, QUEUE_LAST, false, 0, FLEE_TO);
return true;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::unit_attack_order(const int &attacker_id, const int &attacked_who,


const int &attacked_id)
{
int whom = WHO;
int ox = attacker_id;
int whose = attacked_who-1;
int oxx = attacked_id;
Group group;

if (ScriptUtils::valid_object_o(whom, ox) && ScriptUtils::valid_object_o(whose,


oxx)) {
group.add(ox, whom);
group.issue_attack(oxx, whose);
return true;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::unit_stance_order(const int &id, const String &stance)


{
int whom = WHO;
int ox = id;
int new_stance = get_stance(stance);
Group group;

if (valid_unit_o(whom, ox) && new_stance >= 0) {


group.add(ox, whom);
group.issue_stance(new_stance);
return 1;
} else {
return -1;
}
}
//=================================================================

int ScriptFuncs::buy_good(const String &good)


{
int whom = WHO;

int t = ScriptUtils::get_type_index(good);

if (ScriptUtils::active_who(whom) && (t >= 0) && (t < NUM_COMMON)) {


LEADER2.issue_buy( t );
return 1;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::sell_good(const String &good)


{
int whom = WHO;

int t = ScriptUtils::get_type_index(good);

if (ScriptUtils::active_who(whom) && (t >= 0) && (t < NUM_COMMON)) {


LEADER2.issue_sell( t );
return 1;
} else {
return -1;
}
}

//=================================================================

int ScriptFuncs::zoom_in(const int &x, const int &y)


{
TCoord tx = x;
TCoord ty = y;
Coord cx = (Coord)tx;
Coord cy = (Coord)ty;

if (x < 0) {
camera.zoom_to_level(NUM_ZOOM_LEVELS-1);
} else if (WORLD.is_valid(tx, ty)) {
camera.zoom_to_level(NUM_ZOOM_LEVELS-1);
camera.pan_to(cx, cy);
} else {
return -1;
}

return 1;
}

//=================================================================

int ScriptFuncs::zoom_out(const int &x, const int &y)


{
TCoord tx = x;
TCoord ty = y;
Coord cx = (Coord)tx;
Coord cy = (Coord)ty;

if (x < 0) {
camera.zoom_to_level(0);
} else if (WORLD.is_valid(tx, ty)) {
camera.zoom_to_level(0);
camera.pan_to(cx , cy);
} else {
return -1;
}

return 1;
}

//=================================================================

int ScriptFuncs::move_camera(const int &x, const int &y)


{

TCoord tx = x;
TCoord ty = y;
Coord cx = tx;
Coord cy = ty;

if (WORLD.is_valid((TCoord)x, (TCoord)y)) {
camera.pan_to(cx, cy);
} else {
return -1;
}

return 1;
}

//=================================================================

int ScriptFuncs::center_camera_on(const int &id)


{
int whom = WHO;
int ox = id;
if (!GAME.is_solo()) return -1;

if (valid_object_o(whom, ox)) {
camera.pan_to(XX, YY);
} else {
return -1;
}

return 1;
}

//=================================================================

int ScriptFuncs::zoom_in_on(const int &id)


{
int whom = WHO;
int ox = id;
if (!GAME.is_solo()) return -1;

if (valid_object_o(whom, ox)) {
camera.zoom_to_level(NUM_ZOOM_LEVELS-1);
camera.pan_to(XX, YY);
} else {
return -1;
}

return 1;
}

//=================================================================

int ScriptFuncs::get_sound_x(void)
{
return SoundRef::current_x;
}

//=================================================================

int ScriptFuncs::get_sound_y(void)
{
return SoundRef::current_y;
}

//=================================================================

void ScriptFuncs::set_sound_pan(const int &pan)


{
SoundRef::current_pan = pan;
}

//=================================================================

void ScriptFuncs::set_sound_volume(const int &volume)


{
SoundRef::current_volume = volume;
}

//=================================================================

int ScriptFuncs::get_near_zoom(void)
{
return FTOL(CAMERA.get_near_point());
}

//=================================================================

int ScriptFuncs::get_current_zoom(void)
{
return FTOL(CAMERA.zoom_distance);
}

//=================================================================

int ScriptFuncs::get_camera_x(void)
{
return FTOL(CAMERA.loc_x);
}

//=================================================================

int ScriptFuncs::get_camera_y(void)
{
return FTOL(CAMERA.loc_y);
}

//=================================================================

int ScriptFuncs::get_mouse_x(void)
{
int mx, my;
graphsys->get_cursor_pos(&mx, &my);
return mx;
}

//=================================================================

int ScriptFuncs::get_mouse_y(void)
{
int mx, my;
graphsys->get_cursor_pos(&mx, &my);
return my;
}

You might also like