players.c
changeset 2697 97fc22baf3da
parent 2684 4df784e4be66
child 2755 ba133949851b
equal deleted inserted replaced
2696:e33a073f7211 2697:97fc22baf3da
   463 }
   463 }
   464 
   464 
   465 Player *DoStartupNewPlayer(bool is_ai)
   465 Player *DoStartupNewPlayer(bool is_ai)
   466 {
   466 {
   467 	Player *p;
   467 	Player *p;
   468 	int i;
       
   469 
   468 
   470 	p = AllocatePlayer();
   469 	p = AllocatePlayer();
   471 	if (p == NULL)
   470 	if (p == NULL)
   472 		return NULL;
   471 		return NULL;
   473 
   472 
   486 	p->avail_railtypes = GetPlayerRailtypes(p->index);
   485 	p->avail_railtypes = GetPlayerRailtypes(p->index);
   487 	p->inaugurated_year = _cur_year;
   486 	p->inaugurated_year = _cur_year;
   488 	p->face = Random();
   487 	p->face = Random();
   489 
   488 
   490 	/* Engine renewal settings */
   489 	/* Engine renewal settings */
   491 	for (i = 0; i < TOTAL_NUM_ENGINES; i++)
   490 	InitialiseEngineReplacement(p);
   492 		p->engine_replacement[i] = INVALID_ENGINE;
       
   493 
       
   494 	p->renew_keep_length = false;
   491 	p->renew_keep_length = false;
   495 	p->engine_renew = false;
   492 	p->engine_renew = false;
   496 	p->engine_renew_months = -6;
   493 	p->engine_renew_months = -6;
   497 	p->engine_renew_money = 100000;
   494 	p->engine_renew_money = 100000;
   498 
   495 
   729 					return CMD_ERROR;
   726 					return CMD_ERROR;
   730 
   727 
   731 				// make sure that the player can actually buy the new engine
   728 				// make sure that the player can actually buy the new engine
   732 				if (!HASBIT(GetEngine(new_engine_type)->player_avail, _current_player))
   729 				if (!HASBIT(GetEngine(new_engine_type)->player_avail, _current_player))
   733 					return CMD_ERROR;
   730 					return CMD_ERROR;
   734 			}
   731 
   735 
   732 				return AddEngineReplacement(p, old_engine_type, new_engine_type, flags);
   736 			if (flags & DC_EXEC) {
   733 			} else {
   737 				p->engine_replacement[old_engine_type] = new_engine_type;
   734 				return RemoveEngineReplacement(p, old_engine_type, flags);
   738 			}
   735 			}
   739 		} break;
   736 		} break;
   740 		case 4:
   737 		case 4:
   741 			if (flags & DC_EXEC) {
   738 			if (flags & DC_EXEC) {
   742 				p->engine_renew = (bool)GB(p1, 15, 1);
   739 				p->engine_renew = (bool)GB(p1, 15, 1);
  1098 
  1095 
  1099 	/* Initialize end of game variable (when to show highscore chart) */
  1096 	/* Initialize end of game variable (when to show highscore chart) */
  1100 	 _patches.ending_date = 2051;
  1097 	 _patches.ending_date = 2051;
  1101 }
  1098 }
  1102 
  1099 
       
  1100 void InitialiseEngineReplacement(Player *p)
       
  1101 {
       
  1102 	EngineID engine;
       
  1103 
       
  1104 	for (engine = 0; engine < TOTAL_NUM_ENGINES; engine++)
       
  1105 		p->engine_replacement[engine] = INVALID_ENGINE;
       
  1106 }
       
  1107 
       
  1108 /**
       
  1109  * Retrieve the engine replacement for the given player and original engine type.
       
  1110  * @param p Player.
       
  1111  * @param engine Engine type.
       
  1112  * @return Assigned replacement engine.
       
  1113  */
       
  1114 EngineID EngineReplacement(const Player *p, EngineID engine)
       
  1115 {
       
  1116 	return p->engine_replacement[engine];
       
  1117 }
       
  1118 
       
  1119 /**
       
  1120  * Check if an engine has a replacement set up.
       
  1121  * @param p Player.
       
  1122  * @param engine Engine type.
       
  1123  * @return True if there is a replacement for the original engine type.
       
  1124  */
       
  1125 bool EngineHasReplacement(const Player *p, EngineID engine)
       
  1126 {
       
  1127 	return EngineReplacement(p, engine) != INVALID_ENGINE;
       
  1128 }
       
  1129 
       
  1130 /**
       
  1131  * Add an engine replacement for the player.
       
  1132  * @param p Player.
       
  1133  * @param old_engine The original engine type.
       
  1134  * @param new_engine The replacement engine type.
       
  1135  * @param flags The calling command flags.
       
  1136  * @return 0 on success, CMD_ERROR on failure.
       
  1137  */
       
  1138 int32 AddEngineReplacement(Player *p, EngineID old_engine, EngineID new_engine, uint32 flags)
       
  1139 {
       
  1140 	if (flags & DC_EXEC) p->engine_replacement[old_engine] = new_engine;
       
  1141 	return 0;
       
  1142 }
       
  1143 
       
  1144 /**
       
  1145  * Remove an engine replacement for the player.
       
  1146  * @param p Player.
       
  1147  * @param engine The original engine type.
       
  1148  * @param flags The calling command flags.
       
  1149  * @return 0 on success, CMD_ERROR on failure.
       
  1150  */
       
  1151 int32 RemoveEngineReplacement(Player *p, EngineID engine, uint32 flags)
       
  1152 {
       
  1153 	if (flags & DC_EXEC) p->engine_replacement[engine] = INVALID_ENGINE;
       
  1154 	return 0;
       
  1155 }
       
  1156 
  1103 // Save/load of players
  1157 // Save/load of players
  1104 static const SaveLoad _player_desc[] = {
  1158 static const SaveLoad _player_desc[] = {
  1105 	SLE_VAR(Player,name_2,					SLE_UINT32),
  1159 	SLE_VAR(Player,name_2,					SLE_UINT32),
  1106 	SLE_VAR(Player,name_1,					SLE_STRINGID),
  1160 	SLE_VAR(Player,name_1,					SLE_STRINGID),
  1107 
  1161