Auto-increment field based on value of another field
Checkout hook_node_presave() here you can set the values dynamically.
And variable_get() and variable_set() for the increment.

With str_pad() you can add the starting zeros to the increment.

hook_node_presave($node) {
  if ($node-&gt;field_A[LANGUAGE_NONE][0]['value'] == 'Location X') {
    $increment = varibable_get('LocationX_increment', 0);
    $increment++;
    $node-&gt;field_B[LANGUAGE_NONE][0]['value'] = 'X' . str_pad($increment, 3, '0', STR_PAD_LEFT);
    variable_set('LocationX_increment', $increment);
  }
}


You don't need to save the node in this hook, just change the value of the field.