Example #1
0
void Screen::PrintInv(WINDOW * const window, Inventory * const inv) const {
	werase(window);
	wstandend(window);
	switch ( inv->Kind() ) {
		case DWARF:
			mvwaddstr(window, 2, 7, "Head\n Right hand\n  ");
			waddstr(window, "Left hand\n       Body\n       ");
			waddstr(window, "Legs");
		break;
		case WORKBENCH: mvwaddstr(window, 2, 4, "Product"); break;
	}
	mvwprintw(window, 2+inv->Size(), 40, "All weight: %6hu mz",
		inv->Weight());
	QString str;
	for (ushort i=0; i<inv->Size(); ++i) {
		mvwprintw(window, 2+i, 12, "%c)", 'a'+i);
		if ( inv->Number(i) ) {
			wcolor_set(window, Color(inv->GetInvKind(i),
				inv->GetInvSub(i)), NULL);
			wprintw(window, "[%c]%s",
					CharName( inv->GetInvKind(i),
						inv->GetInvSub(i) ),
					qPrintable(inv->InvFullName(str, i)) );
			if ( 1<inv->Number(i) ) {
				waddstr(window,
					qPrintable(inv->NumStr(str, i)));
			}
			if ( ""!=inv->GetInvNote(str, i) ) {
				waddstr(window,
					qPrintable((" ~:"+(( str.size()<24 ) ?
						str : str.left(13)+"..."))));
			}
			wstandend(window);
			mvwprintw(window, 2+i, 53, "%5hu mz",
				inv->GetInvWeight(i));
		}
	}
	wcolor_set(window, Color(inv->Kind(), inv->Sub()), NULL);
	box(window, 0, 0);
	(void)wmove(window, 0, 1);
	if ( player->PlayerInventory()==inv ) {
		wprintw(window, "[%c]Your inventory",
			CharName(inv->Kind(), inv->Sub()));
	} else {
		wprintw(window, "[%c]%s",
			CharName(inv->Kind(), inv->Sub()),
			qPrintable(inv->FullName(str)));
	}
	wnoutrefresh(window);
}
Example #2
0
double Joint::total_com(fVec3& com, const char* chname)
{
	if(!this) return 0.0;
	int is_target = false;
	if(!chname)
	{
		is_target = true;
	}
	else
	{
		char* my_chname = CharName();
		if(my_chname && !strcmp(my_chname, chname))
		{
			is_target = true;
		}
	}
	fVec3 b_com, c_com;
	b_com.zero();
	c_com.zero();
	double ret = brother->total_com(b_com, chname) + child->total_com(c_com, chname);

	com.add(b_com, c_com);
	if(is_target)
	{
		static fVec3 abs_com_pos, my_com;
		ret += mass;
		abs_com_pos.mul(abs_att, loc_com);
		abs_com_pos += abs_pos;
		my_com.mul(abs_com_pos, mass);
		com += my_com;
	}
	return ret;
}
Example #3
0
void Screen::PrintBlock(
		const ushort x, const ushort y, const ushort z,
		WINDOW * const window)
const {
	Block * const block=w->GetBlock(x, y, z);
	const int kind=block->Kind();
	const int sub =block->Sub();
	wcolor_set(window, Color(kind, sub), NULL);
	waddch(window, CharName(kind, sub));
}
Example #4
0
Joint* Joint::find_joint(const char* n, const char* charname)
{
	if(!this) return NULL;
	if(charname)
	{
		char* mych = CharName();
		if(mych
		   && !strcmp(basename, n)
		   && !strcmp(mych, charname)) return this;
	}
	else
	{
		if(!strcmp(name, n)) return this;
	}
	Joint* ret;
	if((ret = child->find_joint(n, charname))) return ret;
	if((ret = brother->find_joint(n, charname))) return ret;
	return NULL;
}
Example #5
0
void Screen::PrintFront(WINDOW * const window) const {
	const int dir=player->Dir();
	if ( UP==dir || DOWN==dir ) {
		wstandend(window);
		werase(window);
		box(window, 0, 0);
		mvwaddstr(window, 0, 1, "No view");
		wnoutrefresh(window);
		return;
	}
	short x_step, z_step,
	      x_end, z_end,
	      * x, * z,
	      i, j, k;
	const ushort pX=player->X();
	const ushort pY=player->Y();
	const ushort pZ=player->Z();
	const ushort begin_x = ( pX/SHRED_WIDTH )*SHRED_WIDTH +
		( SHRED_WIDTH-SCREEN_SIZE )/2;
	const ushort begin_y = ( pY/SHRED_WIDTH )*SHRED_WIDTH +
		( SHRED_WIDTH-SCREEN_SIZE )/2;
	ushort x_start, z_start, k_start;
	ushort arrow_Y, arrow_X;
	switch ( dir ) {
		case NORTH:
			x=&i;
			x_step=1;
			x_start=begin_x;
			x_end=x_start+SCREEN_SIZE;
			z=&j;
			z_step=-1;
			z_start=pY-1;
			z_end=pY-SHRED_WIDTH-1;
			arrow_X=(pX-begin_x)*2+1;
		break;
		case SOUTH:
			x=&i;
			x_step=-1;
			x_start=SCREEN_SIZE-1+begin_x;
			x_end=begin_x-1;
			z=&j;
			z_step=1;
			z_start=pY+1;
			z_end=pY+SHRED_WIDTH+1;
			arrow_X=(SCREEN_SIZE-pX+begin_x)*2-1;
		break;
		case WEST:
			x=&j;
			x_step=-1;
			x_start=SCREEN_SIZE-1+begin_y;
			x_end=begin_y-1;
			z=&i;
			z_step=-1;
			z_start=pX-1;
			z_end=pX-SHRED_WIDTH-1;
			arrow_X=(SCREEN_SIZE-pY+begin_y)*2-1;
		break;
		case EAST:
			x=&j;
			x_step=1;
			x_start=begin_y;
			x_end=SCREEN_SIZE+begin_y;
			z=&i;
			z_step=1;
			z_start=pX+1;
			z_end=pX+SHRED_WIDTH+1;
			arrow_X=(pY-begin_y)*2+1;
		break;
		default:
			fprintf(stderr,
				"Screen::PrintFront(WINDOW *): \
				unlisted dir: %d\n",
				(int)dir);
			return;
	}
	if ( pZ+SCREEN_SIZE/2>=HEIGHT ) {
		k_start=HEIGHT-2;
		arrow_Y=HEIGHT-pZ;
	} else if ( pZ-SCREEN_SIZE/2<0 ) {
		k_start=SCREEN_SIZE-1;
		arrow_Y=SCREEN_SIZE-pZ;
	} else {
		k_start=pZ+SCREEN_SIZE/2;
		arrow_Y=SCREEN_SIZE/2+1;
	}
	const int block_side=w->Anti(dir);
	(void)wmove(window, 1, 1);
	for (k=k_start; k_start-k<SCREEN_SIZE; --k, waddstr(window, "\n_")) {
		for (*x=x_start; *x!=x_end; *x+=x_step) {
			for (*z=z_start; *z!=z_end; *z+=z_step)
				if ( w->Transparent(i, j, k) != INVISIBLE ) {
					if ( (w->Enlightened(i, j, k,
							block_side) &&
							player->
							Visible(i, j, k)) ||
							player->
							GetCreativeMode() )
					{
						PrintBlock(i, j, k, window);
						waddch(window,
							CharNumberFront(i, j));
					} else {
						wstandend(window);
						waddch(window, OBSCURE_BLOCK);
						waddch(window, ' ');
					}
					break;
				}
			if ( *z==z_end ) { //far decorations
				*z-=z_step;
				if ( player->Visible(i, j, k ) ) {
					wcolor_set(window, Color(BLOCK, SKY),
						NULL);
					waddch(window, CharName(BLOCK, SKY));
				} else {
					wstandend(window);
					waddch(window, OBSCURE_BLOCK);
				}
				waddch(window, ' ');
			}
		}
	}
	wstandend(window);
	box(window, 0, 0);
	switch ( dir ) {
		case NORTH: mvwaddstr(window, 0, 1, "North view"); break;
		case SOUTH: mvwaddstr(window, 0, 1, "South view"); break;
		case EAST:  mvwaddstr(window, 0, 1, "East view");  break;
		case WEST:  mvwaddstr(window, 0, 1, "West view");  break;
	}
	Arrows(window, arrow_X, arrow_Y);
	if ( shiftFocus ) {
		HorizontalArrows(window, arrow_Y-=shiftFocus, WHITE_BLUE);
	}
	wnoutrefresh(window);
}
Example #6
0
void Screen::Print() {
	w->ReadLock();

	if ( updated || !player ) {
		w->Unlock();
		return;
	}
	updated=true;

	switch ( player->UsingType() ) {
		case OPEN:
			PrintInv(rightWin,
				player->UsingBlock()->HasInventory());
			break;
		default: PrintFront(rightWin);
	}
	switch ( player->UsingSelfType() ) {
		case OPEN:
			if ( player->PlayerInventory() ) {
				PrintInv(leftWin,
					player->PlayerInventory());
				break;
			} //no break;
		default: PrintNormal(leftWin);
	}

	const short dur=player->HP();
	const short breath=player->Breath();
	const short satiation=player->Satiation();

	werase(hudWin);
	ushort i;
	//quick inventory
	Inventory * const inv=player->GetP() ?
		player->GetP()->HasInventory() : 0;
	if ( inv ) {
		for (i=0; i<inv->Size(); ++i) {
			wstandend(hudWin);
			const int x=36+i*2;
			mvwaddch(hudWin, 0, x, 'a'+i);
			if ( inv->Number(i) ) {
				wcolor_set(hudWin,
					Color( inv->GetInvKind(i),
						inv->GetInvSub(i) ), NULL);
				mvwaddch(hudWin, 1, x,
					CharName( inv->GetInvKind(i),
						inv->GetInvSub(i) ));
				mvwprintw(hudWin, 2, x, "%hu", inv->Number(i));
			}
		}
	}

	w->Unlock();

	wstandend(leftWin);
	QString str;
	if ( -1!=dur ) { //HitPoints line
		str=QString("%1").arg(dur, -10, 10, QChar('.'));
		mvwaddstr(leftWin, SCREEN_SIZE+1, 1, "HP[..........]");
		wcolor_set(leftWin, WHITE_RED, NULL);
		mvwaddstr(leftWin, SCREEN_SIZE+1, 4,
			qPrintable(str.left(10*dur/MAX_DURABILITY+1)));
		wstandend(leftWin);
	}
	if ( -1!=breath ) { //breath line
		str=QString("%1").arg(breath, -10, 10, QChar('.'));
		mvwaddstr(leftWin, SCREEN_SIZE+1, SCREEN_SIZE*2-13,
			"BR[..........]");
		wcolor_set(leftWin, WHITE_BLUE, NULL);
		mvwaddstr(leftWin, SCREEN_SIZE+1, SCREEN_SIZE*2-13+3,
			qPrintable(str.left(10*breath/MAX_BREATH+1)));
	}
	//action mode
	(void)wmove(hudWin, 0, 0);
	wstandend(hudWin);
	waddstr(hudWin, "Action: ");
	switch ( actionMode ) {
		case USE:      waddstr(hudWin, "Use in inventory"); break;
		case THROW:    waddstr(hudWin, "Throw"); break;
		case OBTAIN:   waddstr(hudWin, "Obtain"); break;
		case WIELD:    waddstr(hudWin, "Wield"); break;
		case INSCRIBE: waddstr(hudWin, "Inscribe in inventory"); break;
		case EAT:      waddstr(hudWin, "Eat"); break;
		case BUILD:    waddstr(hudWin, "Build"); break;
		case CRAFT:    waddstr(hudWin, "Craft"); break;
		case TAKEOFF:  waddstr(hudWin, "Take off"); break;
		default:       waddstr(hudWin, "Unknown");
			fprintf(stderr,
				"Screen::Print: Unlisted actionMode: %d\n",
				actionMode);
	}
	if ( -1!=satiation ) { //satiation line
		(void)wmove(hudWin, 1, 0);
		if ( SECONDS_IN_DAY<satiation ) {
			wcolor_set(hudWin, BLUE_BLACK, NULL);
			waddstr(hudWin, "Gorged");
		} else if ( 3*SECONDS_IN_DAY/4<satiation ) {
			wcolor_set(hudWin, GREEN_BLACK, NULL);
			waddstr(hudWin, "Full");
		} else if (SECONDS_IN_DAY/4>satiation) {
			wcolor_set(hudWin, RED_BLACK, NULL);
			waddstr(hudWin, "Hungry");
		}
	}
	//shifted focus
	wstandend(hudWin);
	if ( shiftFocus ) {
		mvwaddstr(hudWin, 0, 100, ( -1==shiftFocus ) ?
			"Focus shift down" : "Focus shift up");
	}
	if ( player->GetCreativeMode() ) {
		mvwaddstr(leftWin, SCREEN_SIZE+1, 1, "Creative Mode");
		//coordinates
		mvwprintw(hudWin, 1, 0, "xyz: %hu, %hu, %hu. XY: %ld, %ld",
			player->X(), player->Y(), player->Z(),
			player->GetLatitude(), player->GetLongitude());
		wcolor_set(leftWin, BLACK_WHITE, NULL);
		switch ( player->Dir() ) {
			case NORTH:
				mvwaddstr(leftWin, SCREEN_SIZE+1,
					SCREEN_SIZE*2-8, "^ North ^");
			break;
			case SOUTH:
				mvwaddstr(leftWin, SCREEN_SIZE+1,
					SCREEN_SIZE*2-8, "v South v");
			break;
			case EAST:
				mvwaddstr(leftWin, SCREEN_SIZE+1,
					SCREEN_SIZE*2-8, ">   East>");
			break;
			case WEST:
				mvwaddstr(leftWin, SCREEN_SIZE+1,
					SCREEN_SIZE*2-8, "<West   <");
			break;
		}
	} else if ( player->GetP() && player->GetP()->IsFalling() ) {
			mvwaddstr(hudWin, 2, 0, "Falling!");
	}
	wnoutrefresh(hudWin);
	wnoutrefresh(leftWin);
	doupdate();
}