@@ -392,18 +392,22 @@ cw_box_add_substitute(CWBoxscore *boxscore, CWGameIterator *gameiter)
392392}
393393
394394/*
395- * Find the boxscore entry for player with ID player_id
395+ * Find the boxscore entry for player with ID player_id.
396+ * If batter is nonzero, search only for batting entries; this implements
397+ * the 'Ohtani rule' for DHes, in which a player who DHes for himself
398+ * has two identities within the game, one in the batting order and
399+ * one as the DHed-for pitcher.
396400 */
397401CWBoxPlayer *
398- cw_box_find_player (CWBoxscore * boxscore , char * player_id )
402+ cw_box_find_player (CWBoxscore * boxscore , char * player_id , int batter )
399403{
400404 int i , t ;
401405
402406 if (player_id == NULL ) {
403407 return NULL ;
404408 }
405409 for (t = 0 ; t <= 1 ; t ++ ) {
406- for (i = 0 ; i <= 9 ; i ++ ) {
410+ for (i = ( batter ) ? 1 : 0 ; i <= 9 ; i ++ ) {
407411 CWBoxPlayer * player = boxscore -> slots [i ][t ];
408412 while (player != NULL ) {
409413 if (!strcmp (player -> player_id , player_id )) {
@@ -616,7 +620,8 @@ cw_box_batter_stats(CWBoxscore *boxscore, CWGameIterator *gameiter)
616620 player = cw_box_find_player (boxscore ,
617621 cw_gamestate_charged_batter (gameiter -> state ,
618622 gameiter -> event -> batter ,
619- event_data ));
623+ event_data ),
624+ 1 );
620625 if (cw_event_is_batter (event_data ) && player == NULL ) {
621626 /* If not a batter event, we will be tolerant if the player ID
622627 * in the batter field is bogus.
@@ -1319,7 +1324,8 @@ cw_box_process_boxscore_file(CWBoxscore *boxscore, CWGame *game)
13191324 team = cw_data_get_item_int (stat , 2 );
13201325 seq = cw_data_get_item_int (stat , 3 );
13211326 pos = cw_data_get_item_int (stat , 4 );
1322- player = cw_box_find_player (boxscore , stat -> data [1 ]);
1327+ player = cw_box_find_player (boxscore , stat -> data [1 ],
1328+ (pos != 1 ) ? 1 : 0 );
13231329 if (player == NULL ) {
13241330 fprintf (stderr ,
13251331 "ERROR: In %s, cannot find entry for player '%s' listed in dline.\n" ,
@@ -1348,7 +1354,7 @@ cw_box_process_boxscore_file(CWBoxscore *boxscore, CWGame *game)
13481354 }
13491355 else if (!strcmp (stat -> data [0 ], "phline" )) {
13501356 team = cw_data_get_item_int (stat , 3 );
1351- player = cw_box_find_player (boxscore , stat -> data [1 ]);
1357+ player = cw_box_find_player (boxscore , stat -> data [1 ], 1 );
13521358 if (player == NULL ) {
13531359 fprintf (stderr ,
13541360 "ERROR: In %s, cannot find entry for player '%s' listed in phline.\n" ,
@@ -1359,7 +1365,7 @@ cw_box_process_boxscore_file(CWBoxscore *boxscore, CWGame *game)
13591365 }
13601366 else if (!strcmp (stat -> data [0 ], "prline" )) {
13611367 team = cw_data_get_item_int (stat , 3 );
1362- player = cw_box_find_player (boxscore , stat -> data [1 ]);
1368+ player = cw_box_find_player (boxscore , stat -> data [1 ], 1 );
13631369 if (player == NULL ) {
13641370 fprintf (stderr ,
13651371 "ERROR: In %s, cannot find entry for player '%s' listed in prline.\n" ,
@@ -1487,7 +1493,7 @@ cw_box_create(CWGame *game)
14871493 if (pitcher != NULL ) pitcher -> pitching -> sv = 1 ;
14881494 }
14891495 if (cw_game_info_lookup (game , "gwrbi" ) != NULL ) {
1490- batter = cw_box_find_player (boxscore , cw_game_info_lookup (game , "gwrbi" ));
1496+ batter = cw_box_find_player (boxscore , cw_game_info_lookup (game , "gwrbi" ), 1 );
14911497 if (batter != NULL ) batter -> batting -> gw = 1 ;
14921498 }
14931499 return boxscore ;
0 commit comments