Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request for sample_npc.h, sample_npc.c, genstruct.c, and default_room #639

Open
wants to merge 47 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a63893d
including npcs in spec room struct and functions
navila-luna May 24, 2020
ed85e23
made edits to have npc_t struct considered
navila-luna May 25, 2020
072a177
lets see
navila-luna Jun 1, 2020
b812938
saving sample_npc.c
navila-luna Jun 1, 2020
c40ae97
Merge remote-tracking branch 'origin/dev' into openworld/samples-npcs
dwahme Jun 1, 2020
ee9e84d
slight edits in autogeneration to include npcs
Jun 1, 2020
f95c171
added npcs in test, need to add room descriptions
Jun 3, 2020
c3a6f76
fixed errors in test_structs.c
Jun 5, 2020
045f5f4
Fixed errors in test_struct
Jun 5, 2020
909ffce
pushing
Jun 6, 2020
ef7c123
Merge branch 'dev' of https://github.com/uchicago-cs/chiventure into …
Jun 6, 2020
2c9cd61
fixed merge issues by simply deletin all and replacing it with Bryans…
Jun 6, 2020
b3e1486
look at autogenerate.c for my thought/confusion process
Jun 6, 2020
02bf49b
revamping npc structure and attempting integration into autogenerate
Jun 6, 2020
45cc244
successfully integrated default_npc into autogenerate. need to write …
Jun 6, 2020
abc268a
fixed merge conflict
Jun 6, 2020
3a15044
resolved merge conflicts
Jun 6, 2020
4d83aff
still need to fix test_autogenerate errors
Jun 7, 2020
a724869
Added tests and made default npcs hash-based
Jun 7, 2020
ac34586
Merge pull request #766 from uchicago-cs/openworld/autogenerate-bugs
carolinaecalderon Jun 7, 2020
1c82bd1
Fixed final tests
Jun 7, 2020
3efc5e7
Merge branch 'openworld/samples-npcs' of https://github.com/uchicago-…
Jun 7, 2020
b6786c5
Editing comments
navila-luna Jun 7, 2020
20ef151
rm since default_npcs is the updated duplicate
navila-luna Jun 7, 2020
daf6b6f
deleting the duplicate of samples-npcs file
Jun 7, 2020
baa8963
Merge branch 'openworld/samples-npcs' of https://github.com/uchicago-…
Jun 7, 2020
9854cfa
made some changes, will come back to more space comments
Jun 7, 2020
26027fd
went through all suggestions
Jun 7, 2020
4523676
minor changes
Jun 7, 2020
bbfd365
will fix comment issues in sample npc
Jun 7, 2020
2d742d3
changes to spaces
navila-luna Jun 7, 2020
5204f90
added on to comment tests and fixed spelling issue in .c file
Jun 7, 2020
d82a55d
fixed merge issue
Jun 7, 2020
6610d3f
made changes in npc functions, need one more fix
Jun 7, 2020
4519c71
I think everythings done!
Jun 8, 2020
c5159b2
Merge branch 'dev' into openworld/samples-npcs
navila-luna Jun 8, 2020
6f47f0f
went back for tabs issues
navila-luna Jun 8, 2020
c0bcacb
went back for tabs issues
navila-luna Jun 8, 2020
b46c5ce
went through for any spacing issues not seen before
navila-luna Jun 8, 2020
fb4dd03
fixed overlooked tabs
navila-luna Jun 8, 2020
768e26a
fixed overlooked tab issue
navila-luna Jun 8, 2020
2048461
fixed overlooks spacing issues
navila-luna Jun 8, 2020
4d43dc4
fixed tab issues
navila-luna Jun 8, 2020
9f4dea9
I really hope spacing issues are resolved
Jun 8, 2020
7865488
fixed merges and spaces thru astyles
Jun 8, 2020
d812be2
Merge branch 'dev' into openworld/samples-npcs
navila-luna Jun 8, 2020
204008d
Merge branch 'dev' into openworld/samples-npcs
navila-luna Jun 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion include/openworld/autogenerate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#include "game-state/game.h"
#include "gen_structs.h"
#include "default_rooms.h"
#include "default_npcs.h"

#define MAX_RAND_ITEMS (6)
#define MAX_NPCS (3)

/*
* path_exists_in_dir
Expand Down Expand Up @@ -160,6 +162,33 @@ item_hash_t *random_items(roomspec_t *room);
*/
int random_item_lookup(item_hash_t **dst, item_hash_t *src, int num_iters);

#endif /* INCLUDE_AUTOGENERATE_H */
/*
* random_npcs
* randomly selects a number of npcs in a room where the max NPCs in a room is 3
* Assumes that npcs are not automatically assigned to rooms
* Includes a NPC room description and then randomly generates
* a certain amount of generic, friendly, and hostile per room.
*
* parameters:
* - a roomspe_t that icnludes the type npc_t struct
* returns: type npc_t and a room npc description
*/
npc_t *random_npcs(roomspec_t *room);

/*
* random_npc_lookup
* Iterates through num_iters times to and copies the source item at most 3 times
* Helper function for random_npcs
*
* parameters:
* - item_hash_t *dst is where you want to store the npc you just found
* - item_hash_t *src is where you're looking up the npc
* - num_iters is how many times you'll iterate through src to settle on an npc
*
* returns:
* - Failure if the NPC is NULL or if the num_iters is 0
* - Success if NPC is not NULL and there's at least 1 num_iters.
*/
int random_npc_lookup(npc_t **dst, npc_t *src, int num_iters);

#endif /* INCLUDE_AUTOGENERATE_H */
60 changes: 60 additions & 0 deletions include/openworld/default_npcs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef _DEFAULT_NPCS_H
#define _DEFAULT_NPCS_H

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "game-state/game_state_common.h"

/*
* Classification of the type of NPC characters to be found
* within the rooms. Where friendly means NPC doesn't engage in fights,
* Hostile means engages in fights, and generic means can engage in fights
*/

typedef enum npc_classification {
NPC_GENERIC = -1,
NPC_HOSTILE = 0,
NPC_FRIENDLY = 1
} npc_classification_t;
navila-luna marked this conversation as resolved.
Show resolved Hide resolved


/* NPC mock struct that contains the bare minimum to add a NPC in a
* openworld room.Consists of player level, char *npc_name, NPC type, and item inventory
*/
typedef struct npc
{
char *npc_name;
int level;
item_hash_t *inventory;
npc_classification_t classification;
struct npc *next;
struct npc *prev;
UT_hash_handle hh;
} npc_t;

/* get_hostile_npcs
* Will get a linked list of hostile npcs and includes the items that
* each NPC carries with them makes 3 npcs that are hostile and return them
* as a linked list
*/
npc_t *get_hostile_npcs();
navila-luna marked this conversation as resolved.
Show resolved Hide resolved


/* get_friendly_npcs
* makes 3 npcs that are friendly and includes the items that
* each NPC carries with them.
* Return them as a hash list
*/
npc_t *get_friendly_npcs();
navila-luna marked this conversation as resolved.
Show resolved Hide resolved



/* get_generic_npcs
* makes 3 npcs that are generic
* Return them as a hash list
*/
npc_t *get_generic_npcs();
navila-luna marked this conversation as resolved.
Show resolved Hide resolved


#endif
2 changes: 1 addition & 1 deletion include/openworld/default_rooms.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ int copy_item_to_hash(item_hash_t **dst, item_hash_t *src, char *name);
* Output:
* - roomspec_t updated hash
*/
roomspec_t *make_default_room(char *bucket, char *sh_desc, char *l_desc);
roomspec_t *make_default_room( char *bucket, char *sh_desc, char *l_desc);
navila-luna marked this conversation as resolved.
Show resolved Hide resolved

#endif /* _DEFAULT_ROOM_H */
35 changes: 19 additions & 16 deletions include/openworld/gen_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <stdlib.h>
#include "game-state/game.h"
#include "game-state/game_state_common.h"
#include "default_npcs.h"

#ifndef GEN_STRUCTS_H
#define GEN_STRUCTS_H
Expand All @@ -30,15 +31,17 @@
* - char *long_desc: long description for room
* - int num_built: how many rooms of this type have been already built. An identifier.
* - item_hash_t *items: hash table of items in room
* - npc_t *npcs: doubly linked list of the npcs
* - UT_hash_handle hh: hash handle for room spec
*/
typedef struct roomspec {
char *room_name;
char *short_desc;
char *long_desc;
int num_built;
item_hash_t *items;
UT_hash_handle hh;
char *room_name;
char *short_desc;
char *long_desc;
int num_built;
item_hash_t *items;
npc_t *npcs;
UT_hash_handle hh;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all tabs- convert to spaces

} roomspec_t;

/* speclist_t struct
Expand All @@ -48,9 +51,9 @@ typedef struct roomspec {
* - speclist_t *next: pointer to the next part of the list.
*/
typedef struct speclist {
roomspec_t *spec;
struct speclist *prev;
struct speclist *next;
roomspec_t *spec;
struct speclist *prev;
struct speclist *next;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all tabs- convert to spaces

} speclist_t;

/* gencontext_t struct
Expand All @@ -62,10 +65,10 @@ typedef struct speclist {
* - speclist_t *speclist: the llist of roomspect_t that each hold the room info.
*/
typedef struct gencontext {
path_t *open_paths;
int num_open_paths;
int level;
speclist_t *speclist;
path_t *open_paths;
int num_open_paths;
int level;
speclist_t *speclist;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all tabs- convert to spaces

} gencontext_t;


Expand Down Expand Up @@ -135,7 +138,7 @@ int gencontext_free(gencontext_t *context);
* SUCCESS - for SUCCESS
* FAILURE - if failed to initialize
*/
int init_roomspec(roomspec_t *spec, char *room_name, char *short_desc, char *long_desc, item_hash_t *items);
int init_roomspec(roomspec_t *spec, char *room_name, char *short_desc, char *long_desc, item_hash_t *items, npc_t *npcs);

/* roomspec_new
* Creates a new roomspec_t* based off the given parameters.
Expand All @@ -150,7 +153,7 @@ int init_roomspec(roomspec_t *spec, char *room_name, char *short_desc, char *lon
* roomspec_t *roomspecnew - the new roomspec
* NULL - if fails to create a new roomspec.
*/
roomspec_t* roomspec_new(char *room_name, char *short_desc, char *long_desc, item_hash_t *items);
roomspec_t* roomspec_new(char *room_name, char *short_desc, char *long_desc, item_hash_t *items, npc_t *npcs);

/* roomspec_free
* Frees a gencontext_t* and returns whether or not it was succesful.
Expand Down Expand Up @@ -218,4 +221,4 @@ int speclist_free(speclist_t *list);
*/
int speclist_free_all(speclist_t *list);

#endif
#endif
1 change: 1 addition & 0 deletions src/openworld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_library(openworld
src/autogenerate.c
src/default_rooms.c
src/default_items.c
src/default_npcs.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all tabs- convert to spaces

src/gen_structs.c)

target_include_directories(openworld PRIVATE src/)
Expand Down
Loading