protoverse

A metaverse protocol
git clone git://jb55.com/protoverse
Log | Files | Refs | README | LICENSE

commit f87b7718b8506a257c3518319e89ebd06367ee5c
parent 4141930b82a49864b402eb19371b206eb77f0236
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  3 Jul 2020 09:59:56 -0700

object state

Diffstat:
Mdescribe.c | 48++++++++++++++++++++++++++++--------------------
Mparse.c | 4++++
Mparse.h | 7+++++++
Msatoshis-citadel.space | 2++
4 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/describe.c b/describe.c @@ -94,10 +94,14 @@ static int push_adjectives(struct describe *desc) continue; if (adjs > 0) { - if (adjs == adj_count-1) - push_word(desc->strs, "and"); - else if (adjs != adj_count-1) - push_str(desc->strs, ","); + if (adjs == adj_count-1) { + ok = push_word(desc->strs, "and"); + if (!ok) return 0; + } + else if (adjs != adj_count-1) { + ok = push_str(desc->strs, ","); + if (!ok) return 0; + } } @@ -191,7 +195,7 @@ static int describe_room(struct describe *desc) int ok; /* TODO: temp buffers for determining a(n) things */ - ok = push_str(desc->strs, "a(n)"); + ok = push_str(desc->strs, "There is a(n)"); if (!ok) return 0; ok = push_adjectives(desc); @@ -239,8 +243,18 @@ static int describe_amount(struct describe *desc, int nobjs) return 1; } -static int describe_object_name(struct cursor *strs, struct cell *cell) +static int describe_object_name(struct cursor *strs, struct cursor *attrs, struct cell *cell) { + int ok; + const char *name; + int name_len; + + cell_name(attrs, cell, &name, &name_len); + if (name_len > 0) { + ok = push_sized_word(strs, name, name_len); + if (!ok) return 0; + } + return push_word(strs, cell->type == C_OBJECT ? object_type_str(cell->obj_type) : cell_type_str(cell->type)); @@ -253,18 +267,6 @@ static int describe_group(struct describe *desc) nobjs = desc->cell->n_children; - ok = push_word(desc->strs, "There"); - if (!ok) return 0; - - if (nobjs == 1) { - ok = push_word(desc->strs, "is"); - if (!ok) return 0; - } - else { - ok = push_word(desc->strs, "are"); - if (!ok) return 0; - } - ok = describe_amount(desc, nobjs); ok = push_word(desc->strs, "object"); @@ -299,7 +301,7 @@ static int describe_group(struct describe *desc) } - ok = describe_object_name(desc->strs, cell); + ok = describe_object_name(desc->strs, desc->parsed->attributes, cell); if (!ok) return 0; } @@ -351,11 +353,17 @@ int describe_cells(struct cell *cell, struct parser *parsed, struct cursor *strs ok = describe_cell(cell, parsed, strs); if (!ok) return 0; - push_str(strs, ".\n"); + ok = push_str(strs, ".\n"); + if (!ok) return 0; if (cell->n_children == 0) return 1; + if (cell->type == C_ROOM || cell->type == C_SPACE) { + ok = push_word(strs, "It contains"); + if (!ok) return 0; + } + /* TODO: for each cell ? for now we just care about the group */ cell = get_cell(parsed->cells, cell->children[0]); assert(cell); diff --git a/parse.c b/parse.c @@ -52,6 +52,7 @@ static const char *attr_type_str(enum attribute_type type) case A_SHAPE: return "shape"; case A_TYPE: return "type"; case A_WIDTH: return "width"; + case A_STATE: return "state"; } return "unknown"; @@ -941,6 +942,9 @@ static int parse_attribute(struct token_cursor *tokens, struct attribute *attr) ok = parse_str_attr(&temp, attr, "location", A_LOCATION, T_SYMBOL); if (ok) goto close; + ok = parse_str_attr(&temp, attr, "state", A_STATE, T_SYMBOL); + if (ok) goto close; + ok = parse_size(&temp, attr); if (ok) goto close; diff --git a/parse.h b/parse.h @@ -46,6 +46,13 @@ enum attribute_type { A_HEIGHT, A_LOCATION, A_SHAPE, + A_STATE, +}; + +enum cell_state { + STATE_ON, + STATE_OFF, + STATE_SLEEPING, }; enum shape { diff --git a/satoshis-citadel.space b/satoshis-citadel.space @@ -17,4 +17,6 @@ (chair (id welcome-desk-chair) (name "fancy")) (light (location ceiling) + (name "ceiling") + (state off) (shape circle))))