Skip to content

Commit

Permalink
Merge branch 'combat1108'
Browse files Browse the repository at this point in the history
Conflicts:
	src/Level.cpp
  • Loading branch information
sorear committed Aug 10, 2011
2 parents a34df19 + 168b633 commit 50e0c93
Show file tree
Hide file tree
Showing 56 changed files with 1,120 additions and 300 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ set(HEADER_FILES
include/Actions/ApplyInDirection.h
include/Actions/Call.h
include/Actions/Charge.h
include/Actions/Christen.h
include/Actions/Donate.h
include/Actions/DropGold.h
include/Actions/Drop.h
Expand Down Expand Up @@ -207,6 +208,7 @@ set(SOURCE_FILES
src/Actions/ApplyInDirection.cpp
src/Actions/Call.cpp
src/Actions/Charge.cpp
src/Actions/Christen.cpp
src/Actions/Dip.cpp
src/Actions/Donate.cpp
src/Actions/Drop.cpp
Expand Down
8 changes: 5 additions & 3 deletions include/Actions/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ namespace action {
public:
static const Command NOOP;

Action(analyzer::Analyzer* analyzer, bool increase_turn_counter = true);
// time_taken values correspond to NetHack nomul values, 1,2,3, counts in moves, -1,-2,-3 count in turns
// values of 2 or more are counted as "indeterminate" due to interruption potential
Action(analyzer::Analyzer* analyzer, int time_taken = 1);
virtual ~Action();

virtual int id() = 0;
analyzer::Analyzer* analyzer();
bool increaseTurnCounter();
int timeTaken();
virtual const Command& command() = 0;
virtual void update(const std::string& messages) = 0;
virtual void failed();
Expand All @@ -31,7 +33,7 @@ namespace action {

private:
analyzer::Analyzer* _analyzer;
bool _increase_turn_counter;
int _time_taken;
};
}
#endif
28 changes: 28 additions & 0 deletions include/Actions/Christen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef ACTION_CHRISTEN_H
#define ACTION_CHRISTEN_H

#include "Actions/Action.h"
#include "Point.h"
#include <vector>
#include <string>

namespace action {
class Christen : public Action {
public:
static const int ID;

Christen(analyzer::Analyzer* analyzer, const std::vector<std::pair<Point, std::string> >& requests);
virtual ~Christen();

virtual int id();
virtual const Command& command();
virtual void update(const std::string&);

private:
std::vector<std::pair<Point, std::string> > _requests;
Command _command;

static int _nao_christen; // +1 means extra 'a', 0 means probing needed
};
}
#endif
1 change: 1 addition & 0 deletions include/Analyzers/Fight.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace analyzer {
void onEvent(event::Event* const event);

private:
std::set<std::string> _no_hitandrun;
std::set<unsigned char> _projectile_slots; // slots where we got weapons we should throw
std::map<std::string, int> _boss_last_seen;
int _boss_waiting_since;
Expand Down
2 changes: 0 additions & 2 deletions include/Analyzers/Food.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ namespace analyzer {
void onEvent(event::Event* const event);

private:
std::map<Point, unsigned char> _prev_monster_loc;
std::map<Point, int> _stashes;
std::map<std::string, int> _eat_priority;
std::set<unsigned char> _food_items;

Expand Down
1 change: 0 additions & 1 deletion include/Analyzers/MonsterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace analyzer {

private:
std::vector<action::FarLook::Request> _requests;
std::map<Point, unsigned int> _checked;
};
}
#endif
24 changes: 20 additions & 4 deletions include/Level.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@

#include <limits.h>
#include <map>
#include <set>
#include <string>
#include <vector>
#include "Globals.h"
#include "Monster.h"
#include "Point.h"
#include "Stash.h"
#include "Tile.h"

/* max amount of nodes in pathing_queue */
#define PATHING_QUEUE_SIZE 16384
/* Fight needs to be able to subtract this */
#define COST_MONSTER 256

namespace data {
class Monster;
}

class Item;
class Monster;

class Level {
public:
Expand All @@ -29,7 +37,7 @@ class Level {
const std::string& name() const;
Tile& tile();
Tile& tile(const Point& point);
const std::map<Point, Monster>& monsters() const;
const std::map<Point, Monster*>& monsters() const;
const std::map<Point, Stash>& stashes() const;
const std::map<Point, int>& symbols(unsigned char symbol) const;
bool isCompletelyOpen() const;
Expand All @@ -39,7 +47,9 @@ class Level {
void setDirtyStash(const Point& point);
void setDungeonSymbol(const Point& point, unsigned char symbol);
void setDungeonSymbolValue(const Point& point, int value);
void setMonster(const Point& point, const Monster& monster);
static void setFarlookResults(const std::map<Point, std::string>& farlooks);
static void clearFarlookData();
std::vector<Point> farlooksNeeded();
void increaseAdjacentSearchCount(const Point& point, int count = 1);

private:
Expand All @@ -54,9 +64,13 @@ class Level {
static bool _got_pickup_menu;
static bool _got_drop_menu;
static Tile _outside_map;
static std::map<Point,std::string> _turn_farlooks;
static unsigned _farlooked_turn;
static Coordinate _prev_position;
int _level;
Tile _map[MAP_ROW_END + 1][MAP_COL_END + 1];
std::map<Point, Monster> _monsters;
std::map<Point, Monster*> _monsters;
std::set<Point> _monster_points;
std::map<Point, Stash> _stashes;
std::map<Point, int> _symbols[UCHAR_MAX + 1];
std::string _name;
Expand All @@ -67,7 +81,9 @@ class Level {
bool _new_level;

void updateMapPoint(const Point& point, unsigned char symbol, int color);
void updateLight(const Point& point);
void updateMonsters();
bool parseFarlook(Point c, bool& shopkeeper, bool& priest, int& attitude, std::string& name, const data::Monster*& data);
void updatePathMap();
void updatePathMapSetCost(const Point& to, const Tile& prev);
unsigned int updatePathMapCalculateCost(const Tile& next, const Tile& prev);
Expand Down
39 changes: 36 additions & 3 deletions include/Monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@
#define MONSTER_H

#include "Globals.h"
#include "Coordinate.h"

#include <string>
#include <map>

namespace data {
class Monster;
}

// Number of turns to remember a monster's movement pattern for. This is probably overkill; 6 suffices to find the movement holes for a soldier under good conditions
#define MOVE_MEMORY 20

class Monster {
public:
Monster(unsigned char symbol = ILLEGAL_MONSTER, int color = 0, int last_seen = -1);
Monster(const std::string& id);

const std::string& id() const;
unsigned char symbol() const;
unsigned char symbol(unsigned char symbol);
int color() const;
Expand All @@ -20,25 +28,50 @@ class Monster {
int attitude() const;
int attitude(int attitude);
int lastSeen() const;
int lastSeen(int last_seen);
int lastMoved() const;
int lastMoved(int last_moved);
Coordinate lastSeenPos() const;
void observed(const Coordinate& in);
int observedTurn() const;
int maxMovesThisTurn() const;
bool called() const;
bool called(bool called);
bool shopkeeper() const;
bool shopkeeper(bool shopkeeper);
bool priest() const;
bool priest(bool priest);
const data::Monster* data() const;
const data::Monster* data(const data::Monster* data);

static std::map<std::string, Monster*>& byID();
static std::multimap<int, Monster*>& byLastSeen();

private:
// uniquely identifies this monster. if G_UNIQ, will be the monster's own identity,
// either as a typename or a shkname, otherwise will be an integer.
std::string _id;
unsigned char _symbol;
int _color;
bool _visible;
int _attitude;
int _last_seen;
int _last_moved;
int _observed_turn;
int _observed_subturn;
int _movehist[MOVE_MEMORY];
Coordinate _last_seen_pos;
// has the monster been 'C'alled with its _id? always true for G_UNIQ
bool _called;
bool _shopkeeper;
bool _priest;
const data::Monster* _data;

void index();
void unindex();

static int _next_id;
// all Monster objects in the game are owned by this map; everyone else just holds pointers
// XXX: Level probably shouldn't be holding pointers. Probably code which uses Level's access should use our maps instead
static std::map<std::string, Monster*> _by_id;
static std::multimap<int, Monster*> _by_last_seen;
};
#endif
7 changes: 7 additions & 0 deletions include/Saiph.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Saiph {
static bool engulfed();
static bool engulfed(bool engulfed);
static bool inAPit();
static bool infravision();
static int skill(int which);
static int maxSkill(int which);
static void updateSkills(int* curp);
Expand All @@ -73,6 +74,10 @@ class Saiph {
static const std::string& race();
static int role();
static int gender();
static int minSpeed();
static int maxSpeed();
static int minMovesThisTurn();
static int minMovesThisTurn(int min);

private:
/* attributes */
Expand Down Expand Up @@ -128,5 +133,7 @@ class Saiph {
static int _gender;
/* for parsing effects */
static char _effects[MAX_EFFECTS][MAX_TEXT_LENGTH];
/* set by World to the number of guaranteed moves this turn */
static int _min_moves_this_turn;
};
#endif
3 changes: 3 additions & 0 deletions include/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Tile {
unsigned int search() const;
unsigned int search(unsigned int search);
unsigned int searchInc(int count = 1);
int lit() const;
int lit(int lit);
unsigned char symbol() const;
unsigned char symbol(unsigned char symbol);
void updatePath(unsigned char direction, unsigned int distance, unsigned int cost);
Expand All @@ -36,6 +38,7 @@ class Tile {
unsigned int _distance; // distance to this tile when on same level
unsigned int _cost; // cost to this tile when on same level
unsigned int _updated; // last internal turn this node was updated, used for pathing
int _lit; // -1 if unknown else 0 or 1
};

std::ostream& operator<<(std::ostream& os, const Tile& t);
Expand Down
10 changes: 8 additions & 2 deletions include/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class World {
static bool question();
static int curPage();
static int maxPage();
static int turn();
static unsigned int internalTurn();
static int turn(); // corresponds to monster_moves and the T: counter
static unsigned int internalTurn(); // monotonically increases but corresponds to nothing in nethack
static int subTurn(); // index of current move in current turn() or -1 if unknown
static const std::vector<Point>& changes();
static void forgetChanges();
static const Coordinate& branchCoordinate(int branch);
Expand All @@ -53,6 +54,7 @@ class World {
static const std::vector<Level>& levels();
static int currentPriority();
static action::Action* lastAction();
static std::string lastData();
static int lastActionID();
static void init(const std::string& logfile, int connection_type);
static void destroy();
Expand Down Expand Up @@ -96,6 +98,9 @@ class World {
static int _cur_page;
static int _max_page;
static int _turn;
static int _sub_turn;
static int _min_saiph_energy;
static int _max_saiph_energy;
static std::vector<analyzer::Analyzer*> _analyzers;
static int _last_action_id;
static unsigned int _internal_turn;
Expand All @@ -112,6 +117,7 @@ class World {
static void drawNormal(void*, Level&, const Point&, unsigned char&, unsigned char&);
static void drawDirections(void*, Level&, const Point&, unsigned char&, unsigned char&);
static void drawCosts(void*, Level&, const Point&, unsigned char&, unsigned char&);
static void drawLight(void*, Level&, const Point&, unsigned char&, unsigned char&);

static void dumpMap(Level& which);
static void dumpMaps();
Expand Down
4 changes: 2 additions & 2 deletions nethackrc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ OPTIONS=gender:random
OPTIONS=hilite_pet
OPTIONS=horsename:futilius
OPTIONS=!legacy
OPTIONS=lit_corridor
OPTIONS=!lit_corridor
OPTIONS=!mail
OPTIONS=menustyle:partial
OPTIONS=monsters:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@X'&;:~m
Expand All @@ -60,7 +60,7 @@ OPTIONS=pettype:none
OPTIONS=pickup_burden:Overloaded
OPTIONS=pickup_types:$
OPTIONS=!prayconfirm
OPTIONS=race:human
OPTIONS=race:dwarf
OPTIONS=role:valk
OPTIONS=runmode:teleport
OPTIONS=!sparkle
Expand Down
17 changes: 14 additions & 3 deletions patches/situation.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- nethack-3.4.3-orig/src/allmain.c 2003-12-07 15:39:13.000000000 -0800
+++ nethack-3.4.3/src/allmain.c 2011-04-20 13:11:53.000000000 -0700
@@ -477,6 +477,239 @@
+++ nethack-3.4.3/src/allmain.c 2011-08-09 21:15:13.000000000 -0700
@@ -477,6 +477,250 @@
}

void
Expand Down Expand Up @@ -38,6 +38,11 @@
+ } else if (!strncmp(lbuf, "skill ", 6)) {
+ sscanf(lbuf, "skill %d %d", &a[0], &a[1]);
+ P_SKILL(a[0]) = a[1];
+ } else if (!strncmp(lbuf, "skillx ", 7)) {
+ sscanf(lbuf, "skillx %d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
+ P_SKILL(a[0]) = a[1];
+ P_MAX_SKILL(a[0]) = a[2];
+ P_ADVANCE(a[0]) = a[3];
+ } else if (!strncmp(lbuf, "blind ", 6)) {
+ sscanf(lbuf, "blind %d", &i);
+ make_blinded(i, FALSE);
Expand Down Expand Up @@ -126,6 +131,9 @@
+ } else if (!strncmp(lbuf, "at ", 3)) {
+ sscanf(lbuf, "at %d %d", &a[0], &a[1]);
+ u.ux = a[0]; u.uy = a[1];
+ } else if (!strncmp(lbuf, "mkroom ", 7)) {
+ sscanf(lbuf, "mkroom %d", &i);
+ mkroom(i);
+ } else if (!strncmp(lbuf, "room ", 5)) {
+ sscanf(lbuf, "room %d %d %d %d %d %d",
+ &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]);
Expand All @@ -147,6 +155,9 @@
+ } else if (!strncmp(lbuf, "fountain ", 9)) {
+ sscanf(lbuf, "fountain %d %d", &a[0], &a[1]);
+ levl[a[0]][a[1]].typ = FOUNTAIN;
+ } else if (!strncmp(lbuf, "trap ", 5)) {
+ sscanf(lbuf, "trap %d %d %d", &a[0], &a[1], &a[2]);
+ maketrap(a[0], a[1], a[2]);
+ } else if (!strncmp(lbuf, "obj ", 4)) {
+ lbuf[strlen(lbuf)-1] = 0;
+ sscanf(lbuf, "obj %d %d %n", &a[0], &a[1], &i);
Expand Down Expand Up @@ -240,7 +251,7 @@
newgame()
{
int i;
@@ -514,6 +747,7 @@
@@ -514,6 +758,7 @@

mklev();
u_on_upstairs();
Expand Down
Loading

0 comments on commit 50e0c93

Please sign in to comment.