예제 #1
0
boolean Thought_Bubble::dump(output_stream &stream, boolean just_prepare, boolean , boolean ) {
   if (just_prepare) return(FALSE);
   int dump_index = about_to_dump(this,stream); // rewritten on 020802
	if (dump_index < 0) return(FALSE); // new on 051099
#if TT_DEBUG_ON
	if (tt_debug_mode == 160299 && !tt_dumping_to_test_equality_or_describe) {
		print_spaces(min(tt_debug_dump_depth,max_debug_depth),tt_error_file());
		tt_error_file() << "About to dump ";
		print(tt_error_file());
		tt_error_file() << endl;
		tt_debug_dump_depth++;
	};
#endif
   if (cubby != NULL) { // && cubby->pointer_to_leader() == this) {
		// changed to top_level_dump on 060201 since there should be no connections between stuff in the thought bubble and outside 
      cubby->top_level_dump(stream);
	} else if (robot->pointer_to_body() != NULL) { // a bit of a hack to distinguish trained robots with empty thought bubbles from untrained ones
		stream.put(NOTHING_MARKER);
	} else {
		stream.put((char) NONE_GIVEN);
	};
#if TT_DEBUG_ON
	if (tt_debug_mode == 160299 && !tt_dumping_to_test_equality_or_describe) {
		print_spaces(min(tt_debug_dump_depth,max_debug_depth),tt_error_file());
		tt_error_file() << "Finished dumping ";
		print(tt_error_file());
		tt_error_file() << endl;
		tt_debug_dump_depth--;
	};
#endif
	return(TRUE);
};
예제 #2
0
void Floor::dump(output_stream &stream, boolean just_prepare) {
   if (just_prepare) {
      if (items != NULL) items->dump(stream,FALSE,just_prepare);
      return;
   };
   stream.put(FLOOR_MARKER);
   if (items != NULL) {
		items->dump(stream,TRUE);
//      Sprites *sorted_items = sort_items(items); // commented out on 210100 since robots now save links to working cubby
		// commented out the following on 050100 since now if tt_toolbox is responsible it is dumped specially
//      if (tt_toolbox != NULL) {
//         Sprites *non_toolbox_items = NULL;
//         Sprites *remaining = items;
//         while (remaining != NULL) {
//            Sprite *sprite = remaining->first();
//            if (!toolbox_tool(sprite)) {
//              insert_at_end(sprite,non_toolbox_items);
//            };
//            remaining = remaining->rest();
//        };
//         sorted_items = sort_items(non_toolbox_items);
//         non_toolbox_items->remove_all();
//         delete non_toolbox_items;
//      } else {
//         sorted_items = sort_items(items);
//      };
//      if (sorted_items != NULL) {
//         sorted_items->dump(stream,TRUE);
//         sorted_items->remove_all();
//         delete sorted_items;
//      };
   };
   stream.put(END_OF_LIST_MARKER);
	stream.write((char *) &current_priority, sizeof(current_priority)); // new on 150100
};
예제 #3
0
void Room::dump(output_stream &stream, boolean just_prepare) {
   if (just_prepare) {
      if (wall_decoration != NULL) wall_decoration->dump(stream,just_prepare);
      if (items != NULL) {
			items->dump(stream,FALSE,just_prepare);
		};
      return;
   };
   stream.put(ROOM_MARKER);
   if (wall_decoration != NULL) {
//		wall_decoration->propagate_changes(); // new on 160601 to get offsets right
      wall_decoration->dump(stream);
		// rewrote the above on 090400 to get the geometry to save correctly
//		Sprite *wall_decoration_copy = wall_decoration->top_level_copy();
//		Sprites *remaining = wall_decoration_copy->pointer_to_followers();
//		while (remaining != NULL) {
//			Sprite *sprite = remaining->first();
//			sprite->move_by(-sprite->return_old_x_offset(),-sprite->return_old_y_offset());
//			remaining = remaining->rest();
//		};
//		wall_decoration_copy->dump(stream);
//		wall_decoration_copy->destroy();
		wall_decoration->set_ok_to_dump(FALSE); // i.e. not when items are dumped below - note this really means don't dump if part of a list - will still be dumped as decoration from here
   } else {
      stream.put(NOTHING_MARKER);
   };
//   Sprites *sorted_items = sort_items(items); // commented out on 210100 since robots now save links to working cubby
   if (items != NULL) {
		items->dump(stream,TRUE);
   };
//   if (sorted_items != NULL) {
//      sorted_items->dump(stream,TRUE);
//      sorted_items->remove_all();
//      delete sorted_items;
//   };
   stream.put(END_OF_LIST_MARKER);
};
예제 #4
0
파일: stream.cpp 프로젝트: zbigg/tinfra
void        write_all(output_stream& output, tstring const& data)
{
    using tinfra::fail;
    using tinfra::tsprintf;

    size_t to_write              = data.size();
    size_t buffer_to_write_index = 0;

    while( to_write > 0 ) {
        const int w = output.write(data.data() + buffer_to_write_index, to_write);
        if( to_write != 0 && w == 0 ) {
            fail(tsprintf("unable to save data, %i bytes left", to_write),
                 "write() unexpectedly returned 0");
        }
        to_write -= w;
        buffer_to_write_index += w;
    }
}
예제 #5
0
void service::get_map_rand_players(output_stream& stream, ROLE* role)
{
	auto iter = map_to_players.find(role->wLastFightMapID);
	if(iter == map_to_players.end())
	{
		stream.write_byte(0);
		return;
	}

	auto& ls = map_to_players[role->wLastFightMapID];
	if(ls.size() <= 4)
	{
		auto pos = stream.length();
		stream.write_byte((byte)0);
		
		byte count = 0;
		for(auto& item : ls)
		{
			auto target = RoleMgr::getMe().getRoleByID(item);
			if(target->dwRoleID == role->dwRoleID)continue;
			if(target == nullptr)continue;

			int reward_pkvalue;

			if(target->wLevel >= role->wLevel)
				reward_pkvalue = 10 + (target->wLevel - role->wLevel) * 2;
			else
			{
				reward_pkvalue = 10 - (role->wLevel - target->wLevel);
				if(reward_pkvalue < 1)reward_pkvalue = 1;
			}

			auto record = role->get_meet_pk_result(item, false);

			stream.write_uint(item);
			stream.write_string(target->roleName);
			stream.write_byte(target->byJob);
			stream.write_byte(target->bySex);
			stream.write_byte((byte)target->wLevel);
			stream.write_uint(target->dwFightValue);
			stream.write_byte(reward_pkvalue);
			stream.write_byte(record?(byte)record->result:0);
			count++;
		}
		stream.write_data((const char*)&count, 1, pos);
	}
	else
	{
		auto pos = stream.length();
		stream.write_byte((byte)0);
		set<int> used;
		int count = 0;
		while(1)
		{
			int index = 0;
			do
			{
				index = rand() % ls.size();
				if(used.find(index) == used.end())break;
			}while(1);

			used.insert(index);

			unsigned roleid = 0;
			auto iter = ls.begin();
			for(int i=0;i<index;i++)iter++;
			

			auto target = RoleMgr::getMe().getRoleByID(*iter);
			if(target->dwRoleID == role->dwRoleID)continue;
			if(target == nullptr)continue;
			auto record = target->get_meet_pk_result(target->dwRoleID, false);

			int reward_pkvalue;

			if(target->wLevel >= role->wLevel)
				reward_pkvalue = 10 + (target->wLevel - role->wLevel) * 2;
			else
			{
				reward_pkvalue = 10 - (role->wLevel - target->wLevel);
				if(reward_pkvalue < 1)reward_pkvalue = 1;
			}

			stream.write_uint(*iter);
			stream.write_string(target->roleName);
			stream.write_byte(target->byJob);
			stream.write_byte(target->bySex);
			stream.write_byte((byte)target->wLevel);
			stream.write_uint(target->dwFightValue);
			stream.write_byte(reward_pkvalue);
			stream.write_byte(record?(byte)record->result:0);
			count++;

			if(count>=4)break;
		}
		stream.write_data((const char*)&count, 1, pos);
	}
}