void tm_rect_generate_overlapping( tm_rect_t* r, tm_rect_t* overlap_r, tm_vect_t* sz, vect_t* map_sz ) { tm_vect_t* unit = tm_vect_create(1, 1); tm_rect_t aux_r; tm_vect_substract( &overlap_r->v1, sz, &aux_r.v1 ); tm_vect_add( &aux_r.v1, unit, &aux_r.v1 ); if( (int) aux_r.v1.x < 0 ) aux_r.v1.x = 0; if( (int) aux_r.v1.y < 0 ) aux_r.v1.y = 0; tm_vect_substract( &overlap_r->v2, unit, &aux_r.v2 ); tm_vect_add( &aux_r.v2, sz, &aux_r.v2 ); if( (int) aux_r.v2.x > map_sz->x ) aux_r.v2.x = map_sz->x; if( (int) aux_r.v2.y > map_sz->y ) aux_r.v2.y = map_sz->y; assert( rect_is_valid(&aux_r) ); tm_vect_init( &r->v1, rand_range((int)aux_r.v1.x, (int)aux_r.v2.x), rand_range((int)aux_r.v1.y, (int)aux_r.v2.y) ); tm_vect_add( &r->v1, sz, &r->v2 ); tm_vect_destroy( unit ); }
int tm_entity_stationary_position_is_valid( tm_entity_stationary_t* ent, vect_t* map_sz ) { vect_t aux; if( !vect_is_positive( &ent->size ) ) return 0; if( !rect_is_positive( &ent->r ) ) return 0; if( !rect_is_valid( &ent->r ) ) return 0; aux.x = map_sz->x - ent->r.v2.x; aux.y = map_sz->y - ent->r.v2.y; if( !vect_is_positive( &aux ) ) return 0; aux.x = ent->r.v2.x - ent->r.v1.x; aux.y = ent->r.v2.y - ent->r.v1.y; if( !vect_is_eq( &ent->size, &aux ) ) return 0; return 1; }
void msg_line_init(const rect_t *display_rect) { if (display_rect && rect_is_valid(display_rect)) { if (_msg_line_doc) { msg_line_clear(); doc_free(_msg_line_doc); } _msg_line_rect = *display_rect; if (_msg_line_rect.x + _msg_line_rect.cx > Term->wid) _msg_line_rect.cx = Term->wid - _msg_line_rect.x; _msg_line_doc = doc_alloc(_msg_line_rect.cx); _msg_line_sync_pos = doc_cursor(_msg_line_doc); } else { rect_t r = rect_create(0, 0, MIN(72, Term->wid - 13), 10); msg_line_init(&r); } }